expand tabs
[platform/upstream/gstreamer.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_YVU420P,   ///< Planar YUV 4:2:0 (1 Cb & Cr sample per 2x2 Y samples) (YV12)
57     PIX_FMT_YUV422,    ///< Packed pixel, Y0 Cb Y1 Cr 
58     PIX_FMT_RGB24,     ///< Packed pixel, 3 bytes per pixel, RGBRGB...
59     PIX_FMT_BGR24,     ///< Packed pixel, 3 bytes per pixel, BGRBGR...
60     PIX_FMT_YUV422P,   ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
61     PIX_FMT_YUV444P,   ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
62     PIX_FMT_RGBA32,    ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
63     PIX_FMT_BGRA32,     ///< Packed pixel, 4 bytes per pixel, ARGBARGB...
64     PIX_FMT_RGB32,     ///< Packed pixel, 4 bytes per pixel, BGRXBGRX..., stored in cpu endianness
65     PIX_FMT_BGR32,     ///< Packed pixel, 4 bytes per pixel, XRGBXRGB...
66     PIX_FMT_YUV410P,   ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
67     PIX_FMT_YUV411P,   ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
68     PIX_FMT_RGB565,    ///< always stored in cpu endianness 
69     PIX_FMT_RGB555,    ///< always stored in cpu endianness, most significant bit to 1 
70     PIX_FMT_GRAY8,
71     PIX_FMT_MONOWHITE, ///< 0 is white 
72     PIX_FMT_MONOBLACK, ///< 0 is black 
73     PIX_FMT_PAL8,      ///< 8 bit with RGBA palette 
74     PIX_FMT_YUVJ420P,  ///< Planar YUV 4:2:0 full scale (jpeg)
75     PIX_FMT_YUVJ422P,  ///< Planar YUV 4:2:2 full scale (jpeg)
76     PIX_FMT_YUVJ444P,  ///< Planar YUV 4:4:4 full scale (jpeg)
77     PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
78     PIX_FMT_XVMC_MPEG2_IDCT,
79     PIX_FMT_UYVY422,   ///< Packed pixel, Cb Y0 Cr Y1 
80     PIX_FMT_UYVY411,   ///< Packed pixel, Cb Y0 Y1 Cr Y2 Y3
81
82     PIX_FMT_AYUV4444,  ///< Packed pixel, A0 Y0 Cb Cr
83     PIX_FMT_NB
84 };
85
86 /* currently unused, may be used if 24/32 bits samples ever supported */
87 enum SampleFormat {
88     SAMPLE_FMT_S16 = 0,         ///< signed 16 bits
89 };
90
91 /* thomas: extracted from imgconvert.c since it's also used in
92  * gstffmpegcodecmap.c */
93
94 /* start of extract */
95
96 #define FF_COLOR_RGB      0     /* RGB color space */
97 #define FF_COLOR_GRAY     1     /* gray color space */
98 #define FF_COLOR_YUV      2     /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
99 #define FF_COLOR_YUV_JPEG 3     /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
100
101 #define FF_PIXEL_PLANAR   0     /* each channel has one component in AVPicture */
102 #define FF_PIXEL_PACKED   1     /* only one components containing all the channels */
103 #define FF_PIXEL_PALETTE  2     /* one components containing indexes for a palette */
104
105 typedef struct PixFmtInfo
106 {
107   enum PixelFormat format;
108   const char *name;
109   uint8_t nb_channels;          /* number of channels (including alpha) */
110   uint8_t color_type;           /* color type (see FF_COLOR_xxx constants) */
111   uint8_t pixel_type;           /* pixel storage type (see FF_PIXEL_xxx constants) */
112   uint8_t is_alpha:1;           /* true if alpha can be specified */
113   uint8_t x_chroma_shift;       /* X chroma subsampling factor is 2 ^ shift */
114   uint8_t y_chroma_shift;       /* Y chroma subsampling factor is 2 ^ shift */
115   uint8_t depth;                /* bit depth of the color components */
116 } PixFmtInfo;
117
118 PixFmtInfo * get_pix_fmt_info (enum PixelFormat format);
119 /* end of extract */
120
121 /**
122  * main external api structure.
123  */
124 typedef struct AVCodecContext {
125     /* video only */
126     /**
127      * frames per sec multiplied by frame_rate_base.
128      * for variable fps this is the precission, so if the timestamps 
129      * can be specified in msec precssion then this is 1000*frame_rate_base
130      * - encoding: MUST be set by user
131      * - decoding: set by lavc. 0 or the frame_rate if available
132      */
133     int frame_rate;
134     
135     /**
136      * frame_rate_base.
137      * for variable fps this is 1
138      * - encoding: set by user.
139      * - decoding: set by lavc.
140      */
141
142     int frame_rate_base;
143     /**
144      * picture width / height.
145      * - encoding: MUST be set by user. 
146      * - decoding: set by lavc.
147      * Note, for compatibility its possible to set this instead of 
148      * coded_width/height before decoding
149      */
150     int width, height;
151
152     /**
153      * pixel format, see PIX_FMT_xxx.
154      * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
155      *                    conversion is in order. This only works for
156      *                    codecs with one supported pix_fmt, we should
157      *                    do something for a generic case as well.
158      * - decoding: set by lavc.
159      */
160     enum PixelFormat pix_fmt;
161
162     /* audio only */
163     int sample_rate; ///< samples per sec 
164     int channels;
165     int sample_fmt;  ///< sample format, currenly unused 
166
167     /**
168      * Palette control structure
169      * - encoding: ??? (no palette-enabled encoder yet)
170      * - decoding: set by user.
171      */
172     struct AVPaletteControl *palctrl;
173 } AVCodecContext;
174
175 /**
176  * four components are given, that's all.
177  * the last component is alpha
178  */
179 typedef struct AVPicture {
180     uint8_t *data[4];
181     int linesize[4];       ///< number of bytes per line
182 } AVPicture;
183
184 /**
185  * AVPaletteControl
186  * This structure defines a method for communicating palette changes
187  * between and demuxer and a decoder.
188  */
189 #define AVPALETTE_SIZE 1024
190 #define AVPALETTE_COUNT 256
191 typedef struct AVPaletteControl {
192
193     /* demuxer sets this to 1 to indicate the palette has changed;
194      * decoder resets to 0 */
195     int palette_changed;
196
197     /* 4-byte ARGB palette entries, stored in native byte order; note that
198      * the individual palette components should be on a 8-bit scale; if
199      * the palette data comes from a IBM VGA native format, the component
200      * data is probably 6 bits in size and needs to be scaled */
201     unsigned int palette[AVPALETTE_COUNT];
202
203 } AVPaletteControl;
204
205 int avpicture_get_size(int pix_fmt, int width, int height);
206
207 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
208 const char *avcodec_get_pix_fmt_name(int pix_fmt);
209 void avcodec_set_dimensions(AVCodecContext *s, int width, int height);
210 enum PixelFormat avcodec_get_pix_fmt(const char* name);
211
212 #define FF_LOSS_RESOLUTION  0x0001 /* loss due to resolution change */
213 #define FF_LOSS_DEPTH       0x0002 /* loss due to color depth change */
214 #define FF_LOSS_COLORSPACE  0x0004 /* loss due to color space conversion */
215 #define FF_LOSS_ALPHA       0x0008 /* loss of alpha bits */
216 #define FF_LOSS_COLORQUANT  0x0010 /* loss due to color quantization */
217 #define FF_LOSS_CHROMA      0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
218
219 int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
220                              int has_alpha);
221 int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
222                               int has_alpha, int *loss_ptr);
223
224 #define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
225 #define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
226 int img_get_alpha_info(const AVPicture *src,
227                        int pix_fmt, int width, int height);
228
229 /* convert among pixel formats */
230 int img_convert(AVPicture *dst, int dst_pix_fmt,
231                 const AVPicture *src, int pix_fmt, 
232                 int width, int height);
233
234 void avcodec_init(void);
235
236 void avcodec_get_context_defaults(AVCodecContext *s);
237 AVCodecContext *avcodec_alloc_context(void);
238
239 /* memory */
240 void *av_malloc(unsigned int size);
241 void *av_mallocz(unsigned int size);
242 void *av_realloc(void *ptr, unsigned int size);
243 void av_free(void *ptr);
244 char *av_strdup(const char *s);
245 void av_freep(void *ptr);
246 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
247 /* for static data only */
248 /* call av_free_static to release all staticaly allocated tables */
249 void av_free_static(void);
250 void *av_mallocz_static(unsigned int size);
251
252 /* endian macros */
253 #if !defined(BE_16) || !defined(BE_32) || !defined(LE_16) || !defined(LE_32)
254 #define BE_16(x)  ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
255 #define BE_32(x)  ((((uint8_t*)(x))[0] << 24) | \
256                    (((uint8_t*)(x))[1] << 16) | \
257                    (((uint8_t*)(x))[2] << 8) | \
258                     ((uint8_t*)(x))[3])
259 #define LE_16(x)  ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
260 #define LE_32(x)  ((((uint8_t*)(x))[3] << 24) | \
261                    (((uint8_t*)(x))[2] << 16) | \
262                    (((uint8_t*)(x))[1] << 8) | \
263                     ((uint8_t*)(x))[0])
264 #endif
265
266 #ifdef __cplusplus
267 }
268 #endif
269
270 #endif /* AVCODEC_H */