| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * copyright (c) 2001 Fabrice Bellard | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #ifndef AVFORMAT_DEMUX_H | ||
| 22 | #define AVFORMAT_DEMUX_H | ||
| 23 | |||
| 24 | #include <stdint.h> | ||
| 25 | #include "libavutil/rational.h" | ||
| 26 | #include "libavcodec/packet.h" | ||
| 27 | #include "avformat.h" | ||
| 28 | |||
| 29 | struct AVDeviceInfoList; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * For an FFInputFormat with this flag set read_close() needs to be called | ||
| 33 | * by the caller upon read_header() failure. | ||
| 34 | */ | ||
| 35 | #define FF_INFMT_FLAG_INIT_CLEANUP (1 << 0) | ||
| 36 | |||
| 37 | /* | ||
| 38 | * Prefer the codec framerate for avg_frame_rate computation. | ||
| 39 | */ | ||
| 40 | #define FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE (1 << 1) | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Automatically parse ID3v2 metadata | ||
| 44 | */ | ||
| 45 | #define FF_INFMT_FLAG_ID3V2_AUTO (1 << 2) | ||
| 46 | |||
| 47 | typedef struct FFInputFormat { | ||
| 48 | /** | ||
| 49 | * The public AVInputFormat. See avformat.h for it. | ||
| 50 | */ | ||
| 51 | AVInputFormat p; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Raw demuxers store their codec ID here. | ||
| 55 | */ | ||
| 56 | enum AVCodecID raw_codec_id; | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Size of private data so that it can be allocated in the wrapper. | ||
| 60 | */ | ||
| 61 | int priv_data_size; | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Internal flags. See FF_INFMT_FLAG_* above and FF_FMT_FLAG_* in internal.h. | ||
| 65 | */ | ||
| 66 | int flags_internal; | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Tell if a given file has a chance of being parsed as this format. | ||
| 70 | * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes | ||
| 71 | * big so you do not have to check for that unless you need more. | ||
| 72 | */ | ||
| 73 | int (*read_probe)(const AVProbeData *); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Read the format header and initialize the AVFormatContext | ||
| 77 | * structure. Return 0 if OK. 'avformat_new_stream' should be | ||
| 78 | * called to create new streams. | ||
| 79 | */ | ||
| 80 | int (*read_header)(struct AVFormatContext *); | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Read one packet and put it in 'pkt'. pts and flags are also | ||
| 84 | * set. 'avformat_new_stream' can be called only if the flag | ||
| 85 | * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a | ||
| 86 | * background thread). | ||
| 87 | * @return 0 on success, < 0 on error. | ||
| 88 | * Upon returning an error, pkt must be unreferenced by the caller. | ||
| 89 | */ | ||
| 90 | int (*read_packet)(struct AVFormatContext *, AVPacket *pkt); | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Close the stream. The AVFormatContext and AVStreams are not | ||
| 94 | * freed by this function | ||
| 95 | */ | ||
| 96 | int (*read_close)(struct AVFormatContext *); | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Seek to a given timestamp relative to the frames in | ||
| 100 | * stream component stream_index. | ||
| 101 | * @param stream_index Must not be -1. | ||
| 102 | * @param flags Selects which direction should be preferred if no exact | ||
| 103 | * match is available. | ||
| 104 | * @return >= 0 on success (but not necessarily the new offset) | ||
| 105 | */ | ||
| 106 | int (*read_seek)(struct AVFormatContext *, | ||
| 107 | int stream_index, int64_t timestamp, int flags); | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Get the next timestamp in stream[stream_index].time_base units. | ||
| 111 | * @return the timestamp or AV_NOPTS_VALUE if an error occurred | ||
| 112 | */ | ||
| 113 | int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, | ||
| 114 | int64_t *pos, int64_t pos_limit); | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Start/resume playing - only meaningful if using a network-based format | ||
| 118 | * (RTSP). | ||
| 119 | */ | ||
| 120 | int (*read_play)(struct AVFormatContext *); | ||
| 121 | |||
| 122 | /** | ||
| 123 | * Pause playing - only meaningful if using a network-based format | ||
| 124 | * (RTSP). | ||
| 125 | */ | ||
| 126 | int (*read_pause)(struct AVFormatContext *); | ||
| 127 | |||
| 128 | /** | ||
| 129 | * Seek to timestamp ts. | ||
| 130 | * Seeking will be done so that the point from which all active streams | ||
| 131 | * can be presented successfully will be closest to ts and within min/max_ts. | ||
| 132 | * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. | ||
| 133 | */ | ||
| 134 | int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Returns device list with it properties. | ||
| 138 | * @see avdevice_list_devices() for more details. | ||
| 139 | */ | ||
| 140 | int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); | ||
| 141 | } FFInputFormat; | ||
| 142 | |||
| 143 | 6147958 | static inline const FFInputFormat *ffifmt(const AVInputFormat *fmt) | |
| 144 | { | ||
| 145 | 6147958 | return (const FFInputFormat*)fmt; | |
| 146 | } | ||
| 147 | |||
| 148 | #define MAX_STD_TIMEBASES (30*12+30+3+6) | ||
| 149 | typedef struct FFStreamInfo { | ||
| 150 | int64_t last_dts; | ||
| 151 | int64_t duration_gcd; | ||
| 152 | int duration_count; | ||
| 153 | int64_t rfps_duration_sum; | ||
| 154 | double (*duration_error)[2][MAX_STD_TIMEBASES]; | ||
| 155 | int64_t codec_info_duration; | ||
| 156 | int64_t codec_info_duration_fields; | ||
| 157 | int frame_delay_evidence; | ||
| 158 | |||
| 159 | /** | ||
| 160 | * 0 -> decoder has not been searched for yet. | ||
| 161 | * >0 -> decoder found | ||
| 162 | * <0 -> decoder with codec_id == -found_decoder has not been found | ||
| 163 | */ | ||
| 164 | int found_decoder; | ||
| 165 | |||
| 166 | int64_t last_duration; | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Those are used for average framerate estimation. | ||
| 170 | */ | ||
| 171 | int64_t fps_first_dts; | ||
| 172 | int fps_first_dts_idx; | ||
| 173 | int64_t fps_last_dts; | ||
| 174 | int fps_last_dts_idx; | ||
| 175 | } FFStreamInfo; | ||
| 176 | |||
| 177 | /** | ||
| 178 | * Returned by demuxers to indicate that data was consumed but discarded | ||
| 179 | * (ignored streams or junk data). The framework will re-call the demuxer. | ||
| 180 | */ | ||
| 181 | #define FFERROR_REDO FFERRTAG('R','E','D','O') | ||
| 182 | |||
| 183 | /** | ||
| 184 | * Read a transport packet from a media file. | ||
| 185 | * | ||
| 186 | * @param s media file handle | ||
| 187 | * @param pkt is filled | ||
| 188 | * @return 0 if OK, AVERROR_xxx on error | ||
| 189 | */ | ||
| 190 | int ff_read_packet(AVFormatContext *s, AVPacket *pkt); | ||
| 191 | |||
| 192 | void ff_read_frame_flush(AVFormatContext *s); | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Perform a binary search using av_index_search_timestamp() and | ||
| 196 | * FFInputFormat.read_timestamp(). | ||
| 197 | * | ||
| 198 | * @param target_ts target timestamp in the time base of the given stream | ||
| 199 | * @param stream_index stream number | ||
| 200 | */ | ||
| 201 | int ff_seek_frame_binary(AVFormatContext *s, int stream_index, | ||
| 202 | int64_t target_ts, int flags); | ||
| 203 | |||
| 204 | /** | ||
| 205 | * Update cur_dts of all streams based on the given timestamp and AVStream. | ||
| 206 | * | ||
| 207 | * Stream ref_st unchanged, others set cur_dts in their native time base. | ||
| 208 | * Only needed for timestamp wrapping or if (dts not set and pts!=dts). | ||
| 209 | * @param timestamp new dts expressed in time_base of param ref_st | ||
| 210 | * @param ref_st reference stream giving time_base of param timestamp | ||
| 211 | */ | ||
| 212 | void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); | ||
| 213 | |||
| 214 | int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, | ||
| 215 | int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); | ||
| 216 | |||
| 217 | /** | ||
| 218 | * Perform a binary search using read_timestamp(). | ||
| 219 | * | ||
| 220 | * @param target_ts target timestamp in the time base of the given stream | ||
| 221 | * @param stream_index stream number | ||
| 222 | */ | ||
| 223 | int64_t ff_gen_search(AVFormatContext *s, int stream_index, | ||
| 224 | int64_t target_ts, int64_t pos_min, | ||
| 225 | int64_t pos_max, int64_t pos_limit, | ||
| 226 | int64_t ts_min, int64_t ts_max, | ||
| 227 | int flags, int64_t *ts_ret, | ||
| 228 | int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); | ||
| 229 | |||
| 230 | /** | ||
| 231 | * Internal version of av_index_search_timestamp | ||
| 232 | */ | ||
| 233 | int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, | ||
| 234 | int64_t wanted_timestamp, int flags); | ||
| 235 | |||
| 236 | /** | ||
| 237 | * Internal version of av_add_index_entry | ||
| 238 | */ | ||
| 239 | int ff_add_index_entry(AVIndexEntry **index_entries, | ||
| 240 | int *nb_index_entries, | ||
| 241 | unsigned int *index_entries_allocated_size, | ||
| 242 | int64_t pos, int64_t timestamp, int size, int distance, int flags); | ||
| 243 | |||
| 244 | void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance); | ||
| 245 | |||
| 246 | /** | ||
| 247 | * Ensure the index uses less memory than the maximum specified in | ||
| 248 | * AVFormatContext.max_index_size by discarding entries if it grows | ||
| 249 | * too large. | ||
| 250 | */ | ||
| 251 | void ff_reduce_index(AVFormatContext *s, int stream_index); | ||
| 252 | |||
| 253 | /** | ||
| 254 | * add frame for rfps calculation. | ||
| 255 | * | ||
| 256 | * @param dts timestamp of the i-th frame | ||
| 257 | * @return 0 if OK, AVERROR_xxx on error | ||
| 258 | */ | ||
| 259 | int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t dts); | ||
| 260 | |||
| 261 | void ff_rfps_calculate(AVFormatContext *ic); | ||
| 262 | |||
| 263 | /** | ||
| 264 | * Rescales a timestamp and the endpoints of an interval to which the temstamp | ||
| 265 | * belongs, from a timebase `tb_in` to a timebase `tb_out`. | ||
| 266 | * | ||
| 267 | * The upper (lower) bound of the output interval is rounded up (down) such that | ||
| 268 | * the output interval always falls within the input interval. The timestamp is | ||
| 269 | * rounded to the nearest integer and halfway cases away from zero, and can | ||
| 270 | * therefore fall outside of the output interval. | ||
| 271 | * | ||
| 272 | * Useful to simplify the rescaling of the arguments of FFInputFormat::read_seek2() | ||
| 273 | * | ||
| 274 | * @param[in] tb_in Timebase of the input `min_ts`, `ts` and `max_ts` | ||
| 275 | * @param[in] tb_out Timebase of the output `min_ts`, `ts` and `max_ts` | ||
| 276 | * @param[in,out] min_ts Lower bound of the interval | ||
| 277 | * @param[in,out] ts Timestamp | ||
| 278 | * @param[in,out] max_ts Upper bound of the interval | ||
| 279 | */ | ||
| 280 | void ff_rescale_interval(AVRational tb_in, AVRational tb_out, | ||
| 281 | int64_t *min_ts, int64_t *ts, int64_t *max_ts); | ||
| 282 | |||
| 283 | void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type); | ||
| 284 | |||
| 285 | /** | ||
| 286 | * Add a new chapter. | ||
| 287 | * | ||
| 288 | * @param s media file handle | ||
| 289 | * @param id unique ID for this chapter | ||
| 290 | * @param start chapter start time in time_base units | ||
| 291 | * @param end chapter end time in time_base units | ||
| 292 | * @param title chapter title | ||
| 293 | * | ||
| 294 | * @return AVChapter or NULL on error | ||
| 295 | */ | ||
| 296 | AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, | ||
| 297 | int64_t start, int64_t end, const char *title); | ||
| 298 | |||
| 299 | /** | ||
| 300 | * Add an attached pic to an AVStream. | ||
| 301 | * | ||
| 302 | * @param st if set, the stream to add the attached pic to; | ||
| 303 | * if unset, a new stream will be added to s. | ||
| 304 | * @param pb AVIOContext to read data from if buf is unset. | ||
| 305 | * @param buf if set, it contains the data and size information to be used | ||
| 306 | * for the attached pic; if unset, data is read from pb. | ||
| 307 | * @param size the size of the data to read if buf is unset. | ||
| 308 | * | ||
| 309 | * @return 0 on success, < 0 on error. On error, this function removes | ||
| 310 | * the stream it has added (if any). | ||
| 311 | */ | ||
| 312 | int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, | ||
| 313 | AVBufferRef **buf, int size); | ||
| 314 | |||
| 315 | /** | ||
| 316 | * Add side data to a packet for changing parameters to the given values. | ||
| 317 | * Parameters set to 0 aren't included in the change. | ||
| 318 | */ | ||
| 319 | int ff_add_param_change(AVPacket *pkt, int32_t channels, | ||
| 320 | uint64_t channel_layout, int32_t sample_rate, | ||
| 321 | int32_t width, int32_t height); | ||
| 322 | |||
| 323 | /** | ||
| 324 | * Generate standard extradata for AVC-Intra based on width/height and field | ||
| 325 | * order. | ||
| 326 | */ | ||
| 327 | int ff_generate_avci_extradata(AVStream *st); | ||
| 328 | |||
| 329 | /** | ||
| 330 | * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end | ||
| 331 | * which is always set to 0 and fill it from pb. | ||
| 332 | * | ||
| 333 | * @param size size of extradata | ||
| 334 | * @return >= 0 if OK, AVERROR_xxx on error | ||
| 335 | */ | ||
| 336 | int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size); | ||
| 337 | |||
| 338 | /** | ||
| 339 | * Find stream index based on format-specific stream ID | ||
| 340 | * @return stream index, or < 0 on error | ||
| 341 | */ | ||
| 342 | int ff_find_stream_index(const AVFormatContext *s, int id); | ||
| 343 | |||
| 344 | int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt); | ||
| 345 | |||
| 346 | #endif /* AVFORMAT_DEMUX_H */ | ||
| 347 |