Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/oggparseskeleton.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2010 David Conrad
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#include "libavutil/intreadwrite.h"
22
#include "avformat.h"
23
#include "internal.h"
24
#include "oggdec.h"
25
26
static int skeleton_header(AVFormatContext *s, int idx)
27
3.61k
{
28
3.61k
    struct ogg *ogg = s->priv_data;
29
3.61k
    struct ogg_stream *os = ogg->streams + idx;
30
3.61k
    AVStream *st = s->streams[idx];
31
3.61k
    uint8_t *buf = os->buf + os->pstart;
32
3.61k
    int version_major, version_minor;
33
3.61k
    int64_t start_num, start_den;
34
3.61k
    uint64_t start_granule;
35
3.61k
    int target_idx, start_time;
36
37
3.61k
    st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
38
39
3.61k
    if ((os->flags & OGG_FLAG_EOS) && os->psize == 0)
40
606
        return 1;
41
42
3.00k
    if (os->psize < 8)
43
8
        return -1;
44
45
2.99k
    if (!strncmp(buf, "fishead", 8)) {
46
1.91k
        if (os->psize < 64)
47
24
            return -1;
48
49
1.88k
        version_major = AV_RL16(buf+8);
50
1.88k
        version_minor = AV_RL16(buf+10);
51
52
1.88k
        if (version_major != 3 && version_major != 4) {
53
10
            av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n",
54
10
                   version_major, version_minor);
55
10
            return -1;
56
10
        }
57
58
        // This is the overall start time. We use it for the start time of
59
        // of the skeleton stream since if left unset lavf assumes 0,
60
        // which we don't want since skeleton is timeless
61
        // FIXME: the real meaning of this field is "start playback at
62
        // this time which can be in the middle of a packet
63
1.87k
        start_num = AV_RL64(buf+12);
64
1.87k
        start_den = AV_RL64(buf+20);
65
66
1.87k
        if (start_den > 0 && start_num > 0) {
67
1.08k
            int base_den;
68
1.08k
            av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX);
69
1.08k
            avpriv_set_pts_info(st, 64, 1, base_den);
70
1.08k
            os->lastpts =
71
1.08k
            st->start_time = start_time;
72
1.08k
        }
73
1.87k
    } else if (!strncmp(buf, "fisbone", 8)) {
74
626
        if (os->psize < 52)
75
0
            return -1;
76
77
626
        target_idx = ogg_find_stream(ogg, AV_RL32(buf+12));
78
626
        start_granule = AV_RL64(buf+36);
79
626
        if (target_idx < 0) {
80
215
            av_log(s, AV_LOG_WARNING, "Serial number in fisbone doesn't match any stream\n");
81
215
            return 1;
82
215
        }
83
411
        os = ogg->streams + target_idx;
84
411
        if (os->start_granule != OGG_NOGRANULE_VALUE) {
85
381
            av_log(s, AV_LOG_WARNING, "Multiple fisbone for the same stream\n");
86
381
            return 1;
87
381
        }
88
30
        if (start_granule != OGG_NOGRANULE_VALUE) {
89
30
            os->start_granule = start_granule;
90
30
        }
91
30
    }
92
93
2.36k
    return 1;
94
2.99k
}
95
96
const struct ogg_codec ff_skeleton_codec = {
97
    .magic = "fishead",
98
    .magicsize = 8,
99
    .header = skeleton_header,
100
    .nb_header = 0,
101
};