Mercurial > mplayer.hg
annotate libvo/vosub_vidix.c @ 4207:1427d0f1f2d6
-lavcopts vme= option to set motion estimation method - patch by Rich Felker <dalias@aerifal.cx>
author | arpi |
---|---|
date | Thu, 17 Jan 2002 01:02:41 +0000 |
parents | 7e2bf04c9a7c |
children | 9a33ad2f3547 |
rev | line source |
---|---|
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 } | |
4138 | 59 vidix_handler = vdlOpen(LIBDIR"/vidix/", |
4132
84ecfd03c86a
test for preinit errors and correct handling subdevice
nick
parents:
4082
diff
changeset
|
60 drvname ? drvname[0] == ':' ? &drvname[1] : drvname[0] ? drvname : NULL : NULL, |
4010 | 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 | |
149 next_frame = 0; | |
150 vidix_mem =vidix_play.dga_addr; | |
151 | |
152 /*clear the buffer*/ | |
4032 | 153 memset(vidix_mem + vidix_play.offsets[0],0x80,vidix_play.frame_size*vidix_play.num_frames); |
4010 | 154 return 0; |
155 } | |
156 | |
4198
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
157 void vidix_start(void) |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
158 { |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
159 int err; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
160 |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
161 if((err=vdlPlaybackOn(vidix_handler))!=0) |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
162 { |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
163 printf("vosub_vidix: Can't start playback: %s\n",strerror(err)); |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
164 return -1; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
165 } |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
166 return 0; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
167 } |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
168 |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
169 void vidix_stop(void) |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
170 { |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
171 int err; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
172 |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
173 if((err=vdlPlaybackOff(vidix_handler))!=0) |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
174 { |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
175 printf("vosub_vidix: Can't stop playback: %s\n",strerror(err)); |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
176 return -1; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
177 } |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
178 return 0; |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
179 } |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
180 |
4010 | 181 void vidix_term( void ) |
182 { | |
183 if(verbose > 1) printf("vosub_vidix: vidix_term() was called\n"); | |
4198
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
184 // vdlPlaybackOff(vidix_handler); |
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4138
diff
changeset
|
185 vidix_stop(); |
4010 | 186 vdlClose(vidix_handler); |
187 } | |
188 | |
189 uint32_t vidix_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
190 { | |
191 uint8_t *src; | |
192 uint8_t *dest; | |
4014 | 193 unsigned bespitch,apitch; |
4010 | 194 int i; |
4014 | 195 apitch = vidix_play.dest.pitch.y-1; |
196 bespitch = (w + apitch) & ~apitch; | |
4010 | 197 |
4032 | 198 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y; |
4010 | 199 dest += bespitch*y + x; |
200 src = image[0]; | |
201 for(i=0;i<h;i++){ | |
202 memcpy(dest,src,w); | |
203 src+=stride[0]; | |
204 dest += bespitch; | |
205 } | |
206 | |
4014 | 207 apitch = vidix_play.dest.pitch.v-1; |
208 bespitch = (w + apitch) & ~apitch; | |
4032 | 209 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v; |
4031 | 210 dest += bespitch*y/4 + x; |
4014 | 211 src = image[1]; |
212 for(i=0;i<h/2;i++){ | |
213 memcpy(dest,src,w/2); | |
214 src+=stride[1]; | |
215 dest+=bespitch/2; | |
216 } | |
217 apitch = vidix_play.dest.pitch.u-1; | |
218 bespitch = (w + apitch) & ~apitch; | |
4010 | 219 |
4032 | 220 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u; |
4031 | 221 dest += bespitch*y/4 + x; |
4010 | 222 src = image[2]; |
4014 | 223 for(i=0;i<h/2;i++){ |
224 memcpy(dest,src,w/2); | |
4010 | 225 src+=stride[2]; |
4014 | 226 dest += bespitch/2; |
4010 | 227 } |
228 return 0; | |
229 } | |
230 | |
231 uint32_t vidix_draw_slice_422(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
232 { | |
233 uint8_t *src; | |
234 uint8_t *dest; | |
4014 | 235 unsigned bespitch,apitch; |
4010 | 236 int i; |
4014 | 237 apitch = vidix_play.dest.pitch.y-1; |
238 bespitch = (w*2 + apitch) & ~apitch; | |
4032 | 239 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y; |
4010 | 240 dest += bespitch*y + x; |
241 src = image[0]; | |
242 for(i=0;i<h;i++){ | |
243 memcpy(dest,src,w*2); | |
244 src+=stride[0]; | |
245 dest += bespitch; | |
246 } | |
247 } | |
248 | |
249 | |
250 uint32_t vidix_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
251 { | |
252 if(verbose > 1) printf("vosub_vidix: vidix_draw_slice() was called\n"); | |
253 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) | |
254 vidix_draw_slice_420(image,stride,w,h,x,y); | |
255 else | |
256 vidix_draw_slice_422(image,stride,w,h,x,y); | |
257 return 0; | |
258 } | |
259 | |
260 uint32_t vidix_draw_frame(uint8_t *image[]) | |
261 { | |
262 if(verbose > 1) printf("vosub_vidix: vidix_draw_frame() was called\n"); | |
263 /* Note it's very strange but sometime for YUY2 draw_frame is called */ | |
264 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) | |
265 { | |
266 printf("vosub_vidix: draw_frame for i420 is called\nExiting...\n"); | |
267 vidix_term(); | |
268 exit( EXIT_FAILURE ); | |
269 } | |
270 else | |
271 { | |
272 int stride[1]; | |
273 stride[0] = vidix_play.src.w*2; | |
274 vidix_draw_slice_422(image,stride,vidix_play.src.w,vidix_play.src.h, | |
275 vidix_play.src.x,vidix_play.src.y); | |
276 } | |
277 return 0; | |
278 } | |
279 | |
280 void vidix_flip_page(void) | |
281 { | |
282 if(verbose > 1) printf("vosub_vidix: vidix_flip_page() was called\n"); | |
283 if(vo_doublebuffering) | |
284 { | |
4032 | 285 vdlPlaybackFrameSelect(vidix_handler,next_frame); |
4010 | 286 next_frame=(next_frame+1)%vidix_play.num_frames; |
287 } | |
288 } | |
289 | |
290 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
291 { | |
292 UNUSED(x0); | |
293 UNUSED(y0); | |
294 UNUSED(w); | |
295 UNUSED(h); | |
296 UNUSED(src); | |
297 UNUSED(srca); | |
298 UNUSED(stride); | |
299 } | |
300 | |
301 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
302 { | |
4032 | 303 uint32_t apitch,bespitch; |
4010 | 304 void *lvo_mem; |
4032 | 305 lvo_mem = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y; |
306 apitch = vidix_play.dest.pitch.y-1; | |
307 bespitch = (vidix_play.src.w + apitch) & (~apitch); | |
4010 | 308 switch(vidix_play.fourcc){ |
309 case IMGFMT_YV12: | |
310 case IMGFMT_IYUV: | |
311 case IMGFMT_I420: | |
312 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch); | |
313 break; | |
314 case IMGFMT_YUY2: | |
4032 | 315 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),2*bespitch); |
4010 | 316 break; |
317 case IMGFMT_UYVY: | |
4032 | 318 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,2*bespitch); |
4010 | 319 break; |
320 default: | |
321 draw_alpha_null(x0,y0,w,h,src,srca,stride); | |
322 } | |
323 } | |
324 | |
325 void vidix_draw_osd(void) | |
326 { | |
327 if(verbose > 1) printf("vosub_vidix: vidix_draw_osd() was called\n"); | |
328 /* TODO: hw support */ | |
329 vo_draw_text(vidix_play.src.w,vidix_play.src.h,draw_alpha); | |
330 } | |
331 | |
332 uint32_t vidix_query_fourcc(uint32_t format) | |
333 { | |
334 if(verbose > 1) printf("vosub_vidix: query_format was called: %x (%s)\n",format,vo_format_name(format)); | |
335 vidix_fourcc.fourcc = format; | |
336 vdlQueryFourcc(vidix_handler,&vidix_fourcc); | |
337 return vidix_fourcc.depth != VID_DEPTH_NONE; | |
338 } |