mga.c 10.6 KB
Newer Older
1 2 3
/*****************************************************************************
 * mga.c : Matrox Graphic Array plugin for vlc
 *****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
4
 * Copyright (C) 2000, 2001 VideoLAN
Sam Hocevar's avatar
 
Sam Hocevar committed
5
 * $Id: mga.c,v 1.10 2002/01/05 03:49:18 sam Exp $
6
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
7 8
 * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *          Samuel Hocevar <sam@zoy.org>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * This program 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.
 * 
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
28 29 30 31 32 33 34
#include <errno.h>                                                 /* ENOMEM */
#include <unistd.h>                                               /* close() */
#include <stdlib.h>                                                /* free() */
#include <string.h>                                            /* strerror() */
#include <fcntl.h>                                                 /* open() */
#include <sys/ioctl.h>                                            /* ioctl() */
#include <sys/mman.h>                                          /* PROT_WRITE */
35

Sam Hocevar's avatar
 
Sam Hocevar committed
36
#include <videolan/vlc.h>
37

Sam Hocevar's avatar
 
Sam Hocevar committed
38 39 40 41
#ifdef SYS_BSD
#include <sys/types.h>                                     /* typedef ushort */
#endif

42 43 44
#include "video.h"
#include "video_output.h"

Sam Hocevar's avatar
 
Sam Hocevar committed
45 46
/*****************************************************************************
 * Capabilities defined in the other files.
Sam Hocevar's avatar
 
Sam Hocevar committed
47
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
48 49 50 51 52 53 54 55 56 57
static void vout_getfunctions( function_list_t * p_function_list );

static int  vout_Probe     ( probedata_t *p_data );
static int  vout_Create    ( vout_thread_t * );
static int  vout_Init      ( vout_thread_t * );
static void vout_End       ( vout_thread_t * );
static void vout_Destroy   ( vout_thread_t * );
static int  vout_Manage    ( vout_thread_t * );
static void vout_Render    ( vout_thread_t *, picture_t * );
static void vout_Display   ( vout_thread_t *, picture_t * );
58 59

/*****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
60
 * Building configuration tree
61
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
62 63
MODULE_CONFIG_START
MODULE_CONFIG_STOP
64

Sam Hocevar's avatar
 
Sam Hocevar committed
65
MODULE_INIT_START
Sam Hocevar's avatar
 
Sam Hocevar committed
66 67 68
    SET_DESCRIPTION( "Matrox Graphic Array video module" )
    ADD_CAPABILITY( VOUT, 10 )
    ADD_SHORTCUT( "mga" )
Sam Hocevar's avatar
 
Sam Hocevar committed
69
MODULE_INIT_STOP
70

Sam Hocevar's avatar
 
Sam Hocevar committed
71
MODULE_ACTIVATE_START
Sam Hocevar's avatar
 
Sam Hocevar committed
72
    vout_getfunctions( &p_module->p_functions->vout );
Sam Hocevar's avatar
 
Sam Hocevar committed
73
MODULE_ACTIVATE_STOP
Sam Hocevar's avatar
 
Sam Hocevar committed
74

Sam Hocevar's avatar
 
Sam Hocevar committed
75 76
MODULE_DEACTIVATE_START
MODULE_DEACTIVATE_STOP
77

Sam Hocevar's avatar
 
Sam Hocevar committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
/*****************************************************************************
 * vout_sys_t: video output MGA method descriptor
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
 * It describes the MGA specific properties of an output thread.
 *****************************************************************************/
#ifndef __LINUX_MGAVID_H
#   define __LINUX_MGAVID_H
#   define MGA_VID_CONFIG _IOR('J', 1, mga_vid_config_t)
#   define MGA_VID_ON     _IO ('J', 2)
#   define MGA_VID_OFF    _IO ('J', 3)
#   define MGA_G200 0x1234
#   define MGA_G400 0x5678
typedef struct mga_vid_config_s
{
    u32     card_type;
    u32     ram_size;
    u32     src_width;
    u32     src_height;
    u32     dest_width;
    u32     dest_height;
    u32     x_org;
    u32     y_org;
    u8      colkey_on;
    u8      colkey_red;
    u8      colkey_green;
    u8      colkey_blue;
} mga_vid_config_t;
#endif

typedef struct vout_sys_s
{
    /* MGA specific variables */
    int                 i_fd;
    int                 i_size;
    mga_vid_config_t    mga;
    byte_t *            p_mga_vid_base;
    boolean_t           b_g400;

} vout_sys_t;

#define DUMMY_WIDTH 16
#define DUMMY_HEIGHT 16
#define DUMMY_BITS_PER_PLANE 16
#define DUMMY_BYTES_PER_PIXEL 2

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
/*****************************************************************************
 * Functions exported as capabilities. They are declared as static so that
 * we don't pollute the namespace too much.
 *****************************************************************************/
