Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/oggdec.h
Line
Count
Source
1
/**
2
    Copyright (C) 2005  Michael Ahlberg, Måns Rullgård
3
4
    Permission is hereby granted, free of charge, to any person
5
    obtaining a copy of this software and associated documentation
6
    files (the "Software"), to deal in the Software without
7
    restriction, including without limitation the rights to use, copy,
8
    modify, merge, publish, distribute, sublicense, and/or sell copies
9
    of the Software, and to permit persons to whom the Software is
10
    furnished to do so, subject to the following conditions:
11
12
    The above copyright notice and this permission notice shall be
13
    included in all copies or substantial portions of the Software.
14
15
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
    DEALINGS IN THE SOFTWARE.
23
**/
24
25
#ifndef AVFORMAT_OGGDEC_H
26
#define AVFORMAT_OGGDEC_H
27
28
#include "avformat.h"
29
30
struct ogg_codec {
31
    const int8_t *magic;
32
    uint8_t magicsize;
33
    const int8_t *name;
34
    /**
35
     * Attempt to process a packet as a header
36
     * @return 1 if the packet was a valid header,
37
     *         0 if the packet was not a header (was a data packet)
38
     *         -1 if an error occurred or for unsupported stream
39
     */
40
    int (*header)(AVFormatContext *, int);
41
    /**
42
     * Attempt to process a packet as a data packet
43
     * @return < 0 (AVERROR) code or -1 on error
44
     *         == 0 if the packet was a regular data packet.
45
     *         == 1 if the packet was a header from a chained bitstream.
46
     *            This will cause the packet to be skipped in calling code (ogg_packet()
47
     */
48
    int (*packet)(AVFormatContext *, int);
49
    /**
50
     * Translate a granule into a timestamp.
51
     * Will set dts if non-null and known.
52
     * @return pts
53
     */
54
    uint64_t (*gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts);
55
    /**
56
     * 1 if granule is the start time of the associated packet.
57
     * 0 if granule is the end time of the associated packet.
58
     */
59
    int granule_is_start;
60
    /**
61
     * Number of expected headers
62
     */
63
    int nb_header;
64
    void (*cleanup)(AVFormatContext *s, int idx);
65
};
66
67
struct ogg_stream {
68
    uint8_t *buf;
69
    unsigned int bufsize;
70
    unsigned int bufpos;
71
    unsigned int pstart;
72
    unsigned int psize;
73
    unsigned int pflags;
74
    unsigned int pduration;
75
    uint32_t serial;
76
    uint64_t granule;
77
    uint64_t start_granule;
78
    int64_t lastpts;
79
    int64_t lastdts;
80
    int64_t sync_pos;   ///< file offset of the first page needed to reconstruct the current packet
81
    int64_t page_pos;   ///< file offset of the current page
82
    int flags;
83
    const struct ogg_codec *codec;
84
    int header;
85
    int nsegs, segp;
86
    uint8_t segments[255];
87
    int incomplete; ///< whether we're expecting a continuation in the next page
88
    int page_end;   ///< current packet is the last one completed in the page
89
    int keyframe_seek;
90
    int got_start;
91
    int got_data;   ///< 1 if the stream got some data (non-initial packets), 0 otherwise
92
    int nb_header; ///< set to the number of parsed headers
93
    int start_trimming; ///< set the number of packets to drop from the start
94
    int end_trimming; ///< set the number of packets to drop from the end
95
    int replace; // < set to 1 after initializing a new chained stream
96
    uint8_t *new_metadata;
97
    size_t new_metadata_size;
98
    uint8_t *new_extradata;
99
    size_t new_extradata_size;
100
    void *private;
101
};
102
103
struct ogg_state {
104
    uint64_t pos;
105
    int curidx;
106
    struct ogg_state *next;
107
    int nstreams;
108
    struct ogg_stream streams[1];
109
};
110
111
struct ogg {
112
    struct ogg_stream *streams;
113
    int nstreams;
114
    int headers;
115
    int curidx;
116
    int64_t page_pos;                   ///< file offset of the current page
117
    struct ogg_state *state;
118
};
119
120
1.18M
#define OGG_FLAG_CONT 1
121
596k
#define OGG_FLAG_BOS  2
122
3.01M
#define OGG_FLAG_EOS  4
123
124
24.4k
#define OGG_NOGRANULE_VALUE (-1ull)
125
126
extern const struct ogg_codec ff_celt_codec;
127
extern const struct ogg_codec ff_dirac_codec;
128
extern const struct ogg_codec ff_flac_codec;
129
extern const struct ogg_codec ff_ogm_audio_codec;
130
extern const struct ogg_codec ff_ogm_old_codec;
131
extern const struct ogg_codec ff_ogm_text_codec;
132
extern const struct ogg_codec ff_ogm_video_codec;
133
extern const struct ogg_codec ff_old_dirac_codec;
134
extern const struct ogg_codec ff_old_flac_codec;
135
extern const struct ogg_codec ff_opus_codec;
136
extern const struct ogg_codec ff_skeleton_codec;
137
extern const struct ogg_codec ff_speex_codec;
138
extern const struct ogg_codec ff_theora_codec;
139
extern const struct ogg_codec ff_vorbis_codec;
140
extern const struct ogg_codec ff_vp8_codec;
141
142
/**
143
 * Parse Vorbis comments
144
 *
145
 * @note  The buffer will be temporarily modified by this function,
146
 *        so it needs to be writable. Furthermore it must be padded
147
 *        by a single byte (not counted in size).
148
 *        All changes will have been reverted upon return.
149
 */
150
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m,
151
                      const uint8_t *buf, int size, int parse_picture);
