diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 7805cb22f1..edc3e9c534 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -9,6 +9,9 @@ struct config conf[]={ CONF_TYPE_PRINT, CONF_NOCFG, 0, 0}, {"vo", &video_driver, CONF_TYPE_STRING, 0, 0, 0}, {"dsp", &dsp, CONF_TYPE_STRING, 0, 0, 0}, +#ifdef HAVE_FBDEV + {"fb", &fb_dev_name, CONF_TYPE_STRING, 0, 0, 0}, +#endif {"encode", &encode_name, CONF_TYPE_STRING, 0, 0, 0}, {"font", &font_name, CONF_TYPE_STRING, 0, 0, 0}, {"ffactor", &font_factor, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 10.0}, diff --git a/configure b/configure index 04577afae7..e7bb6340aa 100755 --- a/configure +++ b/configure @@ -82,6 +82,7 @@ params: --enable-xv build with Xv render support for X 4.x [autodetect] --enable-vm build with XF86VidMode support for x11 driver --enable-x11 build with X11 render support [autodetect] + --enable-fbdev build with FBDev render support [_not_ autodetected] --enable-mlib build with MLIB support ( only Solaris ) --enable-termcap use termcap database for key codes @@ -166,6 +167,7 @@ _mlib=no _mpg123=no _xmga=no _dga=no +_fbdev=no _lirc=no _x=1 @@ -457,6 +459,9 @@ do --enable-syncfb) _syncfb=yes ;; + --enable-fbdev) + _fbdev=yes + ;; --enable-mlib) _mlib=yes ;; @@ -508,6 +513,9 @@ do --disable-dga) _dga=no ;; + --disable-fbdev) + _fbdev=no + ;; --disable-termcap) _termcap=no ;; @@ -548,6 +556,7 @@ echo "Checking for Xv ... $_xv" echo "Checking for X11 ... $_x11" echo "Checking for DGA ... $_dga" echo "Checking for Xf86VM ... $_vm" +echo "Checking for FBDev ... $_fbdev" # write conf files. if [ $_gl = yes ]; then @@ -718,6 +727,13 @@ else _dga='#undef HAVE_DGA' fi +if [ $_fbdev = yes ]; then + _fbdev='#define HAVE_FBDEV' + _vosrc=$_vosrc' vo_fbdev.c' +else + _fbdev='#undef HAVE_FBDEV' +fi + if [ $_mpg123 = yes ]; then _mpg123='#define DEFAULT_MPG123' else @@ -795,6 +811,7 @@ $_sdldef $_3dfx $_mga $_syncfb +$_fbdev #if defined(HAVE_GL)||defined(HAVE_X11)||defined(HAVE_XV) #define X11_FULLSCREEN diff --git a/libvo/video_out.c b/libvo/video_out.c index e35dbec893..79e097b5db 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -49,6 +49,7 @@ extern vo_functions_t video_out_odivx; extern vo_functions_t video_out_pgm; extern vo_functions_t video_out_md5; extern vo_functions_t video_out_syncfb; +extern vo_functions_t video_out_fbdev; vo_functions_t* video_out_drivers[] = { @@ -84,6 +85,7 @@ vo_functions_t* video_out_drivers[] = &video_out_odivx, &video_out_pgm, &video_out_md5, + &video_out_fbdev, NULL }; diff --git a/libvo/vo_fbdev.c b/libvo/vo_fbdev.c new file mode 100644 index 0000000000..88aa36a0d0 --- /dev/null +++ b/libvo/vo_fbdev.c @@ -0,0 +1,286 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "config.h" +#include "video_out.h" +#include "video_out_internal.h" + +#include "yuv2rgb.h" + +LIBVO_EXTERN(fbdev) + +//#include "yuv2rgb.h" + +static vo_info_t vo_info = { + "Framebuffer Device", + "fbdev", + "Szabolcs Berecz ", + "" +}; + +static int vt_active; +static int vt_fd; + +char *fb_dev_name = NULL; +static int fb_dev_fd; +static size_t fb_size; +static uint8_t *frame_buffer; +static int fb_bpp; + +static int in_width; +static int in_height; +static int out_width; +static int out_height; +static uint8_t *next_frame; +static int screen_width; +static uint32_t pixel_format; + +static int init_done = 0; + +static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, + uint32_t d_height, uint32_t fullscreen, char *title, + uint32_t format) +{ + int fd, vt; + char vt_name[11]; + struct vt_stat vt_state; + struct vt_mode vt_mode; + struct fb_fix_screeninfo fix_info; + struct fb_var_screeninfo var_info; + + /* get a free vt */ + if ((fd = open("/dev/tty0", O_WRONLY, 0)) == -1) { + printf("Can't open /dev/tty0: %s\n", strerror(errno)); + return 1; + } + if (ioctl(fd, VT_OPENQRY, &vt) < 0 || vt == -1) { + printf("Can't open a free VT: %s\n", strerror(errno)); + return 1; + } + close(fd); + + /* open the vt */ + snprintf(vt_name, 10, "/dev/tty%d", vt); + if ((vt_fd = open(vt_name, O_RDWR | O_NONBLOCK, 0)) == -1) { + printf("Can't open %s: %s\n", vt_name, strerror(errno)); + return 1; + } + + /* save the current vtnum */ + if (!ioctl(vt_fd, VT_GETSTATE, &vt_state)) + vt_active = vt_state.v_active; + + /* detach the controlling tty */ + if ((fd = open("/dev/tty", O_RDWR)) >= 0) { + ioctl(fd, TIOCNOTTY, 0); + close(fd); + } +#if 0 + /* switch to the new vt */ + if (ioctl(vt_fd, VT_ACTIVATE, vt_active)) + printf("ioctl VT_ACTIVATE: %s\n", strerror(errno)); + if (ioctl(vt_fd, VT_WAITACTIVE, vt_active)) + printf("ioctl VT_WAITACTIVE: %s\n", strerror(errno)); + if (ioctl(vt_fd, VT_GETMODE, &vt_mode) < 0) { + printf("ioctl VT_GETMODE: %s\n", strerror(errno)); + return 1; + } + signal(SIGUSR1, vt_request); + vt_mode.mode = VT_PROCESS; + vt_mode.relsig = SIGUSR1; + vt_mode.acqsig = SIGUSR1; + if (ioctl(vt_fd, VT_SETMODE, &vt_mode) < 0) { + printf("ioctl VT_SETMODE: %s\n", strerror(errno)); + return 1; + } +#endif + + if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) + fb_dev_name = "/dev/fb0"; + if ((fb_dev_fd = open(fb_dev_name, O_RDWR)) == -1) { + printf("Can't open %s: %s\n", fb_dev_name, strerror(errno)); + return 1; + } + if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &var_info)) { + printf("Can't get VSCREENINFO: %s\n", strerror(errno)); + return 1; + } + + if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fix_info)) { + printf("Can't get VSCREENINFO: %s\n", strerror(errno)); + return 1; + } + switch (fix_info.type) { + case FB_TYPE_VGA_PLANES: + printf("FB_TYPE_VGA_PLANES not supported.\n"); + return 1; + break; + case FB_TYPE_PLANES: + printf("FB_TYPE_PLANES not supported.\n"); + return 1; + break; + case FB_TYPE_INTERLEAVED_PLANES: + printf("FB_TYPE_INTERLEAVED_PLANES not supported.\n"); + return 1; + break; +#ifdef FB_TYPE_TEXT + case FB_TYPE_TEXT: + printf("FB_TYPE_TEXT not supported.\n"); + return 1; + break; +#endif + case FB_TYPE_PACKED_PIXELS: + /* OK */ + break; + default: + printf("unknown FB_TYPE: %d\n", fix_info.type); + return 1; + } + fb_size = fix_info.smem_len; + if ((frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) -1) { + printf("Can't mmap %s: %s\n", fb_dev_name, strerror(errno)); + return 1; + } + close(fb_dev_fd); + fb_bpp = var_info.bits_per_pixel; + screen_width = fix_info.line_length; + + printf("vo_fbdev: frame_buffer @ %p\n", frame_buffer); + printf("vo_fbdev: frame_buffer size: %d bytes\n", fb_size); + printf("vo_fbdev: bits_per_pixel: %d\n", fb_bpp); + printf("vo_fbdev: visual: %d\n", fix_info.visual); + + in_width = width; + in_height = height; + out_width = width; + out_height = height; + pixel_format = format; + if (!(next_frame = (uint8_t *) malloc(in_width * in_height * (fb_bpp / 8)))) { + printf("Can't malloc next_frame: %s\n", strerror(errno)); + return 1; + } + + if (format == IMGFMT_YV12) + yuv2rgb_init(fb_bpp, MODE_RGB); + init_done = 1; + return 0; +} + +static uint32_t query_format(uint32_t format) +{ + if (format == IMGFMT_YV12) + return 1; + if (format == IMGFMT_RGB32 && fb_bpp == 32) + return 1; + switch (format) { + case IMGFMT_YV12: + return 1; + case IMGFMT_RGB32: + if (fb_bpp == 32) + return 1; + break; + case IMGFMT_RGB24: + if (fb_bpp == 24) + return 1; + break; + case IMGFMT_RGB16: + if (fb_bpp == 16) + return 1; + break; + case IMGFMT_RGB15: + if (fb_bpp == 15) + return 1; + break; + } + return 0; +} + +static const vo_info_t *get_info(void) +{ + return &vo_info; +} + +static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + int x, y; + uint8_t *dst; + + if (pixel_format == IMGFMT_YV12) { + for (y = 0; y < h; y++){ + dst = next_frame + (in_width * (y0 + y) + x0) * (fb_bpp / 8); + for (x = 0; x < w; x++) { + if (srca[x]) { + dst[0] = (dst[0]*(srca[x]^255)+src[x]*(srca[x]))>>8; + dst[1] = (dst[1]*(srca[x]^255)+src[x]*(srca[x]))>>8; + dst[2] = (dst[2]*(srca[x]^255)+src[x]*(srca[x]))>>8; + } + dst += fb_bpp / 8; + } + src += stride; + srca += stride; + } + } +} + +static uint32_t draw_frame(uint8_t *src[]) +{ + if (pixel_format == IMGFMT_YV12) { + yuv2rgb(next_frame, src[0], src[1], src[2], in_width, + in_height, in_width * (fb_bpp / 8), + in_width, in_width / 2); + } else { + int i; + for (i = 0; i < in_height; i++) + memcpy(next_frame, src[0], in_width * (fb_bpp / 8)); + } + return 0; +} + +static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, int x, + int y) +{ + uint8_t *dest; + + dest = next_frame + (in_width * y + x) * (fb_bpp / 8); + yuv2rgb(dest, src[0], src[1], src[2], w, h, in_width * (fb_bpp / 8), + stride[0], stride[1]); + return 0; +} + +static void check_events(void) +{ +} + +static void flip_page(void) +{ + int i, out_offset = 0, in_offset = 0; + + vo_draw_text(in_width, in_height, draw_alpha); + check_events(); + for (i = 0; i < in_height; i++) { + memcpy(frame_buffer + out_offset, next_frame + in_offset, + in_width * (fb_bpp / 8)); + out_offset += screen_width; + in_offset += in_width * (fb_bpp / 8); + } +} + +static void uninit(void) +{ + if (vt_active >= 0) + ioctl(vt_fd, VT_ACTIVATE, vt_active); + printf("vo_fbdev: uninit\n"); + free(next_frame); + munmap(frame_buffer, fb_size); +} diff --git a/mplayer.c b/mplayer.c index 24b2cd1efd..b556971ef5 100644 --- a/mplayer.c +++ b/mplayer.c @@ -72,6 +72,8 @@ XMM xmm; XMM_PluginSound *pSound=NULL; #endif +extern char *fb_dev_name; + extern int vo_screenwidth; extern char* win32_codec_name; // must be set before calling DrvOpen() !!! @@ -1931,7 +1933,6 @@ switch(has_video){ --osd_visible; if(!osd_visible) vo_osd_progbar_type=-1; // disable } - } // while(v_frame