Commit 0c630661 authored by Rafaël Carré's avatar Rafaël Carré

audiobargraph_v: cosmetics

parent 53d10bb5
...@@ -46,14 +46,14 @@ ...@@ -46,14 +46,14 @@
*****************************************************************************/ *****************************************************************************/
#define POSX_TEXT N_("X coordinate") #define POSX_TEXT N_("X coordinate")
#define POSX_LONGTEXT N_("X coordinate of the bargraph." ) #define POSX_LONGTEXT N_("X coordinate of the bargraph.")
#define POSY_TEXT N_("Y coordinate") #define POSY_TEXT N_("Y coordinate")
#define POSY_LONGTEXT N_("Y coordinate of the bargraph." ) #define POSY_LONGTEXT N_("Y coordinate of the bargraph.")
#define TRANS_TEXT N_("Transparency of the bargraph") #define TRANS_TEXT N_("Transparency of the bargraph")
#define TRANS_LONGTEXT N_("Bargraph transparency value " \ #define TRANS_LONGTEXT N_("Bargraph transparency value " \
"(from 0 for full transparency to 255 for full opacity)." ) "(from 0 for full transparency to 255 for full opacity).")
#define POS_TEXT N_("Bargraph position") #define POS_TEXT N_("Bargraph position")
#define POS_LONGTEXT N_( \ #define POS_LONGTEXT N_(\
"Enforce the bargraph position on the video " \ "Enforce the bargraph position on the video " \
"(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \ "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
"also use combinations of these values, eg 6 = top-right).") "also use combinations of these values, eg 6 = top-right).")
...@@ -68,37 +68,37 @@ static const char *const ppsz_pos_descriptions[] = ...@@ -68,37 +68,37 @@ static const char *const ppsz_pos_descriptions[] =
{ N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"), { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") }; N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
static int OpenSub ( vlc_object_t * ); static int OpenSub (vlc_object_t *);
static int OpenVideo( vlc_object_t * ); static int OpenVideo(vlc_object_t *);
static void Close ( vlc_object_t * ); static void Close (vlc_object_t *);
vlc_module_begin () vlc_module_begin ()
set_category( CAT_VIDEO ) set_category(CAT_VIDEO)
set_subcategory( SUBCAT_VIDEO_SUBPIC ) set_subcategory(SUBCAT_VIDEO_SUBPIC)
set_capability( "sub source", 0 ) set_capability("sub source", 0)
set_callbacks( OpenSub, Close ) set_callbacks(OpenSub, Close)
set_description( N_("Audio Bar Graph Video sub source") ) set_description(N_("Audio Bar Graph Video sub source"))
set_shortname( N_("Audio Bar Graph Video") ) set_shortname(N_("Audio Bar Graph Video"))
add_shortcut( "audiobargraph_v" ) add_shortcut("audiobargraph_v")
add_obsolete_string( CFG_PREFIX "i_values" ) add_obsolete_string(CFG_PREFIX "i_values")
add_integer( CFG_PREFIX "x", 0, POSX_TEXT, POSX_LONGTEXT, true ) add_integer(CFG_PREFIX "x", 0, POSX_TEXT, POSX_LONGTEXT, true)
add_integer( CFG_PREFIX "y", 0, POSY_TEXT, POSY_LONGTEXT, true ) add_integer(CFG_PREFIX "y", 0, POSY_TEXT, POSY_LONGTEXT, true)
add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, add_integer_with_range(CFG_PREFIX "transparency", 255, 0, 255,
TRANS_TEXT, TRANS_LONGTEXT, false ) TRANS_TEXT, TRANS_LONGTEXT, false)
add_integer( CFG_PREFIX "position", -1, POS_TEXT, POS_LONGTEXT, false ) add_integer(CFG_PREFIX "position", -1, POS_TEXT, POS_LONGTEXT, false)
change_integer_list( pi_pos_values, ppsz_pos_descriptions ) change_integer_list(pi_pos_values, ppsz_pos_descriptions)
add_obsolete_integer( CFG_PREFIX "alarm" ) add_obsolete_integer(CFG_PREFIX "alarm")
add_integer( CFG_PREFIX "barWidth", 10, BARWIDTH_TEXT, BARWIDTH_LONGTEXT, true ) add_integer(CFG_PREFIX "barWidth", 10, BARWIDTH_TEXT, BARWIDTH_LONGTEXT, true)
/* video output filter submodule */ /* video output filter submodule */
add_submodule () add_submodule ()
set_capability( "video filter2", 0 ) set_capability("video filter2", 0)
set_callbacks( OpenVideo, Close ) set_callbacks(OpenVideo, Close)
set_description( N_("Audio Bar Graph Video sub source") ) set_description(N_("Audio Bar Graph Video sub source"))
add_shortcut( "audiobargraph_v" ) add_shortcut("audiobargraph_v")
vlc_module_end () vlc_module_end ()
...@@ -180,7 +180,7 @@ static float iec_scale(float dB) ...@@ -180,7 +180,7 @@ static float iec_scale(float dB)
/***************************************************************************** /*****************************************************************************
* parse_i_values : parse i_values parameter and store the corresponding values * parse_i_values : parse i_values parameter and store the corresponding values
*****************************************************************************/ *****************************************************************************/
static void parse_i_values( BarGraph_t *p_BarGraph, char *i_values) static void parse_i_values(BarGraph_t *p_BarGraph, char *i_values)
{ {
char* res = NULL; char* res = NULL;
char delim[] = ":"; char delim[] = ":";
...@@ -195,7 +195,7 @@ static void parse_i_values( BarGraph_t *p_BarGraph, char *i_values) ...@@ -195,7 +195,7 @@ static void parse_i_values( BarGraph_t *p_BarGraph, char *i_values)
p_BarGraph->i_values = xrealloc(p_BarGraph->i_values, p_BarGraph->i_values = xrealloc(p_BarGraph->i_values,
p_BarGraph->nbChannels*sizeof(int)); p_BarGraph->nbChannels*sizeof(int));
db = log10(atof(res)) * 20; db = log10(atof(res)) * 20;
p_BarGraph->i_values[p_BarGraph->nbChannels-1] = VLC_CLIP( iec_scale(db)*p_BarGraph->scale, 0, p_BarGraph->scale ); p_BarGraph->i_values[p_BarGraph->nbChannels-1] = VLC_CLIP(iec_scale(db)*p_BarGraph->scale, 0, p_BarGraph->scale);
res = strtok_r(NULL, delim, &tok); res = strtok_r(NULL, delim, &tok);
} }
...@@ -204,7 +204,7 @@ static void parse_i_values( BarGraph_t *p_BarGraph, char *i_values) ...@@ -204,7 +204,7 @@ static void parse_i_values( BarGraph_t *p_BarGraph, char *i_values)
/***************************************************************************** /*****************************************************************************
* LoadImage: creates and returns the bar graph image * LoadImage: creates and returns the bar graph image
*****************************************************************************/ *****************************************************************************/
static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values, int scale, int alarm, int barWidth) static picture_t *LoadImage(vlc_object_t *p_this, int nbChannels, int* i_values, int scale, int alarm, int barWidth)
{ {
VLC_UNUSED(p_this); VLC_UNUSED(p_this);
picture_t *p_pic; picture_t *p_pic;
...@@ -213,11 +213,11 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values ...@@ -213,11 +213,11 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values
int i_line; int i_line;
int minus8, minus10, minus18, minus20, minus30, minus40, minus50, minus60; int minus8, minus10, minus18, minus20, minus30, minus40, minus50, minus60;
if (nbChannels == 0) { if (nbChannels == 0)
i_width = 20; i_width = 20;
} else { else
i_width = 2 * nbChannels * barWidth + 10; i_width = 2 * nbChannels * barWidth + 10;
}
minus8 = iec_scale(-8)*scale + 20; minus8 = iec_scale(-8)*scale + 20;
minus10 = iec_scale(-10)*scale + 20; minus10 = iec_scale(-10)*scale + 20;
minus18 = iec_scale(-18)*scale + 20; minus18 = iec_scale(-18)*scale + 20;
...@@ -232,24 +232,23 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values ...@@ -232,24 +232,23 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values
#define DrawLine(a,b,Y,U,V,A) \ #define DrawLine(a,b,Y,U,V,A) \
for (i=a; i<b; i++) {\ for (i=a; i<b; i++) {\
*(p_pic->p[0].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[0].i_pitch + i ) = Y;\ *(p_pic->p[0].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[0].i_pitch + i) = Y;\
*(p_pic->p[1].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[1].i_pitch + i ) = U;\ *(p_pic->p[1].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[1].i_pitch + i) = U;\
*(p_pic->p[2].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[2].i_pitch + i ) = V;\ *(p_pic->p[2].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[2].i_pitch + i) = V;\
*(p_pic->p[3].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[3].i_pitch + i ) = A; \ *(p_pic->p[3].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[3].i_pitch + i) = A; \
} }
#define DrawLineBlack(a,b) DrawLine(a,b,0,128,128,0xFF) #define DrawLineBlack(a,b) DrawLine(a,b,0,128,128,0xFF)
#define DrawLineWhite(a,b) DrawLine(a,b,255,128,128,0xFF) #define DrawLineWhite(a,b) DrawLine(a,b,255,128,128,0xFF)
// blacken the whole picture // blacken the whole picture
for( i = 0 ; i < p_pic->i_planes ; i++ ) for (i = 0 ; i < p_pic->i_planes ; i++) {
{ memset(p_pic->p[i].p_pixels, 0x00,
memset( p_pic->p[i].p_pixels, 0x00, p_pic->p[i].i_visible_lines * p_pic->p[i].i_pitch);
p_pic->p[i].i_visible_lines * p_pic->p[i].i_pitch );
} }
// side bar // side bar
for ( i_line = 20; i_line < scale+20; i_line++ ) { for (i_line = 20; i_line < scale+20; i_line++) {
// vertical line // vertical line
DrawLineBlack(20,22); DrawLineBlack(20,22);
DrawLineWhite(22,24); DrawLineWhite(22,24);
...@@ -503,32 +502,29 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values ...@@ -503,32 +502,29 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values
} }
} }
#define drawPoint(offset,y,u,v,a) \ #define drawPoint(offset,y,u,v,a) do { \
*(p_pic->p[0].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[0].i_pitch + offset ) = y; \ *(p_pic->p[0].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[0].i_pitch + offset) = y; \
*(p_pic->p[1].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[1].i_pitch + offset ) = u; \ *(p_pic->p[1].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[1].i_pitch + offset) = u; \
*(p_pic->p[2].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[2].i_pitch + offset ) = v; \ *(p_pic->p[2].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[2].i_pitch + offset) = v; \
*(p_pic->p[3].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[3].i_pitch + offset ) = a; *(p_pic->p[3].p_pixels + (scale + 30 - i_line - 1) * p_pic->p[3].i_pitch + offset) = a; \
} while(0)
// draw the bars and channel indicators // draw the bars and channel indicators
for (i=0; i<nbChannels; i++) { for (i=0; i<nbChannels; i++) {
pi = 25 + ((i+1)*5) + (i*barWidth) ; // 25 separació amb indicador, 5 separació entre barres pi = 25 + ((i+1)*5) + (i*barWidth) ; // 25 separació amb indicador, 5 separació entre barres
for( j = pi; j < pi + barWidth; j++) for (j = pi; j < pi + barWidth; j++) {
{
// channel indicators // channel indicators
for ( i_line = 12; i_line < 20; i_line++ ) { for (i_line = 12; i_line < 20; i_line++) {
if( alarm ) { if (alarm) {
drawPoint(j,76,85,0xFF,0xFF); // red drawPoint(j,76,85,0xFF,0xFF); // red
} } else
else {
drawPoint(j,0,128,128,0xFF); // black DrawLine(pi,pf,0xFF,128,128,0xFF); drawPoint(j,0,128,128,0xFF); // black DrawLine(pi,pf,0xFF,128,128,0xFF);
}
} }
// bars // bars
for( i_line = 20; i_line < i_values[i]+20; i_line++ ) for (i_line = 20; i_line < i_values[i]+20; i_line++) {
{
if (i_line < minus18) { // green if < -18 dB if (i_line < minus18) { // green if < -18 dB
drawPoint(j,150,44,21,0xFF); drawPoint(j,150,44,21,0xFF);
//DrawLine(pi,pf,150,44,21,0xFF); //DrawLine(pi,pf,150,44,21,0xFF);
...@@ -541,8 +537,7 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values ...@@ -541,8 +537,7 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values
} }
} }
// bars no signal // bars no signal
for( ; i_line < scale+20; i_line++ ) for (; i_line < scale+20; i_line++) {
{
if (i_line < minus18) { // green if < -18 dB if (i_line < minus18) { // green if < -18 dB
drawPoint(j,74,85,74,0xFF); drawPoint(j,74,85,74,0xFF);
//DrawLine(pi,pf,74,85,74,0xFF); //DrawLine(pi,pf,74,85,74,0xFF);
...@@ -562,54 +557,40 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values ...@@ -562,54 +557,40 @@ static picture_t *LoadImage( vlc_object_t *p_this, int nbChannels, int* i_values
/***************************************************************************** /*****************************************************************************
* LoadBarGraph: loads the BarGraph images into memory * LoadBarGraph: loads the BarGraph images into memory
*****************************************************************************/ *****************************************************************************/
static void LoadBarGraph( vlc_object_t *p_this, BarGraph_t *p_BarGraph ) static void LoadBarGraph(vlc_object_t *p_this, BarGraph_t *p_BarGraph)
{ {
p_BarGraph->p_pic = LoadImage(p_this, p_BarGraph->nbChannels, p_BarGraph->i_values, p_BarGraph->scale, p_BarGraph->alarm, p_BarGraph->barWidth);
p_BarGraph->p_pic = LoadImage( p_this, p_BarGraph->nbChannels, p_BarGraph->i_values, p_BarGraph->scale, p_BarGraph->alarm, p_BarGraph->barWidth); if (!p_BarGraph->p_pic)
if( !p_BarGraph->p_pic ) msg_Warn(p_this, "error while creating picture");
{
msg_Warn( p_this, "error while creating picture" );
}
} }
/***************************************************************************** /*****************************************************************************
* Callback to update params on the fly * Callback to update params on the fly
*****************************************************************************/ *****************************************************************************/
static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var, static int BarGraphCallback(vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data)
{ {
VLC_UNUSED(oldval); VLC_UNUSED(oldval);
filter_sys_t *p_sys = (filter_sys_t *)p_data; filter_sys_t *p_sys = (filter_sys_t *)p_data;
BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph); BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph);
char* res = NULL; char* res = NULL;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock(&p_sys->lock);
if ( !strcmp( psz_var, "audiobargraph_v-x" ) ) if (!strcmp(psz_var, "audiobargraph_v-x"))
{
p_sys->i_pos_x = newval.i_int; p_sys->i_pos_x = newval.i_int;
} else if (!strcmp(psz_var, "audiobargraph_v-y"))
else if ( !strcmp( psz_var, "audiobargraph_v-y" ) )
{
p_sys->i_pos_y = newval.i_int; p_sys->i_pos_y = newval.i_int;
} else if (!strcmp(psz_var, "audiobargraph_v-position"))
else if ( !strcmp( psz_var, "audiobargraph_v-position" ) )
{
p_sys->i_pos = newval.i_int; p_sys->i_pos = newval.i_int;
} else if (!strcmp(psz_var, "audiobargraph_v-transparency"))
else if ( !strcmp( psz_var, "audiobargraph_v-transparency" ) ) p_BarGraph->i_alpha = VLC_CLIP(newval.i_int, 0, 255);
{ else if (!strcmp(psz_var, "audiobargraph_v-i_values")) {
p_BarGraph->i_alpha = VLC_CLIP( newval.i_int, 0, 255 ); if (p_BarGraph->p_pic) {
} picture_Release(p_BarGraph->p_pic);
else if ( !strcmp( psz_var, "audiobargraph_v-i_values" ) )
{
if( p_BarGraph->p_pic )
{
picture_Release( p_BarGraph->p_pic );
p_BarGraph->p_pic = NULL; p_BarGraph->p_pic = NULL;
} }
char *psz = xstrdup( newval.psz_string ? newval.psz_string : "" ); char *psz = xstrdup(newval.psz_string ? newval.psz_string : "");
free(p_BarGraph->i_values); free(p_BarGraph->i_values);
//p_BarGraph->i_values = NULL; //p_BarGraph->i_values = NULL;
//p_BarGraph->nbChannels = 0; //p_BarGraph->nbChannels = 0;
...@@ -617,32 +598,26 @@ static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var, ...@@ -617,32 +598,26 @@ static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var,
res = strchr(psz, '@'); res = strchr(psz, '@');
if (res) if (res)
*res = 0; *res = 0;
parse_i_values( p_BarGraph, psz); parse_i_values(p_BarGraph, psz);
free( psz ); free(psz);
LoadBarGraph(p_this,p_BarGraph); LoadBarGraph(p_this,p_BarGraph);
} } else if (!strcmp(psz_var, "audiobargraph_v-alarm")) {
else if ( !strcmp( psz_var, "audiobargraph_v-alarm" ) ) if (p_BarGraph->p_pic) {
{ picture_Release(p_BarGraph->p_pic);
if( p_BarGraph->p_pic )
{
picture_Release( p_BarGraph->p_pic );
p_BarGraph->p_pic = NULL; p_BarGraph->p_pic = NULL;
} }
p_BarGraph->alarm = newval.b_bool; p_BarGraph->alarm = newval.b_bool;
LoadBarGraph(p_this,p_BarGraph); LoadBarGraph(p_this,p_BarGraph);
} } else if (!strcmp(psz_var, "audiobargraph_v-barWidth")) {
else if ( !strcmp( psz_var, "audiobargraph_v-barWidth" ) ) if (p_BarGraph->p_pic) {
{ picture_Release(p_BarGraph->p_pic);
if( p_BarGraph->p_pic )
{
picture_Release( p_BarGraph->p_pic );
p_BarGraph->p_pic = NULL; p_BarGraph->p_pic = NULL;
} }
p_BarGraph->barWidth = newval.i_int; p_BarGraph->barWidth = newval.i_int;
LoadBarGraph(p_this,p_BarGraph); LoadBarGraph(p_this,p_BarGraph);
} }
p_sys->b_spu_update = true; p_sys->b_spu_update = true;
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock(&p_sys->lock);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -650,7 +625,7 @@ static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var, ...@@ -650,7 +625,7 @@ static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var,
/** /**
* Sub source * Sub source
*/ */
static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date ) static subpicture_t *FilterSub(filter_t *p_filter, mtime_t date)
{ {
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph); BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph);
...@@ -660,19 +635,18 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date ) ...@@ -660,19 +635,18 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
video_format_t fmt; video_format_t fmt;
picture_t *p_pic; picture_t *p_pic;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock(&p_sys->lock);
/* Basic test: b_spu_update occurs on a dynamic change */ /* Basic test: b_spu_update occurs on a dynamic change */
if( !p_sys->b_spu_update ) if (!p_sys->b_spu_update) {
{ vlc_mutex_unlock(&p_sys->lock);
vlc_mutex_unlock( &p_sys->lock );
return 0; return 0;
} }
p_pic = p_BarGraph->p_pic; p_pic = p_BarGraph->p_pic;
/* Allocate the subpicture internal data. */ /* Allocate the subpicture internal data. */
p_spu = filter_NewSubpicture( p_filter ); p_spu = filter_NewSubpicture(p_filter);
if( !p_spu ) if (!p_spu)
goto exit; goto exit;
p_spu->b_absolute = p_sys->b_absolute; p_spu->b_absolute = p_sys->b_absolute;
...@@ -681,36 +655,32 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date ) ...@@ -681,36 +655,32 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
p_spu->b_ephemer = true; p_spu->b_ephemer = true;
/* Send an empty subpicture to clear the display when needed */ /* Send an empty subpicture to clear the display when needed */
if( !p_pic || !p_BarGraph->i_alpha ) if (!p_pic || !p_BarGraph->i_alpha)
goto exit; goto exit;
/* Create new SPU region */ /* Create new SPU region */
memset( &fmt, 0, sizeof(video_format_t) ); memset(&fmt, 0, sizeof(video_format_t));
fmt.i_chroma = VLC_CODEC_YUVA; fmt.i_chroma = VLC_CODEC_YUVA;
fmt.i_sar_num = fmt.i_sar_den = 1; fmt.i_sar_num = fmt.i_sar_den = 1;
fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch; fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines; fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
fmt.i_x_offset = fmt.i_y_offset = 0; fmt.i_x_offset = fmt.i_y_offset = 0;
p_region = subpicture_region_New( &fmt ); p_region = subpicture_region_New(&fmt);
if( !p_region ) if (!p_region) {
{ msg_Err(p_filter, "cannot allocate SPU region");
msg_Err( p_filter, "cannot allocate SPU region" ); p_filter->pf_sub_buffer_del(p_filter, p_spu);
p_filter->pf_sub_buffer_del( p_filter, p_spu );
p_spu = NULL; p_spu = NULL;
goto exit; goto exit;
} }
/* */ /* */
picture_Copy( p_region->p_picture, p_pic ); picture_Copy(p_region->p_picture, p_pic);
/* where to locate the bar graph: */ /* where to locate the bar graph: */
if( p_sys->i_pos < 0 ) if (p_sys->i_pos < 0) { /* set to an absolute xy */
{ /* set to an absolute xy */
p_region->i_align = SUBPICTURE_ALIGN_RIGHT | SUBPICTURE_ALIGN_TOP; p_region->i_align = SUBPICTURE_ALIGN_RIGHT | SUBPICTURE_ALIGN_TOP;
p_spu->b_absolute = true; p_spu->b_absolute = true;
} } else { /* set to one of the 9 relative locations */
else
{ /* set to one of the 9 relative locations */
p_region->i_align = p_sys->i_pos; p_region->i_align = p_sys->i_pos;
p_spu->b_absolute = false; p_spu->b_absolute = false;
} }
...@@ -723,7 +693,7 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date ) ...@@ -723,7 +693,7 @@ static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
p_spu->i_alpha = p_BarGraph->i_alpha ; p_spu->i_alpha = p_BarGraph->i_alpha ;
exit: exit:
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock(&p_sys->lock);
return p_spu; return p_spu;
} }
...@@ -731,131 +701,116 @@ exit: ...@@ -731,131 +701,116 @@ exit:
/** /**
* Video filter * Video filter
*/ */
static picture_t *FilterVideo( filter_t *p_filter, picture_t *p_src ) static picture_t *FilterVideo(filter_t *p_filter, picture_t *p_src)
{ {
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph); BarGraph_t *p_BarGraph = &(p_sys->p_BarGraph);
picture_t *p_dst = filter_NewPicture( p_filter ); picture_t *p_dst = filter_NewPicture(p_filter);
if( !p_dst ) if (!p_dst) {
goto exit; picture_Release(p_src);
return NULL;
}
picture_Copy( p_dst, p_src ); picture_Copy(p_dst, p_src);
/* */ /* */
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock(&p_sys->lock);
/* */ /* */
const picture_t *p_pic = p_BarGraph->p_pic; const picture_t *p_pic = p_BarGraph->p_pic;
if( p_pic ) if (!p_pic)
{ goto out;
const video_format_t *p_fmt = &p_pic->format;
const int i_dst_w = p_filter->fmt_out.video.i_visible_width; const video_format_t *p_fmt = &p_pic->format;
const int i_dst_h = p_filter->fmt_out.video.i_visible_height; const int i_dst_w = p_filter->fmt_out.video.i_visible_width;
const int i_dst_h = p_filter->fmt_out.video.i_visible_height;
if( p_sys->i_pos )
{ if (p_sys->i_pos) {
if( p_sys->i_pos & SUBPICTURE_ALIGN_BOTTOM ) if (p_sys->i_pos & SUBPICTURE_ALIGN_BOTTOM)
{ p_sys->i_pos_y = i_dst_h - p_fmt->i_visible_height;
p_sys->i_pos_y = i_dst_h - p_fmt->i_visible_height; else if (!(p_sys->i_pos & SUBPICTURE_ALIGN_TOP))
} p_sys->i_pos_y = (i_dst_h - p_fmt->i_visible_height) / 2;
else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_TOP) ) else
{ p_sys->i_pos_y = 0;
p_sys->i_pos_y = ( i_dst_h - p_fmt->i_visible_height ) / 2;
} if (p_sys->i_pos & SUBPICTURE_ALIGN_RIGHT)
else p_sys->i_pos_x = i_dst_w - p_fmt->i_visible_width;
{ else if (!(p_sys->i_pos & SUBPICTURE_ALIGN_LEFT))
p_sys->i_pos_y = 0; p_sys->i_pos_x = (i_dst_w - p_fmt->i_visible_width) / 2;
} else
p_sys->i_pos_x = 0;
}
if( p_sys->i_pos & SUBPICTURE_ALIGN_RIGHT ) /* */
{ const int i_alpha = p_BarGraph->i_alpha;
p_sys->i_pos_x = i_dst_w - p_fmt->i_visible_width; if (filter_ConfigureBlend(p_sys->p_blend, i_dst_w, i_dst_h, p_fmt) ||
} filter_Blend(p_sys->p_blend, p_dst, p_sys->i_pos_x, p_sys->i_pos_y,
else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_LEFT) ) p_pic, i_alpha))
{ msg_Err(p_filter, "failed to blend a picture");
p_sys->i_pos_x = ( i_dst_w - p_fmt->i_visible_width ) / 2;
}
else
{
p_sys->i_pos_x = 0;
}
}
/* */ out:
const int i_alpha = p_BarGraph->i_alpha; vlc_mutex_unlock(&p_sys->lock);
if( filter_ConfigureBlend( p_sys->p_blend, i_dst_w, i_dst_h, p_fmt ) ||
filter_Blend( p_sys->p_blend, p_dst, p_sys->i_pos_x, p_sys->i_pos_y,
p_pic, i_alpha ) )
{
msg_Err( p_filter, "failed to blend a picture" );
}
}
vlc_mutex_unlock( &p_sys->lock );
exit: picture_Release(p_src);
picture_Release( p_src );
return p_dst; return p_dst;
} }
/** /**
* Common open function * Common open function
*/ */
static int OpenCommon( vlc_object_t *p_this, bool b_sub ) static int OpenCommon(vlc_object_t *p_this, bool b_sub)
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys; filter_sys_t *p_sys;
/* */ /* */
if( !b_sub && !es_format_IsSimilar( &p_filter->fmt_in, &p_filter->fmt_out ) ) if (!b_sub && !es_format_IsSimilar(&p_filter->fmt_in, &p_filter->fmt_out)) {
{ msg_Err(p_filter, "Input and output format does not match");
msg_Err( p_filter, "Input and output format does not match" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* */ /* */
p_filter->p_sys = p_sys = malloc( sizeof( *p_sys ) ); p_filter->p_sys = p_sys = malloc(sizeof(*p_sys));
if( !p_sys ) if (!p_sys)
return VLC_ENOMEM; return VLC_ENOMEM;
/* */ /* */
p_sys->p_blend = NULL; p_sys->p_blend = NULL;
if( !b_sub ) if (!b_sub) {
{ p_sys->p_blend = filter_NewBlend(VLC_OBJECT(p_filter),
p_sys->p_blend = filter_NewBlend( VLC_OBJECT(p_filter), &p_filter->fmt_in.video);
&p_filter->fmt_in.video ); if (!p_sys->p_blend) {
if( !p_sys->p_blend ) free(p_sys);
{
free( p_sys );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
} }
/* */ /* */
config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, config_ChainParse(p_filter, CFG_PREFIX, ppsz_filter_options,
p_filter->p_cfg ); p_filter->p_cfg);
/* create and initialize variables */ /* create and initialize variables */
p_sys->i_pos = var_CreateGetIntegerCommand( p_filter, "audiobargraph_v-position" ); p_sys->i_pos = var_CreateGetIntegerCommand(p_filter, "audiobargraph_v-position");
p_sys->i_pos_x = var_CreateGetIntegerCommand( p_filter, "audiobargraph_v-x" ); p_sys->i_pos_x = var_CreateGetIntegerCommand(p_filter, "audiobargraph_v-x");
p_sys->i_pos_y = var_CreateGetIntegerCommand( p_filter, "audiobargraph_v-y" ); p_sys->i_pos_y = var_CreateGetIntegerCommand(p_filter, "audiobargraph_v-y");
BarGraph_t *p_BarGraph = &p_sys->p_BarGraph; BarGraph_t *p_BarGraph = &p_sys->p_BarGraph;
p_BarGraph->p_pic = NULL; p_BarGraph->p_pic = NULL;
p_BarGraph->i_alpha = var_CreateGetIntegerCommand( p_filter, p_BarGraph->i_alpha = var_CreateGetIntegerCommand(p_filter,
"audiobargraph_v-transparency" ); "audiobargraph_v-transparency");
p_BarGraph->i_alpha = VLC_CLIP( p_BarGraph->i_alpha, 0, 255 ); p_BarGraph->i_alpha = VLC_CLIP(p_BarGraph->i_alpha, 0, 255);
parse_i_values(p_BarGraph, &(char){ 0 }); parse_i_values(p_BarGraph, &(char){ 0 });
p_BarGraph->alarm = false; p_BarGraph->alarm = false;
p_BarGraph->barWidth = var_CreateGetIntegerCommand( p_filter, "audiobargraph_v-barWidth" ); p_BarGraph->barWidth = var_CreateGetIntegerCommand(p_filter, "audiobargraph_v-barWidth");
p_BarGraph->scale = 400; p_BarGraph->scale = 400;
/* Ignore aligment if a position is given for video filter */ /* Ignore aligment if a position is given for video filter */
if( !b_sub && p_sys->i_pos_x >= 0 && p_sys->i_pos_y >= 0 ) if (!b_sub && p_sys->i_pos_x >= 0 && p_sys->i_pos_y >= 0)
p_sys->i_pos = 0; p_sys->i_pos = 0;
vlc_mutex_init( &p_sys->lock ); vlc_mutex_init(&p_sys->lock);
var_Create(p_filter->p_libvlc, "audiobargraph_v-alarm", VLC_VAR_BOOL); var_Create(p_filter->p_libvlc, "audiobargraph_v-alarm", VLC_VAR_BOOL);
var_Create(p_filter->p_libvlc, "audiobargraph_v-i_values", VLC_VAR_STRING); var_Create(p_filter->p_libvlc, "audiobargraph_v-i_values", VLC_VAR_STRING);
...@@ -868,11 +823,11 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub ) ...@@ -868,11 +823,11 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub )
var_TriggerCallback(p_filter->p_libvlc, "audiobargraph_v-alarm"); var_TriggerCallback(p_filter->p_libvlc, "audiobargraph_v-alarm");
var_TriggerCallback(p_filter->p_libvlc, "audiobargraph_v-i_values"); var_TriggerCallback(p_filter->p_libvlc, "audiobargraph_v-i_values");
for( int i = 0; ppsz_filter_callbacks[i]; i++ ) for (int i = 0; ppsz_filter_callbacks[i]; i++)
var_AddCallback( p_filter, ppsz_filter_callbacks[i], var_AddCallback(p_filter, ppsz_filter_callbacks[i],
BarGraphCallback, p_sys ); BarGraphCallback, p_sys);
if( b_sub ) if (b_sub)
p_filter->pf_sub_source = FilterSub; p_filter->pf_sub_source = FilterSub;
else else
p_filter->pf_video_filter = FilterVideo; p_filter->pf_video_filter = FilterVideo;
...@@ -883,30 +838,30 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub ) ...@@ -883,30 +838,30 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub )
/** /**
* Open the sub source * Open the sub source
*/ */
static int OpenSub( vlc_object_t *p_this ) static int OpenSub(vlc_object_t *p_this)
{ {
return OpenCommon( p_this, true ); return OpenCommon(p_this, true);
} }
/** /**
* Open the video filter * Open the video filter
*/ */
static int OpenVideo( vlc_object_t *p_this ) static int OpenVideo(vlc_object_t *p_this)
{ {
return OpenCommon( p_this, false ); return OpenCommon(p_this, false);
} }
/** /**
* Common close function * Common close function
*/ */
static void Close( vlc_object_t *p_this ) static void Close(vlc_object_t *p_this)
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
for( int i = 0; ppsz_filter_callbacks[i]; i++ ) for (int i = 0; ppsz_filter_callbacks[i]; i++)
var_DelCallback( p_filter, ppsz_filter_callbacks[i], var_DelCallback(p_filter, ppsz_filter_callbacks[i],
BarGraphCallback, p_sys ); BarGraphCallback, p_sys);
var_DelCallback(p_filter->p_libvlc, "audiobargraph_v-i_values", var_DelCallback(p_filter->p_libvlc, "audiobargraph_v-i_values",
BarGraphCallback, p_sys); BarGraphCallback, p_sys);
...@@ -915,15 +870,15 @@ static void Close( vlc_object_t *p_this ) ...@@ -915,15 +870,15 @@ static void Close( vlc_object_t *p_this )
var_Destroy(p_filter->p_libvlc, "audiobargraph_v-i_values"); var_Destroy(p_filter->p_libvlc, "audiobargraph_v-i_values");
var_Destroy(p_filter->p_libvlc, "audiobargraph_v-alarm"); var_Destroy(p_filter->p_libvlc, "audiobargraph_v-alarm");
if( p_sys->p_blend ) if (p_sys->p_blend)
filter_DeleteBlend( p_sys->p_blend ); filter_DeleteBlend(p_sys->p_blend);
vlc_mutex_destroy( &p_sys->lock ); vlc_mutex_destroy(&p_sys->lock);
if( p_sys->p_BarGraph.p_pic ) if (p_sys->p_BarGraph.p_pic)
picture_Release( p_sys->p_BarGraph.p_pic ); picture_Release(p_sys->p_BarGraph.p_pic);
free( p_sys->p_BarGraph.i_values ); free(p_sys->p_BarGraph.i_values);
free( p_sys ); free(p_sys);
} }
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