1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
32 #include "postprocessing.h"
34 static bool PostProcessIsPresent( const char *psz_filter )
36 const char *psz_pp = "postproc";
37 const size_t i_pp = strlen(psz_pp);
39 !strncmp( psz_filter, psz_pp, strlen(psz_pp) ) &&
40 ( psz_filter[i_pp] == '\0' || psz_filter[i_pp] == ':' );
43 static int PostProcessCallback( vlc_object_t *p_this, char const *psz_cmd,
44 vlc_value_t oldval, vlc_value_t newval, void *p_data )
46 vout_thread_t *p_vout = (vout_thread_t *)p_this;
47 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
49 static const char *psz_pp = "postproc";
51 char *psz_vf2 = var_GetString( p_vout, "video-filter" );
53 if( newval.i_int <= 0 )
55 if( PostProcessIsPresent( psz_vf2 ) )
57 strcpy( psz_vf2, &psz_vf2[strlen(psz_pp)] );
59 strcpy( psz_vf2, &psz_vf2[1] );
64 if( !PostProcessIsPresent( psz_vf2 ) )
68 char *psz_tmp = psz_vf2;
69 if( asprintf( &psz_vf2, "%s:%s", psz_pp, psz_tmp ) < 0 )
76 psz_vf2 = strdup( psz_pp );
80 if( newval.i_int > 0 )
81 var_SetInteger( p_vout, "postproc-q", newval.i_int );
84 var_SetString( p_vout, "video-filter", psz_vf2 );
87 else if( newval.i_int > 0 )
89 var_TriggerCallback( p_vout, "video-filter" );
93 static void PostProcessEnable( vout_thread_t *p_vout )
96 msg_Dbg( p_vout, "Post-processing available" );
97 var_Create( p_vout, "postprocess", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
98 text.psz_string = _("Post processing");
99 var_Change( p_vout, "postprocess", VLC_VAR_SETTEXT, &text, NULL );
101 for( int i = 0; i <= 6; i++ )
108 snprintf( psz_text, sizeof(psz_text), "%d", i );
110 text.psz_string = _("Disable");
112 text.psz_string = psz_text;
113 var_Change( p_vout, "postprocess", VLC_VAR_ADDCHOICE, &val, &text );
115 var_AddCallback( p_vout, "postprocess", PostProcessCallback, NULL );
118 char *psz_filter = var_GetNonEmptyString( p_vout, "video-filter" );
119 int i_postproc_q = 0;
120 if( PostProcessIsPresent( psz_filter ) )
121 i_postproc_q = var_CreateGetInteger( p_vout, "postproc-q" );
123 var_SetInteger( p_vout, "postprocess", i_postproc_q );
127 static void PostProcessDisable( vout_thread_t *p_vout )
129 msg_Dbg( p_vout, "Post-processing no more available" );
130 var_Destroy( p_vout, "postprocess" );
133 void vout_SetPostProcessingState(vout_thread_t *vout, vout_postprocessing_support_t *state, int qtype)
135 const int postproc_change = (qtype != QTYPE_NONE) - (state->qtype != QTYPE_NONE);
136 if (postproc_change == 1)
137 PostProcessEnable(vout);
138 else if (postproc_change == -1)
139 PostProcessDisable(vout);
141 state->qtype = qtype;