]> git.sesse.net Git - vlc/blob - src/video_output/postprocessing.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / video_output / postprocessing.c
1 /*****************************************************************************
2  * postprocessing.c
3  *****************************************************************************
4  * Copyright (C) 2010 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <assert.h>
28
29 #include <vlc_common.h>
30 #include <vlc_vout.h>
31
32 #include "postprocessing.h"
33
34 static bool PostProcessIsPresent( const char *psz_filter )
35 {
36     const char  *psz_pp = "postproc";
37     const size_t i_pp = strlen(psz_pp);
38     return psz_filter &&
39            !strncmp( psz_filter, psz_pp, strlen(psz_pp) ) &&
40            ( psz_filter[i_pp] == '\0' || psz_filter[i_pp] == ':' );
41 }
42
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 )
45 {
46     vout_thread_t *p_vout = (vout_thread_t *)p_this;
47     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
48
49     static const char *psz_pp = "postproc";
50
51     char *psz_vf2 = var_GetString( p_vout, "video-filter" );
52
53     if( newval.i_int <= 0 )
54     {
55         if( PostProcessIsPresent( psz_vf2 ) )
56         {
57             strcpy( psz_vf2, &psz_vf2[strlen(psz_pp)] );
58             if( *psz_vf2 == ':' )
59                 strcpy( psz_vf2, &psz_vf2[1] );
60         }
61     }
62     else
63     {
64         if( !PostProcessIsPresent( psz_vf2 ) )
65         {
66             if( psz_vf2 )
67             {
68                 char *psz_tmp = psz_vf2;
69                 if( asprintf( &psz_vf2, "%s:%s", psz_pp, psz_tmp ) < 0 )
70                     psz_vf2 = psz_tmp;
71                 else
72                     free( psz_tmp );
73             }
74             else
75             {
76                 psz_vf2 = strdup( psz_pp );
77             }
78         }
79     }
80     if( newval.i_int > 0 )
81         var_SetInteger( p_vout, "postproc-q", newval.i_int );
82     if( psz_vf2 )
83     {
84         var_SetString( p_vout, "video-filter", psz_vf2 );
85         free( psz_vf2 );
86     }
87     else if( newval.i_int > 0 )
88     {
89         var_TriggerCallback( p_vout, "video-filter" );
90     }
91     return VLC_SUCCESS;
92 }
93 static void PostProcessEnable( vout_thread_t *p_vout )
94 {
95     vlc_value_t text;
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 );
100
101     for( int i = 0; i <= 6; i++ )
102     {
103         vlc_value_t val;
104         vlc_value_t text;
105         char psz_text[1+1];
106
107         val.i_int = i;
108         snprintf( psz_text, sizeof(psz_text), "%d", i );
109         if( i == 0 )
110             text.psz_string = _("Disable");
111         else
112             text.psz_string = psz_text;
113         var_Change( p_vout, "postprocess", VLC_VAR_ADDCHOICE, &val, &text );
114     }
115     var_AddCallback( p_vout, "postprocess", PostProcessCallback, NULL );
116
117     /* */
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" );
122
123     var_SetInteger( p_vout, "postprocess", i_postproc_q );
124
125     free( psz_filter );
126 }
127 static void PostProcessDisable( vout_thread_t *p_vout )
128 {
129     msg_Dbg( p_vout, "Post-processing no more available" );
130     var_Destroy( p_vout, "postprocess" );
131 }
132
133 void vout_SetPostProcessingState(vout_thread_t *vout, vout_postprocessing_support_t *state, int qtype)
134 {
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);
140         if (postproc_change)
141                 state->qtype = qtype;
142 }
143