Added ref_count method to properties; temporary work around for test card; titles...
[melted] / src / framework / mlt_consumer.c
index ae79cf9..b904f13 100644 (file)
@@ -154,6 +154,10 @@ int mlt_consumer_start( mlt_consumer this )
        // Determine if there's a test card producer
        char *test_card = mlt_properties_get( properties, "test_card" );
 
+       // Just to make sure nothing is hanging around...
+       mlt_frame_close( this->put );
+       this->put = NULL;
+
        // Deal with it now.
        if ( test_card != NULL )
        {
@@ -166,7 +170,9 @@ int mlt_consumer_start( mlt_consumer this )
                        if ( producer != NULL )
                        {
                                // Test card should loop I guess...
-                               mlt_properties_set( mlt_producer_properties( producer ), "eof", "loop" );
+                               mlt_properties_set( mlt_producer_properties( producer ), "eof", "pause" );
+                               mlt_producer_set_speed( producer, 0 );
+                               mlt_producer_set_in_and_out( producer, 0, 0 );
 
                                // Set the test card on the consumer
                                mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
@@ -206,9 +212,16 @@ int mlt_consumer_put_frame( mlt_consumer this, mlt_frame frame )
 
        if ( mlt_service_producer( service ) == NULL )
        {
+               struct timeval now;
+               struct timespec tm;
                pthread_mutex_lock( &this->put_mutex );
-               if ( this->put != NULL )
-                       pthread_cond_wait( &this->put_cond, &this->put_mutex );
+               while ( !mlt_consumer_is_stopped( this ) && this->put != NULL )
+               {
+                       gettimeofday( &now, NULL );
+                       tm.tv_sec = now.tv_sec + 1;
+                       tm.tv_nsec = now.tv_usec * 1000;
+                       pthread_cond_timedwait( &this->put_cond, &this->put_mutex, &tm );
+               }
                if ( this->put == NULL )
                        this->put = frame;
                else
@@ -241,9 +254,16 @@ mlt_frame mlt_consumer_get_frame( mlt_consumer this )
        // Get the frame
        if ( mlt_service_producer( service ) == NULL && mlt_properties_get_int( properties, "put_mode" ) )
        {
+               struct timeval now;
+               struct timespec tm;
                pthread_mutex_lock( &this->put_mutex );
-               if ( this->put == NULL )
-                       pthread_cond_wait( &this->put_cond, &this->put_mutex );
+               while ( !mlt_consumer_is_stopped( this ) && this->put == NULL )
+               {
+                       gettimeofday( &now, NULL );
+                       tm.tv_sec = now.tv_sec + 1;
+                       tm.tv_nsec = now.tv_usec * 1000;
+                       pthread_cond_timedwait( &this->put_cond, &this->put_mutex, &tm );
+               }
                frame = this->put;
                this->put = NULL;
                pthread_cond_broadcast( &this->put_cond );
@@ -251,8 +271,12 @@ mlt_frame mlt_consumer_get_frame( mlt_consumer this )
                if ( frame != NULL )
                        mlt_service_apply_filters( service, frame, 0 );
        }
+       else if ( mlt_service_producer( service ) != NULL )
+       {
+               mlt_service_get_frame( service, &frame, 0 );
+       }
 
-       if ( frame != NULL || mlt_service_get_frame( service, &frame, 0 ) == 0 )
+       if ( frame != NULL )
        {
                // Get the frame properties
                mlt_properties frame_properties = mlt_frame_properties( frame );
@@ -360,12 +384,17 @@ static void *consumer_read_ahead_thread( void *arg )
                mlt_deque_push_back( this->queue, frame );
                pthread_cond_broadcast( &this->cond );
                pthread_mutex_unlock( &this->mutex );
+
                time_wait += time_difference( &ante );
 
                // Get the next frame
                frame = mlt_consumer_get_frame( this );
                time_frame += time_difference( &ante );
 
+               // If there's no frame, we're probably stopped...
+               if ( frame == NULL )
+                       continue;
+
                // Increment the count
                count ++;
 
@@ -536,7 +565,8 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer this )
                frame = mlt_consumer_get_frame( this );
 
                // This isn't true, but from the consumers perspective it is
-               mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 1 );
+               if ( frame != NULL )
+                       mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 1 );
        }
 
        return frame;