FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1_parser.c
Date: 2026-01-14 03:33:33
Exec Total Coverage
Lines: 30 32 93.8%
Functions: 2 2 100.0%
Branches: 8 10 80.0%

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 "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 2099 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 {
36 2099 FFV1ParseContext *p = s->priv_data;
37 2099 FFV1Context *f = &p->f;
38 RangeCoder c;
39 2099 uint8_t keystate = 128;
40
41 2099 *poutbuf = buf;
42 2099 *poutbuf_size = buf_size;
43
44
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 2033 times.
2099 if (!p->got_first) {
45 66 int ret = ff_ffv1_common_init(avctx, f);
46 66 p->got_first = 1;
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (ret < 0)
48 return buf_size;
49
50
3/4
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
66 if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0)
51 return buf_size;
52 }
53
54 2099 ff_init_range_decoder(&c, buf, buf_size);
55 2099 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
56
57 2099 f->avctx = avctx;
58 2099 s->key_frame = get_rac(&c, &keystate);
59 2099 s->pict_type = AV_PICTURE_TYPE_I;
60 2099 s->field_order = AV_FIELD_UNKNOWN;
61 2099 s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
62
63
2/2
✓ Branch 0 taken 225 times.
✓ Branch 1 taken 1874 times.
2099 if (s->key_frame) {
64 uint8_t state[CONTEXT_SIZE];
65 225 memset(state, 128, sizeof(state));
66 225 ff_ffv1_parse_header(f, &c, state);
67 }
68
69 2099 s->width = f->width;
70 2099 s->height = f->height;
71 2099 s->format = f->pix_fmt;
72
73 2099 return buf_size;
74 }
75
76 67 static av_cold void ffv1_close(AVCodecParserContext *s)
77 {
78 67 FFV1ParseContext *p = s->priv_data;
79
80 67 p->f.avctx = NULL;
81 67 ff_ffv1_close(&p->f);
82 67 }
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 };
90