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.

355 lines
11KB

  1. #ifndef AVFORMAT_H
  2. #define AVFORMAT_H
  3. #define LIBAVFORMAT_VERSION_INT 0x000406
  4. #define LIBAVFORMAT_VERSION "0.4.6"
  5. #define LIBAVFORMAT_BUILD 4602
  6. #include "avcodec.h"
  7. #include "avio.h"
  8. /* packet functions */
  9. #define AV_NOPTS_VALUE 0
  10. typedef struct AVPacket {
  11. INT64 pts; /* presentation time stamp in stream units (set av_set_pts_info) */
  12. UINT8 *data;
  13. int size;
  14. int stream_index;
  15. int flags;
  16. int duration;
  17. #define PKT_FLAG_KEY 0x0001
  18. } AVPacket;
  19. int av_new_packet(AVPacket *pkt, int size);
  20. void av_free_packet(AVPacket *pkt);
  21. /*************************************************/
  22. /* fractional numbers for exact pts handling */
  23. /* the exact value of the fractional number is: 'val + num / den'. num
  24. is assumed to be such as 0 <= num < den */
  25. typedef struct AVFrac {
  26. INT64 val, num, den;
  27. } AVFrac;
  28. void av_frac_init(AVFrac *f, INT64 val, INT64 num, INT64 den);
  29. void av_frac_add(AVFrac *f, INT64 incr);
  30. void av_frac_set(AVFrac *f, INT64 val);
  31. /*************************************************/
  32. /* input/output formats */
  33. struct AVFormatContext;
  34. /* this structure contains the data a format has to probe a file */
  35. typedef struct AVProbeData {
  36. char *filename;
  37. unsigned char *buf;
  38. int buf_size;
  39. } AVProbeData;
  40. #define AVPROBE_SCORE_MAX 100
  41. typedef struct AVFormatParameters {
  42. int frame_rate;
  43. int sample_rate;
  44. int channels;
  45. int width;
  46. int height;
  47. enum PixelFormat pix_fmt;
  48. } AVFormatParameters;
  49. #define AVFMT_NOFILE 0x0001 /* no file should be opened */
  50. #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
  51. #define AVFMT_NOHEADER 0x0004 /* signal that no header is present
  52. (streams are added dynamically) */
  53. #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
  54. #define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
  55. - need better api) */
  56. #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
  57. raw picture data */
  58. typedef struct AVOutputFormat {
  59. const char *name;
  60. const char *long_name;
  61. const char *mime_type;
  62. const char *extensions; /* comma separated extensions */
  63. /* size of private data so that it can be allocated in the wrapper */
  64. int priv_data_size;
  65. /* output support */
  66. enum CodecID audio_codec; /* default audio codec */
  67. enum CodecID video_codec; /* default video codec */
  68. int (*write_header)(struct AVFormatContext *);
  69. /* XXX: change prototype for 64 bit pts */
  70. int (*write_packet)(struct AVFormatContext *,
  71. int stream_index,
  72. unsigned char *buf, int size, int force_pts);
  73. int (*write_trailer)(struct AVFormatContext *);
  74. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
  75. int flags;
  76. /* private fields */
  77. struct AVOutputFormat *next;
  78. } AVOutputFormat;
  79. typedef struct AVInputFormat {
  80. const char *name;
  81. const char *long_name;
  82. /* size of private data so that it can be allocated in the wrapper */
  83. int priv_data_size;
  84. /* tell if a given file has a chance of being parsing by this format */
  85. int (*read_probe)(AVProbeData *);
  86. /* read the format header and initialize the AVFormatContext
  87. structure. Return 0 if OK. 'ap' if non NULL contains
  88. additionnal paramters. Only used in raw format right
  89. now. 'av_new_stream' should be called to create new streams. */
  90. int (*read_header)(struct AVFormatContext *,
  91. AVFormatParameters *ap);
  92. /* read one packet and put it in 'pkt'. pts and flags are also
  93. set. 'av_new_stream' can be called only if the flag
  94. AVFMT_NOHEADER is used. */
  95. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  96. /* close the stream. The AVFormatContext and AVStreams are not
  97. freed by this function */
  98. int (*read_close)(struct AVFormatContext *);
  99. /* seek at or before a given pts (given in microsecond). The pts
  100. origin is defined by the stream */
  101. int (*read_seek)(struct AVFormatContext *, INT64 pts);
  102. /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
  103. int flags;
  104. /* if extensions are defined, then no probe is done. You should
  105. usually not use extension format guessing because it is not
  106. reliable enough */
  107. const char *extensions;
  108. /* general purpose read only value that the format can use */
  109. int value;
  110. /* private fields */
  111. struct AVInputFormat *next;
  112. } AVInputFormat;
  113. typedef struct AVStream {
  114. int index; /* stream index in AVFormatContext */
  115. int id; /* format specific stream id */
  116. AVCodecContext codec; /* codec context */
  117. int r_frame_rate; /* real frame rate of the stream */
  118. uint64_t time_length; /* real length of the stream in miliseconds */
  119. void *priv_data;
  120. /* internal data used in av_find_stream_info() */
  121. int codec_info_state;
  122. int codec_info_nb_repeat_frames;
  123. int codec_info_nb_real_frames;
  124. /* PTS generation when outputing stream */
  125. AVFrac pts;
  126. /* ffmpeg.c private use */
  127. int stream_copy; /* if TRUE, just copy stream */
  128. /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
  129. * MN:dunno if thats the right place, for it */
  130. float quality;
  131. } AVStream;
  132. #define MAX_STREAMS 20
  133. /* format I/O context */
  134. typedef struct AVFormatContext {
  135. /* can only be iformat or oformat, not both at the same time */
  136. struct AVInputFormat *iformat;
  137. struct AVOutputFormat *oformat;
  138. void *priv_data;
  139. ByteIOContext pb;
  140. int nb_streams;
  141. AVStream *streams[MAX_STREAMS];
  142. char filename[1024]; /* input or output filename */
  143. /* stream info */
  144. char title[512];
  145. char author[512];
  146. char copyright[512];
  147. char comment[512];
  148. int flags; /* format specific flags */
  149. /* private data for pts handling (do not modify directly) */
  150. int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
  151. int pts_num, pts_den; /* value to convert to seconds */
  152. /* This buffer is only needed when packets were already buffered but
  153. not decoded, for example to get the codec parameters in mpeg
  154. streams */
  155. struct AVPacketList *packet_buffer;
  156. } AVFormatContext;
  157. typedef struct AVPacketList {
  158. AVPacket pkt;
  159. struct AVPacketList *next;
  160. } AVPacketList;
  161. extern AVInputFormat *first_iformat;
  162. extern AVOutputFormat *first_oformat;
  163. /* XXX: use automatic init with either ELF sections or C file parser */
  164. /* modules */
  165. /* mpeg.c */
  166. int mpegps_init(void);
  167. /* mpegts.c */
  168. extern AVInputFormat mpegts_demux;
  169. int mpegts_init(void);
  170. /* rm.c */
  171. int rm_init(void);
  172. /* crc.c */
  173. int crc_init(void);
  174. /* img.c */
  175. int img_init(void);
  176. /* asf.c */
  177. int asf_init(void);
  178. /* avienc.c */
  179. int avienc_init(void);
  180. /* avidec.c */
  181. int avidec_init(void);
  182. /* swf.c */
  183. int swf_init(void);
  184. /* mov.c */
  185. int mov_init(void);
  186. /* jpeg.c */
  187. int jpeg_init(void);
  188. /* gif.c */
  189. int gif_init(void);
  190. /* au.c */
  191. int au_init(void);
  192. /* wav.c */
  193. int wav_init(void);
  194. /* raw.c */
  195. int raw_init(void);
  196. /* ogg.c */
  197. int ogg_init(void);
  198. /* dv.c */
  199. int dv_init(void);
  200. /* ffm.c */
  201. int ffm_init(void);
  202. /* rtsp.c */
  203. extern AVInputFormat redir_demux;
  204. int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
  205. #include "rtp.h"
  206. #include "rtsp.h"
  207. /* utils.c */
  208. #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
  209. #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
  210. void av_register_input_format(AVInputFormat *format);
  211. void av_register_output_format(AVOutputFormat *format);
  212. AVOutputFormat *guess_stream_format(const char *short_name,
  213. const char *filename, const char *mime_type);
  214. AVOutputFormat *guess_format(const char *short_name,
  215. const char *filename, const char *mime_type);
  216. void av_hex_dump(UINT8 *buf, int size);
  217. void av_register_all(void);
  218. typedef struct FifoBuffer {
  219. UINT8 *buffer;
  220. UINT8 *rptr, *wptr, *end;
  221. } FifoBuffer;
  222. int fifo_init(FifoBuffer *f, int size);
  223. void fifo_free(FifoBuffer *f);
  224. int fifo_size(FifoBuffer *f, UINT8 *rptr);
  225. int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
  226. void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
  227. /* media file input */
  228. AVInputFormat *av_find_input_format(const char *short_name);
  229. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  230. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  231. AVInputFormat *fmt,
  232. int buf_size,
  233. AVFormatParameters *ap);
  234. #define AVERROR_UNKNOWN (-1) /* unknown error */
  235. #define AVERROR_IO (-2) /* i/o error */
  236. #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
  237. #define AVERROR_INVALIDDATA (-4) /* invalid data found */
  238. #define AVERROR_NOMEM (-5) /* not enough memory */
  239. #define AVERROR_NOFMT (-6) /* unknown format */
  240. int av_find_stream_info(AVFormatContext *ic);
  241. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  242. void av_close_input_file(AVFormatContext *s);
  243. AVStream *av_new_stream(AVFormatContext *s, int id);
  244. void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
  245. int pts_num, int pts_den);
  246. /* media file output */
  247. int av_write_header(AVFormatContext *s);
  248. int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
  249. int size);
  250. int av_write_trailer(AVFormatContext *s);
  251. void dump_format(AVFormatContext *ic,
  252. int index,
  253. const char *url,
  254. int is_output);
  255. int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  256. INT64 parse_date(const char *datestr, int duration);
  257. INT64 av_gettime(void);
  258. /* ffm specific for ffserver */
  259. #define FFM_PACKET_SIZE 4096
  260. offset_t ffm_read_write_index(int fd);
  261. void ffm_write_write_index(int fd, offset_t pos);
  262. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  263. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  264. int get_frame_filename(char *buf, int buf_size,
  265. const char *path, int number);
  266. int filename_number_test(const char *filename);
  267. /* grab specific */
  268. int video_grab_init(void);
  269. int audio_init(void);
  270. extern const char *v4l_device;
  271. extern const char *audio_device;
  272. #ifdef HAVE_AV_CONFIG_H
  273. int strstart(const char *str, const char *val, const char **ptr);
  274. int stristart(const char *str, const char *val, const char **ptr);
  275. void pstrcpy(char *buf, int buf_size, const char *str);
  276. char *pstrcat(char *buf, int buf_size, const char *s);
  277. struct in_addr;
  278. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  279. void url_split(char *proto, int proto_size,
  280. char *hostname, int hostname_size,
  281. int *port_ptr,
  282. char *path, int path_size,
  283. const char *url);
  284. int match_ext(const char *filename, const char *extensions);
  285. #endif /* HAVE_AV_CONFIG_H */
  286. #endif /* AVFORMAT_H */