diff mbox series

[FFmpeg-devel] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header

Message ID SG2PR01MB2693EE79076DFB14994B4092F20B0@SG2PR01MB2693.apcprd01.prod.exchangelabs.com
State New
Headers show
Series [FFmpeg-devel] 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. 8, 2020, 2:32 p.m. UTC
These will be used by HLS demuxer in case of SAMPLE-AES encryption.

Signed-off-by: Nachiket Tarate <nachiket.tarate@outlook.com>
---
 libavcodec/adts_header.c |  1 +
 libavcodec/adts_header.h |  1 +
 libavcodec/adts_parser.c | 29 ++++++++++++++++++++++++++++-
 libavcodec/adts_parser.h |  4 ++++
 4 files changed, 34 insertions(+), 1 deletion(-)

Comments

Nachiket Tarate Oct. 9, 2020, 2:40 p.m. UTC | #1
@James Almer <jamrial@gmail.com>

Kindly merge this patch if it looks fine.


--
Thanks & Regards,
Nachiket Tarate
Andreas Rheinhardt Oct. 9, 2020, 2:41 p.m. UTC | #2
Nachiket Tarate:
> @James Almer <jamrial@gmail.com>
> 
> Kindly merge this patch if it looks fine.
> 

Can we see the supposed applications first?

- Andreas
Nachiket Tarate Oct. 15, 2020, 4:50 p.m. UTC | #3
@Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
@James Almer <jamrial@gmail.com>


Kindly merge this patch if it looks fine.

--
Best Regards,
Nachiket Tarate
diff mbox series

Patch

diff --git a/libavcodec/adts_header.c b/libavcodec/adts_header.c
index 0889820f8a..c6680b0fc8 100644
--- a/libavcodec/adts_header.c
+++ b/libavcodec/adts_header.c
@@ -66,6 +66,7 @@  int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
     hdr->sample_rate    = avpriv_mpeg4audio_sample_rates[sr];
     hdr->samples        = (rdb + 1) * 1024;
     hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
+    hdr->frame_length	= size;
 
     return size;
 }
diff --git a/libavcodec/adts_header.h b/libavcodec/adts_header.h
index f615f6a9f9..c362ce46a5 100644
--- a/libavcodec/adts_header.h
+++ b/libavcodec/adts_header.h
@@ -34,6 +34,7 @@  typedef struct AACADTSHeaderInfo {
     uint8_t  sampling_index;
     uint8_t  chan_config;
     uint8_t  num_aac_frames;
+    uint32_t frame_length;
 } AACADTSHeaderInfo;
 
 /**
diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
index 5c9f8ff6f2..7513b64181 100644
--- a/libavcodec/adts_parser.c
+++ b/libavcodec/adts_parser.c
@@ -21,7 +21,6 @@ 
 #include <stddef.h>
 #include <stdint.h>
 
-#include "adts_header.h"
 #include "adts_parser.h"
 
 int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
@@ -42,3 +41,31 @@  int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
     return AVERROR(ENOSYS);
 #endif
 }
+
+int avpriv_adts_header_parse (AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size)
+{
+#if CONFIG_ADTS_HEADER
+    int ret = 0;
+    GetBitContext gb;
+
+    if (size < AV_AAC_ADTS_HEADER_SIZE)
+        return AVERROR_INVALIDDATA;
+    
+    if (!*phdr)
+        *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
+    if (!*phdr)
+        return AVERROR(ENOMEM);
+    
+    ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
+    if (ret < 0)
+        return ret;
+
+    ret = ff_adts_header_parse(&gb, *phdr);
+    if (ret < 0)
+        return ret;
+        
+    return 0;
+#else
+    return AVERROR(ENOSYS);
+#endif
+}
diff --git a/libavcodec/adts_parser.h b/libavcodec/adts_parser.h
index f85becd131..faa6e47426 100644
--- a/libavcodec/adts_parser.h
+++ b/libavcodec/adts_parser.h
@@ -22,6 +22,8 @@ 
 #include <stddef.h>
 #include <stdint.h>
 
+#include "adts_header.h"
+
 #define AV_AAC_ADTS_HEADER_SIZE 7
 
 /**
@@ -34,4 +36,6 @@ 
 int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
                          uint8_t *frames);
 
+int avpriv_adts_header_parse (AACADTSHeaderInfo **phdr, const uint8_t *buf, size_t size);
+
 #endif /* AVCODEC_ADTS_PARSER_H */