Commit 293e5623 authored by Laurent Aimar's avatar Laurent Aimar

Converted vout aa to "vout display" API.

parent d070cdeb
/***************************************************************************** /*****************************************************************************
* vout_aa.c: Aa video output display method for testing purposes * aa.c: "vout display" module using aalib
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2009 the VideoLAN team * Copyright (C) 2002-2009 the VideoLAN team
* $Id$ * $Id$
...@@ -28,227 +28,289 @@ ...@@ -28,227 +28,289 @@
# include "config.h" # include "config.h"
#endif #endif
#include <aalib.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_vout.h> #include <vlc_vout_display.h>
#include <vlc_picture_pool.h>
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * );
static int Init ( vout_thread_t * ); #include <assert.h>
static void End ( vout_thread_t * ); #include <aalib.h>
static int Manage ( vout_thread_t * );
static void Render ( vout_thread_t *, picture_t * );
static void Display ( vout_thread_t *, picture_t * );
static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
/* TODO
* - what about RGB palette ?
*/
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
vlc_module_begin () static int Open (vlc_object_t *);
set_shortname( N_("ASCII Art")) static void Close(vlc_object_t *);
set_category( CAT_VIDEO )
set_subcategory( SUBCAT_VIDEO_VOUT ) vlc_module_begin()
set_description( N_("ASCII-art video output") ) set_shortname(N_("ASCII Art"))
set_capability( "video output", 10 ) set_category(CAT_VIDEO)
add_shortcut( "aalib" ) set_subcategory(SUBCAT_VIDEO_VOUT)
set_callbacks( Create, Destroy ) set_description(N_("ASCII-art video output"))
vlc_module_end () set_capability("vout display", 10)
add_shortcut("aalib")
set_callbacks(Open, Close)
vlc_module_end()
/***************************************************************************** /*****************************************************************************
* vout_sys_t: aa video output method descriptor * Local prototypes
*****************************************************************************
* This structure is part of the video output thread descriptor.
* It describes the aa specific properties of an output thread.
*****************************************************************************/ *****************************************************************************/
struct vout_sys_t static picture_t *Get (vout_display_t *);
{ static void Prepare(vout_display_t *, picture_t *);
static void Display(vout_display_t *, picture_t *);
static int Control(vout_display_t *, int, va_list);
/* */
static void Manage(vout_display_t *);
/* */
struct vout_display_sys_t {
struct aa_context* aa_context; struct aa_context* aa_context;
aa_palette palette; aa_palette palette;
int i_width; /* width of main window */
int i_height; /* height of main window */ vout_display_cfg_t state;
picture_pool_t *pool;
}; };
/***************************************************************************** /**
* Create: allocates aa video thread output method
*****************************************************************************
* This function allocates and initializes a aa vout method. * This function allocates and initializes a aa vout method.
*****************************************************************************/ */
static int Create( vlc_object_t *p_this ) static int Open(vlc_object_t *object)
{ {
vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_display_t *vd = (vout_display_t *)object;
vout_display_sys_t *sys;
/* Allocate structure */ /* Allocate structure */
p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); vd->sys = sys = calloc(1, sizeof(*sys));
if( p_vout->p_sys == NULL ) if (!sys)
return VLC_ENOMEM; return VLC_ENOMEM;
/* Don't parse any options, but take $AAOPTS into account */ /* Don't parse any options, but take $AAOPTS into account */
aa_parseoptions( NULL, NULL, NULL, NULL ); aa_parseoptions(NULL, NULL, NULL, NULL);
if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams))) /* */
{ sys->aa_context = aa_autoinit(&aa_defparams);
msg_Err( p_vout, "cannot initialize aalib" ); if (!sys->aa_context) {
free( p_vout->p_sys ); msg_Err(vd, "cannot initialize aalib");
return VLC_EGENERIC; goto error;
} }
p_vout->pf_init = Init; aa_autoinitkbd(sys->aa_context, 0);
p_vout->pf_end = End; aa_autoinitmouse(sys->aa_context, AA_MOUSEALLMASK);
p_vout->pf_manage = Manage;
p_vout->pf_render = Render;
p_vout->pf_display = Display;
p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
aa_hidemouse( p_vout->p_sys->aa_context );
return VLC_SUCCESS;
}
/***************************************************************************** /* */
* Init: initialize aa video thread output method video_format_t fmt = vd->fmt;
*****************************************************************************/ fmt.i_chroma = VLC_CODEC_RGB8;
static int Init( vout_thread_t *p_vout ) fmt.i_width = aa_imgwidth(sys->aa_context);
{ fmt.i_height = aa_imgheight(sys->aa_context);
int i_index;
picture_t *p_pic = NULL;
I_OUTPUTPICTURES = 0;
p_vout->output.i_chroma = VLC_CODEC_RGB8;
p_vout->output.i_width = p_vout->p_sys->i_width;
p_vout->output.i_height = p_vout->p_sys->i_height;
p_vout->output.i_aspect = p_vout->p_sys->i_width
* VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
p_vout->output.pf_setpalette = SetPalette;
/* Find an empty picture slot */
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
{
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
{
p_pic = p_vout->p_picture + i_index;
break;
}
}
if( p_pic == NULL ) /* */
return VLC_EGENERIC; vout_display_info_t info = vd->info;
info.has_pictures_invalid = true;
/* Allocate the picture */ /* Setup vout_display now that everything is fine */
p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context ); vd->fmt = fmt;
p_pic->p->i_lines = p_vout->p_sys->i_height; vd->info = info;
p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
p_pic->p->i_pitch = p_vout->p_sys->i_width;
p_pic->p->i_pixel_pitch = 1;
p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
p_pic->i_planes = 1;
p_pic->i_status = DESTROYED_PICTURE; vd->get = Get;
p_pic->i_type = DIRECT_PICTURE; vd->prepare = Prepare;
vd->display = Display;
vd->control = Control;
vd->manage = Manage;
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; /* Inspect initial configuration and send correction events
I_OUTPUTPICTURES++; * FIXME how to handle aspect ratio with aa ? */
sys->state = *vd->cfg;
sys->state.is_fullscreen = false;
vout_display_SendEventFullscreen(vd, false);
vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
return VLC_SUCCESS; return VLC_SUCCESS;
error:
if (sys && sys->aa_context)
aa_close(sys->aa_context);
free(sys);
return VLC_EGENERIC;
} }
/***************************************************************************** /**
* End: terminate aa video thread output method * Close a aa video output method
*****************************************************************************/ */
static void End( vout_thread_t *p_vout ) static void Close(vlc_object_t *object)
{ {
; vout_display_t *vd = (vout_display_t *)object;
vout_display_sys_t *sys = vd->sys;
if (sys->pool)
picture_pool_Delete(sys->pool);
aa_close(sys->aa_context);
free(sys);
} }
/***************************************************************************** /**
* Destroy: destroy aa video thread output method * Return a direct buffer
***************************************************************************** */
* Terminate an output method created by AaCreateOutputMethod static picture_t *Get(vout_display_t *vd)
*****************************************************************************/
static void Destroy( vlc_object_t *p_this )
{ {
vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_display_sys_t *sys = vd->sys;
if (!sys->pool) {
picture_resource_t rsc;
memset(&rsc, 0, sizeof(rsc));
rsc.p[0].p_pixels = aa_image(sys->aa_context);
rsc.p[0].i_pitch = aa_imgwidth(sys->aa_context);
rsc.p[0].i_lines = aa_imgheight(sys->aa_context);
aa_close( p_vout->p_sys->aa_context ); picture_t *p_picture = picture_NewFromResource(&vd->fmt, &rsc);
free( p_vout->p_sys ); if (!p_picture)
return NULL;
sys->pool = picture_pool_New(1, &p_picture);
if (!sys->pool)
return NULL;
}
return picture_pool_Get(sys->pool);
} }
/***************************************************************************** /**
* Manage: handle aa events * Prepare a picture for display */
***************************************************************************** static void Prepare(vout_display_t *vd, picture_t *picture)
* This function should be called regularly by video output thread. It manages
* console events. It returns a non null value on error.
*****************************************************************************/
static int Manage( vout_thread_t *p_vout )
{ {
int event, x, y, b; vout_display_sys_t *sys = vd->sys;
event = aa_getevent( p_vout->p_sys->aa_context, 0 );
switch ( event ) assert(vd->fmt.i_width == aa_imgwidth(sys->aa_context) &&
{ vd->fmt.i_height == aa_imgheight(sys->aa_context));
case AA_MOUSE:
aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b ); #if 0
if ( b & AA_BUTTON3 ) if (picture->format.p_palette) {
var_SetBool( p_vout->p_libvlc, "intf-popupmenu", true ); for (int i = 0; i < 256; i++) {
break; aa_setpalette(vd->sys->palette, 256 - i,
case AA_RESIZE: red[ i ], green[ i ], blue[ i ]);
p_vout->i_changes |= VOUT_SIZE_CHANGE;
aa_resize( p_vout->p_sys->aa_context );
p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
break;
default:
break;
} }
return VLC_SUCCESS; }
#endif
aa_fastrender(sys->aa_context, 0, 0,
vd->fmt.i_width, vd->fmt.i_height);
} }
/***************************************************************************** /**
* Render: render previously calculated output * Display a picture
*****************************************************************************/ */
static void Render( vout_thread_t *p_vout, picture_t *p_pic ) static void Display(vout_display_t *vd, picture_t *picture)
{ {
aa_fastrender( p_vout->p_sys->aa_context, 0, 0, vout_display_sys_t *sys = vd->sys;
aa_imgwidth( p_vout->p_sys->aa_context ),
aa_imgheight( p_vout->p_sys->aa_context ) ); aa_flush(sys->aa_context);
picture_Release(picture);
} }
/***************************************************************************** /**
* Display: displays previously rendered output * Control for vout display
*****************************************************************************/ */
static void Display( vout_thread_t *p_vout, picture_t *p_pic ) static int Control(vout_display_t *vd, int query, va_list args)
{ {
/* No need to do anything, the fake direct buffers stay as they are */ vout_display_sys_t *sys = vd->sys;
unsigned int i_width, i_height, i_x, i_y;
switch (query) {
case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
/* We have to ignore what is requested */
vout_display_SendEventPicturesInvalid(vd);
return VLC_SUCCESS;
case VOUT_DISPLAY_RESET_PICTURES:
if (sys->pool)
picture_pool_Delete(sys->pool);
sys->pool = NULL;
vd->fmt.i_width = aa_imgwidth(sys->aa_context);
vd->fmt.i_height = aa_imgheight(sys->aa_context);
return VLC_SUCCESS;
vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height, case VOUT_DISPLAY_HIDE_MOUSE:
&i_x, &i_y, &i_width, &i_height ); aa_hidemouse(sys->aa_context);
return VLC_SUCCESS;
aa_flush(p_vout->p_sys->aa_context); default:
msg_Err(vd, "Unsupported query in vout display aalib");
return VLC_EGENERIC;
}
} }
/*****************************************************************************
* SetPalette: set the 8bpp palette /**
*****************************************************************************/ * Proccess pending event
static void SetPalette( vout_thread_t *p_vout, */
uint16_t *red, uint16_t *green, uint16_t *blue ) static void Manage(vout_display_t *vd)
{ {
int i; vout_display_sys_t *sys = vd->sys;
for (;;) {
const int event = aa_getevent(sys->aa_context, 0);
if (!event)
return;
switch (event) {
case AA_MOUSE: {
int x, y;
int button;
int vlc;
aa_getmouse(sys->aa_context, &x, &y, &button);
vlc = 0;
if (button & AA_BUTTON1)
vlc |= 1 << MOUSE_BUTTON_LEFT;
if (button & AA_BUTTON2)
vlc |= 1 << MOUSE_BUTTON_CENTER;
if (button & AA_BUTTON3)
vlc |= 1 << MOUSE_BUTTON_RIGHT;
vout_display_SendEventMouseState(vd, x, y, vlc);
aa_showcursor(sys->aa_context); /* Not perfect, we show it on click too */
break;
}
case AA_RESIZE:
aa_resize(sys->aa_context);
vout_display_SendEventDisplaySize(vd,
aa_imgwidth(sys->aa_context),
aa_imgheight(sys->aa_context));
break;
/* Fill colors with color information */ /* TODO keys support to complete */
for( i = 0; i < 256; i++ ) case AA_UP:
{ vout_display_SendEventKey(vd, KEY_UP);
aa_setpalette( p_vout->p_sys->palette, 256 -i, break;
red[ i ], green[ i ], blue[ i ] ); case AA_DOWN:
vout_display_SendEventKey(vd, KEY_DOWN);
break;
case AA_RIGHT:
vout_display_SendEventKey(vd, KEY_RIGHT);
break;
case AA_LEFT:
vout_display_SendEventKey(vd, KEY_LEFT);
break;
case AA_BACKSPACE:
vout_display_SendEventKey(vd, KEY_BACKSPACE);
break;
case AA_ESC:
vout_display_SendEventKey(vd, KEY_ESC);
break;
case 0x20:
vout_display_SendEventKey(vd, KEY_SPACE);
break;
default:
if (event >= 0x20 && event <= 0x7f)
vout_display_SendEventKey(vd, event);
break;
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment