media/libnestegg/include/nestegg.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /*
michael@0 2 * Copyright © 2010 Mozilla Foundation
michael@0 3 *
michael@0 4 * This program is made available under an ISC-style license. See the
michael@0 5 * accompanying file LICENSE for details.
michael@0 6 */
michael@0 7 #if !defined(NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79)
michael@0 8 #define NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79
michael@0 9
michael@0 10 #include <nestegg/nestegg-stdint.h>
michael@0 11
michael@0 12 #if defined(__cplusplus)
michael@0 13 extern "C" {
michael@0 14 #endif
michael@0 15
michael@0 16 /** @mainpage
michael@0 17
michael@0 18 @section intro Introduction
michael@0 19
michael@0 20 This is the documentation for the <tt>libnestegg</tt> C API.
michael@0 21 <tt>libnestegg</tt> is a demultiplexing library for <a
michael@0 22 href="http://www.webmproject.org/code/specs/container/">WebM</a>
michael@0 23 media files.
michael@0 24
michael@0 25 @section example Example code
michael@0 26
michael@0 27 @code
michael@0 28 nestegg * demux_ctx;
michael@0 29 nestegg_init(&demux_ctx, io, NULL);
michael@0 30
michael@0 31 nestegg_packet * pkt;
michael@0 32 while ((r = nestegg_read_packet(demux_ctx, &pkt)) > 0) {
michael@0 33 unsigned int track;
michael@0 34
michael@0 35 nestegg_packet_track(pkt, &track);
michael@0 36
michael@0 37 // This example decodes the first track only.
michael@0 38 if (track == 0) {
michael@0 39 unsigned int chunk, chunks;
michael@0 40
michael@0 41 nestegg_packet_count(pkt, &chunks);
michael@0 42
michael@0 43 // Decode each chunk of data.
michael@0 44 for (chunk = 0; chunk < chunks; ++chunk) {
michael@0 45 unsigned char * data;
michael@0 46 size_t data_size;
michael@0 47
michael@0 48 nestegg_packet_data(pkt, chunk, &data, &data_size);
michael@0 49
michael@0 50 example_codec_decode(codec_ctx, data, data_size);
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 nestegg_free_packet(pkt);
michael@0 55 }
michael@0 56
michael@0 57 nestegg_destroy(demux_ctx);
michael@0 58 @endcode
michael@0 59 */
michael@0 60
michael@0 61
michael@0 62 /** @file
michael@0 63 The <tt>libnestegg</tt> C API. */
michael@0 64
michael@0 65 #define NESTEGG_TRACK_VIDEO 0 /**< Track is of type video. */
michael@0 66 #define NESTEGG_TRACK_AUDIO 1 /**< Track is of type audio. */
michael@0 67
michael@0 68 #define NESTEGG_CODEC_VP8 0 /**< Track uses Google On2 VP8 codec. */
michael@0 69 #define NESTEGG_CODEC_VORBIS 1 /**< Track uses Xiph Vorbis codec. */
michael@0 70 #define NESTEGG_CODEC_VP9 2 /**< Track uses Google On2 VP9 codec. */
michael@0 71 #define NESTEGG_CODEC_OPUS 3 /**< Track uses Xiph Opus codec. */
michael@0 72
michael@0 73 #define NESTEGG_VIDEO_MONO 0 /**< Track is mono video. */
michael@0 74 #define NESTEGG_VIDEO_STEREO_LEFT_RIGHT 1 /**< Track is side-by-side stereo video. Left first. */
michael@0 75 #define NESTEGG_VIDEO_STEREO_BOTTOM_TOP 2 /**< Track is top-bottom stereo video. Right first. */
michael@0 76 #define NESTEGG_VIDEO_STEREO_TOP_BOTTOM 3 /**< Track is top-bottom stereo video. Left first. */
michael@0 77 #define NESTEGG_VIDEO_STEREO_RIGHT_LEFT 11 /**< Track is side-by-side stereo video. Right first. */
michael@0 78
michael@0 79 #define NESTEGG_SEEK_SET 0 /**< Seek offset relative to beginning of stream. */
michael@0 80 #define NESTEGG_SEEK_CUR 1 /**< Seek offset relative to current position in stream. */
michael@0 81 #define NESTEGG_SEEK_END 2 /**< Seek offset relative to end of stream. */
michael@0 82
michael@0 83 #define NESTEGG_LOG_DEBUG 1 /**< Debug level log message. */
michael@0 84 #define NESTEGG_LOG_INFO 10 /**< Informational level log message. */
michael@0 85 #define NESTEGG_LOG_WARNING 100 /**< Warning level log message. */
michael@0 86 #define NESTEGG_LOG_ERROR 1000 /**< Error level log message. */
michael@0 87 #define NESTEGG_LOG_CRITICAL 10000 /**< Critical level log message. */
michael@0 88
michael@0 89 typedef struct nestegg nestegg; /**< Opaque handle referencing the stream state. */
michael@0 90 typedef struct nestegg_packet nestegg_packet; /**< Opaque handle referencing a packet of data. */
michael@0 91
michael@0 92 /** User supplied IO context. */
michael@0 93 typedef struct {
michael@0 94 /** User supplied read callback.
michael@0 95 @param buffer Buffer to read data into.
michael@0 96 @param length Length of supplied buffer in bytes.
michael@0 97 @param userdata The #userdata supplied by the user.
michael@0 98 @retval 1 Read succeeded.
michael@0 99 @retval 0 End of stream.
michael@0 100 @retval -1 Error. */
michael@0 101 int (* read)(void * buffer, size_t length, void * userdata);
michael@0 102
michael@0 103 /** User supplied seek callback.
michael@0 104 @param offset Offset within the stream to seek to.
michael@0 105 @param whence Seek direction. One of #NESTEGG_SEEK_SET,
michael@0 106 #NESTEGG_SEEK_CUR, or #NESTEGG_SEEK_END.
michael@0 107 @param userdata The #userdata supplied by the user.
michael@0 108 @retval 0 Seek succeeded.
michael@0 109 @retval -1 Error. */
michael@0 110 int (* seek)(int64_t offset, int whence, void * userdata);
michael@0 111
michael@0 112 /** User supplied tell callback.
michael@0 113 @param userdata The #userdata supplied by the user.
michael@0 114 @returns Current position within the stream.
michael@0 115 @retval -1 Error. */
michael@0 116 int64_t (* tell)(void * userdata);
michael@0 117
michael@0 118 /** User supplied pointer to be passed to the IO callbacks. */
michael@0 119 void * userdata;
michael@0 120 } nestegg_io;
michael@0 121
michael@0 122 /** Parameters specific to a video track. */
michael@0 123 typedef struct {
michael@0 124 unsigned int stereo_mode; /**< Video mode. One of #NESTEGG_VIDEO_MONO,
michael@0 125 #NESTEGG_VIDEO_STEREO_LEFT_RIGHT,
michael@0 126 #NESTEGG_VIDEO_STEREO_BOTTOM_TOP, or
michael@0 127 #NESTEGG_VIDEO_STEREO_TOP_BOTTOM. */
michael@0 128 unsigned int width; /**< Width of the video frame in pixels. */
michael@0 129 unsigned int height; /**< Height of the video frame in pixels. */
michael@0 130 unsigned int display_width; /**< Display width of the video frame in pixels. */
michael@0 131 unsigned int display_height; /**< Display height of the video frame in pixels. */
michael@0 132 unsigned int crop_bottom; /**< Pixels to crop from the bottom of the frame. */
michael@0 133 unsigned int crop_top; /**< Pixels to crop from the top of the frame. */
michael@0 134 unsigned int crop_left; /**< Pixels to crop from the left of the frame. */
michael@0 135 unsigned int crop_right; /**< Pixels to crop from the right of the frame. */
michael@0 136 } nestegg_video_params;
michael@0 137
michael@0 138 /** Parameters specific to an audio track. */
michael@0 139 typedef struct {
michael@0 140 double rate; /**< Sampling rate in Hz. */
michael@0 141 unsigned int channels; /**< Number of audio channels. */
michael@0 142 unsigned int depth; /**< Bits per sample. */
michael@0 143 uint64_t codec_delay; /**< Nanoseconds that must be discarded from the start. */
michael@0 144 uint64_t seek_preroll;/**< Nanoseconds that must be discarded after a seek. */
michael@0 145 } nestegg_audio_params;
michael@0 146
michael@0 147 /** Logging callback function pointer. */
michael@0 148 typedef void (* nestegg_log)(nestegg * context, unsigned int severity, char const * format, ...);
michael@0 149
michael@0 150 /** Initialize a nestegg context. During initialization the parser will
michael@0 151 read forward in the stream processing all elements until the first
michael@0 152 block of media is reached. All track metadata has been processed at this point.
michael@0 153 @param context Storage for the new nestegg context. @see nestegg_destroy
michael@0 154 @param io User supplied IO context.
michael@0 155 @param callback Optional logging callback function pointer. May be NULL.
michael@0 156 @param max_offset Optional maximum offset to be read. Set -1 to ignore.
michael@0 157 @retval 0 Success.
michael@0 158 @retval -1 Error. */
michael@0 159 int nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback, int64_t max_offset);
michael@0 160
michael@0 161 /** Destroy a nestegg context and free associated memory.
michael@0 162 @param context #nestegg context to be freed. @see nestegg_init */
michael@0 163 void nestegg_destroy(nestegg * context);
michael@0 164
michael@0 165 /** Query the duration of the media stream in nanoseconds.
michael@0 166 @param context Stream context initialized by #nestegg_init.
michael@0 167 @param duration Storage for the queried duration.
michael@0 168 @retval 0 Success.
michael@0 169 @retval -1 Error. */
michael@0 170 int nestegg_duration(nestegg * context, uint64_t * duration);
michael@0 171
michael@0 172 /** Query the tstamp scale of the media stream in nanoseconds.
michael@0 173 Timecodes presented by nestegg have been scaled by this value
michael@0 174 before presentation to the caller.
michael@0 175 @param context Stream context initialized by #nestegg_init.
michael@0 176 @param scale Storage for the queried scale factor.
michael@0 177 @retval 0 Success.
michael@0 178 @retval -1 Error. */
michael@0 179 int nestegg_tstamp_scale(nestegg * context, uint64_t * scale);
michael@0 180
michael@0 181 /** Query the number of tracks in the media stream.
michael@0 182 @param context Stream context initialized by #nestegg_init.
michael@0 183 @param tracks Storage for the queried track count.
michael@0 184 @retval 0 Success.
michael@0 185 @retval -1 Error. */
michael@0 186 int nestegg_track_count(nestegg * context, unsigned int * tracks);
michael@0 187
michael@0 188 /** Query the start and end offset for a particular cluster.
michael@0 189 @param context Stream context initialized by #nestegg_init.
michael@0 190 @param cluster_num Zero-based cluster number; order they appear in cues.
michael@0 191 @param max_offset Optional maximum offset to be read. Set -1 to ignore.
michael@0 192 @param start_pos Starting offset of the cluster. -1 means non-existant.
michael@0 193 @param end_pos Starting offset of the cluster. -1 means non-existant or
michael@0 194 final cluster.
michael@0 195 @param tstamp Starting timestamp of the cluster.
michael@0 196 @retval 0 Success.
michael@0 197 @retval -1 Error. */
michael@0 198 int nestegg_get_cue_point(nestegg * context, unsigned int cluster_num,
michael@0 199 int64_t max_offset, int64_t * start_pos,
michael@0 200 int64_t * end_pos, uint64_t * tstamp);
michael@0 201
michael@0 202 /** Seek to @a offset. Stream will seek directly to offset.
michael@0 203 Should be used to seek to the start of a resync point, i.e. cluster; the
michael@0 204 parser will not be able to understand other offsets.
michael@0 205 @param context Stream context initialized by #nestegg_init.
michael@0 206 @param offset Absolute offset in bytes.
michael@0 207 @retval 0 Success.
michael@0 208 @retval -1 Error. */
michael@0 209 int nestegg_offset_seek(nestegg * context, uint64_t offset);
michael@0 210
michael@0 211 /** Seek @a track to @a tstamp. Stream seek will terminate at the earliest
michael@0 212 key point in the stream at or before @a tstamp. Other tracks in the
michael@0 213 stream will output packets with unspecified but nearby timestamps.
michael@0 214 @param context Stream context initialized by #nestegg_init.
michael@0 215 @param track Zero based track number.
michael@0 216 @param tstamp Absolute timestamp in nanoseconds.
michael@0 217 @retval 0 Success.
michael@0 218 @retval -1 Error. */
michael@0 219 int nestegg_track_seek(nestegg * context, unsigned int track, uint64_t tstamp);
michael@0 220
michael@0 221 /** Query the type specified by @a track.
michael@0 222 @param context Stream context initialized by #nestegg_init.
michael@0 223 @param track Zero based track number.
michael@0 224 @retval #NESTEGG_TRACK_VIDEO Track type is video.
michael@0 225 @retval #NESTEGG_TRACK_AUDIO Track type is audio.
michael@0 226 @retval -1 Error. */
michael@0 227 int nestegg_track_type(nestegg * context, unsigned int track);
michael@0 228
michael@0 229 /** Query the codec ID specified by @a track.
michael@0 230 @param context Stream context initialized by #nestegg_init.
michael@0 231 @param track Zero based track number.
michael@0 232 @retval #NESTEGG_CODEC_VP8 Track codec is VP8.
michael@0 233 @retval #NESTEGG_CODEC_VORBIS Track codec is Vorbis.
michael@0 234 @retval -1 Error. */
michael@0 235 int nestegg_track_codec_id(nestegg * context, unsigned int track);
michael@0 236
michael@0 237 /** Query the number of codec initialization chunks for @a track. Each
michael@0 238 chunk of data should be passed to the codec initialization functions in
michael@0 239 the order returned.
michael@0 240 @param context Stream context initialized by #nestegg_init.
michael@0 241 @param track Zero based track number.
michael@0 242 @param count Storage for the queried chunk count.
michael@0 243 @retval 0 Success.
michael@0 244 @retval -1 Error. */
michael@0 245 int nestegg_track_codec_data_count(nestegg * context, unsigned int track,
michael@0 246 unsigned int * count);
michael@0 247
michael@0 248 /** Get a pointer to chunk number @a item of codec initialization data for
michael@0 249 @a track.
michael@0 250 @param context Stream context initialized by #nestegg_init.
michael@0 251 @param track Zero based track number.
michael@0 252 @param item Zero based chunk item number.
michael@0 253 @param data Storage for the queried data pointer.
michael@0 254 The data is owned by the #nestegg context.
michael@0 255 @param length Storage for the queried data size.
michael@0 256 @retval 0 Success.
michael@0 257 @retval -1 Error. */
michael@0 258 int nestegg_track_codec_data(nestegg * context, unsigned int track, unsigned int item,
michael@0 259 unsigned char ** data, size_t * length);
michael@0 260
michael@0 261 /** Query the video parameters specified by @a track.
michael@0 262 @param context Stream context initialized by #nestegg_init.
michael@0 263 @param track Zero based track number.
michael@0 264 @param params Storage for the queried video parameters.
michael@0 265 @retval 0 Success.
michael@0 266 @retval -1 Error. */
michael@0 267 int nestegg_track_video_params(nestegg * context, unsigned int track,
michael@0 268 nestegg_video_params * params);
michael@0 269
michael@0 270 /** Query the audio parameters specified by @a track.
michael@0 271 @param context Stream context initialized by #nestegg_init.
michael@0 272 @param track Zero based track number.
michael@0 273 @param params Storage for the queried audio parameters.
michael@0 274 @retval 0 Success.
michael@0 275 @retval -1 Error. */
michael@0 276 int nestegg_track_audio_params(nestegg * context, unsigned int track,
michael@0 277 nestegg_audio_params * params);
michael@0 278
michael@0 279 /** Query the default frame duration for @a track. For a video track, this
michael@0 280 is typically the inverse of the video frame rate.
michael@0 281 @param context Stream context initialized by #nestegg_init.
michael@0 282 @param track Zero based track number.
michael@0 283 @param duration Storage for the default duration in nanoseconds.
michael@0 284 @retval 0 Success.
michael@0 285 @retval -1 Error. */
michael@0 286 int nestegg_track_default_duration(nestegg * context, unsigned int track,
michael@0 287 uint64_t * duration);
michael@0 288
michael@0 289 /** Read a packet of media data. A packet consists of one or more chunks of
michael@0 290 data associated with a single track. nestegg_read_packet should be
michael@0 291 called in a loop while the return value is 1 to drive the stream parser
michael@0 292 forward. @see nestegg_free_packet
michael@0 293 @param context Context returned by #nestegg_init.
michael@0 294 @param packet Storage for the returned nestegg_packet.
michael@0 295 @retval 1 Additional packets may be read in subsequent calls.
michael@0 296 @retval 0 End of stream.
michael@0 297 @retval -1 Error. */
michael@0 298 int nestegg_read_packet(nestegg * context, nestegg_packet ** packet);
michael@0 299
michael@0 300 /** Destroy a nestegg_packet and free associated memory.
michael@0 301 @param packet #nestegg_packet to be freed. @see nestegg_read_packet */
michael@0 302 void nestegg_free_packet(nestegg_packet * packet);
michael@0 303
michael@0 304 /** Query the track number of @a packet.
michael@0 305 @param packet Packet initialized by #nestegg_read_packet.
michael@0 306 @param track Storage for the queried zero based track index.
michael@0 307 @retval 0 Success.
michael@0 308 @retval -1 Error. */
michael@0 309 int nestegg_packet_track(nestegg_packet * packet, unsigned int * track);
michael@0 310
michael@0 311 /** Query the time stamp in nanoseconds of @a packet.
michael@0 312 @param packet Packet initialized by #nestegg_read_packet.
michael@0 313 @param tstamp Storage for the queried timestamp in nanoseconds.
michael@0 314 @retval 0 Success.
michael@0 315 @retval -1 Error. */
michael@0 316 int nestegg_packet_tstamp(nestegg_packet * packet, uint64_t * tstamp);
michael@0 317
michael@0 318 /** Query the duration in nanoseconds of @a packet.
michael@0 319 @param packet Packet initialized by #nestegg_read_packet.
michael@0 320 @param duration Storage for the queried duration in nanoseconds.
michael@0 321 @retval 0 Success.
michael@0 322 @retval -1 Error. */
michael@0 323 int nestegg_packet_duration(nestegg_packet * packet, uint64_t * duration);
michael@0 324
michael@0 325 /** Query the number of data chunks contained in @a packet.
michael@0 326 @param packet Packet initialized by #nestegg_read_packet.
michael@0 327 @param count Storage for the queried timestamp in nanoseconds.
michael@0 328 @retval 0 Success.
michael@0 329 @retval -1 Error. */
michael@0 330 int nestegg_packet_count(nestegg_packet * packet, unsigned int * count);
michael@0 331
michael@0 332 /** Get a pointer to chunk number @a item of packet data.
michael@0 333 @param packet Packet initialized by #nestegg_read_packet.
michael@0 334 @param item Zero based chunk item number.
michael@0 335 @param data Storage for the queried data pointer.
michael@0 336 The data is owned by the #nestegg_packet packet.
michael@0 337 @param length Storage for the queried data size.
michael@0 338 @retval 0 Success.
michael@0 339 @retval -1 Error. */
michael@0 340 int nestegg_packet_data(nestegg_packet * packet, unsigned int item,
michael@0 341 unsigned char ** data, size_t * length);
michael@0 342
michael@0 343 /** Returns discard_padding for given packet
michael@0 344 @param packet Packet initialized by #nestegg_read_packet.
michael@0 345 @param discard_padding pointer to store discard padding in.
michael@0 346 @retval 0 Success.
michael@0 347 @retval -1 Error. */
michael@0 348 int nestegg_packet_discard_padding(nestegg_packet * packet,
michael@0 349 int64_t * discard_padding);
michael@0 350
michael@0 351 /** Query the presence of cues.
michael@0 352 @param context Stream context initialized by #nestegg_init.
michael@0 353 @retval 0 The media has no cues.
michael@0 354 @retval 1 The media has cues. */
michael@0 355 int nestegg_has_cues(nestegg * context);
michael@0 356
michael@0 357 /**
michael@0 358 * Try to determine if the buffer looks like the beginning of a WebM file.
michael@0 359 *
michael@0 360 * @param buffer A buffer containing the beginning of a media file.
michael@0 361 * @param length The size of the buffer.
michael@0 362 * @retval 0 The file is not a WebM file.
michael@0 363 * @retval 1 The file is a WebM file. */
michael@0 364 int nestegg_sniff(unsigned char const * buffer, size_t length);
michael@0 365
michael@0 366 /**
michael@0 367 * Set the underlying allocation function for library allocations.
michael@0 368 *
michael@0 369 * @param realloc_func The desired function.
michael@0 370 */
michael@0 371 void nestegg_set_halloc_func(void * (* realloc_func)(void *, size_t));
michael@0 372
michael@0 373 #if defined(__cplusplus)
michael@0 374 }
michael@0 375 #endif
michael@0 376
michael@0 377 #endif /* NESTEGG_671cac2a_365d_ed69_d7a3_4491d3538d79 */

mercurial