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.

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