* some minor modification by Philip Gladston
[libav.git] / libav / avformat.h
1
2 #include "avcodec.h"
3
4 #include "avio.h"
5
6 /* packet functions */
7
8 typedef struct AVPacket {
9 INT64 pts;
10 UINT8 *data;
11 int size;
12 int stream_index;
13 int flags;
14 #define PKT_FLAG_KEY 0x0001
15 #define PKT_FLAG_DROPPED_FRAME 0x0002
16 } AVPacket;
17
18 int av_new_packet(AVPacket *pkt, int size);
19 void av_free_packet(AVPacket *pkt);
20
21 /*************************************************/
22 /* output formats */
23
24 struct AVFormatContext;
25 struct AVFormatInputContext;
26
27 typedef struct AVFormatParameters {
28 int frame_rate;
29 int sample_rate;
30 int channels;
31 int width;
32 int height;
33 enum PixelFormat pix_fmt;
34 } AVFormatParameters;
35
36 typedef struct AVFormat {
37 const char *name;
38 const char *long_name;
39 const char *mime_type;
40 const char *extensions; /* comma separated extensions */
41
42 /* output support */
43 enum CodecID audio_codec; /* default audio codec */
44 enum CodecID video_codec; /* default video codec */
45 int (*write_header)(struct AVFormatContext *);
46 int (*write_packet)(struct AVFormatContext *,
47 int stream_index,
48 unsigned char *buf, int size, int force_pts);
49 int (*write_trailer)(struct AVFormatContext *);
50
51 /* optional input support */
52 /* read the format header and initialize the AVFormatInputContext
53 structure. Return 0 if OK. 'ap' if non NULL contains
54 additionnal paramters. Only used in raw format right now */
55 int (*read_header)(struct AVFormatContext *,
56 AVFormatParameters *ap);
57 /* read one packet and put it in 'pkt'. pts and flags are also set */
58 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
59 /* close the stream. The AVFormatContext and AVStreams are not
60 freed by this function */
61 int (*read_close)(struct AVFormatContext *);
62 /* seek at or before a given pts (given in microsecond). The pts
63 origin is defined by the stream */
64 int (*read_seek)(struct AVFormatContext *, INT64 pts);
65 int flags;
66 #define AVFMT_NOFILE 0x0001 /* no file should be opened */
67 #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
68 struct AVFormat *next;
69 } AVFormat;
70
71 typedef struct AVStream {
72 int id; /* internal stream id */
73 AVCodecContext codec; /* codec context */
74 void *priv_data;
75 } AVStream;
76
77 #define MAX_STREAMS 20
78
79 /* format I/O context */
80 typedef struct AVFormatContext {
81 struct AVFormat *format;
82 void *priv_data;
83 ByteIOContext pb;
84 int nb_streams;
85 AVStream *streams[MAX_STREAMS];
86 char filename[1024]; /* input or output filename */
87 /* stream info */
88 char title[512];
89 char author[512];
90 char copyright[512];
91 char comment[512];
92 /* This buffer is only needed when packets were already buffered but
93 not decoded, for example to get the codec parameters in mpeg
94 streams */
95 struct AVPacketList *packet_buffer;
96 } AVFormatContext;
97
98 typedef struct AVPacketList {
99 AVPacket pkt;
100 struct AVPacketList *next;
101 } AVPacketList;
102
103 extern AVFormat *first_format;
104
105 /* rv10enc.c */
106 extern AVFormat rm_format;
107
108 /* mpegmux.c */
109 extern AVFormat mpeg_mux_format;
110
111 /* asfenc.c */
112 extern AVFormat asf_format;
113
114 /* avienc.c */
115 extern AVFormat avi_format;
116
117 /* mov.c */
118 extern AVFormat mov_format;
119 extern AVFormat mp4_format;
120
121 /* jpegenc.c */
122 extern AVFormat mpjpeg_format;
123 extern AVFormat jpeg_format;
124 extern AVFormat single_jpeg_format;
125
126 /* swfenc.c */
127 extern AVFormat swf_format;
128
129 /* gif.c */
130 extern AVFormat gif_format;
131 /* au.c */
132 extern AVFormat au_format;
133
134 /* wav.c */
135 extern AVFormat wav_format;
136
137 /* img.c */
138 extern AVFormat pgm_format;
139 extern AVFormat ppm_format;
140 extern AVFormat pgmyuv_format;
141 extern AVFormat imgyuv_format;
142
143 extern AVFormat pgmpipe_format;
144 extern AVFormat pgmyuvpipe_format;
145 extern AVFormat ppmpipe_format;
146
147 /* raw.c */
148 extern AVFormat mp2_format;
149 extern AVFormat ac3_format;
150 extern AVFormat h263_format;
151 extern AVFormat mpeg1video_format;
152 extern AVFormat mjpeg_format;
153 extern AVFormat pcm_s16le_format;
154 extern AVFormat pcm_s16be_format;
155 extern AVFormat pcm_u16le_format;
156 extern AVFormat pcm_u16be_format;
157 extern AVFormat pcm_s8_format;
158 extern AVFormat pcm_u8_format;
159 extern AVFormat pcm_mulaw_format;
160 extern AVFormat pcm_alaw_format;
161 extern AVFormat rawvideo_format;
162
163 /* ffm.c */
164 extern AVFormat ffm_format;
165
166 /* formats.c */
167
168 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
169 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
170
171 void register_avformat(AVFormat *format);
172 AVFormat *guess_format(const char *short_name, const char *filename, const char *mime_type);
173
174 int strstart(const char *str, const char *val, const char **ptr);
175 void nstrcpy(char *buf, int buf_size, const char *str);
176 int match_ext(const char *filename, const char *extensions);
177
178 void register_all(void);
179
180 INT64 gettime(void);
181
182 typedef struct FifoBuffer {
183 UINT8 *buffer;
184 UINT8 *rptr, *wptr, *end;
185 } FifoBuffer;
186
187 int fifo_init(FifoBuffer *f, int size);
188 void fifo_free(FifoBuffer *f);
189 int fifo_size(FifoBuffer *f, UINT8 *rptr);
190 int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
191 void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
192
193 AVFormatContext *av_open_input_file(const char *filename,
194 const char *format_name,
195 int buf_size,
196 AVFormatParameters *ap);
197 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
198 void av_close_input_file(AVFormatContext *s);
199
200 int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
201
202 void dump_format(AVFormatContext *ic,
203 int index,
204 const char *url,
205 int is_output);
206 int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
207 INT64 gettime(void);
208 INT64 parse_date(const char *datestr, int duration);
209
210 /* ffm specific for ffserver */
211 #define FFM_PACKET_SIZE 4096
212 offset_t ffm_read_write_index(int fd);
213 void ffm_write_write_index(int fd, offset_t pos);
214 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
215
216 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
217
218 int get_frame_filename(char *buf, int buf_size,
219 const char *path, int number);
220
221 /* grab/output specific */
222 extern AVFormat video_grab_device_format;
223 extern AVFormat audio_device_format;
224
225 extern const char *v4l_device;
226 extern const char *audio_device;