comparison libmpcodecs/vd_xvid.c @ 6701:522713337297

Support for Xvid using their new api. If divx4 compatiblity is disabeled in xvid it can be used along with divx4.
author albeu
date Wed, 10 Jul 2002 20:56:57 +0000
parents
children 6af6d7b40638
comparison
equal deleted inserted replaced
6700:3b1be2b0fa55 6701:522713337297
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "config.h"
5 #include "mp_msg.h"
6
7 #ifdef HAVE_XVID
8
9 #include "vd_internal.h"
10
11 #include <divx4.h>
12 #include <xvid.h>
13
14
15 static vd_info_t info =
16 {
17 "xvid decoder",
18 "xvid",
19 VFM_XVID,
20 "Albeu",
21 "Albeu",
22 ""
23 };
24
25 LIBVD_EXTERN(xvid)
26
27 typedef struct {
28 int cs;
29 void* hdl;
30 mp_image_t* mpi;
31 } priv_t;
32
33 // to set/get/query special features/parameters
34 static int control(sh_video_t *sh,int cmd,void* arg,...){
35 return CONTROL_UNKNOWN;
36 }
37
38 // init driver
39 static int init(sh_video_t *sh){
40 XVID_INIT_PARAM ini;
41 XVID_DEC_PARAM dec_p;
42 priv_t* p;
43 int cs;
44
45 memset(&ini,0,sizeof(XVID_INIT_PARAM));
46 memset(&dec_p,0,sizeof(XVID_DEC_PARAM));
47
48 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12))
49 return 0;
50
51 switch(sh->codec->outfmt[sh->outfmtidx]){
52 case IMGFMT_YV12:
53 cs= XVID_CSP_USER;
54 break;
55 case IMGFMT_YUY2:
56 cs=XVID_CSP_YUY2;
57 break;
58 case IMGFMT_UYVY:
59 cs=XVID_CSP_UYVY;
60 break;
61 case IMGFMT_I420:
62 cs=XVID_CSP_I420;
63 break;
64 case IMGFMT_BGR15:
65 cs=XVID_CSP_RGB555;
66 break;
67 case IMGFMT_BGR16:
68 cs=XVID_CSP_RGB565;
69 break;
70 case IMGFMT_BGR24:
71 cs=XVID_CSP_RGB24;
72 break;
73 case IMGFMT_BGR32:
74 cs=XVID_CSP_RGB32;
75 break;
76 case IMGFMT_YVYU:
77 cs=XVID_CSP_YVYU;
78 break;
79 default:
80 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",sh->codec->outfmt[sh->outfmtidx]);
81 return 0;
82 }
83
84 if(xvid_init(NULL, 0, &ini, NULL))
85 return 0;
86
87 if(ini.api_version != API_VERSION) {
88 if(ini.api_version < API_VERSION) {
89 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Too old version of xivd (min. %d)\n",API_VERSION);
90 return 0;
91 }
92 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Bad xvid version %d was compiled with %d\n",
93 ini.api_version,API_VERSION);
94 }
95
96 dec_p.width = sh->disp_w;
97 dec_p.height = sh->disp_h;
98
99 if(xvid_decore(NULL, XVID_DEC_CREATE, &dec_p, NULL)) {
100 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"xvid init failed\n");
101 return 0;
102 }
103
104 p = (priv_t*)malloc(sizeof(priv_t));
105 p->cs = cs;
106 p->hdl = dec_p.handle;
107 sh->context = p;
108
109 return 1;
110 }
111
112 // uninit driver
113 static void uninit(sh_video_t *sh){
114 priv_t* p = sh->context;
115 if(!p)
116 return;
117 xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL);
118 free(p);
119 }
120
121 // decode a frame
122 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
123 XVID_DEC_FRAME dec;
124 DEC_PICTURE d4_pic;
125 priv_t* p = sh->context;
126
127 mp_image_t* mpi = mpcodecs_get_image(sh, p->cs == XVID_CSP_USER ?
128 MP_IMGTYPE_EXPORT : MP_IMGTYPE_TEMP,
129 MP_IMGFLAG_ACCEPT_STRIDE,
130 sh->disp_w,sh->disp_h);
131
132 if(!data || !mpi || len <= 0)
133 return NULL;
134
135 memset(&dec,0,sizeof(XVID_DEC_FRAME));
136
137 dec.bitstream = data;
138 dec.length = len;
139 switch(p->cs) {
140 case XVID_CSP_USER:
141 dec.image = &d4_pic;
142 break;
143 default:
144 dec.image = mpi->planes[0];
145 if(IMGFMT_IS_BGR(mpi->imgfmt) || IMGFMT_IS_RGB(mpi->imgfmt))
146 dec.stride = mpi->width;
147 else
148 dec.stride = mpi->stride[0];
149 }
150 dec.colorspace = p->cs;
151
152 if(xvid_decore(p->hdl,XVID_DEC_DECODE,&dec,NULL)) {
153 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"decoding error\n");
154 return NULL;
155 }
156
157 if(p->cs == XVID_CSP_USER) {
158 mpi->planes[0] = d4_pic.y;
159 mpi->planes[1] = d4_pic.u;
160 mpi->planes[2] = d4_pic.v;
161 mpi->stride[0] = d4_pic.stride_y;
162 mpi->stride[1] = mpi->stride[2] = d4_pic.stride_uv;
163 }
164
165 return mpi;
166 }
167
168 #endif