📄 logo.c
字号:
if( p_sys == NULL ) return VLC_ENOMEM; p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) ); if( p_logo_list == NULL ) { free( p_sys ); return VLC_ENOMEM; } config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options, p_vout->p_cfg ); p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout, "logo-file" ); if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename ) { msg_Err( p_vout, "logo file not specified" ); free( p_logo_list->psz_filename ); free( p_sys ); return VLC_EGENERIC; } p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" ); p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" ); p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" ); p_logo_list->i_delay = __MAX( __MIN( var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 ); p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat"); p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 ); LoadLogoList( p_vout, p_logo_list ); return VLC_SUCCESS;}/***************************************************************************** * Init: initialize logo video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){ vout_sys_t *p_sys = p_vout->p_sys; picture_t *p_pic; int i_index; video_format_t fmt; logo_list_t *p_logo_list = p_sys->p_logo_list; I_OUTPUTPICTURES = 0; memset( &fmt, 0, sizeof(video_format_t) ); /* adjust index to the next logo */ p_logo_list->i_counter = ( p_logo_list->i_counter + 1 )%p_logo_list->i_count; p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic; /* Initialize the output structure */ p_vout->output.i_chroma = p_vout->render.i_chroma; 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; p_vout->fmt_out = p_vout->fmt_in; fmt = p_vout->fmt_out; /* Load the video blending filter */ p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) ); vlc_object_attach( p_sys->p_blend, p_vout ); p_sys->p_blend->fmt_out.video.i_x_offset = p_sys->p_blend->fmt_out.video.i_y_offset = 0; p_sys->p_blend->fmt_in.video.i_x_offset = p_sys->p_blend->fmt_in.video.i_y_offset = 0; p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect; p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma; p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A'); p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR; p_sys->i_width = p_sys->p_blend->fmt_in.video.i_width = p_sys->p_blend->fmt_in.video.i_visible_width = p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0; p_sys->i_height = p_sys->p_blend->fmt_in.video.i_height = p_sys->p_blend->fmt_in.video.i_visible_height = p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0; p_sys->p_blend->fmt_out.video.i_width = p_sys->p_blend->fmt_out.video.i_visible_width = p_vout->output.i_width; p_sys->p_blend->fmt_out.video.i_height = p_sys->p_blend->fmt_out.video.i_visible_height = p_vout->output.i_height; p_sys->p_blend->p_module = module_Need( p_sys->p_blend, "video blending", 0, 0 ); if( !p_sys->p_blend->p_module ) { msg_Err( p_vout, "can't open blending filter, aborting" ); vlc_object_detach( p_sys->p_blend ); vlc_object_release( p_sys->p_blend ); return VLC_EGENERIC; } if( p_sys->posx < 0 || p_sys->posy < 0 ) { p_sys->posx = 0; p_sys->posy = 0; if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM ) { p_sys->posy = p_vout->render.i_height - p_sys->i_height; } else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) ) { p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2; } if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT ) { p_sys->posx = p_vout->render.i_width - p_sys->i_width; } else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) ) { p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2; } } else { p_sys->pos = 0; } /* Try to open the real video output */ msg_Dbg( p_vout, "spawning the real video output" ); p_sys->p_vout = vout_Create( p_vout, &fmt ); /* Everything failed */ if( p_sys->p_vout == NULL ) { msg_Err( p_vout, "can't open vout, aborting" ); return VLC_EGENERIC; } var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout); var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout); ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES ); ADD_CALLBACKS( p_sys->p_vout, SendEvents ); ADD_PARENT_CALLBACKS( SendEventsToChild ); return VLC_SUCCESS;}/***************************************************************************** * End: terminate logo video thread output method *****************************************************************************/static void End( vout_thread_t *p_vout ){ vout_sys_t *p_sys = p_vout->p_sys; int i_index; DEL_PARENT_CALLBACKS( SendEventsToChild ); DEL_CALLBACKS( p_sys->p_vout, SendEvents ); /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { i_index--; free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); } var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout); var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout); vout_CloseAndRelease( p_sys->p_vout ); if( p_sys->p_blend->p_module ) module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module ); vlc_object_detach( p_sys->p_blend ); vlc_object_release( p_sys->p_blend );}/***************************************************************************** * Destroy: destroy logo video thread output method *****************************************************************************/static void Destroy( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys = p_vout->p_sys; FreeLogoList( p_sys->p_logo_list ); free( p_sys->p_logo_list ); free( p_sys );}/***************************************************************************** * Render: render the logo onto the video *****************************************************************************/static void Render( vout_thread_t *p_vout, picture_t *p_inpic ){ vout_sys_t *p_sys = p_vout->p_sys; picture_t *p_outpic; picture_t *p_pic; logo_list_t *p_logo_list; logo_t * p_logo; p_logo_list = p_sys->p_logo_list; if( p_logo_list->i_next_pic < p_inpic->date ) { /* It's time to use a new logo */ p_logo_list->i_counter = ( p_logo_list->i_counter + 1 )%p_logo_list->i_count; p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter]; p_pic = p_logo->p_pic; p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000; if( p_pic ) { p_sys->i_width = p_sys->p_blend->fmt_in.video.i_width = p_sys->p_blend->fmt_in.video.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch; p_sys->i_height = p_sys->p_blend->fmt_in.video.i_height = p_sys->p_blend->fmt_in.video.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines; if( p_sys->pos ) { if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM ) { p_sys->posy = p_vout->render.i_height - p_sys->i_height; } else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) ) { p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2; } if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT ) { p_sys->posx = p_vout->render.i_width - p_sys->i_width; } else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) ) { p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2; } } } } else { p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter]; p_pic = p_logo->p_pic; } /* This is a new frame. Get a structure from the video_output. */ while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) ) { if( !vlc_object_alive (p_vout) || p_vout->b_error ) return; msleep( VOUT_OUTMEM_SLEEP ); } vout_CopyPicture( p_vout, p_outpic, p_inpic ); vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date ); if( p_pic ) p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic, p_pic, p_sys->posx, p_sys->posy, p_logo->i_alpha != -1 ? p_logo->i_alpha : p_logo_list->i_alpha ); vout_DisplayPicture( p_sys->p_vout, p_outpic );}/***************************************************************************** * SendEvents: forward mouse and keyboard events to the parent p_vout *****************************************************************************/static int SendEvents( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ VLC_UNUSED(p_this); VLC_UNUSED(oldval); var_Set( (vlc_object_t *)p_data, psz_var, newval ); return VLC_SUCCESS;}/***************************************************************************** * MouseEvent: callback for mouse events *****************************************************************************/static int MouseEvent( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ){ VLC_UNUSED(p_this); VLC_UNUSED(oldval); vout_thread_t *p_vout = (vout_thread_t*)p_data; vout_sys_t *p_sys = p_vout->p_sys; vlc_value_t valb; int i_delta; var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb ); i_delta = newval.i_int - oldval.i_int; if( (valb.i_int & 0x1) == 0 ) { return VLC_SUCCESS; } if( psz_var[6] == 'x' ) { vlc_value_t valy;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -