From 8cb1ff78ac62ff0f652b0cb06369ba50d5e946c6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 20 Sep 2025 01:56:20 +0200 Subject: [PATCH] avformat/dhav: Factorize some code in get_duration() Signed-off-by: Michael Niedermayer --- libavformat/dhav.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libavformat/dhav.c b/libavformat/dhav.c index b3fa612ab3..614934dc68 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -242,7 +242,7 @@ static int64_t get_duration(AVFormatContext *s) int64_t start_pos = avio_tell(s->pb); int64_t pos = -1; - int64_t start = 0, end = 0; + int64_t start = 0; struct tm timeinfo; uint8_t *buffer; int64_t buffer_size; @@ -250,6 +250,7 @@ static int64_t get_duration(AVFormatContext *s) int64_t offset; unsigned date; int64_t size = avio_size(s->pb); + int64_t ret = 0; if (start_pos + 20 > size) return 0; @@ -284,17 +285,12 @@ static int64_t get_duration(AVFormatContext *s) date = AV_RL32(buffer + (pos - buffer_pos) + 16); get_timeinfo(date, &timeinfo); - end = av_timegm(&timeinfo) * 1000LL; - av_freep(&buffer); - - avio_seek(s->pb, start_pos, SEEK_SET); - - return end - start; + ret = av_timegm(&timeinfo) * 1000LL - start; fail: av_freep(&buffer); avio_seek(s->pb, start_pos, SEEK_SET); - return 0; + return ret; } static int dhav_read_header(AVFormatContext *s)