diff mbox

[FFmpeg-devel] libavformat/aac: Parse all ID3 tags present between ADTS frames

Message ID 1600c26d-13ac-8e95-7cda-aab5a79f29ca@avm.se
State Superseded
Headers show

Commit Message

Mattias Amnefelt April 2, 2018, 11:35 a.m. UTC
This is a follow-up to https://patchwork.ffmpeg.org/patch/7477/ and 
changes so all ID3 tags between ADTS frames gets parsed, not just the 
first one.

Sample media for the included fate test is available at 
http://mattias.amnefe.lt/tmp/id3v2_two_tags.aac
From 2f681aa27c216a1aa8d8f2b643289dbf087de306 Mon Sep 17 00:00:00 2001
From: Mattias Amnefelt <mattiasa@avm.se>
Date: Mon, 2 Apr 2018 11:30:40 +0200
Subject: [PATCH] libavformat/aac: Parse all ID3 tags present between ADTS
 frames

Some ADTS streams can have multiple ID3 tags between frames. This
change parses all of them, rather than just the first one.

Signed-off-by: Mattias Amnefelt <mattiasa@avm.se>
---
 libavformat/aacdec.c                     |  14 +-
 tests/fate/demux.mak                     |   3 +-
 tests/ref/fate/adts-id3v2-two-tags-demux | 241 +++++++++++++++++++++++++++++++
 3 files changed, 252 insertions(+), 6 deletions(-)
 create mode 100644 tests/ref/fate/adts-id3v2-two-tags-demux

Comments

rshaffer@tunein.com April 2, 2018, 9:25 p.m. UTC | #1
It seems like some software can insert an additional ID3v2 tag instead
of appending a frame to an existing one. One could argue that that is
somewhat broken, but I agree it's better to handle it instead of
returning an error. The changes in aacdec.c look ok to me.

The fate sample you provided has two tags at the beginning of the
file. These will actually get parsed by avformat_open_input calling
ff_id3v2_read_dict and not by the adts demuxer. The ff_id3v2_read_dict
code path will already parse multiple tags, which is why the test
passes. In order to exercise your code change, the ID3v2 tags would
have to be between ADTS frames.

-Richard

On Mon, Apr 2, 2018 at 4:35 AM, Mattias Amnefelt <mattiasa@avm.se> wrote:
> This is a follow-up to https://patchwork.ffmpeg.org/patch/7477/ and changes
> so all ID3 tags between ADTS frames gets parsed, not just the first one.
>
> Sample media for the included fate test is available at
> http://mattias.amnefe.lt/tmp/id3v2_two_tags.aac
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index 5ec706bdc7..685458b911 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -154,11 +154,15 @@  static int adts_aac_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, fsize;
 
