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