FFmpeg
Loading...
Searching...
No Matches
mapping.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_OGG_MAPPING_H
26#define AVFORMAT_OGG_MAPPING_H
27
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, add metadata to an AVStream
144 *
145 * This function also attaches the metadata to the next decoded
146 * packet as AV_PKT_DATA_STRINGS_METADATA
147 *
148 * @note The buffer will be temporarily modified by this function,
149 * so it needs to be writable. Furthermore it must be padded
150 * by a single byte (not counted in size).
151 * All changes will have been reverted upon return.
152 */
154 const uint8_t *buf, int size);
155
156static inline int
157ogg_find_stream (struct ogg * ogg, int serial)
158{
159 int i;
160
161 for (i = 0; i < ogg->nstreams; i++)
162 if (ogg->streams[i].serial == serial)
163 return i;
164
165 return -1;
166}
167
168static inline uint64_t
169ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts)
170{
171 struct ogg *ogg = s->priv_data;
172 struct ogg_stream *os = ogg->streams + i;
173 uint64_t pts = AV_NOPTS_VALUE;
174
175 if(os->codec && os->codec->gptopts){
176 pts = os->codec->gptopts(s, i, gp, dts);
177 } else {
178 pts = gp;
179 if (dts)
180 *dts = pts;
181 }
182 if (pts > INT64_MAX && pts != AV_NOPTS_VALUE) {
183 // The return type is unsigned, we thus cannot return negative pts
184 av_log(s, AV_LOG_ERROR, "invalid pts %"PRId64"\n", pts);
186 }
187
188 return pts;
189}
190
191#endif /* AVFORMAT_OGG_MAPPING_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.
Definition vorbis.c:125
const struct ogg_codec ff_skeleton_codec
Definition skeleton.c:96
const struct ogg_codec ff_flac_codec
Definition flac.c:172
const struct ogg_codec ff_ogm_old_codec
Definition ogm.c:223
const struct ogg_codec ff_opus_codec
Definition opus.c:230
const struct ogg_codec ff_vp8_codec
Definition vp8.c:140
const struct ogg_codec ff_ogm_video_codec
Definition ogm.c:196
static uint64_t ogg_gptopts(AVFormatContext *s, int i, uint64_t gp, int64_t *dts)
Definition mapping.h:169
const struct ogg_codec ff_speex_codec
Definition speex.c:145
const struct ogg_codec ff_old_dirac_codec
Definition dirac.c:126
const struct ogg_codec ff_old_flac_codec
Definition flac.c:180
const struct ogg_codec ff_ogm_audio_codec
Definition ogm.c:205
const struct ogg_codec ff_dirac_codec
Definition dirac.c:117
const struct ogg_codec ff_vorbis_codec
Definition vorbis.c:537
static int ogg_find_stream(struct ogg *ogg, int serial)
Definition mapping.h:157
const struct ogg_codec ff_ogm_text_codec
Definition ogm.c:214
const struct ogg_codec ff_theora_codec
Definition theora.c:214
Format I/O context.
Definition avformat.h:1401
Stream structure.
Definition avformat.h:768
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård.
Definition mapping.h:30
const int8_t * name
Definition mapping.h:33
int(* header)(AVFormatContext *, int)
Attempt to process a packet as a header.
Definition mapping.h:40
void(* cleanup)(AVFormatContext *s, int idx)
Definition mapping.h:64
uint64_t(* gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts)
Translate a granule into a timestamp.
Definition mapping.h:54
int granule_is_start
1 if granule is the start time of the associated packet.
Definition mapping.h:59
int nb_header
Number of expected headers.
Definition mapping.h:63
int(* packet)(AVFormatContext *, int)
Attempt to process a packet as a data packet.
Definition mapping.h:48
const int8_t * magic
Definition mapping.h:31
uint8_t magicsize
Definition mapping.h:32
uint64_t pos
Definition mapping.h:105
int nstreams
Definition mapping.h:108
struct ogg_stream streams[1]
Definition mapping.h:109
int curidx
Definition mapping.h:106
struct ogg_state * next
Definition mapping.h:107
unsigned int pduration
Definition mapping.h:74
int incomplete
whether we're expecting a continuation in the next page
Definition mapping.h:87
uint8_t * new_extradata
Definition mapping.h:99
size_t new_metadata_size
Definition mapping.h:98
uint64_t start_granule
Definition mapping.h:77
size_t new_extradata_size
Definition mapping.h:100
int end_trimming
set the number of packets to drop from the end
Definition mapping.h:95
unsigned int pflags
Definition mapping.h:73
int nb_header
set to the number of parsed headers
Definition mapping.h:93
uint8_t * new_metadata
Definition mapping.h:97
int nsegs
Definition mapping.h:85
unsigned int bufpos
Definition mapping.h:70
int start_trimming
set the number of packets to drop from the start
Definition mapping.h:94
int keyframe_seek
Definition mapping.h:90
uint8_t segments[255]
Definition mapping.h:86
int page_start
current packet is the first one starting in the page
Definition mapping.h:88
unsigned int bufsize
Definition mapping.h:69
uint64_t granule
Definition mapping.h:76
int64_t lastdts
Definition mapping.h:79
unsigned int pstart
Definition mapping.h:71
int replace
Definition mapping.h:96
unsigned int psize
Definition mapping.h:72
uint8_t * buf
Definition mapping.h:68
int page_end
current packet is the last one completed in the page
Definition mapping.h:89
int header
Definition mapping.h:84
int64_t page_pos
file offset of the current page
Definition mapping.h:81
const struct ogg_codec * codec
Definition mapping.h:83
int64_t lastpts
Definition mapping.h:78
int got_start
Definition mapping.h:91
int segp
Definition mapping.h:85
int64_t sync_pos
file offset of the first page needed to reconstruct the current packet
Definition mapping.h:80
uint32_t serial
Definition mapping.h:75
int flags
Definition mapping.h:82
int got_data
1 if the stream got some data (non-initial packets), 0 otherwise
Definition mapping.h:92
Definition mapping.h:112
int64_t page_pos
file offset of the current page
Definition mapping.h:117
int nstreams
Definition mapping.h:114
struct ogg_stream * streams
Definition mapping.h:113
int headers
Definition mapping.h:115
int curidx
Definition mapping.h:116
struct ogg_state * state
Definition mapping.h:118
#define av_log(a,...)
static int64_t pts
int size