+ *frame = mlt_frame_init( service );
+ result = 0;
+ }
+
+ // Pass on all meta properties from the producer/cut on to the frame
+ if ( *frame != NULL && self != NULL )
+ {
+ int i = 0;
+ mlt_properties p_props = MLT_PRODUCER_PROPERTIES( self );
+ mlt_properties f_props = MLT_FRAME_PROPERTIES( *frame );
+ mlt_properties_lock( p_props );
+ int count = mlt_properties_count( p_props );
+ for ( i = 0; i < count; i ++ )
+ {
+ char *name = mlt_properties_get_name( p_props, i );
+ if ( !strncmp( name, "meta.", 5 ) )
+ mlt_properties_set( f_props, name, mlt_properties_get_value( p_props, i ) );
+ else if ( !strncmp( name, "set.", 4 ) )
+ mlt_properties_set( f_props, name + 4, mlt_properties_get_value( p_props, i ) );
+ }
+ mlt_properties_unlock( p_props );
+ }
+
+ return result;
+}
+
+/** Attach a filter.
+ *
+ * \public \memberof mlt_producer_s
+ * \param self a producer
+ * \param filter the filter to attach
+ * \return true if there was an error
+ */
+
+int mlt_producer_attach( mlt_producer self, mlt_filter filter )
+{
+ return mlt_service_attach( MLT_PRODUCER_SERVICE( self ), filter );
+}
+
+/** Detach a filter.
+ *
+ * \public \memberof mlt_producer_s
+ * \param self a service
+ * \param filter the filter to detach
+ * \return true if there was an error
+ */
+
+int mlt_producer_detach( mlt_producer self, mlt_filter filter )
+{
+ return mlt_service_detach( MLT_PRODUCER_SERVICE( self ), filter );
+}
+
+/** Retrieve a filter.
+ *
+ * \public \memberof mlt_producer_s
+ * \param self a service
+ * \param index which filter to retrieve
+ * \return the filter or null if there was an error
+ */
+
+mlt_filter mlt_producer_filter( mlt_producer self, int index )
+{
+ return mlt_service_filter( MLT_PRODUCER_SERVICE( self ), index );
+}
+
+/** Clone a producer.
+ *
+ * \private \memberof mlt_producer_s
+ * \param self a producer
+ * \return a new producer that is a copy of \p self
+ * \see mlt_producer_set_clones
+ */
+
+static mlt_producer mlt_producer_clone( mlt_producer self )
+{
+ mlt_producer clone = NULL;
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( self );
+ char *resource = mlt_properties_get( properties, "resource" );
+ char *service = mlt_properties_get( properties, "mlt_service" );
+ mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( self ) );
+
+ mlt_events_block( mlt_factory_event_object( ), mlt_factory_event_object( ) );
+
+ if ( service != NULL )
+ clone = mlt_factory_producer( profile, service, resource );
+
+ if ( clone == NULL && resource != NULL )
+ clone = mlt_factory_producer( profile, NULL, resource );
+
+ if ( clone != NULL )
+ mlt_properties_inherit( MLT_PRODUCER_PROPERTIES( clone ), properties );
+
+ mlt_events_unblock( mlt_factory_event_object( ), mlt_factory_event_object( ) );
+
+ return clone;
+}
+
+/** Create clones.
+ *
+ * \private \memberof mlt_producer_s
+ * \param self a producer
+ * \param clones the number of copies to make
+ * \see mlt_producer_optimise
+ */
+
+static void mlt_producer_set_clones( mlt_producer self, int clones )
+{
+ mlt_producer parent = mlt_producer_cut_parent( self );
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( parent );
+ int existing = mlt_properties_get_int( properties, "_clones" );
+ int i = 0;
+ char key[ 25 ];
+
+ // If the number of existing clones is different, then create/remove as necessary
+ if ( existing != clones )
+ {
+ if ( existing < clones )
+ {
+ for ( i = existing; i < clones; i ++ )
+ {
+ mlt_producer clone = mlt_producer_clone( parent );
+ sprintf( key, "_clone.%d", i );
+ mlt_properties_set_data( properties, key, clone, 0, ( mlt_destructor )mlt_producer_close, NULL );
+ }
+ }
+ else
+ {
+ for ( i = clones; i < existing; i ++ )
+ {
+ sprintf( key, "_clone.%d", i );
+ mlt_properties_set_data( properties, key, NULL, 0, NULL, NULL );
+ }
+ }
+ }
+
+ // Ensure all properties on the parent are passed to the clones
+ for ( i = 0; i < clones; i ++ )
+ {
+ mlt_producer clone = NULL;
+ sprintf( key, "_clone.%d", i );
+ clone = mlt_properties_get_data( properties, key, NULL );
+ if ( clone != NULL )
+ mlt_properties_pass( MLT_PRODUCER_PROPERTIES( clone ), properties, "" );
+ }
+
+ // Update the number of clones on the properties
+ mlt_properties_set_int( properties, "_clones", clones );
+}
+
+/** \brief private to mlt_producer_s, used by mlt_producer_optimise() */
+
+typedef struct
+{
+ int multitrack;
+ int track;
+ int position;
+ int length;
+ int offset;
+}
+track_info;