annotate ffmpeg/libavformat/internal.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * copyright (c) 2001 Fabrice Bellard
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #ifndef AVFORMAT_INTERNAL_H
yading@11 22 #define AVFORMAT_INTERNAL_H
yading@11 23
yading@11 24 #include <stdint.h>
yading@11 25 #include "avformat.h"
yading@11 26
yading@11 27 #define MAX_URL_SIZE 4096
yading@11 28
yading@11 29 #ifdef DEBUG
yading@11 30 # define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size)
yading@11 31 #else
yading@11 32 # define hex_dump_debug(class, buf, size)
yading@11 33 #endif
yading@11 34
yading@11 35 typedef struct AVCodecTag {
yading@11 36 enum AVCodecID id;
yading@11 37 unsigned int tag;
yading@11 38 } AVCodecTag;
yading@11 39
yading@11 40 typedef struct CodecMime{
yading@11 41 char str[32];
yading@11 42 enum AVCodecID id;
yading@11 43 } CodecMime;
yading@11 44
yading@11 45 #ifdef __GNUC__
yading@11 46 #define dynarray_add(tab, nb_ptr, elem)\
yading@11 47 do {\
yading@11 48 __typeof__(tab) _tab = (tab);\
yading@11 49 __typeof__(elem) _elem = (elem);\
yading@11 50 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
yading@11 51 av_dynarray_add(_tab, nb_ptr, _elem);\
yading@11 52 } while(0)
yading@11 53 #else
yading@11 54 #define dynarray_add(tab, nb_ptr, elem)\
yading@11 55 do {\
yading@11 56 av_dynarray_add((tab), nb_ptr, (elem));\
yading@11 57 } while(0)
yading@11 58 #endif
yading@11 59
yading@11 60 struct tm *ff_brktimegm(time_t secs, struct tm *tm);
yading@11 61
yading@11 62 char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
yading@11 63
yading@11 64 /**
yading@11 65 * Parse a string of hexadecimal strings. Any space between the hexadecimal
yading@11 66 * digits is ignored.
yading@11 67 *
yading@11 68 * @param data if non-null, the parsed data is written to this pointer
yading@11 69 * @param p the string to parse
yading@11 70 * @return the number of bytes written (or to be written, if data is null)
yading@11 71 */
yading@11 72 int ff_hex_to_data(uint8_t *data, const char *p);
yading@11 73
yading@11 74 void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx);
yading@11 75
yading@11 76 /**
yading@11 77 * Add packet to AVFormatContext->packet_buffer list, determining its
yading@11 78 * interleaved position using compare() function argument.
yading@11 79 * @return 0, or < 0 on error
yading@11 80 */
yading@11 81 int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
yading@11 82 int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
yading@11 83
yading@11 84 void ff_read_frame_flush(AVFormatContext *s);
yading@11 85
yading@11 86 #define NTP_OFFSET 2208988800ULL
yading@11 87 #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL)
yading@11 88
yading@11 89 /** Get the current time since NTP epoch in microseconds. */
yading@11 90 uint64_t ff_ntp_time(void);
yading@11 91
yading@11 92 /**
yading@11 93 * Assemble a URL string from components. This is the reverse operation
yading@11 94 * of av_url_split.
yading@11 95 *
yading@11 96 * Note, this requires networking to be initialized, so the caller must
yading@11 97 * ensure ff_network_init has been called.
yading@11 98 *
yading@11 99 * @see av_url_split
yading@11 100 *
yading@11 101 * @param str the buffer to fill with the url
yading@11 102 * @param size the size of the str buffer
yading@11 103 * @param proto the protocol identifier, if null, the separator
yading@11 104 * after the identifier is left out, too
yading@11 105 * @param authorization an optional authorization string, may be null.
yading@11 106 * An empty string is treated the same as a null string.
yading@11 107 * @param hostname the host name string
yading@11 108 * @param port the port number, left out from the string if negative
yading@11 109 * @param fmt a generic format string for everything to add after the
yading@11 110 * host/port, may be null
yading@11 111 * @return the number of characters written to the destination buffer
yading@11 112 */
yading@11 113 int ff_url_join(char *str, int size, const char *proto,
yading@11 114 const char *authorization, const char *hostname,
yading@11 115 int port, const char *fmt, ...) av_printf_format(7, 8);
yading@11 116
yading@11 117 /**
yading@11 118 * Append the media-specific SDP fragment for the media stream c
yading@11 119 * to the buffer buff.
yading@11 120 *
yading@11 121 * Note, the buffer needs to be initialized, since it is appended to
yading@11 122 * existing content.
yading@11 123 *
yading@11 124 * @param buff the buffer to append the SDP fragment to
yading@11 125 * @param size the size of the buff buffer
yading@11 126 * @param st the AVStream of the media to describe
yading@11 127 * @param idx the global stream index
yading@11 128 * @param dest_addr the destination address of the media stream, may be NULL
yading@11 129 * @param dest_type the destination address type, may be NULL
yading@11 130 * @param port the destination port of the media stream, 0 if unknown
yading@11 131 * @param ttl the time to live of the stream, 0 if not multicast
yading@11 132 * @param fmt the AVFormatContext, which might contain options modifying
yading@11 133 * the generated SDP
yading@11 134 */
yading@11 135 void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
yading@11 136 const char *dest_addr, const char *dest_type,
yading@11 137 int port, int ttl, AVFormatContext *fmt);
yading@11 138
yading@11 139 /**
yading@11 140 * Write a packet to another muxer than the one the user originally
yading@11 141 * intended. Useful when chaining muxers, where one muxer internally
yading@11 142 * writes a received packet to another muxer.
yading@11 143 *
yading@11 144 * @param dst the muxer to write the packet to
yading@11 145 * @param dst_stream the stream index within dst to write the packet to
yading@11 146 * @param pkt the packet to be written
yading@11 147 * @param src the muxer the packet originally was intended for
yading@11 148 * @return the value av_write_frame returned
yading@11 149 */
yading@11 150 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
yading@11 151 AVFormatContext *src);
yading@11 152
yading@11 153 /**
yading@11 154 * Get the length in bytes which is needed to store val as v.
yading@11 155 */
yading@11 156 int ff_get_v_length(uint64_t val);
yading@11 157
yading@11 158 /**
yading@11 159 * Put val using a variable number of bytes.
yading@11 160 */
yading@11 161 void ff_put_v(AVIOContext *bc, uint64_t val);
yading@11 162
yading@11 163 /**
yading@11 164 * Read a whole line of text from AVIOContext. Stop reading after reaching
yading@11 165 * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
yading@11 166 * and may be truncated if the buffer is too small.
yading@11 167 *
yading@11 168 * @param s the read-only AVIOContext
yading@11 169 * @param buf buffer to store the read line
yading@11 170 * @param maxlen size of the buffer
yading@11 171 * @return the length of the string written in the buffer, not including the
yading@11 172 * final \\0
yading@11 173 */
yading@11 174 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
yading@11 175
yading@11 176 #define SPACE_CHARS " \t\r\n"
yading@11 177
yading@11 178 /**
yading@11 179 * Callback function type for ff_parse_key_value.
yading@11 180 *
yading@11 181 * @param key a pointer to the key
yading@11 182 * @param key_len the number of bytes that belong to the key, including the '='
yading@11 183 * char
yading@11 184 * @param dest return the destination pointer for the value in *dest, may
yading@11 185 * be null to ignore the value
yading@11 186 * @param dest_len the length of the *dest buffer
yading@11 187 */
yading@11 188 typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
yading@11 189 int key_len, char **dest, int *dest_len);
yading@11 190 /**
yading@11 191 * Parse a string with comma-separated key=value pairs. The value strings
yading@11 192 * may be quoted and may contain escaped characters within quoted strings.
yading@11 193 *
yading@11 194 * @param str the string to parse
yading@11 195 * @param callback_get_buf function that returns where to store the
yading@11 196 * unescaped value string.
yading@11 197 * @param context the opaque context pointer to pass to callback_get_buf
yading@11 198 */
yading@11 199 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
yading@11 200 void *context);
yading@11 201
yading@11 202 /**
yading@11 203 * Find stream index based on format-specific stream ID
yading@11 204 * @return stream index, or < 0 on error
yading@11 205 */
yading@11 206 int ff_find_stream_index(AVFormatContext *s, int id);
yading@11 207
yading@11 208 /**
yading@11 209 * Internal version of av_index_search_timestamp
yading@11 210 */
yading@11 211 int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries,
yading@11 212 int64_t wanted_timestamp, int flags);
yading@11 213
yading@11 214 /**
yading@11 215 * Internal version of av_add_index_entry
yading@11 216 */
yading@11 217 int ff_add_index_entry(AVIndexEntry **index_entries,
yading@11 218 int *nb_index_entries,
yading@11 219 unsigned int *index_entries_allocated_size,
yading@11 220 int64_t pos, int64_t timestamp, int size, int distance, int flags);
yading@11 221
yading@11 222 /**
yading@11 223 * Add a new chapter.
yading@11 224 *
yading@11 225 * @param s media file handle
yading@11 226 * @param id unique ID for this chapter
yading@11 227 * @param start chapter start time in time_base units
yading@11 228 * @param end chapter end time in time_base units
yading@11 229 * @param title chapter title
yading@11 230 *
yading@11 231 * @return AVChapter or NULL on error
yading@11 232 */
yading@11 233 AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base,
yading@11 234 int64_t start, int64_t end, const char *title);
yading@11 235
yading@11 236 /**
yading@11 237 * Ensure the index uses less memory than the maximum specified in
yading@11 238 * AVFormatContext.max_index_size by discarding entries if it grows
yading@11 239 * too large.
yading@11 240 */
yading@11 241 void ff_reduce_index(AVFormatContext *s, int stream_index);
yading@11 242
yading@11 243 /**
yading@11 244 * Convert a relative url into an absolute url, given a base url.
yading@11 245 *
yading@11 246 * @param buf the buffer where output absolute url is written
yading@11 247 * @param size the size of buf
yading@11 248 * @param base the base url, may be equal to buf.
yading@11 249 * @param rel the new url, which is interpreted relative to base
yading@11 250 */
yading@11 251 void ff_make_absolute_url(char *buf, int size, const char *base,
yading@11 252 const char *rel);
yading@11 253
yading@11 254 enum AVCodecID ff_guess_image2_codec(const char *filename);
yading@11 255
yading@11 256 /**
yading@11 257 * Convert a date string in ISO8601 format to Unix timestamp.
yading@11 258 */
yading@11 259 int64_t ff_iso8601_to_unix_time(const char *datestr);
yading@11 260
yading@11 261 /**
yading@11 262 * Perform a binary search using av_index_search_timestamp() and
yading@11 263 * AVInputFormat.read_timestamp().
yading@11 264 *
yading@11 265 * @param target_ts target timestamp in the time base of the given stream
yading@11 266 * @param stream_index stream number
yading@11 267 */
yading@11 268 int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
yading@11 269 int64_t target_ts, int flags);
yading@11 270
yading@11 271 /**
yading@11 272 * Update cur_dts of all streams based on the given timestamp and AVStream.
yading@11 273 *
yading@11 274 * Stream ref_st unchanged, others set cur_dts in their native time base.
yading@11 275 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
yading@11 276 * @param timestamp new dts expressed in time_base of param ref_st
yading@11 277 * @param ref_st reference stream giving time_base of param timestamp
yading@11 278 */
yading@11 279 void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
yading@11 280
yading@11 281 /**
yading@11 282 * Perform a binary search using read_timestamp().
yading@11 283 *
yading@11 284 * @param target_ts target timestamp in the time base of the given stream
yading@11 285 * @param stream_index stream number
yading@11 286 */
yading@11 287 int64_t ff_gen_search(AVFormatContext *s, int stream_index,
yading@11 288 int64_t target_ts, int64_t pos_min,
yading@11 289 int64_t pos_max, int64_t pos_limit,
yading@11 290 int64_t ts_min, int64_t ts_max,
yading@11 291 int flags, int64_t *ts_ret,
yading@11 292 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
yading@11 293
yading@11 294 /**
yading@11 295 * Set the time base and wrapping info for a given stream. This will be used
yading@11 296 * to interpret the stream's timestamps. If the new time base is invalid
yading@11 297 * (numerator or denominator are non-positive), it leaves the stream
yading@11 298 * unchanged.
yading@11 299 *
yading@11 300 * @param s stream
yading@11 301 * @param pts_wrap_bits number of bits effectively used by the pts
yading@11 302 * (used for wrap control)
yading@11 303 * @param pts_num time base numerator
yading@11 304 * @param pts_den time base denominator
yading@11 305 */
yading@11 306 void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits,
yading@11 307 unsigned int pts_num, unsigned int pts_den);
yading@11 308
yading@11 309 /**
yading@11 310 * Add side data to a packet for changing parameters to the given values.
yading@11 311 * Parameters set to 0 aren't included in the change.
yading@11 312 */
yading@11 313 int ff_add_param_change(AVPacket *pkt, int32_t channels,
yading@11 314 uint64_t channel_layout, int32_t sample_rate,
yading@11 315 int32_t width, int32_t height);
yading@11 316
yading@11 317 /**
yading@11 318 * Set the timebase for each stream from the corresponding codec timebase and
yading@11 319 * print it.
yading@11 320 */
yading@11 321 int ff_framehash_write_header(AVFormatContext *s);
yading@11 322
yading@11 323 /**
yading@11 324 * Read a transport packet from a media file.
yading@11 325 *
yading@11 326 * @param s media file handle
yading@11 327 * @param pkt is filled
yading@11 328 * @return 0 if OK, AVERROR_xxx on error
yading@11 329 */
yading@11 330 int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
yading@11 331
yading@11 332 /**
yading@11 333 * Interleave a packet per dts in an output media file.
yading@11 334 *
yading@11 335 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
yading@11 336 * function, so they cannot be used after it. Note that calling av_free_packet()
yading@11 337 * on them is still safe.
yading@11 338 *
yading@11 339 * @param s media file handle
yading@11 340 * @param out the interleaved packet will be output here
yading@11 341 * @param pkt the input packet
yading@11 342 * @param flush 1 if no further packets are available as input and all
yading@11 343 * remaining packets should be output
yading@11 344 * @return 1 if a packet was output, 0 if no packet could be output,
yading@11 345 * < 0 if an error occurred
yading@11 346 */
yading@11 347 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
yading@11 348 AVPacket *pkt, int flush);
yading@11 349
yading@11 350 void ff_free_stream(AVFormatContext *s, AVStream *st);
yading@11 351
yading@11 352 /**
yading@11 353 * Return the frame duration in seconds. Return 0 if not available.
yading@11 354 */
yading@11 355 void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st,
yading@11 356 AVCodecParserContext *pc, AVPacket *pkt);
yading@11 357
yading@11 358 int ff_get_audio_frame_size(AVCodecContext *enc, int size, int mux);
yading@11 359
yading@11 360 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
yading@11 361
yading@11 362 enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
yading@11 363
yading@11 364 /**
yading@11 365 * Select a PCM codec based on the given parameters.
yading@11 366 *
yading@11 367 * @param bps bits-per-sample
yading@11 368 * @param flt floating-point
yading@11 369 * @param be big-endian
yading@11 370 * @param sflags signed flags. each bit corresponds to one byte of bit depth.
yading@11 371 * e.g. the 1st bit indicates if 8-bit should be signed or
yading@11 372 * unsigned, the 2nd bit indicates if 16-bit should be signed or
yading@11 373 * unsigned, etc... This is useful for formats such as WAVE where
yading@11 374 * only 8-bit is unsigned and all other bit depths are signed.
yading@11 375 * @return a PCM codec id or AV_CODEC_ID_NONE
yading@11 376 */
yading@11 377 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
yading@11 378
yading@11 379 /**
yading@11 380 * Chooses a timebase for muxing the specified stream.
yading@11 381 *
yading@11 382 * The choosen timebase allows sample accurate timestamps based
yading@11 383 * on the framerate or sample rate for audio streams. It also is
yading@11 384 * at least as precisse as 1/min_precission would be.
yading@11 385 */
yading@11 386 AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission);
yading@11 387
yading@11 388 /**
yading@11 389 * Generate standard extradata for AVC-Intra based on width/height and field order.
yading@11 390 */
yading@11 391 void ff_generate_avci_extradata(AVStream *st);
yading@11 392
yading@11 393 int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
yading@11 394
yading@11 395 #endif /* AVFORMAT_INTERNAL_H */