X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmelted%2Fmelted_unit.c;h=3da08a7112aa7f6dcc3fab6ae3a5442c86ae04c2;hb=50494c72c7b8b700cf4df4c1f25ae1b5323e4df2;hp=c25d27f047f6cb0a477d1e877cf4fc1e4ea14b25;hpb=91af795798049db85f9ad3814edc85fd474a5866;p=melted diff --git a/src/melted/melted_unit.c b/src/melted/melted_unit.c index c25d27f..3da08a7 100644 --- a/src/melted/melted_unit.c +++ b/src/melted/melted_unit.c @@ -34,7 +34,6 @@ #include #include #include -#include #include @@ -56,6 +55,7 @@ melted_unit melted_unit_init( int index, char *constructor ) { melted_unit this = NULL; mlt_consumer consumer = NULL; + mlt_profile profile = mlt_profile_init( NULL ); char *id = strdup( constructor ); char *arg = strchr( id, ':' ); @@ -63,7 +63,8 @@ melted_unit melted_unit_init( int index, char *constructor ) if ( arg != NULL ) *arg ++ = '\0'; - consumer = mlt_factory_consumer( NULL, id, arg ); + profile->is_explicit = 1; + consumer = mlt_factory_consumer( profile, id, arg ); if ( consumer != NULL ) { @@ -76,6 +77,7 @@ melted_unit melted_unit_init( int index, char *constructor ) mlt_properties_set( this->properties, "constructor", constructor ); mlt_properties_set( this->properties, "id", id ); mlt_properties_set( this->properties, "arg", arg ); + mlt_properties_set_data( this->properties, "producer", mlt_properties_new( ), 0, ( mlt_destructor )mlt_properties_close, NULL ); mlt_properties_set_data( this->properties, "consumer", consumer, 0, ( mlt_destructor )mlt_consumer_close, NULL ); mlt_properties_set_data( this->properties, "playlist", playlist, 0, ( mlt_destructor )mlt_playlist_close, NULL ); mlt_consumer_connect( consumer, MLT_PLAYLIST_SERVICE( playlist ) ); @@ -149,13 +151,23 @@ static mlt_producer locate_producer( melted_unit unit, char *file ) { // Try to get the profile from the consumer mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); + mlt_properties m_prop = mlt_properties_get_data( unit->properties, "producer", NULL ); + mlt_producer producer; mlt_profile profile = NULL; if ( consumer != NULL ) { profile = mlt_service_profile( MLT_CONSUMER_SERVICE( consumer ) ); } - return mlt_factory_producer( profile, NULL, file ); + + producer = mlt_factory_producer( profile, NULL, file ); + if( producer ) + { + mlt_properties p_prop = mlt_producer_properties( producer ); + mlt_properties_inherit ( p_prop, m_prop ); + } + + return producer; } /** Update the generation count. @@ -175,11 +187,13 @@ static void clear_unit( melted_unit unit ) { mlt_properties properties = unit->properties; mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL ); + mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); mlt_producer producer = MLT_PLAYLIST_PRODUCER( playlist ); mlt_service_lock( MLT_PLAYLIST_SERVICE( playlist ) ); mlt_playlist_clear( playlist ); mlt_producer_seek( producer, 0 ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "refresh", 1 ); mlt_service_unlock( MLT_PLAYLIST_SERVICE( playlist ) ); update_generation( unit ); @@ -192,6 +206,7 @@ static void clean_unit( melted_unit unit ) { mlt_properties properties = unit->properties; mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL ); + mlt_consumer consumer = mlt_properties_get_data( properties, "consumer", NULL ); mlt_playlist_clip_info info; int current = mlt_playlist_current_clip( playlist ); mlt_producer producer = MLT_PLAYLIST_PRODUCER( playlist ); @@ -208,6 +223,7 @@ static void clean_unit( melted_unit unit ) mlt_playlist_append_io( playlist, info.producer, info.frame_in, info.frame_out ); mlt_producer_seek( producer, position ); mlt_producer_set_speed( producer, speed ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "refresh", 1 ); mlt_service_unlock( MLT_PLAYLIST_SERVICE( playlist ) ); mlt_producer_close( info.producer ); } @@ -286,31 +302,15 @@ mvcp_error_code melted_unit_load( melted_unit unit, char *clip, int32_t in, int3 { mlt_properties properties = unit->properties; mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL ); - mlt_producer producer = MLT_PLAYLIST_PRODUCER( playlist ); - int original = mlt_producer_get_playtime( producer ); - mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); - double speed = mlt_producer_get_speed( producer ); - struct timespec tm = { 1, 0 }; - + int original = mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( playlist ) ); mlt_service_lock( MLT_PLAYLIST_SERVICE( playlist ) ); mlt_playlist_append_io( playlist, instance, in, out ); + mlt_playlist_remove_region( playlist, 0, original ); mlt_service_unlock( MLT_PLAYLIST_SERVICE( playlist ) ); - // We try to ensure all frames from producers that will be removed are closed. - mlt_producer_seek( producer, original ); - mlt_consumer_purge( consumer ); - melted_log( LOG_DEBUG, "loaded clip %s", clip ); update_generation( unit ); melted_unit_status_communicate( unit ); mlt_producer_close( instance ); - - // Give more time for those frames to be closed - there could still be some - // in the consumer plugin that were not purged from the base consumer buffer. - nanosleep( &tm, NULL ); - mlt_service_lock( MLT_PLAYLIST_SERVICE( playlist ) ); - mlt_playlist_remove_region( playlist, 0, original ); - mlt_service_unlock( MLT_PLAYLIST_SERVICE( playlist ) ); - return mvcp_ok; } @@ -456,6 +456,7 @@ void melted_unit_play( melted_unit_t *unit, int speed ) mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); mlt_producer_set_speed( producer, ( double )speed / 1000 ); mlt_consumer_start( consumer ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "refresh", 1 ); melted_unit_status_communicate( unit ); } @@ -565,7 +566,7 @@ int melted_unit_get_status( melted_unit unit, mvcp_status status ) title = strip_root( unit, info.resource ); strncpy( status->clip, title, sizeof( status->clip ) ); status->speed = (int)( mlt_producer_get_speed( producer ) * 1000.0 ); - status->fps = mlt_producer_get_fps( producer ); + status->fps = info.fps; status->in = info.frame_in; status->out = info.frame_out; status->position = mlt_producer_frame( clip ); @@ -577,6 +578,8 @@ int melted_unit_get_status( melted_unit unit, mvcp_status status ) status->tail_length = mlt_producer_get_length( clip ); status->clip_index = mlt_playlist_current_clip( playlist ); status->seek_flag = 1; + status->dur = mlt_producer_get_length( producer ); + status->start = info.start; } status->generation = mlt_properties_get_int( properties, "generation" ); @@ -625,6 +628,7 @@ void melted_unit_change_position( melted_unit unit, int clip, int32_t position ) { int32_t frame_start = info.start; int32_t frame_offset = position; + mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); if ( frame_offset < 0 ) frame_offset = info.frame_out; @@ -634,6 +638,7 @@ void melted_unit_change_position( melted_unit unit, int clip, int32_t position ) frame_offset = info.frame_out; mlt_producer_seek( producer, frame_start + frame_offset - info.frame_in ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "refresh", 1 ); } melted_unit_status_communicate( unit ); @@ -705,8 +710,10 @@ void melted_unit_step( melted_unit unit, int32_t offset ) mlt_properties properties = unit->properties; mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL ); mlt_producer producer = MLT_PLAYLIST_PRODUCER( playlist ); + mlt_consumer consumer = mlt_properties_get_data( unit->properties, "consumer", NULL ); mlt_position position = mlt_producer_frame( producer ); mlt_producer_seek( producer, position + offset ); + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "refresh", 1 ); } /** Set the unit's clip mode regarding in and out points. @@ -754,8 +761,16 @@ int melted_unit_set( melted_unit unit, char *name_value ) if ( strncmp( name_value, "consumer.", 9 ) ) { - mlt_playlist playlist = mlt_properties_get_data( unit->properties, "playlist", NULL ); - properties = MLT_PLAYLIST_PROPERTIES( playlist ); + if ( strncmp( name_value, "producer.", 9 ) ) + { + mlt_playlist playlist = mlt_properties_get_data( unit->properties, "playlist", NULL ); + properties = MLT_PLAYLIST_PROPERTIES( playlist ); + } + else + { + properties = mlt_properties_get_data( unit->properties, "producer", NULL ); + name_value += 9; + } } else {