../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
47 / 63
74.6%
Branches:
14 / 26
53.8%
Functions:
1 / 1
100.0%

libavcodec/prores_parser.c
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 1102 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 1102 *poutbuf = buf;
34 1102 *poutbuf_size = buf_size;
35
36 /* Frame fields + frame header size */
37
2/2
✓ Branch 2 → 3 taken 42 times.
✓ Branch 2 → 4 taken 1060 times.
1102 if (buf_size < 28)
38 42 return buf_size;
39
40 1060 bytestream2_init(&gb, buf, buf_size);
41
42 /* Frame size */
43
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1060 times.
1060 if (bytestream2_get_be32(&gb) != buf_size)
44 ✗ return buf_size;
45
46 /* Frame identifier */
47
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 1060 times.
1060 if (bytestream2_get_le32(&gb) != MKTAG('i','c','p','f'))
48 ✗ return buf_size;
49
50 /* Frame header size */
51
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1060 times.
1060 if (bytestream2_get_be16(&gb) < 20)
52 ✗ return buf_size;
53
54 1060 bytestream2_skip(&gb, 6); /* Bitstream version, encoder identifier */
55
56 1060 s->key_frame = 1;
57 1060 s->pict_type = AV_PICTURE_TYPE_I;
58
59 1060 s->width = bytestream2_get_be16(&gb);
60 1060 s->height = bytestream2_get_be16(&gb);
61 1060 s->coded_width = FFALIGN(s->width, 16);
62 1060 s->coded_height = FFALIGN(s->height, 16);
63
64 1060 flags = bytestream2_get_byte(&gb);
65
66 /* Interlace mode */
67
3/4
✓ Branch 18 → 19 taken 634 times.
✓ Branch 18 → 20 taken 400 times.
✓ Branch 18 → 21 taken 26 times.
✗ Branch 18 → 22 not taken.
1060 switch (flags >> 2 & 3) {
68 634 case 0:
69 634 s->field_order = AV_FIELD_PROGRESSIVE;
70 634 s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
71 634 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 26 case 2:
77 26 s->field_order = AV_FIELD_BB;
78 26 s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
79 26 break;
80 ✗ default:
81 ✗ break;
82 }
83
84 1060 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 24 → 25 taken 654 times.
✓ Branch 24 → 26 taken 406 times.
✗ Branch 24 → 27 not taken.
1060 switch (avctx->codec_tag) {
88 654 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 654 depth = 10;
93 654 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 1060 chroma_format = flags >> 6 & 3;
103
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 1060 times.
1060 if (chroma_format < 2)
104 ✗ return buf_size;
105
106 1060 alpha_channel_type = bytestream2_get_byte(&gb) & 0xf;
107
108
3/9
✓ Branch 31 → 32 taken 654 times.
✗ Branch 31 → 33 not taken.
✗ Branch 31 → 34 not taken.
✗ Branch 31 → 35 not taken.
✗ Branch 31 → 36 not taken.
✗ Branch 31 → 37 not taken.
✓ Branch 31 → 38 taken 400 times.
✓ Branch 31 → 39 taken 6 times.
✗ Branch 31 → 40 not taken.
1060 switch (depth | (chroma_format << 4) | (alpha_channel_type << 8)) {
109 654 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 1060 return buf_size;
124 }
125
126 const FFCodecParser ff_prores_parser = {
127 PARSER_CODEC_LIST(AV_CODEC_ID_PRORES),
128 .parse = parse,
129 };
130