[FFmpeg-devel] [PATCH 2/2] libavcodec/ac3_parser: add avpriv function to parse EC3SpecificBox (dec3)

Nachiket Tarate nachiket.tarate at outlook.com
Fri Oct 2 16:10:06 EEST 2020


This will be used by HLS demuxer for SAMPLE-AES decryption.

Signed-off-by: Nachiket Tarate <nachiket.tarate at outlook.com>
---
 libavcodec/ac3_parser.c          | 47 ++++++++++++++++++++++++++++++++
 libavcodec/ac3_parser_internal.h |  4 +++
 2 files changed, 51 insertions(+)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index ba171653ef..a8fdde0ff9 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -2,6 +2,7 @@
  * AC-3 parser
  * Copyright (c) 2003 Fabrice Bellard
  * Copyright (c) 2003 Michael Niedermayer
+ * Copyright (c) 2020 Nachiket Tarate
  *
  * This file is part of FFmpeg.
  *
@@ -172,6 +173,47 @@ int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf,
     return get_bits_count(&gb);
 }
 
+/*
+ * Parse 'dec3' EC3SpecificBox
+ */
+int avpriv_eac3_parse_dec3(AC3HeaderInfo **phdr, const uint8_t *buf, size_t size)
+{
+    GetBitContext gb;
+    AC3HeaderInfo *hdr;
+    int err;
+
+    int data_rate, fscod, acmod, lfeon;
+
+    if (!*phdr)
+        *phdr = av_mallocz(sizeof(AC3HeaderInfo));
+    if (!*phdr)
+        return AVERROR(ENOMEM);
+    hdr = *phdr;
+
+    err = init_get_bits8(&gb, buf, size);
+    if (err < 0)
+        return AVERROR_INVALIDDATA;
+
+    data_rate = get_bits(&gb, 13);
+    skip_bits(&gb, 3);
+    fscod = get_bits(&gb, 2);
+    skip_bits(&gb, 10);
+    acmod = get_bits(&gb, 3);
+    lfeon = get_bits(&gb, 1);
+
+    hdr->sample_rate = ff_ac3_sample_rate_tab[fscod];
+
+    hdr->channels = ff_ac3_channels_tab[acmod] + lfeon;
+
+    hdr->channel_layout = avpriv_ac3_channel_layout_tab[acmod];
+    if (lfeon)
+        hdr->channel_layout |= AV_CH_LOW_FREQUENCY;
+ 
+    hdr->bit_rate = data_rate*1000;
+
+    return 0;
+}
+
 int av_ac3_parse_header(const uint8_t *buf, size_t size,
                         uint8_t *bitstream_id, uint16_t *frame_size)
 {
@@ -256,6 +298,11 @@ int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf,
     return AVERROR(ENOSYS);
 }
 
+int avpriv_eac3_parse_dec3(AC3HeaderInfo **phdr, const uint8_t *buf, size_t size)
+{
+    return AVERROR(ENOSYS);
+}
+
 int av_ac3_parse_header(const uint8_t *buf, size_t size,
                         uint8_t *bitstream_id, uint16_t *frame_size)
 {
diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
index 3648802a73..0388a5bb5e 100644
--- a/libavcodec/ac3_parser_internal.h
+++ b/libavcodec/ac3_parser_internal.h
@@ -38,5 +38,9 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
 
 int avpriv_ac3_parse_header(AC3HeaderInfo **hdr, const uint8_t *buf,
                             size_t size);
+/*
+ * Parse 'dec3' EC3SpecificBox
+ */
+int avpriv_eac3_parse_dec3(AC3HeaderInfo **phdr, const uint8_t *buf, size_t size);
 
 #endif /* AVCODEC_AC3_PARSER_INTERNAL_H */
-- 
2.17.1



More information about the ffmpeg-devel mailing list