]> git.sesse.net Git - mlt/blobdiff - src/modules/core/consumer_multi.c
Fix applying properties preset with multi consumer.
[mlt] / src / modules / core / consumer_multi.c
index 1cf6593a17ec45754ca5a60991d52d8f139f2fe2..8d0b66eb71a17514e9d21bf60747aa0dba5f3afc 100644 (file)
@@ -30,6 +30,7 @@ static int stop( mlt_consumer consumer );
 static int is_stopped( mlt_consumer consumer );
 static void *consumer_thread( void *arg );
 static void consumer_close( mlt_consumer consumer );
+static void purge( mlt_consumer consumer );
 
 static mlt_properties normalisers = NULL;
 
@@ -57,6 +58,7 @@ mlt_consumer consumer_multi_init( mlt_profile profile, mlt_service_type type, co
                consumer->start = start;
                consumer->stop = stop;
                consumer->is_stopped = is_stopped;
+               consumer->purge = purge;
        }
 
        return consumer;
@@ -257,12 +259,23 @@ static void foreach_consumer_init( mlt_consumer consumer )
                        if ( ( s = mlt_properties_get( properties, key ) ) )
                        {
                                mlt_properties p = mlt_properties_new();
-                               int i, count;
-
                                if ( !p ) break;
-                               mlt_properties_set( p, "mlt_service", mlt_properties_get( properties, key ) );
+
+                               // Terminate mlt_service value at the argument delimiter if supplied.
+                               // Needed here instead of just relying upon create_consumer() so that
+                               // a properties preset is picked up correctly.
+                               char *service = strdup( mlt_properties_get( properties, key ) );
+                               char *arg = strchr( service, ':' );
+                               if ( arg ) {
+                                       *arg ++ = '\0';
+                                       mlt_properties_set( p, "target", arg );
+                               }
+                               mlt_properties_set( p, "mlt_service", service );
+                               free( service );
+
                                snprintf( key, sizeof(key), "%d.", index );
 
+                               int i, count;
                                count = mlt_properties_count( properties );
                                for ( i = 0; i < count; i++ )
                                {
@@ -363,6 +376,7 @@ static void foreach_consumer_put( mlt_consumer consumer, mlt_frame frame )
                                // put ideal number of samples into cloned frame
                                int deeply = index > 1 ? 1 : 0;
                                mlt_frame clone_frame = mlt_frame_clone( frame, deeply );
+                               mlt_properties clone_props = MLT_FRAME_PROPERTIES( clone_frame );
                                int nested_samples = mlt_sample_calculator( nested_fps, frequency, nested_pos );
                                // -10 is an optimization to avoid tiny amounts of leftover samples
                                nested_samples = nested_samples > current_samples - 10 ? current_samples : nested_samples;
@@ -378,15 +392,21 @@ static void foreach_consumer_put( mlt_consumer consumer, mlt_frame frame )
                                        nested_size = 0;
                                }
                                mlt_frame_set_audio( clone_frame, prev_buffer, format, nested_size, mlt_pool_release );
-                               mlt_properties_set_int( MLT_FRAME_PROPERTIES(clone_frame), "audio_samples", nested_samples );
-                               mlt_properties_set_int( MLT_FRAME_PROPERTIES(clone_frame), "audio_frequency", frequency );
-                               mlt_properties_set_int( MLT_FRAME_PROPERTIES(clone_frame), "audio_channels", channels );
+                               mlt_properties_set_int( clone_props, "audio_samples", nested_samples );
+                               mlt_properties_set_int( clone_props, "audio_frequency", frequency );
+                               mlt_properties_set_int( clone_props, "audio_channels", channels );
 
                                // chomp the audio
                                current_samples -= nested_samples;
                                current_size -= nested_size;
                                buffer += nested_size;
 
+                               // Fix some things
+                               mlt_properties_set_int( clone_props, "meta.media.width",
+                                       mlt_properties_get_int( MLT_FRAME_PROPERTIES(frame), "width" ) );
+                               mlt_properties_set_int( clone_props, "meta.media.height",
+                                       mlt_properties_get_int( MLT_FRAME_PROPERTIES(frame), "height" ) );
+
                                // send frame to nested consumer
                                mlt_consumer_put_frame( nested, clone_frame );
                                mlt_properties_set_position( nested_props, "_multi_position", ++nested_pos );
@@ -507,6 +527,27 @@ static int is_stopped( mlt_consumer consumer )
        return !mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "running" );
 }
 
+/** Purge each of the child consumers.
+*/
+
+static void purge( mlt_consumer consumer )
+{
+       mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
+       if ( mlt_properties_get_int( properties, "running" ) )
+       {
+               mlt_consumer nested = NULL;
+               char key[30];
+               int index = 0;
+
+               do {
+                       snprintf( key, sizeof(key), "%d.consumer", index++ );
+                       nested = mlt_properties_get_data( properties, key, NULL );
+                       if ( nested )
+                               mlt_consumer_purge( nested );
+               } while ( nested );
+       }
+}
+
 /** The main thread - the argument is simply the consumer.
 */