Playlist and blank rearrangement, fix for mlt_consumer and NULL
[melted] / src / framework / mlt_producer.c
index 89d81cd..9ed89af 100644 (file)
@@ -78,12 +78,12 @@ int mlt_producer_init( mlt_producer this, void *child )
                        if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) )
                        {
                                mlt_properties_set_double( properties, "fps", 25.0 );
-                               mlt_properties_set_double( properties, "aspect_ratio", 72.0 / 79.0 );
+                               mlt_properties_set_double( properties, "aspect_ratio", 59.0 / 54.0 );
                        }
                        else
                        {
                                mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 );
-                               mlt_properties_set_double( properties, "aspect_ratio", 128.0 / 117.0 );
+                               mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 );
                        }
                        mlt_properties_set_double( properties, "_speed", 1.0 );
                        mlt_properties_set_position( properties, "in", 0 );
@@ -162,6 +162,14 @@ int mlt_producer_is_mix( mlt_producer this )
        return tractor != NULL;
 }
 
+/** Determine if the producer is a blank [from a playlist].
+*/
+
+int mlt_producer_is_blank( mlt_producer this )
+{
+       return this == NULL || !strcmp( mlt_properties_get( mlt_producer_properties( mlt_producer_cut_parent( this ) ), "resource" ), "blank" );
+}
+
 /** Obtain the parent producer.
 */
 
@@ -187,7 +195,7 @@ mlt_producer mlt_producer_cut( mlt_producer this, int in, int out )
        // Special case - allow for a cut of the entire producer (this will squeeze all other cuts to 0)
        if ( in <= 0 )
                in = 0;
-       if ( out >= mlt_producer_get_playtime( parent ) )
+       if ( out >= mlt_producer_get_playtime( parent ) && !mlt_producer_is_blank( this ) )
                out = mlt_producer_get_playtime( parent ) - 1;
 
        mlt_properties_inc_ref( parent_props );
