2
* MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
3
* Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
5
* This file is part of Libav.
7
* Libav is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* Libav is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with Libav; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "aacadtsdec.h"
26
#include "mpeg4audio.h"
29
typedef struct AACBSFContext {
34
* This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
35
* ADTS header and removes the ADTS header.
37
static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
38
AVCodecContext *avctx, const char *args,
39
uint8_t **poutbuf, int *poutbuf_size,
40
const uint8_t *buf, int buf_size,
45
AACADTSHeaderInfo hdr;
47
AACBSFContext *ctx = bsfc->priv_data;
49
init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8);
51
*poutbuf = (uint8_t*) buf;
52
*poutbuf_size = buf_size;
55
if (show_bits(&gb, 12) != 0xfff)
58
if (ff_aac_parse_header(&gb, &hdr) < 0) {
59
av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
63
if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
64
av_log_missing_feature(avctx, "Multiple RDBs per frame with CRC is", 0);
68
buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
69
buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
71
if (!ctx->first_frame_done) {
73
uint8_t pce_data[MAX_PCE_SIZE];
74
if (!hdr.chan_config) {
75
init_get_bits(&gb, buf, buf_size);
76
if (get_bits(&gb, 3) != 5) {
77
av_log_missing_feature(avctx, "PCE based channel configuration, where the PCE is not the first syntax element is", 0);
80
init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
81
pce_size = ff_copy_pce_data(&pb, &gb)/8;
83
buf_size -= get_bits_count(&gb)/8;
84
buf += get_bits_count(&gb)/8;
86
avctx->extradata_size = 2 + pce_size;
87
avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
89
init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
90
put_bits(&pb, 5, hdr.object_type);
91
put_bits(&pb, 4, hdr.sampling_index);
92
put_bits(&pb, 4, hdr.chan_config);
93
put_bits(&pb, 1, 0); //frame length - 1024 samples
94
put_bits(&pb, 1, 0); //does not depend on core coder
95
put_bits(&pb, 1, 0); //is not extension
98
memcpy(avctx->extradata + 2, pce_data, pce_size);
101
ctx->first_frame_done = 1;
104
*poutbuf = (uint8_t*) buf;
105
*poutbuf_size = buf_size;
110
AVBitStreamFilter ff_aac_adtstoasc_bsf = {
112
sizeof(AACBSFContext),
113
aac_adtstoasc_filter,