FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aac_ac3_parser.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 47 48 97.9%
Branches: 29 30 96.7%

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 "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "parser.h"
26 #include "aac_ac3_parser.h"
27
28 14804 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 14804 AACAC3ParseContext *s = s1->priv_data;
34 14804 ParseContext *pc = &s->pc;
35 int len, i;
36 int new_frame_start;
37 14804 int got_frame = 0;
38
39 20941 get_next:
40 20941 i=END_NOT_FOUND;
41
2/2
✓ Branch 0 taken 17696 times.
✓ Branch 1 taken 3245 times.
20941 if(s->remaining_size <= buf_size){
42
4/4
✓ Branch 0 taken 10206 times.
✓ Branch 1 taken 7490 times.
✓ Branch 2 taken 5770 times.
✓ Branch 3 taken 4436 times.
17696 if(s->remaining_size && !s->need_next_header){
43 5770 i= s->remaining_size;
44 5770 s->remaining_size = 0;
45 }else{ //we need a header first
46 11926 len=0;
47
2/2
✓ Branch 0 taken 72616 times.
✓ Branch 1 taken 1692 times.
74308 for(i=s->remaining_size; i<buf_size; i++){
48 72616 s->state = (s->state<<8) + buf[i];
49
2/2
✓ Branch 1 taken 10234 times.
✓ Branch 2 taken 62382 times.
72616 if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
50 10234 break;
51 }
52
2/2
✓ Branch 0 taken 1692 times.
✓ Branch 1 taken 10234 times.
11926 if(len<=0){
53 1692 i=END_NOT_FOUND;
54 }else{
55 10234 got_frame = 1;
56 10234 s->state=0;
57 10234 i-= s->header_size -1;
58 10234 s->remaining_size = len;
59
4/4
✓ Branch 0 taken 9920 times.
✓ Branch 1 taken 314 times.
✓ Branch 2 taken 5823 times.
✓ Branch 3 taken 4097 times.
10234 if(!new_frame_start || pc->index+i<=0){
60 6137 s->remaining_size += i;
61 6137 goto get_next;
62 }
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4097 times.
4097 else if (i < 0) {
64 s->remaining_size += i;
65 }
66 }
67 }
68 }
69
70
2/2
✓ Branch 1 taken 4808 times.
✓ Branch 2 taken 9996 times.
14804 if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
71 4808 s->remaining_size -= FFMIN(s->remaining_size, buf_size);
72 4808 *poutbuf = NULL;
73 4808 *poutbuf_size = 0;
74 4808 return buf_size;
75 }
76
77 9996 *poutbuf = buf;
78 9996 *poutbuf_size = buf_size;
79
80 /* update codec info */
81
2/2
✓ Branch 0 taken 4193 times.
✓ Branch 1 taken 5803 times.
9996 if(s->codec_id)
82 4193 avctx->codec_id = s->codec_id;
83
84
2/2
✓ Branch 0 taken 9867 times.
✓ Branch 1 taken 129 times.
9996 if (got_frame) {
85 /* Due to backwards compatible HE-AAC the sample rate, channel count,
86 and total number of samples found in an AAC ADTS header are not
87 reliable. Bit rate is still accurate because the total frame
88 duration in seconds is still correct (as is the number of bits in
89 the frame). */
90
2/2
✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 5770 times.
9867 if (avctx->codec_id != AV_CODEC_ID_AAC) {
91 4097 avctx->sample_rate = s->sample_rate;
92
2/2
✓ Branch 0 taken 1454 times.
✓ Branch 1 taken 2643 times.
4097 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
93 1454 avctx->channels = s->channels;
94 1454 avctx->channel_layout = s->channel_layout;
95 }
96 4097 s1->duration = s->samples;
97 4097 avctx->audio_service_type = s->service_type;
98 }
99
100 /* Calculate the average bit rate */
101 9867 s->frame_number++;
102
2/2
✓ Branch 0 taken 7224 times.
✓ Branch 1 taken 2643 times.
9867 if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
103 7224 avctx->bit_rate +=
104 7224 (s->bit_rate - avctx->bit_rate) / s->frame_number;
105 }
106 }
107
108 9996 return i;
109 }
110