Coverage Report

Created: 2025-12-31 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/ffv1_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 "avcodec.h"
20
#include "ffv1.h"
21
#include "parser_internal.h"
22
#include "rangecoder.h"
23
24
#include "libavutil/attributes.h"
25
26
typedef struct FFV1ParseContext {
27
    FFV1Context f;
28
    int got_first;
29
} FFV1ParseContext;
30
31
static int parse(AVCodecParserContext *s,
32
                 AVCodecContext *avctx,
33
                 const uint8_t **poutbuf, int *poutbuf_size,
34
                 const uint8_t *buf, int buf_size)
35
49.8k
{
36
49.8k
    FFV1ParseContext *p = s->priv_data;
37
49.8k
    FFV1Context *f = &p->f;
38
49.8k
    RangeCoder c;
39
49.8k
    uint8_t keystate = 128;
40
41
49.8k
    *poutbuf      = buf;
42
49.8k
    *poutbuf_size = buf_size;
43
44
49.8k
    if (!p->got_first) {
45
1.08k
        int ret = ff_ffv1_common_init(avctx, f);
46
1.08k
        p->got_first = 1;
47
1.08k
        if (ret < 0)
48
1.08k
            return buf_size;
49
50
0
        if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0)
51
0
            return buf_size;
52
0
    }
53
54
48.7k
    ff_init_range_decoder(&c, buf, buf_size);
55
48.7k
    ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
56
57
48.7k
    f->avctx = avctx;
58
48.7k
    s->key_frame = get_rac(&c, &keystate);
59
48.7k
    s->pict_type = AV_PICTURE_TYPE_I;
60
48.7k
    s->field_order = AV_FIELD_UNKNOWN;
61
48.7k
    s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
62
63
48.7k
    if (s->key_frame) {
64
31.7k
        uint8_t state[CONTEXT_SIZE];
65
31.7k
        memset(state, 128, sizeof(state));
66
31.7k
        ff_ffv1_parse_header(f, &c, state);
67
31.7k
    }
68
69
48.7k
    s->width  = f->width;
70
48.7k
    s->height = f->height;
71
48.7k
    s->format = f->pix_fmt;
72
73
48.7k
    return buf_size;
74
49.8k
}
75
76
static av_cold void ffv1_close(AVCodecParserContext *s)
77
1.22k
{
78
1.22k
    FFV1ParseContext *p = s->priv_data;
79
80
    p->f.avctx = NULL;
81
1.22k
    ff_ffv1_close(&p->f);
82
1.22k
}
83
84
const FFCodecParser ff_ffv1_parser = {
85
    PARSER_CODEC_LIST(AV_CODEC_ID_FFV1),
86
    .priv_data_size = sizeof(FFV1ParseContext),
87
    .parse          = parse,
88
    .close          = ffv1_close,
89
};