Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 3019:64ce4a515a78
Bad attempt of YV12 direct support
author | nick |
---|---|
date | Tue, 20 Nov 2001 10:00:58 +0000 |
parents | fb792e58aac5 |
children | e5ebde3ebdd6 |
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 | |
22 #include "vesa_lvo.h" | |
23 #include "img_format.h" | |
24 #include "../drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */ | |
25 #include "fastmemcpy.h" | |
26 #include "../mmx_defs.h" | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
27 #include "../postproc/rgb2rgb.h" |
2869 | 28 |
29 #define WIDTH_ALIGN 32 /* should be 16 for radeons */ | |
30 #define NUM_FRAMES 2 | |
31 static uint8_t *frames[NUM_FRAMES]; | |
32 | |
33 static int lvo_handler = -1; | |
34 static uint8_t *lvo_mem = NULL; | |
35 static uint8_t next_frame; | |
36 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
|
37 static unsigned image_bpp,image_height,image_width,src_format; |
2952 | 38 extern int verbose; |
2869 | 39 |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
40 #define HAVE_RADEON 1 |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
41 |
2869 | 42 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8) |
43 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) ) | |
44 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size)) | |
45 | |
2971 | 46 int vlvo_preinit(const char *drvname) |
47 { | |
3017 | 48 if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname); |
2971 | 49 lvo_handler = open(drvname,O_RDWR); |
50 if(lvo_handler == -1) | |
51 { | |
52 printf("vesa_lvo: Couldn't open '%s'\n",drvname); | |
53 return -1; | |
54 } | |
55 return 0; | |
56 } | |
57 | |
58 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 59 unsigned x_org,unsigned y_org,unsigned dst_width, |
60 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
61 { | |
62 size_t i,awidth; | |
3017 | 63 if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n"); |
2869 | 64 image_width = src_width; |
65 image_height = src_height; | |
66 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
|
67 src_format = mga_vid_config.format=format; |
2869 | 68 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
69 switch(format){ | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
70 #ifdef HAVE_RADEON |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
71 case IMGFMT_YV12: |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
72 case IMGFMT_I420: |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
73 case IMGFMT_IYUV: |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
74 image_bpp=16; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
75 mga_vid_config.format = IMGFMT_YUY2; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
76 mga_vid_config.frame_size = awidth*src_height*2; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
77 break; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
78 #else |
2869 | 79 case IMGFMT_YV12: |
80 case IMGFMT_I420: | |
81 case IMGFMT_IYUV: | |
82 image_bpp=16; | |
83 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2; | |
84 break; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
85 #endif |
2869 | 86 case IMGFMT_YUY2: |
87 case IMGFMT_UYVY: | |
88 image_bpp=16; | |
89 mga_vid_config.frame_size = awidth*src_height*2; | |
90 break; | |
91 case IMGFMT_RGB15: | |
92 case IMGFMT_BGR15: | |
93 case IMGFMT_RGB16: | |
94 case IMGFMT_BGR16: | |
95 image_bpp=16; | |
96 mga_vid_config.frame_size = awidth*src_height*2; | |
97 break; | |
98 case IMGFMT_RGB24: | |
99 case IMGFMT_BGR24: | |
100 image_bpp=24; | |
101 mga_vid_config.frame_size = awidth*src_height*3; | |
102 break; | |
103 case IMGFMT_RGB32: | |
104 case IMGFMT_BGR32: | |
105 image_bpp=32; | |
106 mga_vid_config.frame_size = awidth*src_height*4; | |
107 break; | |
108 default: | |
109 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format); | |
110 return -1; | |
111 } | |
112 mga_vid_config.colkey_on=0; | |
113 mga_vid_config.src_width = src_width; | |
114 mga_vid_config.src_height= src_height; | |
115 mga_vid_config.dest_width = dst_width; | |
116 mga_vid_config.dest_height= dst_height; | |
117 mga_vid_config.x_org=x_org; | |
118 mga_vid_config.y_org=y_org; | |
119 mga_vid_config.num_frames=NUM_FRAMES; | |
120 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
121 { | |
2971 | 122 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
123 printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n"); | |
2869 | 124 return -1; |
125 } | |
126 ioctl(lvo_handler,MGA_VID_ON,0); | |
127 | |
128 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
129 for(i=1;i<NUM_FRAMES;i++) | |
130 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
131 next_frame = 0; | |
132 lvo_mem = frames[next_frame]; | |
133 | |
134 /*clear the buffer*/ | |
135 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
136 return 0; | |
137 } | |
138 | |
139 void vlvo_term( void ) | |
140 { | |
3017 | 141 if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n"); |
2869 | 142 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
143 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
144 if(lvo_handler != -1) close(lvo_handler); | |
145 } | |
146 | |
3019 | 147 static void |
148 CopyData420( | |
149 unsigned char *src1, | |
150 unsigned char *src2, | |
151 unsigned char *src3, | |
152 unsigned char *dst1, | |
153 unsigned char *dst2, | |
154 unsigned char *dst3, | |
155 int srcPitch, | |
156 int srcPitch2, | |
157 int dstPitch, | |
158 int h, | |
159 int w | |
160 ){ | |
161 int count; | |
162 | |
163 count = h; | |
164 while(count--) { | |
165 memcpy(dst1, src1, w); | |
166 src1 += srcPitch; | |
167 dst1 += dstPitch; | |
168 } | |
169 | |
170 w >>= 1; | |
171 h >>= 1; | |
172 dstPitch >>= 1; | |
173 | |
174 count = h; | |
175 while(count--) { | |
176 memcpy(dst2, src2, w); | |
177 src2 += srcPitch2; | |
178 dst2 += dstPitch; | |
179 } | |
180 | |
181 count = h; | |
182 while(count--) { | |
183 memcpy(dst3, src3, w); | |
184 src3 += srcPitch2; | |
185 dst3 += dstPitch; | |
186 } | |
187 } | |
188 | |
189 | |
2869 | 190 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) |
191 { | |
2924 | 192 #if 0 |
193 /* original vo_mga stuff */ | |
2869 | 194 uint8_t *src; |
195 uint8_t *dest; | |
2924 | 196 uint32_t bespitch,bespitch2,srcpitch; |
2869 | 197 int i; |
198 | |
199 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
200 bespitch2 = bespitch/2; | |
201 | |
202 dest = lvo_mem + bespitch * y + x; | |
203 src = image[0]; | |
204 for(i=0;i<h;i++){ | |
205 memcpy(dest,src,w); | |
206 src+=stride[0]; | |
207 dest += bespitch; | |
208 } | |
209 | |
210 w/=2;h/=2;x/=2;y/=2; | |
211 | |
212 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
213 src = image[1]; | |
214 for(i=0;i<h;i++){ | |
215 memcpy(dest,src,w); | |
216 src+=stride[1]; | |
217 dest += bespitch2; | |
218 } | |
219 | |
220 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
221 + bespitch*mga_vid_config.src_height / 4 | |
222 + bespitch2 * y + x; | |
223 src = image[2]; | |
224 for(i=0;i<h;i++){ | |
225 memcpy(dest,src,w); | |
226 src+=stride[2]; | |
227 dest += bespitch2; | |
228 } | |
2952 | 229 #else |
230 uint8_t *dst; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
231 uint8_t bytpp; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
232 bytpp = (image_bpp+7)/8; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
233 dst = lvo_mem + (image_width * y + x)*bytpp; |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
234 #ifdef HAVE_RADEON |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
235 if(src_format == IMGFMT_YV12) |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
236 { |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
237 yv12toyuy2(image[0],image[1],image[2],dst |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
238 ,w,h,stride[0],stride[1],w*2); |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
239 } |
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
240 else |
3019 | 241 #else |
242 if(src_format == IMGFMT_YV12) | |
243 { | |
244 uint32_t dstPitch,d1line,d2line,d3line,d1offset,d2offset,d3offset; | |
245 dstPitch = (mga_vid_config.src_width + 15) & ~15; /* of luma */ | |
246 d1line = y * dstPitch; | |
247 d2line = (mga_vid_config.src_height * dstPitch) + ((y >> 1) * (dstPitch >> 1)); | |
248 d3line = d2line + ((mga_vid_config.src_height >> 1) * (dstPitch >> 1)); | |
249 | |
250 y &= ~1; | |
251 | |
252 d1offset = (y * dstPitch) + x; | |
253 d2offset = d2line + (x >> 1); | |
254 d3offset = d3line + (x >> 1); | |
255 CopyData420(image[0],image[1],image[2], | |
256 dst+d1offset,dst+d2offset,dst+d3offset, | |
257 stride[0],stride[1],dstPitch,h,w); | |
258 } | |
259 else | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
260 #endif |
3017 | 261 memcpy(dst,image[0],mga_vid_config.frame_size); |
2924 | 262 #endif |
3017 | 263 if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n"); |
2924 | 264 return 0; |
2869 | 265 } |
266 | |
3017 | 267 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 268 { |
3017 | 269 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
270 memcpy(lvo_mem,image[0],mga_vid_config.frame_size); | |
271 if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n"); | |
272 return 0; | |
2869 | 273 } |
274 | |
275 void vlvo_flip_page(void) | |
276 { | |
3017 | 277 if(verbose > 1) printf("vesa_lvo: vlvo_flip_page() was called\n"); |
2869 | 278 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
279 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
280 lvo_mem=frames[next_frame]; | |
281 } | |
282 | |
283 void vlvo_draw_osd(void) | |
284 { | |
3017 | 285 if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n"); |
2869 | 286 /* TODO: hw support */ |
287 } | |
288 | |
289 uint32_t vlvo_query_info(uint32_t format) | |
290 { | |
3017 | 291 if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); |
2869 | 292 return 1; |
293 } |