]> git.sesse.net Git - ffmpeg/blob - libavcodec/avcodec.h
wmv1 header parser (unfinished)
[ffmpeg] / libavcodec / avcodec.h
1 #ifndef AVCODEC_H
2 #define AVCODEC_H
3
4 #include "common.h"
5
6 enum CodecID {
7     CODEC_ID_NONE, 
8     CODEC_ID_MPEG1VIDEO,
9     CODEC_ID_H263,
10     CODEC_ID_RV10,
11     CODEC_ID_MP2,
12     CODEC_ID_MP3LAME,
13     CODEC_ID_AC3,
14     CODEC_ID_MJPEG,
15     CODEC_ID_MPEG4,
16     CODEC_ID_RAWVIDEO,
17     CODEC_ID_MSMPEG4V1,
18     CODEC_ID_MSMPEG4V2,
19     CODEC_ID_MSMPEG4V3,
20     CODEC_ID_WMV1,
21     CODEC_ID_H263P,
22     CODEC_ID_H263I,
23
24     /* various pcm "codecs" */
25     CODEC_ID_PCM_S16LE,
26     CODEC_ID_PCM_S16BE,
27     CODEC_ID_PCM_U16LE,
28     CODEC_ID_PCM_U16BE,
29     CODEC_ID_PCM_S8,
30     CODEC_ID_PCM_U8,
31     CODEC_ID_PCM_MULAW,
32     CODEC_ID_PCM_ALAW,
33 };
34 #define CODEC_ID_MSMPEG4 CODEC_ID_MSMPEG4V3
35
36 enum CodecType {
37     CODEC_TYPE_VIDEO,
38     CODEC_TYPE_AUDIO,
39 };
40
41 enum PixelFormat {
42     PIX_FMT_YUV420P,
43     PIX_FMT_YUV422,
44     PIX_FMT_RGB24,
45     PIX_FMT_BGR24,
46     PIX_FMT_YUV422P,
47     PIX_FMT_YUV444P,
48 };
49
50 /* currently unused, may be used if 24/32 bits samples ever supported */
51 enum SampleFormat {
52     SAMPLE_FMT_S16 = 0,         /* signed 16 bits */
53 };
54
55 /* in bytes */
56 #define AVCODEC_MAX_AUDIO_FRAME_SIZE 18432
57
58 /* motion estimation type */
59 extern int motion_estimation_method;
60 #define ME_ZERO   0
61 #define ME_FULL   1
62 #define ME_LOG    2
63 #define ME_PHODS  3
64 #define ME_EPZS   4
65 #define ME_X1     5
66
67 /* encoding support */
68 /* note not everything is supported yet */
69
70 #define CODEC_FLAG_HQ     0x0001 /* high quality (non real time) encoding */
71 #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
72 #define CODEC_FLAG_4MV    0x0004 /* 4 MV per MB allowed */
73 #define CODEC_FLAG_B      0x0008 /* use B frames */
74 #define CODEC_FLAG_QPEL   0x0010 /* use qpel MC */
75 #define CODEC_FLAG_GMC    0x0020 /* use GMC */
76 #define CODEC_FLAG_TYPE   0x0040 /* fixed I/P frame type, from avctx->key_frame */
77
78 /* codec capabilities */
79
80 /* decoder can use draw_horiz_band callback */
81 #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001
82
83 #define FRAME_RATE_BASE 10000
84
85 typedef struct AVCodecContext {
86     int bit_rate;
87     int bit_rate_tolerance; /* amount of +- bits (>0)*/
88     int flags;
89     int sub_id;    /* some codecs needs additionnal format info. It is
90                       stored there */
91     /* video only */
92     int frame_rate; /* frames per sec multiplied by FRAME_RATE_BASE */
93     int width, height;
94     int aspect_ratio_info;
95 #define FF_ASPECT_SQUARE 1
96 #define FF_ASPECT_4_3_625 2
97 #define FF_ASPECT_4_3_525 3
98 #define FF_ASPECT_16_9_625 4
99 #define FF_ASPECT_16_9_525 5
100     int gop_size; /* 0 = intra only */
101     int pix_fmt;  /* pixel format, see PIX_FMT_xxx */
102
103     /* if non NULL, 'draw_horiz_band' is called by the libavcodec
104        decoder to draw an horizontal band. It improve cache usage. Not
105        all codecs can do that. You must check the codec capabilities
106        before */
107     void (*draw_horiz_band)(struct AVCodecContext *s,
108                             UINT8 **src_ptr, int linesize,
109                             int y, int width, int height);
110
111     /* audio only */
112     int sample_rate; /* samples per sec */
113     int channels;
114     int sample_fmt;  /* sample format, currenly unused */
115
116     /* the following data should not be initialized */
117     int frame_size; /* in samples, initialized when calling 'init' */
118     int frame_number; /* audio or video frame number */
119     int key_frame;    /* true if the previous compressed frame was 
120                          a key frame (intra, or seekable) */
121     int quality;      /* quality of the previous encoded frame 
122                          (between 1 (good) and 31 (bad)) */
123     float qcompress;  /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
124     float qblur;      /* amount of qscale smoothing over time (0.0-1.0) */
125     int qmin;         /* min qscale */
126     int qmax;         /* max qscale */
127     int max_qdiff;    /* max qscale difference between frames */
128     
129     struct AVCodec *codec;
130     void *priv_data;
131
132     /* The following data is for RTP friendly coding */
133     /* By now only H.263/H.263+ coder honours this   */
134     int rtp_mode;   /* 1 for activate RTP friendly-mode           */
135                     /* highers numbers represent more error-prone */
136                     /* enviroments, by now just "1" exist         */
137     
138     int rtp_payload_size;   /* The size of the RTP payload, the coder will  */
139                             /* do it's best to deliver a chunk with size    */
140                             /* below rtp_payload_size, the chunk will start */
141                             /* with a start code on some codecs like H.263  */
142                             /* This doesn't take account of any particular  */
143                             /* headers inside the transmited RTP payload    */
144
145     
146     /* The RTP callcack: This function is called  */
147     /* every time the encoder as a packet to send */
148     /* Depends on the encoder if the data starts  */
149     /* with a Start Code (it should) H.263 does   */
150     void (*rtp_callback)(void *data, int size, int packet_number); 
151
152     /* These are for PSNR calculation, if you set get_psnr to 1 */
153     /* after encoding you will have the PSNR on psnr_y/cb/cr    */
154     int get_psnr;
155     float psnr_y;
156     float psnr_cb;
157     float psnr_cr;
158     
159     /* statistics, used for 2-pass encoding */
160     int mv_bits;
161     int header_bits;
162     int i_tex_bits;
163     int p_tex_bits;
164     int i_count;
165     int p_count;
166     int skip_count;
167     int misc_bits; // cbp, mb_type
168     int frame_bits;
169                  
170     /* the following fields are ignored */
171     void *opaque;   /* can be used to carry app specific stuff */
172     char codec_name[32];
173     int codec_type; /* see CODEC_TYPE_xxx */
174     int codec_id; /* see CODEC_ID_xxx */
175     unsigned int codec_tag;  /* codec tag, only used if unknown codec */
176 } AVCodecContext;
177
178 typedef struct AVCodec {
179     char *name;
180     int type;
181     int id;
182     int priv_data_size;
183     int (*init)(AVCodecContext *);
184     int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
185     int (*close)(AVCodecContext *);
186     int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, 
187                   UINT8 *buf, int buf_size);
188     int capabilities;
189     struct AVCodec *next;
190 } AVCodec;
191
192 /* three components are given, that's all */
193 typedef struct AVPicture {
194     UINT8 *data[3];
195     int linesize[3];
196 } AVPicture;
197
198 extern AVCodec ac3_encoder;
199 extern AVCodec mp2_encoder;
200 extern AVCodec mp3lame_encoder;
201 extern AVCodec mpeg1video_encoder;
202 extern AVCodec h263_encoder;
203 extern AVCodec h263p_encoder;
204 extern AVCodec rv10_encoder;
205 extern AVCodec mjpeg_encoder;
206 extern AVCodec mpeg4_encoder;
207 extern AVCodec msmpeg4v1_encoder;
208 extern AVCodec msmpeg4v2_encoder;
209 extern AVCodec msmpeg4v3_encoder;
210
211 extern AVCodec h263_decoder;
212 extern AVCodec mpeg4_decoder;
213 extern AVCodec msmpeg4v1_decoder;
214 extern AVCodec msmpeg4v2_decoder;
215 extern AVCodec msmpeg4v3_decoder;
216 extern AVCodec wmv1_decoder;
217 extern AVCodec mpeg_decoder;
218 extern AVCodec h263i_decoder;
219 extern AVCodec rv10_decoder;
220 extern AVCodec mjpeg_decoder;
221 extern AVCodec mp3_decoder;
222
223 /* pcm codecs */
224 #define PCM_CODEC(id, name) \
225 extern AVCodec name ## _decoder; \
226 extern AVCodec name ## _encoder;
227
228 PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
229 PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
230 PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
231 PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
232 PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
233 PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
234 PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
235 PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
236
237 #undef PCM_CODEC
238
239 /* dummy raw video codec */
240 extern AVCodec rawvideo_codec;
241
242 /* the following codecs use external GPL libs */
243 extern AVCodec ac3_decoder;
244
245 /* resample.c */
246
247 struct ReSampleContext;
248
249 typedef struct ReSampleContext ReSampleContext;
250
251 ReSampleContext *audio_resample_init(int output_channels, int input_channels, 
252                                      int output_rate, int input_rate);
253 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
254 void audio_resample_close(ReSampleContext *s);
255
256 /* YUV420 format is assumed ! */
257
258 struct ImgReSampleContext;
259
260 typedef struct ImgReSampleContext ImgReSampleContext;
261
262 ImgReSampleContext *img_resample_init(int output_width, int output_height,
263                                       int input_width, int input_height);
264 void img_resample(ImgReSampleContext *s, 
265                   AVPicture *output, AVPicture *input);
266
267 void img_resample_close(ImgReSampleContext *s);
268
269 void avpicture_fill(AVPicture *picture, UINT8 *ptr,
270                     int pix_fmt, int width, int height);
271 int avpicture_get_size(int pix_fmt, int width, int height);
272
273 /* convert among pixel formats */
274 int img_convert(AVPicture *dst, int dst_pix_fmt,
275                 AVPicture *src, int pix_fmt, 
276                 int width, int height);
277
278 /* deinterlace a picture */
279 int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
280                           int pix_fmt, int width, int height);
281
282 /* external high level API */
283
284 extern AVCodec *first_avcodec;
285
286 void avcodec_init(void);
287
288 void register_avcodec(AVCodec *format);
289 AVCodec *avcodec_find_encoder(enum CodecID id);
290 AVCodec *avcodec_find_encoder_by_name(const char *name);
291 AVCodec *avcodec_find_decoder(enum CodecID id);
292 AVCodec *avcodec_find_decoder_by_name(const char *name);
293 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
294
295 int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
296 int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples, 
297                          int *frame_size_ptr,
298                          UINT8 *buf, int buf_size);
299 int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture, 
300                          int *got_picture_ptr,
301                          UINT8 *buf, int buf_size);
302 int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size, 
303                          const short *samples);
304 int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size, 
305                          const AVPicture *pict);
306
307 int avcodec_close(AVCodecContext *avctx);
308
309 void avcodec_register_all(void);
310
311 #ifdef FF_POSTPROCESS
312 #ifndef MBC
313 #define MBC 48
314 #define MBR 36
315 #endif
316 extern int quant_store[MBR+1][MBC+1]; // [Review]
317 #endif
318
319 #endif /* AVCODEC_H */