minor clean ups; added a null consumer for easier valgrind testing
[melted] / src / modules / fezzik / producer_hold.c
index d2ce7f8..6c33877 100644 (file)
@@ -28,6 +28,7 @@
 
 // Forward references
 static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index );
+static void producer_close( mlt_producer this );
 
 /** Constructor for the frame holding producer. Basically, all this producer does is
        provide a producer wrapper for the requested producer, allows the specifcation of
@@ -57,15 +58,19 @@ mlt_producer producer_hold_init( char *arg )
                mlt_properties_set_position( properties, "in", 0 );
                mlt_properties_set_position( properties, "out", 25 );
                mlt_properties_set_position( properties, "length", 15000 );
+               mlt_properties_set( properties, "resource", arg );
 
                // Override the get_frame method
                this->get_frame = producer_get_frame;
+               this->close = producer_close;
        }
        else
        {
                // Clean up (not sure which one failed, can't be bothered to find out, so close both)
-               mlt_producer_close( this );
-               mlt_producer_close( producer );
+               if ( this )
+                       mlt_producer_close( this );
+               if ( producer )
+                       mlt_producer_close( producer );
 
                // Make sure we return NULL
                this = NULL;
@@ -83,19 +88,49 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Obtain the real frame
        mlt_frame real_frame = mlt_frame_pop_service( frame );
 
-       // We want distorted to ensure we don't hit the resize filter twice
-       mlt_properties_set_int( properties, "distort", 1 );
-
        // Get the image from the real frame
-       mlt_frame_get_image( real_frame, buffer, format, width, height, writable );
+       int size = 0;
+       *buffer = mlt_properties_get_data( mlt_frame_properties( real_frame ), "image", &size );
+       *width = mlt_properties_get_int( mlt_frame_properties( real_frame ), "width" );
+       *height = mlt_properties_get_int( mlt_frame_properties( real_frame ), "height" );
+
+       // If this is the first time, get it from the producer
+       if ( *buffer == NULL )
+       {
+               mlt_properties_pass( mlt_frame_properties( real_frame ), properties, "" );
+
+               // We'll deinterlace on the downstream deinterlacer
+               mlt_properties_set_int( mlt_frame_properties( real_frame ), "consumer_deinterlace", 1 );
+
+               // We want distorted to ensure we don't hit the resize filter twice
+               mlt_properties_set_int( mlt_frame_properties( real_frame ), "distort", 1 );
+
+               // Get the image
+               mlt_frame_get_image( real_frame, buffer, format, width, height, writable );
+       
+               // Make sure we get the size
+               *buffer = mlt_properties_get_data( mlt_frame_properties( real_frame ), "image", &size );
+       }
+
+       mlt_properties_pass( properties, mlt_frame_properties( real_frame ), "" );
 
        // Set the values obtained on the frame
-       mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
-       mlt_properties_set_int( properties, "width", *width );
-       mlt_properties_set_int( properties, "height", *height );
+       if ( *buffer != NULL )
+       {
+               uint8_t *image = mlt_pool_alloc( size );
+               memcpy( image, *buffer, size );
+               *buffer = image;
+               mlt_properties_set_data( properties, "image", *buffer, size, mlt_pool_release, NULL );
+       }
+       else
+       {
+               // Pass the current image as is
+               mlt_properties_set_data( properties, "image", *buffer, size, NULL, NULL );
+       }
 
-       // We'll deinterlace on the downstream deinterlacer
-       mlt_properties_set_int( mlt_frame_properties( real_frame ), "consumer_deinterlace", 1 );
+       // Make sure that no further scaling is done
+       mlt_properties_set( properties, "rescale.interps", "none" );
+       mlt_properties_set( properties, "scale", "off" );
 
        // All done
        return 0;
@@ -113,22 +148,33 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
        if ( *frame != NULL )
        {
                // Define the real frame
-               mlt_frame real_frame = NULL;
-
-               // Get the producer
-               mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
-
-               // Get the frame position requested
-               mlt_position position = mlt_properties_get_position( properties, "frame" );
-
-               // Seek the producer to the correct place
-               mlt_producer_seek( producer, position );
-
-               // Get the real frame
-               mlt_service_get_frame( mlt_producer_service( producer ), &real_frame, index );
-
-               // Ensure that the real frame gets wiped
-               mlt_properties_set_data( mlt_frame_properties( *frame ), "real_frame", real_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
+               mlt_frame real_frame = mlt_properties_get_data( properties, "real_frame", NULL );
+
+               // Obtain real frame if we don't have it
+               if ( real_frame == NULL )
+               {
+                       // Get the producer
+                       mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
+
+                       // Get the frame position requested
+                       mlt_position position = mlt_properties_get_position( properties, "frame" );
+
+                       // Seek the producer to the correct place
+                       mlt_producer_seek( producer, position );
+
+                       // Get the real frame
+                       mlt_service_get_frame( mlt_producer_service( producer ), &real_frame, index );
+
+                       // Ensure that the real frame gets wiped eventually
+                       mlt_properties_set_data( properties, "real_frame", real_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
+               }
+               else
+               {
+                       // Temporary fix - ensure that we aren't seen as a test frame
+                       int8_t *image = mlt_properties_get_data( mlt_frame_properties( real_frame ), "image", NULL );
+                       mlt_properties_set_data( mlt_frame_properties( *frame ), "image", image, 0, NULL, NULL );
+                       mlt_properties_set_int( mlt_frame_properties( *frame ), "test_image", 0 );
+               }
 
                // Stack the real frame and method
                mlt_frame_push_service( *frame, real_frame );
@@ -136,9 +182,6 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 
                // Ensure that the consumer sees what the real frame has
                mlt_properties_pass( mlt_frame_properties( *frame ), mlt_frame_properties( real_frame ), "" );
-
-               // Mirror the properties of the frame
-               mlt_properties_mirror( mlt_frame_properties( *frame ), mlt_frame_properties( real_frame ) );
        }
 
        // Move to the next position
@@ -146,3 +189,11 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 
        return 0;
 }
+
+static void producer_close( mlt_producer this )
+{
+       this->close = NULL;
+       mlt_producer_close( this );
+       free( this );
+}
+