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