2001-11-13 17:13:33 +00:00
|
|
|
/*
|
|
|
|
* vesa_lvo.c
|
|
|
|
*
|
|
|
|
* Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001
|
|
|
|
*
|
|
|
|
* You can redistribute this file under terms and conditions
|
|
|
|
* of GNU General Public licence v2.
|
|
|
|
*
|
|
|
|
* This file contains vo_vesa interface to Linux Video Overlay.
|
|
|
|
* (Partly based on vo_mga.c from mplayer's package)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-11-29 18:37:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-11-13 17:13:33 +00:00
|
|
|
#include "vesa_lvo.h"
|
|
|
|
#include "img_format.h"
|
|
|
|
#include "../drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */
|
|
|
|
#include "fastmemcpy.h"
|
2001-11-29 18:37:52 +00:00
|
|
|
#include "osd.h"
|
2001-11-29 18:00:57 +00:00
|
|
|
#include "video_out.h"
|
|
|
|
|
2001-11-27 18:36:35 +00:00
|
|
|
#define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */
|
2001-12-02 12:21:13 +00:00
|
|
|
#define NUM_FRAMES 10
|
2001-11-29 18:37:52 +00:00
|
|
|
#define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */
|
|
|
|
|
2001-11-13 17:13:33 +00:00
|
|
|
static uint8_t *frames[NUM_FRAMES];
|
|
|
|
|
|
|
|
static int lvo_handler = -1;
|
|
|
|
static uint8_t *lvo_mem = NULL;
|
|
|
|
static uint8_t next_frame;
|
|
|
|
static mga_vid_config_t mga_vid_config;
|
2001-11-18 18:04:29 +00:00
|
|
|
static unsigned image_bpp,image_height,image_width,src_format;
|
2001-11-17 16:10:41 +00:00
|
|
|
extern int verbose;
|
2001-11-13 17:13:33 +00:00
|
|
|
|
|
|
|
#define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8)
|
|
|
|
#define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) )
|
|
|
|
#define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size))
|
|
|
|
|
2001-11-29 18:00:57 +00:00
|
|
|
extern vo_functions_t video_out_vesa;
|
|
|
|
|
2001-11-18 15:06:32 +00:00
|
|
|
int vlvo_preinit(const char *drvname)
|
2001-11-13 17:13:33 +00:00
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_preinit(%s) was called\n",drvname);
|
2001-11-13 17:13:33 +00:00
|
|
|
lvo_handler = open(drvname,O_RDWR);
|
|
|
|
if(lvo_handler == -1)
|
|
|
|
{
|
2001-11-18 15:06:32 +00:00
|
|
|
printf("vesa_lvo: Couldn't open '%s'\n",drvname);
|
2001-11-13 17:13:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-11-29 18:00:57 +00:00
|
|
|
/* we are able to tune up this stuff depend on fourcc format */
|
|
|
|
video_out_vesa.draw_slice=vlvo_draw_slice;
|
|
|
|
video_out_vesa.draw_frame=vlvo_draw_frame;
|
|
|
|
video_out_vesa.flip_page=vlvo_flip_page;
|
|
|
|
video_out_vesa.draw_osd=vlvo_draw_osd;
|
2002-01-27 08:05:56 +00:00
|
|
|
video_out_vesa.query_format=vlvo_query_info;
|
2001-11-18 15:06:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vlvo_init(unsigned src_width,unsigned src_height,
|
|
|
|
unsigned x_org,unsigned y_org,unsigned dst_width,
|
|
|
|
unsigned dst_height,unsigned format,unsigned dest_bpp)
|
|
|
|
{
|
|
|
|
size_t i,awidth;
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_init() was called\n");
|
2001-11-13 17:13:33 +00:00
|
|
|
image_width = src_width;
|
|
|
|
image_height = src_height;
|
|
|
|
mga_vid_config.version=MGA_VID_VERSION;
|
2001-11-18 18:04:29 +00:00
|
|
|
src_format = mga_vid_config.format=format;
|
2001-11-13 17:13:33 +00:00
|
|
|
awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
|
|
|
|
switch(format){
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
image_bpp=16;
|
|
|
|
mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2;
|
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
image_bpp=16;
|
|
|
|
mga_vid_config.frame_size = awidth*src_height*2;
|
|
|
|
break;
|
|
|
|
case IMGFMT_RGB15:
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
case IMGFMT_RGB16:
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
image_bpp=16;
|
|
|
|
mga_vid_config.frame_size = awidth*src_height*2;
|
|
|
|
break;
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
image_bpp=24;
|
|
|
|
mga_vid_config.frame_size = awidth*src_height*3;
|
|
|
|
break;
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
image_bpp=32;
|
|
|
|
mga_vid_config.frame_size = awidth*src_height*4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("vesa_lvo: invalid output format %s(%0X)\n",vo_format_name(format),format);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mga_vid_config.colkey_on=0;
|
|
|
|
mga_vid_config.src_width = src_width;
|
|
|
|
mga_vid_config.src_height= src_height;
|
|
|
|
mga_vid_config.dest_width = dst_width;
|
|
|
|
mga_vid_config.dest_height= dst_height;
|
|
|
|
mga_vid_config.x_org=x_org;
|
|
|
|
mga_vid_config.y_org=y_org;
|
|
|
|
mga_vid_config.num_frames=NUM_FRAMES;
|
|
|
|
if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config))
|
|
|
|
{
|
2001-11-18 15:06:32 +00:00
|
|
|
perror("vesa_lvo: Error in mga_vid_config ioctl()");
|
|
|
|
printf("vesa_lvo: Your fb_vid driver version is incompatible with this MPlayer version!\n");
|
2001-11-13 17:13:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ioctl(lvo_handler,MGA_VID_ON,0);
|
|
|
|
|
|
|
|
frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0);
|
|
|
|
for(i=1;i<NUM_FRAMES;i++)
|
|
|
|
frames[i] = frames[i-1] + mga_vid_config.frame_size;
|
|
|
|
next_frame = 0;
|
|
|
|
lvo_mem = frames[next_frame];
|
|
|
|
|
|
|
|
/*clear the buffer*/
|
|
|
|
memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vlvo_term( void )
|
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_term() was called\n");
|
2001-11-13 17:13:33 +00:00
|
|
|
ioctl( lvo_handler,MGA_VID_OFF,0 );
|
|
|
|
munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames);
|
|
|
|
if(lvo_handler != -1) close(lvo_handler);
|
|
|
|
}
|
|
|
|
|
2001-11-27 18:36:35 +00:00
|
|
|
uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
2001-11-13 17:13:33 +00:00
|
|
|
{
|
|
|
|
uint8_t *src;
|
|
|
|
uint8_t *dest;
|
2001-11-20 10:34:00 +00:00
|
|
|
uint32_t bespitch,bespitch2;
|
2001-11-13 17:13:33 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1);
|
|
|
|
bespitch2 = bespitch/2;
|
|
|
|
|
|
|
|
dest = lvo_mem + bespitch * y + x;
|
|
|
|
src = image[0];
|
|
|
|
for(i=0;i<h;i++){
|
|
|
|
memcpy(dest,src,w);
|
|
|
|
src+=stride[0];
|
|
|
|
dest += bespitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
w/=2;h/=2;x/=2;y/=2;
|
|
|
|
|
|
|
|
dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
|
|
|
|
src = image[1];
|
|
|
|
for(i=0;i<h;i++){
|
|
|
|
memcpy(dest,src,w);
|
|
|
|
src+=stride[1];
|
|
|
|
dest += bespitch2;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = lvo_mem + bespitch*mga_vid_config.src_height
|
|
|
|
+ bespitch*mga_vid_config.src_height / 4
|
|
|
|
+ bespitch2 * y + x;
|
|
|
|
src = image[2];
|
|
|
|
for(i=0;i<h;i++){
|
|
|
|
memcpy(dest,src,w);
|
|
|
|
src+=stride[2];
|
|
|
|
dest += bespitch2;
|
|
|
|
}
|
2001-11-20 10:34:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
|
|
{
|
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_draw_slice() was called\n");
|
2001-11-27 18:36:35 +00:00
|
|
|
if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
|
2001-11-29 18:00:57 +00:00
|
|
|
vlvo_draw_slice_420(image,stride,w,h,x,y);
|
2001-11-20 10:00:58 +00:00
|
|
|
else
|
2001-11-29 18:00:57 +00:00
|
|
|
{
|
|
|
|
uint8_t *dst;
|
|
|
|
uint8_t bytpp;
|
|
|
|
bytpp = (image_bpp+7)/8;
|
|
|
|
dst = lvo_mem + (image_width * y + x)*bytpp;
|
|
|
|
/* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */
|
|
|
|
memcpy(dst,image[0],mga_vid_config.frame_size);
|
|
|
|
}
|
2001-11-16 18:43:25 +00:00
|
|
|
return 0;
|
2001-11-13 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 08:38:15 +00:00
|
|
|
uint32_t vlvo_draw_frame(uint8_t *image[])
|
2001-11-13 17:13:33 +00:00
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
/* Note it's very strange but sometime for YUY2 draw_frame is called */
|
|
|
|
memcpy(lvo_mem,image[0],mga_vid_config.frame_size);
|
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_draw_frame() was called\n");
|
|
|
|
return 0;
|
2001-11-13 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vlvo_flip_page(void)
|
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_flip_page() was called\n");
|
2001-12-02 12:21:13 +00:00
|
|
|
if(vo_doublebuffering)
|
|
|
|
{
|
2001-11-13 17:13:33 +00:00
|
|
|
ioctl(lvo_handler,MGA_VID_FSEL,&next_frame);
|
|
|
|
next_frame=(next_frame+1)%mga_vid_config.num_frames;
|
|
|
|
lvo_mem=frames[next_frame];
|
2001-12-02 12:21:13 +00:00
|
|
|
}
|
2001-11-13 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
2001-11-29 18:37:52 +00:00
|
|
|
static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
|
|
|
|
{
|
|
|
|
UNUSED(x0);
|
|
|
|
UNUSED(y0);
|
|
|
|
UNUSED(w);
|
|
|
|
UNUSED(h);
|
|
|
|
UNUSED(src);
|
|
|
|
UNUSED(srca);
|
|
|
|
UNUSED(stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
|
|
|
|
{
|
|
|
|
uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15;
|
|
|
|
switch(mga_vid_config.format){
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
case IMGFMT_RGB15:
|
|
|
|
vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
case IMGFMT_RGB16:
|
|
|
|
vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch);
|
|
|
|
break;
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
draw_alpha_null(x0,y0,w,h,src,srca,stride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-13 17:13:33 +00:00
|
|
|
void vlvo_draw_osd(void)
|
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: vlvo_draw_osd() was called\n");
|
2001-11-13 17:13:33 +00:00
|
|
|
/* TODO: hw support */
|
2001-11-29 18:37:52 +00:00
|
|
|
#if 0
|
|
|
|
/* disable this stuff until new fbvid.h interface will be implemented
|
|
|
|
because in different fourcc radeon_vid and rage128_vid have different
|
|
|
|
width alignment */
|
|
|
|
vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);
|
|
|
|
#endif
|
2001-11-13 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vlvo_query_info(uint32_t format)
|
|
|
|
{
|
2001-11-20 08:38:15 +00:00
|
|
|
if(verbose > 1) printf("vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format));
|
2001-11-13 17:13:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|