Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/dpx_parser.c
Line
Count
Source
1
/*
2
 * DPX parser
3
 * Copyright (c) 2013 Paul B Mahol
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
/**
23
 * @file
24
 * DPX parser
25
 */
26
27
#include "libavutil/bswap.h"
28
#include "libavutil/common.h"
29
30
#include "parser.h"
31
#include "parser_internal.h"
32
33
typedef struct DPXParseContext {
34
    ParseContext pc;
35
    uint32_t index;
36
    uint32_t fsize;
37
    uint32_t remaining_size;
38
    int is_be;
39
} DPXParseContext;
40
41
static int dpx_parse(AVCodecParserContext *s, AVCodecContext *avctx,
42
                     const uint8_t **poutbuf, int *poutbuf_size,
43
                     const uint8_t *buf, int buf_size)
44
71.3k
{
45
71.3k
    DPXParseContext *d = s->priv_data;
46
71.3k
    uint32_t state = d->pc.state;
47
71.3k
    int next = END_NOT_FOUND;
48
71.3k
    int i = 0;
49
50
71.3k
    s->pict_type = AV_PICTURE_TYPE_I;
51
52
71.3k
    *poutbuf_size = 0;
53
71.3k
    if (buf_size == 0)
54
196
        next = 0;
55
56
71.3k
    if (!d->pc.frame_start_found) {
57
6.59M
        for (; i < buf_size; i++) {
58
6.54M
            state = (state << 8) | buf[i];
59
6.54M
            if (state == MKBETAG('S','D','P','X') ||
60
6.54M
                state == MKTAG('S','D','P','X')) {
61
5.27k
                d->pc.frame_start_found = 1;
62
5.27k
                d->is_be = state == MKBETAG('S','D','P','X');
63
5.27k
                d->index = 0;
64
5.27k
                break;
65
5.27k
            }
66
6.54M
        }
67
53.8k
        d->pc.state = state;
68
53.8k
    } else {
69
17.4k
        if (d->remaining_size) {
70
13.3k
            i = FFMIN(d->remaining_size, buf_size);
71
13.3k
            d->remaining_size -= i;
72
13.3k
            if (d->remaining_size)
73
10.7k
                goto flush;
74
13.3k
        }
75
17.4k
    }
76
77
14.4M
    for (; d->pc.frame_start_found && i < buf_size; i++) {
78
14.3M
        d->pc.state = (d->pc.state << 8) | buf[i];
79
14.3M
        d->index++;
80
14.3M
        if (d->index == 17) {
81
5.19k
            d->fsize = d->is_be ? d->pc.state : av_bswap32(d->pc.state);
82
5.19k
            if (d->fsize <= 1664) {
83
1.63k
                d->pc.frame_start_found = 0;
84
1.63k
                goto flush;
85
1.63k
            }
86
3.55k
            if (d->fsize > buf_size - i + 19)
87
2.92k
                d->remaining_size = d->fsize - buf_size + i - 19;
88
632
            else
89
632
                i += d->fsize - 19;
90
91
3.55k
            break;
92
14.3M
        } else if (d->index > 17) {
93
14.2M
            if (d->pc.state == MKBETAG('S','D','P','X') ||
94
14.2M
                d->pc.state == MKTAG('S','D','P','X')) {
95
3.15k
                next = i - 3;
96
3.15k
                break;
97
3.15k
            }
98
14.2M
        }
99
14.3M
    }
100
101
71.3k
flush:
102
71.3k
    if (ff_combine_frame(&d->pc, next, &buf, &buf_size) < 0)
103
67.9k
        return buf_size;
104
105
3.35k
    d->pc.frame_start_found = 0;
106
107
3.35k
    *poutbuf      = buf;
108
3.35k
    *poutbuf_size = buf_size;
109
3.35k
    return next;
110
71.3k
}
111
112
const FFCodecParser ff_dpx_parser = {
113
    PARSER_CODEC_LIST(AV_CODEC_ID_DPX),
114
    .priv_data_size = sizeof(DPXParseContext),
115
    .parse          = dpx_parse,
116
    .close          = ff_parse_close,
117
};