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.

472 lines
14KB

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