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.

563 lines
17KB

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