FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tak_parser.c
Date: 2026-01-16 07:34:38
Exec Total Coverage
Lines: 49 57 86.0%
Functions: 1 1 100.0%
Branches: 37 48 77.1%

Line Branch Exec Source
1 /*
2 * TAK parser
3 * Copyright (c) 2012 Michael Niedermayer
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * TAK parser
25 **/
26
27 #define CACHED_BITSTREAM_READER !ARCH_X86_32
28 #define BITSTREAM_READER_LE
29 #include "parser.h"
30 #include "parser_internal.h"
31 #include "tak.h"
32
33 typedef struct TAKParseContext {
34 ParseContext pc;
35 TAKStreamInfo ti;
36 int index;
37 } TAKParseContext;
38
39 1026 static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
40 const uint8_t **poutbuf, int *poutbuf_size,
41 const uint8_t *buf, int buf_size)
42 {
43 1026 TAKParseContext *t = s->priv_data;
44 1026 ParseContext *pc = &t->pc;
45 1026 int next = END_NOT_FOUND;
46 GetBitContext gb;
47 1026 int consumed = 0;
48
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 2 times.
1026 int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;
49 int ret;
50
51 1026 *poutbuf = buf;
52 1026 *poutbuf_size = buf_size;
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1026 times.
1026 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
55 TAKStreamInfo ti;
56 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
57 return buf_size;
58 if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
59 s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
60 : t->ti.frame_samples;
61 return buf_size;
62 }
63
64
4/4
✓ Branch 0 taken 27687 times.
✓ Branch 1 taken 990 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 989 times.
28677 while (buf_size || t->index + needed <= pc->index) {
65
3/4
✓ Branch 0 taken 27687 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 27687 times.
✗ Branch 3 not taken.
27688 if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {
66 27687 int tmp_buf_size = FFMIN(TAK_MAX_FRAME_HEADER_BYTES,
67 buf_size);
68 27687 const uint8_t *tmp_buf = buf;
69
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27687 times.
27687 if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1)
71 goto fail;
72 27687 consumed += tmp_buf_size;
73 27687 buf += tmp_buf_size;
74 27687 buf_size -= tmp_buf_size;
75 }
76
77
2/2
✓ Branch 0 taken 1010250 times.
✓ Branch 1 taken 27651 times.
1037901 for (; t->index + needed <= pc->index; t->index++) {
78
2/2
✓ Branch 0 taken 3663 times.
✓ Branch 1 taken 1006587 times.
1010250 if (pc->buffer[ t->index ] == 0xFF &&
79
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 3577 times.
3663 pc->buffer[ t->index + 1 ] == 0xA0) {
80 TAKStreamInfo ti;
81
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
86 if ((ret = init_get_bits8(&gb, pc->buffer + t->index,
83 86 pc->index - t->index)) < 0)
84 goto fail;
85
2/2
✓ Branch 1 taken 82 times.
✓ Branch 2 taken 4 times.
86 if (!ff_tak_decode_frame_header(avctx, &gb,
86
4/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 7 times.
168 pc->frame_start_found ? &ti : &t->ti, 127) &&
87 82 !ff_tak_check_crc(pc->buffer + t->index,
88 82 get_bits_count(&gb) / 8)) {
89
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 37 times.
75 if (!pc->frame_start_found) {
90 38 pc->frame_start_found = 1;
91 76 s->duration = t->ti.last_frame_samples ?
92
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
38 t->ti.last_frame_samples :
93 t->ti.frame_samples;
94 38 s->key_frame = !!(t->ti.flags & TAK_FRAME_FLAG_HAS_INFO);
95 } else {
96 37 pc->frame_start_found = 0;
97 37 next = t->index - pc->index;
98 37 t->index = 0;
99 37 goto found;
100 }
101 }
102 }
103 }
104 }
105 989 found:
106
107
7/8
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 990 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 987 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 39 times.
1065 if (consumed && !buf_size && next == END_NOT_FOUND ||
108 39 ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
109 987 goto fail;
110 }
111
112
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 2 times.
39 if (next != END_NOT_FOUND) {
113 37 next += consumed;
114 37 pc->overread = FFMAX(0, -next);
115 }
116
117 39 *poutbuf = buf;
118 39 *poutbuf_size = buf_size;
119 39 return next;
120
121 987 fail:
122 987 *poutbuf = NULL;
123 987 *poutbuf_size = 0;
124 987 return buf_size + consumed;
125 }
126
127 const FFCodecParser ff_tak_parser = {
128 PARSER_CODEC_LIST(AV_CODEC_ID_TAK),
129 .priv_data_size = sizeof(TAKParseContext),
130 .parse = tak_parse,
131 .close = ff_parse_close,
132 };
133