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