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.

532 lines
16KB

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