9 #include "vd_internal.h"
14 #ifdef XVID_API_UNSTABLE
15 #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 **
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 ! **
22 #warning ** If you want stable code use stable XViD releases (0.9.x). **
24 #warning *******************************************************************
39 static vd_info_t info
=
52 unsigned char img_type
;
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
;
71 static int init(sh_video_t
*sh
){
77 #ifdef XVID_API_UNSTABLE
78 mp_msg (MSGT_DECVIDEO
, MSGL_WARN
,
80 "*******************************************************************\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"
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"
87 "** If you want stable code use stable XViD releases (0.9.x). **\n"
89 "*******************************************************************\n"
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
))
99 switch(sh
->codec
->outfmt
[sh
->outfmtidx
]){
101 #ifdef XVID_CSP_EXTERN
102 cs
= do_dr2
? XVID_CSP_EXTERN
: XVID_CSP_USER
;
133 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Unsupported out_fmt: 0x%X\n",sh
->codec
->outfmt
[sh
->outfmtidx
]);
137 if(xvid_init(NULL
, 0, &ini
, NULL
))
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
);
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");
157 p
= (priv_t
*)malloc(sizeof(priv_t
));
159 p
->hdl
= dec_p
.handle
;
163 #ifdef XVID_CSP_EXTERN
164 case XVID_CSP_EXTERN
:
165 p
->img_type
= MP_IMGTYPE_STATIC
;
169 p
->img_type
= MP_IMGTYPE_EXPORT
;
172 p
->img_type
= MP_IMGTYPE_TEMP
;
180 static void uninit(sh_video_t
*sh
){
181 priv_t
* p
= sh
->context
;
184 xvid_decore(p
->hdl
,XVID_DEC_DESTROY
, NULL
, NULL
);
189 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
){
191 DIVX4_DEC_PICTURE d4_pic
;
192 #ifdef XVID_CSP_EXTERN
193 XVID_DEC_PICTURE pic
;
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)
204 memset(&dec
,0,sizeof(XVID_DEC_FRAME
));
206 dec
.bitstream
= data
;
208 #ifdef XVID_API_UNSTABLE
209 dec
.general
|= XVID_DEC_LOWDELAY
;
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];
227 dec
.image
= mpi
->planes
[0];
228 if(IMGFMT_IS_BGR(mpi
->imgfmt
) || IMGFMT_IS_RGB(mpi
->imgfmt
))
229 dec
.stride
= mpi
->width
;
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");
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
;