+
+/*****************************************************************************
+ * Builders
+ *****************************************************************************/
+static int BuildChromaResize( filter_t *p_filter )
+{
+ filter_sys_t *p_sys = p_filter->p_sys;
+ es_format_t fmt_mid;
+ int i_ret;
+
+ /* Lets try resizing and then doing the chroma conversion */
+ msg_Dbg( p_filter, "Trying to build resize+chroma" );
+ EsFormatMergeSize( &fmt_mid, &p_filter->fmt_in, &p_filter->fmt_out );
+ i_ret = CreateChain( p_sys->p_chain, &fmt_mid );
+ es_format_Clean( &fmt_mid );
+ if( i_ret == VLC_SUCCESS )
+ return VLC_SUCCESS;
+
+ /* Lets try it the other way arround (chroma and then resize) */
+ msg_Dbg( p_filter, "Trying to build chroma+resize" );
+ EsFormatMergeSize( &fmt_mid, &p_filter->fmt_out, &p_filter->fmt_in );
+ i_ret = CreateChain( p_sys->p_chain, &fmt_mid );
+ es_format_Clean( &fmt_mid );
+ if( i_ret == VLC_SUCCESS )
+ return VLC_SUCCESS;
+
+ return VLC_EGENERIC;
+}
+
+static int BuildChromaChain( filter_t *p_filter )
+{
+ filter_sys_t *p_sys = p_filter->p_sys;
+ es_format_t fmt_mid;
+ int i_ret;
+ int i;
+
+ /* We have to protect ourself against a too high recursion */
+ const char *psz_option = MODULE_STRING"-level";
+ bool b_first = !var_Type( p_filter, psz_option );
+
+ if( var_Create( p_filter, MODULE_STRING"-level", VLC_VAR_INTEGER | (b_first ? VLC_VAR_DOINHERIT : 0 ) ) )
+ {
+ msg_Err( p_filter, "Failed to create %s variable\n", psz_option );
+ return VLC_EGENERIC;
+ }
+ int i_level = var_GetInteger( p_filter, psz_option );
+ if( i_level >= CHAIN_LEVEL_MAX )
+ {
+ msg_Err( p_filter, "Too high level of recursion (%d)\n", i_level );
+ return VLC_EGENERIC;
+ }
+ var_SetInteger( p_filter, psz_option, i_level + 1 );
+
+ /* Now try chroma format list */
+ for( i = 0; pi_allowed_chromas[i]; i++ )
+ {
+ const vlc_fourcc_t i_chroma = pi_allowed_chromas[i];
+
+ msg_Dbg( p_filter, "Trying to use chroma %4.4s as middle man",
+ (char*)&i_chroma );
+
+ es_format_Copy( &fmt_mid, &p_filter->fmt_in );
+ fmt_mid.video.i_chroma = i_chroma;
+
+ i_ret = CreateChain( p_sys->p_chain, &fmt_mid );
+ es_format_Clean( &fmt_mid );
+
+ if( i_ret == VLC_SUCCESS )
+ return VLC_SUCCESS;
+ }
+ return VLC_EGENERIC;
+}
+
+/*****************************************************************************
+ * Buffer management
+ *****************************************************************************/
+static picture_t *BufferNew( filter_t *p_filter )
+{
+ filter_t *p_parent = (filter_t*)p_filter->p_owner;
+
+ return p_parent->pf_vout_buffer_new( p_parent );
+}
+static void BufferDel( filter_t *p_filter, picture_t *p_pic )
+{
+ filter_t *p_parent = (filter_t*)p_filter->p_owner;
+
+ p_parent->pf_vout_buffer_del( p_parent, p_pic );
+}
+static int BufferAllocationInit ( filter_t *p_filter, void *p_data )
+{
+ p_filter->pf_vout_buffer_new = BufferNew;
+ p_filter->pf_vout_buffer_del = BufferDel;
+ p_filter->p_owner = p_data;
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+static int CreateChain( filter_chain_t *p_chain, es_format_t *p_fmt_mid )
+{
+ filter_t *p_filter1;
+ if( !( p_filter1 =
+ filter_chain_AppendFilter( p_chain, NULL, NULL, NULL, p_fmt_mid )) )
+ return VLC_EGENERIC;
+ if( !filter_chain_AppendFilter( p_chain, NULL, NULL, p_fmt_mid, NULL ) )
+ {
+ filter_chain_DeleteFilter( p_chain, p_filter1 );
+ return VLC_EGENERIC;
+ }
+ return VLC_SUCCESS;
+}
+
+static void EsFormatMergeSize( es_format_t *p_dst,
+ const es_format_t *p_base,
+ const es_format_t *p_size )
+{
+ es_format_Copy( p_dst, p_base );
+
+ p_dst->video.i_width = p_size->video.i_width;
+ p_dst->video.i_height = p_size->video.i_height;
+
+ p_dst->video.i_visible_width = p_size->video.i_visible_width;
+ p_dst->video.i_visible_height = p_size->video.i_visible_height;
+}
+