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.

1079 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 17
  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. unsigned int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
  141. unsigned int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
  142. stream packet (only meaningful if
  143. mpeg2ts_raw is TRUE) */
  144. unsigned int initial_pause:1; /**< do not begin to play the stream
  145. immediately (RTSP only) */
  146. unsigned 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. /**
  486. * Flags to enable debuging.
  487. */
  488. int debug;
  489. #define FF_FDEBUG_TS 0x0001
  490. } AVFormatContext;
  491. typedef struct AVPacketList {
  492. AVPacket pkt;
  493. struct AVPacketList *next;
  494. } AVPacketList;
  495. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  496. extern AVInputFormat *first_iformat;
  497. extern AVOutputFormat *first_oformat;
  498. #endif
  499. AVInputFormat *av_iformat_next(AVInputFormat *f);
  500. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  501. enum CodecID av_guess_image2_codec(const char *filename);
  502. /* XXX: use automatic init with either ELF sections or C file parser */
  503. /* modules */
  504. /* utils.c */
  505. void av_register_input_format(AVInputFormat *format);
  506. void av_register_output_format(AVOutputFormat *format);
  507. AVOutputFormat *guess_stream_format(const char *short_name,
  508. const char *filename, const char *mime_type);
  509. AVOutputFormat *guess_format(const char *short_name,
  510. const char *filename, const char *mime_type);
  511. /**
  512. * Guesses the codec id based upon muxer and filename.
  513. */
  514. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  515. const char *filename, const char *mime_type, enum CodecType type);
  516. /**
  517. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  518. *
  519. * @param f The file stream pointer where the dump should be sent to.
  520. * @param buf buffer
  521. * @param size buffer size
  522. *
  523. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  524. */
  525. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  526. /**
  527. * Send a nice hexadecimal dump of a buffer to the log.
  528. *
  529. * @param avcl A pointer to an arbitrary struct of which the first field is a
  530. * pointer to an AVClass struct.
  531. * @param level The importance level of the message, lower values signifying
  532. * higher importance.
  533. * @param buf buffer
  534. * @param size buffer size
  535. *
  536. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  537. */
  538. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  539. /**
  540. * Send a nice dump of a packet to the specified file stream.
  541. *
  542. * @param f The file stream pointer where the dump should be sent to.
  543. * @param pkt packet to dump
  544. * @param dump_payload true if the payload must be displayed too
  545. */
  546. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  547. /**
  548. * Send a nice dump of a packet to the log.
  549. *
  550. * @param avcl A pointer to an arbitrary struct of which the first field is a
  551. * pointer to an AVClass struct.
  552. * @param level The importance level of the message, lower values signifying
  553. * higher importance.
  554. * @param pkt packet to dump
  555. * @param dump_payload true if the payload must be displayed too
  556. */
  557. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  558. void av_register_all(void);
  559. /** codec tag <-> codec id */
  560. enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
  561. unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
  562. /* media file input */
  563. /**
  564. * finds AVInputFormat based on input format's short name.
  565. */
  566. AVInputFormat *av_find_input_format(const char *short_name);
  567. /**
  568. * Guess file format.
  569. *
  570. * @param is_opened whether the file is already opened, determines whether
  571. * demuxers with or without AVFMT_NOFILE are probed
  572. */
  573. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  574. /**
  575. * Allocates all the structures needed to read an input stream.
  576. * This does not open the needed codecs for decoding the stream[s].
  577. */
  578. int av_open_input_stream(AVFormatContext **ic_ptr,
  579. ByteIOContext *pb, const char *filename,
  580. AVInputFormat *fmt, AVFormatParameters *ap);
  581. /**
  582. * Open a media file as input. The codecs are not opened. Only the file
  583. * header (if present) is read.
  584. *
  585. * @param ic_ptr the opened media file handle is put here
  586. * @param filename filename to open.
  587. * @param fmt if non NULL, force the file format to use
  588. * @param buf_size optional buffer size (zero if default is OK)
  589. * @param ap additional parameters needed when opening the file (NULL if default)
  590. * @return 0 if OK. AVERROR_xxx otherwise.
  591. */
  592. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  593. AVInputFormat *fmt,
  594. int buf_size,
  595. AVFormatParameters *ap);
  596. /**
  597. * Allocate an AVFormatContext.
  598. * Can be freed with av_free() but do not forget to free everything you
  599. * explicitly allocated as well!
  600. */
  601. AVFormatContext *av_alloc_format_context(void);
  602. /**
  603. * Read packets of a media file to get stream information. This
  604. * is useful for file formats with no headers such as MPEG. This
  605. * function also computes the real frame rate in case of mpeg2 repeat
  606. * frame mode.
  607. * The logical file position is not changed by this function;
  608. * examined packets may be buffered for later processing.
  609. *
  610. * @param ic media file handle
  611. * @return >=0 if OK. AVERROR_xxx if error.
  612. * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need.
  613. */
  614. int av_find_stream_info(AVFormatContext *ic);
  615. /**
  616. * Read a transport packet from a media file.
  617. *
  618. * This function is obsolete and should never be used.
  619. * Use av_read_frame() instead.
  620. *
  621. * @param s media file handle
  622. * @param pkt is filled
  623. * @return 0 if OK. AVERROR_xxx if error.
  624. */
  625. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  626. /**
  627. * Return the next frame of a stream.
  628. *
  629. * The returned packet is valid
  630. * until the next av_read_frame() or until av_close_input_file() and
  631. * must be freed with av_free_packet. For video, the packet contains
  632. * exactly one frame. For audio, it contains an integer number of
  633. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  634. * data). If the audio frames have a variable size (e.g. MPEG audio),
  635. * then it contains one frame.
  636. *
  637. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  638. * values in AVStream.timebase units (and guessed if the format cannot
  639. * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
  640. * has B frames, so it is better to rely on pkt->dts if you do not
  641. * decompress the payload.
  642. *
  643. * @return 0 if OK, < 0 if error or end of file.
  644. */
  645. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  646. /**
  647. * Seek to the key frame at timestamp.
  648. * 'timestamp' in 'stream_index'.
  649. * @param stream_index If stream_index is (-1), a default
  650. * stream is selected, and timestamp is automatically converted
  651. * from AV_TIME_BASE units to the stream specific time_base.
  652. * @param timestamp timestamp in AVStream.time_base units
  653. * or if there is no stream specified then in AV_TIME_BASE units
  654. * @param flags flags which select direction and seeking mode
  655. * @return >= 0 on success
  656. */
  657. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
  658. /**
  659. * start playing a network based stream (e.g. RTSP stream) at the
  660. * current position
  661. */
  662. int av_read_play(AVFormatContext *s);
  663. /**
  664. * Pause a network based stream (e.g. RTSP stream).
  665. *
  666. * Use av_read_play() to resume it.
  667. */
  668. int av_read_pause(AVFormatContext *s);
  669. /**
  670. * Free a AVFormatContext allocated by av_open_input_stream.
  671. * @param s context to free
  672. */
  673. void av_close_input_stream(AVFormatContext *s);
  674. /**
  675. * Close a media file (but not its codecs).
  676. *
  677. * @param s media file handle
  678. */
  679. void av_close_input_file(AVFormatContext *s);
  680. /**
  681. * Add a new stream to a media file.
  682. *
  683. * Can only be called in the read_header() function. If the flag
  684. * AVFMTCTX_NOHEADER is in the format context, then new streams
  685. * can be added in read_packet too.
  686. *
  687. * @param s media file handle
  688. * @param id file format dependent stream id
  689. */
  690. AVStream *av_new_stream(AVFormatContext *s, int id);
  691. AVProgram *av_new_program(AVFormatContext *s, int id);
  692. /**
  693. * Add a new chapter.
  694. * This function is NOT part of the public API
  695. * and should be ONLY used by demuxers.
  696. *
  697. * @param s media file handle
  698. * @param id unique id for this chapter
  699. * @param start chapter start time in time_base units
  700. * @param end chapter end time in time_base units
  701. * @param title chapter title
  702. *
  703. * @return AVChapter or NULL if error.
  704. */
  705. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title);
  706. /**
  707. * Set the pts for a given stream.
  708. *
  709. * @param s stream
  710. * @param pts_wrap_bits number of bits effectively used by the pts
  711. * (used for wrap control, 33 is the value for MPEG)
  712. * @param pts_num numerator to convert to seconds (MPEG: 1)
  713. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  714. */
  715. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  716. int pts_num, int pts_den);
  717. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  718. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  719. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
  720. int av_find_default_stream_index(AVFormatContext *s);
  721. /**
  722. * Gets the index for a specific timestamp.
  723. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
  724. * the timestamp which is <= the requested one, if backward is 0
  725. * then it will be >=
  726. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  727. * @return < 0 if no such timestamp could be found
  728. */
  729. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  730. /**
  731. * Ensures the index uses less memory than the maximum specified in
  732. * AVFormatContext.max_index_size, by discarding entries if it grows
  733. * too large.
  734. * This function is not part of the public API and should only be called
  735. * by demuxers.
  736. */
  737. void ff_reduce_index(AVFormatContext *s, int stream_index);
  738. /**
  739. * Add a index entry into a sorted list updateing if it is already there.
  740. *
  741. * @param timestamp timestamp in the timebase of the given stream
  742. */
  743. int av_add_index_entry(AVStream *st,
  744. int64_t pos, int64_t timestamp, int size, int distance, int flags);
  745. /**
  746. * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
  747. * This is not supposed to be called directly by a user application, but by demuxers.
  748. * @param target_ts target timestamp in the time base of the given stream
  749. * @param stream_index stream number
  750. */
  751. int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
  752. /**
  753. * Updates cur_dts of all streams based on given timestamp and AVStream.
  754. *
  755. * Stream ref_st unchanged, others set cur_dts in their native timebase
  756. * only needed for timestamp wrapping or if (dts not set and pts!=dts).
  757. * @param timestamp new dts expressed in time_base of param ref_st
  758. * @param ref_st reference stream giving time_base of param timestamp
  759. */
  760. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  761. /**
  762. * Does a binary search using read_timestamp().
  763. * This is not supposed to be called directly by a user application, but by demuxers.
  764. * @param target_ts target timestamp in the time base of the given stream
  765. * @param stream_index stream number
  766. */
  767. 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 ));
  768. /** media file output */
  769. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  770. /**
  771. * Allocate the stream private data and write the stream header to an
  772. * output media file.
  773. *
  774. * @param s media file handle
  775. * @return 0 if OK. AVERROR_xxx if error.
  776. */
  777. int av_write_header(AVFormatContext *s);
  778. /**
  779. * Write a packet to an output media file.
  780. *
  781. * The packet shall contain one audio or video frame.
  782. * The packet must be correctly interleaved according to the container specification,
  783. * if not then av_interleaved_write_frame must be used
  784. *
  785. * @param s media file handle
  786. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  787. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  788. */
  789. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  790. /**
  791. * Writes a packet to an output media file ensuring correct interleaving.
  792. *
  793. * The packet must contain one audio or video frame.
  794. * If the packets are already correctly interleaved the application should
  795. * call av_write_frame() instead as it is slightly faster. It is also important
  796. * to keep in mind that completely non-interleaved input will need huge amounts
  797. * of memory to interleave with this, so it is preferable to interleave at the
  798. * demuxer level.
  799. *
  800. * @param s media file handle
  801. * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
  802. * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
  803. */
  804. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  805. /**
  806. * Interleave a packet per DTS in an output media file.
  807. *
  808. * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
  809. * so they cannot be used after it, note calling av_free_packet() on them is still safe.
  810. *
  811. * @param s media file handle
  812. * @param out the interleaved packet will be output here
  813. * @param in the input packet
  814. * @param flush 1 if no further packets are available as input and all
  815. * remaining packets should be output
  816. * @return 1 if a packet was output, 0 if no packet could be output,
  817. * < 0 if an error occurred
  818. */
  819. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
  820. /**
  821. * @brief Write the stream trailer to an output media file and
  822. * free the file private data.
  823. *
  824. * @param s media file handle
  825. * @return 0 if OK. AVERROR_xxx if error.
  826. */
  827. int av_write_trailer(AVFormatContext *s);
  828. void dump_format(AVFormatContext *ic,
  829. int index,
  830. const char *url,
  831. int is_output);
  832. /**
  833. * parses width and height out of string str.
  834. * @deprecated Use av_parse_video_frame_size instead.
  835. */
  836. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  837. /**
  838. * Converts frame rate from string to a fraction.
  839. * @deprecated Use av_parse_video_frame_rate instead.
  840. */
  841. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  842. /**
  843. * Parses \p datestr and returns a corresponding number of microseconds.
  844. * @param datestr String representing a date or a duration.
  845. * - If a date the syntax is:
  846. * @code
  847. * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
  848. * @endcode
  849. * Time is localtime unless Z is appended, in which case it is
  850. * interpreted as UTC.
  851. * If the year-month-day part isn't specified it takes the current
  852. * year-month-day.
  853. * Returns the number of microseconds since 1st of January, 1970 up to
  854. * the time of the parsed date or INT64_MIN if \p datestr cannot be
  855. * successfully parsed.
  856. * - If a duration the syntax is:
  857. * @code
  858. * [-]HH[:MM[:SS[.m...]]]
  859. * [-]S+[.m...]
  860. * @endcode
  861. * Returns the number of microseconds contained in a time interval
  862. * with the specified duration or INT64_MIN if \p datestr cannot be
  863. * successfully parsed.
  864. * @param duration Flag which tells how to interpret \p datestr, if
  865. * not zero \p datestr is interpreted as a duration, otherwise as a
  866. * date.
  867. */
  868. int64_t parse_date(const char *datestr, int duration);
  869. int64_t av_gettime(void);
  870. /* ffm specific for ffserver */
  871. #define FFM_PACKET_SIZE 4096
  872. offset_t ffm_read_write_index(int fd);
  873. void ffm_write_write_index(int fd, offset_t pos);
  874. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  875. /**
  876. * Attempts to find a specific tag in a URL.
  877. *
  878. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  879. * Return 1 if found.
  880. */
  881. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  882. /**
  883. * Returns in 'buf' the path with '%d' replaced by number.
  884. * Also handles the '%0nd' format where 'n' is the total number
  885. * of digits and '%%'.
  886. *
  887. * @param buf destination buffer
  888. * @param buf_size destination buffer size
  889. * @param path numbered sequence string
  890. * @param number frame number
  891. * @return 0 if OK, -1 if format error.
  892. */
  893. int av_get_frame_filename(char *buf, int buf_size,
  894. const char *path, int number);
  895. /**
  896. * Check whether filename actually is a numbered sequence generator.
  897. *
  898. * @param filename possible numbered sequence string
  899. * @return 1 if a valid numbered sequence string, 0 otherwise.
  900. */
  901. int av_filename_number_test(const char *filename);
  902. /**
  903. * Generate an SDP for an RTP session.
  904. *
  905. * @param ac array of AVFormatContexts describing the RTP streams. If the
  906. * array is composed by only one context, such context can contain
  907. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  908. * all the contexts in the array (an AVCodecContext per RTP stream)
  909. * must contain only one AVStream
  910. * @param n_files number of AVCodecContexts contained in ac
  911. * @param buff buffer where the SDP will be stored (must be allocated by
  912. * the caller
  913. * @param size the size of the buffer
  914. * @return 0 if OK. AVERROR_xxx if error.
  915. */
  916. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  917. #ifdef HAVE_AV_CONFIG_H
  918. void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  919. #ifdef __GNUC__
  920. #define dynarray_add(tab, nb_ptr, elem)\
  921. do {\
  922. typeof(tab) _tab = (tab);\
  923. typeof(elem) _elem = (elem);\
  924. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  925. ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  926. } while(0)
  927. #else
  928. #define dynarray_add(tab, nb_ptr, elem)\
  929. do {\
  930. ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
  931. } while(0)
  932. #endif
  933. time_t mktimegm(struct tm *tm);
  934. struct tm *brktimegm(time_t secs, struct tm *tm);
  935. const char *small_strptime(const char *p, const char *fmt,
  936. struct tm *dt);
  937. struct in_addr;
  938. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  939. void url_split(char *proto, int proto_size,
  940. char *authorization, int authorization_size,
  941. char *hostname, int hostname_size,
  942. int *port_ptr,
  943. char *path, int path_size,
  944. const char *url);
  945. int match_ext(const char *filename, const char *extensions);
  946. #endif /* HAVE_AV_CONFIG_H */
  947. #endif /* FFMPEG_AVFORMAT_H */