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