@@ -310,7 +318,7 @@ int mlt_producer_set_in_and_out( mlt_producer this, mlt_position in, mlt_positio
 
        if ( out < 0 )
                out = 0;
-       else if ( out > mlt_producer_get_length( this ) )
+       else if ( out > mlt_producer_get_length( this ) && !mlt_producer_is_blank( this ) )
                out = mlt_producer_get_length( this );
 
        // Swap ins and outs if wrong
@@ -393,13 +401,25 @@ void mlt_producer_prepare_next( mlt_producer this )
 static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int index )
 {
        int result = 1;
-       mlt_producer this = service->child;
+       mlt_producer this = service != NULL ? service->child : NULL;
 
-       if ( !mlt_producer_is_cut( this ) )
+       if ( this != NULL && !mlt_producer_is_cut( this ) )
        {
+               // Get the properties of this producer
+               mlt_properties properties = mlt_producer_properties( this );
+
                // Determine eof handling
                char *eof = mlt_properties_get( mlt_producer_properties( this ), "eof" );
 
+               // Get the speed of the producer
+               double speed = mlt_producer_get_speed( this );
+
+               // We need to use the clone if it's specified
+               mlt_producer clone = mlt_properties_get_data( properties, "use_clone", NULL );
+
+               // If no clone is specified, use this
+               clone = clone == NULL ? this : clone;
+
                // A properly instatiated producer will have a get_frame method...
                if ( this->get_frame == NULL || ( !strcmp( eof, "continue" ) && mlt_producer_position( this ) > mlt_producer_get_out( this ) ) )
                {
@@ -419,12 +439,11 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind
                else
                {
                        // Get the frame from the implementation
-                       result = this->get_frame( this, frame, index );
+                       result = this->get_frame( clone, frame, index );
                }
 
                // Copy the fps and speed of the producer onto the frame
-               mlt_properties properties = mlt_frame_properties( *frame );
-               double speed = mlt_producer_get_speed( this );
+               properties = mlt_frame_properties( *frame );
                mlt_properties_set_double( properties, "_speed", speed );
                mlt_properties_set_double( properties, "fps", mlt_producer_get_fps( this ) );
                mlt_properties_set_int( properties, "test_audio", mlt_frame_is_test_audio( *frame ) );
@@ -432,28 +451,58 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind
                if ( mlt_properties_get_data( properties, "_producer", NULL ) == NULL )
                        mlt_properties_set_data( properties, "_producer", service, 0, NULL, NULL );
        }
-       else
+       else if ( this != NULL )
        {
+               // Get the speed of the cut
+               double speed = mlt_producer_get_speed( this );
+
+               // Get the parent of this cut
+               mlt_producer parent = mlt_producer_cut_parent( this );
+
+               // Get the properties of the parent
+               mlt_properties parent_properties = mlt_producer_properties( parent );
+
+               // Get the properties of the cut
                mlt_properties properties = mlt_producer_properties( this );
+
+               // Determine the clone index
                int clone_index = mlt_properties_get_int( properties, "_clone" );
+
+               // Determine the clone to use
                mlt_producer clone = this;
+
                if ( clone_index > 0 )
                {
                        char key[ 25 ];
                        sprintf( key, "_clone.%d", clone_index - 1 );
                        clone = mlt_properties_get_data( mlt_producer_properties( mlt_producer_cut_parent( this ) ), key, NULL );
-                       if ( clone == NULL ) fprintf( stderr, "requested clone doesn't exist\n" );
+                       if ( clone == NULL ) fprintf( stderr, "requested clone doesn't exist %d\n", clone_index );
                        clone = clone == NULL ? this : clone;
                }
                else
                {
-                       clone = mlt_producer_cut_parent( this );
+                       clone = parent;
                }
+
+               // We need to seek to the correct position in the clone
                mlt_producer_seek( clone, mlt_producer_get_in( this ) + mlt_properties_get_int( properties, "_position" ) );
-               result = producer_get_frame( mlt_producer_service( clone ), frame, index );
-               double speed = mlt_producer_get_speed( this );
+
+               // Assign the clone property to the parent
+               mlt_properties_set_data( parent_properties, "use_clone", clone, 0, NULL, NULL );
+
+               // Now get the frame from the parents service
+               result = mlt_service_get_frame( mlt_producer_service( parent ), frame, index );
+
+               // We're done with the clone now
+               mlt_properties_set_data( parent_properties, "use_clone", NULL, 0, NULL, NULL );
+
                mlt_properties_set_double( mlt_frame_properties( *frame ), "_speed", speed );
-               mlt_producer_prepare_next( clone );
+               mlt_producer_prepare_next( this );
+       }
+       else
+       {
+               *frame = mlt_frame_init( );
+               result = 0;
        }
 
        return result;
@@ -494,16 +543,7 @@ static mlt_producer mlt_producer_clone( mlt_producer this )
        char *service = mlt_properties_get( properties, "mlt_service" );
 
        if ( service != NULL )
-       {
-               char temp[ 1024 ];
-               strncpy( temp, service, 1024 );
-               if ( resource != NULL )
-               {
-                       strcat( temp, ":" );
-                       strncat( temp, resource, 1023 - strlen( temp ) );
-               }
-               clone = mlt_factory_producer( "fezzik", temp );
-       }
+               clone = mlt_factory_producer( service, resource );
 
        if ( clone == NULL && resource != NULL )
                clone = mlt_factory_producer( "fezzik", resource );
@@ -525,7 +565,7 @@ static void mlt_producer_set_clones( mlt_producer this, int clones )
        int i = 0;
        char key[ 25 ];
 
-       // If the number of existing clones is different, the create/remove as necessary
+       // If the number of existing clones is different, then create/remove as necessary
        if ( existing != clones )
        {
                if ( existing < clones )
@@ -634,7 +674,7 @@ static int on_start_producer( mlt_parser this, mlt_producer object )
        mlt_properties properties = mlt_parser_properties( this );
        mlt_properties producers = mlt_properties_get_data( properties, "producers", NULL );
        mlt_producer parent = mlt_producer_cut_parent( object );
-       if ( !mlt_producer_is_mix( mlt_producer_cut_parent( object ) ) && mlt_producer_is_cut( object ) )
+       if ( mlt_service_identify( ( mlt_service )mlt_producer_cut_parent( object ) ) == producer_type && mlt_producer_is_cut( object ) )
        {
                int ref_count = 0;
                clip_references *old_refs = NULL;