Yet more sdl hacking, region memory leak fix, mlt_position changed to int32_t, experi...
[melted] / src / modules / core / filter_region.c
index 8e11f37..b6ef970 100644 (file)
@@ -66,6 +66,10 @@ static int create_instance( mlt_filter this, char *name, char *value, int count
                // Counstruct key
                sprintf( key, "%s.", name );
 
+               // Just in case, let's assume that the filter here has a composite
+               mlt_properties_set( mlt_filter_properties( filter ), "composite.start", "0%,0%:100%x100%" );
+               mlt_properties_set( mlt_filter_properties( filter ), "composite.fill", "true" );
+
                // Pass all the key properties on the filter down
                mlt_properties_pass( mlt_filter_properties( filter ), properties, key );
 
@@ -114,6 +118,12 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Look for the first filter
        mlt_filter filter = mlt_properties_get_data( properties, "_filter_0", NULL );
 
+       // Get the unique id of the filter (used to reacquire the producer position)
+       char *name = mlt_properties_get( properties, "_unique_id" );
+
+       // Get the original producer position
+       mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
+
        // Create a composite if we don't have one
        if ( composite == NULL )
        {
@@ -172,6 +182,9 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Only continue if we have both filter and composite
        if ( composite != NULL && filter != NULL )
        {
+               // Get the resource of this filter (could be a shape [rectangle/circle] or an alpha provider of choice
+               char *resource =  mlt_properties_get( properties, "resource" );
+
                // String to hold the filter to query on
                char id[ 256 ];
 
@@ -179,7 +192,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                int i = 0;
 
                // We will get the 'b frame' from the composite
-               mlt_frame b_frame = composite_copy_region( composite, frame );
+               mlt_frame b_frame = composite_copy_region( composite, frame, position );
 
                // Make sure the filter is in the correct position
                while ( filter != NULL )
@@ -194,30 +207,35 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        filter = mlt_properties_get_data( properties, id, NULL );
                }
 
+               // Hmm - this is probably going to go wrong....
+               mlt_frame_set_position( frame, position );
+
                // Get the b frame and process with composite if successful
                mlt_transition_process( composite, frame, b_frame );
 
-               // See if we have a shape producer
-               // Copy the alpha mask from the shape frame to the b_frame
-               char *resource =  mlt_properties_get( properties, "resource" );
-
+               // If we have a shape producer copy the alpha mask from the shape frame to the b_frame
                if ( strcmp( resource, "rectangle" ) != 0 )
                {
-                       if ( strcmp( resource, "circle" ) == 0 )
-                       {
-                               resource = strdup( "pixbuf" );
-                               mlt_properties_set( properties, "producer.resource", "<svg width='100' height='100'><circle cx='50' cy='50' r='50' fill='black'/></svg>" );
-                       }
-
                        // Get the producer from the filter
                        mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
 
+                       // If We have no producer then create one
                        if ( producer == NULL )
                        {
                                // Get the factory producer service
                                char *factory = mlt_properties_get( properties, "factory" );
 
-                               // Create the producer
+                               // Special case circle resource
+                               if ( strcmp( resource, "circle" ) == 0 )
+                               {
+                                       // Special case to ensure that fezzik produces a pixbuf with a NULL constructor
+                                       resource = "pixbuf";
+
+                                       // Specify the svg circle
+                                       mlt_properties_set( properties, "producer.resource", "<svg width='100' height='100'><circle cx='50' cy='50' r='50' fill='black'/></svg>" );
+                               }
+
+                               // Create the producer 
                                producer = mlt_factory_producer( factory, resource );
 
                                // If we have one
@@ -237,17 +255,12 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                }
                        }
 
+                       // Now use the shape producer
                        if ( producer != NULL )
                        {
                                // We will get the alpha frame from the producer
                                mlt_frame shape_frame = NULL;
 
-                               // Get the unique id of the filter (used to reacquire the producer position)
-                               char *name = mlt_properties_get( properties, "_unique_id" );
-
-                               // Get the original producer position
-                               mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
-
                                // Make sure the producer is in the correct position
                                mlt_producer_seek( producer, position );
 
@@ -269,26 +282,17 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                                b_frame->get_alpha_mask = filter_get_alpha_mask;
                                        }
                                        
-                                       // Get the image
-                                       error = mlt_frame_get_image( frame, image, format, width, height, 0 );
-
-                                       // Close the b frame
-                                       mlt_frame_close( b_frame );
-                                       b_frame = NULL;
-
-                                       // Close the shape frame
-                                       mlt_frame_close( shape_frame );
+                                       // Ensure that the shape frame will be closed
+                                       mlt_properties_set_data( mlt_frame_properties( b_frame ), "shape_frame", shape_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
                                }
                        }
                }
-               if ( b_frame != NULL )
-               {
-                       // Get the image
-                       error = mlt_frame_get_image( frame, image, format, width, height, 0 );
 
-                       // Close the b frame
-                       mlt_frame_close( b_frame );
-               }
+               // Get the image
+               error = mlt_frame_get_image( frame, image, format, width, height, 0 );
+
+               // Close the b frame
+               mlt_frame_close( b_frame );
        }
 
        return error;
@@ -299,6 +303,15 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
 
 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 {
+       // Get the properties of the frame
+       mlt_properties properties = mlt_frame_properties( frame );
+
+       // Get a unique name to store the frame position
+       char *name = mlt_properties_get( mlt_filter_properties( this ), "_unique_id" );
+
+       // Assign the current position to the name
+       mlt_properties_set_position( properties, name, mlt_frame_get_position( frame ) );
+
        // Push the filter on to the frame
        mlt_frame_push_service( frame, this );