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.

539 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 4608
  9. #define LIBAVFORMAT_BUILD_STR "4608"
  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. int (*write_packet)(struct AVFormatContext *,
  104. int stream_index,
  105. const uint8_t *buf, int size, int64_t 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. char album[512];
  190. int year; /* ID3 year, 0 if none */
  191. int track; /* track number, 0 if none */
  192. char genre[32]; /* ID3 genre */
  193. int flags; /* format specific flags */
  194. /* private data for pts handling (do not modify directly) */
  195. int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
  196. int pts_num, pts_den; /* value to convert to seconds */
  197. /* This buffer is only needed when packets were already buffered but
  198. not decoded, for example to get the codec parameters in mpeg
  199. streams */
  200. struct AVPacketList *packet_buffer;
  201. /* decoding: position of the first frame of the component, in
  202. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  203. it is deduced from the AVStream values. */
  204. int64_t start_time;
  205. /* decoding: duration of the stream, in AV_TIME_BASE fractional
  206. seconds. NEVER set this value directly: it is deduced from the
  207. AVStream values. */
  208. int64_t duration;
  209. /* decoding: total file size. 0 if unknown */
  210. int64_t file_size;
  211. /* decoding: total stream bitrate in bit/s, 0 if not
  212. available. Never set it directly if the file_size and the
  213. duration are known as ffmpeg can compute it automatically. */
  214. int bit_rate;
  215. } AVFormatContext;
  216. typedef struct AVPacketList {
  217. AVPacket pkt;
  218. struct AVPacketList *next;
  219. } AVPacketList;
  220. extern AVInputFormat *first_iformat;
  221. extern AVOutputFormat *first_oformat;
  222. /* still image support */
  223. struct AVInputImageContext;
  224. typedef struct AVInputImageContext AVInputImageContext;
  225. typedef struct AVImageInfo {
  226. enum PixelFormat pix_fmt; /* requested pixel format */
  227. int width; /* requested width */
  228. int height; /* requested height */
  229. int interleaved; /* image is interleaved (e.g. interleaved GIF) */
  230. AVPicture pict; /* returned allocated image */
  231. } AVImageInfo;
  232. /* AVImageFormat.flags field constants */
  233. #define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
  234. typedef struct AVImageFormat {
  235. const char *name;
  236. const char *extensions;
  237. /* tell if a given file has a chance of being parsing by this format */
  238. int (*img_probe)(AVProbeData *);
  239. /* read a whole image. 'alloc_cb' is called when the image size is
  240. known so that the caller can allocate the image. If 'allo_cb'
  241. returns non zero, then the parsing is aborted. Return '0' if
  242. OK. */
  243. int (*img_read)(ByteIOContext *,
  244. int (*alloc_cb)(void *, AVImageInfo *info), void *);
  245. /* write the image */
  246. int supported_pixel_formats; /* mask of supported formats for output */
  247. int (*img_write)(ByteIOContext *, AVImageInfo *);
  248. int flags;
  249. struct AVImageFormat *next;
  250. } AVImageFormat;
  251. void av_register_image_format(AVImageFormat *img_fmt);
  252. AVImageFormat *av_probe_image_format(AVProbeData *pd);
  253. AVImageFormat *guess_image_format(const char *filename);
  254. int av_read_image(ByteIOContext *pb, const char *filename,
  255. AVImageFormat *fmt,
  256. int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
  257. int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
  258. extern AVImageFormat *first_image_format;
  259. extern AVImageFormat pnm_image_format;
  260. extern AVImageFormat pbm_image_format;
  261. extern AVImageFormat pgm_image_format;
  262. extern AVImageFormat ppm_image_format;
  263. extern AVImageFormat pam_image_format;
  264. extern AVImageFormat pgmyuv_image_format;
  265. extern AVImageFormat yuv_image_format;
  266. #ifdef CONFIG_ZLIB
  267. extern AVImageFormat png_image_format;
  268. #endif
  269. extern AVImageFormat jpeg_image_format;
  270. extern AVImageFormat gif_image_format;
  271. /* XXX: use automatic init with either ELF sections or C file parser */
  272. /* modules */
  273. /* mpeg.c */
  274. extern AVInputFormat mpegps_demux;
  275. int mpegps_init(void);
  276. /* mpegts.c */
  277. extern AVInputFormat mpegts_demux;
  278. int mpegts_init(void);
  279. /* rm.c */
  280. int rm_init(void);
  281. /* crc.c */
  282. int crc_init(void);
  283. /* img.c */
  284. int img_init(void);
  285. /* asf.c */
  286. int asf_init(void);
  287. /* avienc.c */
  288. int avienc_init(void);
  289. /* avidec.c */
  290. int avidec_init(void);
  291. /* swf.c */
  292. int swf_init(void);
  293. /* mov.c */
  294. int mov_init(void);
  295. /* movenc.c */
  296. int movenc_init(void);
  297. /* flvenc.c */
  298. int flvenc_init(void);
  299. /* flvdec.c */
  300. int flvdec_init(void);
  301. /* jpeg.c */
  302. int jpeg_init(void);
  303. /* gif.c */
  304. int gif_init(void);
  305. /* au.c */
  306. int au_init(void);
  307. /* amr.c */
  308. int amr_init(void);
  309. /* wav.c */
  310. int wav_init(void);
  311. /* raw.c */
  312. int raw_init(void);
  313. /* mp3.c */
  314. int mp3_init(void);
  315. /* yuv4mpeg.c */
  316. int yuv4mpeg_init(void);
  317. /* ogg.c */
  318. int ogg_init(void);
  319. /* dv.c */
  320. int dv_init(void);
  321. /* ffm.c */
  322. int ffm_init(void);
  323. /* rtsp.c */
  324. extern AVInputFormat redir_demux;
  325. int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
  326. /* 4xm.c */
  327. int fourxm_init(void);
  328. /* psxstr.c */
  329. int str_init(void);
  330. /* idroq.c */
  331. int roq_init(void);
  332. /* ipmovie.c */
  333. int ipmovie_init(void);
  334. /* nut.c */
  335. int nut_init(void);
  336. /* wc3movie.c */
  337. int wc3_init(void);
  338. #include "rtp.h"
  339. #include "rtsp.h"
  340. /* yuv4mpeg.c */
  341. extern AVOutputFormat yuv4mpegpipe_oformat;
  342. /* utils.c */
  343. void av_register_input_format(AVInputFormat *format);
  344. void av_register_output_format(AVOutputFormat *format);
  345. AVOutputFormat *guess_stream_format(const char *short_name,
  346. const char *filename, const char *mime_type);
  347. AVOutputFormat *guess_format(const char *short_name,
  348. const char *filename, const char *mime_type);
  349. void av_hex_dump(uint8_t *buf, int size);
  350. void av_register_all(void);
  351. typedef struct FifoBuffer {
  352. uint8_t *buffer;
  353. uint8_t *rptr, *wptr, *end;
  354. } FifoBuffer;
  355. int fifo_init(FifoBuffer *f, int size);
  356. void fifo_free(FifoBuffer *f);
  357. int fifo_size(FifoBuffer *f, uint8_t *rptr);
  358. int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
  359. void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
  360. /* media file input */
  361. AVInputFormat *av_find_input_format(const char *short_name);
  362. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  363. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  364. AVInputFormat *fmt,
  365. int buf_size,
  366. AVFormatParameters *ap);
  367. #define AVERROR_UNKNOWN (-1) /* unknown error */
  368. #define AVERROR_IO (-2) /* i/o error */
  369. #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
  370. #define AVERROR_INVALIDDATA (-4) /* invalid data found */
  371. #define AVERROR_NOMEM (-5) /* not enough memory */
  372. #define AVERROR_NOFMT (-6) /* unknown format */
  373. int av_find_stream_info(AVFormatContext *ic);
  374. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  375. void av_close_input_file(AVFormatContext *s);
  376. AVStream *av_new_stream(AVFormatContext *s, int id);
  377. void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
  378. int pts_num, int pts_den);
  379. /* media file output */
  380. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  381. int av_write_header(AVFormatContext *s);
  382. int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
  383. int size);
  384. int av_write_trailer(AVFormatContext *s);
  385. void dump_format(AVFormatContext *ic,
  386. int index,
  387. const char *url,
  388. int is_output);
  389. int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  390. int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
  391. int64_t parse_date(const char *datestr, int duration);
  392. int64_t av_gettime(void);
  393. /* ffm specific for ffserver */
  394. #define FFM_PACKET_SIZE 4096
  395. offset_t ffm_read_write_index(int fd);
  396. void ffm_write_write_index(int fd, offset_t pos);
  397. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  398. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  399. int get_frame_filename(char *buf, int buf_size,
  400. const char *path, int number);
  401. int filename_number_test(const char *filename);
  402. /* grab specific */
  403. int video_grab_init(void);
  404. int audio_init(void);
  405. /* DV1394 */
  406. int dv1394_init(void);
  407. #ifdef HAVE_AV_CONFIG_H
  408. #include "os_support.h"
  409. int strstart(const char *str, const char *val, const char **ptr);
  410. int stristart(const char *str, const char *val, const char **ptr);
  411. void pstrcpy(char *buf, int buf_size, const char *str);
  412. char *pstrcat(char *buf, int buf_size, const char *s);
  413. void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
  414. #define dynarray_add(tab, nb_ptr, elem)\
  415. do {\
  416. typeof(tab) _tab = (tab);\
  417. typeof(elem) _elem = (elem);\
  418. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  419. __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
  420. } while(0)
  421. time_t mktimegm(struct tm *tm);
  422. const char *small_strptime(const char *p, const char *fmt,
  423. struct tm *dt);
  424. struct in_addr;
  425. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  426. void url_split(char *proto, int proto_size,
  427. char *hostname, int hostname_size,
  428. int *port_ptr,
  429. char *path, int path_size,
  430. const char *url);
  431. int match_ext(const char *filename, const char *extensions);
  432. #endif /* HAVE_AV_CONFIG_H */
  433. #ifdef __cplusplus
  434. }
  435. #endif
  436. #endif /* AVFORMAT_H */