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