152
153
/**
154
 * Parse Vorbis comments and add metadata to an AVStream
155
 *
156
 * @note  The buffer will be temporarily modified by this function,
157
 *        so it needs to be writable. Furthermore it must be padded
158
 *        by a single byte (not counted in size).
159
 *        All changes will have been reverted upon return.
160
 */
161
int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st,
162
                             const uint8_t *buf, int size);
163
164
/**
165
 * Parse Vorbis comments, add metadata to an AVStream
166
 *
167
 * This function also attaches the metadata to the next decoded
168
 * packet as AV_PKT_DATA_STRINGS_METADATA
169
 *
170
 * @note  The buffer will be temporarily modified by this function,
171
 *        so it needs to be writable. Furthermore it must be padded
172
 *        by a single byte (not counted in size).
173
 *        All changes will have been reverted upon return.
174
 */
175
int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st,
176
                              const uint8_t *buf, int size);
177
178
static inline int
179
ogg_find_stream (struct ogg * ogg, int serial)
180
875k
{
181
875k
    int i;
182
183
2.00M
    for (i = 0; i < ogg->nstreams; i++)
184
1.86M
        if (ogg->streams[i].serial == serial)
185
738k
            return i;
186
187
137k
    return -1;
188
875k
}
Unexecuted instantiation: flacdec.c:ogg_find_stream
Unexecuted instantiation: matroskadec.c:ogg_find_stream
oggdec.c:ogg_find_stream
Line
Count
Source
180
875k
{
181
875k
    int i;
182
183
2.00M
    for (i = 0; i < ogg->nstreams; i++)
184
1.86M
        if (ogg->streams[i].serial == serial)
185
738k
            return i;
186
187
137k
    return -1;
188
875k
}
Unexecuted instantiation: oggparsecelt.c:ogg_find_stream
Unexecuted instantiation: oggparsedirac.c:ogg_find_stream
Unexecuted instantiation: oggparseflac.c:ogg_find_stream
Unexecuted instantiation: oggparseogm.c:ogg_find_stream
Unexecuted instantiation: oggparseopus.c:ogg_find_stream
oggparseskeleton.c:ogg_find_stream
Line
Count
Source
180
487
{
181
487
    int i;
182
183
1.61k
    for (i = 0; i < ogg->nstreams; i++)
184
1.39k
        if (ogg->streams[i].serial == serial)
185
266
            return i;
186
187
221
    return -1;
188
487
}
Unexecuted instantiation: oggparsespeex.c:ogg_find_stream
Unexecuted instantiation: oggparsetheora.c:ogg_find_stream
Unexecuted instantiation: oggparsevorbis.c:ogg_find_stream
Unexecuted instantiation: oggparsevp8.c:ogg_find_stream
189
190
static inline uint64_t
191
ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
192
467k
{
193
467k
    struct ogg *ogg = s->priv_data;
194
467k
    struct ogg_stream *os = ogg->streams + i;
195
467k
    uint64_t pts = AV_NOPTS_VALUE;
196
197
467k
    if(os->codec && os->codec->gptopts){
198
445k
        pts = os->codec->gptopts(s, i, gp, dts);
199
445k
    } else {
200
21.7k
        pts = gp;
201
21.7k
        if (dts)
202
18.5k
            *dts = pts;
203
21.7k
    }
204
467k
    if (pts > INT64_MAX && pts != AV_NOPTS_VALUE) {
205
        // The return type is unsigned, we thus cannot return negative pts
206
6.63k
        av_log(s, AV_LOG_ERROR, "invalid pts %"PRId64"\n", pts);
207
6.63k
        pts = AV_NOPTS_VALUE;
208
6.63k
    }
209
210
467k
    return pts;
211
467k
}
Unexecuted instantiation: flacdec.c:ogg_gptopts
Unexecuted instantiation: matroskadec.c:ogg_gptopts
oggdec.c:ogg_gptopts
Line
Count
Source
192
467k
{
193
467k
    struct ogg *ogg = s->priv_data;
194
467k
    struct ogg_stream *os = ogg->streams + i;
195
467k
    uint64_t pts = AV_NOPTS_VALUE;
196
197
467k
    if(os->codec && os->codec->gptopts){
198
445k
        pts = os->codec->gptopts(s, i, gp, dts);
199
445k
    } else {
200
21.7k
        pts = gp;
201
21.7k
        if (dts)
202
18.5k
            *dts = pts;
203
21.7k
    }
204
467k
    if (pts > INT64_MAX && pts != AV_NOPTS_VALUE) {
205
        // The return type is unsigned, we thus cannot return negative pts
206
6.63k
        av_log(s, AV_LOG_ERROR, "invalid pts %"PRId64"\n", pts);
207
6.63k
        pts = AV_NOPTS_VALUE;
208
6.63k
    }
209
210
467k
    return pts;
211
467k
}
Unexecuted instantiation: oggparsecelt.c:ogg_gptopts
Unexecuted instantiation: oggparsedirac.c:ogg_gptopts
Unexecuted instantiation: oggparseflac.c:ogg_gptopts
Unexecuted instantiation: oggparseogm.c:ogg_gptopts
Unexecuted instantiation: oggparseopus.c:ogg_gptopts
Unexecuted instantiation: oggparseskeleton.c:ogg_gptopts
Unexecuted instantiation: oggparsespeex.c:ogg_gptopts
Unexecuted instantiation: oggparsetheora.c:ogg_gptopts
Unexecuted instantiation: oggparsevorbis.c:ogg_gptopts
Unexecuted instantiation: oggparsevp8.c:ogg_gptopts
212
213
#endif /* AVFORMAT_OGGDEC_H */