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.

352 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. } AVStream;
  129. #define MAX_STREAMS 20
  130. /* format I/O context */
  131. typedef struct AVFormatContext {
  132. /* can only be iformat or oformat, not both at the same time */
  133. struct AVInputFormat *iformat;
  134. struct AVOutputFormat *oformat;
  135. void *priv_data;
  136. ByteIOContext pb;
  137. int nb_streams;
  138. AVStream *streams[MAX_STREAMS];
  139. char filename[1024]; /* input or output filename */
  140. /* stream info */
  141. char title[512];
  142. char author[512];
  143. char copyright[512];
  144. char comment[512];
  145. int flags; /* format specific flags */
  146. /* private data for pts handling (do not modify directly) */
  147. int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
  148. int pts_num, pts_den; /* value to convert to seconds */
  149. /* This buffer is only needed when packets were already buffered but
  150. not decoded, for example to get the codec parameters in mpeg
  151. streams */
  152. struct AVPacketList *packet_buffer;
  153. } AVFormatContext;
  154. typedef struct AVPacketList {
  155. AVPacket pkt;
  156. struct AVPacketList *next;
  157. } AVPacketList;
  158. extern AVInputFormat *first_iformat;
  159. extern AVOutputFormat *first_oformat;
  160. /* XXX: use automatic init with either ELF sections or C file parser */
  161. /* modules */
  162. /* mpeg.c */
  163. int mpegps_init(void);
  164. /* mpegts.c */
  165. extern AVInputFormat mpegts_demux;
  166. int mpegts_init(void);
  167. /* rm.c */
  168. int rm_init(void);
  169. /* crc.c */
  170. int crc_init(void);
  171. /* img.c */
  172. int img_init(void);
  173. /* asf.c */
  174. int asf_init(void);
  175. /* avienc.c */
  176. int avienc_init(void);
  177. /* avidec.c */
  178. int avidec_init(void);
  179. /* swf.c */
  180. int swf_init(void);
  181. /* mov.c */
  182. int mov_init(void);
  183. /* jpeg.c */
  184. int jpeg_init(void);
  185. /* gif.c */
  186. int gif_init(void);
  187. /* au.c */
  188. int au_init(void);
  189. /* wav.c */
  190. int wav_init(void);
  191. /* raw.c */
  192. int raw_init(void);
  193. /* ogg.c */
  194. int ogg_init(void);
  195. /* dv.c */
  196. int dv_init(void);
  197. /* ffm.c */
  198. int ffm_init(void);
  199. /* rtsp.c */
  200. extern AVInputFormat redir_demux;
  201. int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
  202. #include "rtp.h"
  203. #include "rtsp.h"
  204. /* utils.c */
  205. #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
  206. #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
  207. void av_register_input_format(AVInputFormat *format);
  208. void av_register_output_format(AVOutputFormat *format);
  209. AVOutputFormat *guess_stream_format(const char *short_name,
  210. const char *filename, const char *mime_type);
  211. AVOutputFormat *guess_format(const char *short_name,
  212. const char *filename, const char *mime_type);
  213. void av_hex_dump(UINT8 *buf, int size);
  214. void av_register_all(void);
  215. typedef struct FifoBuffer {
  216. UINT8 *buffer;
  217. UINT8 *rptr, *wptr, *end;
  218. } FifoBuffer;
  219. int fifo_init(FifoBuffer *f, int size);
  220. void fifo_free(FifoBuffer *f);
  221. int fifo_size(FifoBuffer *f, UINT8 *rptr);
  222. int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
  223. void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
  224. /* media file input */
  225. AVInputFormat *av_find_input_format(const char *short_name);
  226. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  227. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  228. AVInputFormat *fmt,
  229. int buf_size,
  230. AVFormatParameters *ap);
  231. #define AVERROR_UNKNOWN (-1) /* unknown error */
  232. #define AVERROR_IO (-2) /* i/o error */
  233. #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
  234. #define AVERROR_INVALIDDATA (-4) /* invalid data found */
  235. #define AVERROR_NOMEM (-5) /* not enough memory */
  236. #define AVERROR_NOFMT (-6) /* unknown format */
  237. int av_find_stream_info(AVFormatContext *ic);
  238. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  239. void av_close_input_file(AVFormatContext *s);
  240. AVStream *av_new_stream(AVFormatContext *s, int id);
  241. void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
  242. int pts_num, int pts_den);
  243. /* media file output */
  244. int av_write_header(AVFormatContext *s);
  245. int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
  246. int size);
  247. int av_write_trailer(AVFormatContext *s);
  248. void dump_format(AVFormatContext *ic,
  249. int index,
  250. const char *url,
  251. int is_output);
  252. int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
  253. INT64 parse_date(const char *datestr, int duration);
  254. INT64 av_gettime(void);
  255. /* ffm specific for ffserver */
  256. #define FFM_PACKET_SIZE 4096
  257. offset_t ffm_read_write_index(int fd);
  258. void ffm_write_write_index(int fd, offset_t pos);
  259. void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
  260. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  261. int get_frame_filename(char *buf, int buf_size,
  262. const char *path, int number);
  263. int filename_number_test(const char *filename);
  264. /* grab specific */
  265. int video_grab_init(void);
  266. int audio_init(void);
  267. extern const char *v4l_device;
  268. extern const char *audio_device;
  269. #ifdef HAVE_AV_CONFIG_H
  270. int strstart(const char *str, const char *val, const char **ptr);
  271. int stristart(const char *str, const char *val, const char **ptr);
  272. void pstrcpy(char *buf, int buf_size, const char *str);
  273. char *pstrcat(char *buf, int buf_size, const char *s);
  274. struct in_addr;
  275. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  276. void url_split(char *proto, int proto_size,
  277. char *hostname, int hostname_size,
  278. int *port_ptr,
  279. char *path, int path_size,
  280. const char *url);
  281. int match_ext(const char *filename, const char *extensions);
  282. #endif /* HAVE_AV_CONFIG_H */
  283. #endif /* AVFORMAT_H */