FFmpeg
Loading...
Searching...
No Matches
oggdec.h
Go to the documentation of this file.
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
30struct 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 */
60 /**
61 * Number of expected headers
62 */
64 void (*cleanup)(AVFormatContext *s, int idx);
65};
66
67struct 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;
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_start; ///< current packet is the first one starting in the page
89 int page_end; ///< current packet is the last one completed in the page
92 int got_data; ///< 1 if the stream got some data (non-initial packets), 0 otherwise
93 int nb_header; ///< set to the number of parsed headers
94 int start_trimming; ///< set the number of packets to drop from the start
95 int end_trimming; ///< set the number of packets to drop from the end
96 int replace; // < set to 1 after initializing a new chained stream
97 uint8_t *new_metadata;
99 uint8_t *new_extradata;
101 void *private;
102};
103
104struct ogg_state {
105 uint64_t pos;
110};
111
112struct ogg {
117 int64_t page_pos; ///< file offset of the current page
119};
120
121#define OGG_FLAG_CONT 1
122#define OGG_FLAG_BOS 2
123#define OGG_FLAG_EOS 4
124
125#define OGG_NOGRANULE_VALUE (-1ull)
126
127extern const struct ogg_codec ff_dirac_codec;
128extern const struct ogg_codec ff_flac_codec;
129extern const struct ogg_codec ff_ogm_audio_codec;
130extern const struct ogg_codec ff_ogm_old_codec;
131extern const struct ogg_codec ff_ogm_text_codec;
132extern const struct ogg_codec ff_ogm_video_codec;
133extern const struct ogg_codec ff_old_dirac_codec;
134extern const struct ogg_codec ff_old_flac_codec;
135extern const struct ogg_codec ff_opus_codec;
136extern const struct ogg_codec ff_skeleton_codec;
137extern const struct ogg_codec ff_speex_codec;
138extern const struct ogg_codec ff_theora_codec;
139extern const struct ogg_codec ff_vorbis_codec;
140extern 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 */
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 */
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 */
176 const uint8_t *buf, int size);
177
178static inline int
179ogg_find_stream (struct ogg * ogg, int serial)
180{
181 int i;
182
183 for (i = 0; i < ogg->nstreams; i++)
184 if (ogg->streams[i].serial == serial)
185 return i;
186
187 return -1;
188}
189
190static inline uint64_t
191ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
192{
193 struct ogg *ogg = s->priv_data;
194 struct ogg_stream *os = ogg->streams + i;
195 uint64_t pts = AV_NOPTS_VALUE;
196
197 if(os->codec && os->codec->gptopts){
198 pts = os->codec->gptopts(s, i, gp, dts);
199 } else {
200 pts = gp;
201 if (dts)
202 *dts = pts;
203 }
204 if (pts > INT64_MAX && pts != AV_NOPTS_VALUE) {
205 // The return type is unsigned, we thus cannot return negative pts
206 av_log(s, AV_LOG_ERROR, "invalid pts %"PRId64"\n", pts);
208 }
209
210 return pts;
211}
212
213#endif /* AVFORMAT_OGGDEC_H */
Main libavformat public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st, const uint8_t *buf, int size)
Parse Vorbis comments, add metadata to an AVStream.
const struct ogg_codec ff_skeleton_codec
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size, int parse_picture)
Parse Vorbis comments.
const struct ogg_codec ff_flac_codec
int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st, const uint8_t *buf, int size)
Parse Vorbis comments and add metadata to an AVStream.
const struct ogg_codec ff_ogm_old_codec
const struct ogg_codec ff_opus_codec
const struct ogg_codec ff_vp8_codec
const struct ogg_codec ff_ogm_video_codec
static uint64_t ogg_gptopts(AVFormatContext *s, int i, uint64_t gp, int64_t *dts)
Definition oggdec.h:191
const struct ogg_codec ff_speex_codec
const struct ogg_codec ff_old_dirac_codec
const struct ogg_codec ff_old_flac_codec
const struct ogg_codec ff_ogm_audio_codec
const struct ogg_codec ff_dirac_codec
const struct ogg_codec ff_vorbis_codec
static int ogg_find_stream(struct ogg *ogg, int serial)
Definition oggdec.h:179
const struct ogg_codec ff_ogm_text_codec
const struct ogg_codec ff_theora_codec
Format I/O context.
Definition avformat.h:1333
Stream structure.
Definition avformat.h:766
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition oggdec.h:30
const int8_t * name
Definition oggdec.h:33
int(* header)(AVFormatContext *, int)
Attempt to process a packet as a header.
Definition oggdec.h:40
void(* cleanup)(AVFormatContext *s, int idx)
Definition oggdec.h:64
uint64_t(* gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts)
Translate a granule into a timestamp.
Definition oggdec.h:54
int granule_is_start
1 if granule is the start time of the associated packet.
Definition oggdec.h:59
int nb_header
Number of expected headers.
Definition oggdec.h:63
int(* packet)(AVFormatContext *, int)
Attempt to process a packet as a data packet.
Definition oggdec.h:48
const int8_t * magic
Definition oggdec.h:31
uint8_t magicsize
Definition oggdec.h:32
uint64_t pos
Definition oggdec.h:105
int nstreams
Definition oggdec.h:108
struct ogg_stream streams[1]
Definition oggdec.h:109
int curidx
Definition oggdec.h:106
struct ogg_state * next
Definition oggdec.h:107
unsigned int pduration
Definition oggdec.h:74
int incomplete
whether we're expecting a continuation in the next page
Definition oggdec.h:87
uint8_t * new_extradata
Definition oggdec.h:99
size_t new_metadata_size
Definition oggdec.h:98
uint64_t start_granule
Definition oggdec.h:77
size_t new_extradata_size
Definition oggdec.h:100
int end_trimming
set the number of packets to drop from the end
Definition oggdec.h:95
unsigned int pflags
Definition oggdec.h:73
int nb_header
set to the number of parsed headers
Definition oggdec.h:93
uint8_t * new_metadata
Definition oggdec.h:97
int nsegs
Definition oggdec.h:85
unsigned int bufpos
Definition oggdec.h:70
int start_trimming
set the number of packets to drop from the start
Definition oggdec.h:94
int keyframe_seek
Definition oggdec.h:90
uint8_t segments[255]
Definition oggdec.h:86
int page_start
current packet is the first one starting in the page
Definition oggdec.h:88
unsigned int bufsize
Definition oggdec.h:69
uint64_t granule
Definition oggdec.h:76
int64_t lastdts
Definition oggdec.h:79
unsigned int pstart
Definition oggdec.h:71
int replace
Definition oggdec.h:96
unsigned int psize
Definition oggdec.h:72
uint8_t * buf
Definition oggdec.h:68
int page_end
current packet is the last one completed in the page
Definition oggdec.h:89
int header
Definition oggdec.h:84
int64_t page_pos
file offset of the current page
Definition oggdec.h:81
const struct ogg_codec * codec
Definition oggdec.h:83
int64_t lastpts
Definition oggdec.h:78
int got_start
Definition oggdec.h:91
int segp
Definition oggdec.h:85
int64_t sync_pos
file offset of the first page needed to reconstruct the current packet
Definition oggdec.h:80
uint32_t serial
Definition oggdec.h:75
int flags
Definition oggdec.h:82
int got_data
1 if the stream got some data (non-initial packets), 0 otherwise
Definition oggdec.h:92
Definition oggdec.h:112
int64_t page_pos
file offset of the current page
Definition oggdec.h:117
int nstreams
Definition oggdec.h:114
struct ogg_stream * streams
Definition oggdec.h:113
int headers
Definition oggdec.h:115
int curidx
Definition oggdec.h:116
struct ogg_state * state
Definition oggdec.h:118
#define av_log(a,...)
static int64_t pts
int size