[FFmpeg-cvslog] avformat/aea: improve probe function

Paul B Mahol git at videolan.org
Mon Oct 2 02:29:51 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Oct  2 00:53:16 2023 +0200| [edb6d6d5361ad6c58af32d3c1ba9a6569988380d] | committer: Paul B Mahol

avformat/aea: improve probe function

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

 libavformat/aea.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libavformat/aea.c b/libavformat/aea.c
index d16217381b..684217a2a3 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -25,36 +25,32 @@
 #include "avformat.h"
 #include "pcm.h"
 
-#define AT1_SU_SIZE     212
+#define AT1_SU_SIZE 212
 
 static int aea_read_probe(const AVProbeData *p)
 {
-    if (p->buf_size <= 2048+212)
+    if (p->buf_size <= 2048+AT1_SU_SIZE)
         return 0;
 
     /* Magic is '00 08 00 00' in little-endian*/
     if (AV_RL32(p->buf)==0x800) {
-        int ch, i;
+        int ch, block_size, score = 0;
         ch = p->buf[264];
 
         if (ch != 1 && ch != 2)
             return 0;
 
+        block_size = ch * AT1_SU_SIZE;
         /* Check so that the redundant bsm bytes and info bytes are valid
          * the block size mode bytes have to be the same
          * the info bytes have to be the same
          */
-        for (i = 2048; i + 211 < p->buf_size; i+= 212) {
-            int bsm_s, bsm_e, inb_s, inb_e;
-            bsm_s = p->buf[0];
-            inb_s = p->buf[1];
-            inb_e = p->buf[210];
-            bsm_e = p->buf[211];
-
-            if (bsm_s != bsm_e || inb_s != inb_e)
+        for (int i = 2048 + block_size; i + block_size <= p->buf_size; i += block_size) {
+            if (AV_RN16(p->buf+i) != AV_RN16(p->buf+i+AT1_SU_SIZE))
                 return 0;
+            score++;
         }
-        return AVPROBE_SCORE_MAX / 4 + 1;
+        return FFMIN(AVPROBE_SCORE_MAX / 4 + score, AVPROBE_SCORE_MAX);
     }
     return 0;
 }



More information about the ffmpeg-cvslog mailing list