aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavcodec / aac_ac3_parser.c
CommitLineData
99ff31dc 1/*
14b70628 2 * Common AAC and AC-3 parser
406792e7
DB
3 * Copyright (c) 2003 Fabrice Bellard
4 * Copyright (c) 2003 Michael Niedermayer
99ff31dc 5 *
2912e87a 6 * This file is part of Libav.
99ff31dc 7 *
2912e87a 8 * Libav is free software; you can redistribute it and/or
99ff31dc
AJ
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 *
2912e87a 13 * Libav is distributed in the hope that it will be useful,
99ff31dc
AJ
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
2912e87a 19 * License along with Libav; if not, write to the Free Software
99ff31dc
AJ
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
b5328546 23#include "libavutil/channel_layout.h"
1d9c2dc8 24#include "libavutil/common.h"
99ff31dc
AJ
25#include "parser.h"
26#include "aac_ac3_parser.h"
27
679c2294 28int ff_aac_ac3_parse(AVCodecParserContext *s1,
99ff31dc
AJ
29 AVCodecContext *avctx,
30 const uint8_t **poutbuf, int *poutbuf_size,
31 const uint8_t *buf, int buf_size)
32{
679c2294 33 AACAC3ParseContext *s = s1->priv_data;
454064ad
MN
34 ParseContext *pc = &s->pc;
35 int len, i;
133ac890 36 int new_frame_start;
99ff31dc 37
8629e756 38get_next:
454064ad
MN
39 i=END_NOT_FOUND;
40 if(s->remaining_size <= buf_size){
8629e756 41 if(s->remaining_size && !s->need_next_header){
454064ad
MN
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];
133ac890 48 if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
454064ad
MN
49 break;
50 }
51 if(len<=0){
52 i=END_NOT_FOUND;
53 }else{
bf2cdefc 54 s->state=0;
454064ad 55 i-= s->header_size -1;
e4d5a185 56 s->remaining_size = len;
8dbd9cb6 57 if(!new_frame_start || pc->index+i<=0){
8870cf82 58 s->remaining_size += i;
8629e756 59 goto get_next;
8870cf82 60 }
454064ad
MN
61 }
62 }
63 }
99ff31dc 64
454064ad
MN
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 }
469d8816 71
454064ad
MN
72 *poutbuf = buf;
73 *poutbuf_size = buf_size;
211dd1e8 74
7bc5f6e5 75 /* update codec info */
4cff8dc8
JP
76 if(s->codec_id)
77 avctx->codec_id = s->codec_id;
78
ca1fa414
AC
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). */
36ef5369 83 if (avctx->codec_id != AV_CODEC_ID_AAC) {
ca1fa414 84 avctx->sample_rate = s->sample_rate;
dd3aa85b
VG
85 avctx->channels = s->channels;
86 avctx->channel_layout = s->channel_layout;
16e54ac7 87 s1->duration = s->samples;
be187388 88 avctx->audio_service_type = s->service_type;
ca1fa414
AC
89 }
90
91 avctx->bit_rate = s->bit_rate;
454064ad
MN
92
93 return i;
99ff31dc 94}