Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 5610:fd196de4f1e9
cleanup. cosmetics only, no functional changes
author | arpi |
---|---|
date | Sat, 13 Apr 2002 22:16:15 +0000 |
parents | 5fbfd8545c3b |
children | 3e62e9cd1816 |
rev | line source |
---|---|
2869 | 1 /* |
2 * vesa_lvo.c | |
3 * | |
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001 | |
5 * | |
6 * You can redistribute this file under terms and conditions | |
7 * of GNU General Public licence v2. | |
8 * | |
9 * This file contains vo_vesa interface to Linux Video Overlay. | |
10 * (Partly based on vo_mga.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 | |
3205 | 22 #include "config.h" |
23 | |
2869 | 24 #include "vesa_lvo.h" |
25 #include "img_format.h" | |
26 #include "../drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */ | |
27 #include "fastmemcpy.h" | |
3205 | 28 #include "osd.h" |
3202 | 29 #include "video_out.h" |
30 | |
3165 | 31 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */ |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
32 #define NUM_FRAMES 10 |
3205 | 33 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ |
34 | |
2869 | 35 static uint8_t *frames[NUM_FRAMES]; |
36 | |
37 static int lvo_handler = -1; | |
38 static uint8_t *lvo_mem = NULL; | |
39 static uint8_t next_frame; | |
40 static mga_vid_config_t mga_vid_config; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
41 static unsigned image_bpp,image_height,image_width,src_format; |
2952 | 42 extern int verbose; |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
43 uint32_t vlvo_control(uint32_t request, void *data, ...); |
2869 | 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 | |
3202 | 49 extern vo_functions_t video_out_vesa; |
50 | |
4493 | 51 static void vlvo_query_vaa(vo_vaa_t *vaa) |
52 { | |
53 memset(vaa,0,sizeof(vo_vaa_t)); | |
54 } | |
55 | |
2971 | 56 int vlvo_preinit(const char *drvname) |
57 { | |
4493 | 58 printf("vesa_lvo: This branch is no longer supported.\n" |
59 "vesa_lvo: Please use -vo vesa:vidix instead\n"); | |
60 return -1; | |
3017 | 61 if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname); |
2971 | 62 lvo_handler = open(drvname,O_RDWR); |
63 if(lvo_handler == -1) | |
64 { | |
65 printf("vesa_lvo: Couldn't open '%s'\n",drvname); | |
66 return -1; | |
67 } | |
3202 | 68 /* we are able to tune up this stuff depend on fourcc format */ |
69 video_out_vesa.draw_slice=vlvo_draw_slice; | |
70 video_out_vesa.draw_frame=vlvo_draw_frame; | |
71 video_out_vesa.flip_page=vlvo_flip_page; | |
72 video_out_vesa.draw_osd=vlvo_draw_osd; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
73 video_out_vesa.control=vlvo_control; |
2971 | 74 return 0; |
75 } | |
76 | |
77 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 78 unsigned x_org,unsigned y_org,unsigned dst_width, |
79 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
80 { | |
81 size_t i,awidth; | |
4493 | 82 printf("vesa_lvo: This branch is no longer supported.\n" |
83 "vesa_lvo: Please use -vo vesa:vidix instead\n"); | |
84 return -1; | |
3017 | 85 if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n"); |
2869 | 86 image_width = src_width; |
87 image_height = src_height; | |
88 mga_vid_config.version=MGA_VID_VERSION; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
89 src_format = mga_vid_config.format=format; |
2869 | 90 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
91 switch(format){ | |
92 case IMGFMT_YV12: | |
93 case IMGFMT_I420: | |
94 case IMGFMT_IYUV: | |
95 image_bpp=16; | |
96 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2; | |
97 break; | |
98 case IMGFMT_YUY2: | |
99 case IMGFMT_UYVY: | |
100 image_bpp=16; | |
101 mga_vid_config.frame_size = awidth*src_height*2; | |
102 break; | |
103 case IMGFMT_RGB15: | |
104 case IMGFMT_BGR15: | |
105 case IMGFMT_RGB16: | |
106 case IMGFMT_BGR16: | |
107 image_bpp=16; | |
108 mga_vid_config.frame_size = awidth*src_height*2; | |
109 break; | |
110 case IMGFMT_RGB24: | |
111 case IMGFMT_BGR24: | |
112 image_bpp=24; | |
113 mga_vid_config.frame_size = awidth*src_height*3; | |
114 break; | |
115 case IMGFMT_RGB32: | |
116 case IMGFMT_BGR32: | |
117 image_bpp=32; | |
118 mga_vid_config.frame_size = awidth*src_height*4; | |
119 break; | |
120 default: | |
121 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format); | |
122 return -1; | |
123 } | |
124 mga_vid_config.colkey_on=0; | |
125 mga_vid_config.src_width = src_width; | |
126 mga_vid_config.src_height= src_height; | |
127 mga_vid_config.dest_width = dst_width; | |
128 mga_vid_config.dest_height= dst_height; | |
129 mga_vid_config.x_org=x_org; | |
130 mga_vid_config.y_org=y_org; | |
131 mga_vid_config.num_frames=NUM_FRAMES; | |
132 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
133 { | |
2971 | 134 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
135 printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n"); | |
2869 | 136 return -1; |
137 } | |
138 ioctl(lvo_handler,MGA_VID_ON,0); | |
139 | |
140 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
141 for(i=1;i<NUM_FRAMES;i++) | |
142 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
143 next_frame = 0; | |
144 lvo_mem = frames[next_frame]; | |
145 | |
146 /*clear the buffer*/ | |
147 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
148 return 0; | |
149 } | |
150 | |
151 void vlvo_term( void ) | |
152 { | |
3017 | 153 if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n"); |
2869 | 154 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
155 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
156 if(lvo_handler != -1) close(lvo_handler); | |
157 } | |
158 | |
3165 | 159 uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) |
2869 | 160 { |
161 uint8_t *src; | |
162 uint8_t *dest; | |
3020 | 163 uint32_t bespitch,bespitch2; |
2869 | 164 int i; |
165 | |
166 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
167 bespitch2 = bespitch/2; | |
168 | |
169 dest = lvo_mem + bespitch * y + x; | |
170 src = image[0]; | |
171 for(i=0;i<h;i++){ | |
172 memcpy(dest,src,w); | |
173 src+=stride[0]; | |
174 dest += bespitch; | |
175 } | |
176 | |
177 w/=2;h/=2;x/=2;y/=2; | |
178 | |
179 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
180 src = image[1]; | |
181 for(i=0;i<h;i++){ | |
182 memcpy(dest,src,w); | |
183 src+=stride[1]; | |
184 dest += bespitch2; | |
185 } | |
186 | |
187 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
188 + bespitch*mga_vid_config.src_height / 4 | |
189 + bespitch2 * y + x; | |
190 src = image[2]; | |
191 for(i=0;i<h;i++){ | |
192 memcpy(dest,src,w); | |
193 src+=stride[2]; | |
194 dest += bespitch2; | |
195 } | |
3020 | 196 return 0; |
197 } | |
198 | |
199 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
200 { | |
201 if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n"); | |
3165 | 202 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) |
3202 | 203 vlvo_draw_slice_420(image,stride,w,h,x,y); |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
204 else |
3202 | 205 { |
206 uint8_t *dst; | |
207 uint8_t bytpp; | |
208 bytpp = (image_bpp+7)/8; | |
209 dst = lvo_mem + (image_width * y + x)*bytpp; | |
210 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */ | |
211 memcpy(dst,image[0],mga_vid_config.frame_size); | |
212 } | |
2924 | 213 return 0; |
2869 | 214 } |
215 | |
3017 | 216 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 217 { |
3017 | 218 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
219 memcpy(lvo_mem,image[0],mga_vid_config.frame_size); | |
220 if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n"); | |
221 return 0; | |
2869 | 222 } |
223 | |
224 void vlvo_flip_page(void) | |
225 { | |
3017 | 226 if(verbose > 1) printf("vesa_lvo: vlvo_flip_page() was called\n"); |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
227 if(vo_doublebuffering) |
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
228 { |
2869 | 229 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
230 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
231 lvo_mem=frames[next_frame]; | |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
232 } |
2869 | 233 } |
234 | |
3205 | 235 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
236 { | |
237 UNUSED(x0); | |
238 UNUSED(y0); | |
239 UNUSED(w); | |
240 UNUSED(h); | |
241 UNUSED(src); | |
242 UNUSED(srca); | |
243 UNUSED(stride); | |
244 } | |
245 | |
246 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
247 { | |
248 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15; | |
249 switch(mga_vid_config.format){ | |
250 case IMGFMT_BGR15: | |
251 case IMGFMT_RGB15: | |
252 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
253 break; | |
254 case IMGFMT_BGR16: | |
255 case IMGFMT_RGB16: | |
256 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
257 break; | |
258 case IMGFMT_BGR24: | |
259 case IMGFMT_RGB24: | |
260 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch); | |
261 break; | |
262 case IMGFMT_BGR32: | |
263 case IMGFMT_RGB32: | |
264 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch); | |
265 break; | |
266 case IMGFMT_YV12: | |
267 case IMGFMT_IYUV: | |
268 case IMGFMT_I420: | |
269 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch); | |
270 break; | |
271 case IMGFMT_YUY2: | |
272 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch); | |
273 break; | |
274 case IMGFMT_UYVY: | |
275 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch); | |
276 break; | |
277 default: | |
278 draw_alpha_null(x0,y0,w,h,src,srca,stride); | |
279 } | |
280 } | |
281 | |
2869 | 282 void vlvo_draw_osd(void) |
283 { | |
3017 | 284 if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n"); |
2869 | 285 /* TODO: hw support */ |
3205 | 286 #if 0 |
287 /* disable this stuff until new fbvid.h interface will be implemented | |
288 because in different fourcc radeon_vid and rage128_vid have different | |
289 width alignment */ | |
290 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha); | |
291 #endif | |
2869 | 292 } |
293 | |
294 uint32_t vlvo_query_info(uint32_t format) | |
295 { | |
3017 | 296 if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); |
2869 | 297 return 1; |
298 } | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
299 |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
300 uint32_t vlvo_control(uint32_t request, void *data, ...) |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
301 { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
302 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
303 case VOCTRL_QUERY_VAA: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
304 vlvo_query_vaa((vo_vaa_t*)data); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
305 return VO_TRUE; |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
306 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
307 return vlvo_query_info(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
308 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
309 return VO_NOTIMPL; |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
310 } |