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.

545 lines
16KB

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