static void vout_getfunctions( function_list_t * p_function_list )
{
    p_function_list->pf_probe = vout_Probe;
    p_function_list->functions.vout.pf_create     = vout_Create;
    p_function_list->functions.vout.pf_init       = vout_Init;
    p_function_list->functions.vout.pf_end        = vout_End;
    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
    p_function_list->functions.vout.pf_manage     = vout_Manage;
    p_function_list->functions.vout.pf_render     = vout_Render;
    p_function_list->functions.vout.pf_display    = vout_Display;
}

/*****************************************************************************
 * intf_Probe: return a score
 *****************************************************************************/
static int vout_Probe( probedata_t *p_data )
{
    int i_fd;

    i_fd = open( "/dev/mga_vid", O_RDWR );

    if( i_fd == -1 )
    {
        return 0;
    }

    close( i_fd );

    return 10;
}

/*****************************************************************************
 * vout_Create: allocates dummy video thread output method
 *****************************************************************************
 * This function allocates and initializes a dummy vout method.
 *****************************************************************************/
static int vout_Create( vout_thread_t *p_vout )
{
    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
        intf_ErrMsg("vout error: %s", strerror(ENOMEM) );
        return( 1 );
    }

    if( (p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR )) == -1 )
    {
        intf_ErrMsg( "vout error: can't open MGA driver /dev/mga_vid" );
        free( p_vout->p_sys );
        return( 1 );
    }

    return( 0 );
}

/*****************************************************************************
 * vout_Init: initialize dummy video thread output method
 *****************************************************************************/
static int vout_Init( vout_thread_t *p_vout )
{
    /* create the MGA output */
    p_vout->output.i_width = p_vout->render.i_width;
    p_vout->output.i_height = p_vout->render.i_height;
    p_vout->output.i_aspect = p_vout->render.i_aspect;

    /* FIXME: we should initialize these ones according to the streams */
    p_vout->p_sys->mga.src_width = p_vout->output.i_width;
    p_vout->p_sys->mga.src_height = p_vout->output.i_height;
    p_vout->p_sys->mga.dest_width = 900;
    p_vout->p_sys->mga.dest_height = 700;
    p_vout->p_sys->mga.x_org = 50;
    p_vout->p_sys->mga.y_org = 50;
    p_vout->p_sys->mga.colkey_on = 0;

    if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) )
    {
        intf_ErrMsg( "vout error: MGA config ioctl failed" );
    }

    if( p_vout->p_sys->mga.card_type == MGA_G200 )
    {
        intf_Msg( "vout: detected MGA G200 (%d MB Ram)",
                  p_vout->p_sys->mga.ram_size );
        p_vout->p_sys->b_g400 = 0;
    }
    else
    {
        intf_Msg( "vout: detected MGA G400 (%d MB Ram)",
                  p_vout->p_sys->mga.ram_size );
        p_vout->p_sys->b_g400 = 1;
    }

    ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );

    p_vout->p_sys->i_size = ( (p_vout->p_sys->mga.src_width + 31) & ~31 )
                             * p_vout->p_sys->mga.src_height;

    p_vout->p_sys->p_mga_vid_base = mmap( 0, p_vout->p_sys->i_size
                                             + p_vout->p_sys->i_size / 2,
                                          PROT_WRITE, MAP_SHARED,
                                          p_vout->p_sys->i_fd, 0 );

    memset( p_vout->p_sys->p_mga_vid_base,
            0x00, p_vout->p_sys->i_size );

    memset( p_vout->p_sys->p_mga_vid_base + p_vout->p_sys->i_size,
            0x80, p_vout->p_sys->i_size / 2 );

    return( 0 );
}

/*****************************************************************************
 * vout_End: terminate dummy video thread output method
 *****************************************************************************/
static void vout_End( vout_thread_t *p_vout )
{
    ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );
}

/*****************************************************************************
 * vout_Destroy: destroy dummy video thread output method
 *****************************************************************************
 * Terminate an output method created by DummyCreateOutputMethod
 *****************************************************************************/
static void vout_Destroy( vout_thread_t *p_vout )
{
    close( p_vout->p_sys->i_fd );

    free( p_vout->p_sys );
}

/*****************************************************************************
 * vout_Manage: handle dummy events
 *****************************************************************************
 * This function should be called regularly by video output thread. It manages
 * console events. It returns a non null value on error.
 *****************************************************************************/
static int vout_Manage( vout_thread_t *p_vout )
{
    return( 0 );
}

/*****************************************************************************
 * vout_Render: displays previously calculated output
 *****************************************************************************/
static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
{
    ;
}

/*****************************************************************************
 * vout_Display: displays previously rendered output
 *****************************************************************************/
static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
{
    ;
}