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.

627 lines
19KB

  1. #ifndef AVFORMAT_H
  2. #define AVFORMAT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define LIBAVFORMAT_BUILD 4610
  7. #define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
  8. #define LIBAVFORMAT_VERSION FFMPEG_VERSION
  9. #define LIBAVFORMAT_IDENT "FFmpeg" FFMPEG_VERSION "b" AV_STRINGIFY(LIBAVFORMAT_BUILD)
  10. #include <time.h>
  11. #include "avcodec.h"
  12. #include "avio.h"
  13. /* packet functions */
  14. #ifndef MAXINT64
  15. #define MAXINT64 int64_t_C(0x7fffffffffffffff)
  16. #endif
  17. #ifndef MININT64
  18. #define MININT64 int64_t_C(0x8000000000000000)
  19. #endif
  20. #define AV_NOPTS_VALUE MININT64
  21. #define AV_TIME_BASE 1000000
  22. typedef struct AVPacket {
  23. int64_t pts; /* presentation time stamp in AV_TIME_BASE units (or
  24. pts_den units in muxers or demuxers) */
  25. int64_t dts; /* decompression time stamp in AV_TIME_BASE units (or
  26. pts_den units in muxers or demuxers) */
  27. uint8_t *data;
  28. int size;
  29. int stream_index;
  30. int flags;
  31. int duration; /* presentation duration (0 if not available) */
  32. void (*destruct)(struct AVPacket *);
  33. void *priv;
  34. } AVPacket;
  35. #define PKT_FLAG_KEY 0x0001
  36. /* initialize optional fields of a packet */
  37. static inline void av_init_packet(AVPacket *pkt)
  38. {
  39. pkt->pts = AV_NOPTS_VALUE;
  40. pkt->dts = AV_NOPTS_VALUE;
  41. pkt->duration = 0;
  42. pkt->flags = 0;
  43. pkt->stream_index = 0;
  44. }
  45. int av_new_packet(AVPacket *pkt, int size);
  46. int av_dup_packet(AVPacket *pkt);
  47. /**
  48. * Free a packet
  49. *
  50. * @param pkt packet to free
  51. */
  52. static inline void av_free_packet(AVPacket *pkt)
  53. {
  54. if (pkt && pkt->destruct) {
  55. pkt->destruct(pkt);
  56. }
  57. }
  58. /*************************************************/
  59. /* fractional numbers for exact pts handling */
  60. /* the exact value of the fractional number is: 'val + num / den'. num
  61. is assumed to be such as 0 <= num < den */
  62. typedef struct AVFrac {
  63. int64_t val, num, den;
  64. } AVFrac;
  65. void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
  66. void av_frac_add(AVFrac *f, int64_t incr);
  67. void av_frac_set(AVFrac *f, int64_t val);
  68. /*************************************************/
  69. /* input/output formats */
  70. struct AVFormatContext;
  71. /* this structure contains the data a format has to probe a file */
  72. typedef struct AVProbeData {
  73. const char *filename;
  74. unsigned char *buf;
  75. int buf_size;
  76. } AVProbeData;
  77. #define AVPROBE_SCORE_MAX 100
  78. typedef struct AVFormatParameters {
  79. int frame_rate;
  80. int frame_rate_base;
  81. int sample_rate;
  82. int channels;
  83. int width;
  84. int height;
  85. enum PixelFormat pix_fmt;
  86. struct AVImageFormat *image_format;
  87. int channel; /* used to select dv channel */
  88. const char *device; /* video4linux, audio or DV device */
  89. const char *standard; /* tv standard, NTSC, PAL, SECAM */
  90. int mpeg2ts_raw:1; /* force raw MPEG2 transport stream output, if possible */
  91. int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport
  92. stream packet (only meaningful if
  93. mpeg2ts_raw is TRUE */
  94. int initial_pause:1; /* do not begin to play the stream
  95. immediately (RTSP only) */
  96. } AVFormatParameters;
  97. #define AVFMT_NOFILE 0x0001 /* no file should be opened */
  98. #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
  99. #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
  100. #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
  101. raw picture data */
  102. typedef struct AVOutputFormat {
  103. const char *name;
  104. const char *long_name;
  105. const char *mime_type;
  106. const char *extensions; /* comma separated extensions */
  107. /* size of private data so that it can be allocated in the wrapper */
  108. int priv_data_size;
  109. /* output support */
  110. enum CodecID audio_codec; /* default audio codec */
  111. enum CodecID video_codec; /* default video codec */
  112. int (*write_header)(struct AVFormatContext *);
  113. int (*write_packet)(struct AVFormatContext *,
  114. int stream_index,
  115. const uint8_t *buf, int size, int64_t pts);
  116. int (*write_trailer)(struct AVFormatContext *);
  117. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
  118. int flags;
  119. /* currently only used to set pixel format if not YUV420P */
  120. int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
  121. /* private fields */
  122. struct AVOutputFormat *next;
  123. } AVOutputFormat;
  124. typedef struct AVInputFormat {
  125. const char *name;
  126. const char *long_name;
  127. /* size of private data so that it can be allocated in the wrapper */
  128. int priv_data_size;
  129. /* tell if a given file has a chance of being parsing by this format */
  130. int (*read_probe)(AVProbeData *);
  131. /* read the format header and initialize the AVFormatContext
  132. structure. Return 0 if OK. 'ap' if non NULL contains
  133. additionnal paramters. Only used in raw format right
  134. now. 'av_new_stream' should be called to create new streams. */
  135. int (*read_header)(struct AVFormatContext *,
  136. AVFormatParameters *ap);
  137. /* read one packet and put it in 'pkt'. pts and flags are also
  138. set. 'av_new_stream' can be called only if the flag
  139. AVFMTCTX_NOHEADER is used. */
  140. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  141. /* close the stream. The AVFormatContext and AVStreams are not
  142. freed by this function */
  143. int (*read_close)(struct AVFormatContext *);
  144. /* seek at or before a given timestamp (given in AV_TIME_BASE
  145. units) relative to the frames in stream component stream_index */
  146. int (*read_seek)(struct AVFormatContext *,
  147. int stream_index, int64_t timestamp);
  148. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
  149. int flags;
  150. /* if extensions are defined, then no probe is done. You should
  151. usually not use extension format guessing because it is not
  152. reliable enough */
  153. const char *extensions;
  154. /* general purpose read only value that the format can use */
  155. int value;
  156. /* start/resume playing - only meaningful if using a network based format
  157. (RTSP) */
  158. int (*read_play)(struct AVFormatContext *);
  159. /* pause playing - only meaningful if using a network based format
  160. (RTSP) */
  161. int (*read_pause)(struct AVFormatContext *);
  162. /* private fields */
  163. struct AVInputFormat *next;
  164. } AVInputFormat;
  165. typedef struct AVIndexEntry {
  166. int64_t pos;
  167. int64_t timestamp;
  168. #define AVINDEX_KEYFRAME 0x0001
  169. int flags;
  170. } AVIndexEntry;
  171. typedef struct AVStream {
  172. int index; /* stream index in AVFormatContext */
  173. int id; /* format specific stream id */
  174. AVCodecContext codec; /* codec context */
  175. int r_frame_rate; /* real frame rate of the stream */
  176. int r_frame_rate_base;/* real frame rate base of the stream */
  177. void *priv_data;
  178. /* internal data used in av_find_stream_info() */
  179. int64_t codec_info_duration;
  180. int codec_info_nb_frames;
  181. /* encoding: PTS generation when outputing stream */
  182. AVFrac pts;
  183. /* ffmpeg.c private use */
  184. int stream_copy; /* if TRUE, just copy stream */
  185. /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
  186. * MN:dunno if thats the right place, for it */
  187. float quality;
  188. /* decoding: position of the first frame of the component, in
  189. AV_TIME_BASE fractional seconds. */
  190. int64_t start_time;
  191. /* decoding: duration of the stream, in AV_TIME_BASE fractional
  192. seconds. */
  193. int64_t duration;
  194. /* av_read_frame() support */
  195. int need_parsing;
  196. struct AVCodecParserContext *parser;
  197. int got_frame;
  198. int64_t cur_frame_pts;
  199. int64_t cur_frame_dts;
  200. int64_t cur_dts;
  201. int last_IP_duration;
  202. /* av_seek_frame() support */
  203. AVIndexEntry *index_entries; /* only used if the format does not
  204. support seeking natively */
  205. int nb_index_entries;
  206. int index_entries_allocated_size;
  207. } AVStream;
  208. #define AVFMTCTX_NOHEADER 0x0001 /* signal that no header is present
  209. (streams are added dynamically) */
  210. #define MAX_STREAMS 20
  211. /* format I/O context */
  212. typedef struct AVFormatContext {
  213. /* can only be iformat or oformat, not both at the same time */
  214. struct AVInputFormat *iformat;
  215. struct AVOutputFormat *oformat;
  216. void *priv_data;
  217. ByteIOContext pb;
  218. int nb_streams;
  219. AVStream *streams[MAX_STREAMS];
  220. char filename[1024]; /* input or output filename */
  221. /* stream info */
  222. char title[512];
  223. char author[512];
  224. char copyright[512];
  225. char comment[512];
  226. char album[512];
  227. int year; /* ID3 year, 0 if none */
  228. int track; /* track number, 0 if none */
  229. char genre[32]; /* ID3 genre */
  230. int ctx_flags; /* format specific flags, see AVFMTCTX_xx */
  231. /* private data for pts handling (do not modify directly) */
  232. int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
  233. int pts_num, pts_den; /* value to convert to seconds */
  234. /* This buffer is only needed when packets were already buffered but
  235. not decoded, for example to get the codec parameters in mpeg
  236. streams */
  237. struct AVPacketList *packet_buffer;
  238. /* decoding: position of the first frame of the component, in
  239. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  240. it is deduced from the AVStream values. */
  241. int64_t start_time;
  242. /* decoding: duration of the stream, in AV_TIME_BASE fractional
  243. seconds. NEVER set this value directly: it is deduced from the
  244. AVStream values. */
  245. int64_t duration;
  246. /* decoding: total file size. 0 if unknown */
  247. int64_t file_size;
  248. /* decoding: total stream bitrate in bit/s, 0 if not
  249. available. Never set it directly if the file_size and the
  250. duration are known as ffmpeg can compute it automatically. */
  251. int bit_rate;
  252. /* av_read_frame() support */
  253. AVStream *cur_st;
  254. const uint8_t *cur_ptr;
  255. int cur_len;
  256. AVPacket cur_pkt;
  257. /* the following are used for pts/dts unit conversion */
  258. int64_t last_pkt_stream_pts;
  259. int64_t last_pkt_stream_dts;
  260. int64_t last_pkt_pts;
  261. int64_t last_pkt_dts;
  262. int last_pkt_pts_frac;
  263. int last_pkt_dts_frac;
  264. /* av_seek_frame() support */
  265. int64_t data_offset; /* offset of the first packet */
  266. int index_built;
  267. } AVFormatContext;
  268. typedef struct AVPacketList {
  269. AVPacket pkt;
  270. struct AVPacketList *next;
  271. } AVPacketList;
  272. extern AVInputFormat *first_iformat;
  273. extern AVOutputFormat *first_oformat;
  274. /* still image support */
  275. struct AVInputImageContext;
  276. typedef struct AVInputImageContext AVInputImageContext;
  277. typedef struct AVImageInfo {
  278. enum PixelFormat pix_fmt; /* requested pixel format */
  279. int width; /* requested width */
  280. int height; /* requested height */
  281. int interleaved; /* image is interleaved (e.g. interleaved GIF) */
  282. AVPicture pict; /* returned allocated image */
  283. } AVImageInfo;
  284. /* AVImageFormat.flags field constants */
  285. #define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
  286. typedef struct AVImageFormat {
  287. const char *name;
  288. const char *extensions;
  289. /* tell if a given file has a chance of being parsing by this format */
  290. int (*img_probe)(AVProbeData *);
  291. /* read a whole image. 'alloc_cb' is called when the image size is
  292. known so that the caller can allocate the image. If 'allo_cb'
  293. returns non zero, then the parsing is aborted. Return '0' if
  294. OK. */
  295. int (*img_read)(ByteIOContext *,
  296. int (*alloc_cb)(void *, AVImageInfo *info), void *);
  297. /* write the image */
  298. int supported_pixel_formats; /* mask of supported formats for output */
  299. int (*img_write)(ByteIOContext *, AVImageInfo *);
  300. int flags;
  301. struct AVImageFormat *next;
  302. } AVImageFormat;
  303. void av_register_image_format(AVImageFormat *img_fmt);
  304. AVImageFormat *av_probe_image_format(AVProbeData *pd);
  305. AVImageFormat *guess_image_format(const char *filename);
  306. int av_read_image(ByteIOContext *pb, const char *filename,
  307. AVImageFormat *fmt,
  308. int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
  309. int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
  310. extern AVImageFormat *first_image_format;
  311. extern AVImageFormat pnm_image_format;
  312. extern AVImageFormat pbm_image_format;
  313. extern AVImageFormat pgm_image_format;
  314. extern AVImageFormat ppm_image_format;
  315. extern AVImageFormat pam_image_format;
  316. extern AVImageFormat pgmyuv_image_format;
  317. extern AVImageFormat yuv_image_format;
  318. #ifdef CONFIG_ZLIB
  319. extern AVImageFormat png_image_format;
  320. #endif
  321. extern AVImageFormat jpeg_image_format;
  322. extern AVImageFormat gif_image_format;
  323. /* XXX: use automatic init with either ELF sections or C file parser */
  324. /* modules */
  325. /* mpeg.c */
  326. extern AVInputFormat mpegps_demux;
  327. int mpegps_init(void);
  328. /* mpegts.c */
  329. extern AVInputFormat mpegts_demux;
  330. int mpegts_init(void);
  331. /* rm.c */
  332. int rm_init(void);
  333. /* crc.c */
  334. int crc_init(void);
  335. /* img.c */
  336. int img_init(void);
  337. /* asf.c */
  338. int asf_init(void);
  339. /* avienc.c */
  340. int avienc_init(void);
  341. /* avidec.c */
  342. int avidec_init(void);
  343. /* swf.c */
  344. int swf_init(void);
  345. /* mov.c */
  346. int mov_init(void);
  347. /* movenc.c */
  348. int movenc_init(void);
  349. /* flvenc.c */
  350. int flvenc_init(void);
  351. /* flvdec.c */
  352. int flvdec_init(void);
  353. /* jpeg.c */
  354. int jpeg_init(void);
  355. /* gif.c */
  356. int gif_init(void);
  357. /* au.c */
  358. int au_init(void);
  359. /* amr.c */
  360. int amr_init(void);
  361. /* wav.c */
  362. int wav_init(void);
  363. /* raw.c */
  364. int pcm_read_seek(AVFormatContext *s,
  365. int stream_index, int64_t timestamp);
  366. int raw_init(void);
  367. /* mp3.c */
  368. int mp3_init(void);
  369. /* yuv4mpeg.c */
  370. int yuv4mpeg_init(void);
  371. /* ogg.c */
  372. int ogg_init(void);
  373. /* dv.c */
  374. int dv_init(void);
  375. /* ffm.c */
  376. int ffm_init(void);
  377. /* rtsp.c */
  378. extern AVInputFormat redir_demux;
  379. int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
  380. /* 4xm.c */
  381. int fourxm_init(void);
  382. /* psxstr.c */
  383. int str_init(void);
  384. /* idroq.c */
  385. int roq_init(void);
  386. /* ipmovie.c */
  387. int ipmovie_init(void);
  388. /* nut.c */
  389. int nut_init(void);
  390. /* wc3movie.c */
  391. int wc3_init(void);
  392. /* westwood.c */
  393. int westwood_init(void);
  394. /* segafilm.c */
  395. int film_init(void);
  396. /* idcin.c */
  397. int idcin_init(void);
  398. #include "rtp.h"
  399. #include "rtsp.h"
  400. /* yuv4mpeg.c */
  401. extern AVOutputFormat yuv4mpegpipe_oformat;
  402. /* utils.c */
  403. void av_register_input_format(AVInputFormat *format);
  404. void av_register_output_format(AVOutputFormat *format);
  405. AVOutputFormat *guess_stream_format(const char *short_name,
  406. const char *filename, const char *mime_type);
  407. AVOutputFormat *guess_format(const char *short_name,
  408. const char *filename, const char *mime_type);
  409. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  410. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  411. void av_register_all(void);
  412. typedef struct FifoBuffer {
  413. uint8_t *buffer;
  414. uint8_t *rptr, *wptr, *end;
  415. } FifoBuffer;
  416. int fifo_init(FifoBuffer *f, int size);
  417. void fifo_free(FifoBuffer *f);
  418. int fifo_size(FifoBuffer *f, uint8_t *rptr);
  419. int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
  420. void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
  421. /* media file input */
  422. AVInputFormat *av_find_input_format(const char *short_name);
  423. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  424. int av_open_input_stream(AVFormatContext **ic_ptr,
  425. ByteIOContext *pb, const char *filename,
  426. AVInputFormat *fmt, AVFormatParameters *ap);
  427. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  428. AVInputFormat *fmt,
  429. int buf_size,
  430. AVFormatParameters *ap);
  431. #define AVERROR_UNKNOWN (-1) /* unknown error */
  432. #define AVERROR_IO (-2) /* i/o error */
  433. #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
  434. #define AVERROR_INVALIDDATA (-4) /* invalid data found */
  435. #define AVERROR_NOMEM (-5) /* not enough memory */
  436. #define AVERROR_NOFMT (-6) /* unknown format */
  437. #define AVERROR_NOTSUPP (-7) /* operation not supported */
  438. int av_find_stream_info(AVFormatContext *ic);
  439. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  440. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  441. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp);
  442. int av_read_play(AVFormatContext *s);
  443. int av_read_pause(AVFormatContext *s);
  444. void av_close_input_file(AVFormatContext *s);
  445. AVStream *av_new_stream(AVFormatContext *s, int id);
  446. void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
  447. int pts_num, int pts_den);
  448. /* media file output */
  449. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  450. int av_write_header(AVFormatContext *s);
  451. int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
  452. int size);
  453. int av_write_trailer(AVFormatContext *s);
  454. void dump_format(AVFormatContext *ic,
  455. int index,
  456. const char *url,
  457. int is_output);
  458. int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  459. int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  460. int64_t parse_date(const char *datestr, int duration);
  461. int64_t av_gettime(void);
  462. /* ffm specific for ffserver */
  463. #define FFM_PACKET_SIZE 4096
  464. offset_t ffm_read_write_index(int fd);
  465. void ffm_write_write_index(int fd, offset_t pos);
  466. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  467. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  468. int get_frame_filename(char *buf, int buf_size,
  469. const char *path, int number);
  470. int filename_number_test(const char *filename);
  471. /* grab specific */
  472. int video_grab_init(void);
  473. int audio_init(void);
  474. /* DV1394 */
  475. int dv1394_init(void);
  476. #ifdef HAVE_AV_CONFIG_H
  477. #include "os_support.h"
  478. int strstart(const char *str, const char *val, const char **ptr);
  479. int stristart(const char *str, const char *val, const char **ptr);
  480. void pstrcpy(char *buf, int buf_size, const char *str);
  481. char *pstrcat(char *buf, int buf_size, const char *s);
  482. void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  483. #ifdef __GNUC__
  484. #define dynarray_add(tab, nb_ptr, elem)\
  485. do {\
  486. typeof(tab) _tab = (tab);\
  487. typeof(elem) _elem = (elem);\
  488. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  489. __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  490. } while(0)
  491. #else
  492. #define dynarray_add(tab, nb_ptr, elem)\
  493. do {\
  494. __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
  495. } while(0)
  496. #endif
  497. time_t mktimegm(struct tm *tm);
  498. const char *small_strptime(const char *p, const char *fmt,
  499. struct tm *dt);
  500. struct in_addr;
  501. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  502. void url_split(char *proto, int proto_size,
  503. char *hostname, int hostname_size,
  504. int *port_ptr,
  505. char *path, int path_size,
  506. const char *url);
  507. int match_ext(const char *filename, const char *extensions);
  508. #endif /* HAVE_AV_CONFIG_H */
  509. #ifdef __cplusplus
  510. }
  511. #endif
  512. #endif /* AVFORMAT_H */