comparison libmpcodecs/vd_xvid4.c @ 11437:7826e4e376c7

XviD Api4 driver from http://ed.gomez.free.fr/
author iive
date Wed, 12 Nov 2003 00:50:43 +0000
parents
children 4f4b81257d19
comparison
equal deleted inserted replaced
11436:6afc2d6f5a08 11437:7826e4e376c7
1 /*****************************************************************************
2 *
3 * - XviD 1.0 decoder module for mplayer/mencoder -
4 *
5 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
6 * 2003 Edouard Gomez <ed.gomez@free.fr>
7 *
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.
12 *
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.
17 *
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
21 *
22 *****************************************************************************/
23
24 /*****************************************************************************
25 * Includes
26 ****************************************************************************/
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include "config.h"
32 #include "mp_msg.h"
33
34 #ifdef HAVE_XVID4
35
36 #include "vd_internal.h"
37 #include "m_option.h"
38
39 #include <xvid.h>
40
41 /*****************************************************************************
42 * Configuration options
43 ****************************************************************************/
44
45 static int do_dr2 = 1;
46
47 m_option_t xvid_dec_opts[] = {
48 { "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL},
49 { "nodr2", &do_dr2, CONF_TYPE_FLAG, 0, 1, 0, NULL},
50 {NULL, NULL, 0, 0, 0, 0, NULL}
51 };
52
53 /*****************************************************************************
54 * Module private data
55 ****************************************************************************/
56
57 typedef struct {
58 int cs;
59 unsigned char img_type;
60 void* hdl;
61 mp_image_t* mpi;
62 } priv_t;
63
64 /*****************************************************************************
65 * Video decoder API function definitions
66 ****************************************************************************/
67
68 /*============================================================================
69 * control - to set/get/query special features/parameters
70 *==========================================================================*/
71
72 static int control(sh_video_t *sh,int cmd,void* arg,...)
73 {
74 return(CONTROL_UNKNOWN);
75 }
76
77 /*============================================================================
78 * init - initialize the codec
79 *==========================================================================*/
80
81 static int init(sh_video_t *sh)
82 {
83 xvid_gbl_init_t xvid_ini;
84 xvid_dec_create_t dec_p;
85 priv_t* p;
86 int cs;
87
88 memset(&xvid_ini, 0, sizeof(xvid_gbl_init_t));
89 xvid_ini.version = XVID_VERSION;
90 memset(&dec_p, 0, sizeof(xvid_dec_create_t));
91 dec_p.version = XVID_VERSION;
92
93 if(!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_YV12))
94 return(0);
95
96 switch(sh->codec->outfmt[sh->outfmtidx]){
97 case IMGFMT_YV12:
98 /* We will use our own buffers, this speeds decoding avoiding
99 * frame memcpy's overhead */
100 cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER;
101 break;
102 case IMGFMT_YUY2:
103 cs = XVID_CSP_YUY2;
104 break;
105 case IMGFMT_UYVY:
106 cs = XVID_CSP_UYVY;
107 break;
108 case IMGFMT_I420:
109 case IMGFMT_IYUV:
110 /* We will use our own buffers, this speeds decoding avoiding
111 * frame memcpy's overhead */
112 cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER;
113 break;
114 case IMGFMT_BGR15:
115 cs = XVID_CSP_RGB555;
116 break;
117 case IMGFMT_BGR16:
118 cs = XVID_CSP_RGB565;
119 break;
120 case IMGFMT_BGR32:
121 cs = XVID_CSP_BGRA;
122 break;
123 case IMGFMT_YVYU:
124 cs = XVID_CSP_YVYU;
125 break;
126 default:
127 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unsupported out_fmt: 0x%X\n",
128 sh->codec->outfmt[sh->outfmtidx]);
129 return(0);
130 }
131
132 if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL))
133 return(0);
134
135 dec_p.width = sh->disp_w;
136 dec_p.height = sh->disp_h;
137
138 if(xvid_decore(0, XVID_DEC_CREATE, &dec_p, NULL)<0) {
139 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "XviD init failed\n");
140 return(0);
141 }
142
143 p = (priv_t*)malloc(sizeof(priv_t));
144 p->cs = cs;
145 p->hdl = dec_p.handle;
146 sh->context = p;
147
148 switch(cs) {
149 case XVID_CSP_INTERNAL:
150 p->img_type = MP_IMGTYPE_EXPORT;
151 break;
152 case XVID_CSP_USER:
153 p->img_type = MP_IMGTYPE_STATIC;
154 break;
155 default:
156 p->img_type = MP_IMGTYPE_TEMP;
157 break;
158 }
159
160 return(1);
161 }
162
163 /*============================================================================
164 * uninit - close the codec
165 *==========================================================================*/
166
167 static void uninit(sh_video_t *sh){
168 priv_t* p = sh->context;
169 if(!p)
170 return;
171 xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL);
172 free(p);
173 }
174
175 /*============================================================================
176 * decode - decode a frame from stream
177 *==========================================================================*/
178
179 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
180 {
181 xvid_dec_frame_t dec;
182 priv_t* p = sh->context;
183
184 mp_image_t* mpi = mpcodecs_get_image(sh, p->img_type,
185 MP_IMGFLAG_ACCEPT_STRIDE,
186 sh->disp_w,sh->disp_h);
187
188 if(!data || !mpi || len <= 0)
189 return(NULL);
190
191 memset(&dec,0,sizeof(xvid_dec_frame_t));
192 dec.version = XVID_VERSION;
193
194 dec.bitstream = data;
195 dec.length = len;
196
197 dec.general |= XVID_LOWDELAY;
198
199 dec.output.csp = p->cs;
200
201 if(p->cs != XVID_CSP_INTERNAL) {
202 dec.output.plane[0] = mpi->planes[0];
203 dec.output.plane[1] = mpi->planes[1];
204 dec.output.plane[2] = mpi->planes[2];
205
206 dec.output.stride[0] = mpi->stride[0];
207 dec.output.stride[1] = mpi->stride[1];
208 dec.output.stride[2] = mpi->stride[2];
209 }
210
211 if(xvid_decore(p->hdl, XVID_DEC_DECODE, &dec, NULL) < 0) {
212 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Decoding error\n");
213 return(NULL);
214 }
215
216 if(p->cs == XVID_CSP_INTERNAL) {
217 mpi->planes[0] = dec.output.plane[0];
218 mpi->planes[1] = dec.output.plane[1];
219 mpi->planes[2] = dec.output.plane[2];
220
221 mpi->stride[0] = dec.output.stride[0];
222 mpi->stride[1] = dec.output.stride[1];
223 mpi->stride[2] = dec.output.stride[2];
224 }
225
226 return(mpi);
227 }
228
229 /*****************************************************************************
230 * Module structure definition
231 ****************************************************************************/
232
233 static vd_info_t info =
234 {
235 "XviD 1.0 decoder",
236 "xvid",
237 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
238 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
239 "No Comment"
240 };
241
242 LIBVD_EXTERN(xvid)
243
244 #endif /* HAVE_XVID4 */
245
246 /* Please do not change that tag comment.
247 * arch-tag: b7d654a5-76ea-4768-9713-2c791567fe7d mplayer xvid decoder module */