📄 fbosd.c
字号:
p_sys->i_height = p_sys->fmt_out.i_height = 576; psz_tmp = var_CreateGetNonEmptyStringCommand( p_intf, "fbosd-image" ); var_AddCallback( p_intf, "fbosd-image", OverlayCallback, NULL ); if( psz_tmp && *psz_tmp ) { p_sys->render[0].i_type = FBOSD_RENDER_IMAGE; p_sys->render[0].i_state = FBOSD_STATE_RENDER; p_sys->render[0].psz_string = strdup( psz_tmp ); } free( psz_tmp ); psz_tmp = var_CreateGetNonEmptyStringCommand( p_intf, "fbosd-text" ); var_AddCallback( p_intf, "fbosd-text", OverlayCallback, NULL ); if( psz_tmp && *psz_tmp ) { p_sys->render[1].i_type = FBOSD_RENDER_TEXT; p_sys->render[1].i_state = FBOSD_STATE_RENDER; p_sys->render[1].psz_string = strdup( psz_tmp ); } free( psz_tmp ); p_sys->i_pos = var_CreateGetIntegerCommand( p_intf, "fbosd-position" ); p_sys->i_x = var_CreateGetIntegerCommand( p_intf, "fbosd-x" ); p_sys->i_y = var_CreateGetIntegerCommand( p_intf, "fbosd-y" ); var_AddCallback( p_intf, "fbosd-position", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-x", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-y", OverlayCallback, NULL ); p_sys->p_style->i_font_size = var_CreateGetIntegerCommand( p_intf, "fbosd-font-size" ); p_sys->p_style->i_font_color = var_CreateGetIntegerCommand( p_intf, "fbosd-font-color" ); p_sys->p_style->i_font_alpha = 255 - var_CreateGetIntegerCommand( p_intf, "fbosd-font-opacity" ); var_AddCallback( p_intf, "fbosd-font-color", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-font-size", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-font-opacity", OverlayCallback, NULL ); for( i = 0; i < FBOSD_RENDER_MAX; i++ ) { vlc_memcpy( &p_sys->render[i].text_style, &default_text_style, sizeof( text_style_t ) ); } p_sys->b_clear = var_CreateGetBoolCommand( p_intf, "fbosd-clear" ); p_sys->b_render = var_CreateGetBoolCommand( p_intf, "fbosd-render" ); p_sys->b_need_update = var_CreateGetBoolCommand( p_intf, "fbosd-display" ); var_AddCallback( p_intf, "fbosd-clear", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-render", OverlayCallback, NULL ); var_AddCallback( p_intf, "fbosd-display", OverlayCallback, NULL ); /* Check if picture position was overridden */ p_sys->b_absolute = true; if( ( p_sys->i_x >= 0 ) && ( p_sys->i_y >= 0 ) ) { p_sys->b_absolute = false; p_sys->i_y = (p_sys->i_y < p_sys->i_height) ? p_sys->i_y : p_sys->i_height; p_sys->i_x = (p_sys->i_x < p_sys->i_width) ? p_sys->i_x : p_sys->i_width; } p_sys->render[0].i_x = p_sys->render[1].i_x = p_sys->i_x; p_sys->render[0].i_y = p_sys->render[1].i_y = p_sys->i_y; p_sys->render[0].i_pos = p_sys->render[1].i_pos = p_sys->i_pos; p_sys->render[0].i_alpha = p_sys->render[1].i_alpha = p_sys->i_alpha; /* Initialize framebuffer */ if( OpenDisplay( p_intf ) ) { Destroy( VLC_OBJECT(p_intf) ); return VLC_EGENERIC; } Init( p_intf );#if defined(FBOSD_BLENDING) /* Load the blending module */ if( OpenBlending( p_intf ) ) { msg_Err( p_intf, "Unable to load image blending module" ); Destroy( VLC_OBJECT(p_intf) ); return VLC_EGENERIC; }#endif /* Load text renderer module */ if( OpenTextRenderer( p_intf ) ) { msg_Err( p_intf, "Unable to load text rendering module" ); Destroy( VLC_OBJECT(p_intf) ); return VLC_EGENERIC; } p_sys->b_render = true; p_sys->b_need_update = true; return VLC_SUCCESS;}/***************************************************************************** * Destroy: destroy FB interface thread output method ***************************************************************************** * Terminate an output method created by Create *****************************************************************************/static void Destroy( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys = (intf_sys_t *) p_intf->p_sys; int i; p_sys->b_need_update = false; p_sys->b_render = false; p_sys->b_clear = false; var_DelCallback( p_intf, "fbosd-alpha", OverlayCallback, NULL ); var_Destroy( p_intf, "fbosd-alpha" ); var_DelCallback( p_intf, "fbosd-x", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-y", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-position", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-image", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-text", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-font-size", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-font-color", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-font-opacity", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-clear", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-render", OverlayCallback, NULL ); var_DelCallback( p_intf, "fbosd-display", OverlayCallback, NULL ); var_Destroy( p_intf, "fbosd-x" ); var_Destroy( p_intf, "fbosd-y" ); var_Destroy( p_intf, "fbosd-position" ); var_Destroy( p_intf, "fbosd-image" ); var_Destroy( p_intf, "fbosd-text" ); var_Destroy( p_intf, "fbosd-font-size" ); var_Destroy( p_intf, "fbosd-font-color" ); var_Destroy( p_intf, "fbosd-font-opacity" ); var_Destroy( p_intf, "fbosd-clear" ); var_Destroy( p_intf, "fbosd-render" ); var_Destroy( p_intf, "fbosd-display" ); var_Destroy( p_intf, "fbosd-aspect-ratio" ); CloseDisplay( p_intf ); for( i = 0; i < FBOSD_RENDER_MAX; i++ ) { free( p_sys->render[i].psz_string ); p_sys->render[i].i_state = FBOSD_STATE_FREE; }#if defined(FBOSD_BLENDING) if( p_sys->p_blend ) CloseBlending( p_intf );#endif if( p_sys->p_text ) CloseTextRenderer( p_intf ); if( p_sys->p_image ) image_HandlerDelete( p_sys->p_image ); if( p_sys->p_overlay ) picture_Release( p_sys->p_overlay ); free( p_sys->p_style ); free( p_sys );}#if defined(FBOSD_BLENDING)static int OpenBlending( intf_thread_t *p_intf ){ if( p_intf->p_sys->p_blend ) return VLC_EGENERIC; p_intf->p_sys->p_blend = vlc_object_create( p_intf, sizeof(filter_t) ); vlc_object_attach( p_intf->p_sys->p_blend, p_intf ); p_intf->p_sys->p_blend->fmt_out.video.i_x_offset = p_intf->p_sys->p_blend->fmt_out.video.i_y_offset = 0; p_intf->p_sys->p_blend->fmt_out.video.i_aspect = p_intf->p_sys->fmt_out.i_aspect; p_intf->p_sys->p_blend->fmt_out.video.i_chroma = p_intf->p_sys->fmt_out.i_chroma; if( config_GetInt( p_intf, "freetype-yuvp" ) ) p_intf->p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','P'); else p_intf->p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A'); p_intf->p_sys->p_blend->p_module = module_Need( p_intf->p_sys->p_blend, "video blending", 0, 0 ); if( !p_intf->p_sys->p_blend->p_module ) return VLC_EGENERIC; return VLC_SUCCESS;}static void CloseBlending( intf_thread_t *p_intf ){ if( p_intf->p_sys->p_blend ) { if( p_intf->p_sys->p_blend->p_module ) module_Unneed( p_intf->p_sys->p_blend, p_intf->p_sys->p_blend->p_module ); vlc_object_detach( p_intf->p_sys->p_blend ); vlc_object_release( p_intf->p_sys->p_blend ); }}#endifstatic int OpenTextRenderer( intf_thread_t *p_intf ){ char *psz_modulename = NULL; if( p_intf->p_sys->p_text ) return VLC_EGENERIC; p_intf->p_sys->p_text = vlc_object_create( p_intf, sizeof(filter_t) ); vlc_object_attach( p_intf->p_sys->p_text, p_intf ); p_intf->p_sys->p_text->fmt_out.video.i_width = p_intf->p_sys->p_text->fmt_out.video.i_visible_width = p_intf->p_sys->i_width; p_intf->p_sys->p_text->fmt_out.video.i_height = p_intf->p_sys->p_text->fmt_out.video.i_visible_height = p_intf->p_sys->i_height; psz_modulename = var_CreateGetString( p_intf, "text-renderer" ); if( psz_modulename && *psz_modulename ) { p_intf->p_sys->p_text->p_module = module_Need( p_intf->p_sys->p_text, "text renderer", psz_modulename, true ); } if( !p_intf->p_sys->p_text->p_module ) { p_intf->p_sys->p_text->p_module = module_Need( p_intf->p_sys->p_text, "text renderer", 0, 0 ); } free( psz_modulename ); if( !p_intf->p_sys->p_text->p_module ) return VLC_EGENERIC; return VLC_SUCCESS;}static void CloseTextRenderer( intf_thread_t *p_intf ){ if( p_intf->p_sys->p_text ) { if( p_intf->p_sys->p_text->p_module ) module_Unneed( p_intf->p_sys->p_text, p_intf->p_sys->p_text->p_module ); vlc_object_detach( p_intf->p_sys->p_text ); vlc_object_release( p_intf->p_sys->p_text ); }}/***************************************************************************** * AllocatePicture: * allocate a picture buffer for use with the overlay fb. *****************************************************************************/static picture_t *AllocatePicture( vlc_object_t *p_this, video_format_t *p_fmt ){ picture_t *p_picture = picture_New( p_fmt->i_chroma, p_fmt->i_width, p_fmt->i_height, p_fmt->i_aspect ); if( !p_picture ) return NULL; if( !p_fmt->p_palette && ( p_fmt->i_chroma == VLC_FOURCC('Y','U','V','P') ) ) { p_fmt->p_palette = malloc( sizeof(video_palette_t) ); if( !p_fmt->p_palette ) { picture_Release( p_picture ); return NULL; } } else { p_fmt->p_palette = NULL; } return p_picture;}/***************************************************************************** * DeAllocatePicture: * Deallocate a picture buffer and free all associated memory. *****************************************************************************/static void DeAllocatePicture( vlc_object_t *p_this, picture_t *p_pic, video_format_t *p_fmt ){ VLC_UNUSED(p_this); if( p_fmt ) { free( p_fmt->p_palette ); p_fmt->p_palette = NULL; } if( p_pic ) picture_Release( p_pic );}/***************************************************************************** * SetOverlayTransparency: Set the transparency for this overlay fb, * - true is make transparent * - false is make non tranparent *****************************************************************************/static void SetOverlayTransparency( intf_thread_t *p_intf, bool b_transparent ){ intf_sys_t *p_sys = (intf_sys_t *) p_intf->p_sys; size_t i_size = p_sys->fmt_out.i_width * p_sys->fmt_out.i_height * p_sys->i_bytes_per_pixel; size_t i_page_size = (p_sys->i_page_size > i_size) ? i_size : p_sys->i_page_size; if( p_sys->p_overlay ) { msg_Dbg( p_intf, "Make overlay %s", b_transparent ? "transparent" : "opaque" ); if( b_transparent ) memset( p_sys->p_overlay->p[0].p_pixels, 0xFF, i_page_size ); else memset( p_sys->p_overlay->p[0].p_pixels, 0x00, i_page_size ); }}#if defined(FBOSD_BLENDING)/***************************************************************************** * BlendPicture: Blend two pictures together.. *****************************************************************************/static int BlendPicture( intf_thread_t *p_intf, video_format_t *p_fmt_src, video_format_t *p_fmt_dst, picture_t *p_pic_src, picture_t *p_pic_dst ){ intf_sys_t *p_sys = (intf_sys_t *) p_intf->p_sys; if( p_sys->p_blend && p_sys->p_blend->p_module ) { int i_x_offset = p_sys->i_x; int i_y_offset = p_sys->i_y; memcpy( &p_sys->p_blend->fmt_in.video, p_fmt_src, sizeof( video_format_t ) ); /* Update the output picture size */ p_sys->p_blend->fmt_out.video.i_width = p_sys->p_blend->fmt_out.video.i_visible_width = p_fmt_dst->i_width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -