Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/hdr_parser.c
Line
Count
Source
1
/*
2
 * Radiance HDR parser
3
 * Copyright (c) 2022 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
 * Radiance HDR parser
25
 */
26
27
#include "libavutil/intreadwrite.h"
28
#include "parser.h"
29
#include "parser_internal.h"
30
31
typedef struct HDRParseContext {
32
    ParseContext pc;
33
} HDRParseContext;
34
35
static int hdr_parse(AVCodecParserContext *s, AVCodecContext *avctx,
36
                     const uint8_t **poutbuf, int *poutbuf_size,
37
                     const uint8_t *buf, int buf_size)
38
530k
{
39
530k
    HDRParseContext *ipc = s->priv_data;
40
530k
    uint64_t state = ipc->pc.state64;
41
530k
    int next = END_NOT_FOUND, i = 0;
42
43
530k
    *poutbuf_size = 0;
44
530k
    *poutbuf = NULL;
45
46
530k
    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
47
0
        next = buf_size;
48
530k
    } else {
49
38.2M
        for (; i < buf_size; i++) {
50
37.9M
            state = (state << 8) | buf[i];
51
37.9M
            if (state == AV_RB64("ADIANCE\n") && (i > 10 || ipc->pc.index > 10)) {
52
248k
                next = i - 10;
53
248k
                break;
54
248k
            }
55
37.9M
        }
56
57
530k
        ipc->pc.state64 = state;
58
530k
        if (ff_combine_frame(&ipc->pc, next, &buf, &buf_size) < 0) {
59
281k
            *poutbuf = NULL;
60
281k
            *poutbuf_size = 0;
61
281k
            return buf_size;
62
281k
        }
63
530k
    }
64
65
248k
    *poutbuf      = buf;
66
248k
    *poutbuf_size = buf_size;
67
68
248k
    s->pict_type = AV_PICTURE_TYPE_I;
69
248k
    s->key_frame = 1;
70
248k
    s->duration  = 1;
71
72
248k
    return next;
73
530k
}
74
75
const FFCodecParser ff_hdr_parser = {
76
    PARSER_CODEC_LIST(AV_CODEC_ID_RADIANCE_HDR),
77
    .priv_data_size = sizeof(HDRParseContext),
78
    .parse          = hdr_parse,
79
    .close          = ff_parse_close,
80
};