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.

1112 lines
39KB

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