adding the code documentation guide lines
[mplayer/glamo.git] / libmpcodecs / vd_xvid4.c
blob9389955edb35828de4481bc88bd1ae3624301837
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 /*****************************************************************************
25 * Includes
26 ****************************************************************************/
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "config.h"
32 #include "mp_msg.h"
34 #ifdef HAVE_XVID4
36 #include "vd_internal.h"
37 #include "m_option.h"
39 #include <xvid.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 /*****************************************************************************
60 * Module private data
61 ****************************************************************************/
63 typedef struct {
64 int cs;
65 unsigned char img_type;
66 void* hdl;
67 mp_image_t* mpi;
68 } priv_t;
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;
91 priv_t* p;
92 int cs;
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))
100 return(0);
102 switch(sh->codec->outfmt[sh->outfmtidx]){
103 case IMGFMT_YV12:
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;
107 break;
108 case IMGFMT_YUY2:
109 cs = XVID_CSP_YUY2;
110 break;
111 case IMGFMT_UYVY:
112 cs = XVID_CSP_UYVY;
113 break;
114 case IMGFMT_I420:
115 case IMGFMT_IYUV:
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;
119 break;
120 case IMGFMT_BGR15:
121 cs = XVID_CSP_RGB555;
122 break;
123 case IMGFMT_BGR16:
124 cs = XVID_CSP_RGB565;
125 break;
126 case IMGFMT_BGR32:
127 cs = XVID_CSP_BGRA;
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",
134 sh->codec->outfmt[sh->outfmtidx]);
135 return(0);
138 if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL))
139 return(0);
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");
146 return(0);
149 p = (priv_t*)malloc(sizeof(priv_t));
150 p->cs = cs;
151 p->hdl = dec_p.handle;
152 sh->context = p;
154 switch(cs) {
155 case XVID_CSP_INTERNAL:
156 p->img_type = MP_IMGTYPE_EXPORT;
157 break;
158 case XVID_CSP_USER:
159 p->img_type = MP_IMGTYPE_STATIC;
160 break;
161 default:
162 p->img_type = MP_IMGTYPE_TEMP;
163 break;
166 return(1);
169 /*============================================================================
170 * uninit - close the codec
171 *==========================================================================*/
173 static void uninit(sh_video_t *sh){
174 priv_t* p = sh->context;
175 if(!p)
176 return;
177 xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL);
178 free(p);
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)
195 return(NULL);
197 memset(&dec,0,sizeof(xvid_dec_frame_t));
198 dec.version = XVID_VERSION;
200 dec.bitstream = data;
201 dec.length = len;
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");
222 return(NULL);
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];
235 return(mpi);
238 /*****************************************************************************
239 * Module structure definition
240 ****************************************************************************/
242 static vd_info_t info =
244 "XviD 1.0 decoder",
245 "xvid",
246 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
247 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
248 "No Comment"
251 LIBVD_EXTERN(xvid)
253 #endif /* HAVE_XVID4 */
255 /* Please do not change that tag comment.
256 * arch-tag: b7d654a5-76ea-4768-9713-2c791567fe7d mplayer xvid decoder module */