[FFmpeg-devel] [PATCH 3/4] lavc/aac_ac3_parser: convert ADTS AAC to ASC format

Rodger Combs rodger.combs at gmail.com
Tue Sep 22 03:49:43 CEST 2015


---
 libavcodec/aac_ac3_parser.c | 65 ++++++++++++++++++++++++++++++++++++++++++---
 tests/ref/fate/adts-demux   |  2 +-
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index dfa951e..a7e9278 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -24,6 +24,10 @@
 #include "libavutil/common.h"
 #include "parser.h"
 #include "aac_ac3_parser.h"
+#include "aacadtsdec.h"
+#include "put_bits.h"
+#include "get_bits.h"
+#include "mpeg4audio.h"
 
 int ff_aac_ac3_parse(AVCodecParserContext *s1,
                      AVCodecContext *avctx,
@@ -69,9 +73,6 @@ get_next:
         return buf_size;
     }
 
-    *poutbuf = buf;
-    *poutbuf_size = buf_size;
-
     /* update codec info */
     if(s->codec_id)
         avctx->codec_id = s->codec_id;
@@ -98,7 +99,65 @@ get_next:
         }
         s1->duration = s->samples;
         avctx->audio_service_type = s->service_type;
+    } else if (AV_RB16(buf) & 0xfff0 == 0xfff0) {
+        GetBitContext gb;
+        AACADTSHeaderInfo hdr;
+        int            pce_size = 0;
+        uint8_t        pce_data[MAX_PCE_SIZE];
+        init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE * 8);
+        if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
+            goto skip_adts;
+        }
+        if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
+            avpriv_report_missing_feature(avctx, "Multiple RDBs per frame with CRC");
+            goto skip_adts;
+        }
+
+        buf      += AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
+        buf_size -= AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
+
+        if (!avctx->extradata) {
+            PutBitContext pb;
+            if (!hdr.chan_config) {
+                init_get_bits(&gb, buf, buf_size * 8);
+                if (get_bits(&gb, 3) != 5) {
+                    avpriv_report_missing_feature(avctx,
+                                                  "PCE-based channel configuration "
+                                                  "without PCE as first syntax "
+                                                  "element");
+                    goto skip_adts;
+                }
+                init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
+                pce_size = avpriv_copy_pce_data(&pb, &gb) / 8;
+                flush_put_bits(&pb);
+                buf_size -= get_bits_count(&gb) / 8;
+                buf      += get_bits_count(&gb) / 8;
+            }
+            av_free(avctx->extradata);
+            avctx->extradata_size = 2 + pce_size;
+            avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+            if (!avctx->extradata) {
+                avctx->extradata_size = 0;
+                goto skip_adts;
+            }
+
+            init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
+            put_bits(&pb, 5, hdr.object_type);
+            put_bits(&pb, 4, hdr.sampling_index);
+            put_bits(&pb, 4, hdr.chan_config);
+            put_bits(&pb, 1, 0); //frame length - 1024 samples
+            put_bits(&pb, 1, 0); //does not depend on core coder
+            put_bits(&pb, 1, 0); //is not extension
+            flush_put_bits(&pb);
+            if (pce_size)
+                memcpy(avctx->extradata + 2, pce_data, pce_size);
+        }
     }
+skip_adts:
+
+    *poutbuf = buf;
+    *poutbuf_size = buf_size;
 
     avctx->bit_rate = s->bit_rate;
 
diff --git a/tests/ref/fate/adts-demux b/tests/ref/fate/adts-demux
index 744ae64..78898cc 100644
--- a/tests/ref/fate/adts-demux
+++ b/tests/ref/fate/adts-demux
@@ -1 +1 @@
-CRC=0xbda37454
+CRC=0x6def5f3d
-- 
2.5.1



More information about the ffmpeg-devel mailing list