diff mbox series

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

Message ID SG2PR01MB26933CF054EA42E5A67A6CB7F2310@SG2PR01MB2693.apcprd01.prod.exchangelabs.com
State New
Headers show
Series [FFmpeg-devel,1/2] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Nachiket Tarate Oct. 2, 2020, 1:10 p.m. UTC
This will be used by HLS demuxer for SAMPLE-AES decryption.

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

Comments

James Almer Oct. 2, 2020, 2:18 p.m. UTC | #1
On 10/2/2020 10:10 AM, Nachiket Tarate wrote:
> This will be used by HLS demuxer for SAMPLE-AES decryption.
> 
> Signed-off-by: Nachiket Tarate <nachiket.tarate@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];

Why not instead just make this array avpriv_? Everything else can be
done within libavformat. See mov_read_dec3() in mov.c

> +
> +    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 */
>
Nachiket Tarate Oct. 3, 2020, 5:30 p.m. UTC | #2
Actually names of 2 tables ff_ac3_sample_rate_tab and ff_ac3_channels_tab need to be changed in order to access them from libavformat.
There would be changes in multiple files in which these tables have been used currently. Is that fine ?
James Almer Oct. 3, 2020, 5:34 p.m. UTC | #3
On 10/3/2020 2:30 PM, Nachiket Tarate wrote:
> Actually names of 2 tables ff_ac3_sample_rate_tab and ff_ac3_channels_tab need to be changed in order to access them from libavformat.
> There would be changes in multiple files in which these tables have been used currently. Is that fine ?

You can use av_get_channel_layout_nb_channels() to get channel count
from the output of avpriv_ac3_channel_layout_tab[]. Same as
mov_read_dec3() in libavformat/mov.c does.

> 
> ________________________________
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> on behalf of James Almer <jamrial@gmail.com>
> Sent: Friday, October 2, 2020 7:48 PM
> To: ffmpeg-devel@ffmpeg.org <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] libavcodec/ac3_parser: add avpriv function to parse EC3SpecificBox (dec3)
> 
> On 10/2/2020 10:10 AM, Nachiket Tarate wrote:
>> This will be used by HLS demuxer for SAMPLE-AES decryption.
>>
>> Signed-off-by: Nachiket Tarate <nachiket.tarate@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];
> 
> Why not instead just make this array avpriv_? Everything else can be
> done within libavformat. See mov_read_dec3() in mov.c
> 
>> +
>> +    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 */
>>
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Nachiket Tarate Oct. 3, 2020, 9:12 p.m. UTC | #4
So you want me to change ff_ac3_sample_rate_tab to avpriv_ac3_sample_rate_tab and get channel count using av_get_channel_layout_nb_channels(). Is my understanding correct ?
James Almer Oct. 3, 2020, 9:37 p.m. UTC | #5
On 10/3/2020 6:12 PM, Nachiket Tarate wrote:
> So you want me to change ff_ac3_sample_rate_tab to avpriv_ac3_sample_rate_tab and get channel count using av_get_channel_layout_nb_channels(). Is my understanding correct ?

Yes.

Also please, don't top post in this list. Write below the paragraph
you're replying to.

> ________________________________
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> on behalf of James Almer <jamrial@gmail.com>
> Sent: Saturday, October 3, 2020 11:04 PM
> To: ffmpeg-devel@ffmpeg.org <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] libavcodec/ac3_parser: add avpriv function to parse EC3SpecificBox (dec3)
> 
> On 10/3/2020 2:30 PM, Nachiket Tarate wrote:
>> Actually names of 2 tables ff_ac3_sample_rate_tab and ff_ac3_channels_tab need to be changed in order to access them from libavformat.
>> There would be changes in multiple files in which these tables have been used currently. Is that fine ?
> 
> You can use av_get_channel_layout_nb_channels() to get channel count
> from the output of avpriv_ac3_channel_layout_tab[]. Same as
> mov_read_dec3() in libavformat/mov.c does.
> 
>>
>> ________________________________
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> on behalf of James Almer <jamrial@gmail.com>
>> Sent: Friday, October 2, 2020 7:48 PM
>> To: ffmpeg-devel@ffmpeg.org <ffmpeg-devel@ffmpeg.org>
>> Subject: Re: [FFmpeg-devel] [PATCH 2/2] libavcodec/ac3_parser: add avpriv function to parse EC3SpecificBox (dec3)
>>
>> On 10/2/2020 10:10 AM, Nachiket Tarate wrote:
>>> This will be used by HLS demuxer for SAMPLE-AES decryption.
>>>
>>> Signed-off-by: Nachiket Tarate <nachiket.tarate@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];
>>
>> Why not instead just make this array avpriv_? Everything else can be
>> done within libavformat. See mov_read_dec3() in mov.c
>>
>>> +
>>> +    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 */
>>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

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 */