2008-08-03 20:04:03 +00:00
|
|
|
/*
|
|
|
|
* Video driver for Nintendo Wii/GameCube Framebuffer device
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Jing Liu <fatersh-1@yahoo.com>
|
|
|
|
*
|
|
|
|
* Maintainer: Benjamin Zores <ben@geexbox.org>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This driver handles dedicated ATI GPU, which can be found in:
|
|
|
|
* - Nintendo GameCube (ATI LSI Flipper @ 162 MHz)
|
|
|
|
* - Nintendo Wii (ATI Hollywood @ 243 MHz)
|
|
|
|
*
|
|
|
|
* Flipper and Hollywood chipsets are pretty similar, except from clock speed:
|
|
|
|
* - Embedded framebuffer is 2MB.
|
|
|
|
* - Texture cache is 1MB.
|
|
|
|
* - Vertex cache is 0.1 MB.
|
|
|
|
* - Framebuffer is YUY2, not RGB.
|
|
|
|
* - Best resolution is 480p (854x480)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/kd.h>
|
|
|
|
#include <linux/fb.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
|
|
|
#include "sub.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
static const vo_info_t info = {
|
|
|
|
"Nintendo Wii/GameCube Framebuffer Device",
|
|
|
|
"wii",
|
|
|
|
"Jing Liu <fartersh-1@yahoo.com>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBVO_EXTERN(wii)
|
|
|
|
|
|
|
|
static signed int pre_init_err = -2;
|
|
|
|
|
2008-11-23 14:57:51 +00:00
|
|
|
static char *fb_dev_name = NULL;
|
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
static FILE *vt_fp = NULL;
|
|
|
|
static int vt_doit = 1;
|
2008-11-24 14:35:08 +00:00
|
|
|
|
2008-11-24 14:44:09 +00:00
|
|
|
static int fb_dev_fd;
|
2008-08-03 20:04:03 +00:00
|
|
|
static int fb_tty_fd = -1;
|
2008-11-23 12:08:18 +00:00
|
|
|
static size_t fb_size;
|
2008-08-03 20:04:03 +00:00
|
|
|
static uint8_t *frame_buffer;
|
|
|
|
static uint8_t *center;
|
|
|
|
static struct fb_var_screeninfo fb_orig_vinfo;
|
|
|
|
static struct fb_var_screeninfo fb_vinfo;
|
2008-11-23 14:15:54 +00:00
|
|
|
static int fb_pixel_size; // 32: 4 24: 3 16: 2 15: 2
|
2008-08-03 20:04:03 +00:00
|
|
|
static int fb_line_len;
|
2008-11-23 12:08:18 +00:00
|
|
|
static int in_width;
|
|
|
|
static int in_height;
|
|
|
|
static int out_width;
|
|
|
|
static int out_height;
|
2008-08-03 20:04:03 +00:00
|
|
|
static int fs;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
static int fb_preinit(int reset)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
static int fb_preinit_done = 0;
|
|
|
|
static int fb_works = 0;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (reset) {
|
2008-08-03 20:04:03 +00:00
|
|
|
fb_preinit_done = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fb_preinit_done)
|
|
|
|
return fb_works;
|
|
|
|
|
2008-11-23 14:57:51 +00:00
|
|
|
if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER")))
|
|
|
|
fb_dev_name = strdup("/dev/fb0");
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "using %s\n", fb_dev_name);
|
|
|
|
|
|
|
|
if ((fb_dev_fd = open(fb_dev_name, O_RDWR)) == -1) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't open %s: %s\n", fb_dev_name, strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo)) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't get VSCREENINFO: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
goto err_out_fd;
|
|
|
|
}
|
|
|
|
fb_orig_vinfo = fb_vinfo;
|
|
|
|
|
2008-11-23 13:55:23 +00:00
|
|
|
if ((fb_tty_fd = open("/dev/tty", O_RDWR)) < 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "notice: Can't open /dev/tty: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
goto err_out_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
fb_preinit_done = 1;
|
|
|
|
fb_works = 1;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
err_out_fd:
|
2008-11-23 13:19:43 +00:00
|
|
|
close(fb_dev_fd);
|
2008-08-03 20:04:03 +00:00
|
|
|
fb_dev_fd = -1;
|
|
|
|
err_out:
|
|
|
|
fb_preinit_done = 1;
|
|
|
|
fb_works = 0;
|
2008-11-23 12:08:18 +00:00
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void vt_set_textarea(int u, int l)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
/* how can I determine the font height?
|
|
|
|
* just use 16 for now
|
|
|
|
*/
|
|
|
|
int urow = ((u + 15) / 16) + 1;
|
|
|
|
int lrow = l / 16;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "vt_set_textarea(%d, %d): %d,%d\n", u, l, urow, lrow);
|
2008-08-03 20:04:03 +00:00
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
if (vt_fp) {
|
2008-11-23 13:19:43 +00:00
|
|
|
fprintf(vt_fp, "\33[%d;%dr\33[%d;%dH", urow, lrow, lrow, 0);
|
|
|
|
fflush(vt_fp);
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int config(uint32_t width, uint32_t height, uint32_t d_width,
|
|
|
|
uint32_t d_height, uint32_t flags, char *title,
|
|
|
|
uint32_t format)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
struct fb_fix_screeninfo fb_finfo;
|
|
|
|
uint32_t black = 0x00800080;
|
|
|
|
long temp;
|
|
|
|
int vt_fd;
|
2008-11-23 12:08:18 +00:00
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
fs = flags & VOFLAG_FULLSCREEN;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (pre_init_err == -2) {
|
2008-11-23 12:08:18 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Internal fatal error: config() was called before preinit()\n");
|
2008-08-03 20:04:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pre_init_err)
|
|
|
|
return 1;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
in_width = width;
|
2008-08-03 20:04:03 +00:00
|
|
|
in_height = height;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
out_width = (d_width && fs) ? d_width : width;
|
2008-08-03 20:04:03 +00:00
|
|
|
out_height = (d_width && fs) ? d_height : height;
|
|
|
|
|
|
|
|
fb_vinfo.xres_virtual = fb_vinfo.xres;
|
|
|
|
fb_vinfo.yres_virtual = fb_vinfo.yres;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (fb_tty_fd >= 0 && ioctl(fb_tty_fd, KDSETMODE, KD_GRAPHICS) < 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "Can't set graphics mode: %s\n", strerror(errno));
|
|
|
|
close(fb_tty_fd);
|
2008-08-03 20:04:03 +00:00
|
|
|
fb_tty_fd = -1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo)) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't put VSCREENINFO: %s\n", strerror(errno));
|
|
|
|
if (fb_tty_fd >= 0 && ioctl(fb_tty_fd, KDSETMODE, KD_TEXT) < 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't restore text mode: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 14:15:54 +00:00
|
|
|
fb_pixel_size = 2;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (fs) {
|
|
|
|
out_width = fb_vinfo.xres;
|
2008-08-03 20:04:03 +00:00
|
|
|
out_height = fb_vinfo.yres;
|
|
|
|
}
|
2008-11-23 12:08:18 +00:00
|
|
|
if (out_width < in_width || out_height < in_height) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "screensize is smaller than video size\n");
|
2008-08-03 20:04:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't get FSCREENINFO: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "type %d not supported\n", fb_finfo.type);
|
2008-08-03 20:04:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fb_line_len = fb_finfo.line_length;
|
2008-11-23 13:19:43 +00:00
|
|
|
fb_size = fb_finfo.smem_len;
|
2008-11-24 08:40:11 +00:00
|
|
|
|
|
|
|
frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED, fb_dev_fd, 0);
|
|
|
|
if (frame_buffer == (uint8_t *) -1) {
|
2008-11-23 14:57:51 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "Can't mmap %s: %s\n", fb_dev_name, strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
center = frame_buffer +
|
2008-11-23 14:15:54 +00:00
|
|
|
((out_width - in_width) / 2) * fb_pixel_size +
|
2008-08-03 20:04:03 +00:00
|
|
|
((out_height - in_height) / 2) * fb_line_len;
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "frame_buffer @ %p\n", frame_buffer);
|
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "center @ %p\n", center);
|
2008-11-23 14:15:54 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "pixel per line: %d\n", fb_line_len / fb_pixel_size);
|
2008-08-03 20:04:03 +00:00
|
|
|
|
|
|
|
/* blanking screen */
|
|
|
|
for (temp = 0; temp < fb_size; temp += 4)
|
2008-11-23 13:19:43 +00:00
|
|
|
memcpy(frame_buffer + temp, (void *) &black, 4);
|
2008-08-03 20:04:03 +00:00
|
|
|
|
2008-11-23 13:55:23 +00:00
|
|
|
if (vt_doit && (vt_fd = open("/dev/tty", O_WRONLY)) == -1) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "can't open /dev/tty: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
vt_doit = 0;
|
|
|
|
}
|
2008-11-23 13:42:41 +00:00
|
|
|
if (vt_doit && !(vt_fp = fdopen(vt_fd, "w"))) {
|
2008-11-23 13:55:23 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "can't fdopen /dev/tty: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
vt_doit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vt_doit)
|
2008-11-23 13:19:43 +00:00
|
|
|
vt_set_textarea((out_height + in_height) / 2, fb_vinfo.yres);
|
2008-08-03 20:04:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int query_format(uint32_t format)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
2008-11-23 13:23:14 +00:00
|
|
|
if (!fb_preinit(0))
|
2008-08-03 20:04:03 +00:00
|
|
|
return 0;
|
2008-11-23 12:08:18 +00:00
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
if (format != IMGFMT_YUY2)
|
|
|
|
return 0;
|
2008-11-23 12:08:18 +00:00
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
return VFCAP_ACCEPT_STRIDE | VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|
|
|
unsigned char *srca, int stride)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
unsigned char *dst;
|
|
|
|
|
2008-11-23 14:15:54 +00:00
|
|
|
dst = center + fb_line_len * y0 + fb_pixel_size * x0;
|
|
|
|
|
2008-11-23 13:19:43 +00:00
|
|
|
vo_draw_alpha_yuy2(w, h, src, srca, stride, dst, fb_line_len);
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int draw_frame(uint8_t *src[])
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
uint8_t *d, *s;
|
|
|
|
|
2008-11-23 14:15:54 +00:00
|
|
|
d = center + fb_line_len * y + fb_pixel_size * x;
|
|
|
|
|
2008-08-03 20:04:03 +00:00
|
|
|
s = src[0];
|
2008-11-23 12:08:18 +00:00
|
|
|
while (h) {
|
2008-11-23 14:15:54 +00:00
|
|
|
memcpy(d, s, w * fb_pixel_size);
|
2008-08-03 20:04:03 +00:00
|
|
|
d += fb_line_len;
|
|
|
|
s += stride[0];
|
|
|
|
h--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void check_events(void)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void flip_page(void)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void draw_osd(void)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
2008-11-23 13:19:43 +00:00
|
|
|
vo_draw_text(in_width, in_height, draw_alpha);
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static void uninit(void)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo))
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
fb_orig_vinfo.xoffset = fb_vinfo.xoffset;
|
|
|
|
fb_orig_vinfo.yoffset = fb_vinfo.yoffset;
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_orig_vinfo))
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "Can't reset original fb_var_screeninfo: %s\n", strerror(errno));
|
2008-11-23 12:08:18 +00:00
|
|
|
if (fb_tty_fd >= 0) {
|
2008-11-23 13:19:43 +00:00
|
|
|
if (ioctl(fb_tty_fd, KDSETMODE, KD_TEXT) < 0)
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "Can't restore text mode: %s\n", strerror(errno));
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
if (vt_doit)
|
2008-11-23 13:19:43 +00:00
|
|
|
vt_set_textarea(0, fb_orig_vinfo.yres);
|
|
|
|
close(fb_tty_fd);
|
|
|
|
close(fb_dev_fd);
|
2008-08-03 20:04:03 +00:00
|
|
|
if (frame_buffer)
|
2008-11-23 13:19:43 +00:00
|
|
|
munmap(frame_buffer, fb_size);
|
2008-08-03 20:04:03 +00:00
|
|
|
frame_buffer = NULL;
|
2008-11-23 13:19:43 +00:00
|
|
|
fb_preinit(1);
|
2008-08-03 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int preinit(const char *vo_subdevice)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
pre_init_err = 0;
|
|
|
|
|
|
|
|
if (!pre_init_err)
|
2008-11-23 13:19:43 +00:00
|
|
|
return pre_init_err = (fb_preinit(0) ? 0 : -1);
|
2008-08-03 20:04:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static uint32_t get_image(mp_image_t *mpi)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
if (((mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
|
|
|
|
(mpi->flags & MP_IMGFLAG_PLANAR) ||
|
|
|
|
(mpi->flags & MP_IMGFLAG_YUV) ||
|
|
|
|
(mpi->width != in_width) ||
|
2008-11-23 13:19:43 +00:00
|
|
|
(mpi->height != in_height)
|
|
|
|
)
|
2008-08-03 20:04:03 +00:00
|
|
|
return VO_FALSE;
|
|
|
|
|
|
|
|
mpi->planes[0] = center;
|
|
|
|
mpi->stride[0] = fb_line_len;
|
|
|
|
mpi->flags |= MP_IMGFLAG_DIRECT;
|
|
|
|
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-23 12:08:18 +00:00
|
|
|
static int control(uint32_t request, void *data, ...)
|
2008-08-03 20:04:03 +00:00
|
|
|
{
|
|
|
|
if (request == VOCTRL_GET_IMAGE)
|
2008-11-23 13:19:43 +00:00
|
|
|
return get_image(data);
|
2008-08-03 20:04:03 +00:00
|
|
|
else if (request == VOCTRL_QUERY_FORMAT)
|
2008-11-23 13:19:43 +00:00
|
|
|
return query_format(*((uint32_t*) data));
|
2008-08-03 20:04:03 +00:00
|
|
|
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|