Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 4247:2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
author | atmos4 |
---|---|
date | Sat, 19 Jan 2002 05:12:34 +0000 |
parents | ff90589b635f |
children | 9b6430df4de5 |
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; |
2869 | 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 | |
3202 | 48 extern vo_functions_t video_out_vesa; |
49 | |
2971 | 50 int vlvo_preinit(const char *drvname) |
51 { | |
3017 | 52 if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname); |
2971 | 53 lvo_handler = open(drvname,O_RDWR); |
54 if(lvo_handler == -1) | |
55 { | |
56 printf("vesa_lvo: Couldn't open '%s'\n",drvname); | |
57 return -1; | |
58 } | |
3202 | 59 /* we are able to tune up this stuff depend on fourcc format */ |
60 video_out_vesa.draw_slice=vlvo_draw_slice; | |
61 video_out_vesa.draw_frame=vlvo_draw_frame; | |
62 video_out_vesa.flip_page=vlvo_flip_page; | |
63 video_out_vesa.draw_osd=vlvo_draw_osd; | |
2971 | 64 return 0; |
65 } | |
66 | |
67 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 68 unsigned x_org,unsigned y_org,unsigned dst_width, |
69 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
70 { | |
71 size_t i,awidth; | |
3017 | 72 if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n"); |
2869 | 73 image_width = src_width; |
74 image_height = src_height; | |
75 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
|
76 src_format = mga_vid_config.format=format; |
2869 | 77 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
78 switch(format){ | |
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; | |
85 case IMGFMT_YUY2: | |
86 case IMGFMT_UYVY: | |
87 image_bpp=16; | |
88 mga_vid_config.frame_size = awidth*src_height*2; | |
89 break; | |
90 case IMGFMT_RGB15: | |
91 case IMGFMT_BGR15: | |
92 case IMGFMT_RGB16: | |
93 case IMGFMT_BGR16: | |
94 image_bpp=16; | |
95 mga_vid_config.frame_size = awidth*src_height*2; | |
96 break; | |
97 case IMGFMT_RGB24: | |
98 case IMGFMT_BGR24: | |
99 image_bpp=24; | |
100 mga_vid_config.frame_size = awidth*src_height*3; | |
101 break; | |
102 case IMGFMT_RGB32: | |
103 case IMGFMT_BGR32: | |
104 image_bpp=32; | |
105 mga_vid_config.frame_size = awidth*src_height*4; | |
106 break; | |
107 default: | |
108 printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format); | |
109 return -1; | |
110 } | |
111 mga_vid_config.colkey_on=0; | |
112 mga_vid_config.src_width = src_width; | |
113 mga_vid_config.src_height= src_height; | |
114 mga_vid_config.dest_width = dst_width; | |
115 mga_vid_config.dest_height= dst_height; | |
116 mga_vid_config.x_org=x_org; | |
117 mga_vid_config.y_org=y_org; | |
118 mga_vid_config.num_frames=NUM_FRAMES; | |
119 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
120 { | |
2971 | 121 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
122 printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n"); | |
2869 | 123 return -1; |
124 } | |
125 ioctl(lvo_handler,MGA_VID_ON,0); | |
126 | |
127 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
128 for(i=1;i<NUM_FRAMES;i++) | |
129 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
130 next_frame = 0; | |
131 lvo_mem = frames[next_frame]; | |
132 | |
133 /*clear the buffer*/ | |
134 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
135 return 0; | |
136 } | |
137 | |
138 void vlvo_term( void ) | |
139 { | |
3017 | 140 if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n"); |
2869 | 141 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
142 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
143 if(lvo_handler != -1) close(lvo_handler); | |
144 } | |
145 | |
3165 | 146 uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) |
2869 | 147 { |
148 uint8_t *src; | |
149 uint8_t *dest; | |
3020 | 150 uint32_t bespitch,bespitch2; |
2869 | 151 int i; |
152 | |
153 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
154 bespitch2 = bespitch/2; | |
155 | |
156 dest = lvo_mem + bespitch * y + x; | |
157 src = image[0]; | |
158 for(i=0;i<h;i++){ | |
159 memcpy(dest,src,w); | |
160 src+=stride[0]; | |
161 dest += bespitch; | |
162 } | |
163 | |
164 w/=2;h/=2;x/=2;y/=2; | |
165 | |
166 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
167 src = image[1]; | |
168 for(i=0;i<h;i++){ | |
169 memcpy(dest,src,w); | |
170 src+=stride[1]; | |
171 dest += bespitch2; | |
172 } | |
173 | |
174 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
175 + bespitch*mga_vid_config.src_height / 4 | |
176 + bespitch2 * y + x; | |
177 src = image[2]; | |
178 for(i=0;i<h;i++){ | |
179 memcpy(dest,src,w); | |
180 src+=stride[2]; | |
181 dest += bespitch2; | |
182 } | |
3020 | 183 return 0; |
184 } | |
185 | |
186 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
187 { | |
188 if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n"); | |
3165 | 189 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) |
3202 | 190 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
|
191 else |
3202 | 192 { |
193 uint8_t *dst; | |
194 uint8_t bytpp; | |
195 bytpp = (image_bpp+7)/8; | |
196 dst = lvo_mem + (image_width * y + x)*bytpp; | |
197 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */ | |
198 memcpy(dst,image[0],mga_vid_config.frame_size); | |
199 } | |
2924 | 200 return 0; |
2869 | 201 } |
202 | |
3017 | 203 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 204 { |
3017 | 205 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
206 memcpy(lvo_mem,image[0],mga_vid_config.frame_size); | |
207 if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n"); | |
208 return 0; | |
2869 | 209 } |
210 | |
211 void vlvo_flip_page(void) | |
212 { | |
3017 | 213 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
|
214 if(vo_doublebuffering) |
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
215 { |
2869 | 216 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
217 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
218 lvo_mem=frames[next_frame]; | |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
219 } |
2869 | 220 } |
221 | |
3205 | 222 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
223 { | |
224 UNUSED(x0); | |
225 UNUSED(y0); | |
226 UNUSED(w); | |
227 UNUSED(h); | |
228 UNUSED(src); | |
229 UNUSED(srca); | |
230 UNUSED(stride); | |
231 } | |
232 | |
233 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
234 { | |
235 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15; | |
236 switch(mga_vid_config.format){ | |
237 case IMGFMT_BGR15: | |
238 case IMGFMT_RGB15: | |
239 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
240 break; | |
241 case IMGFMT_BGR16: | |
242 case IMGFMT_RGB16: | |
243 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
244 break; | |
245 case IMGFMT_BGR24: | |
246 case IMGFMT_RGB24: | |
247 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch); | |
248 break; | |
249 case IMGFMT_BGR32: | |
250 case IMGFMT_RGB32: | |
251 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch); | |
252 break; | |
253 case IMGFMT_YV12: | |
254 case IMGFMT_IYUV: | |
255 case IMGFMT_I420: | |
256 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch); | |
257 break; | |
258 case IMGFMT_YUY2: | |
259 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch); | |
260 break; | |
261 case IMGFMT_UYVY: | |
262 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch); | |
263 break; | |
264 default: | |
265 draw_alpha_null(x0,y0,w,h,src,srca,stride); | |
266 } | |
267 } | |
268 | |
2869 | 269 void vlvo_draw_osd(void) |
270 { | |
3017 | 271 if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n"); |
2869 | 272 /* TODO: hw support */ |
3205 | 273 #if 0 |
274 /* disable this stuff until new fbvid.h interface will be implemented | |
275 because in different fourcc radeon_vid and rage128_vid have different | |
276 width alignment */ | |
277 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha); | |
278 #endif | |
2869 | 279 } |
280 | |
281 uint32_t vlvo_query_info(uint32_t format) | |
282 { | |
3017 | 283 if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); |
2869 | 284 return 1; |
285 } |