// 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 )
{
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
// 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 );
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 );
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 ++;
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;
}
// Check if the length of the producer has changed
- if ( this->list[ i ]->producer != &this->blank &&
- ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
- this->list[ i ]->frame_out != mlt_producer_get_out( producer ) ) )
+ if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
+ this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
{
// This clip should be removed...
if ( current_length < 1 )
static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer source, mlt_position in, mlt_position out )
{
- char *resource = source != NULL ? mlt_properties_get( mlt_producer_properties( source ), "resource" ) : NULL;
mlt_producer producer = NULL;
mlt_properties properties = NULL;
mlt_properties parent = NULL;
// If we have a cut, then use the in/out points from the cut
- if ( resource == NULL || !strcmp( resource, "blank" ) )
+ if ( mlt_producer_is_blank( source ) )
{
- producer = &this->blank;
+ // Make sure the blank is long enough to accomodate the length specified
+ if ( out - in + 1 > mlt_producer_get_length( &this->blank ) )
+ {
+ mlt_properties blank_props = mlt_producer_properties( &this->blank );
+ mlt_events_block( blank_props, blank_props );
+ mlt_producer_set_in_and_out( &this->blank, in, out );
+ mlt_events_unblock( blank_props, blank_props );
+ }
+
+ // Now make sure the cut comes from this this->blank
+ if ( source == NULL )
+ {
+ producer = mlt_producer_cut( &this->blank, in, out );
+ }
+ else if ( !mlt_producer_is_cut( source ) || mlt_producer_cut_parent( source ) != &this->blank )
+ {
+ producer = mlt_producer_cut( &this->blank, in, out );
+ }
+ else
+ {
+ producer = source;
+ mlt_properties_inc_ref( mlt_producer_properties( producer ) );
+ }
+
properties = mlt_producer_properties( producer );
- mlt_properties_inc_ref( properties );
}
else if ( mlt_producer_is_cut( source ) )
{
playlist_entry *entry = this->list[ clip ];
mlt_producer producer = entry->producer;
+ if ( mlt_producer_is_blank( producer ) )
+ {
+ // Make sure the blank is long enough to accomodate the length specified
+ if ( out - in + 1 > mlt_producer_get_length( &this->blank ) )
+ {
+ mlt_properties blank_props = mlt_producer_properties( &this->blank );
+ mlt_events_block( blank_props, blank_props );
+ mlt_producer_set_in_and_out( &this->blank, in, out );
+ mlt_events_unblock( blank_props, blank_props );
+ }
+ }
+
if ( in <= -1 )
in = 0;
if ( out <= -1 || out >= mlt_producer_get_length( producer ) )
position = position < 0 ? entry->frame_count + position - 1 : position;
if ( position >= 0 && position <= entry->frame_count )
{
- mlt_producer split = NULL;
int in = entry->frame_in;
int out = entry->frame_out;
mlt_events_block( mlt_playlist_properties( this ), this );
mlt_playlist_resize_clip( this, clip, in, in + position );
- split = mlt_producer_cut( entry->producer, in + position + 1, out );
- mlt_playlist_insert( this, split, clip + 1, 0, -1 );
- mlt_producer_close( split );
+ if ( !mlt_producer_is_blank( entry->producer ) )
+ {
+ mlt_producer split = mlt_producer_cut( entry->producer, in + position + 1, out );
+ mlt_playlist_insert( this, split, clip + 1, 0, -1 );
+ mlt_producer_close( split );
+ }
+ else
+ {
+ mlt_playlist_insert( this, &this->blank, clip + 1, 0, out - position - 1 );
+ }
mlt_events_unblock( mlt_playlist_properties( this ), this );
mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL );
}
return error;
}
+/** Consolodate adjacent blank producers.
+*/
+
+void mlt_playlist_consolidate_blanks( mlt_playlist this, int keep_length )
+{
+ if ( this != NULL )
+ {
+ int i = 0;
+ mlt_properties properties = mlt_playlist_properties( this );
+
+ mlt_events_block( properties, properties );
+ for ( i = 1; i < this->count; i ++ )
+ {
+ playlist_entry *left = this->list[ i - 1 ];
+ playlist_entry *right = this->list[ i ];
+
+ if ( mlt_producer_cut_parent( left->producer ) == mlt_producer_cut_parent( right->producer ) &&
+ mlt_producer_is_blank( left->producer ) )
+ {
+ mlt_playlist_resize_clip( this, i - 1, 0, left->frame_count + right->frame_count - 1 );
+ mlt_playlist_remove( this, i -- );
+ }
+ }
+
+ if ( !keep_length )
+ {
+ playlist_entry *last = this->list[ this->count - 1 ];
+ if ( mlt_producer_is_blank( last->producer ) )
+ mlt_playlist_remove( this, this->count - 1 );
+ }
+
+ mlt_events_unblock( properties, properties );
+ mlt_playlist_virtual_refresh( this );
+ }
+}
+
+/** Determine if the specified clip index is a blank.
+*/
+
+int mlt_playlist_is_blank( mlt_playlist this, int clip )
+{
+ return this == NULL || mlt_producer_is_blank( mlt_playlist_get_clip( this, clip ) );
+}
+
+/** Replace the specified clip with a blank and return the clip.
+*/
+
+mlt_producer mlt_playlist_replace_with_blank( mlt_playlist this, int clip )
+{
+ mlt_producer producer = NULL;
+ if ( !mlt_playlist_is_blank( this, clip ) )
+ {
+ playlist_entry *entry = this->list[ clip ];
+ int in = entry->frame_in;
+ int out = entry->frame_out;
+ mlt_properties properties = mlt_playlist_properties( this );
+ producer = entry->producer;
+ mlt_properties_inc_ref( mlt_producer_properties( producer ) );
+ mlt_events_block( properties, properties );
+ mlt_playlist_remove( this, clip );
+ mlt_playlist_blank( this, out - in );
+ mlt_playlist_move( this, this->count - 1, clip );
+ mlt_producer_set_in_and_out( producer, in, out );
+ mlt_events_unblock( properties, properties );
+ mlt_playlist_virtual_refresh( this );
+ }
+ return producer;
+}
+
/** Get the current frame.
*/
static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
{
+ // Check that we have a producer
+ if ( producer == NULL )
+ {
+ *frame = mlt_frame_init( );
+ return 0;
+ }
+
// Get this mlt_playlist
mlt_playlist this = producer->child;
// Get the real producer
mlt_service real = mlt_playlist_virtual_seek( this, &progressive );
+ // Check that we have a producer
+ if ( real == NULL )
+ {
+ *frame = mlt_frame_init( );
+ return 0;
+ }
+
// Get the frame
mlt_service_get_frame( real, frame, index );
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.
*/
// 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 );
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
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 );
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 );
mlt_properties_set_double( mlt_frame_properties( *frame ), "_speed", speed );
mlt_producer_prepare_next( this );
}
+ else
+ {
+ *frame = mlt_frame_init( );
+ result = 0;
+ }
return result;
}