[FFmpeg-cvslog] avformat/aacdec: factorize the adts frame resync code

James Almer git at videolan.org
Tue Jul 23 07:15:40 EEST 2019


ffmpeg | branch: release/3.4 | James Almer <jamrial at gmail.com> | Sat Jul 20 10:13:08 2019 -0300| [a9282fc9642bd67c2bbc16dd4b7b3fe7ab27e104] | committer: James Almer

avformat/aacdec: factorize the adts frame resync code

Signed-off-by: James Almer <jamrial at gmail.com>
(cherry picked from commit a38eab8b7501440f872ff1af8a0c5482b7b3e532)

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

 libavformat/aacdec.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index 36d558ff54..4cd2f9077e 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -77,10 +77,31 @@ static int adts_aac_probe(AVProbeData *p)
         return 0;
 }
 
+static int adts_aac_resync(AVFormatContext *s)
+{
+    uint16_t state;
+
+    // skip data until an ADTS frame is found
+    state = avio_r8(s->pb);
+    while (!avio_feof(s->pb) && avio_tell(s->pb) < s->probesize) {
+        state = (state << 8) | avio_r8(s->pb);
+        if ((state >> 4) != 0xFFF)
+            continue;
+        avio_seek(s->pb, -2, SEEK_CUR);
+        break;
+    }
+    if (s->pb->eof_reached)
+        return AVERROR_EOF;
+    if ((state >> 4) != 0xFFF)
+        return AVERROR_INVALIDDATA;
+
+    return 0;
+}
+
 static int adts_aac_read_header(AVFormatContext *s)
 {
     AVStream *st;
-    uint16_t state;
+    int ret;
 
     st = avformat_new_stream(s, NULL);
     if (!st)
@@ -98,17 +119,9 @@ static int adts_aac_read_header(AVFormatContext *s)
         avio_seek(s->pb, cur, SEEK_SET);
     }
 
-    // skip data until the first ADTS frame is found
-    state = avio_r8(s->pb);
-    while (!avio_feof(s->pb) && avio_tell(s->pb) < s->probesize) {
-        state = (state << 8) | avio_r8(s->pb);
-        if ((state >> 4) != 0xFFF)
-            continue;
-        avio_seek(s->pb, -2, SEEK_CUR);
-        break;
-    }
-    if ((state >> 4) != 0xFFF)
-        return AVERROR_INVALIDDATA;
+    ret = adts_aac_resync(s);
+    if (ret < 0)
+        return ret;
 
     // LCM of all possible ADTS sample rates
     avpriv_set_pts_info(st, 64, 1, 28224000);



More information about the ffmpeg-cvslog mailing list