Coverage Report

Created: 2026-07-25 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/prores_parser.c
Line
Count
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
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
81.4k
{
30
81.4k
    GetByteContext gb;
31
81.4k
    uint8_t flags, depth, chroma_format, alpha_channel_type;
32
33
81.4k
    *poutbuf      = buf;
34
81.4k
    *poutbuf_size = buf_size;
35
36
    /* Frame fields + frame header size */
37
81.4k
    if (buf_size < 28)
38
13.2k
        return buf_size;
39
40
68.2k
    bytestream2_init(&gb, buf, buf_size);
41
42
    /* Frame size */
43
68.2k
    if (bytestream2_get_be32(&gb) != buf_size)
44
61.8k
        return buf_size;
45
46
    /* Frame identifier */
47
6.32k
    if (bytestream2_get_le32(&gb) != MKTAG('i','c','p','f'))
48
245
        return buf_size;
49
50
    /* Frame header size */
51
6.07k
    if (bytestream2_get_be16(&gb) < 20)
52
331
        return buf_size;
53
54
5.74k
    bytestream2_skip(&gb, 6); /* Bitstream version, encoder identifier */
55
56
5.74k
    s->key_frame = 1;
57
5.74k
    s->pict_type = AV_PICTURE_TYPE_I;
58
59
5.74k
    s->width  = bytestream2_get_be16(&gb);
60
5.74k
    s->height = bytestream2_get_be16(&gb);
61
5.74k
    s->coded_width  = FFALIGN(s->width,  16);
62
5.74k
    s->coded_height = FFALIGN(s->height, 16);
63
64
5.74k
    flags = bytestream2_get_byte(&gb);
65
66
    /* Interlace mode */
67
5.74k
    switch (flags >> 2 & 3) {
68
806
        case 0:
69
806
            s->field_order       = AV_FIELD_PROGRESSIVE;
70
806
            s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
71
806
            break;
72
278
        case 1:
73
278
            s->field_order       = AV_FIELD_TT;
74
278
            s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
75
278
            break;
76
4.32k
        case 2:
77
4.32k
            s->field_order       = AV_FIELD_BB;
78
4.32k
            s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
79
4.32k
            break;
80
342
        default:
81
342
            break;
82
5.74k
    }
83
84
5.74k
    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
5.74k
    switch (avctx->codec_tag) {
88
38
        case MKTAG('a','p','c','o'):
89
40
        case MKTAG('a','p','c','s'):
90
43
        case MKTAG('a','p','c','n'):
91
79
        case MKTAG('a','p','c','h'):
92
79
            depth = 10;
93
79
            break;
94
3
        case MKTAG('a','p','4','h'):
95
3
        case MKTAG('a','p','4','x'):
96
3
            depth = 12;
97
3
            break;
98
5.66k
        default:
99
5.66k
            return buf_size;
100
5.74k
    }
101
102
82
    chroma_format = flags >> 6 & 3;
103
82
    if (chroma_format < 2)
104
16
        return buf_size;
105
106
66
    alpha_channel_type = bytestream2_get_byte(&gb) & 0xf;
107
108
66
    switch (depth | (chroma_format << 4) | (alpha_channel_type << 8)) {
109
62
        case 10 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P10;  break;
110
0
        case 10 | (2 << 4) | (1 << 8):
111
0
        case 10 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P10; break;
112
1
        case 10 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P10;  break;
113
0
        case 10 | (3 << 4) | (1 << 8):
114
0
        case 10 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P10; break;
115
0
        case 12 | (2 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV422P12;  break;
116
0
        case 12 | (2 << 4) | (1 << 8):
117
0
        case 12 | (2 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA422P12; break;
118
0
        case 12 | (3 << 4) | (0 << 8): s->format = AV_PIX_FMT_YUV444P12;  break;
119
0
        case 12 | (3 << 4) | (1 << 8):
120
3
        case 12 | (3 << 4) | (2 << 8): s->format = AV_PIX_FMT_YUVA444P12; break;
121
66
    }
122
123
66
    return buf_size;
124
66
}
125
126
const FFCodecParser ff_prores_parser = {
127
    PARSER_CODEC_LIST(AV_CODEC_ID_PRORES),
128
    .parse        = parse,
129
};