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.

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