-    ret = av_get_packet(s->pb, pkt, FFMAX(ID3v2_HEADER_SIZE, ADTS_HEADER_SIZE));
-
-    if (ret >= ID3v2_HEADER_SIZE && ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) {
-        if ((ret = handle_id3(s, pkt)) >= 0)
-            ret = av_get_packet(s->pb, pkt, ADTS_HEADER_SIZE);
+    // Parse all the ID3 headers between frames
+    while (1) {
+        ret = av_get_packet(s->pb, pkt, FFMAX(ID3v2_HEADER_SIZE, ADTS_HEADER_SIZE));
+        if (ret >= ID3v2_HEADER_SIZE && ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) {
+            if ((ret = handle_id3(s, pkt)) >= 0) {
+                continue;
+            }
+        }
+        break;
     }
 
     if (ret < 0)
diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index 306904b9de..fc581f81ad 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -1,10 +1,11 @@ 
 FATE_SAMPLES_DEMUX-$(call DEMDEC, AVI, FRAPS) += fate-avio-direct
 fate-avio-direct: CMD = framecrc -avioflags direct -i $(TARGET_SAMPLES)/fraps/fraps-v5-bouncing-balls-partial.avi -avioflags direct
 
-FATE_SAMPLES_DEMUX-$(call DEMDEC, AAC, AAC) += fate-adts-demux fate-adts-id3v1-demux fate-adts-id3v2-demux
+FATE_SAMPLES_DEMUX-$(call DEMDEC, AAC, AAC) += fate-adts-demux fate-adts-id3v1-demux fate-adts-id3v2-demux fate-adts-id3v2-two-tags-demux
 fate-adts-demux: CMD = crc -i $(TARGET_SAMPLES)/aac/ct_faac-adts.aac -c:a copy
 fate-adts-id3v1-demux: CMD = framecrc -f aac -i $(TARGET_SAMPLES)/aac/id3v1.aac -c:a copy
 fate-adts-id3v2-demux: CMD = framecrc -f aac -i $(TARGET_SAMPLES)/aac/id3v2.aac -c:a copy
+fate-adts-id3v2-two-tags-demux: CMD = framecrc -f aac -i $(TARGET_SAMPLES)/aac/id3v2_two_tags.aac -c:a copy
 
 FATE_SAMPLES_DEMUX-$(CONFIG_AEA_DEMUXER) += fate-aea-demux
 fate-aea-demux: CMD = crc -i $(TARGET_SAMPLES)/aea/chirp.aea -c:a copy
diff --git a/tests/ref/fate/adts-id3v2-two-tags-demux b/tests/ref/fate/adts-id3v2-two-tags-demux
new file mode 100644
index 0000000000..61463f4996
--- /dev/null
+++ b/tests/ref/fate/adts-id3v2-two-tags-demux
@@ -0,0 +1,241 @@ 
+#tb 0: 1/28224000
+#media_type 0: audio
+#codec_id 0: aac
+#sample_rate 0: 48000
+#channel_layout 0: 4
+#channel_layout_name 0: mono
+0,          0,          0,   602112,      128, 0x23291993
+0,     602112,     602112,   602112,      128, 0x23291993
+0,    1204224,    1204224,   602112,      128, 0x23291993
+0,    1806336,    1806336,   602112,      128, 0x23291993
+0,    2408448,    2408448,   602112,      128, 0x23291993
+0,    3010560,    3010560,   602112,      128, 0x23291993
+0,    3612672,    3612672,   602112,      128, 0x23291993
+0,    4214784,    4214784,   602112,      128, 0x23291993
+0,    4816896,    4816896,   602112,      128, 0x23291993
+0,    5419008,    5419008,   602112,      128, 0x23291993
+0,    6021120,    6021120,   602112,      128, 0x23291993
+0,    6623232,    6623232,   602112,      128, 0x23291993
+0,    7225344,    7225344,   602112,      128, 0x23291993
+0,    7827456,    7827456,   602112,      128, 0x23291993
+0,    8429568,    8429568,   602112,      128, 0x23291993
+0,    9031680,    9031680,   602112,      128, 0x23291993
+0,    9633792,    9633792,   602112,      128, 0x23291993
+0,   10235904,   10235904,   602112,      128, 0x23291993
+0,   10838016,   10838016,   602112,      128, 0x23291993
+0,   11440128,   11440128,   602112,      128, 0x23291993
+0,   12042240,   12042240,   602112,      128, 0x23291993
+0,   12644352,   12644352,   602112,      128, 0x23291993
+0,   13246464,   13246464,   602112,      128, 0x23291993
+0,   13848576,   13848576,   602112,      128, 0x23291993
+0,   14450688,   14450688,   602112,      128, 0x23291993
+0,   15052800,   15052800,   602112,      128, 0x23291993
+0,   15654912,   15654912,   602112,      128, 0x23291993
+0,   16257024,   16257024,   602112,      128, 0x23291993
+0,   16859136,   16859136,   602112,      128, 0x23291993
+0,   17461248,   17461248,   602112,      128, 0x23291993
+0,   18063360,   18063360,   602112,      128, 0x23291993
+0,   18665472,   18665472,   602112,      128, 0x23291993
+0,   19267584,   19267584,   602112,      128, 0x23291993
+0,   19869696,   19869696,   602112,      128, 0x23291993
+0,   20471808,   20471808,   602112,      128, 0x23291993
+0,   21073920,   21073920,   602112,      128, 0x23291993
+0,   21676032,   21676032,   602112,      128, 0x23291993
+0,   22278144,   22278144,   602112,      128, 0x23291993
+0,   22880256,   22880256,   602112,      128, 0x23291993
+0,   23482368,   23482368,   602112,      128, 0x23291993
+0,   24084480,   24084480,   602112,      128, 0x23291993
+0,   24686592,   24686592,   602112,      128, 0x23291993
+0,   25288704,   25288704,   602112,      128, 0x23291993
+0,   25890816,   25890816,   602112,      128, 0x23291993
+0,   26492928,   26492928,   602112,      128, 0x23291993
+0,   27095040,   27095040,   602112,      128, 0x23291993
+0,   27697152,   27697152,   602112,      128, 0x23291993
+0,   28299264,   28299264,   602112,      128, 0x23291993
+0,   28901376,   28901376,   602112,      128, 0x23291993
+0,   29503488,   29503488,   602112,      128, 0x23291993
+0,   30105600,   30105600,   602112,      128, 0x23291993
+0,   30707712,   30707712,   602112,      128, 0x23291993
+0,   31309824,   31309824,   602112,      128, 0x23291993
+0,   31911936,   31911936,   602112,      128, 0x23291993
+0,   32514048,   32514048,   602112,      128, 0x23291993
+0,   33116160,   33116160,   602112,      128, 0x23291993
+0,   33718272,   33718272,   602112,      128, 0x23291993
+0,   34320384,   34320384,   602112,      128, 0x23291993
+0,   34922496,   34922496,   602112,      128, 0x23291993
+0,   35524608,   35524608,   602112,      128, 0x23291993
+0,   36126720,   36126720,   602112,      128, 0x23291993
+0,   36728832,   36728832,   602112,      128, 0x23291993
+0,   37330944,   37330944,   602112,      128, 0x23291993
+0,   37933056,   37933056,   602112,      128, 0x23291993
+0,   38535168,   38535168,   602112,      128, 0x23291993
+0,   39137280,   39137280,   602112,      128, 0x23291993
+0,   39739392,   39739392,   602112,      128, 0x23291993
+0,   40341504,   40341504,   602112,      128, 0x23291993
+0,   40943616,   40943616,   602112,      128, 0x23291993
+0,   41545728,   41545728,   602112,      128, 0x23291993
+0,   42147840,   42147840,   602112,      128, 0x23291993
+0,   42749952,   42749952,   602112,      128, 0x23291993
+0,   43352064,   43352064,   602112,      128, 0x23291993
+0,   43954176,   43954176,   602112,      128, 0x23291993
+0,   44556288,   44556288,   602112,      128, 0x23291993
+0,   45158400,   45158400,   602112,      128, 0x23291993
+0,   45760512,   45760512,   602112,      128, 0x23291993
+0,   46362624,   46362624,   602112,      128, 0x23291993
+0,   46964736,   46964736,   602112,      128, 0x23291993
+0,   47566848,   47566848,   602112,      128, 0x23291993
+0,   48168960,   48168960,   602112,      128, 0x23291993
+0,   48771072,   48771072,   602112,      128, 0x23291993
+0,   49373184,   49373184,   602112,      128, 0x23291993
+0,   49975296,   49975296,   602112,      128, 0x23291993
+0,   50577408,   50577408,   602112,      128, 0x23291993
+0,   51179520,   51179520,   602112,      128, 0x23291993
+0,   51781632,   51781632,   602112,      128, 0x23291993
+0,   52383744,   52383744,   602112,      128, 0x23291993
+0,   52985856,   52985856,   602112,      128, 0x23291993
+0,   53587968,   53587968,   602112,      128, 0x23291993
+0,   54190080,   54190080,   602112,      128, 0x23291993
+0,   54792192,   54792192,   602112,      128, 0x23291993
+0,   55394304,   55394304,   602112,      128, 0x23291993
+0,   55996416,   55996416,   602112,      128, 0x23291993
+0,   56598528,   56598528,   602112,      128, 0x23291993
+0,   57200640,   57200640,   602112,      128, 0x23291993
+0,   57802752,   57802752,   602112,      128, 0x23291993
+0,   58404864,   58404864,   602112,      128, 0x23291993
+0,   59006976,   59006976,   602112,      128, 0x23291993
+0,   59609088,   59609088,   602112,      128, 0x23291993
+0,   60211200,   60211200,   602112,      128, 0x23291993
+0,   60813312,   60813312,   602112,      128, 0x23291993
+0,   61415424,   61415424,   602112,      128, 0x23291993
+0,   62017536,   62017536,   602112,      128, 0x23291993
+0,   62619648,   62619648,   602112,      128, 0x23291993
+0,   63221760,   63221760,   602112,      128, 0x23291993
+0,   63823872,   63823872,   602112,      128, 0x23291993
+0,   64425984,   64425984,   602112,      128, 0x23291993
+0,   65028096,   65028096,   602112,      128, 0x23291993
+0,   65630208,   65630208,   602112,      128, 0x23291993
+0,   66232320,   66232320,   602112,      128, 0x23291993
+0,   66834432,   66834432,   602112,      128, 0x23291993
+0,   67436544,   67436544,   602112,      128, 0x23291993
+0,   68038656,   68038656,   602112,      128, 0x23291993
+0,   68640768,   68640768,   602112,      128, 0x23291993
+0,   69242880,   69242880,   602112,      128, 0x23291993
+0,   69844992,   69844992,   602112,      128, 0x23291993
+0,   70447104,   70447104,   602112,      128, 0x23291993
+0,   71049216,   71049216,   602112,      128, 0x23291993
+0,   71651328,   71651328,   602112,      128, 0x23291993
+0,   72253440,   72253440,   602112,      128, 0x23291993
+0,   72855552,   72855552,   602112,      128, 0x23291993
+0,   73457664,   73457664,   602112,      128, 0x23291993
+0,   74059776,   74059776,   602112,      128, 0x23291993
+0,   74661888,   74661888,   602112,      128, 0x23291993
+0,   75264000,   75264000,   602112,      128, 0x23291993
+0,   75866112,   75866112,   602112,      128, 0x23291993
+0,   76468224,   76468224,   602112,      128, 0x23291993
+0,   77070336,   77070336,   602112,      128, 0x23291993
+0,   77672448,   77672448,   602112,      128, 0x23291993
+0,   78274560,   78274560,   602112,      128, 0x23291993
+0,   78876672,   78876672,   602112,      128, 0x23291993
+0,   79478784,   79478784,   602112,      128, 0x23291993
+0,   80080896,   80080896,   602112,      128, 0x23291993
+0,   80683008,   80683008,   602112,      128, 0x23291993
+0,   81285120,   81285120,   602112,      128, 0x23291993
+0,   81887232,   81887232,   602112,      128, 0x23291993
+0,   82489344,   82489344,   602112,      128, 0x23291993
+0,   83091456,   83091456,   602112,      128, 0x23291993
+0,   83693568,   83693568,   602112,      128, 0x23291993
+0,   84295680,   84295680,   602112,      128, 0x23291993
+0,   84897792,   84897792,   602112,      128, 0x23291993
+0,   85499904,   85499904,   602112,      128, 0x23291993
+0,   86102016,   86102016,   602112,      128, 0x23291993
+0,   86704128,   86704128,   602112,      128, 0x23291993
+0,   87306240,   87306240,   602112,      128, 0x23291993
+0,   87908352,   87908352,   602112,      128, 0x23291993
+0,   88510464,   88510464,   602112,      128, 0x23291993
+0,   89112576,   89112576,   602112,      128, 0x23291993
+0,   89714688,   89714688,   602112,      128, 0x23291993
+0,   90316800,   90316800,   602112,      128, 0x23291993
+0,   90918912,   90918912,   602112,      128, 0x23291993
+0,   91521024,   91521024,   602112,      128, 0x23291993
+0,   92123136,   92123136,   602112,      128, 0x23291993
+0,   92725248,   92725248,   602112,      128, 0x23291993
+0,   93327360,   93327360,   602112,      128, 0x23291993
+0,   93929472,   93929472,   602112,      128, 0x23291993
+0,   94531584,   94531584,   602112,      128, 0x23291993
+0,   95133696,   95133696,   602112,      128, 0x23291993
+0,   95735808,   95735808,   602112,      128, 0x23291993
+0,   96337920,   96337920,   602112,      128, 0x23291993
+0,   96940032,   96940032,   602112,      128, 0x23291993
+0,   97542144,   97542144,   602112,      128, 0x23291993
+0,   98144256,   98144256,   602112,      128, 0x23291993
+0,   98746368,   98746368,   602112,      128, 0x23291993
+0,   99348480,   99348480,   602112,      128, 0x23291993
+0,   99950592,   99950592,   602112,      128, 0x23291993
+0,  100552704,  100552704,   602112,      128, 0x23291993
+0,  101154816,  101154816,   602112,      128, 0x23291993
+0,  101756928,  101756928,   602112,      128, 0x23291993
+0,  102359040,  102359040,   602112,      128, 0x23291993
+0,  102961152,  102961152,   602112,      128, 0x23291993
+0,  103563264,  103563264,   602112,      128, 0x23291993
+0,  104165376,  104165376,   602112,      128, 0x23291993
+0,  104767488,  104767488,   602112,      128, 0x23291993
+0,  105369600,  105369600,   602112,      128, 0x23291993
+0,  105971712,  105971712,   602112,      128, 0x23291993
+0,  106573824,  106573824,   602112,      128, 0x23291993
+0,  107175936,  107175936,   602112,      128, 0x23291993
+0,  107778048,  107778048,   602112,      128, 0x23291993
+0,  108380160,  108380160,   602112,      128, 0x23291993
+0,  108982272,  108982272,   602112,      128, 0x23291993
+0,  109584384,  109584384,   602112,      128, 0x23291993
+0,  110186496,  110186496,   602112,      128, 0x23291993
+0,  110788608,  110788608,   602112,      128, 0x23291993
+0,  111390720,  111390720,   602112,      128, 0x23291993
+0,  111992832,  111992832,   602112,      128, 0x23291993
+0,  112594944,  112594944,   602112,      128, 0x23291993
+0,  113197056,  113197056,   602112,      128, 0x23291993
+0,  113799168,  113799168,   602112,      128, 0x23291993
+0,  114401280,  114401280,   602112,      128, 0x23291993
+0,  115003392,  115003392,   602112,      128, 0x23291993
+0,  115605504,  115605504,   602112,      128, 0x23291993
+0,  116207616,  116207616,   602112,      128, 0x23291993
+0,  116809728,  116809728,   602112,      128, 0x23291993
+0,  117411840,  117411840,   602112,      128, 0x23291993
+0,  118013952,  118013952,   602112,      128, 0x23291993
+0,  118616064,  118616064,   602112,      128, 0x23291993
+0,  119218176,  119218176,   602112,      128, 0x23291993
+0,  119820288,  119820288,   602112,      128, 0x23291993
+0,  120422400,  120422400,   602112,      128, 0x23291993
+0,  121024512,  121024512,   602112,      128, 0x23291993
+0,  121626624,  121626624,   602112,      128, 0x23291993
+0,  122228736,  122228736,   602112,      128, 0x23291993
+0,  122830848,  122830848,   602112,      128, 0x23291993
+0,  123432960,  123432960,   602112,      128, 0x23291993
+0,  124035072,  124035072,   602112,      128, 0x23291993
+0,  124637184,  124637184,   602112,      128, 0x23291993
+0,  125239296,  125239296,   602112,      128, 0x23291993
+0,  125841408,  125841408,   602112,      128, 0x23291993
+0,  126443520,  126443520,   602112,      128, 0x23291993
+0,  127045632,  127045632,   602112,      128, 0x23291993
+0,  127647744,  127647744,   602112,      128, 0x23291993
+0,  128249856,  128249856,   602112,      128, 0x23291993
+0,  128851968,  128851968,   602112,      128, 0x23291993
+0,  129454080,  129454080,   602112,      128, 0x23291993
+0,  130056192,  130056192,   602112,      128, 0x23291993
+0,  130658304,  130658304,   602112,      128, 0x23291993
+0,  131260416,  131260416,   602112,      128, 0x23291993
+0,  131862528,  131862528,   602112,      128, 0x23291993
+0,  132464640,  132464640,   602112,      128, 0x23291993
+0,  133066752,  133066752,   602112,      128, 0x23291993
+0,  133668864,  133668864,   602112,      128, 0x23291993
+0,  134270976,  134270976,   602112,      128, 0x23291993
+0,  134873088,  134873088,   602112,      128, 0x23291993
+0,  135475200,  135475200,   602112,      128, 0x23291993
+0,  136077312,  136077312,   602112,      128, 0x23291993
+0,  136679424,  136679424,   602112,      128, 0x23291993
+0,  137281536,  137281536,   602112,      128, 0x23291993
+0,  137883648,  137883648,   602112,      128, 0x23291993
+0,  138485760,  138485760,   602112,      128, 0x23291993
+0,  139087872,  139087872,   602112,      128, 0x23291993
+0,  139689984,  139689984,   602112,      128, 0x23291993
+0,  140292096,  140292096,   602112,      128, 0x23291993
+0,  140894208,  140894208,   602112,      128, 0x23291993