[FFmpeg-devel] [PATCH] lavf/mov: fix hang while seek on a kind of fragmented mp4.
Charles Liu
liuchh83 at gmail.com
Sat Feb 2 09:40:26 EET 2019
Binary searching would hang if the fragment items do NOT have timestamp for the specified stream.
For example, a fmp4 consists of separated 'moof' boxes for each track, and separated 'sidx' for each segment, but no 'mfra' box.
Then every fragment item only have the timestamp for one of its tracks.
Signed-off-by: Charles Liu <liuchh83 at gmail.com>
---
libavformat/mov.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9b9739f788..ce1130ad07 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1266,9 +1266,8 @@ static int64_t get_frag_time(MOVFragmentIndex *frag_index,
static int search_frag_timestamp(MOVFragmentIndex *frag_index,
AVStream *st, int64_t timestamp)
{
- int a, b, m;
int64_t frag_time;
- int id = -1;
+ int i, frag = 0, id = -1;
if (st) {
// If the stream is referenced by any sidx, limit the search
@@ -1278,20 +1277,18 @@ static int search_frag_timestamp(MOVFragmentIndex *frag_index,
id = st->id;
}
- a = -1;
- b = frag_index->nb_items;
-
- while (b - a > 1) {
- m = (a + b) >> 1;
- frag_time = get_frag_time(frag_index, m, id);
+ for (i = 0; i < frag_index->nb_items; i++) {
+ frag_time = get_frag_time(frag_index, i, id);
if (frag_time != AV_NOPTS_VALUE) {
- if (frag_time >= timestamp)
- b = m;
if (frag_time <= timestamp)
- a = m;
+ frag = i;
+ else {
+ break;
+ }
}
}
- return a;
+
+ return frag;
}
static int update_frag_index(MOVContext *c, int64_t offset)
--
2.20.1
More information about the ffmpeg-devel
mailing list