Skip to content

Commit a98e47e

Browse files
author
Rémi Denis-Courmont
committed
chain: use variable inheritance instead of config chain
It was rather confusing for a conversion plugin to parse the chain. (Then again, variable inheritance is also ugly in its own ways. Recursion should be prevented in a more controlled manner.)
1 parent ba6144f commit a98e47e

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

modules/video_chroma/chain.c

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int BuildTransformChain( filter_t *p_filter );
5555
static int BuildChromaResize( filter_t * );
5656
static int BuildChromaChain( filter_t *p_filter );
5757

58-
static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid, config_chain_t * );
58+
static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid );
5959
static filter_t * AppendTransform( filter_chain_t *p_chain, es_format_t *p_fmt_in, es_format_t *p_fmt_out );
6060
static void EsFormatMergeSize( es_format_t *p_dst,
6161
const es_format_t *p_base,
@@ -124,7 +124,18 @@ static int Activate( vlc_object_t *p_this )
124124
return VLC_EGENERIC;
125125
}
126126

127-
if( b_transform )
127+
int type = VLC_VAR_INTEGER;
128+
if( var_Type( p_filter->obj.parent, MODULE_STRING "-level" ) != 0 )
129+
type |= VLC_VAR_DOINHERIT;
130+
131+
var_Create( p_filter, MODULE_STRING "-level", type );
132+
/* Note: atomicity is not actually needed here. */
133+
var_IncInteger( p_filter, MODULE_STRING "-level" );
134+
135+
int level = var_GetInteger( p_filter, MODULE_STRING "-level" );
136+
if( level < 0 || level > CHAIN_LEVEL_MAX )
137+
msg_Err( p_filter, "Too high level of recursion (%d)", level );
138+
else if( b_transform )
128139
i_ret = BuildTransformChain( p_filter );
129140
else if( b_chroma && b_resize )
130141
i_ret = BuildChromaResize( p_filter );
@@ -136,6 +147,7 @@ static int Activate( vlc_object_t *p_this )
136147
if( i_ret )
137148
{
138149
/* Hum ... looks like this really isn't going to work. Too bad. */
150+
var_Destroy( p_filter, MODULE_STRING "-level" );
139151
filter_chain_Delete( p_sys->p_chain );
140152
free( p_sys );
141153
return VLC_EGENERIC;
@@ -148,6 +160,8 @@ static int Activate( vlc_object_t *p_this )
148160
static void Destroy( vlc_object_t *p_this )
149161
{
150162
filter_t *p_filter = (filter_t *)p_this;
163+
164+
var_Destroy( p_filter, MODULE_STRING "-level" );
151165
filter_chain_Delete( p_filter->p_sys->p_chain );
152166
free( p_filter->p_sys );
153167
}
@@ -174,15 +188,15 @@ static int BuildTransformChain( filter_t *p_filter )
174188
msg_Dbg( p_filter, "Trying to build transform, then chroma+resize" );
175189
es_format_Copy( &fmt_mid, &p_filter->fmt_in );
176190
video_format_TransformTo(&fmt_mid.video, p_filter->fmt_out.video.orientation);
177-
i_ret = CreateChain( p_filter, &fmt_mid, NULL );
191+
i_ret = CreateChain( p_filter, &fmt_mid );
178192
es_format_Clean( &fmt_mid );
179193
if( i_ret == VLC_SUCCESS )
180194
return VLC_SUCCESS;
181195

182196
/* Lets try resize+chroma first, then transform */
183197
msg_Dbg( p_filter, "Trying to build chroma+resize" );
184198
EsFormatMergeSize( &fmt_mid, &p_filter->fmt_out, &p_filter->fmt_in );
185-
i_ret = CreateChain( p_filter, &fmt_mid, NULL );
199+
i_ret = CreateChain( p_filter, &fmt_mid );
186200
es_format_Clean( &fmt_mid );
187201
if( i_ret == VLC_SUCCESS )
188202
return VLC_SUCCESS;
@@ -198,15 +212,15 @@ static int BuildChromaResize( filter_t *p_filter )
198212
/* Lets try resizing and then doing the chroma conversion */
199213
msg_Dbg( p_filter, "Trying to build resize+chroma" );
200214
EsFormatMergeSize( &fmt_mid, &p_filter->fmt_in, &p_filter->fmt_out );
201-
i_ret = CreateChain( p_filter, &fmt_mid, NULL );
215+
i_ret = CreateChain( p_filter, &fmt_mid );
202216
es_format_Clean( &fmt_mid );
203217
if( i_ret == VLC_SUCCESS )
204218
return VLC_SUCCESS;
205219

206220
/* Lets try it the other way arround (chroma and then resize) */
207221
msg_Dbg( p_filter, "Trying to build chroma+resize" );
208222
EsFormatMergeSize( &fmt_mid, &p_filter->fmt_out, &p_filter->fmt_in );
209-
i_ret = CreateChain( p_filter, &fmt_mid, NULL );
223+
i_ret = CreateChain( p_filter, &fmt_mid );
210224
es_format_Clean( &fmt_mid );
211225
if( i_ret == VLC_SUCCESS )
212226
return VLC_SUCCESS;
@@ -217,35 +231,7 @@ static int BuildChromaResize( filter_t *p_filter )
217231
static int BuildChromaChain( filter_t *p_filter )
218232
{
219233
es_format_t fmt_mid;
220-
221-
/* We have to protect ourself against a too high recursion */
222-
const char *psz_option = MODULE_STRING"-level";
223-
int i_level = 0;
224-
for( const config_chain_t *c = p_filter->p_cfg; c != NULL; c = c->p_next)
225-
{
226-
if( c->psz_name && c->psz_value && !strcmp(c->psz_name, psz_option) )
227-
{
228-
i_level = atoi(c->psz_value);
229-
if( i_level < 0 || i_level > CHAIN_LEVEL_MAX )
230-
{
231-
msg_Err( p_filter, "Too high level of recursion (%d)", i_level );
232-
return VLC_EGENERIC;
233-
}
234-
break;
235-
}
236-
}
237-
238-
/* */
239-
int i_ret = VLC_EGENERIC;
240-
241-
/* */
242-
config_chain_t cfg_level;
243-
memset(&cfg_level, 0, sizeof(cfg_level));
244-
cfg_level.psz_name = strdup(psz_option);
245-
if( asprintf( &cfg_level.psz_value, "%d", i_level + 1) < 0 )
246-
cfg_level.psz_value = NULL;
247-
if( !cfg_level.psz_name || !cfg_level.psz_value )
248-
goto exit;
234+
int i_ret;
249235

250236
/* Now try chroma format list */
251237
for( int i = 0; pi_allowed_chromas[i]; i++ )
@@ -266,23 +252,21 @@ static int BuildChromaChain( filter_t *p_filter )
266252
fmt_mid.video.i_bmask = 0;
267253
video_format_FixRgb(&fmt_mid.video);
268254

269-
i_ret = CreateChain( p_filter, &fmt_mid, &cfg_level );
255+
i_ret = CreateChain( p_filter, &fmt_mid );
270256
es_format_Clean( &fmt_mid );
271257

272258
if( i_ret == VLC_SUCCESS )
273259
break;
274260
}
275261

276-
exit:
277-
free( cfg_level.psz_name );
278-
free( cfg_level.psz_value );
262+
var_Destroy( p_filter, MODULE_STRING "-level" );
279263
return i_ret;
280264
}
281265

