You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1073 lines
38KB

  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. #ifndef FFMPEG_AVFORMAT_H
  21. #define FFMPEG_AVFORMAT_H
  22. #define LIBAVFORMAT_VERSION_MAJOR 52
  23. #define LIBAVFORMAT_VERSION_MINOR 14
  24. #define LIBAVFORMAT_VERSION_MICRO 0
  25. #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
  26. LIBAVFORMAT_VERSION_MINOR, \
  27. LIBAVFORMAT_VERSION_MICRO)
  28. #define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
  29. LIBAVFORMAT_VERSION_MINOR, \
  30. LIBAVFORMAT_VERSION_MICRO)
  31. #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
  32. #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
  33. #include <time.h>
  34. #include <stdio.h> /* FILE */
  35. #include "libavcodec/avcodec.h"
  36. #include "avio.h"
  37. /* packet functions */
  38. typedef struct AVPacket {
  39. /**
  40. * Presentation time stamp in time_base units.
  41. * This is the time at which the decompressed packet will be presented
  42. * to the user.
  43. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  44. * pts MUST be larger or equal to dts as presentation can not happen before
  45. * decompression, unless one wants to view hex dumps. Some formats misuse
  46. * the terms dts and pts/cts to mean something different, these timestamps
  47. * must be converted to true pts/dts before they are stored in AVPacket.
  48. */
  49. int64_t pts;
  50. /**
  51. * Decompression time stamp in time_base units.
  52. * This is the time at which the packet is decompressed.
  53. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  54. */
  55. int64_t dts;
  56. uint8_t *data;
  57. int size;
  58. int stream_index;
  59. int flags;
  60. int duration; ///< presentation duration in time_base units (0 if not available)
  61. void (*destruct)(struct AVPacket *);
  62. void *priv;
  63. int64_t pos; ///< byte position in stream, -1 if unknown
  64. } AVPacket;
  65. #define PKT_FLAG_KEY 0x0001
  66. void av_destruct_packet_nofree(AVPacket *pkt);
  67. /**
  68. * Default packet destructor.
  69. */
  70. void av_destruct_packet(AVPacket *pkt);
  71. /**
  72. * Initialize optional fields of a packet to default values.
  73. *
  74. * @param pkt packet
  75. */
  76. void av_init_packet(AVPacket *pkt);
  77. /**
  78. * Allocate the payload of a packet and initialize its fields to default values.
  79. *
  80. * @param pkt packet
  81. * @param size wanted payload size
  82. * @return 0 if OK. AVERROR_xxx otherwise.
  83. */
  84. int av_new_packet(AVPacket *pkt, int size);
  85. /**
  86. * Allocate and read the payload of a packet and initialize its fields to default values.
  87. *
  88. * @param pkt packet
  89. * @param size wanted payload size
  90. * @return >0 (read size) if OK. AVERROR_xxx otherwise.
  91. */
  92. int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
  93. /**
  94. * @warning This is a hack - the packet memory allocation stuff is broken. The
  95. * packet is allocated if it was not really allocated
  96. */
  97. int av_dup_packet(AVPacket *pkt);
  98. /**
  99. * Free a packet
  100. *
  101. * @param pkt packet to free
  102. */
  103. static inline void av_free_packet(AVPacket *pkt)
  104. {
  105. if (pkt && pkt->destruct) {
  106. pkt->destruct(pkt);
  107. }
  108. }
  109. /*************************************************/
  110. /* fractional numbers for exact pts handling */
  111. /**
  112. * the exact value of the fractional number is: 'val + num / den'.
  113. * num is assumed to be such as 0 <= num < den
  114. * @deprecated Use AVRational instead
  115. */
  116. typedef struct AVFrac {
  117. int64_t val, num, den;
  118. } AVFrac attribute_deprecated;
  119. /*************************************************/
  120. /* input/output formats */
  121. struct AVCodecTag;
  122. struct AVFormatContext;
  123. /** this structure contains the data a format has to probe a file */
  124. typedef struct AVProbeData {
  125. const char *filename;
  126. unsigned char *buf;
  127. int buf_size;
  128. } AVProbeData;
  129. #define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
  130. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  131. typedef struct AVFormatParameters {
  132. AVRational time_base;
  133. int sample_rate;
  134. int channels;
  135. int width;
  136. int height;
  137. enum PixelFormat pix_fmt;
  138. int channel; /**< used to select dv channel */
  139. const char *standard; /**< tv standard, NTSC, PAL, SECAM */
  140. int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
  141. int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
  142. stream packet (only meaningful if
  143. mpeg2ts_raw is TRUE) */
  144. int initial_pause:1; /**< do not begin to play the stream
  145. immediately (RTSP only) */
  146. int prealloced_context:1;
  147. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  148. enum CodecID video_codec_id;
  149. enum CodecID audio_codec_id;
  150. #endif
  151. } AVFormatParameters;
  152. //! demuxer will use url_fopen, no opened file should be provided by the caller
  153. #define AVFMT_NOFILE 0x0001
  154. #define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
  155. #define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
  156. #define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
  157. raw picture data */
  158. #define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
  159. #define AVFMT_NOTIMESTAMPS 0x0080 /**< format does not need / have any timestamps */
  160. #define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
  161. typedef struct AVOutputFormat {
  162. const char *name;
  163. /**
  164. * Descriptive name for the format, meant to be more human-readable
  165. * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
  166. * to define it.
  167. */
  168. const char *long_name;
  169. const char *mime_type;
  170. const char *extensions; /**< comma separated filename extensions */
  171. /** size of private data so that it can be allocated in the wrapper */
  172. int priv_data_size;
  173. /* output support */
  174. enum CodecID audio_codec; /**< default audio codec */
  175. enum CodecID video_codec; /**< default video codec */
  176. int (*write_header)(struct AVFormatContext *);
  177. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  178. int (*write_trailer)(struct AVFormatContext *);
  179. /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
  180. int flags;
  181. /** currently only used to set pixel format if not YUV420P */
  182. int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
  183. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
  184. /**
  185. * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
  186. * the arrays are all CODEC_ID_NONE terminated
  187. */
  188. const struct AVCodecTag **codec_tag;
  189. enum CodecID subtitle_codec; /**< default subtitle codec */
  190. /* private fields */
  191. struct AVOutputFormat *next;
  192. } AVOutputFormat;
  193. typedef struct AVInputFormat {
  194. const char *name;
  195. /**
  196. * Descriptive name for the format, meant to be more human-readable
  197. * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
  198. * to define it.
  199. */
  200. const char *long_name;
  201. /** size of private data so that it can be allocated in the wrapper */
  202. int priv_data_size;
  203. /**
  204. * Tell if a given file has a chance of being parsed by this format.
  205. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  206. * big so you do not have to check for that unless you need more.
  207. */
  208. int (*read_probe)(AVProbeData *);
  209. /** read the format header and initialize the AVFormatContext
  210. structure. Return 0 if OK. 'ap' if non NULL contains
  211. additional paramters. Only used in raw format right
  212. now. 'av_new_stream' should be called to create new streams. */
  213. int (*read_header)(struct AVFormatContext *,
  214. AVFormatParameters *ap);
  215. /** read one packet and put it in 'pkt'. pts and flags are also
  216. set. 'av_new_stream' can be called only if the flag
  217. AVFMTCTX_NOHEADER is used. */
  218. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  219. /** close the stream. The AVFormatContext and AVStreams are not
  220. freed by this function */
  221. int (*read_close)(struct AVFormatContext *);
  222. /**
  223. * seek to a given timestamp relative to the frames in
  224. * stream component stream_index
  225. * @param stream_index must not be -1
  226. * @param flags selects which direction should be preferred if no exact
  227. * match is available
  228. * @return >= 0 on success (but not necessarily the new offset)
  229. */
  230. int (*read_seek)(struct AVFormatContext *,
  231. int stream_index, int64_t timestamp, int flags);
  232. /**
  233. * gets the next timestamp in stream[stream_index].time_base units.
  234. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  235. */
  236. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  237. int64_t *pos, int64_t pos_limit);
  238. /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
  239. int flags;
  240. /** if extensions are defined, then no probe is done. You should
  241. usually not use extension format guessing because it is not
  242. reliable enough */
  243. const char *extensions;
  244. /** general purpose read only value that the format can use */
  245. int value;
  246. /** start/resume playing - only meaningful if using a network based format
  247. (RTSP) */
  248. int (*read_play)(struct AVFormatContext *);
  249. /** pause playing - only meaningful if using a network based format
  250. (RTSP) */
  251. int (*read_pause)(struct AVFormatContext *);
  252. const struct AVCodecTag **codec_tag;
  253. /* private fields */
  254. struct AVInputFormat *next;
  255. } AVInputFormat;
  256. enum AVStreamParseType {
  257. AVSTREAM_PARSE_NONE,
  258. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  259. AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */
  260. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */
  261. };
  262. typedef struct AVIndexEntry {
  263. int64_t pos;
  264. int64_t timestamp;
  265. #define AVINDEX_KEYFRAME 0x0001
  266. int flags:2;
  267. int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs 32 byte due to possible 8byte align).
  268. int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
  269. } AVIndexEntry;
  270. #define AV_DISPOSITION_DEFAULT 0x0001
  271. #define AV_DISPOSITION_DUB 0x0002
  272. #define AV_DISPOSITION_ORIGINAL 0x0004
  273. #define AV_DISPOSITION_COMMENT 0x0008
  274. #define AV_DISPOSITION_LYRICS 0x0010
  275. #define AV_DISPOSITION_KARAOKE 0x0020
  276. /**
  277. * Stream structure.
  278. * New fields can be added to the end with minor version bumps.
  279. * Removal, reordering and changes to existing fields require a major
  280. * version bump.
  281. * sizeof(AVStream) must not be used outside libav*.
  282. */
  283. typedef struct AVStream {
  284. int index; /**< stream index in AVFormatContext */
  285. int id; /**< format specific stream id */
  286. AVCodecContext *codec; /**< codec context */
  287. /**
  288. * Real base frame rate of the stream.
  289. * This is the lowest frame rate with which all timestamps can be
  290. * represented accurately (it is the least common multiple of all
  291. * frame rates in the stream), Note, this value is just a guess!
  292. * For example if the timebase is 1/90000 and all frames have either
  293. * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1.
  294. */
  295. AVRational r_frame_rate;
  296. void *priv_data;
  297. /* internal data used in av_find_stream_info() */
  298. int64_t first_dts;
  299. /** encoding: PTS generation when outputing stream */
  300. struct AVFrac pts;
  301. /**
  302. * This is the fundamental unit of time (in seconds) in terms
  303. * of which frame timestamps are represented. For fixed-fps content,
  304. * timebase should be 1/frame rate and timestamp increments should be
  305. * identically 1.
  306. */
  307. AVRational time_base;
  308. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  309. /* ffmpeg.c private use */
  310. int stream_copy; /**< if set, just copy stream */
  311. enum AVDiscard discard; ///< selects which packets can be discarded at will and do not need to be demuxed
  312. //FIXME move stuff to a flags field?
  313. /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
  314. * MN: dunno if that is the right place for it */
  315. float quality;
  316. /**
  317. * Decoding: pts of the first frame of the stream, in stream time base.
  318. * Only set this if you are absolutely 100% sure that the value you set
  319. * it to really is the pts of the first frame.
  320. * This may be undefined (AV_NOPTS_VALUE).
  321. * @note The ASF header does NOT contain a correct start_time the ASF
  322. * demuxer must NOT set this.
  323. */
  324. int64_t start_time;
  325. /**
  326. * Decoding: duration of the stream, in stream time base.
  327. * If a source file does not specify a duration, but does specify
  328. * a bitrate, this value will be estimates from bit rate and file size.
  329. */
  330. int64_t duration;
  331. char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
  332. /* av_read_frame() support */
  333. enum AVStreamParseType need_parsing;
  334. struct AVCodecParserContext *parser;
  335. int64_t cur_dts;
  336. int last_IP_duration;
  337. int64_t last_IP_pts;
  338. /* av_seek_frame() support */
  339. AVIndexEntry *index_entries; /**< only used if the format does not
  340. support seeking natively */
  341. int nb_index_entries;
  342. unsigned int index_entries_allocated_size;
  343. int64_t nb_frames; ///< number of frames in this stream if known or 0
  344. #define MAX_REORDER_DELAY 4
  345. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  346. char *filename; /**< source filename of the stream */
  347. int disposition; /**< AV_DISPOSITION_* bitfield */
  348. } AVStream;
  349. #define AV_PROGRAM_RUNNING 1
  350. /**
  351. * New fields can be added to the end with minor version bumps.
  352. * Removal, reordering and changes to existing fields require a major
  353. * version bump.
  354. * sizeof(AVProgram) must not be used outside libav*.
  355. */
  356. typedef struct AVProgram {
  357. int id;
  358. char *provider_name; ///< Network name for DVB streams
  359. char *name; ///< Service name for DVB streams
  360. int flags;
  361. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  362. unsigned int *stream_index;
  363. unsigned int nb_stream_indexes;
  364. } AVProgram;
  365. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  366. (streams are added dynamically) */
  367. typedef struct AVChapter {
  368. int id; ///< Unique id to identify the chapter
  369. AVRational time_base; ///< Timebase in which the start/end timestamps are specified
  370. int64_t start, end; ///< chapter start/end time in time_base units
  371. char *title; ///< chapter title
  372. } AVChapter;
  373. #define MAX_STREAMS 20
  374. /**
  375. * format I/O context.
  376. * New fields can be added to the end with minor version bumps.
  377. * Removal, reordering and changes to existing fields require a major
  378. * version bump.
  379. * sizeof(AVFormatContext) must not be used outside libav*.
  380. */
  381. typedef struct AVFormatContext {
  382. const AVClass *av_class; /**< set by av_alloc_format_context */
  383. /* can only be iformat or oformat, not both at the same time */
  384. struct AVInputFormat *iformat;
  385. struct AVOutputFormat *oformat;
  386. void *priv_data;
  387. ByteIOContext *pb;
  388. unsigned int nb_streams;
  389. AVStream *streams[MAX_STREAMS];
  390. char filename[1024]; /**< input or output filename */
  391. /* stream info */
  392. int64_t timestamp;
  393. char title[512];
  394. char author[512];
  395. char copyright[512];
  396. char comment[512];
  397. char album[512];
  398. int year; /**< ID3 year, 0 if none */
  399. int track; /**< track number, 0 if none */
  400. char genre[32]; /**< ID3 genre */
  401. int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
  402. /* private data for pts handling (do not modify directly) */
  403. /** This buffer is only needed when packets were already buffered but
  404. not decoded, for example to get the codec parameters in mpeg
  405. streams */
  406. struct AVPacketList *packet_buffer;
  407. /** decoding: position of the first frame of the component, in
  408. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  409. it is deduced from the AVStream values. */
  410. int64_t start_time;
  411. /** decoding: duration of the stream, in AV_TIME_BASE fractional
  412. seconds. NEVER set this value directly: it is deduced from the
  413. AVStream values. */
  414. int64_t duration;
  415. /** decoding: total file size. 0 if unknown */
  416. int64_t file_size;
  417. /** decoding: total stream bitrate in bit/s, 0 if not
  418. available. Never set it directly if the file_size and the
  419. duration are known as ffmpeg can compute it automatically. */
  420. int bit_rate;
  421. /* av_read_frame() support */
  422. AVStream *cur_st;
  423. const uint8_t *cur_ptr;
  424. int cur_len;
  425. AVPacket cur_pkt;
  426. /* av_seek_frame() support */
  427. int64_t data_offset; /** offset of the first packet */
  428. int index_built;
  429. int mux_rate;
  430. int packet_size;
  431. int preload;
  432. int max_delay;
  433. #define AVFMT_NOOUTPUTLOOP -1
  434. #define AVFMT_INFINITEOUTPUTLOOP 0
  435. /** number of times to loop output in formats that support it */
  436. int loop_output;
  437. int flags;
  438. #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
  439. #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
  440. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input
  441. int loop_input;
  442. /** decoding: size of data to probe; encoding unused */
  443. unsigned int probesize;
  444. /**
  445. * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
  446. */
  447. int max_analyze_duration;
  448. const uint8_t *key;
  449. int keylen;
  450. unsigned int nb_programs;
  451. AVProgram **programs;
  452. /**
  453. * Forced video codec_id.
  454. * demuxing: set by user
  455. */
  456. enum CodecID video_codec_id;
  457. /**
  458. * Forced audio codec_id.
  459. * demuxing: set by user
  460. */
  461. enum CodecID audio_codec_id;
  462. /**
  463. * Forced subtitle codec_id.
  464. * demuxing: set by user
  465. */
  466. enum CodecID subtitle_codec_id;
  467. /**
  468. * Maximum amount of memory in bytes to use per stream for the index.
  469. * If the needed index exceeds this size entries will be discarded as
  470. * needed to maintain a smaller size. This can lead to slower or less
  471. * accurate seeking (depends on demuxer).
  472. * Demuxers for which a full in memory index is mandatory will ignore
  473. * this.
  474. * muxing : unused
  475. * demuxing: set by user
  476. */
  477. unsigned int max_index_size;
  478. /**
  479. * Maximum amount of memory in bytes to use for buffering frames
  480. * obtained from real-time capture devices.
  481. */
  482. unsigned int max_picture_buffer;
  483. unsigned int nb_chapters;
  484. AVChapter **chapters;
  485. } AVFormatContext;
  486. typedef struct AVPacketList {
  487. AVPacket pkt;
  488. struct AVPacketList *next;
  489. } AVPacketList;
  490. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  491. extern AVInputFormat *first_iformat;
  492. extern AVOutputFormat *first_oformat;
  493. #endif
  494. AVInputFormat *av_iformat_next(AVInputFormat *f);
  495. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  496. enum CodecID av_guess_image2_codec(const char *filename);
  497. /* XXX: use automatic init with either ELF sections or C file parser */
  498. /* modules */
  499. /* utils.c */
  500. void av_register_input_format(AVInputFormat *format);
  501. void av_register_output_format(AVOutputFormat *format);
  502. AVOutputFormat *guess_stream_format(const char *short_name,
  503. const char *filename, const char *mime_type);
  504. AVOutputFormat *guess_format(const char *short_name,
  505. const char *filename, const char *mime_type);
  506. /**
  507. * Guesses the codec id based upon muxer and filename.
  508. */
  509. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  510. const char *filename, const char *mime_type, enum CodecType type);
  511. /**
  512. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  513. *
  514. * @param f The file stream pointer where the dump should be sent to.
  515. * @param buf buffer
  516. * @param size buffer size
  517. *
  518. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  519. */
  520. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  521. /**
  522. * Send a nice hexadecimal dump of a buffer to the log.
  523. *
  524. * @param avcl A pointer to an arbitrary struct of which the first field is a
  525. * pointer to an AVClass struct.
  526. * @param level The importance level of the message, lower values signifying
  527. * higher importance.
  528. * @param buf buffer
  529. * @param size buffer size
  530. *
  531. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  532. */
  533. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  534. /**
  535. * Send a nice dump of a packet to the specified file stream.
  536. *
  537. * @param f The file stream pointer where the dump should be sent to.
  538. * @param pkt packet to dump
  539. * @param dump_payload true if the payload must be displayed too
  540. */
  541. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  542. /**
  543. * Send a nice dump of a packet to the log.
  544. *
  545. * @param avcl A pointer to an arbitrary struct of which the first field is a
  546. * pointer to an AVClass struct.
  547. * @param level The importance level of the message, lower values signifying
  548. * higher importance.
  549. * @param pkt packet to dump
  550. * @param dump_payload true if the payload must be displayed too
  551. */
  552. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  553. void av_register_all(void);
  554. /** codec tag <-> codec id */
  555. enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
  556. unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
  557. /* media file input */
  558. /**
  559. * finds AVInputFormat based on input format's short name.
  560. */
  561. AVInputFormat *av_find_input_format(const char *short_name);
  562. /**
  563. * Guess file format.
  564. *
  565. * @param is_opened whether the file is already opened, determines whether
  566. * demuxers with or without AVFMT_NOFILE are probed
  567. */
  568. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  569. /**
  570. * Allocates all the structures needed to read an input stream.
  571. * This does not open the needed codecs for decoding the stream[s].
  572. */
  573. int av_open_input_stream(AVFormatContext **ic_ptr,
  574. ByteIOContext *pb, const char *filename,
  575. AVInputFormat *fmt, AVFormatParameters *ap);
  576. /**
  577. * Open a media file as input. The codecs are not opened. Only the file
  578. * header (if present) is read.
  579. *
  580. * @param ic_ptr the opened media file handle is put here
  581. * @param filename filename to open.
  582. * @param fmt if non NULL, force the file format to use
  583. * @param buf_size optional buffer size (zero if default is OK)
  584. * @param ap additional parameters needed when opening the file (NULL if default)
  585. * @return 0 if OK. AVERROR_xxx otherwise.
  586. */
  587. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  588. AVInputFormat *fmt,
  589. int buf_size,
  590. AVFormatParameters *ap);
  591. /**
  592. * Allocate an AVFormatContext.
  593. * Can be freed with av_free() but do not forget to free everything you
  594. * explicitly allocated as well!
  595. */
  596. AVFormatContext *av_alloc_format_context(void);
  597. /**
  598. * Read packets of a media file to get stream information. This
  599. * is useful for file formats with no headers such as MPEG. This
  600. * function also computes the real frame rate in case of mpeg2 repeat
  601. * frame mode.
  602. * The logical file position is not changed by this function;
  603. * examined packets may be buffered for later processing.
  604. *
  605. * @param ic media file handle
  606. * @return >=0 if OK. AVERROR_xxx if error.
  607. * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
  608. */
  609. int av_find_stream_info(AVFormatContext *ic);
  610. /**
  611. * Read a transport packet from a media file.
  612. *
  613. * This function is obsolete and should never be used.
  614. * Use av_read_frame() instead.
  615. *
  616. * @param s media file handle
  617. * @param pkt is filled
  618. * @return 0 if OK. AVERROR_xxx if error.
  619. */
  620. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  621. /**
  622. * Return the next frame of a stream.
  623. *
  624. * The returned packet is valid
  625. * until the next av_read_frame() or until av_close_input_file() and
  626. * must be freed with av_free_packet. For video, the packet contains
  627. * exactly one frame. For audio, it contains an integer number of
  628. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  629. * data). If the audio frames have a variable size (e.g. MPEG audio),
  630. * then it contains one frame.
  631. *
  632. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  633. * values in AVStream.timebase units (and guessed if the format cannot
  634. * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
  635. * has B frames, so it is better to rely on pkt->dts if you do not
  636. * decompress the payload.
  637. *
  638. * @return 0 if OK, < 0 if error or end of file.
  639. */
  640. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  641. /**
  642. * Seek to the key frame at timestamp.
  643. * 'timestamp' in 'stream_index'.
  644. * @param stream_index If stream_index is (-1), a default
  645. * stream is selected, and timestamp is automatically converted
  646. * from AV_TIME_BASE units to the stream specific time_base.
  647. * @param timestamp timestamp in AVStream.time_base units
  648. * or if there is no stream specified then in AV_TIME_BASE units
  649. * @param flags flags which select direction and seeking mode
  650. * @return >= 0 on success
  651. */
  652. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
  653. /**
  654. * start playing a network based stream (e.g. RTSP stream) at the
  655. * current position
  656. */
  657. int av_read_play(AVFormatContext *s);
  658. /**
  659. * Pause a network based stream (e.g. RTSP stream).
  660. *
  661. * Use av_read_play() to resume it.
  662. */
  663. int av_read_pause(AVFormatContext *s);
  664. /**
  665. * Free a AVFormatContext allocated by av_open_input_stream.
  666. * @param s context to free
  667. */
  668. void av_close_input_stream(AVFormatContext *s);
  669. /**
  670. * Close a media file (but not its codecs).
  671. *
  672. * @param s media file handle
  673. */
  674. void av_close_input_file(AVFormatContext *s);
  675. /**
  676. * Add a new stream to a media file.
  677. *
  678. * Can only be called in the read_header() function. If the flag
  679. * AVFMTCTX_NOHEADER is in the format context, then new streams
  680. * can be added in read_packet too.
  681. *
  682. * @param s media file handle
  683. * @param id file format dependent stream id
  684. */
  685. AVStream *av_new_stream(AVFormatContext *s, int id);
  686. AVProgram *av_new_program(AVFormatContext *s, int id);
  687. /**
  688. * Add a new chapter.
  689. * This function is NOT part of the public API
  690. * and should be ONLY used by demuxers.
  691. *
  692. * @param s media file handle
  693. * @param id unique id for this chapter
  694. * @param start chapter start time in time_base units
  695. * @param end chapter end time in time_base units
  696. * @param title chapter title
  697. *
  698. * @return AVChapter or NULL if error.
  699. */
  700. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
  701. /**
  702. * Set the pts for a given stream.
  703. *
  704. * @param s stream
  705. * @param pts_wrap_bits number of bits effectively used by the pts
  706. * (used for wrap control, 33 is the value for MPEG)
  707. * @param pts_num numerator to convert to seconds (MPEG: 1)
  708. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  709. */
  710. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  711. int pts_num, int pts_den);
  712. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  713. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  714. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
  715. int av_find_default_stream_index(AVFormatContext *s);
  716. /**
  717. * Gets the index for a specific timestamp.
  718. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
  719. * the timestamp which is <= the requested one, if backward is 0
  720. * then it will be >=
  721. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  722. * @return < 0 if no such timestamp could be found
  723. */
  724. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  725. /**
  726. * Ensures the index uses less memory than the maximum specified in
  727. * AVFormatContext.max_index_size, by discarding entries if it grows
  728. * too large.
  729. * This function is not part of the public API and should only be called
  730. * by demuxers.
  731. */
  732. void ff_reduce_index(AVFormatContext *s, int stream_index);
  733. /**
  734. * Add a index entry into a sorted list updateing if it is already there.
  735. *
  736. * @param timestamp timestamp in the timebase of the given stream
  737. */
  738. int av_add_index_entry(AVStream *st,
  739. int64_t pos, int64_t timestamp, int size, int distance, int flags);
  740. /**
  741. * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
  742. * This is not supposed to be called directly by a user application, but by demuxers.
  743. * @param target_ts target timestamp in the time base of the given stream
  744. * @param stream_index stream number
  745. */
  746. int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
  747. /**
  748. * Updates cur_dts of all streams based on given timestamp and AVStream.
  749. *
  750. * Stream ref_st unchanged, others set cur_dts in their native timebase
  751. * only needed for timestamp wrapping or if (dts not set and pts!=dts).
  752. * @param timestamp new dts expressed in time_base of param ref_st
  753. * @param ref_st reference stream giving time_base of param timestamp
  754. */
  755. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  756. /**
  757. * Does a binary search using read_timestamp().
  758. * This is not supposed to be called directly by a user application, but by demuxers.
  759. * @param target_ts target timestamp in the time base of the given stream
  760. * @param stream_index stream number
  761. */
  762. int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  763. /** media file output */
  764. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  765. /**
  766. * Allocate the stream private data and write the stream header to an
  767. * output media file.
  768. *
  769. * @param s media file handle
  770. * @return 0 if OK. AVERROR_xxx if error.
  771. */
  772. int av_write_header(AVFormatContext *s);
  773. /**
  774. * Write a packet to an output media file.
  775. *
  776. * The packet shall contain one audio or video frame.
  777. * The packet must be correctly interleaved according to the container specification,
  778. * if not then av_interleaved_write_frame must be used
  779. *
  780. * @param s media file handle
  781. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  782. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  783. */
  784. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  785. /**
  786. * Writes a packet to an output media file ensuring correct interleaving.
  787. *
  788. * The packet must contain one audio or video frame.
  789. * If the packets are already correctly interleaved the application should
  790. * call av_write_frame() instead as it is slightly faster. It is also important
  791. * to keep in mind that completely non-interleaved input will need huge amounts
  792. * of memory to interleave with this, so it is preferable to interleave at the
  793. * demuxer level.
  794. *
  795. * @param s media file handle
  796. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  797. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  798. */
  799. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  800. /**
  801. * Interleave a packet per DTS in an output media file.
  802. *
  803. * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
  804. * so they cannot be used after it, note calling av_free_packet() on them is still safe.
  805. *
  806. * @param s media file handle
  807. * @param out the interleaved packet will be output here
  808. * @param in the input packet
  809. * @param flush 1 if no further packets are available as input and all
  810. * remaining packets should be output
  811. * @return 1 if a packet was output, 0 if no packet could be output,
  812. * < 0 if an error occurred
  813. */
  814. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
  815. /**
  816. * @brief Write the stream trailer to an output media file and
  817. * free the file private data.
  818. *
  819. * @param s media file handle
  820. * @return 0 if OK. AVERROR_xxx if error.
  821. */
  822. int av_write_trailer(AVFormatContext *s);
  823. void dump_format(AVFormatContext *ic,
  824. int index,
  825. const char *url,
  826. int is_output);
  827. /**
  828. * parses width and height out of string str.
  829. * @deprecated Use av_parse_video_frame_size instead.
  830. */
  831. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  832. /**
  833. * Converts frame rate from string to a fraction.
  834. * @deprecated Use av_parse_video_frame_rate instead.
  835. */
  836. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  837. /**
  838. * Parses \p datestr and returns a corresponding number of microseconds.
  839. * @param datestr String representing a date or a duration.
  840. * - If a date the syntax is:
  841. * @code
  842. * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
  843. * @endcode
  844. * Time is localtime unless Z is appended, in which case it is
  845. * interpreted as UTC.
  846. * If the year-month-day part isn't specified it takes the current
  847. * year-month-day.
  848. * Returns the number of microseconds since 1st of January, 1970 up to
  849. * the time of the parsed date or INT64_MIN if \p datestr cannot be
  850. * successfully parsed.
  851. * - If a duration the syntax is:
  852. * @code
  853. * [-]HH[:MM[:SS[.m...]]]
  854. * [-]S+[.m...]
  855. * @endcode
  856. * Returns the number of microseconds contained in a time interval
  857. * with the specified duration or INT64_MIN if \p datestr cannot be
  858. * successfully parsed.
  859. * @param duration Flag which tells how to interpret \p datestr, if
  860. * not zero \p datestr is interpreted as a duration, otherwise as a
  861. * date.
  862. */
  863. int64_t parse_date(const char *datestr, int duration);
  864. int64_t av_gettime(void);
  865. /* ffm specific for ffserver */
  866. #define FFM_PACKET_SIZE 4096
  867. offset_t ffm_read_write_index(int fd);
  868. void ffm_write_write_index(int fd, offset_t pos);
  869. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  870. /**
  871. * Attempts to find a specific tag in a URL.
  872. *
  873. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  874. * Return 1 if found.
  875. */
  876. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  877. /**
  878. * Returns in 'buf' the path with '%d' replaced by number.
  879. * Also handles the '%0nd' format where 'n' is the total number
  880. * of digits and '%%'.
  881. *
  882. * @param buf destination buffer
  883. * @param buf_size destination buffer size
  884. * @param path numbered sequence string
  885. * @param number frame number
  886. * @return 0 if OK, -1 if format error.
  887. */
  888. int av_get_frame_filename(char *buf, int buf_size,
  889. const char *path, int number);
  890. /**
  891. * Check whether filename actually is a numbered sequence generator.
  892. *
  893. * @param filename possible numbered sequence string
  894. * @return 1 if a valid numbered sequence string, 0 otherwise.
  895. */
  896. int av_filename_number_test(const char *filename);
  897. /**
  898. * Generate an SDP for an RTP session.
  899. *
  900. * @param ac array of AVFormatContexts describing the RTP streams. If the
  901. * array is composed by only one context, such context can contain
  902. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  903. * all the contexts in the array (an AVCodecContext per RTP stream)
  904. * must contain only one AVStream
  905. * @param n_files number of AVCodecContexts contained in ac
  906. * @param buff buffer where the SDP will be stored (must be allocated by
  907. * the caller
  908. * @param size the size of the buffer
  909. * @return 0 if OK. AVERROR_xxx if error.
  910. */
  911. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  912. #ifdef HAVE_AV_CONFIG_H
  913. void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  914. #ifdef __GNUC__
  915. #define dynarray_add(tab, nb_ptr, elem)\
  916. do {\
  917. typeof(tab) _tab = (tab);\
  918. typeof(elem) _elem = (elem);\
  919. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  920. ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  921. } while(0)
  922. #else
  923. #define dynarray_add(tab, nb_ptr, elem)\
  924. do {\
  925. ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
  926. } while(0)
  927. #endif
  928. time_t mktimegm(struct tm *tm);
  929. struct tm *brktimegm(time_t secs, struct tm *tm);
  930. const char *small_strptime(const char *p, const char *fmt,
  931. struct tm *dt);
  932. struct in_addr;
  933. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  934. void url_split(char *proto, int proto_size,
  935. char *authorization, int authorization_size,
  936. char *hostname, int hostname_size,
  937. int *port_ptr,
  938. char *path, int path_size,
  939. const char *url);
  940. int match_ext(const char *filename, const char *extensions);
  941. #endif /* HAVE_AV_CONFIG_H */
  942. #endif /* FFMPEG_AVFORMAT_H */