Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
293e5623
Commit
293e5623
authored
Aug 03, 2009
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted vout aa to "vout display" API.
parent
d070cdeb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
230 additions
and
168 deletions
+230
-168
modules/video_output/aa.c
modules/video_output/aa.c
+230
-168
No files found.
modules/video_output/aa.c
View file @
293e5623
/*****************************************************************************
*
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
* $Id$
...
...
@@ -28,227 +28,289 @@
# include "config.h"
#endif
#include <aalib.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_vout.h>
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static
int
Create
(
vlc_object_t
*
);
static
void
Destroy
(
vlc_object_t
*
);
static
int
Init
(
vout_thread_t
*
);
static
void
End
(
vout_thread_t
*
);
static
int
Manage
(
vout_thread_t
*
);
static
void
Render
(
vout_thread_t
*
,
picture_t
*
);
static
void
Display
(
vout_thread_t
*
,
picture_t
*
);
#include <vlc_vout_display.h>
#include <vlc_picture_pool.h>
static
void
SetPalette
(
vout_thread_t
*
,
uint16_t
*
,
uint16_t
*
,
uint16_t
*
);
#include <assert.h>
#include <aalib.h>
/* TODO
* - what about RGB palette ?
*/
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin
()
set_shortname
(
N_
(
"ASCII Art"
))
set_category
(
CAT_VIDEO
)
set_subcategory
(
SUBCAT_VIDEO_VOUT
)
set_description
(
N_
(
"ASCII-art video output"
)
)
set_capability
(
"video output"
,
10
)
add_shortcut
(
"aalib"
)
set_callbacks
(
Create
,
Destroy
)
vlc_module_end
()
static
int
Open
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
vlc_module_begin
()
set_shortname
(
N_
(
"ASCII Art"
))
set_category
(
CAT_VIDEO
)
set_subcategory
(
SUBCAT_VIDEO_VOUT
)
set_description
(
N_
(
"ASCII-art video output"
))
set_capability
(
"vout display"
,
10
)
add_shortcut
(
"aalib"
)
set_callbacks
(
Open
,
Close
)
vlc_module_end
()
/*****************************************************************************
* vout_sys_t: aa video output method descriptor
*****************************************************************************
* This structure is part of the video output thread descriptor.
* It describes the aa specific properties of an output thread.
* Local prototypes
*****************************************************************************/
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
;
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.
*
****************************************************************************
/
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 */
p_vout
->
p_sys
=
malloc
(
sizeof
(
vout_sys_t
)
);
if
(
p_vout
->
p_sys
==
NULL
)
vd
->
sys
=
sys
=
calloc
(
1
,
sizeof
(
*
sys
)
);
if
(
!
sys
)
return
VLC_ENOMEM
;
/* 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
)))
{
msg_Err
(
p_vout
,
"cannot initialize aalib"
);
free
(
p_vout
->
p_sys
);
return
VLC_EGENERIC
;
/* */
sys
->
aa_context
=
aa_autoinit
(
&
aa_defparams
);
if
(
!
sys
->
aa_context
)
{
msg_Err
(
vd
,
"cannot initialize aalib"
);
goto
error
;
}
p_vout
->
pf_init
=
Init
;
p_vout
->
pf_end
=
End
;
p_vout
->
pf_manage
=
Manage
;
p_vout
->
pf_render
=
Render
;
p_vout
->
pf_display
=
Display
;
aa_autoinitkbd
(
sys
->
aa_context
,
0
);
aa_autoinitmouse
(
sys
->
aa_context
,
AA_MOUSEALLMASK
);
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
);
/* */
video_format_t
fmt
=
vd
->
fmt
;
fmt
.
i_chroma
=
VLC_CODEC_RGB8
;
fmt
.
i_width
=
aa_imgwidth
(
sys
->
aa_context
);
fmt
.
i_height
=
aa_imgheight
(
sys
->
aa_context
);
return
VLC_SUCCESS
;
}
/* */
vout_display_info_t
info
=
vd
->
info
;
info
.
has_pictures_invalid
=
true
;
/*****************************************************************************
* Init: initialize aa video thread output method
*****************************************************************************/
static
int
Init
(
vout_thread_t
*
p_vout
)
{
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
;
/* Setup vout_display now that everything is fine */
vd
->
fmt
=
fmt
;
vd
->
info
=
info
;
/* Allocate the picture */
p_pic
->
p
->
p_pixels
=
aa_image
(
p_vout
->
p_sys
->
aa_context
);
p_pic
->
p
->
i_lines
=
p_vout
->
p_sys
->
i_height
;
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
;
vd
->
get
=
Get
;
vd
->
prepare
=
Prepare
;
vd
->
display
=
Display
;
vd
->
control
=
Control
;
vd
->
manage
=
Manage
;
p_pic
->
i_status
=
DESTROYED_PICTURE
;
p_pic
->
i_type
=
DIRECT_PICTURE
;
PP_OUTPUTPICTURE
[
I_OUTPUTPICTURES
]
=
p_pic
;
I_OUTPUTPICTURES
++
;
/* Inspect initial configuration and send correction events
* 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
;
error:
if
(
sys
&&
sys
->
aa_context
)
aa_close
(
sys
->
aa_context
);
free
(
sys
);
return
VLC_EGENERIC
;
}
/**
***************************************************************************
*
End: terminate aa video thread
output method
*
****************************************************************************
/
static
void
End
(
vout_thread_t
*
p_vout
)
/**
*
Close a aa video
output method
*/
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
*****************************************************************************
* Terminate an output method created by AaCreateOutputMethod
*****************************************************************************/
static
void
Destroy
(
vlc_object_t
*
p_this
)
/**
* Return a direct buffer
*/
static
picture_t
*
Get
(
vout_display_t
*
vd
)
{
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
);
picture_t
*
p_picture
=
picture_NewFromResource
(
&
vd
->
fmt
,
&
rsc
);
if
(
!
p_picture
)
return
NULL
;
aa_close
(
p_vout
->
p_sys
->
aa_context
);
free
(
p_vout
->
p_sys
);
sys
->
pool
=
picture_pool_New
(
1
,
&
p_picture
);
if
(
!
sys
->
pool
)
return
NULL
;
}
return
picture_pool_Get
(
sys
->
pool
);
}
/*****************************************************************************
* Manage: handle aa 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
Manage
(
vout_thread_t
*
p_vout
)
/**
* Prepare a picture for display */
static
void
Prepare
(
vout_display_t
*
vd
,
picture_t
*
picture
)
{
int
event
,
x
,
y
,
b
;
event
=
aa_getevent
(
p_vout
->
p_sys
->
aa_context
,
0
);
switch
(
event
)
{
case
AA_MOUSE
:
aa_getmouse
(
p_vout
->
p_sys
->
aa_context
,
&
x
,
&
y
,
&
b
);
if
(
b
&
AA_BUTTON3
)
var_SetBool
(
p_vout
->
p_libvlc
,
"intf-popupmenu"
,
true
);
break
;
case
AA_RESIZE
:
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
;
vout_display_sys_t
*
sys
=
vd
->
sys
;
assert
(
vd
->
fmt
.
i_width
==
aa_imgwidth
(
sys
->
aa_context
)
&&
vd
->
fmt
.
i_height
==
aa_imgheight
(
sys
->
aa_context
));
#if 0
if (picture->format.p_palette) {
for (int i = 0; i < 256; i++) {
aa_setpalette(vd->sys->palette, 256 - i,
red[ i ], green[ i ], blue[ i ]);
}
}
return
VLC_SUCCESS
;
#endif
aa_fastrender
(
sys
->
aa_context
,
0
,
0
,
vd
->
fmt
.
i_width
,
vd
->
fmt
.
i_height
);
}
/**
***************************************************************************
*
Render: render previously calculated output
*
****************************************************************************
/
static
void
Render
(
vout_thread_t
*
p_vout
,
picture_t
*
p_pic
)
/**
*
Display a picture
*/
static
void
Display
(
vout_display_t
*
vd
,
picture_t
*
picture
)
{
aa_fastrender
(
p_vout
->
p_sys
->
aa_context
,
0
,
0
,
aa_imgwidth
(
p_vout
->
p_sys
->
aa_context
),
aa_imgheight
(
p_vout
->
p_sys
->
aa_context
)
);
vout_display_sys_t
*
sys
=
vd
->
sys
;
aa_flush
(
sys
->
aa_context
);
picture_Release
(
picture
);
}
/**
***************************************************************************
*
Display: displays previously rendered output
*
****************************************************************************
/
static
void
Display
(
vout_thread_t
*
p_vout
,
picture_t
*
p_pic
)
/**
*
Control for vout display
*/
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 */
unsigned
int
i_width
,
i_height
,
i_x
,
i_y
;
vout_display_sys_t
*
sys
=
vd
->
sys
;
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
;
vout_PlacePicture
(
p_vout
,
p_vout
->
p_sys
->
i_width
,
p_vout
->
p_sys
->
i_height
,
&
i_x
,
&
i_y
,
&
i_width
,
&
i_height
);
vd
->
fmt
.
i_width
=
aa_imgwidth
(
sys
->
aa_context
);
vd
->
fmt
.
i_height
=
aa_imgheight
(
sys
->
aa_context
);
return
VLC_SUCCESS
;
aa_flush
(
p_vout
->
p_sys
->
aa_context
);
case
VOUT_DISPLAY_HIDE_MOUSE
:
aa_hidemouse
(
sys
->
aa_context
);
return
VLC_SUCCESS
;
default:
msg_Err
(
vd
,
"Unsupported query in vout display aalib"
);
return
VLC_EGENERIC
;
}
}
/*****************************************************************************
* SetPalette: set the 8bpp palette
*
****************************************************************************/
static
void
SetPalette
(
vout_thread_t
*
p_vout
,
uint16_t
*
red
,
uint16_t
*
green
,
uint16_t
*
blue
)
/**
*
Proccess pending event
*/
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
;
}
/* Fill colors with color information */
for
(
i
=
0
;
i
<
256
;
i
++
)
{
aa_setpalette
(
p_vout
->
p_sys
->
palette
,
256
-
i
,
red
[
i
],
green
[
i
],
blue
[
i
]
);
case
AA_RESIZE
:
aa_resize
(
sys
->
aa_context
);
vout_display_SendEventDisplaySize
(
vd
,
aa_imgwidth
(
sys
->
aa_context
),
aa_imgheight
(
sys
->
aa_context
));
break
;
/* TODO keys support to complete */
case
AA_UP
:
vout_display_SendEventKey
(
vd
,
KEY_UP
);
break
;
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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment