annotate aac_adtstoasc_bsf.c @ 9976:e52cd349e708 libavcodec

Only compile in NEON optimizations for H.264 when the H.264 decoder is enabled.
author diego
date Wed, 22 Jul 2009 22:33:33 +0000
parents 7ad7d4094d1f
children d5339724d6ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9788
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
1 /*
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
2 * MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
3 * Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
4 *
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
5 * This file is part of FFmpeg.
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
6 *
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
11 *
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
15 * Lesser General Public License for more details.
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
16 *
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
20 */
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
21
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
22 #include "avcodec.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
23 #include "aac_parser.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
24 #include "put_bits.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
25 #include "get_bits.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
26 #include "mpeg4audio.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
27 #include "internal.h"
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
28
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
29 typedef struct AACBSFContext {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
30 int first_frame_done;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
31 } AACBSFContext;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
32
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
33 /**
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
34 * This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
35 * ADTS header and removes the ADTS header.
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
36 */
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
37 static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
38 AVCodecContext *avctx, const char *args,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
39 uint8_t **poutbuf, int *poutbuf_size,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
40 const uint8_t *buf, int buf_size,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
41 int keyframe)
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
42 {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
43 GetBitContext gb;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
44 PutBitContext pb;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
45 AACADTSHeaderInfo hdr;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
46
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
47 AACBSFContext *ctx = bsfc->priv_data;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
48
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
49 init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
50
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
51 *poutbuf = (uint8_t*) buf;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
52 *poutbuf_size = buf_size;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
53
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
54 if (avctx->extradata)
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
55 if (show_bits(&gb, 12) != 0xfff)
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
56 return 0;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
57
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
58 if (ff_aac_parse_header(&gb, &hdr) < 0) {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
59 av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
60 return -1;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
61 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
62
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
63 if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9788
diff changeset
64 av_log_missing_feature(avctx, "Multiple RDBs per frame with CRC is", 0);
9788
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
65 return -1;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
66 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
67
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
68 buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
69 buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
70
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
71 if (!ctx->first_frame_done) {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
72 int pce_size = 0;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
73 uint8_t pce_data[MAX_PCE_SIZE];
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
74 if (!hdr.chan_config) {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
75 init_get_bits(&gb, buf, buf_size);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
76 if (get_bits(&gb, 3) != 5) {
9891
7ad7d4094d1f Rename ff_log_missing_feature() to av_log_missing_feature().
rbultje
parents: 9788
diff changeset
77 av_log_missing_feature(avctx, "PCE based channel configuration, where the PCE is not the first syntax element is", 0);
9788
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
78 return -1;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
79 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
80 init_put_bits(&pb, pce_data, MAX_PCE_SIZE);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
81 pce_size = ff_copy_pce_data(&pb, &gb)/8;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
82 flush_put_bits(&pb);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
83 buf_size -= get_bits_count(&gb)/8;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
84 buf += get_bits_count(&gb)/8;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
85 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
86 avctx->extradata_size = 2 + pce_size;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
87 avctx->extradata = av_malloc(avctx->extradata_size);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
88
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
89 init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
90 put_bits(&pb, 5, hdr.object_type);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
91 put_bits(&pb, 4, hdr.sampling_index);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
92 put_bits(&pb, 4, hdr.chan_config);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
93 put_bits(&pb, 1, 0); //frame length - 1024 samples
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
94 put_bits(&pb, 1, 0); //does not depend on core coder
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
95 put_bits(&pb, 1, 0); //is not extension
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
96 flush_put_bits(&pb);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
97 if (pce_size) {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
98 memcpy(avctx->extradata + 2, pce_data, pce_size);
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
99 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
100
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
101 ctx->first_frame_done = 1;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
102 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
103
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
104 *poutbuf = (uint8_t*) buf;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
105 *poutbuf_size = buf_size;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
106
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
107 return 0;
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
108 }
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
109
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
110 AVBitStreamFilter aac_adtstoasc_bsf = {
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
111 "aac_adtstoasc",
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
112 sizeof(AACBSFContext),
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
113 aac_adtstoasc_filter,
b9563486a234 AAC ADTS to AudioSpecificConfig bitstream filter
alexc
parents:
diff changeset
114 };