📄 logo.c
字号:
} 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_logo_list->psz_filename = var_CreateGetString( p_this , "logo-file" ); if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename ) { msg_Err( p_this, "logo file not specified" ); return 0; } var_Create( p_this, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Get( p_this, "logo-position", &val ); p_sys->pos = val.i_int; var_Create( p_this, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Get( p_this, "logo-x", &val ); p_sys->posx = val.i_int; var_Create( p_this, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Get( p_this, "logo-y", &val ); p_sys->posy = val.i_int; var_Create( p_this, "logo-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Get( p_this, "logo-delay", &val ); p_logo_list->i_delay = __MAX( __MIN( val.i_int, 60000 ), 0 ); var_Create( p_this, "logo-repeat", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Get( p_this, "logo-repeat", &val ); p_logo_list->i_repeat = val.i_int; var_Create(p_this, "logo-transparency", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT); var_Get( p_this, "logo-transparency", &val ); p_logo_list->i_alpha = __MAX( __MIN( val.i_int, 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 = {0}; logo_list_t *p_logo_list = p_sys->p_logo_list; I_OUTPUTPICTURES = 0; /* 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_destroy( 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; } } /* 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; /* 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); if( p_sys->p_vout ) { DEL_CALLBACKS( p_sys->p_vout, SendEvents ); vlc_object_detach( p_sys->p_vout ); vout_Destroy( 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_destroy( 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; DEL_PARENT_CALLBACKS( SendEventsToChild ); 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; /* Just in case the new image would overflow the vout */ if( (unsigned int)(p_sys->posy + p_sys->i_height) > p_vout->render.i_height || (unsigned int)(p_sys->posx + p_sys->i_width) > p_vout->render.i_width || 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( p_vout->b_die || 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 ){ 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 ){ 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' )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -