FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/prores_parser.c
Date: 2025-11-29 09:16:16
Exec Total Coverage
Lines: 47 63 74.6%
Functions: 1 1 100.0%
Branches: 14 26 53.8%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/intreadwrite.h"
20 #include "bytestream.h"
21
22 #include "avcodec.h"
23 #include "parser_internal.h"
24
25 1091 static int parse(AVCodecParserContext *s,
26 AVCodecContext *avctx,
27 const uint8_t **poutbuf, int *poutbuf_size,
28 const uint8_t *buf, int buf_size)
29 {
30 GetByteContext gb;
31 uint8_t flags, depth, chroma_format, alpha_channel_type;
32
33 1091 *poutbuf = buf;
34 1091 *poutbuf_size = buf_size;
35
36 /* Frame fields + frame header size */
37
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1052 times.
1091 if (buf_size < 28)
38 39 return buf_size;
39
40 1052 bytestream2_init(&gb, buf, buf_size);
41
42 /* Frame size */
43
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1052 times.
1052 if (bytestream2_get_be32(&gb) != buf_size)
44 return buf_size;
45
46 /* Frame identifier */
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1052 times.
1052 if (bytestream2_get_le32(&gb) != MKTAG('i','c','p','f'))
48 return buf_size;
49
50 /* Frame header size */
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1052 times.
1052 if (bytestream2_get_be16(&gb) < 20)
52 return buf_size;
53
54 1052 bytestream2_skip(&gb, 6); /* Bitstream version, encoder identifier */
55
56 1052 s->key_frame = 1;
57 1052 s->pict_type = AV_PICTURE_TYPE_I;
58
59 1052 s->width = bytestream2_get_be16(&gb);
60 1052 s->height = bytestream2_get_be16(&gb);
61 1052 s->coded_width = FFALIGN(s->width, 16);
62 1052 s->coded_height = FFALIGN(s->height, 16);
63
64 1052 flags = bytestream2_get_byte(&gb);
65
66 /* Interlace mode */
67
3/4
✓ Branch 0 taken 632 times.
✓ Branch 1 taken 400 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
1052 switch (flags >> 2 & 3) {
68 632 case 0:
69 632 s->field_order = AV_FIELD_PROGRESSIVE;
70 632 s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
71 632 break;
72 400 case 1:
73 400 s->field_order = AV_FIELD_TT;
74 400 s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
75 400 break;
76 20 case 2:
77 20 s->field_order = AV_FIELD_BB;
78 20 s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
79 20 break;
80 default:
81 break;
82 }
83
84 1052 bytestream2_skip(&gb, 4); /* Aspect ratio information, frame rate code, color primaries, transfer characteristic, matrix coefficients */
85
86 /* Determine pixel format based on color depth, chroma format and alpha type */
87
2/3
✓ Branch 0 taken 646 times.
✓ Branch 1 taken 406 times.
✗ Branch 2 not taken.
1052 switch (avctx->codec_tag) {
88 646 case MKTAG('a','p','c','o'):
89 case MKTAG('a','p','c','s'):
90 case MKTAG('a','p','c','n'):
91 case MKTAG('a','p','c','h'):
92 646 depth = 10;
93 646 break;
94 406 case MKTAG('a','p','4','h'):
95 case MKTAG('a','p','4','x'):
96 406 depth = 12;
97 406 break;
98 default:
99 return buf_size;
100 }
101
102 1052 chroma_format = flags >> 6 & 3;
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1052 times.
1052 if (chroma_format < 2)
104 return buf_size;
105
106 1052 alpha_channel_type = bytestream2_get_byte(&gb) & 0xf;
107
108
3/9
✓ Branch 0 taken 646 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 400 times.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
1052 switch (depth | (chroma_format << 4) | (alpha_channel_type << 8)) {
109 646 case 10 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P10; break;
110 case 10 | (2 << 4) | (1 << 8):
111 case 10 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P10; break;
112 case 10 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P10; break;
113 case 10 | (3 << 4) | (1 << 8):
114 case 10 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P10; break;
115 case 12 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P12; break;
116 case 12 | (2 << 4) | (1 << 8):
117 case 12 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P12; break;
118 400 case 12 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P12; break;
119 6 case 12 | (3 << 4) | (1 << 8):
120 6 case 12 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P12; break;
121 }
122
123 1052 return buf_size;
124 }
125
126 const FFCodecParser ff_prores_parser = {
127 PARSER_CODEC_LIST(AV_CODEC_ID_PRORES),
128 .parse = parse,
129 };
130