FFmpeg coverage


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