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