typo fixes
[mplayer/greg.git] / libmpcodecs / vd_xvid.c
blobf2ca6a152b18f49a4943af19d63447bb837c355e
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "config.h"
5 #include "mp_msg.h"
7 #ifdef HAVE_XVID3
9 #include "vd_internal.h"
10 #include "m_option.h"
12 #include <xvid.h>
14 #ifdef XVID_API_UNSTABLE
15 #warning *******************************************************************
16 #warning ** **
17 #warning ** Y O U '' R E U S I N G U N S T A B L E S O F T W A R E **
18 #warning ** **
19 #warning ** There are bugs, this code could crash, could blow up your PC **
20 #warning ** or the whole building and do many other nasty things ! **
21 #warning ** **
22 #warning ** If you want stable code use stable XViD releases (0.9.x). **
23 #warning ** **
24 #warning *******************************************************************
25 #endif
27 typedef struct
29 void *y;
30 void *u;
31 void *v;
32 int stride_y;
33 int stride_uv;
35 DIVX4_DEC_PICTURE;
39 static vd_info_t info =
41 "xvid decoder",
42 "xvid",
43 "Albeu",
44 "Albeu",
48 LIBVD_EXTERN(xvid)
50 typedef struct {
51 int cs;
52 unsigned char img_type;
53 void* hdl;
54 mp_image_t* mpi;
55 } priv_t;
57 static int do_dr2 = 0;
59 m_option_t xvid_dec_opts[] = {
60 { "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL},
61 { "nodr2", &do_dr2, CONF_TYPE_FLAG, 0, 1, 0, NULL},
62 {NULL, NULL, 0, 0, 0, 0, NULL}
65 // to set/get/query special features/parameters
66 static int control(sh_video_t *sh,int cmd,void* arg,...){
67 return CONTROL_UNKNOWN;
70 // init driver
71 static int init(sh_video_t *sh){
72 XVID_INIT_PARAM ini;
73 XVID_DEC_PARAM dec_p;
74 priv_t* p;
75 int cs;
77 #ifdef XVID_API_UNSTABLE
78 mp_msg (MSGT_DECVIDEO, MSGL_WARN,
79 "\n"
80 "*******************************************************************\n"
81 "** **\n"
82 "** Y O U ' R E U S I N G U N S T A B L E S O F T W A R E **\n"
83 "** **\n"
84 "** There are bugs, this code could crash, could blow up your PC **\n"
85 "** or the whole building and do many other nasty things ! **\n"
86 "** **\n"
87 "** If you want stable code use stable XViD releases (0.9.x). **\n"
88 "** **\n"
89 "*******************************************************************\n"
90 "\n");
91 #endif
93 memset(&ini,0,sizeof(XVID_INIT_PARAM));
94 memset(&dec_p,0,sizeof(XVID_DEC_PARAM));
96 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12))
97 return 0;
99 switch(sh->codec->outfmt[sh->outfmtidx]){
100 case IMGFMT_YV12:
101 #ifdef XVID_CSP_EXTERN
102 cs= do_dr2 ? XVID_CSP_EXTERN : XVID_CSP_USER;
103 #else
104 cs= XVID_CSP_USER;
105 #endif
106 break;
107 case IMGFMT_YUY2:
108 cs=XVID_CSP_YUY2;
109 break;
110 case IMGFMT_UYVY:
111 cs=XVID_CSP_UYVY;
112 break;
113 case IMGFMT_I420:
114 case IMGFMT_IYUV:
115 cs=XVID_CSP_I420;
116 break;
117 case IMGFMT_BGR15:
118 cs=XVID_CSP_RGB555;
119 break;
120 case IMGFMT_BGR16:
121 cs=XVID_CSP_RGB565;
122 break;
123 case IMGFMT_BGR24:
124 cs=XVID_CSP_RGB24;
125 break;
126 case IMGFMT_BGR32:
127 cs=XVID_CSP_RGB32;
128 break;
129 case IMGFMT_YVYU:
130 cs=XVID_CSP_YVYU;
131 break;
132 default:
133 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",sh->codec->outfmt[sh->outfmtidx]);
134 return 0;
137 if(xvid_init(NULL, 0, &ini, NULL))
138 return 0;
140 if(ini.api_version != API_VERSION) {
141 if(ini.api_version < API_VERSION) {
142 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Too old version of xvid (min. %d)\n",API_VERSION);
143 return 0;
145 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Bad xvid version %d was compiled with %d\n",
146 ini.api_version,API_VERSION);
149 dec_p.width = sh->disp_w;
150 dec_p.height = sh->disp_h;
152 if(xvid_decore(NULL, XVID_DEC_CREATE, &dec_p, NULL)) {
153 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"xvid init failed\n");
154 return 0;
157 p = (priv_t*)malloc(sizeof(priv_t));
158 p->cs = cs;
159 p->hdl = dec_p.handle;
160 sh->context = p;
162 switch(cs) {
163 #ifdef XVID_CSP_EXTERN
164 case XVID_CSP_EXTERN:
165 p->img_type = MP_IMGTYPE_STATIC;
166 break;
167 #endif
168 case XVID_CSP_USER:
169 p->img_type = MP_IMGTYPE_EXPORT;
170 break;
171 default:
172 p->img_type = MP_IMGTYPE_TEMP;
173 break;
176 return 1;
179 // uninit driver
180 static void uninit(sh_video_t *sh){
181 priv_t* p = sh->context;
182 if(!p)
183 return;
184 xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL);
185 free(p);
188 // decode a frame
189 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
190 XVID_DEC_FRAME dec;
191 DIVX4_DEC_PICTURE d4_pic;
192 #ifdef XVID_CSP_EXTERN
193 XVID_DEC_PICTURE pic;
194 #endif
195 priv_t* p = sh->context;
197 mp_image_t* mpi = mpcodecs_get_image(sh, p->img_type,
198 MP_IMGFLAG_ACCEPT_STRIDE,
199 sh->disp_w,sh->disp_h);
201 if(!data || !mpi || len <= 0)
202 return NULL;
204 memset(&dec,0,sizeof(XVID_DEC_FRAME));
206 dec.bitstream = data;
207 dec.length = len;
208 #ifdef XVID_API_UNSTABLE
209 dec.general |= XVID_DEC_LOWDELAY;
210 #endif
211 switch(p->cs) {
212 case XVID_CSP_USER:
213 dec.image = &d4_pic;
214 break;
215 #ifdef XVID_CSP_EXTERN
216 case XVID_CSP_EXTERN:
217 pic.y = mpi->planes[0];
218 pic.u = mpi->planes[1];
219 pic.v = mpi->planes[2];
220 pic.stride_y = mpi->stride[0];
221 pic.stride_u = mpi->stride[1];
222 pic.stride_v = mpi->stride[2];
223 dec.image = &pic;
224 break;
225 #endif
226 default:
227 dec.image = mpi->planes[0];
228 if(IMGFMT_IS_BGR(mpi->imgfmt) || IMGFMT_IS_RGB(mpi->imgfmt))
229 dec.stride = mpi->width;
230 else
231 dec.stride = mpi->stride[0];
233 dec.colorspace = p->cs;
235 if(xvid_decore(p->hdl,XVID_DEC_DECODE,&dec,NULL)) {
236 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"decoding error\n");
237 return NULL;
240 if(p->cs == XVID_CSP_USER) {
241 mpi->planes[0] = d4_pic.y;
242 mpi->planes[1] = d4_pic.u;
243 mpi->planes[2] = d4_pic.v;
244 mpi->stride[0] = d4_pic.stride_y;
245 mpi->stride[1] = mpi->stride[2] = d4_pic.stride_uv;
248 return mpi;
250 #endif //have_xvid