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.

1369 lines
49KB

  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 54
  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. * I return the LIBAVFORMAT_VERSION_INT constant. You got
  35. * a fucking problem with that, douchebag?
  36. */
  37. unsigned avformat_version(void);
  38. /**
  39. * Returns the libavformat build-time configuration.
  40. */
  41. const char *avformat_configuration(void);
  42. /**
  43. * Returns the libavformat license.
  44. */
  45. const char *avformat_license(void);
  46. #include <time.h>
  47. #include <stdio.h> /* FILE */
  48. #include "libavcodec/avcodec.h"
  49. #include "avio.h"
  50. struct AVFormatContext;
  51. /*
  52. * Public Metadata API.
  53. * The metadata API allows libavformat to export metadata tags to a client
  54. * application using a sequence of key/value pairs.
  55. * Important concepts to keep in mind:
  56. * 1. Keys are unique; there can never be 2 tags with the same key. This is
  57. * also meant semantically, i.e., a demuxer should not knowingly produce
  58. * several keys that are literally different but semantically identical.
  59. * E.g., key=Author5, key=Author6. In this example, all authors must be
  60. * placed in the same tag.
  61. * 2. Metadata is flat, not hierarchical; there are no subtags. If you
  62. * want to store, e.g., the email address of the child of producer Alice
  63. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  64. * 3. Several modifiers can be applied to the tag name. This is done by
  65. * appending a dash character ('-') and the modifier name in the order
  66. * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
  67. * a) language -- a tag whose value is localized for a particular language
  68. * is appended with the ISO 639-2/B 3-letter language code.
  69. * For example: Author-ger=Michael, Author-eng=Mike
  70. * The original/default language is in the unqualified "Author" tag.
  71. * A demuxer should set a default if it sets any translated tag.
  72. * b) sorting -- a modified version of a tag that should be used for
  73. * sorting will have '-sort' appended. E.g. artist="The Beatles",
  74. * artist-sort="Beatles, The".
  75. *
  76. * 4. Tag names are normally exported exactly as stored in the container to
  77. * allow lossless remuxing to the same format. For container-independent
  78. * handling of metadata, av_metadata_conv() can convert it to ffmpeg generic
  79. * format. Follows a list of generic tag names:
  80. *
  81. * album -- name of the set this work belongs to
  82. * album_artist -- main creator of the set/album, if different from artist.
  83. * e.g. "Various Artists" for compilation albums.
  84. * artist -- main creator of the work
  85. * comment -- any additional description of the file.
  86. * composer -- who composed the work, if different from artist.
  87. * copyright -- name of copyright holder.
  88. * date -- date when the work was created, preferably in ISO 8601.
  89. * disc -- number of a subset, e.g. disc in a multi-disc collection.
  90. * encoder -- name/settings of the software/hardware that produced the file.
  91. * encoded_by -- person/group who created the file.
  92. * filename -- original name of the file.
  93. * genre -- <self-evident>.
  94. * language -- main language in which the work is performed, preferably
  95. * in ISO 639-2 format.
  96. * performer -- artist who performed the work, if different from artist.
  97. * E.g for "Also sprach Zarathustra", artist would be "Richard
  98. * Strauss" and performer "London Philharmonic Orchestra".
  99. * publisher -- name of the label/publisher.
  100. * title -- name of the work.
  101. * track -- number of this work in the set, can be in form current/total.
  102. */
  103. #define AV_METADATA_MATCH_CASE 1
  104. #define AV_METADATA_IGNORE_SUFFIX 2
  105. #define AV_METADATA_DONT_STRDUP_KEY 4
  106. #define AV_METADATA_DONT_STRDUP_VAL 8
  107. typedef struct {
  108. char *key;
  109. char *value;
  110. }AVMetadataTag;
  111. typedef struct AVMetadata AVMetadata;
  112. typedef struct AVMetadataConv AVMetadataConv;
  113. /**
  114. * Gets a metadata element with matching key.
  115. * @param prev Set to the previous matching element to find the next.
  116. * @param flags Allows case as well as suffix-insensitive comparisons.
  117. * @return Found tag or NULL, changing key or value leads to undefined behavior.
  118. */
  119. AVMetadataTag *
  120. av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
  121. #if LIBAVFORMAT_VERSION_MAJOR == 52
  122. /**
  123. * Sets the given tag in m, overwriting an existing tag.
  124. * @param key tag key to add to m (will be av_strduped)
  125. * @param value tag value to add to m (will be av_strduped)
  126. * @return >= 0 on success otherwise an error code <0
  127. */
  128. int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
  129. #endif
  130. /**
  131. * Sets the given tag in m, overwriting an existing tag.
  132. * @param key tag key to add to m (will be av_strduped depending on flags)
  133. * @param value tag value to add to m (will be av_strduped depending on flags)
  134. * @return >= 0 on success otherwise an error code <0
  135. */
  136. int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
  137. /**
  138. * Converts all the metadata sets from ctx according to the source and
  139. * destination conversion tables. If one of the tables is NULL, then
  140. * tags are converted to/from ffmpeg generic tag names.
  141. * @param d_conv destination tags format conversion table
  142. * @param s_conv source tags format conversion table
  143. */
  144. void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
  145. const AVMetadataConv *s_conv);
  146. /**
  147. * Frees all the memory allocated for an AVMetadata struct.
  148. */
  149. void av_metadata_free(AVMetadata **m);
  150. /* packet functions */
  151. /**
  152. * Allocates and reads the payload of a packet and initializes its
  153. * fields with default values.
  154. *
  155. * @param pkt packet
  156. * @param size desired payload size
  157. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  158. */
  159. int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
  160. /*************************************************/
  161. /* fractional numbers for exact pts handling */
  162. /**
  163. * The exact value of the fractional number is: 'val + num / den'.
  164. * num is assumed to be 0 <= num < den.
  165. */
  166. typedef struct AVFrac {
  167. int64_t val, num, den;
  168. } AVFrac;
  169. /*************************************************/
  170. /* input/output formats */
  171. struct AVCodecTag;
  172. /** This structure contains the data a format has to probe a file. */
  173. typedef struct AVProbeData {
  174. const char *filename;
  175. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  176. int buf_size; /**< Size of buf except extra allocated bytes */
  177. } AVProbeData;
  178. #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
  179. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  180. typedef struct AVFormatParameters {
  181. AVRational time_base;
  182. int sample_rate;
  183. int channels;
  184. int width;
  185. int height;
  186. enum PixelFormat pix_fmt;
  187. int channel; /**< Used to select DV channel. */
  188. const char *standard; /**< TV standard, NTSC, PAL, SECAM */
  189. unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
  190. unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
  191. stream packet (only meaningful if
  192. mpeg2ts_raw is TRUE). */
  193. unsigned int initial_pause:1; /**< Do not begin to play the stream
  194. immediately (RTSP only). */
  195. unsigned int prealloced_context:1;
  196. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  197. enum CodecID video_codec_id;
  198. enum CodecID audio_codec_id;
  199. #endif
  200. } AVFormatParameters;
  201. //! Demuxer will use url_fopen, no opened file should be provided by the caller.
  202. #define AVFMT_NOFILE 0x0001
  203. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  204. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  205. #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
  206. raw picture data. */
  207. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  208. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  209. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  210. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
  211. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  212. #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
  213. typedef struct AVOutputFormat {
  214. const char *name;
  215. /**
  216. * Descriptive name for the format, meant to be more human-readable
  217. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  218. * to define it.
  219. */
  220. const char *long_name;
  221. const char *mime_type;
  222. const char *extensions; /**< comma-separated filename extensions */
  223. /** size of private data so that it can be allocated in the wrapper */
  224. int priv_data_size;
  225. /* output support */
  226. enum CodecID audio_codec; /**< default audio codec */
  227. enum CodecID video_codec; /**< default video codec */
  228. int (*write_header)(struct AVFormatContext *);
  229. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  230. int (*write_trailer)(struct AVFormatContext *);
  231. /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
  232. int flags;
  233. /** Currently only used to set pixel format if not YUV420P. */
  234. int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
  235. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  236. AVPacket *in, int flush);
  237. /**
  238. * List of supported codec_id-codec_tag pairs, ordered by "better
  239. * choice first". The arrays are all terminated by CODEC_ID_NONE.
  240. */
  241. const struct AVCodecTag * const *codec_tag;
  242. enum CodecID subtitle_codec; /**< default subtitle codec */
  243. const AVMetadataConv *metadata_conv;
  244. /* private fields */
  245. struct AVOutputFormat *next;
  246. } AVOutputFormat;
  247. typedef struct AVInputFormat {
  248. const char *name;
  249. /**
  250. * Descriptive name for the format, meant to be more human-readable
  251. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  252. * to define it.
  253. */
  254. const char *long_name;
  255. /** Size of private data so that it can be allocated in the wrapper. */
  256. int priv_data_size;
  257. /**
  258. * Tell if a given file has a chance of being parsed as this format.
  259. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  260. * big so you do not have to check for that unless you need more.
  261. */
  262. int (*read_probe)(AVProbeData *);
  263. /** Read the format header and initialize the AVFormatContext
  264. structure. Return 0 if OK. 'ap' if non-NULL contains
  265. additional parameters. Only used in raw format right
  266. now. 'av_new_stream' should be called to create new streams. */
  267. int (*read_header)(struct AVFormatContext *,
  268. AVFormatParameters *ap);
  269. /** Read one packet and put it in 'pkt'. pts and flags are also
  270. set. 'av_new_stream' can be called only if the flag
  271. AVFMTCTX_NOHEADER is used.
  272. @return 0 on success, < 0 on error.
  273. When returning an error, pkt must not have been allocated
  274. or must be freed before returning */
  275. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  276. /** Close the stream. The AVFormatContext and AVStreams are not
  277. freed by this function */
  278. int (*read_close)(struct AVFormatContext *);
  279. #if LIBAVFORMAT_VERSION_MAJOR < 53
  280. /**
  281. * Seek to a given timestamp relative to the frames in
  282. * stream component stream_index.
  283. * @param stream_index Must not be -1.
  284. * @param flags Selects which direction should be preferred if no exact
  285. * match is available.
  286. * @return >= 0 on success (but not necessarily the new offset)
  287. */
  288. int (*read_seek)(struct AVFormatContext *,
  289. int stream_index, int64_t timestamp, int flags);
  290. #endif
  291. /**
  292. * Gets the next timestamp in stream[stream_index].time_base units.
  293. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  294. */
  295. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  296. int64_t *pos, int64_t pos_limit);
  297. /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
  298. int flags;
  299. /** If extensions are defined, then no probe is done. You should
  300. usually not use extension format guessing because it is not
  301. reliable enough */
  302. const char *extensions;
  303. /** General purpose read-only value that the format can use. */
  304. int value;
  305. /** Starts/resumes playing - only meaningful if using a network-based format
  306. (RTSP). */
  307. int (*read_play)(struct AVFormatContext *);
  308. /** Pauses playing - only meaningful if using a network-based format
  309. (RTSP). */
  310. int (*read_pause)(struct AVFormatContext *);
  311. const struct AVCodecTag * const *codec_tag;
  312. /**
  313. * Seeks to timestamp ts.
  314. * Seeking will be done so that the point from which all active streams
  315. * can be presented successfully will be closest to ts and within min/max_ts.
  316. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  317. */
  318. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  319. const AVMetadataConv *metadata_conv;
  320. /* private fields */
  321. struct AVInputFormat *next;
  322. } AVInputFormat;
  323. enum AVStreamParseType {
  324. AVSTREAM_PARSE_NONE,
  325. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  326. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  327. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  328. };
  329. typedef struct AVIndexEntry {
  330. int64_t pos;
  331. int64_t timestamp;
  332. #define AVINDEX_KEYFRAME 0x0001
  333. int flags:2;
  334. int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
  335. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  336. } AVIndexEntry;
  337. #define AV_DISPOSITION_DEFAULT 0x0001
  338. #define AV_DISPOSITION_DUB 0x0002
  339. #define AV_DISPOSITION_ORIGINAL 0x0004
  340. #define AV_DISPOSITION_COMMENT 0x0008
  341. #define AV_DISPOSITION_LYRICS 0x0010
  342. #define AV_DISPOSITION_KARAOKE 0x0020
  343. /**
  344. * Stream structure.
  345. * New fields can be added to the end with minor version bumps.
  346. * Removal, reordering and changes to existing fields require a major
  347. * version bump.
  348. * sizeof(AVStream) must not be used outside libav*.
  349. */
  350. typedef struct AVStream {
  351. int index; /**< stream index in AVFormatContext */
  352. int id; /**< format-specific stream ID */
  353. AVCodecContext *codec; /**< codec context */
  354. /**
  355. * Real base framerate of the stream.
  356. * This is the lowest framerate with which all timestamps can be
  357. * represented accurately (it is the least common multiple of all
  358. * framerates in the stream). Note, this value is just a guess!
  359. * For example, if the time base is 1/90000 and all frames have either
  360. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  361. */
  362. AVRational r_frame_rate;
  363. void *priv_data;
  364. /* internal data used in av_find_stream_info() */
  365. int64_t first_dts;
  366. /** encoding: pts generation when outputting stream */
  367. struct AVFrac pts;
  368. /**
  369. * This is the fundamental unit of time (in seconds) in terms
  370. * of which frame timestamps are represented. For fixed-fps content,
  371. * time base should be 1/framerate and timestamp increments should be 1.
  372. */
  373. AVRational time_base;
  374. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  375. /* ffmpeg.c private use */
  376. int stream_copy; /**< If set, just copy stream. */
  377. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  378. //FIXME move stuff to a flags field?
  379. /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
  380. * MN: dunno if that is the right place for it */
  381. float quality;
  382. /**
  383. * Decoding: pts of the first frame of the stream, in stream time base.
  384. * Only set this if you are absolutely 100% sure that the value you set
  385. * it to really is the pts of the first frame.
  386. * This may be undefined (AV_NOPTS_VALUE).
  387. * @note The ASF header does NOT contain a correct start_time the ASF
  388. * demuxer must NOT set this.
  389. */
  390. int64_t start_time;
  391. /**
  392. * Decoding: duration of the stream, in stream time base.
  393. * If a source file does not specify a duration, but does specify
  394. * a bitrate, this value will be estimated from bitrate and file size.
  395. */
  396. int64_t duration;
  397. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  398. char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
  399. #endif
  400. /* av_read_frame() support */
  401. enum AVStreamParseType need_parsing;
  402. struct AVCodecParserContext *parser;
  403. int64_t cur_dts;
  404. int last_IP_duration;
  405. int64_t last_IP_pts;
  406. /* av_seek_frame() support */
  407. AVIndexEntry *index_entries; /**< Only used if the format does not
  408. support seeking natively. */
  409. int nb_index_entries;
  410. unsigned int index_entries_allocated_size;
  411. int64_t nb_frames; ///< number of frames in this stream if known or 0
  412. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  413. int64_t unused[4+1];
  414. char *filename; /**< source filename of the stream */
  415. #endif
  416. int disposition; /**< AV_DISPOSITION_* bit field */
  417. AVProbeData probe_data;
  418. #define MAX_REORDER_DELAY 16
  419. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  420. /**
  421. * sample aspect ratio (0 if unknown)
  422. * - encoding: Set by user.
  423. * - decoding: Set by libavformat.
  424. */
  425. AVRational sample_aspect_ratio;
  426. AVMetadata *metadata;
  427. /* av_read_frame() support */
  428. const uint8_t *cur_ptr;
  429. int cur_len;
  430. AVPacket cur_pkt;
  431. // Timestamp generation support:
  432. /**
  433. * Timestamp corresponding to the last dts sync point.
  434. *
  435. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  436. * a DTS is received from the underlying container. Otherwise set to
  437. * AV_NOPTS_VALUE by default.
  438. */
  439. int64_t reference_dts;
  440. /**
  441. * Number of packets to buffer for codec probing
  442. * NOT PART OF PUBLIC API
  443. */
  444. #define MAX_PROBE_PACKETS 2500
  445. int probe_packets;
  446. /**
  447. * last packet in packet_buffer for this stream when muxing.
  448. * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
  449. */
  450. struct AVPacketList *last_in_packet_buffer;
  451. /**
  452. * Average framerate
  453. */
  454. AVRational avg_frame_rate;
  455. /**
  456. * Number of frames that have been demuxed during av_find_stream_info()
  457. */
  458. int codec_info_nb_frames;
  459. } AVStream;
  460. #define AV_PROGRAM_RUNNING 1
  461. /**
  462. * New fields can be added to the end with minor version bumps.
  463. * Removal, reordering and changes to existing fields require a major
  464. * version bump.
  465. * sizeof(AVProgram) must not be used outside libav*.
  466. */
  467. typedef struct AVProgram {
  468. int id;
  469. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  470. char *provider_name; ///< network name for DVB streams
  471. char *name; ///< service name for DVB streams
  472. #endif
  473. int flags;
  474. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  475. unsigned int *stream_index;
  476. unsigned int nb_stream_indexes;
  477. AVMetadata *metadata;
  478. } AVProgram;
  479. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  480. (streams are added dynamically) */
  481. typedef struct AVChapter {
  482. int id; ///< unique ID to identify the chapter
  483. AVRational time_base; ///< time base in which the start/end timestamps are specified
  484. int64_t start, end; ///< chapter start/end time in time_base units
  485. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  486. char *title; ///< chapter title
  487. #endif
  488. AVMetadata *metadata;
  489. } AVChapter;
  490. #if LIBAVFORMAT_VERSION_MAJOR < 53
  491. #define MAX_STREAMS 20
  492. #else
  493. #define MAX_STREAMS 100
  494. #endif
  495. /**
  496. * Format I/O context.
  497. * New fields can be added to the end with minor version bumps.
  498. * Removal, reordering and changes to existing fields require a major
  499. * version bump.
  500. * sizeof(AVFormatContext) must not be used outside libav*.
  501. */
  502. typedef struct AVFormatContext {
  503. const AVClass *av_class; /**< Set by avformat_alloc_context. */
  504. /* Can only be iformat or oformat, not both at the same time. */
  505. struct AVInputFormat *iformat;
  506. struct AVOutputFormat *oformat;
  507. void *priv_data;
  508. ByteIOContext *pb;
  509. unsigned int nb_streams;
  510. AVStream *streams[MAX_STREAMS];
  511. char filename[1024]; /**< input or output filename */
  512. /* stream info */
  513. int64_t timestamp;
  514. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  515. char title[512];
  516. char author[512];
  517. char copyright[512];
  518. char comment[512];
  519. char album[512];
  520. int year; /**< ID3 year, 0 if none */
  521. int track; /**< track number, 0 if none */
  522. char genre[32]; /**< ID3 genre */
  523. #endif
  524. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  525. /* private data for pts handling (do not modify directly). */
  526. /** This buffer is only needed when packets were already buffered but
  527. not decoded, for example to get the codec parameters in MPEG
  528. streams. */
  529. struct AVPacketList *packet_buffer;
  530. /** Decoding: position of the first frame of the component, in
  531. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  532. It is deduced from the AVStream values. */
  533. int64_t start_time;
  534. /** Decoding: duration of the stream, in AV_TIME_BASE fractional
  535. seconds. NEVER set this value directly: it is deduced from the
  536. AVStream values. */
  537. int64_t duration;
  538. /** decoding: total file size, 0 if unknown */
  539. int64_t file_size;
  540. /** Decoding: total stream bitrate in bit/s, 0 if not
  541. available. Never set it directly if the file_size and the
  542. duration are known as FFmpeg can compute it automatically. */
  543. int bit_rate;
  544. /* av_read_frame() support */
  545. AVStream *cur_st;
  546. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  547. const uint8_t *cur_ptr_deprecated;
  548. int cur_len_deprecated;
  549. AVPacket cur_pkt_deprecated;
  550. #endif
  551. /* av_seek_frame() support */
  552. int64_t data_offset; /** offset of the first packet */
  553. int index_built;
  554. int mux_rate;
  555. unsigned int packet_size;
  556. int preload;
  557. int max_delay;
  558. #define AVFMT_NOOUTPUTLOOP -1
  559. #define AVFMT_INFINITEOUTPUTLOOP 0
  560. /** number of times to loop output in formats that support it */
  561. int loop_output;
  562. int flags;
  563. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  564. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  565. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  566. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  567. int loop_input;
  568. /** decoding: size of data to probe; encoding: unused. */
  569. unsigned int probesize;
  570. /**
  571. * Maximum time (in AV_TIME_BASE units) during which the input should
  572. * be analyzed in av_find_stream_info().
  573. */
  574. int max_analyze_duration;
  575. const uint8_t *key;
  576. int keylen;
  577. unsigned int nb_programs;
  578. AVProgram **programs;
  579. /**
  580. * Forced video codec_id.
  581. * Demuxing: Set by user.
  582. */
  583. enum CodecID video_codec_id;
  584. /**
  585. * Forced audio codec_id.
  586. * Demuxing: Set by user.
  587. */
  588. enum CodecID audio_codec_id;
  589. /**
  590. * Forced subtitle codec_id.
  591. * Demuxing: Set by user.
  592. */
  593. enum CodecID subtitle_codec_id;
  594. /**
  595. * Maximum amount of memory in bytes to use for the index of each stream.
  596. * If the index exceeds this size, entries will be discarded as
  597. * needed to maintain a smaller size. This can lead to slower or less
  598. * accurate seeking (depends on demuxer).
  599. * Demuxers for which a full in-memory index is mandatory will ignore
  600. * this.
  601. * muxing : unused
  602. * demuxing: set by user
  603. */
  604. unsigned int max_index_size;
  605. /**
  606. * Maximum amount of memory in bytes to use for buffering frames
  607. * obtained from realtime capture devices.
  608. */
  609. unsigned int max_picture_buffer;
  610. unsigned int nb_chapters;
  611. AVChapter **chapters;
  612. /**
  613. * Flags to enable debugging.
  614. */
  615. int debug;
  616. #define FF_FDEBUG_TS 0x0001
  617. /**
  618. * Raw packets from the demuxer, prior to parsing and decoding.
  619. * This buffer is used for buffering packets until the codec can
  620. * be identified, as parsing cannot be done without knowing the
  621. * codec.
  622. */
  623. struct AVPacketList *raw_packet_buffer;
  624. struct AVPacketList *raw_packet_buffer_end;
  625. struct AVPacketList *packet_buffer_end;
  626. AVMetadata *metadata;
  627. /**
  628. * Remaining size available for raw_packet_buffer, in bytes.
  629. * NOT PART OF PUBLIC API
  630. */
  631. #define RAW_PACKET_BUFFER_SIZE 2500000
  632. int raw_packet_buffer_remaining_size;
  633. } AVFormatContext;
  634. typedef struct AVPacketList {
  635. AVPacket pkt;
  636. struct AVPacketList *next;
  637. } AVPacketList;
  638. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  639. extern AVInputFormat *first_iformat;
  640. extern AVOutputFormat *first_oformat;
  641. #endif
  642. /**
  643. * If f is NULL, returns the first registered input format,
  644. * if f is non-NULL, returns the next registered input format after f
  645. * or NULL if f is the last one.
  646. */
  647. AVInputFormat *av_iformat_next(AVInputFormat *f);
  648. /**
  649. * If f is NULL, returns the first registered output format,
  650. * if f is non-NULL, returns the next registered output format after f
  651. * or NULL if f is the last one.
  652. */
  653. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  654. enum CodecID av_guess_image2_codec(const char *filename);
  655. /* XXX: Use automatic init with either ELF sections or C file parser */
  656. /* modules. */
  657. /* utils.c */
  658. void av_register_input_format(AVInputFormat *format);
  659. void av_register_output_format(AVOutputFormat *format);
  660. #if LIBAVFORMAT_VERSION_MAJOR < 53
  661. attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
  662. const char *filename,
  663. const char *mime_type);
  664. /**
  665. * @deprecated Use av_guess_format() instead.
  666. */
  667. attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
  668. const char *filename,
  669. const char *mime_type);
  670. #endif
  671. /**
  672. * Returns the output format in the list of registered output formats
  673. * which best matches the provided parameters, or returns NULL if
  674. * there is no match.
  675. *
  676. * @param short_name if non-NULL checks if short_name matches with the
  677. * names of the registered formats
  678. * @param filename if non-NULL checks if filename terminates with the
  679. * extensions of the registered formats
  680. * @param mime_type if non-NULL checks if mime_type matches with the
  681. * MIME type of the registered formats
  682. */
  683. AVOutputFormat *av_guess_format(const char *short_name,
  684. const char *filename,
  685. const char *mime_type);
  686. /**
  687. * Guesses the codec ID based upon muxer and filename.
  688. */
  689. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  690. const char *filename, const char *mime_type,
  691. enum CodecType type);
  692. /**
  693. * Sends a nice hexadecimal dump of a buffer to the specified file stream.
  694. *
  695. * @param f The file stream pointer where the dump should be sent to.
  696. * @param buf buffer
  697. * @param size buffer size
  698. *
  699. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  700. */
  701. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  702. /**
  703. * Sends a nice hexadecimal dump of a buffer to the log.
  704. *
  705. * @param avcl A pointer to an arbitrary struct of which the first field is a
  706. * pointer to an AVClass struct.
  707. * @param level The importance level of the message, lower values signifying
  708. * higher importance.
  709. * @param buf buffer
  710. * @param size buffer size
  711. *
  712. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  713. */
  714. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  715. /**
  716. * Sends a nice dump of a packet to the specified file stream.
  717. *
  718. * @param f The file stream pointer where the dump should be sent to.
  719. * @param pkt packet to dump
  720. * @param dump_payload True if the payload must be displayed, too.
  721. */
  722. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  723. /**
  724. * Sends a nice dump of a packet to the log.
  725. *
  726. * @param avcl A pointer to an arbitrary struct of which the first field is a
  727. * pointer to an AVClass struct.
  728. * @param level The importance level of the message, lower values signifying
  729. * higher importance.
  730. * @param pkt packet to dump
  731. * @param dump_payload True if the payload must be displayed, too.
  732. */
  733. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  734. /**
  735. * Initializes libavformat and registers all the muxers, demuxers and
  736. * protocols. If you do not call this function, then you can select
  737. * exactly which formats you want to support.
  738. *
  739. * @see av_register_input_format()
  740. * @see av_register_output_format()
  741. * @see av_register_protocol()
  742. */
  743. void av_register_all(void);
  744. /** codec tag <-> codec id */
  745. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  746. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  747. /* media file input */
  748. /**
  749. * Finds AVInputFormat based on the short name of the input format.
  750. */
  751. AVInputFormat *av_find_input_format(const char *short_name);
  752. /**
  753. * Guesses the file format.
  754. *
  755. * @param is_opened Whether the file is already opened; determines whether
  756. * demuxers with or without AVFMT_NOFILE are probed.
  757. */
  758. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  759. /**
  760. * Allocates all the structures needed to read an input stream.
  761. * This does not open the needed codecs for decoding the stream[s].
  762. */
  763. int av_open_input_stream(AVFormatContext **ic_ptr,
  764. ByteIOContext *pb, const char *filename,
  765. AVInputFormat *fmt, AVFormatParameters *ap);
  766. /**
  767. * Opens a media file as input. The codecs are not opened. Only the file
  768. * header (if present) is read.
  769. *
  770. * @param ic_ptr The opened media file handle is put here.
  771. * @param filename filename to open
  772. * @param fmt If non-NULL, force the file format to use.
  773. * @param buf_size optional buffer size (zero if default is OK)
  774. * @param ap Additional parameters needed when opening the file
  775. * (NULL if default).
  776. * @return 0 if OK, AVERROR_xxx otherwise
  777. */
  778. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  779. AVInputFormat *fmt,
  780. int buf_size,
  781. AVFormatParameters *ap);
  782. #if LIBAVFORMAT_VERSION_MAJOR < 53
  783. /**
  784. * @deprecated Use avformat_alloc_context() instead.
  785. */
  786. attribute_deprecated AVFormatContext *av_alloc_format_context(void);
  787. #endif
  788. /**
  789. * Allocates an AVFormatContext.
  790. * Can be freed with av_free() but do not forget to free everything you
  791. * explicitly allocated as well!
  792. */
  793. AVFormatContext *avformat_alloc_context(void);
  794. /**
  795. * Reads packets of a media file to get stream information. This
  796. * is useful for file formats with no headers such as MPEG. This
  797. * function also computes the real framerate in case of MPEG-2 repeat
  798. * frame mode.
  799. * The logical file position is not changed by this function;
  800. * examined packets may be buffered for later processing.
  801. *
  802. * @param ic media file handle
  803. * @return >=0 if OK, AVERROR_xxx on error
  804. * @todo Let the user decide somehow what information is needed so that
  805. * we do not waste time getting stuff the user does not need.
  806. */
  807. int av_find_stream_info(AVFormatContext *ic);
  808. /**
  809. * Reads a transport packet from a media file.
  810. *
  811. * This function is obsolete and should never be used.
  812. * Use av_read_frame() instead.
  813. *
  814. * @param s media file handle
  815. * @param pkt is filled
  816. * @return 0 if OK, AVERROR_xxx on error
  817. */
  818. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  819. /**
  820. * Returns the next frame of a stream.
  821. *
  822. * The returned packet is valid
  823. * until the next av_read_frame() or until av_close_input_file() and
  824. * must be freed with av_free_packet. For video, the packet contains
  825. * exactly one frame. For audio, it contains an integer number of
  826. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  827. * data). If the audio frames have a variable size (e.g. MPEG audio),
  828. * then it contains one frame.
  829. *
  830. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  831. * values in AVStream.time_base units (and guessed if the format cannot
  832. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  833. * has B-frames, so it is better to rely on pkt->dts if you do not
  834. * decompress the payload.
  835. *
  836. * @return 0 if OK, < 0 on error or end of file
  837. */
  838. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  839. /**
  840. * Seeks to the keyframe at timestamp.
  841. * 'timestamp' in 'stream_index'.
  842. * @param stream_index If stream_index is (-1), a default
  843. * stream is selected, and timestamp is automatically converted
  844. * from AV_TIME_BASE units to the stream specific time_base.
  845. * @param timestamp Timestamp in AVStream.time_base units
  846. * or, if no stream is specified, in AV_TIME_BASE units.
  847. * @param flags flags which select direction and seeking mode
  848. * @return >= 0 on success
  849. */
  850. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  851. int flags);
  852. /**
  853. * Seeks to timestamp ts.
  854. * Seeking will be done so that the point from which all active streams
  855. * can be presented successfully will be closest to ts and within min/max_ts.
  856. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  857. *
  858. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  859. * are the file position (this may not be supported by all demuxers).
  860. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  861. * in the stream with stream_index (this may not be supported by all demuxers).
  862. * Otherwise all timestamps are in units of the stream selected by stream_index
  863. * or if stream_index is -1, in AV_TIME_BASE units.
  864. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  865. * keyframes (this may not be supported by all demuxers).
  866. *
  867. * @param stream_index index of the stream which is used as time base reference
  868. * @param min_ts smallest acceptable timestamp
  869. * @param ts target timestamp
  870. * @param max_ts largest acceptable timestamp
  871. * @param flags flags
  872. * @returns >=0 on success, error code otherwise
  873. *
  874. * @NOTE This is part of the new seek API which is still under construction.
  875. * Thus do not use this yet. It may change at any time, do not expect
  876. * ABI compatibility yet!
  877. */
  878. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  879. /**
  880. * Starts playing a network-based stream (e.g. RTSP stream) at the
  881. * current position.
  882. */
  883. int av_read_play(AVFormatContext *s);
  884. /**
  885. * Pauses a network-based stream (e.g. RTSP stream).
  886. *
  887. * Use av_read_play() to resume it.
  888. */
  889. int av_read_pause(AVFormatContext *s);
  890. /**
  891. * Frees a AVFormatContext allocated by av_open_input_stream.
  892. * @param s context to free
  893. */
  894. void av_close_input_stream(AVFormatContext *s);
  895. /**
  896. * Closes a media file (but not its codecs).
  897. *
  898. * @param s media file handle
  899. */
  900. void av_close_input_file(AVFormatContext *s);
  901. /**
  902. * Adds a new stream to a media file.
  903. *
  904. * Can only be called in the read_header() function. If the flag
  905. * AVFMTCTX_NOHEADER is in the format context, then new streams
  906. * can be added in read_packet too.
  907. *
  908. * @param s media file handle
  909. * @param id file-format-dependent stream ID
  910. */
  911. AVStream *av_new_stream(AVFormatContext *s, int id);
  912. AVProgram *av_new_program(AVFormatContext *s, int id);
  913. /**
  914. * Adds a new chapter.
  915. * This function is NOT part of the public API
  916. * and should ONLY be used by demuxers.
  917. *
  918. * @param s media file handle
  919. * @param id unique ID for this chapter
  920. * @param start chapter start time in time_base units
  921. * @param end chapter end time in time_base units
  922. * @param title chapter title
  923. *
  924. * @return AVChapter or NULL on error
  925. */
  926. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
  927. int64_t start, int64_t end, const char *title);
  928. /**
  929. * Sets the pts for a given stream.
  930. *
  931. * @param s stream
  932. * @param pts_wrap_bits number of bits effectively used by the pts
  933. * (used for wrap control, 33 is the value for MPEG)
  934. * @param pts_num numerator to convert to seconds (MPEG: 1)
  935. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  936. */
  937. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  938. unsigned int pts_num, unsigned int pts_den);
  939. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  940. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  941. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  942. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  943. int av_find_default_stream_index(AVFormatContext *s);
  944. /**
  945. * Gets the index for a specific timestamp.
  946. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  947. * to the timestamp which is <= the requested one, if backward
  948. * is 0, then it will be >=
  949. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  950. * @return < 0 if no such timestamp could be found
  951. */
  952. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  953. /**
  954. * Ensures the index uses less memory than the maximum specified in
  955. * AVFormatContext.max_index_size by discarding entries if it grows
  956. * too large.
  957. * This function is not part of the public API and should only be called
  958. * by demuxers.
  959. */
  960. void ff_reduce_index(AVFormatContext *s, int stream_index);
  961. /**
  962. * Adds an index entry into a sorted list. Updates the entry if the list
  963. * already contains it.
  964. *
  965. * @param timestamp timestamp in the time base of the given stream
  966. */
  967. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  968. int size, int distance, int flags);
  969. /**
  970. * Does a binary search using av_index_search_timestamp() and
  971. * AVCodec.read_timestamp().
  972. * This is not supposed to be called directly by a user application,
  973. * but by demuxers.
  974. * @param target_ts target timestamp in the time base of the given stream
  975. * @param stream_index stream number
  976. */
  977. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  978. int64_t target_ts, int flags);
  979. /**
  980. * Updates cur_dts of all streams based on the given timestamp and AVStream.
  981. *
  982. * Stream ref_st unchanged, others set cur_dts in their native time base.
  983. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  984. * @param timestamp new dts expressed in time_base of param ref_st
  985. * @param ref_st reference stream giving time_base of param timestamp
  986. */
  987. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  988. /**
  989. * Does a binary search using read_timestamp().
  990. * This is not supposed to be called directly by a user application,
  991. * but by demuxers.
  992. * @param target_ts target timestamp in the time base of the given stream
  993. * @param stream_index stream number
  994. */
  995. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  996. int64_t target_ts, int64_t pos_min,
  997. int64_t pos_max, int64_t pos_limit,
  998. int64_t ts_min, int64_t ts_max,
  999. int flags, int64_t *ts_ret,
  1000. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1001. /** media file output */
  1002. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1003. /**
  1004. * Allocates the stream private data and writes the stream header to an
  1005. * output media file.
  1006. *
  1007. * @param s media file handle
  1008. * @return 0 if OK, AVERROR_xxx on error
  1009. */
  1010. int av_write_header(AVFormatContext *s);
  1011. /**
  1012. * Writes a packet to an output media file.
  1013. *
  1014. * The packet shall contain one audio or video frame.
  1015. * The packet must be correctly interleaved according to the container
  1016. * specification, if not then av_interleaved_write_frame must be used.
  1017. *
  1018. * @param s media file handle
  1019. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1020. dts/pts, ...
  1021. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1022. */
  1023. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1024. /**
  1025. * Writes a packet to an output media file ensuring correct interleaving.
  1026. *
  1027. * The packet must contain one audio or video frame.
  1028. * If the packets are already correctly interleaved, the application should
  1029. * call av_write_frame() instead as it is slightly faster. It is also important
  1030. * to keep in mind that completely non-interleaved input will need huge amounts
  1031. * of memory to interleave with this, so it is preferable to interleave at the
  1032. * demuxer level.
  1033. *
  1034. * @param s media file handle
  1035. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1036. dts/pts, ...
  1037. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1038. */
  1039. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1040. /**
  1041. * Interleaves a packet per dts in an output media file.
  1042. *
  1043. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1044. * function, so they cannot be used after it. Note that calling av_free_packet()
  1045. * on them is still safe.
  1046. *
  1047. * @param s media file handle
  1048. * @param out the interleaved packet will be output here
  1049. * @param in the input packet
  1050. * @param flush 1 if no further packets are available as input and all
  1051. * remaining packets should be output
  1052. * @return 1 if a packet was output, 0 if no packet could be output,
  1053. * < 0 if an error occurred
  1054. */
  1055. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1056. AVPacket *pkt, int flush);
  1057. /**
  1058. * Writes the stream trailer to an output media file and frees the
  1059. * file private data.
  1060. *
  1061. * May only be called after a successful call to av_write_header.
  1062. *
  1063. * @param s media file handle
  1064. * @return 0 if OK, AVERROR_xxx on error
  1065. */
  1066. int av_write_trailer(AVFormatContext *s);
  1067. void dump_format(AVFormatContext *ic,
  1068. int index,
  1069. const char *url,
  1070. int is_output);
  1071. #if LIBAVFORMAT_VERSION_MAJOR < 53
  1072. /**
  1073. * Parses width and height out of string str.
  1074. * @deprecated Use av_parse_video_frame_size instead.
  1075. */
  1076. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
  1077. const char *str);
  1078. /**
  1079. * Converts framerate from a string to a fraction.
  1080. * @deprecated Use av_parse_video_frame_rate instead.
  1081. */
  1082. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
  1083. const char *arg);
  1084. #endif
  1085. /**
  1086. * Parses datestr and returns a corresponding number of microseconds.
  1087. * @param datestr String representing a date or a duration.
  1088. * - If a date the syntax is:
  1089. * @code
  1090. * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
  1091. * @endcode
  1092. * Time is local time unless Z is appended, in which case it is
  1093. * interpreted as UTC.
  1094. * If the year-month-day part is not specified it takes the current
  1095. * year-month-day.
  1096. * Returns the number of microseconds since 1st of January, 1970 up to
  1097. * the time of the parsed date or INT64_MIN if datestr cannot be
  1098. * successfully parsed.
  1099. * - If a duration the syntax is:
  1100. * @code
  1101. * [-]HH[:MM[:SS[.m...]]]
  1102. * [-]S+[.m...]
  1103. * @endcode
  1104. * Returns the number of microseconds contained in a time interval
  1105. * with the specified duration or INT64_MIN if datestr cannot be
  1106. * successfully parsed.
  1107. * @param duration Flag which tells how to interpret datestr, if
  1108. * not zero datestr is interpreted as a duration, otherwise as a
  1109. * date.
  1110. */
  1111. int64_t parse_date(const char *datestr, int duration);
  1112. /** Gets the current time in microseconds. */
  1113. int64_t av_gettime(void);
  1114. /* ffm-specific for ffserver */
  1115. #define FFM_PACKET_SIZE 4096
  1116. int64_t ffm_read_write_index(int fd);
  1117. int ffm_write_write_index(int fd, int64_t pos);
  1118. void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
  1119. /**
  1120. * Attempts to find a specific tag in a URL.
  1121. *
  1122. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  1123. * Return 1 if found.
  1124. */
  1125. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1126. /**
  1127. * Returns in 'buf' the path with '%d' replaced by a number.
  1128. *
  1129. * Also handles the '%0nd' format where 'n' is the total number
  1130. * of digits and '%%'.
  1131. *
  1132. * @param buf destination buffer
  1133. * @param buf_size destination buffer size
  1134. * @param path numbered sequence string
  1135. * @param number frame number
  1136. * @return 0 if OK, -1 on format error
  1137. */
  1138. int av_get_frame_filename(char *buf, int buf_size,
  1139. const char *path, int number);
  1140. /**
  1141. * Checks whether filename actually is a numbered sequence generator.
  1142. *
  1143. * @param filename possible numbered sequence string
  1144. * @return 1 if a valid numbered sequence string, 0 otherwise
  1145. */
  1146. int av_filename_number_test(const char *filename);
  1147. /**
  1148. * Generates an SDP for an RTP session.
  1149. *
  1150. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1151. * array is composed by only one context, such context can contain
  1152. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1153. * all the contexts in the array (an AVCodecContext per RTP stream)
  1154. * must contain only one AVStream.
  1155. * @param n_files number of AVCodecContexts contained in ac
  1156. * @param buff buffer where the SDP will be stored (must be allocated by
  1157. * the caller)
  1158. * @param size the size of the buffer
  1159. * @return 0 if OK, AVERROR_xxx on error
  1160. */
  1161. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1162. #ifdef HAVE_AV_CONFIG_H
  1163. void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
  1164. #ifdef __GNUC__
  1165. #define dynarray_add(tab, nb_ptr, elem)\
  1166. do {\
  1167. __typeof__(tab) _tab = (tab);\
  1168. __typeof__(elem) _elem = (elem);\
  1169. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  1170. ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
  1171. } while(0)
  1172. #else
  1173. #define dynarray_add(tab, nb_ptr, elem)\
  1174. do {\
  1175. ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
  1176. } while(0)
  1177. #endif
  1178. time_t mktimegm(struct tm *tm);
  1179. struct tm *brktimegm(time_t secs, struct tm *tm);
  1180. const char *small_strptime(const char *p, const char *fmt,
  1181. struct tm *dt);
  1182. struct in_addr;
  1183. /* Deprecated, use getaddrinfo instead. */
  1184. attribute_deprecated int resolve_host(struct in_addr *sin_addr, const char *hostname);
  1185. void url_split(char *proto, int proto_size,
  1186. char *authorization, int authorization_size,
  1187. char *hostname, int hostname_size,
  1188. int *port_ptr,
  1189. char *path, int path_size,
  1190. const char *url);
  1191. #if LIBAVFORMAT_VERSION_MAJOR < 53
  1192. /**
  1193. * @deprecated Use av_match_ext() instead.
  1194. */
  1195. attribute_deprecated int match_ext(const char *filename, const char *extensions);
  1196. #endif
  1197. /**
  1198. * Returns a positive value if the given filename has one of the given
  1199. * extensions, 0 otherwise.
  1200. *
  1201. * @param extensions a comma-separated list of filename extensions
  1202. */
  1203. int av_match_ext(const char *filename, const char *extensions);
  1204. #endif /* HAVE_AV_CONFIG_H */
  1205. #endif /* AVFORMAT_AVFORMAT_H */