📄 deinterlace.c
字号:
/***************************************************************************** * deinterlace.c : deinterlacer plugin for vlc ***************************************************************************** * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team * $Id: 52d693de87050cb3db1c608384448dd1e861df87 $ * * Author: Sam Hocevar <sam@zoy.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <errno.h>#ifdef HAVE_ALTIVEC_H# include <altivec.h>#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_vout.h>#include <vlc_sout.h>#include "vlc_filter.h"#ifdef CAN_COMPILE_MMXEXT# include "mmx.h"#endif#include "filter_common.h"#define DEINTERLACE_DISCARD 1#define DEINTERLACE_MEAN 2#define DEINTERLACE_BLEND 3#define DEINTERLACE_BOB 4#define DEINTERLACE_LINEAR 5#define DEINTERLACE_X 6/***************************************************************************** * Local protypes *****************************************************************************/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 void Render ( vout_thread_t *, picture_t * );static void RenderDiscard( vout_thread_t *, picture_t *, picture_t *, int );static void RenderBob ( vout_thread_t *, picture_t *, picture_t *, int );static void RenderMean ( vout_thread_t *, picture_t *, picture_t * );static void RenderBlend ( vout_thread_t *, picture_t *, picture_t * );static void RenderLinear ( vout_thread_t *, picture_t *, picture_t *, int );static void RenderX ( picture_t *, picture_t * );static void MergeGeneric ( void *, const void *, const void *, size_t );#if defined(CAN_COMPILE_C_ALTIVEC)static void MergeAltivec ( void *, const void *, const void *, size_t );#endif#if defined(CAN_COMPILE_MMXEXT)static void MergeMMXEXT ( void *, const void *, const void *, size_t );#endif#if defined(CAN_COMPILE_3DNOW)static void Merge3DNow ( void *, const void *, const void *, size_t );#endif#if defined(CAN_COMPILE_SSE)static void MergeSSE2 ( void *, const void *, const void *, size_t );#endif#if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)static void EndMMX ( void );#endif#if defined(CAN_COMPILE_3DNOW)static void End3DNow ( void );#endifstatic int SendEvents ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method );static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout );static int OpenFilter( vlc_object_t *p_this );static void CloseFilter( vlc_object_t *p_this );/***************************************************************************** * Callback prototypes *****************************************************************************/static int FilterCallback ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * );/***************************************************************************** * Module descriptor *****************************************************************************/#define MODE_TEXT N_("Deinterlace mode")#define MODE_LONGTEXT N_("Deinterlace method to use for local playback.")#define SOUT_MODE_TEXT N_("Streaming deinterlace mode")#define SOUT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")#define FILTER_CFG_PREFIX "sout-deinterlace-"static const char *const mode_list[] = { "discard", "blend", "mean", "bob", "linear", "x" };static const char *const mode_list_text[] = { N_("Discard"), N_("Blend"), N_("Mean"), N_("Bob"), N_("Linear"), "X" };vlc_module_begin(); set_description( N_("Deinterlacing video filter") ); set_shortname( N_("Deinterlace" )); set_capability( "video filter", 0 ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_VFILTER ); set_section( N_("Display"),NULL); add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT, MODE_LONGTEXT, false ); change_string_list( mode_list, mode_list_text, 0 ); add_shortcut( "deinterlace" ); set_callbacks( Create, Destroy ); add_submodule(); set_capability( "video filter2", 0 ); set_section( N_("Streaming"),NULL); add_string( FILTER_CFG_PREFIX "mode", "blend", NULL, SOUT_MODE_TEXT, SOUT_MODE_LONGTEXT, false ); change_string_list( mode_list, mode_list_text, 0 ); set_callbacks( OpenFilter, CloseFilter );vlc_module_end();static const char *const ppsz_filter_options[] = { "mode", NULL};/***************************************************************************** * vout_sys_t: Deinterlace video output method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the Deinterlace specific properties of an output thread. *****************************************************************************/struct vout_sys_t{ int i_mode; /* Deinterlace mode */ bool b_double_rate; /* Shall we double the framerate? */ bool b_half_height; /* Shall be devide the height by 2 */ mtime_t last_date; mtime_t next_date; vout_thread_t *p_vout; vlc_mutex_t filter_lock; void (*pf_merge) ( void *, const void *, const void *, size_t ); void (*pf_end_merge) ( void );};/***************************************************************************** * Control: control facility for the vout (forwards to child vout) *****************************************************************************/static int Control( vout_thread_t *p_vout, int i_query, va_list args ){ return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );}/***************************************************************************** * Create: allocates Deinterlace video thread output method ***************************************************************************** * This function allocates and initializes a Deinterlace vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){ vout_thread_t *p_vout = (vout_thread_t *)p_this; vlc_value_t val; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; 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_vout->p_sys->i_mode = DEINTERLACE_DISCARD; p_vout->p_sys->b_double_rate = false; p_vout->p_sys->b_half_height = true; p_vout->p_sys->last_date = 0; p_vout->p_sys->p_vout = 0; vlc_mutex_init( &p_vout->p_sys->filter_lock );#if defined(CAN_COMPILE_C_ALTIVEC) if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC ) { p_vout->p_sys->pf_merge = MergeAltivec; p_vout->p_sys->pf_end_merge = NULL; } else#endif#if defined(CAN_COMPILE_SSE) if( vlc_CPU() & CPU_CAPABILITY_SSE2 ) { p_vout->p_sys->pf_merge = MergeSSE2; p_vout->p_sys->pf_end_merge = EndMMX; } else#endif#if defined(CAN_COMPILE_MMXEXT) if( vlc_CPU() & CPU_CAPABILITY_MMXEXT ) { p_vout->p_sys->pf_merge = MergeMMXEXT; p_vout->p_sys->pf_end_merge = EndMMX; } else#endif#if defined(CAN_COMPILE_3DNOW) if( vlc_CPU() & CPU_CAPABILITY_3DNOW ) { p_vout->p_sys->pf_merge = Merge3DNow; p_vout->p_sys->pf_end_merge = End3DNow; } else#endif { p_vout->p_sys->pf_merge = MergeGeneric; p_vout->p_sys->pf_end_merge = NULL; } /* Look what method was requested */ var_Create( p_vout, "deinterlace-mode", VLC_VAR_STRING ); var_Change( p_vout, "deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL ); if( val.psz_string == NULL ) { msg_Err( p_vout, "configuration variable deinterlace-mode empty" ); msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" ); val.psz_string = strdup( "discard" ); } msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string ); SetFilterMethod( p_vout, val.psz_string ); free( val.psz_string ); return VLC_SUCCESS;}/***************************************************************************** * SetFilterMethod: setup the deinterlace method to use. *****************************************************************************/static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method ){ if( !strcmp( psz_method, "mean" ) ) { p_vout->p_sys->i_mode = DEINTERLACE_MEAN; p_vout->p_sys->b_double_rate = false; p_vout->p_sys->b_half_height = true; } else if( !strcmp( psz_method, "blend" ) || !strcmp( psz_method, "average" ) || !strcmp( psz_method, "combine-fields" ) ) { p_vout->p_sys->i_mode = DEINTERLACE_BLEND; p_vout->p_sys->b_double_rate = false; p_vout->p_sys->b_half_height = false; } else if( !strcmp( psz_method, "bob" ) || !strcmp( psz_method, "progressive-scan" ) ) { p_vout->p_sys->i_mode = DEINTERLACE_BOB; p_vout->p_sys->b_double_rate = true; p_vout->p_sys->b_half_height = false; } else if( !strcmp( psz_method, "linear" ) ) { p_vout->p_sys->i_mode = DEINTERLACE_LINEAR; p_vout->p_sys->b_double_rate = true; p_vout->p_sys->b_half_height = false; } else if( !strcmp( psz_method, "x" ) ) { p_vout->p_sys->i_mode = DEINTERLACE_X; p_vout->p_sys->b_double_rate = false; p_vout->p_sys->b_half_height = false; } else { if( strcmp( psz_method, "discard" ) ) msg_Err( p_vout, "no valid deinterlace mode provided, " "using \"discard\"" ); p_vout->p_sys->i_mode = DEINTERLACE_DISCARD; p_vout->p_sys->b_double_rate = false; p_vout->p_sys->b_half_height = true; } msg_Dbg( p_vout, "using %s deinterlace method", psz_method );}/***************************************************************************** * Init: initialize Deinterlace video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){ int i_index; picture_t *p_pic; I_OUTPUTPICTURES = 0; /* Initialize the output structure, full of directbuffers since we want * the decoder to output directly to our structures. */ switch( p_vout->render.i_chroma ) { case VLC_FOURCC('I','4','2','0'): case VLC_FOURCC('I','Y','U','V'): case VLC_FOURCC('Y','V','1','2'): case VLC_FOURCC('I','4','2','2'): 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; break; default: return VLC_EGENERIC; /* unknown chroma */ break; } /* Try to open the real video output */ p_vout->p_sys->p_vout = SpawnRealVout( p_vout ); if( p_vout->p_sys->p_vout == NULL ) { /* Everything failed */ msg_Err( p_vout, "cannot open vout, aborting" ); return VLC_EGENERIC; } var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL ); ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES ); ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); ADD_PARENT_CALLBACKS( SendEventsToChild ); return VLC_SUCCESS;}/***************************************************************************** * SpawnRealVout: spawn the real video output. *****************************************************************************/static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout ){ vout_thread_t *p_real_vout = NULL; video_format_t fmt; memset( &fmt, 0, sizeof( video_format_t ) ); msg_Dbg( p_vout, "spawning the real video output" ); fmt = p_vout->fmt_out; switch( p_vout->render.i_chroma ) { case VLC_FOURCC('I','4','2','0'): case VLC_FOURCC('I','Y','U','V'): case VLC_FOURCC('Y','V','1','2'): if( p_vout->p_sys->b_half_height ) { fmt.i_height /= 2; fmt.i_visible_height /= 2; fmt.i_y_offset /= 2; fmt.i_sar_den *= 2; } p_real_vout = vout_Create( p_vout, &fmt ); break; case VLC_FOURCC('I','4','2','2'): fmt.i_chroma = VLC_FOURCC('I','4','2','0'); p_real_vout = vout_Create( p_vout, &fmt ); break; default: break; } return p_real_vout;}/***************************************************************************** * End: terminate Deinterlace video thread output method *****************************************************************************/static void End( vout_thread_t *p_vout ){ int i_index; DEL_PARENT_CALLBACKS( SendEventsToChild ); if( p_vout->p_sys->p_vout ) DEL_CALLBACKS( p_vout->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 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -