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.

417 lines
13KB

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