FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1_parser.c
Date: 2025-10-10 03:51:19
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 "rangecoder.h"
22
23 #include "libavutil/attributes.h"
24
25 typedef struct FFV1ParseContext {
26 FFV1Context f;
27 int got_first;
28 } FFV1ParseContext;
29
30 2099 static int parse(AVCodecParserContext *s,
31 AVCodecContext *avctx,
32 const uint8_t **poutbuf, int *poutbuf_size,
33 const uint8_t *buf, int buf_size)
34 {
35 2099 FFV1ParseContext *p = s->priv_data;
36 2099 FFV1Context *f = &p->f;
37 RangeCoder c;
38 2099 uint8_t keystate = 128;
39
40 2099 *poutbuf = buf;
41 2099 *poutbuf_size = buf_size;
42
43
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 2033 times.
2099 if (!p->got_first) {
44 66 int ret = ff_ffv1_common_init(avctx, f);
45 66 p->got_first = 1;
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (ret < 0)
47 return buf_size;
48
49
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)
50 return buf_size;
51 }
52
53 2099 ff_init_range_decoder(&c, buf, buf_size);
54 2099 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
55
56 2099 f->avctx = avctx;
57 2099 s->key_frame = get_rac(&c, &keystate);
58 2099 s->pict_type = AV_PICTURE_TYPE_I;
59 2099 s->field_order = AV_FIELD_UNKNOWN;
60 2099 s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
61
62
2/2
✓ Branch 0 taken 225 times.
✓ Branch 1 taken 1874 times.
2099 if (s->key_frame) {
63 uint8_t state[CONTEXT_SIZE];
64 225 memset(state, 128, sizeof(state));
65 225 ff_ffv1_parse_header(f, &c, state);
66 }
67
68 2099 s->width = f->width;
69 2099 s->height = f->height;
70 2099 s->format = f->pix_fmt;
71
72 2099 return buf_size;
73 }
74
75 67 static av_cold void ffv1_close(AVCodecParserContext *s)
76 {
77 67 FFV1ParseContext *p = s->priv_data;
78
79 67 p->f.avctx = NULL;
80 67 ff_ffv1_close(&p->f);
81 67 }
82
83 const AVCodecParser ff_ffv1_parser = {
84 .codec_ids = { AV_CODEC_ID_FFV1 },
85 .priv_data_size = sizeof(FFV1ParseContext),
86 .parser_parse = parse,
87 .parser_close = ffv1_close,
88 };
89