[FFmpeg-devel] [PATCH] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header
Nachiket Tarate
nachiket.tarate at outlook.com
Thu Oct 15 19:50:53 EEST 2020
@Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
@James Almer <jamrial at gmail.com>
Kindly merge this patch if it looks fine.
--
Best Regards,
Nachiket Tarate
________________________________
From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> on behalf of Nachiket Tarate <nachiket.tarate at outlook.com>
Sent: Thursday, October 8, 2020 8:02 PM
To: ffmpeg-devel at ffmpeg.org <ffmpeg-devel at ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] libavcodec/adts_header: add frame_length field and avpriv function to parse AAC ADTS header
These will be used by HLS demuxer in case of SAMPLE-AES encryption.
Signed-off-by: Nachiket Tarate <nachiket.tarate at 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(-)
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 */
--
2.17.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list