comparison libmpcodecs/vd_odivx.c @ 4968:236b06410b03

vfw, vfwex, odivx, divx4 added
author arpi
date Thu, 07 Mar 2002 00:44:58 +0000
parents
children eb57973314ae
comparison
equal deleted inserted replaced
4967:f88dfc3de52c 4968:236b06410b03
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4
5 #include "config.h"
6 #include "mp_msg.h"
7 #include "help_mp.h"
8
9 #ifdef USE_DIVX
10
11 #include "codec-cfg.h"
12 #include "../libvo/img_format.h"
13
14 #include "stream.h"
15 #include "demuxer.h"
16 #include "stheader.h"
17
18 #include "vd.h"
19 #include "vd_internal.h"
20
21 static vd_info_t info = {
22 #ifdef NEW_DECORE
23 #ifdef DECORE_DIVX5
24 "DivX5Linux lib (odivx mode)",
25 #else
26 "DivX4Linux lib (odivx mode)",
27 #endif
28 #else
29 "Opendivx 0.48 codec",
30 #endif
31 "odivx",
32 VFM_ODIVX,
33 "A'rpi",
34 #ifdef NEW_DECORE
35 "http://www.divx.com",
36 #else
37 "http://www.projectmayo.org",
38 #endif
39 "native codecs"
40 };
41
42 LIBVD_EXTERN(odivx)
43
44 #ifndef NEW_DECORE
45 #include "opendivx/decore.h"
46 #else
47 #include <decore.h>
48 #endif
49
50 //**************************************************************************//
51 // The OpenDivX stuff:
52 //**************************************************************************//
53
54 #ifndef NEW_DECORE
55
56 static unsigned char *opendivx_src[3];
57 static int opendivx_stride[3];
58
59 // callback, the opendivx decoder calls this for each frame:
60 void convert_linux(unsigned char *puc_y, int stride_y,
61 unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
62 unsigned char *bmp, int width_y, int height_y){
63
64 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv);
65
66 opendivx_src[0]=puc_y;
67 opendivx_src[1]=puc_u;
68 opendivx_src[2]=puc_v;
69
70 opendivx_stride[0]=stride_y;
71 opendivx_stride[1]=stride_uv;
72 opendivx_stride[2]=stride_uv;
73 }
74 #endif
75
76
77 // to set/get/query special features/parameters
78 static int control(sh_video_t *sh,int cmd,void* arg,...){
79 switch(cmd){
80 case VDCTRL_QUERY_MAX_PP_LEVEL:
81 #ifdef NEW_DECORE
82 return 9; // for divx4linux
83 #else
84 return GET_PP_QUALITY_MAX; // for opendivx
85 #endif
86 case VDCTRL_SET_PP_LEVEL: {
87 DEC_SET dec_set;
88 int quality=*((int*)arg);
89 #ifdef NEW_DECORE
90 if(quality<0 || quality>9) quality=9;
91 dec_set.postproc_level=quality*10;
92 #else
93 if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX;
94 dec_set.postproc_level=getPpModeForQuality(quality);
95 #endif
96 decore(0x123,DEC_OPT_SETPP,&dec_set,NULL);
97 return CONTROL_OK;
98 }
99
100 }
101
102 return CONTROL_UNKNOWN;
103 }
104
105 // init driver
106 static int init(sh_video_t *sh){
107 DEC_PARAM dec_param;
108 // DEC_SET dec_set;
109 memset(&dec_param,0,sizeof(dec_param));
110 #ifdef NEW_DECORE
111 dec_param.output_format=DEC_USER;
112 #else
113 dec_param.color_depth = 32;
114 #endif
115 dec_param.x_dim = sh->disp_w;
116 dec_param.y_dim = sh->disp_h;
117 decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
118 // dec_set.postproc_level = divx_quality;
119 // decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
120
121 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: OpenDivX video codec init OK!\n");
122
123 mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
124 return 1;
125 }
126
127 // uninit driver
128 static void uninit(sh_video_t *sh){
129 decore(0x123,DEC_OPT_RELEASE,NULL,NULL);
130 }
131
132 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
133
134 // decode a frame
135 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
136 mp_image_t* mpi;
137 DEC_FRAME dec_frame;
138 #ifdef NEW_DECORE
139 DEC_PICTURE dec_pic;
140 #endif
141
142 if(len<=0) return NULL; // skipped frame
143
144 dec_frame.length = len;
145 dec_frame.bitstream = data;
146 dec_frame.render_flag = (flags&3)?0:1;
147
148 #ifdef NEW_DECORE
149 dec_frame.bmp=&dec_pic;
150 dec_pic.y=dec_pic.u=dec_pic.v=NULL;
151 #ifdef DECORE_DIVX5
152 decore(0x123, DEC_OPT_FRAME, &dec_frame, NULL);
153 #else
154 decore(0x123, (sh->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL);
155 #endif
156 #else
157 // opendivx:
158 opendivx_src[0]=NULL;
159 decore(0x123, 0, &dec_frame, NULL);
160 #endif
161
162 if(flags&3) return NULL; // framedrop
163
164 #ifdef NEW_DECORE
165 if(!dec_pic.y) return NULL; // bad frame
166 #else
167 if(!opendivx_src[0]) return NULL; // bad frame
168 #endif
169
170 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
171 sh->disp_w, sh->disp_h);
172 if(!mpi) return NULL;
173
174 #ifdef NEW_DECORE
175 mpi->planes[0]=dec_pic.y;
176 mpi->planes[1]=dec_pic.u;
177 mpi->planes[2]=dec_pic.v;
178 mpi->stride[0]=dec_pic.stride_y;
179 mpi->stride[1]=mpi->stride[2]=dec_pic.stride_uv;
180 #else
181 mpi->planes[0]=opendivx_src[0];
182 mpi->planes[1]=opendivx_src[1];
183 mpi->planes[2]=opendivx_src[2];
184 mpi->stride[0]=opendivx_stride[0];
185 mpi->stride[1]=opendivx_stride[1];
186 mpi->stride[2]=opendivx_stride[2];
187 #endif
188
189 return mpi;
190 }
191
192 #endif
193