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.

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