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.
25 #include <sys/ioctl.h>
38 #include "libmpcodecs/img_format.h"
39 #include "drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
40 #include "fastmemcpy.h"
42 #include "video_out.h"
44 #include "libmpcodecs/vfcap.h"
46 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */
48 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */
50 static uint8_t *frames
[NUM_FRAMES
];
52 static int lvo_handler
= -1;
53 static uint8_t *lvo_mem
= NULL
;
54 static uint8_t next_frame
;
55 static mga_vid_config_t mga_vid_config
;
56 static unsigned image_bpp
,image_height
,image_width
,src_format
;
57 uint32_t vlvo_control(uint32_t request
, void *data
, ...);
59 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
60 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
61 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
63 extern vo_functions_t video_out_vesa
;
65 int vlvo_preinit(const char *drvname
)
67 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported
);
69 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
70 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_preinit(%s) was called\n",drvname
);}
71 lvo_handler
= open(drvname
,O_RDWR
);
74 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_VESA_CouldntOpen
,drvname
);
77 /* we are able to tune up this stuff depend on fourcc format */
78 video_out_vesa
.draw_slice
=vlvo_draw_slice
;
79 video_out_vesa
.draw_frame
=vlvo_draw_frame
;
80 video_out_vesa
.flip_page
=vlvo_flip_page
;
81 video_out_vesa
.draw_osd
=vlvo_draw_osd
;
82 video_out_vesa
.control
=vlvo_control
;
86 int vlvo_init(unsigned src_width
,unsigned src_height
,
87 unsigned x_org
,unsigned y_org
,unsigned dst_width
,
88 unsigned dst_height
,unsigned format
,unsigned dest_bpp
)
91 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported
);
93 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
94 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_init() was called\n");}
95 image_width
= src_width
;
96 image_height
= src_height
;
97 mga_vid_config
.version
=MGA_VID_VERSION
;
98 src_format
= mga_vid_config
.format
=format
;
99 awidth
= (src_width
+ (WIDTH_ALIGN
-1)) & ~(WIDTH_ALIGN
-1);
105 mga_vid_config
.frame_size
= awidth
*src_height
+(awidth
*src_height
)/2;
110 mga_vid_config
.frame_size
= awidth
*src_height
*2;
117 mga_vid_config
.frame_size
= awidth
*src_height
*2;
122 mga_vid_config
.frame_size
= awidth
*src_height
*3;
127 mga_vid_config
.frame_size
= awidth
*src_height
*4;
130 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_VESA_InvalidOutputFormat
,vo_format_name(format
),format
);
133 mga_vid_config
.colkey_on
=0;
134 mga_vid_config
.src_width
= src_width
;
135 mga_vid_config
.src_height
= src_height
;
136 mga_vid_config
.dest_width
= dst_width
;
137 mga_vid_config
.dest_height
= dst_height
;
138 mga_vid_config
.x_org
=x_org
;
139 mga_vid_config
.y_org
=y_org
;
140 mga_vid_config
.num_frames
=NUM_FRAMES
;
141 if (ioctl(lvo_handler
,MGA_VID_CONFIG
,&mga_vid_config
))
143 perror("vesa_lvo: Error in mga_vid_config ioctl()");
144 mp_msg(MSGT_VO
,MSGL_WARN
, MSGTR_LIBVO_VESA_IncompatibleDriverVersion
);
147 ioctl(lvo_handler
,MGA_VID_ON
,0);
149 frames
[0] = (char*)mmap(0,mga_vid_config
.frame_size
*mga_vid_config
.num_frames
,PROT_WRITE
,MAP_SHARED
,lvo_handler
,0);
150 for(i
=1;i
<NUM_FRAMES
;i
++)
151 frames
[i
] = frames
[i
-1] + mga_vid_config
.frame_size
;
153 lvo_mem
= frames
[next_frame
];
156 memset(frames
[0],0x80,mga_vid_config
.frame_size
*mga_vid_config
.num_frames
);
160 void vlvo_term( void )
162 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
163 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_term() was called\n");}
164 ioctl( lvo_handler
,MGA_VID_OFF
,0 );
165 munmap(frames
[0],mga_vid_config
.frame_size
*mga_vid_config
.num_frames
);
166 if(lvo_handler
!= -1) close(lvo_handler
);
169 uint32_t vlvo_draw_slice_420(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
173 uint32_t bespitch
,bespitch2
;
176 bespitch
= (mga_vid_config
.src_width
+ (WIDTH_ALIGN
-1)) & ~(WIDTH_ALIGN
-1);
177 bespitch2
= bespitch
/2;
179 dest
= lvo_mem
+ bespitch
* y
+ x
;
182 fast_memcpy(dest
,src
,w
);
189 dest
= lvo_mem
+ bespitch
*mga_vid_config
.src_height
+ bespitch2
* y
+ x
;
192 fast_memcpy(dest
,src
,w
);
197 dest
= lvo_mem
+ bespitch
*mga_vid_config
.src_height
198 + bespitch
*mga_vid_config
.src_height
/ 4
202 fast_memcpy(dest
,src
,w
);
209 uint32_t vlvo_draw_slice(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
211 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
212 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_draw_slice() was called\n");}
213 if(src_format
== IMGFMT_YV12
|| src_format
== IMGFMT_I420
|| src_format
== IMGFMT_IYUV
)
214 vlvo_draw_slice_420(image
,stride
,w
,h
,x
,y
);
219 bytpp
= (image_bpp
+7)/8;
220 dst
= lvo_mem
+ (image_width
* y
+ x
)*bytpp
;
221 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */
222 fast_memcpy(dst
,image
[0],mga_vid_config
.frame_size
);
227 uint32_t vlvo_draw_frame(uint8_t *image
[])
229 /* Note it's very strange but sometime for YUY2 draw_frame is called */
230 fast_memcpy(lvo_mem
,image
[0],mga_vid_config
.frame_size
);
231 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
232 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_flip_page() was called\n");}
236 void vlvo_flip_page(void)
238 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
239 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: vlvo_draw_osd() was called\n");}
240 if(vo_doublebuffering
)
242 ioctl(lvo_handler
,MGA_VID_FSEL
,&next_frame
);
243 next_frame
=(next_frame
+1)%mga_vid_config
.num_frames
;
244 lvo_mem
=frames
[next_frame
];
249 static void draw_alpha_null(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
)
260 static void draw_alpha(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
)
262 uint32_t bespitch
= /*(*/mga_vid_config
.src_width
;// + 15) & ~15;
263 switch(mga_vid_config
.format
){
266 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,lvo_mem
+2*(y0
*bespitch
+x0
),2*bespitch
);
270 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,lvo_mem
+2*(y0
*bespitch
+x0
),2*bespitch
);
274 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,lvo_mem
+3*(y0
*bespitch
+x0
),3*bespitch
);
278 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,lvo_mem
+4*(y0
*bespitch
+x0
),4*bespitch
);
283 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,lvo_mem
+bespitch
*y0
+x0
,bespitch
);
286 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,lvo_mem
+2*(bespitch
*y0
+x0
),bespitch
);
289 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,lvo_mem
+2*(bespitch
*y0
+x0
)+1,bespitch
);
292 draw_alpha_null(x0
,y0
,w
,h
,src
,srca
,stride
);
297 void vlvo_draw_osd(void)
299 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
300 mp_msg(MSGT_VO
,MSGL_DBG2
,"vesa_lvo: vlvo_draw_osd() was called\n"); }
301 /* TODO: hw support */
303 /* disable this stuff until new fbvid.h interface will be implemented
304 because in different fourcc radeon_vid and rage128_vid have different
306 vo_draw_text(mga_vid_config
.src_width
,mga_vid_config
.src_height
,draw_alpha
);
310 uint32_t vlvo_query_info(uint32_t format
)
312 if( mp_msg_test(MSGT_VO
,MSGL_DBG2
) ) {
313 mp_msg(MSGT_VO
,MSGL_DBG2
, "vesa_lvo: query_format was called: %x (%s)\n",format
,vo_format_name(format
)); }
314 return VFCAP_CSP_SUPPORTED
;
317 uint32_t vlvo_control(uint32_t request
, void *data
, ...)
320 case VOCTRL_QUERY_FORMAT
:
321 return vlvo_query_info(*((uint32_t*)data
));