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