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