FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac_ac3_parser.c
Date: 2022-07-04 19:11:22
Exec Total Coverage
Lines: 50 53 94.3%
Branches: 30 32 93.8%

Line Branch Exec Source
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 "config_components.h"
24
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/common.h"
27 #include "parser.h"
28 #include "aac_ac3_parser.h"
29
30 14890 int ff_aac_ac3_parse(AVCodecParserContext *s1,
31 AVCodecContext *avctx,
32 const uint8_t **poutbuf, int *poutbuf_size,
33 const uint8_t *buf, int buf_size)
34 {
35 14890 AACAC3ParseContext *s = s1->priv_data;
36 14890 ParseContext *pc = &s->pc;
37 int len, i;
38 int new_frame_start;
39 14890 int got_frame = 0;
40
41 21039 get_next:
42 21039 i=END_NOT_FOUND;
43
2/2
✓ Branch 0 taken 17769 times.
✓ Branch 1 taken 3270 times.
21039 if(s->remaining_size <= buf_size){
44
4/4
✓ Branch 0 taken 10243 times.
✓ Branch 1 taken 7526 times.
✓ Branch 2 taken 5770 times.
✓ Branch 3 taken 4473 times.
17769 if(s->remaining_size && !s->need_next_header){
45 5770 i= s->remaining_size;
46 5770 s->remaining_size = 0;
47 }else{ //we need a header first
48 11999 len=0;
49
2/2
✓ Branch 0 taken 72938 times.
✓ Branch 1 taken 1719 times.
74657 for(i=s->remaining_size; i<buf_size; i++){
50 72938 s->state = (s->state<<8) + buf[i];
51
2/2
✓ Branch 1 taken 10280 times.
✓ Branch 2 taken 62658 times.
72938 if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
52 10280 break;
53 }
54
2/2
✓ Branch 0 taken 1719 times.
✓ Branch 1 taken 10280 times.
11999 if(len<=0){
55 1719 i=END_NOT_FOUND;
56 }else{
57 10280 got_frame = 1;
58 10280 s->state=0;
59 10280 i-= s->header_size -1;
60 10280 s->remaining_size = len;
61
4/4
✓ Branch 0 taken 9966 times.
✓ Branch 1 taken 314 times.
✓ Branch 2 taken 5835 times.
✓ Branch 3 taken 4131 times.
10280 if(!new_frame_start || pc->index+i<=0){
62 6149 s->remaining_size += i;
63 6149 goto get_next;
64 }
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4131 times.
4131 else if (i < 0) {
66 s->remaining_size += i;
67 }
68 }
69 }
70 }
71
72
2/2
✓ Branch 1 taken 4844 times.
✓ Branch 2 taken 10046 times.
14890 if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
73 4844 s->remaining_size -= FFMIN(s->remaining_size, buf_size);
74 4844 *poutbuf = NULL;
75 4844 *poutbuf_size = 0;
76 4844 return buf_size;
77 }
78
79 10046 *poutbuf = buf;
80 10046 *poutbuf_size = buf_size;
81
82 /* update codec info */
83
2/2
✓ Branch 0 taken 4243 times.
✓ Branch 1 taken 5803 times.
10046 if(s->codec_id)
84 4243 avctx->codec_id = s->codec_id;
85
86
2/2
✓ Branch 0 taken 9901 times.
✓ Branch 1 taken 145 times.
10046 if (got_frame) {
87 /* Due to backwards compatible HE-AAC the sample rate, channel count,
88 and total number of samples found in an AAC ADTS header are not
89 reliable. Bit rate is still accurate because the total frame
90 duration in seconds is still correct (as is the number of bits in
91 the frame). */
92
2/2
✓ Branch 0 taken 4131 times.
✓ Branch 1 taken 5770 times.
9901 if (avctx->codec_id != AV_CODEC_ID_AAC) {
93 4131 avctx->sample_rate = s->sample_rate;
94
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 2643 times.
4131 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
95 1488 av_channel_layout_uninit(&avctx->ch_layout);
96
1/2
✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
1488 if (s->channel_layout) {
97 1488 av_channel_layout_from_mask(&avctx->ch_layout, s->channel_layout);
98 } else {
99 avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
100 avctx->ch_layout.nb_channels = s->channels;
101 }
102 #if FF_API_OLD_CHANNEL_LAYOUT
103 FF_DISABLE_DEPRECATION_WARNINGS
104 1488 avctx->channels = avctx->ch_layout.nb_channels;
105 1488 avctx->channel_layout = s->channel_layout;
106 FF_ENABLE_DEPRECATION_WARNINGS
107 #endif
108 }
109 4131 s1->duration = s->samples;
110 4131 avctx->audio_service_type = s->service_type;
111 }
112
113 /* Calculate the average bit rate */
114 9901 s->frame_number++;
115
2/2
✓ Branch 0 taken 7258 times.
✓ Branch 1 taken 2643 times.
9901 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
116 7258 avctx->bit_rate +=
117 7258 (s->bit_rate - avctx->bit_rate) / s->frame_number;
118 }
119 }
120
121 10046 return i;
122 }
123