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.

898 lines
31KB

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