Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libvo / vesa_lvo.c
blobb1905679c858955a60abe8607decd83115c3d5b0
1 /*
2 * vo_vesa interface to Linux Video Overlay
3 * (partly based on vo_mga.c)
5 * copyright (C) 2001 Nick Kurshev <nickols_k@mail.ru>
7 * This file is part of MPlayer.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <inttypes.h>
25 #include <sys/ioctl.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <sys/mman.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include "config.h"
34 #include "mp_msg.h"
36 #include "vesa_lvo.h"
37 #include "libmpcodecs/img_format.h"
38 #include "drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
39 #include "fastmemcpy.h"
40 #include "osd.h"
41 #include "video_out.h"
42 #include "sub.h"
43 #include "libmpcodecs/vfcap.h"
45 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */
46 #define NUM_FRAMES 10
47 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */
49 static uint8_t *frames[NUM_FRAMES];
51 static int lvo_handler = -1;
52 static uint8_t *lvo_mem = NULL;
53 static uint8_t next_frame;
54 static mga_vid_config_t mga_vid_config;
55 static unsigned image_bpp,image_height,image_width,src_format;
56 int vlvo_control(uint32_t request, void *data);
58 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
59 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
60 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
62 extern struct vo_old_functions video_out_vesa;
64 int vlvo_preinit(const char *drvname)
66 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n");
67 return -1;
68 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
69 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_preinit(%s) was called\n",drvname);}
70 lvo_handler = open(drvname,O_RDWR);
71 if(lvo_handler == -1)
73 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] Couldn't open: '%s'\n",drvname);
74 return -1;
76 /* we are able to tune up this stuff depend on fourcc format */
77 video_out_vesa.draw_slice=vlvo_draw_slice;
78 video_out_vesa.draw_frame=vlvo_draw_frame;
79 video_out_vesa.flip_page=vlvo_flip_page;
80 video_out_vesa.draw_osd=vlvo_draw_osd;
81 video_out_vesa.control=vlvo_control;
82 return 0;
85 int vlvo_init(unsigned src_width,unsigned src_height,
86 unsigned x_org,unsigned y_org,unsigned dst_width,
87 unsigned dst_height,unsigned format,unsigned dest_bpp)
89 size_t i,awidth;
90 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n");
91 return -1;
92 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
93 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_init() was called\n");}
94 image_width = src_width;
95 image_height = src_height;
96 mga_vid_config.version=MGA_VID_VERSION;
97 src_format = mga_vid_config.format=format;
98 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
99 switch(format){
100 case IMGFMT_YV12:
101 case IMGFMT_I420:
102 case IMGFMT_IYUV:
103 image_bpp=16;
104 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
105 break;
106 case IMGFMT_YUY2:
107 case IMGFMT_UYVY:
108 image_bpp=16;
109 mga_vid_config.frame_size = awidth*src_height*2;
110 break;
111 case IMGFMT_RGB15:
112 case IMGFMT_BGR15:
113 case IMGFMT_RGB16:
114 case IMGFMT_BGR16:
115 image_bpp=16;
116 mga_vid_config.frame_size = awidth*src_height*2;
117 break;
118 case IMGFMT_RGB24:
119 case IMGFMT_BGR24:
120 image_bpp=24;
121 mga_vid_config.frame_size = awidth*src_height*3;
122 break;
123 case IMGFMT_RGB32:
124 case IMGFMT_BGR32:
125 image_bpp=32;
126 mga_vid_config.frame_size = awidth*src_height*4;
127 break;
128 default:
129 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVI] Invalid output format: %s(%0X)\n",vo_format_name(format),format);
130 return -1;
132 mga_vid_config.colkey_on=0;
133 mga_vid_config.src_width = src_width;
134 mga_vid_config.src_height= src_height;
135 mga_vid_config.dest_width = dst_width;
136 mga_vid_config.dest_height= dst_height;
137 mga_vid_config.x_org=x_org;
138 mga_vid_config.y_org=y_org;
139 mga_vid_config.num_frames=NUM_FRAMES;
140 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
142 perror("vesa_lvo: Error in mga_vid_config ioctl()");
143 mp_tmsg(MSGT_VO,MSGL_WARN, "[VESA_LVO] Your fb_vid driver version is incompatible with this MPlayer version!\n");
144 return -1;
146 ioctl(lvo_handler,MGA_VID_ON,0);
148 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
149 for(i=1;i<NUM_FRAMES;i++)
150 frames[i] = frames[i-1] + mga_vid_config.frame_size;
151 next_frame = 0;
152 lvo_mem = frames[next_frame];
154 /*clear the buffer*/
155 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
156 return 0;
159 void vlvo_term( void )
161 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
162 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_term() was called\n");}
163 ioctl( lvo_handler,MGA_VID_OFF,0 );
164 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
165 if(lvo_handler != -1) close(lvo_handler);
168 int vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
170 uint8_t *src;
171 uint8_t *dest;
172 uint32_t bespitch,bespitch2;
173 int i;
175 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
176 bespitch2 = bespitch/2;
178 dest = lvo_mem + bespitch * y + x;
179 src = image[0];
180 for(i=0;i<h;i++){
181 fast_memcpy(dest,src,w);
182 src+=stride[0];
183 dest += bespitch;
186 w/=2;h/=2;x/=2;y/=2;
188 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
189 src = image[1];
190 for(i=0;i<h;i++){
191 fast_memcpy(dest,src,w);
192 src+=stride[1];
193 dest += bespitch2;
196 dest = lvo_mem + bespitch*mga_vid_config.src_height
197 + bespitch*mga_vid_config.src_height / 4
198 + bespitch2 * y + x;
199 src = image[2];
200 for(i=0;i<h;i++){
201 fast_memcpy(dest,src,w);
202 src+=stride[2];
203 dest += bespitch2;
205 return 0;
208 int vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
210 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
211 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_slice() was called\n");}
212 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
213 vlvo_draw_slice_420(image,stride,w,h,x,y);
214 else
216 uint8_t *dst;
217 uint8_t bytpp;
218 bytpp = (image_bpp+7)/8;
219 dst = lvo_mem + (image_width * y + x)*bytpp;
220 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */
221 fast_memcpy(dst,image[0],mga_vid_config.frame_size);
223 return 0;
226 int vlvo_draw_frame(uint8_t *image[])
228 /* Note it's very strange but sometime for YUY2 draw_frame is called */
229 fast_memcpy(lvo_mem,image[0],mga_vid_config.frame_size);
230 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
231 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_flip_page() was called\n");}
232 return 0;
235 void vlvo_flip_page(void)
237 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
238 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_osd() was called\n");}
239 if(vo_doublebuffering)
241 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
242 next_frame=(next_frame+1)%mga_vid_config.num_frames;
243 lvo_mem=frames[next_frame];
247 #if 0
248 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
250 UNUSED(x0);
251 UNUSED(y0);
252 UNUSED(w);
253 UNUSED(h);
254 UNUSED(src);
255 UNUSED(srca);
256 UNUSED(stride);
259 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
261 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15;
262 switch(mga_vid_config.format){
263 case IMGFMT_BGR15:
264 case IMGFMT_RGB15:
265 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
266 break;
267 case IMGFMT_BGR16:
268 case IMGFMT_RGB16:
269 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
270 break;
271 case IMGFMT_BGR24:
272 case IMGFMT_RGB24:
273 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch);
274 break;
275 case IMGFMT_BGR32:
276 case IMGFMT_RGB32:
277 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch);
278 break;
279 case IMGFMT_YV12:
280 case IMGFMT_IYUV:
281 case IMGFMT_I420:
282 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
283 break;
284 case IMGFMT_YUY2:
285 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch);
286 break;
287 case IMGFMT_UYVY:
288 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch);
289 break;
290 default:
291 draw_alpha_null(x0,y0,w,h,src,srca,stride);
294 #endif
296 void vlvo_draw_osd(void)
298 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
299 mp_msg(MSGT_VO,MSGL_DBG2,"vesa_lvo: vlvo_draw_osd() was called\n"); }
300 /* TODO: hw support */
301 #if 0
302 /* disable this stuff until new fbvid.h interface will be implemented
303 because in different fourcc radeon_vid and rage128_vid have different
304 width alignment */
305 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);
306 #endif
309 uint32_t vlvo_query_info(uint32_t format)
311 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
312 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); }
313 return VFCAP_CSP_SUPPORTED;
316 int vlvo_control(uint32_t request, void *data)
318 switch (request) {
319 case VOCTRL_QUERY_FORMAT:
320 return vlvo_query_info(*((uint32_t*)data));
322 return VO_NOTIMPL;