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.

523 lines
16KB

  1. #ifndef AVFORMAT_H
  2. #define AVFORMAT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define LIBAVFORMAT_VERSION_INT 0x000408
  7. #define LIBAVFORMAT_VERSION "0.4.8"
  8. #define LIBAVFORMAT_BUILD 4606
  9. #define LIBAVFORMAT_BUILD_STR "4606"
  10. #define LIBAVFORMAT_IDENT "FFmpeg" LIBAVFORMAT_VERSION "b" LIBAVFORMAT_BUILD_STR
  11. #include "avcodec.h"
  12. #include "avio.h"
  13. /* packet functions */
  14. #ifndef MAXINT64
  15. #define MAXINT64 int64_t_C(0x7fffffffffffffff)
  16. #endif
  17. #ifndef MININT64
  18. #define MININT64 int64_t_C(0x8000000000000000)
  19. #endif
  20. #define AV_NOPTS_VALUE MININT64
  21. #define AV_TIME_BASE 1000000
  22. typedef struct AVPacket {
  23. int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
  24. uint8_t *data;
  25. int size;
  26. int stream_index;
  27. int flags;
  28. int duration;
  29. void (*destruct)(struct AVPacket *);
  30. void *priv;
  31. } AVPacket;
  32. #define PKT_FLAG_KEY 0x0001
  33. static inline void av_init_packet(AVPacket *pkt)
  34. {
  35. pkt->pts = AV_NOPTS_VALUE;
  36. pkt->flags = 0;
  37. pkt->stream_index = 0;
  38. }
  39. int av_new_packet(AVPacket *pkt, int size);
  40. /**
  41. * Free a packet
  42. *
  43. * @param pkt packet to free
  44. */
  45. static inline void av_free_packet(AVPacket *pkt)
  46. {
  47. if (pkt && pkt->destruct) {
  48. pkt->destruct(pkt);
  49. }
  50. }
  51. /*************************************************/
  52. /* fractional numbers for exact pts handling */
  53. /* the exact value of the fractional number is: 'val + num / den'. num
  54. is assumed to be such as 0 <= num < den */
  55. typedef struct AVFrac {
  56. int64_t val, num, den;
  57. } AVFrac;
  58. void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
  59. void av_frac_add(AVFrac *f, int64_t incr);
  60. void av_frac_set(AVFrac *f, int64_t val);
  61. /*************************************************/
  62. /* input/output formats */
  63. struct AVFormatContext;
  64. /* this structure contains the data a format has to probe a file */
  65. typedef struct AVProbeData {
  66. const char *filename;
  67. unsigned char *buf;
  68. int buf_size;
  69. } AVProbeData;
  70. #define AVPROBE_SCORE_MAX 100
  71. typedef struct AVFormatParameters {
  72. int frame_rate;
  73. int frame_rate_base;
  74. int sample_rate;
  75. int channels;
  76. int width;
  77. int height;
  78. enum PixelFormat pix_fmt;
  79. struct AVImageFormat *image_format;
  80. int channel; /* used to select dv channel */
  81. const char *device; /* video4linux, audio or DV device */
  82. const char *standard; /* tv standard, NTSC, PAL, SECAM */
  83. } AVFormatParameters;
  84. #define AVFMT_NOFILE 0x0001 /* no file should be opened */
  85. #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
  86. #define AVFMT_NOHEADER 0x0004 /* signal that no header is present
  87. (streams are added dynamically) */
  88. #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
  89. #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
  90. raw picture data */
  91. typedef struct AVOutputFormat {
  92. const char *name;
  93. const char *long_name;
  94. const char *mime_type;
  95. const char *extensions; /* comma separated extensions */
  96. /* size of private data so that it can be allocated in the wrapper */
  97. int priv_data_size;
  98. /* output support */
  99. enum CodecID audio_codec; /* default audio codec */
  100. enum CodecID video_codec; /* default video codec */
  101. int (*write_header)(struct AVFormatContext *);
  102. /* XXX: change prototype for 64 bit pts */
  103. int (*write_packet)(struct AVFormatContext *,
  104. int stream_index,
  105. unsigned char *buf, int size, int force_pts);
  106. int (*write_trailer)(struct AVFormatContext *);
  107. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
  108. int flags;
  109. /* currently only used to set pixel format if not YUV420P */
  110. int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
  111. /* private fields */
  112. struct AVOutputFormat *next;
  113. } AVOutputFormat;
  114. typedef struct AVInputFormat {
  115. const char *name;
  116. const char *long_name;
  117. /* size of private data so that it can be allocated in the wrapper */
  118. int priv_data_size;
  119. /* tell if a given file has a chance of being parsing by this format */
  120. int (*read_probe)(AVProbeData *);
  121. /* read the format header and initialize the AVFormatContext
  122. structure. Return 0 if OK. 'ap' if non NULL contains
  123. additionnal paramters. Only used in raw format right
  124. now. 'av_new_stream' should be called to create new streams. */
  125. int (*read_header)(struct AVFormatContext *,
  126. AVFormatParameters *ap);
  127. /* read one packet and put it in 'pkt'. pts and flags are also
  128. set. 'av_new_stream' can be called only if the flag
  129. AVFMT_NOHEADER is used. */
  130. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  131. /* close the stream. The AVFormatContext and AVStreams are not
  132. freed by this function */
  133. int (*read_close)(struct AVFormatContext *);
  134. /* seek at or before a given pts (given in microsecond). The pts
  135. origin is defined by the stream */
  136. int (*read_seek)(struct AVFormatContext *, int64_t pts);
  137. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
  138. int flags;
  139. /* if extensions are defined, then no probe is done. You should
  140. usually not use extension format guessing because it is not
  141. reliable enough */
  142. const char *extensions;
  143. /* general purpose read only value that the format can use */
  144. int value;
  145. /* private fields */
  146. struct AVInputFormat *next;
  147. } AVInputFormat;
  148. typedef struct AVStream {
  149. int index; /* stream index in AVFormatContext */
  150. int id; /* format specific stream id */
  151. AVCodecContext codec; /* codec context */
  152. int r_frame_rate; /* real frame rate of the stream */
  153. int r_frame_rate_base;/* real frame rate base of the stream */
  154. void *priv_data;
  155. /* internal data used in av_find_stream_info() */
  156. int codec_info_state;
  157. int codec_info_nb_repeat_frames;
  158. int codec_info_nb_real_frames;
  159. /* PTS generation when outputing stream */
  160. AVFrac pts;
  161. /* ffmpeg.c private use */
  162. int stream_copy; /* if TRUE, just copy stream */
  163. /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
  164. * MN:dunno if thats the right place, for it */
  165. float quality;
  166. /* decoding: position of the first frame of the component, in
  167. AV_TIME_BASE fractional seconds. */
  168. int64_t start_time;
  169. /* decoding: duration of the stream, in AV_TIME_BASE fractional
  170. seconds. */
  171. int64_t duration;
  172. } AVStream;
  173. #define MAX_STREAMS 20
  174. /* format I/O context */
  175. typedef struct AVFormatContext {
  176. /* can only be iformat or oformat, not both at the same time */
  177. struct AVInputFormat *iformat;
  178. struct AVOutputFormat *oformat;
  179. void *priv_data;
  180. ByteIOContext pb;
  181. int nb_streams;
  182. AVStream *streams[MAX_STREAMS];
  183. char filename[1024]; /* input or output filename */
  184. /* stream info */
  185. char title[512];
  186. char author[512];
  187. char copyright[512];
  188. char comment[512];
  189. int flags; /* format specific flags */
  190. /* private data for pts handling (do not modify directly) */
  191. int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
  192. int pts_num, pts_den; /* value to convert to seconds */
  193. /* This buffer is only needed when packets were already buffered but
  194. not decoded, for example to get the codec parameters in mpeg
  195. streams */
  196. struct AVPacketList *packet_buffer;
  197. /* decoding: position of the first frame of the component, in
  198. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  199. it is deduced from the AVStream values. */
  200. int64_t start_time;
  201. /* decoding: duration of the stream, in AV_TIME_BASE fractional
  202. seconds. NEVER set this value directly: it is deduced from the
  203. AVStream values. */
  204. int64_t duration;
  205. /* decoding: total file size. 0 if unknown */
  206. int64_t file_size;
  207. /* decoding: total stream bitrate in bit/s, 0 if not
  208. available. Never set it directly if the file_size and the
  209. duration are known as ffmpeg can compute it automatically. */
  210. int bit_rate;
  211. } AVFormatContext;
  212. typedef struct AVPacketList {
  213. AVPacket pkt;
  214. struct AVPacketList *next;
  215. } AVPacketList;
  216. extern AVInputFormat *first_iformat;
  217. extern AVOutputFormat *first_oformat;
  218. /* still image support */
  219. struct AVInputImageContext;
  220. typedef struct AVInputImageContext AVInputImageContext;
  221. typedef struct AVImageInfo {
  222. enum PixelFormat pix_fmt; /* requested pixel format */
  223. int width; /* requested width */
  224. int height; /* requested height */
  225. int interleaved; /* image is interleaved (e.g. interleaved GIF) */
  226. AVPicture pict; /* returned allocated image */
  227. } AVImageInfo;
  228. /* AVImageFormat.flags field constants */
  229. #define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
  230. typedef struct AVImageFormat {
  231. const char *name;
  232. const char *extensions;
  233. /* tell if a given file has a chance of being parsing by this format */
  234. int (*img_probe)(AVProbeData *);
  235. /* read a whole image. 'alloc_cb' is called when the image size is
  236. known so that the caller can allocate the image. If 'allo_cb'
  237. returns non zero, then the parsing is aborted. Return '0' if
  238. OK. */
  239. int (*img_read)(ByteIOContext *,
  240. int (*alloc_cb)(void *, AVImageInfo *info), void *);
  241. /* write the image */
  242. int supported_pixel_formats; /* mask of supported formats for output */
  243. int (*img_write)(ByteIOContext *, AVImageInfo *);
  244. int flags;
  245. struct AVImageFormat *next;
  246. } AVImageFormat;
  247. void av_register_image_format(AVImageFormat *img_fmt);
  248. AVImageFormat *av_probe_image_format(AVProbeData *pd);
  249. AVImageFormat *guess_image_format(const char *filename);
  250. int av_read_image(ByteIOContext *pb, const char *filename,
  251. AVImageFormat *fmt,
  252. int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
  253. int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
  254. extern AVImageFormat *first_image_format;
  255. extern AVImageFormat pnm_image_format;
  256. extern AVImageFormat pbm_image_format;
  257. extern AVImageFormat pgm_image_format;
  258. extern AVImageFormat ppm_image_format;
  259. extern AVImageFormat pam_image_format;
  260. extern AVImageFormat pgmyuv_image_format;
  261. extern AVImageFormat yuv_image_format;
  262. #ifdef CONFIG_ZLIB
  263. extern AVImageFormat png_image_format;
  264. #endif
  265. extern AVImageFormat jpeg_image_format;
  266. extern AVImageFormat gif_image_format;
  267. /* XXX: use automatic init with either ELF sections or C file parser */
  268. /* modules */
  269. /* mpeg.c */
  270. extern AVInputFormat mpegps_demux;
  271. int mpegps_init(void);
  272. /* mpegts.c */
  273. extern AVInputFormat mpegts_demux;
  274. int mpegts_init(void);
  275. /* rm.c */
  276. int rm_init(void);
  277. /* crc.c */
  278. int crc_init(void);
  279. /* img.c */
  280. int img_init(void);
  281. /* asf.c */
  282. int asf_init(void);
  283. /* avienc.c */
  284. int avienc_init(void);
  285. /* avidec.c */
  286. int avidec_init(void);
  287. /* swf.c */
  288. int swf_init(void);
  289. /* mov.c */
  290. int mov_init(void);
  291. /* movenc.c */
  292. int movenc_init(void);
  293. /* flvenc.c */
  294. int flvenc_init(void);
  295. /* flvdec.c */
  296. int flvdec_init(void);
  297. /* jpeg.c */
  298. int jpeg_init(void);
  299. /* gif.c */
  300. int gif_init(void);
  301. /* au.c */
  302. int au_init(void);
  303. /* amr.c */
  304. int amr_init(void);
  305. /* wav.c */
  306. int wav_init(void);
  307. /* raw.c */
  308. int raw_init(void);
  309. /* yuv4mpeg.c */
  310. int yuv4mpeg_init(void);
  311. /* ogg.c */
  312. int ogg_init(void);
  313. /* dv.c */
  314. int dv_init(void);
  315. /* ffm.c */
  316. int ffm_init(void);
  317. /* rtsp.c */
  318. extern AVInputFormat redir_demux;
  319. int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
  320. /* 4xm.c */
  321. int fourxm_init(void);
  322. /* psxstr.c */
  323. int str_init(void);
  324. /* idroq.c */
  325. int roq_init(void);
  326. /* ipmovie.c */
  327. int ipmovie_init(void);
  328. /* nut.c */
  329. int nut_init(void);
  330. /* wc3movie.c */
  331. int wc3_init(void);
  332. #include "rtp.h"
  333. #include "rtsp.h"
  334. /* yuv4mpeg.c */
  335. extern AVOutputFormat yuv4mpegpipe_oformat;
  336. /* utils.c */
  337. void av_register_input_format(AVInputFormat *format);
  338. void av_register_output_format(AVOutputFormat *format);
  339. AVOutputFormat *guess_stream_format(const char *short_name,
  340. const char *filename, const char *mime_type);
  341. AVOutputFormat *guess_format(const char *short_name,
  342. const char *filename, const char *mime_type);
  343. void av_hex_dump(uint8_t *buf, int size);
  344. void av_register_all(void);
  345. typedef struct FifoBuffer {
  346. uint8_t *buffer;
  347. uint8_t *rptr, *wptr, *end;
  348. } FifoBuffer;
  349. int fifo_init(FifoBuffer *f, int size);
  350. void fifo_free(FifoBuffer *f);
  351. int fifo_size(FifoBuffer *f, uint8_t *rptr);
  352. int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
  353. void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
  354. /* media file input */
  355. AVInputFormat *av_find_input_format(const char *short_name);
  356. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  357. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  358. AVInputFormat *fmt,
  359. int buf_size,
  360. AVFormatParameters *ap);
  361. #define AVERROR_UNKNOWN (-1) /* unknown error */
  362. #define AVERROR_IO (-2) /* i/o error */
  363. #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
  364. #define AVERROR_INVALIDDATA (-4) /* invalid data found */
  365. #define AVERROR_NOMEM (-5) /* not enough memory */
  366. #define AVERROR_NOFMT (-6) /* unknown format */
  367. int av_find_stream_info(AVFormatContext *ic);
  368. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  369. void av_close_input_file(AVFormatContext *s);
  370. AVStream *av_new_stream(AVFormatContext *s, int id);
  371. void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
  372. int pts_num, int pts_den);
  373. /* media file output */
  374. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  375. int av_write_header(AVFormatContext *s);
  376. int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
  377. int size);
  378. int av_write_trailer(AVFormatContext *s);
  379. void dump_format(AVFormatContext *ic,
  380. int index,
  381. const char *url,
  382. int is_output);
  383. int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  384. int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  385. int64_t parse_date(const char *datestr, int duration);
  386. int64_t av_gettime(void);
  387. /* ffm specific for ffserver */
  388. #define FFM_PACKET_SIZE 4096
  389. offset_t ffm_read_write_index(int fd);
  390. void ffm_write_write_index(int fd, offset_t pos);
  391. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  392. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  393. int get_frame_filename(char *buf, int buf_size,
  394. const char *path, int number);
  395. int filename_number_test(const char *filename);
  396. /* grab specific */
  397. int video_grab_init(void);
  398. int audio_init(void);
  399. /* DV1394 */
  400. int dv1394_init(void);
  401. #ifdef HAVE_AV_CONFIG_H
  402. int strstart(const char *str, const char *val, const char **ptr);
  403. int stristart(const char *str, const char *val, const char **ptr);
  404. void pstrcpy(char *buf, int buf_size, const char *str);
  405. char *pstrcat(char *buf, int buf_size, const char *s);
  406. void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  407. #define dynarray_add(tab, nb_ptr, elem)\
  408. do {\
  409. typeof(tab) _tab = (tab);\
  410. typeof(elem) _elem = (elem);\
  411. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  412. __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  413. } while(0)
  414. struct in_addr;
  415. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  416. void url_split(char *proto, int proto_size,
  417. char *hostname, int hostname_size,
  418. int *port_ptr,
  419. char *path, int path_size,
  420. const char *url);
  421. int match_ext(const char *filename, const char *extensions);
  422. #endif /* HAVE_AV_CONFIG_H */
  423. #ifdef __cplusplus
  424. }
  425. #endif
  426. #endif /* AVFORMAT_H */