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.

460 lines
14KB

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