1 /*****************************************************************************
3 * - XviD 1.0 decoder module for mplayer/mencoder -
5 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
6 * 2003 Edouard Gomez <ed.gomez@free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *****************************************************************************/
24 /*****************************************************************************
26 ****************************************************************************/
36 #include "vd_internal.h"
41 /*****************************************************************************
42 * Configuration options
43 ****************************************************************************/
45 static int do_dr2
= 1;
46 static int filmeffect
= 0;
47 static int lumadeblock
= 0;
48 static int chromadeblock
= 0;
50 m_option_t xvid_dec_opts
[] = {
51 { "dr2", &do_dr2
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
52 { "nodr2", &do_dr2
, CONF_TYPE_FLAG
, 0, 1, 0, NULL
},
53 { "filmeffect", &filmeffect
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
54 { "deblock-luma", &lumadeblock
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
55 { "deblock-chroma", &chromadeblock
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
56 {NULL
, NULL
, 0, 0, 0, 0, NULL
}
59 /*****************************************************************************
61 ****************************************************************************/
65 unsigned char img_type
;
70 /*****************************************************************************
71 * Video decoder API function definitions
72 ****************************************************************************/
74 /*============================================================================
75 * control - to set/get/query special features/parameters
76 *==========================================================================*/
78 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...)
80 return(CONTROL_UNKNOWN
);
83 /*============================================================================
84 * init - initialize the codec
85 *==========================================================================*/
87 static int init(sh_video_t
*sh
)
89 xvid_gbl_init_t xvid_ini
;
90 xvid_dec_create_t dec_p
;
94 memset(&xvid_ini
, 0, sizeof(xvid_gbl_init_t
));
95 xvid_ini
.version
= XVID_VERSION
;
96 memset(&dec_p
, 0, sizeof(xvid_dec_create_t
));
97 dec_p
.version
= XVID_VERSION
;
99 if(!mpcodecs_config_vo(sh
, sh
->disp_w
, sh
->disp_h
, IMGFMT_YV12
))
102 switch(sh
->codec
->outfmt
[sh
->outfmtidx
]){
104 /* We will use our own buffers, this speeds decoding avoiding
105 * frame memcpy's overhead */
106 cs
= (do_dr2
)?XVID_CSP_INTERNAL
:XVID_CSP_USER
;
116 /* We will use our own buffers, this speeds decoding avoiding
117 * frame memcpy's overhead */
118 cs
= (do_dr2
)?XVID_CSP_INTERNAL
:XVID_CSP_USER
;
121 cs
= XVID_CSP_RGB555
;
124 cs
= XVID_CSP_RGB565
;
133 mp_msg(MSGT_DECVIDEO
, MSGL_ERR
, "Unsupported out_fmt: 0x%X\n",
134 sh
->codec
->outfmt
[sh
->outfmtidx
]);
138 if(xvid_global(NULL
, XVID_GBL_INIT
, &xvid_ini
, NULL
))
141 dec_p
.width
= sh
->disp_w
;
142 dec_p
.height
= sh
->disp_h
;
144 if(xvid_decore(0, XVID_DEC_CREATE
, &dec_p
, NULL
)<0) {
145 mp_msg(MSGT_DECVIDEO
, MSGL_ERR
, "XviD init failed\n");
149 p
= (priv_t
*)malloc(sizeof(priv_t
));
151 p
->hdl
= dec_p
.handle
;
155 case XVID_CSP_INTERNAL
:
156 p
->img_type
= MP_IMGTYPE_EXPORT
;
159 p
->img_type
= MP_IMGTYPE_STATIC
;
162 p
->img_type
= MP_IMGTYPE_TEMP
;
169 /*============================================================================
170 * uninit - close the codec
171 *==========================================================================*/
173 static void uninit(sh_video_t
*sh
){
174 priv_t
* p
= sh
->context
;
177 xvid_decore(p
->hdl
,XVID_DEC_DESTROY
, NULL
, NULL
);
181 /*============================================================================
182 * decode - decode a frame from stream
183 *==========================================================================*/
185 static mp_image_t
* decode(sh_video_t
*sh
, void* data
, int len
, int flags
)
187 xvid_dec_frame_t dec
;
188 priv_t
* p
= sh
->context
;
190 mp_image_t
* mpi
= mpcodecs_get_image(sh
, p
->img_type
,
191 MP_IMGFLAG_ACCEPT_STRIDE
,
192 sh
->disp_w
,sh
->disp_h
);
194 if(!data
|| !mpi
|| len
<= 0)
197 memset(&dec
,0,sizeof(xvid_dec_frame_t
));
198 dec
.version
= XVID_VERSION
;
200 dec
.bitstream
= data
;
203 dec
.general
|= XVID_LOWDELAY
204 | (filmeffect
? XVID_FILMEFFECT
: 0 )
205 | (lumadeblock
? XVID_DEBLOCKY
: 0 )
206 | (chromadeblock
? XVID_DEBLOCKUV
: 0 );
208 dec
.output
.csp
= p
->cs
;
210 if(p
->cs
!= XVID_CSP_INTERNAL
) {
211 dec
.output
.plane
[0] = mpi
->planes
[0];
212 dec
.output
.plane
[1] = mpi
->planes
[1];
213 dec
.output
.plane
[2] = mpi
->planes
[2];
215 dec
.output
.stride
[0] = mpi
->stride
[0];
216 dec
.output
.stride
[1] = mpi
->stride
[1];
217 dec
.output
.stride
[2] = mpi
->stride
[2];
220 if(xvid_decore(p
->hdl
, XVID_DEC_DECODE
, &dec
, NULL
) < 0) {
221 mp_msg(MSGT_DECVIDEO
, MSGL_ERR
, "Decoding error\n");
225 if(p
->cs
== XVID_CSP_INTERNAL
) {
226 mpi
->planes
[0] = dec
.output
.plane
[0];
227 mpi
->planes
[1] = dec
.output
.plane
[1];
228 mpi
->planes
[2] = dec
.output
.plane
[2];
230 mpi
->stride
[0] = dec
.output
.stride
[0];
231 mpi
->stride
[1] = dec
.output
.stride
[1];
232 mpi
->stride
[2] = dec
.output
.stride
[2];
238 /*****************************************************************************
239 * Module structure definition
240 ****************************************************************************/
242 static vd_info_t info
=
246 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
247 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
253 #endif /* HAVE_XVID4 */
255 /* Please do not change that tag comment.
256 * arch-tag: b7d654a5-76ea-4768-9713-2c791567fe7d mplayer xvid decoder module */