summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2017-04-26 18:57:54 +0200
committerDiego Biurrun <diego@biurrun.de>2017-05-02 18:50:34 +0200
commitb5f19f7478492307e4b4763aeac3180faf50e17f (patch)
tree0fb69992023b946295a3130e2066256e3caf88fe /libavformat
parent0ac1fec1c3dacedabbf3dd4122ef4bf8523e688c (diff)
aac: Split function to parse ADTS header data into public and private part
This makes the currently semi-public avpriv_aac_parse_header() function private to libavcodec and adds a proper public API function to return the parts of the ADTS header required in libavformat.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/spdifdec.c24
-rw-r--r--libavformat/spdifenc.c17
2 files changed, 22 insertions, 19 deletions
diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c
index 7c212353f1..38692c27e6 100644
--- a/libavformat/spdifdec.c
+++ b/libavformat/spdifdec.c
@@ -25,18 +25,22 @@
* @author Anssi Hannula
*/
+#include "libavutil/bswap.h"
+
+#include "libavcodec/ac3.h"
+#include "libavcodec/adts_parser.h"
+
#include "avformat.h"
#include "spdif.h"
-#include "libavcodec/ac3.h"
-#include "libavcodec/aacadtsdec.h"
static int spdif_get_offset_and_codec(AVFormatContext *s,
enum IEC61937DataType data_type,
const char *buf, int *offset,
enum AVCodecID *codec)
{
- AACADTSHeaderInfo aac_hdr;
- GetBitContext gbc;
+ uint32_t samples;
+ uint8_t frames;
+ int ret;
switch (data_type & 0xff) {
case IEC61937_AC3:
@@ -56,13 +60,13 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
*codec = AV_CODEC_ID_MP3;
break;
case IEC61937_MPEG2_AAC:
- init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);
- if (avpriv_aac_parse_header(&gbc, &aac_hdr)) {
+ ret = av_adts_header_parse(buf, &samples, &frames);
+ if (ret < 0) {
if (s) /* be silent during a probe */
av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");
- return AVERROR_INVALIDDATA;
+ return ret;
}
- *offset = aac_hdr.samples << 2;
+ *offset = samples << 2;
*codec = AV_CODEC_ID_AAC;
break;
case IEC61937_MPEG2_LAYER1_LSF:
@@ -100,7 +104,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
}
/* Largest offset between bursts we currently handle, i.e. AAC with
- aac_hdr.samples = 4096 */
+ samples = 4096 */
#define SPDIF_MAX_OFFSET 16384
static int spdif_probe(AVProbeData *p)
@@ -127,7 +131,7 @@ static int spdif_probe(AVProbeData *p)
} else
consecutive_codes = 0;
- if (buf + 4 + AAC_ADTS_HEADER_SIZE > p->buf + p->buf_size)
+ if (buf + 4 + AV_AAC_ADTS_HEADER_SIZE > p->buf + p->buf_size)
break;
/* continue probing to find more sync codes */
diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index a9b3b522b3..6497a82734 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -50,9 +50,9 @@
#include "avio_internal.h"
#include "spdif.h"
#include "libavcodec/ac3.h"
+#include "libavcodec/adts_parser.h"
#include "libavcodec/dca.h"
#include "libavcodec/dca_syncwords.h"
-#include "libavcodec/aacadtsdec.h"
#include "libavutil/opt.h"
typedef struct IEC61937Context {
@@ -349,19 +349,18 @@ static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
{
IEC61937Context *ctx = s->priv_data;
- AACADTSHeaderInfo hdr;
- GetBitContext gbc;
+ uint32_t samples;
+ uint8_t frames;
int ret;
- init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
- ret = avpriv_aac_parse_header(&gbc, &hdr);
+ ret = av_adts_header_parse(pkt->data, &samples, &frames);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
- return AVERROR_INVALIDDATA;
+ return ret;
}
- ctx->pkt_offset = hdr.samples << 2;
- switch (hdr.num_aac_frames) {
+ ctx->pkt_offset = samples << 2;
+ switch (frames) {
case 1:
ctx->data_type = IEC61937_MPEG2_AAC;
break;
@@ -373,7 +372,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
break;
default:
av_log(s, AV_LOG_ERROR,
- "%"PRIu32" samples in AAC frame not supported\n", hdr.samples);
+ "%"PRIu32" samples in AAC frame not supported\n", samples);
return AVERROR(EINVAL);
}
//TODO Data type dependent info (LC profile/SBR)