2 * Common AAC and AC-3 parser
3 * Copyright (c) 2003 Fabrice Bellard
4 * Copyright (c) 2003 Michael Niedermayer
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23#include "config_components.h"
34 const uint8_t **poutbuf,
int *poutbuf_size,
35 const uint8_t *buf,
int buf_size)
51 if(
s->remaining_size <= buf_size){
52 if(
s->remaining_size && !
s->need_next_header){
54 s->remaining_size = 0;
55 }
else{
//we need a header first
57 for(
i=
s->remaining_size;
i<buf_size;
i++){
58 s->state = (
s->state<<8) + buf[
i];
59 if((
len=
s->sync(
s->state, &
s->need_next_header, &new_frame_start)))
67 i-=
s->header_size -1;
68 s->remaining_size =
len;
69 if(!new_frame_start || pc->
index+
i<=0){
70 s->remaining_size +=
i;
74 s->remaining_size +=
i;
81 s->remaining_size -=
FFMIN(
s->remaining_size, buf_size);
89 *poutbuf_size = buf_size;
94 /* Due to backwards compatible HE-AAC the sample rate, channel count,
95 and total number of samples found in an AAC ADTS header are not
96 reliable. Bit rate is still accurate because the total frame
97 duration in seconds is still correct (as is the number of bits in
109 while (buf_size > 0) {
112 if (ret < 0 || hdr.frame_size > buf_size)
120 /* Check for false positives since the syncword is not enough.
121 See section 6.1.2 of A/52. */
157 /* ADTS does not support USAC */
163 /* Calculate the average bit rate */
167 (bit_rate - avctx->
bit_rate) /
s->frame_number;
int ff_aac_ac3_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf, size_t size)
int ff_ac3_find_syncword(const uint8_t *buf, int buf_size)
#define AV_AAC_ADTS_HEADER_SIZE
#define PARSER_FLAG_COMPLETE_FRAMES
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
#define AV_PROFILE_UNKNOWN
@ AV_AUDIO_SERVICE_TYPE_KARAOKE
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
int duration
Duration of the current frame.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.