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.

328 lines
9.9KB

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