57f551ce5f953fab4b39a63b124d8e6357d03d66
[framework/multimedia/gst-plugins-base0.10.git] / gst / ffmpegcolorspace / avcodec.h
1 #ifndef AVCODEC_H
2 #define AVCODEC_H
3
4 /**
5  * @file avcodec.h
6  * external api header.
7  */
8
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include "_stdint.h"
15
16 #include <sys/types.h> /* size_t */
17
18 #define FFMPEG_VERSION_INT     0x000409
19 #define FFMPEG_VERSION         "0.4.9-pre1"
20 #define LIBAVCODEC_BUILD       4728
21
22 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
23 #define LIBAVCODEC_VERSION     FFMPEG_VERSION
24
25 #define AV_STRINGIFY(s) AV_TOSTRING(s)
26 #define AV_TOSTRING(s) #s
27 #define LIBAVCODEC_IDENT        "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD)
28
29 enum CodecType {
30     CODEC_TYPE_UNKNOWN = -1,
31     CODEC_TYPE_VIDEO,
32     CODEC_TYPE_AUDIO,
33     CODEC_TYPE_DATA,
34 };
35
36 /*
37  * Pixel format. Notes: 
38  *
39  * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
40  * color is put together as:
41  *  (A << 24) | (R << 16) | (G << 8) | B
42  * This is stored as BGRA on little endian CPU architectures and ARGB on
43  * big endian CPUs.
44  *
45  * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
46  * image data is stored in AVFrame.data[0]. The palette is transported in
47  * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
48  * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
49  * also endian-specific). Note also that the individual RGB palette
50  * components stored in AVFrame.data[1] should be in the range 0..255.
51  * This is important as many custom PAL8 video codecs that were designed
52  * to run on the IBM VGA graphics adapter use 6-bit palette components.
53  */
54 enum PixelFormat {
55     PIX_FMT_YUV420P,   ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples) (I420)
56     PIX_FMT_NV12,      ///< Packed YUV 4:2:0 (separate Y plane, interleaved Cb & Cr planes)
57     PIX_FMT_NV21,      ///< Packed YUV 4:2:0 (separate Y plane, interleaved Cb & Cr planes)
58     PIX_FMT_YVU420P,   ///< Planar YUV 4:2:0 (1 Cb & Cr sample per 2x2 Y samples) (YV12)
59     PIX_FMT_YUV422,    ///< Packed pixel, Y0 Cb Y1 Cr 
60     PIX_FMT_RGB24,     ///< Packed pixel, 3 bytes per pixel, RGBRGB...
61     PIX_FMT_BGR24,     ///< Packed pixel, 3 bytes per pixel, BGRBGR...
62     PIX_FMT_YUV422P,   ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
63     PIX_FMT_YUV444P,   ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
64     PIX_FMT_RGBA32,    ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
65     PIX_FMT_BGRA32,    ///< Packed pixel, 4 bytes per pixel, ARGBARGB...
66     PIX_FMT_ARGB32,    ///< Packed pixel, 4 bytes per pixel, ABGRABGR..., stored in cpu endianness
67     PIX_FMT_ABGR32,    ///< Packed pixel, 4 bytes per pixel, RGBARGBA...
68     PIX_FMT_RGB32,     ///< Packed pixel, 4 bytes per pixel, BGRxBGRx..., stored in cpu endianness
69     PIX_FMT_xRGB32,    ///< Packed pixel, 4 bytes per pixel, xBGRxBGR..., stored in cpu endianness
70     PIX_FMT_BGR32,     ///< Packed pixel, 4 bytes per pixel, xRGBxRGB...
71     PIX_FMT_BGRx32,    ///< Packed pixel, 4 bytes per pixel, RGBxRGBx...
72     PIX_FMT_YUV410P,   ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
73     PIX_FMT_YVU410P,   ///< Planar YVU 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
74     PIX_FMT_YUV411P,   ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
75     PIX_FMT_Y800,      ///< 8 bit Y plane (range [16-235])
76     PIX_FMT_Y16,       ///< 16 bit Y plane (little endian)
77     PIX_FMT_RGB565,    ///< always stored in cpu endianness 
78     PIX_FMT_RGB555,    ///< always stored in cpu endianness, most significant bit to 1 
79     PIX_FMT_GRAY8,
80     PIX_FMT_GRAY16_L,
81     PIX_FMT_GRAY16_B,
82     PIX_FMT_MONOWHITE, ///< 0 is white 
83     PIX_FMT_MONOBLACK, ///< 0 is black 
84     PIX_FMT_PAL8,      ///< 8 bit with RGBA palette 
85     PIX_FMT_YUVJ420P,  ///< Planar YUV 4:2:0 full scale (jpeg)
86     PIX_FMT_YUVJ422P,  ///< Planar YUV 4:2:2 full scale (jpeg)
87     PIX_FMT_YUVJ444P,  ///< Planar YUV 4:4:4 full scale (jpeg)
88     PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
89     PIX_FMT_XVMC_MPEG2_IDCT,
90     PIX_FMT_UYVY422,   ///< Packed pixel, Cb Y0 Cr Y1 
91     PIX_FMT_YVYU422,   ///< Packed pixel, Y0 Cr Y1 Cb 
92     PIX_FMT_UYVY411,   ///< Packed pixel, Cb Y0 Y1 Cr Y2 Y3
93     PIX_FMT_V308,      ///< Packed pixel, Y0 Cb Cr
94
95     PIX_FMT_AYUV4444,  ///< Packed pixel, A0 Y0 Cb Cr
96     PIX_FMT_YUVA420P,   ///< Planar YUV 4:4:2:0 (1 Cr & Cb sample per 2x2 Y & A samples) (A420)
97     PIX_FMT_NB
98 };
99
100 /* currently unused, may be used if 24/32 bits samples ever supported */
101 enum SampleFormat {
102     SAMPLE_FMT_S16 = 0,         ///< signed 16 bits
103 };
104
105 /* thomas: extracted from imgconvert.c since it's also used in
106  * gstffmpegcodecmap.c */
107
108 /* start of extract */
109
110 #define FF_COLOR_RGB      0     /* RGB color space */
111 #define FF_COLOR_GRAY     1     /* gray color space */
112 #define FF_COLOR_YUV      2     /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
113 #define FF_COLOR_YUV_JPEG 3     /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
114
115 #define FF_PIXEL_PLANAR   0     /* each channel has one component in AVPicture */
116 #define FF_PIXEL_PACKED   1     /* only one components containing all the channels */
117 #define FF_PIXEL_PALETTE  2     /* one components containing indexes for a palette */
118
119 typedef struct PixFmtInfo
120 {
121   enum PixelFormat format;
122   const char *name;
123   uint8_t nb_channels;          /* number of channels (including alpha) */
124   uint8_t color_type;           /* color type (see FF_COLOR_xxx constants) */
125   uint8_t pixel_type;           /* pixel storage type (see FF_PIXEL_xxx constants) */
126   uint8_t is_alpha:1;           /* true if alpha can be specified */
127   uint8_t x_chroma_shift;       /* X chroma subsampling factor is 2 ^ shift */
128   uint8_t y_chroma_shift;       /* Y chroma subsampling factor is 2 ^ shift */
129   uint8_t depth;                /* bit depth of the color components */
130 } PixFmtInfo;
131
132 PixFmtInfo * get_pix_fmt_info (enum PixelFormat format);
133 /* end of extract */
134
135 /**
136  * main external api structure.
137  */
138 typedef struct AVCodecContext {
139     /* video only */
140     /**
141      * frames per sec multiplied by frame_rate_base.
142      * for variable fps this is the precission, so if the timestamps 
143      * can be specified in msec precssion then this is 1000*frame_rate_base
144      * - encoding: MUST be set by user
145      * - decoding: set by lavc. 0 or the frame_rate if available
146      */
147     int frame_rate;
148     
149     /**
150      * frame_rate_base.
151      * for variable fps this is 1
152      * - encoding: set by user.
153      * - decoding: set by lavc.
154      */
155
156     int frame_rate_base;
157     /**
158      * picture width / height.
159      * - encoding: MUST be set by user. 
160      * - decoding: set by lavc.
161      * Note, for compatibility its possible to set this instead of 
162      * coded_width/height before decoding
163      */
164     int width, height;
165
166     /**
167      * pixel format, see PIX_FMT_xxx.
168      * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
169      *                    conversion is in order. This only works for
170      *                    codecs with one supported pix_fmt, we should
171      *                    do something for a generic case as well.
172      * - decoding: set by lavc.
173      */
174     enum PixelFormat pix_fmt;
175
176     /* audio only */
177     int sample_rate; ///< samples per sec 
178     int channels;
179     int sample_fmt;  ///< sample format, currenly unused 
180
181     /**
182      * Palette control structure
183      * - encoding: ??? (no palette-enabled encoder yet)
184      * - decoding: set by user.
185      */
186     struct AVPaletteControl *palctrl;
187 } AVCodecContext;
188
189 /**
190  * four components are given, that's all.
191  * the last component is alpha
192  */
193 typedef struct AVPicture {
194     uint8_t *data[4];
195     int linesize[4];       ///< number of bytes per line
196     int interlaced;
197 } AVPicture;
198
199 /**
200  * AVPaletteControl
201  * This structure defines a method for communicating palette changes
202  * between and demuxer and a decoder.
203  */
204 #define AVPALETTE_SIZE 1024
205 #define AVPALETTE_COUNT 256
206 typedef struct AVPaletteControl {
207
208     /* demuxer sets this to 1 to indicate the palette has changed;
209      * decoder resets to 0 */
210     int palette_changed;
211
212     /* 4-byte ARGB palette entries, stored in native byte order; note that
213      * the individual palette components should be on a 8-bit scale; if
214      * the palette data comes from a IBM VGA native format, the component
215      * data is probably 6 bits in size and needs to be scaled */
216     unsigned int palette[AVPALETTE_COUNT];
217
218 } AVPaletteControl;
219
220 int avpicture_get_size(int pix_fmt, int width, int height);
221
222 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
223 const char *avcodec_get_pix_fmt_name(int pix_fmt);
224 void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
225 enum PixelFormat avcodec_get_pix_fmt(const char* name);
226
227 #define FF_LOSS_RESOLUTION  0x0001 /* loss due to resolution change */
228 #define FF_LOSS_DEPTH       0x0002 /* loss due to color depth change */
229 #define FF_LOSS_COLORSPACE  0x0004 /* loss due to color space conversion */
230 #define FF_LOSS_ALPHA       0x0008 /* loss of alpha bits */
231 #define FF_LOSS_COLORQUANT  0x0010 /* loss due to color quantization */
232 #define FF_LOSS_CHROMA      0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
233
234 int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
235                              int has_alpha);
236 int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
237                               int has_alpha, int *loss_ptr);
238
239 #define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
240 #define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
241 int img_get_alpha_info(const AVPicture *src,
242                        int pix_fmt, int width, int height);
243
244 /* convert among pixel formats */
245 int img_convert(AVPicture *dst, int dst_pix_fmt,
246                 const AVPicture *src, int pix_fmt, 
247                 int width, int height);
248
249 void avcodec_init(void);
250
251 void avcodec_get_context_defaults(AVCodecContext *s);
252 AVCodecContext *avcodec_alloc_context(void);
253
254 /* memory */
255 void *av_malloc(unsigned int size);
256 void *av_mallocz(unsigned int size);
257 void *av_realloc(void *ptr, unsigned int size);
258 void av_free(void *ptr);
259 char *av_strdup(const char *s);
260 void av_freep(void *ptr);
261 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
262 /* for static data only */
263 /* call av_free_static to release all staticaly allocated tables */
264 void av_free_static(void);
265 void *av_mallocz_static(unsigned int size);
266
267 /* endian macros */
268 #if !defined(BE_16) || !defined(BE_32) || !defined(LE_16) || !defined(LE_32)
269 #define BE_16(x)  ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
270 #define BE_32(x)  ((((uint8_t*)(x))[0] << 24) | \
271                    (((uint8_t*)(x))[1] << 16) | \
272                    (((uint8_t*)(x))[2] << 8) | \
273                     ((uint8_t*)(x))[3])
274 #define LE_16(x)  ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
275 #define LE_32(x)  ((((uint8_t*)(x))[3] << 24) | \
276                    (((uint8_t*)(x))[2] << 16) | \
277                    (((uint8_t*)(x))[1] << 8) | \
278                     ((uint8_t*)(x))[0])
279 #endif
280
281 #ifdef __cplusplus
282 }
283 #endif
284
285 #endif /* AVCODEC_H */