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.

405 lines
13KB

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