[FFmpeg-cvslog] avformat/mxfdec: use binary search in mxf_absolute_bodysid_offset

Marton Balint git at videolan.org
Fri Mar 9 22:11:46 EET 2018


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Mon Feb 19 00:43:05 2018 +0100| [90756e67a0a1de762d27c2fe01a30ac8434a3631] | committer: Marton Balint

avformat/mxfdec: use binary search in mxf_absolute_bodysid_offset

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90756e67a0a1de762d27c2fe01a30ac8434a3631
---

 libavformat/mxfdec.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index d4291f5dc7..70091e0dc9 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1347,24 +1347,30 @@ static int mxf_get_sorted_table_segments(MXFContext *mxf, int *nb_sorted_segment
  */
 static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t offset, int64_t *offset_out)
 {
-    int x;
     MXFPartition *last_p = NULL;
+    int a, b, m, m0;
 
     if (offset < 0)
         return AVERROR(EINVAL);
 
-    for (x = 0; x < mxf->partitions_count; x++) {
-        MXFPartition *p = &mxf->partitions[x];
+    a = -1;
+    b = mxf->partitions_count;
 
-        if (p->body_sid != body_sid)
-            continue;
+    while (b - a > 1) {
+        m0 = m = (a + b) >> 1;
 
-        if (p->body_offset > offset)
-            break;
+        while (m < b && mxf->partitions[m].body_sid != body_sid)
+            m++;
 
-        last_p = p;
+        if (m < b && mxf->partitions[m].body_offset <= offset)
+            a = m;
+        else
+            b = m0;
     }
 
+    if (a >= 0)
+        last_p = &mxf->partitions[a];
+
     if (last_p && (!last_p->essence_length || last_p->essence_length > (offset - last_p->body_offset))) {
         *offset_out = last_p->essence_offset + (offset - last_p->body_offset);
         return 0;



More information about the ffmpeg-cvslog mailing list