FFmpeg: libavcodec/aac_ac3_parser.c Source File

FFmpeg
aac_ac3_parser.c
Go to the documentation of this file.
1 /*
2  * Common AAC and AC-3 parser
3  * Copyright (c) 2003 Fabrice Bellard
4  * Copyright (c) 2003 Michael Niedermayer
5  *
6  * This file is part of FFmpeg.
7  *
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.
12  *
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.
17  *
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
21  */
22 
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "parser.h"
26 #include "aac_ac3_parser.h"
27 
28  int ff_aac_ac3_parse(AVCodecParserContext *s1,
29  AVCodecContext *avctx,
30  const uint8_t **poutbuf, int *poutbuf_size,
31  const uint8_t *buf, int buf_size)
32 {
33  AACAC3ParseContext *s = s1->priv_data;
34  ParseContext *pc = &s->pc;
35  int len, i;
36  int new_frame_start;
37 
38 get_next:
39  i=END_NOT_FOUND;
40  if(s->remaining_size <= buf_size){
41  if(s->remaining_size && !s->need_next_header){
42  i= s->remaining_size;
43  s->remaining_size = 0;
44  }else{ //we need a header first
45  len=0;
46  for(i=s->remaining_size; i<buf_size; i++){
47  s->state = (s->state<<8) + buf[i];
48  if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
49  break;
50  }
51  if(len<=0){
52  i=END_NOT_FOUND;
53  }else{
54  s->state=0;
55  i-= s->header_size -1;
56  s->remaining_size = len;
57  if(!new_frame_start || pc->index+i<=0){
58  s->remaining_size += i;
59  goto get_next;
60  }
61  }
62  }
63  }
64 
65  if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
66  s->remaining_size -= FFMIN(s->remaining_size, buf_size);
67  *poutbuf = NULL;
68  *poutbuf_size = 0;
69  return buf_size;
70  }
71 
72  *poutbuf = buf;
73  *poutbuf_size = buf_size;
74 
75  /* update codec info */
76  if(s->codec_id)
77  avctx->codec_id = s->codec_id;
78 
79  /* Due to backwards compatible HE-AAC the sample rate, channel count,
80  and total number of samples found in an AAC ADTS header are not
81  reliable. Bit rate is still accurate because the total frame duration in
82  seconds is still correct (as is the number of bits in the frame). */
83  if (avctx->codec_id != AV_CODEC_ID_AAC) {
84  avctx->sample_rate = s->sample_rate;
85 
86  /* (E-)AC-3: allow downmixing to stereo or mono */
87 #if FF_API_REQUEST_CHANNELS
88 FF_DISABLE_DEPRECATION_WARNINGS
89  if (avctx->request_channels == 1)
90  avctx->request_channel_layout = AV_CH_LAYOUT_MONO;
91  else if (avctx->request_channels == 2)
92  avctx->request_channel_layout = AV_CH_LAYOUT_STEREO;
93 FF_ENABLE_DEPRECATION_WARNINGS
94 #endif
95  if (s->channels > 1 &&
96  avctx->request_channel_layout == AV_CH_LAYOUT_MONO) {
97  avctx->channels = 1;
98  avctx->channel_layout = AV_CH_LAYOUT_MONO;
99  } else if (s->channels > 2 &&
100  avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
101  avctx->channels = 2;
102  avctx->channel_layout = AV_CH_LAYOUT_STEREO;
103  } else {
104  avctx->channels = s->channels;
105  avctx->channel_layout = s->channel_layout;
106  }
107  s1->duration = s->samples;
108  avctx->audio_service_type = s->service_type;
109  }
110 
111  avctx->bit_rate = s->bit_rate;
112 
113  return i;
114 }
NULL
#define NULL
Definition: coverity.c:32
s
const char * s
Definition: avisynth_c.h:631
AACAC3ParseContext::channel_layout
uint64_t channel_layout
Definition: aac_ac3_parser.h:51
AVCodecContext::request_channels
attribute_deprecated int request_channels
Decoder should decode to this many channels if it can (0 for default)
Definition: avcodec.h:2038
AVCodecParserContext::duration
int duration
Duration of the current frame.
Definition: avcodec.h:4380
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
AVCodecContext::audio_service_type
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:2060
uint8_t
uint8_t
Definition: audio_convert.c:194
AACAC3ParseContext::sync
int(* sync)(uint64_t state, struct AACAC3ParseContext *hdr_info, int *need_next_header, int *new_frame_start)
Definition: aac_ac3_parser.h:44
ff_combine_frame
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
Definition: parser.c:231
AVCodecParserContext::priv_data
void * priv_data
Definition: avcodec.h:4248
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2046
AVCodecContext::bit_rate
int bit_rate
the average bitrate
Definition: avcodec.h:1305
channel_layout.h
audio channel layout utility functions
FFMIN
#define FFMIN(a, b)
Definition: common.h:66
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:1258
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1985
AVCodecContext
main external API structure.
Definition: avcodec.h:1241
buf
void * buf
Definition: avisynth_c.h:553
AACAC3ParseContext::pc
ParseContext pc
Definition: aac_ac3_parser.h:41
AACAC3ParseContext::codec_id
enum AVCodecID codec_id
Definition: aac_ac3_parser.h:58
s1
#define s1
Definition: regdef.h:38
END_NOT_FOUND
#define END_NOT_FOUND
Definition: parser.h:40
ff_aac_ac3_parse
int ff_aac_ac3_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: aac_ac3_parser.c:28
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
common.h
common internal and external API header
ParseContext::index
int index
Definition: parser.h:30
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
len
int len
Definition: vorbis_enc_data.h:452
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:1986
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
AVCodecContext::request_channel_layout
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
Definition: avcodec.h:2053

Generated on Wed Jun 10 2015 01:56:36 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /