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.

322 lines
9.7KB

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