2 * Copyright © 2010 Mozilla Foundation
4 * This program is made available under an ISC-style license. See the
5 * accompanying file LICENSE for details.
7 #ifndef NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
8 #define NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
10 #include "vpx/vpx_integer.h"
18 @section intro Introduction
20 This is the documentation fot the <tt>libnestegg</tt> C API.
21 <tt>libnestegg</tt> is a demultiplexing library for <a
22 href="http://www.matroska.org/">Matroska</a> and <a
23 href="http://www.webmproject.org/">WebMedia</a> media files.
25 @section example Example code
29 nestegg_init(&demux_ctx, io, NULL);
32 while ((r = nestegg_read_packet(demux_ctx, &pkt)) > 0) {
35 nestegg_packet_track(pkt, &track);
37 // This example decodes the first track only.
39 unsigned int chunk, chunks;
41 nestegg_packet_count(pkt, &chunks);
43 // Decode each chunk of data.
44 for (chunk = 0; chunk < chunks; ++chunk) {
48 nestegg_packet_data(pkt, chunk, &data, &data_size);
50 example_codec_decode(codec_ctx, data, data_size);
54 nestegg_free_packet(pkt);
57 nestegg_destroy(demux_ctx);
63 The <tt>libnestegg</tt> C API. */
65 #define NESTEGG_TRACK_VIDEO 0 /**< Track is of type video. */
66 #define NESTEGG_TRACK_AUDIO 1 /**< Track is of type audio. */
68 #define NESTEGG_CODEC_VP8 0 /**< Track uses Google On2 VP8 codec. */
69 #define NESTEGG_CODEC_VORBIS 1 /**< Track uses Xiph Vorbis codec. */
71 #define NESTEGG_SEEK_SET 0 /**< Seek offset relative to beginning of stream. */
72 #define NESTEGG_SEEK_CUR 1 /**< Seek offset relative to current position in stream. */
73 #define NESTEGG_SEEK_END 2 /**< Seek offset relative to end of stream. */
75 #define NESTEGG_LOG_DEBUG 1 /**< Debug level log message. */
76 #define NESTEGG_LOG_INFO 10 /**< Informational level log message. */
77 #define NESTEGG_LOG_WARNING 100 /**< Warning level log message. */
78 #define NESTEGG_LOG_ERROR 1000 /**< Error level log message. */
79 #define NESTEGG_LOG_CRITICAL 10000 /**< Critical level log message. */
81 typedef struct nestegg nestegg; /**< Opaque handle referencing the stream state. */
82 typedef struct nestegg_packet nestegg_packet; /**< Opaque handle referencing a packet of data. */
84 /** User supplied IO context. */
86 /** User supplied read callback.
87 @param buffer Buffer to read data into.
88 @param length Length of supplied buffer in bytes.
89 @param userdata The #userdata supplied by the user.
90 @retval 1 Read succeeded.
91 @retval 0 End of stream.
93 int (* read)(void * buffer, size_t length, void * userdata);
95 /** User supplied seek callback.
96 @param offset Offset within the stream to seek to.
97 @param whence Seek direction. One of #NESTEGG_SEEK_SET,
98 #NESTEGG_SEEK_CUR, or #NESTEGG_SEEK_END.
99 @param userdata The #userdata supplied by the user.
100 @retval 0 Seek succeeded.
102 int (* seek)(int64_t offset, int whence, void * userdata);
104 /** User supplied tell callback.
105 @param userdata The #userdata supplied by the user.
106 @returns Current position within the stream.
108 int64_t (* tell)(void * userdata);
110 /** User supplied pointer to be passed to the IO callbacks. */
114 /** Parameters specific to a video track. */
116 unsigned int width; /**< Width of the video frame in pixels. */
117 unsigned int height; /**< Height of the video frame in pixels. */
118 unsigned int display_width; /**< Display width of the video frame in pixels. */
119 unsigned int display_height; /**< Display height of the video frame in pixels. */
120 unsigned int crop_bottom; /**< Pixels to crop from the bottom of the frame. */
121 unsigned int crop_top; /**< Pixels to crop from the top of the frame. */
122 unsigned int crop_left; /**< Pixels to crop from the left of the frame. */
123 unsigned int crop_right; /**< Pixels to crop from the right of the frame. */
124 } nestegg_video_params;
126 /** Parameters specific to an audio track. */
128 double rate; /**< Sampling rate in Hz. */
129 unsigned int channels; /**< Number of audio channels. */
130 unsigned int depth; /**< Bits per sample. */
131 } nestegg_audio_params;
133 /** Logging callback function pointer. */
134 typedef void (* nestegg_log)(nestegg * context, unsigned int severity, char const * format, ...);
136 /** Initialize a nestegg context. During initialization the parser will
137 read forward in the stream processing all elements until the first
138 block of media is reached. All track metadata has been processed at this point.
139 @param context Storage for the new nestegg context. @see nestegg_destroy
140 @param io User supplied IO context.
141 @param callback Optional logging callback function pointer. May be NULL.
144 int nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback);
146 /** Destroy a nestegg context and free associated memory.
147 @param context #nestegg context to be freed. @see nestegg_init */
148 void nestegg_destroy(nestegg * context);
150 /** Query the duration of the media stream in nanoseconds.
151 @param context Stream context initialized by #nestegg_init.
152 @param duration Storage for the queried duration.
155 int nestegg_duration(nestegg * context, uint64_t * duration);
157 /** Query the tstamp scale of the media stream in nanoseconds.
158 Timecodes presented by nestegg have been scaled by this value
159 before presentation to the caller.
160 @param context Stream context initialized by #nestegg_init.
161 @param scale Storage for the queried scale factor.
164 int nestegg_tstamp_scale(nestegg * context, uint64_t * scale);
166 /** Query the number of tracks in the media stream.
167 @param context Stream context initialized by #nestegg_init.
168 @param tracks Storage for the queried track count.
171 int nestegg_track_count(nestegg * context, unsigned int * tracks);
173 /** Seek @a track to @a tstamp. Stream seek will terminate at the earliest
174 key point in the stream at or before @a tstamp. Other tracks in the
175 stream will output packets with unspecified but nearby timestamps.
176 @param context Stream context initialized by #nestegg_init.
177 @param track Zero based track number.
178 @param tstamp Absolute timestamp in nanoseconds.
181 int nestegg_track_seek(nestegg * context, unsigned int track, uint64_t tstamp);
183 /** Query the type specified by @a track.
184 @param context Stream context initialized by #nestegg_init.
185 @param track Zero based track number.
186 @retval #NESTEGG_TRACK_VIDEO Track type is video.
187 @retval #NESTEGG_TRACK_AUDIO Track type is audio.
189 int nestegg_track_type(nestegg * context, unsigned int track);
191 /** Query the codec ID specified by @a track.
192 @param context Stream context initialized by #nestegg_init.
193 @param track Zero based track number.
194 @retval #NESTEGG_CODEC_VP8 Track codec is VP8.
195 @retval #NESTEGG_CODEC_VORBIS Track codec is Vorbis.
197 int nestegg_track_codec_id(nestegg * context, unsigned int track);
199 /** Query the number of codec initialization chunks for @a track. Each
200 chunk of data should be passed to the codec initialization functions in
202 @param context Stream context initialized by #nestegg_init.
203 @param track Zero based track number.
204 @param count Storage for the queried chunk count.
207 int nestegg_track_codec_data_count(nestegg * context, unsigned int track,
208 unsigned int * count);
210 /** Get a pointer to chunk number @a item of codec initialization data for
212 @param context Stream context initialized by #nestegg_init.
213 @param track Zero based track number.
214 @param item Zero based chunk item number.
215 @param data Storage for the queried data pointer.
216 The data is owned by the #nestegg context.
217 @param length Storage for the queried data size.
220 int nestegg_track_codec_data(nestegg * context, unsigned int track, unsigned int item,
221 unsigned char ** data, size_t * length);
223 /** Query the video parameters specified by @a track.
224 @param context Stream context initialized by #nestegg_init.
225 @param track Zero based track number.
226 @param params Storage for the queried video parameters.
229 int nestegg_track_video_params(nestegg * context, unsigned int track,
230 nestegg_video_params * params);
232 /** Query the audio parameters specified by @a track.
233 @param context Stream context initialized by #nestegg_init.
234 @param track Zero based track number.
235 @param params Storage for the queried audio parameters.
238 int nestegg_track_audio_params(nestegg * context, unsigned int track,
239 nestegg_audio_params * params);
241 /** Read a packet of media data. A packet consists of one or more chunks of
242 data associated with a single track. nestegg_read_packet should be
243 called in a loop while the return value is 1 to drive the stream parser
244 forward. @see nestegg_free_packet
245 @param context Context returned by #nestegg_init.
246 @param packet Storage for the returned nestegg_packet.
247 @retval 1 Additional packets may be read in subsequent calls.
248 @retval 0 End of stream.
250 int nestegg_read_packet(nestegg * context, nestegg_packet ** packet);
252 /** Destroy a nestegg_packet and free associated memory.
253 @param packet #nestegg_packet to be freed. @see nestegg_read_packet */
254 void nestegg_free_packet(nestegg_packet * packet);
256 /** Query the track number of @a packet.
257 @param packet Packet initialized by #nestegg_read_packet.
258 @param track Storage for the queried zero based track index.
261 int nestegg_packet_track(nestegg_packet * packet, unsigned int * track);
263 /** Query the time stamp in nanoseconds of @a packet.
264 @param packet Packet initialized by #nestegg_read_packet.
265 @param tstamp Storage for the queried timestamp in nanoseconds.
268 int nestegg_packet_tstamp(nestegg_packet * packet, uint64_t * tstamp);
270 /** Query the number of data chunks contained in @a packet.
271 @param packet Packet initialized by #nestegg_read_packet.
272 @param count Storage for the queried timestamp in nanoseconds.
275 int nestegg_packet_count(nestegg_packet * packet, unsigned int * count);
277 /** Get a pointer to chunk number @a item of packet data.
278 @param packet Packet initialized by #nestegg_read_packet.
279 @param item Zero based chunk item number.
280 @param data Storage for the queried data pointer.
281 The data is owned by the #nestegg_packet packet.
282 @param length Storage for the queried data size.
285 int nestegg_packet_data(nestegg_packet * packet, unsigned int item,
286 unsigned char ** data, size_t * length);
292 #endif /* NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79 */