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.

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