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.

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