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