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.

508 lines
15KB

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