4014
|
1
|
4010
|
2 /*
|
|
3 * vosub_vidix.c
|
|
4 *
|
|
5 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - 2002
|
|
6 *
|
|
7 * You can redistribute this file under terms and conditions
|
|
8 * of GNU General Public licence v2.
|
|
9 *
|
|
10 * This file contains vidix interface to any mplayer's VO plugin.
|
|
11 * (Partly based on vesa_lvo.c from mplayer's package)
|
|
12 */
|
|
13
|
|
14 #include <inttypes.h>
|
|
15 #include <sys/ioctl.h>
|
|
16 #include <unistd.h>
|
|
17 #include <fcntl.h>
|
|
18 #include <sys/mman.h>
|
|
19 #include <stdio.h>
|
|
20 #include <stdlib.h>
|
|
21 #include <string.h>
|
|
22
|
|
23 #include "config.h"
|
|
24
|
|
25 #include "vosub_vidix.h"
|
|
26 #include "../vidix/vidixlib.h"
|
|
27 #include "fastmemcpy.h"
|
|
28 #include "osd.h"
|
|
29 #include "video_out.h"
|
|
30
|
|
31 #define NUM_FRAMES 10 /* Temporary: driver will overwrite it */
|
|
32 #define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */
|
|
33
|
|
34 static VDL_HANDLE vidix_handler = NULL;
|
|
35 static uint8_t *vidix_mem = NULL;
|
|
36 static uint8_t next_frame;
|
|
37 static unsigned image_bpp,image_height,image_width,src_format;
|
|
38 extern int verbose;
|
|
39
|
|
40 static vidix_capability_t vidix_cap;
|
|
41 static vidix_playback_t vidix_play;
|
|
42 static vidix_fourcc_t vidix_fourcc;
|
|
43
|
|
44 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
|
|
45 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
|
|
46 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
|
|
47
|
|
48 extern vo_functions_t video_out_vesa;
|
|
49
|
4082
|
50 int vidix_preinit(const char *drvname,void *server)
|
4010
|
51 {
|
|
52 int err;
|
|
53 if(verbose > 1) printf("vosub_vidix: vidix_preinit(%s) was called\n",drvname);
|
|
54 if(vdlGetVersion() != VIDIX_VERSION)
|
|
55 {
|
|
56 printf("vosub_vidix: You have wrong version of VIDIX library\n");
|
|
57 return -1;
|
|
58 }
|
|
59 vidix_handler = vdlOpen("/usr/lib/mplayer/vidix/",
|
|
60 drvname ? drvname[0] == ':' ? &drvname[1] : NULL : NULL,
|
|
61 TYPE_OUTPUT,
|
|
62 verbose);
|
|
63 if(vidix_handler == NULL)
|
|
64 {
|
|
65 printf("vosub_vidix: Couldn't find working VIDIX driver\n");
|
|
66 return -1;
|
|
67 }
|
|
68 if((err=vdlGetCapability(vidix_handler,&vidix_cap)) != 0)
|
|
69 {
|
|
70 printf("vosub_vidix: Couldn't get capability: %s\n",strerror(err));
|
|
71 return -1;
|
|
72 }
|
4013
|
73 printf("vosub_vidix: Using: %s\n",vidix_cap.name);
|
4010
|
74 /* we are able to tune up this stuff depend on fourcc format */
|
4082
|
75 ((vo_functions_t *)server)->draw_slice=vidix_draw_slice;
|
|
76 ((vo_functions_t *)server)->draw_frame=vidix_draw_frame;
|
|
77 ((vo_functions_t *)server)->flip_page=vidix_flip_page;
|
|
78 ((vo_functions_t *)server)->draw_osd=vidix_draw_osd;
|
4010
|
79 return 0;
|
|
80 }
|
|
81
|
|
82 int vidix_init(unsigned src_width,unsigned src_height,
|
|
83 unsigned x_org,unsigned y_org,unsigned dst_width,
|
|
84 unsigned dst_height,unsigned format,unsigned dest_bpp,
|
|
85 unsigned vid_w,unsigned vid_h)
|
|
86 {
|
|
87 size_t i,awidth;
|
|
88 int err;
|
4082
|
89 if(verbose > 1)
|
|
90 printf("vosub_vidix: vidix_init() was called\n"
|
|
91 "src_w=%u src_h=%u dest_x_y_w_h = %u %u %u %u\n"
|
|
92 "format=%s dest_bpp=%u vid_w=%u vid_h=%u\n"
|
|
93 ,src_width,src_height,x_org,y_org,dst_width,dst_height
|
|
94 ,vo_format_name(format),dest_bpp,vid_w,vid_h);
|
4010
|
95 if(vid_w > vidix_cap.maxwidth || vid_w < vidix_cap.minwidth ||
|
|
96 vid_h > vidix_cap.maxheight || vid_h < vidix_cap.minheight)
|
|
97 {
|
|
98 printf("vosub_vidix: video server has unsupported resolution by vidix\n");
|
|
99 return -1;
|
|
100 }
|
|
101 err = 0;
|
|
102 switch(dest_bpp)
|
|
103 {
|
|
104 case 1: err = ((vidix_fourcc.depth & VID_DEPTH_1BPP) != VID_DEPTH_1BPP); break;
|
|
105 case 2: err = ((vidix_fourcc.depth & VID_DEPTH_2BPP) != VID_DEPTH_2BPP); break;
|
|
106 case 4: err = ((vidix_fourcc.depth & VID_DEPTH_4BPP) != VID_DEPTH_4BPP); break;
|
|
107 case 8: err = ((vidix_fourcc.depth & VID_DEPTH_8BPP) != VID_DEPTH_8BPP); break;
|
|
108 case 12:err = ((vidix_fourcc.depth & VID_DEPTH_12BPP) != VID_DEPTH_12BPP); break;
|
|
109 case 16:err = ((vidix_fourcc.depth & VID_DEPTH_16BPP) != VID_DEPTH_16BPP); break;
|
|
110 case 24:err = ((vidix_fourcc.depth & VID_DEPTH_24BPP) != VID_DEPTH_24BPP); break;
|
|
111 case 32:err = ((vidix_fourcc.depth & VID_DEPTH_32BPP) != VID_DEPTH_32BPP); break;
|
|
112 }
|
|
113 if(err)
|
|
114 {
|
|
115 printf("vosub_vidix: video server has unsupported color depth by vidix\n");
|
|
116 return -1;
|
|
117 }
|
|
118 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_UPSCALER) != FLAG_UPSCALER)
|
|
119 {
|
|
120 printf("vosub_vidix: vidix driver can't upscale image\n");
|
|
121 return -1;
|
|
122 }
|
|
123 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_DOWNSCALER) != FLAG_DOWNSCALER)
|
|
124 {
|
|
125 printf("vosub_vidix: vidix driver can't downscale image\n");
|
|
126 return -1;
|
|
127 }
|
|
128 image_width = src_width;
|
|
129 image_height = src_height;
|
4014
|
130 src_format = format;
|
4010
|
131 memset(&vidix_play,0,sizeof(vidix_playback_t));
|
|
132 vidix_play.fourcc = format;
|
|
133 vidix_play.capability = vidix_cap.flags; /* every ;) */
|
|
134 vidix_play.blend_factor = 0; /* for now */
|
|
135 vidix_play.src.x = vidix_play.src.y = 0;
|
|
136 vidix_play.src.w = src_width;
|
|
137 vidix_play.src.h = src_height;
|
|
138 vidix_play.dest.x = x_org;
|
|
139 vidix_play.dest.y = y_org;
|
|
140 vidix_play.dest.w = dst_width;
|
|
141 vidix_play.dest.h = dst_height;
|
|
142 vidix_play.num_frames=NUM_FRAMES;
|
|
143 if((err=vdlConfigPlayback(vidix_handler,&vidix_play))!=0)
|
|
144 {
|
|
145 printf("vosub_vidix: Can't configure playback: %s\n",strerror(err));
|
|
146 return -1;
|
|
147 }
|
|
148 if((err=vdlPlaybackOn(vidix_handler))!=0)
|
|
149 {
|
|
150 printf("vosub_vidix: Can't start playback: %s\n",strerror(err));
|
|
151 return -1;
|
|
152 }
|
|
153
|
|
154 next_frame = 0;
|
|
155 vidix_mem =vidix_play.dga_addr;
|
|
156
|
|
157 /*clear the buffer*/
|
4032
|
158 memset(vidix_mem + vidix_play.offsets[0],0x80,vidix_play.frame_size*vidix_play.num_frames);
|
4010
|
159 return 0;
|
|
160 }
|
|
161
|
|
162 void vidix_term( void )
|
|
163 {
|
|
164 if(verbose > 1) printf("vosub_vidix: vidix_term() was called\n");
|
|
165 vdlPlaybackOff(vidix_handler);
|
|
166 vdlClose(vidix_handler);
|
|
167 }
|
|
168
|
|
169 uint32_t vidix_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
170 {
|
|
171 uint8_t *src;
|
|
172 uint8_t *dest;
|
4014
|
173 unsigned bespitch,apitch;
|
4010
|
174 int i;
|
4014
|
175 apitch = vidix_play.dest.pitch.y-1;
|
|
176 bespitch = (w + apitch) & ~apitch;
|
4010
|
177
|
4032
|
178 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
|
4010
|
179 dest += bespitch*y + x;
|
|
180 src = image[0];
|
|
181 for(i=0;i<h;i++){
|
|
182 memcpy(dest,src,w);
|
|
183 src+=stride[0];
|
|
184 dest += bespitch;
|
|
185 }
|
|
186
|
4014
|
187 apitch = vidix_play.dest.pitch.v-1;
|
|
188 bespitch = (w + apitch) & ~apitch;
|
4032
|
189 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
|
4031
|
190 dest += bespitch*y/4 + x;
|
4014
|
191 src = image[1];
|
|
192 for(i=0;i<h/2;i++){
|
|
193 memcpy(dest,src,w/2);
|
|
194 src+=stride[1];
|
|
195 dest+=bespitch/2;
|
|
196 }
|
|
197 apitch = vidix_play.dest.pitch.u-1;
|
|
198 bespitch = (w + apitch) & ~apitch;
|
4010
|
199
|
4032
|
200 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
|
4031
|
201 dest += bespitch*y/4 + x;
|
4010
|
202 src = image[2];
|
4014
|
203 for(i=0;i<h/2;i++){
|
|
204 memcpy(dest,src,w/2);
|
4010
|
205 src+=stride[2];
|
4014
|
206 dest += bespitch/2;
|
4010
|
207 }
|
|
208 return 0;
|
|
209 }
|
|
210
|
|
211 uint32_t vidix_draw_slice_422(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
212 {
|
|
213 uint8_t *src;
|
|
214 uint8_t *dest;
|
4014
|
215 unsigned bespitch,apitch;
|
4010
|
216 int i;
|
4014
|
217 apitch = vidix_play.dest.pitch.y-1;
|
|
218 bespitch = (w*2 + apitch) & ~apitch;
|
4032
|
219 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
|
4010
|
220 dest += bespitch*y + x;
|
|
221 src = image[0];
|
|
222 for(i=0;i<h;i++){
|
|
223 memcpy(dest,src,w*2);
|
|
224 src+=stride[0];
|
|
225 dest += bespitch;
|
|
226 }
|
|
227 }
|
|
228
|
|
229
|
|
230 uint32_t vidix_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
231 {
|
|
232 if(verbose > 1) printf("vosub_vidix: vidix_draw_slice() was called\n");
|
|
233 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
|
|
234 vidix_draw_slice_420(image,stride,w,h,x,y);
|
|
235 else
|
|
236 vidix_draw_slice_422(image,stride,w,h,x,y);
|
|
237 return 0;
|
|
238 }
|
|
239
|
|
240 uint32_t vidix_draw_frame(uint8_t *image[])
|
|
241 {
|
|
242 if(verbose > 1) printf("vosub_vidix: vidix_draw_frame() was called\n");
|
|
243 /* Note it's very strange but sometime for YUY2 draw_frame is called */
|
|
244 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
|
|
245 {
|
|
246 printf("vosub_vidix: draw_frame for i420 is called\nExiting...\n");
|
|
247 vidix_term();
|
|
248 exit( EXIT_FAILURE );
|
|
249 }
|
|
250 else
|
|
251 {
|
|
252 int stride[1];
|
|
253 stride[0] = vidix_play.src.w*2;
|
|
254 vidix_draw_slice_422(image,stride,vidix_play.src.w,vidix_play.src.h,
|
|
255 vidix_play.src.x,vidix_play.src.y);
|
|
256 }
|
|
257 return 0;
|
|
258 }
|
|
259
|
|
260 void vidix_flip_page(void)
|
|
261 {
|
|
262 if(verbose > 1) printf("vosub_vidix: vidix_flip_page() was called\n");
|
|
263 if(vo_doublebuffering)
|
|
264 {
|
4032
|
265 vdlPlaybackFrameSelect(vidix_handler,next_frame);
|
4010
|
266 next_frame=(next_frame+1)%vidix_play.num_frames;
|
|
267 }
|
|
268 }
|
|
269
|
|
270 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
|
|
271 {
|
|
272 UNUSED(x0);
|
|
273 UNUSED(y0);
|
|
274 UNUSED(w);
|
|
275 UNUSED(h);
|
|
276 UNUSED(src);
|
|
277 UNUSED(srca);
|
|
278 UNUSED(stride);
|
|
279 }
|
|
280
|
|
281 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
|
|
282 {
|
4032
|
283 uint32_t apitch,bespitch;
|
4010
|
284 void *lvo_mem;
|
4032
|
285 lvo_mem = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
|
|
286 apitch = vidix_play.dest.pitch.y-1;
|
|
287 bespitch = (vidix_play.src.w + apitch) & (~apitch);
|
4010
|
288 switch(vidix_play.fourcc){
|
|
289 case IMGFMT_YV12:
|
|
290 case IMGFMT_IYUV:
|
|
291 case IMGFMT_I420:
|
|
292 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
|
|
293 break;
|
|
294 case IMGFMT_YUY2:
|
4032
|
295 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),2*bespitch);
|
4010
|
296 break;
|
|
297 case IMGFMT_UYVY:
|
4032
|
298 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,2*bespitch);
|
4010
|
299 break;
|
|
300 default:
|
|
301 draw_alpha_null(x0,y0,w,h,src,srca,stride);
|
|
302 }
|
|
303 }
|
|
304
|
|
305 void vidix_draw_osd(void)
|
|
306 {
|
|
307 if(verbose > 1) printf("vosub_vidix: vidix_draw_osd() was called\n");
|
|
308 /* TODO: hw support */
|
|
309 vo_draw_text(vidix_play.src.w,vidix_play.src.h,draw_alpha);
|
|
310 }
|
|
311
|
|
312 uint32_t vidix_query_fourcc(uint32_t format)
|
|
313 {
|
|
314 if(verbose > 1) printf("vosub_vidix: query_format was called: %x (%s)\n",format,vo_format_name(format));
|
|
315 vidix_fourcc.fourcc = format;
|
|
316 vdlQueryFourcc(vidix_handler,&vidix_fourcc);
|
|
317 return vidix_fourcc.depth != VID_DEPTH_NONE;
|
|
318 }
|