282266
/*****************************************************************************
283267
*
284268
*****************************************************************************/
285-
static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid, config_chain_t *p_cfg )
269+
static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid )
286270
{
287271
filter_chain_Reset( p_parent->p_sys->p_chain, &p_parent->fmt_in, &p_parent->fmt_out );
288272

@@ -294,7 +278,7 @@ static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid, config_chain
294278
}
295279
else
296280
{
297-
p_filter = filter_chain_AppendFilter( p_parent->p_sys->p_chain, NULL, p_cfg, NULL, p_fmt_mid );
281+
p_filter = filter_chain_AppendFilter( p_parent->p_sys->p_chain, NULL, NULL, NULL, p_fmt_mid );
298282
}
299283

300284
if( !p_filter )
@@ -310,7 +294,7 @@ static int CreateChain( filter_t *p_parent, es_format_t *p_fmt_mid, config_chain
310294
}
311295
else
312296
{
313-
p_filter = filter_chain_AppendFilter( p_parent->p_sys->p_chain, NULL, p_cfg, p_fmt_mid, NULL );
297+
p_filter = filter_chain_AppendFilter( p_parent->p_sys->p_chain, NULL, NULL, p_fmt_mid, NULL );
314298
}
315299

316300
if( !p_filter )

0 commit comments

Comments
 (0)