]> git.sesse.net Git - mlt/blobdiff - src/modules/core/consumer_multi.c
Let qglsl multi consumer work with more consumers.
[mlt] / src / modules / core / consumer_multi.c
index 90223bbdbee14cd7fb47ea86dae3ae8499689067..1781746a419fec89f9c0b2d5f6b13eebbbb00576 100644 (file)
@@ -62,13 +62,15 @@ mlt_consumer consumer_multi_init( mlt_profile profile, mlt_service_type type, co
        return consumer;
 }
 
-static mlt_consumer create_consumer( mlt_profile profile, char *id )
+static mlt_consumer create_consumer( mlt_profile profile, char *id, char *arg )
 {
        char *myid = id ? strdup( id ) : NULL;
-       char *arg = myid ? strchr( myid, ':' ) : NULL;
-       if ( arg != NULL )
-               *arg ++ = '\0';
-       mlt_consumer consumer = mlt_factory_consumer( profile, myid, arg );
+       char *myarg = ( myid && !arg ) ? strchr( myid, ':' ) : NULL;
+       if ( myarg )
+               *myarg ++ = '\0';
+       else
+               myarg = arg;
+       mlt_consumer consumer = mlt_factory_consumer( profile, myid, myarg );
        if ( myid )
                free( myid );
        return consumer;
@@ -83,15 +85,19 @@ static void create_filter( mlt_profile profile, mlt_service service, char *effec
 
        // The swscale and avcolor_space filters require resolution as arg to test compatibility
        if ( strncmp( effect, "swscale", 7 ) == 0 || strncmp( effect, "avcolo", 6 ) == 0 )
-               arg = (char*) mlt_properties_get_int( MLT_SERVICE_PROPERTIES( service ), "_real_width" );
+               arg = (char*) mlt_properties_get_int( MLT_SERVICE_PROPERTIES( service ), "meta.media.width" );
 
-       mlt_filter filter = mlt_factory_filter( profile, id, arg );
-       if ( filter != NULL )
+       // We cannot use GLSL-based filters here.
+       if ( strncmp( effect, "movit.", 6 ) && strncmp( effect, "glsl.", 5 ) )
        {
-               mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
-               mlt_service_attach( service, filter );
-               mlt_filter_close( filter );
-               *created = 1;
+               mlt_filter filter = mlt_factory_filter( profile, id, arg );
+               if ( filter != NULL )
+               {
+                       mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
+                       mlt_service_attach( service, filter );
+                       mlt_filter_close( filter );
+                       *created = 1;
+               }
        }
        free( id );
 }
@@ -129,12 +135,27 @@ static void attach_normalisers( mlt_profile profile, mlt_service service )
 
        // Attach the audio and video format converters
        int created = 0;
+       // movit.convert skips setting the frame->convert_image pointer if GLSL cannot be used.
+       mlt_filter filter = mlt_factory_filter( profile, "movit.convert", NULL );
+       if ( filter != NULL )
+       {
+               mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
+               mlt_service_attach( service, filter );
+               mlt_filter_close( filter );
+               created = 1;
+       }
+       // avcolor_space and imageconvert only set frame->convert_image if it has not been set.
        create_filter( profile, service, "avcolor_space", &created );
        if ( !created )
                create_filter( profile, service, "imageconvert", &created );
        create_filter( profile, service, "audioconvert", &created );
 }
 
+static void on_frame_show( void *dummy, mlt_properties properties, mlt_frame frame )
+{
+       mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
+}
+
 static mlt_consumer generate_consumer( mlt_consumer consumer, mlt_properties props, int index )
 {
        mlt_profile profile = NULL;
@@ -142,7 +163,8 @@ static mlt_consumer generate_consumer( mlt_consumer consumer, mlt_properties pro
                profile = mlt_profile_init( mlt_properties_get( props, "mlt_profile" ) );
        if ( !profile )
                profile = mlt_profile_clone( mlt_service_profile( MLT_CONSUMER_SERVICE(consumer) ) );
-       mlt_consumer nested = create_consumer( profile, mlt_properties_get( props, "mlt_service" ) );
+       mlt_consumer nested = create_consumer( profile, mlt_properties_get( props, "mlt_service" ),
+               mlt_properties_get( props, "target" ) );
 
        if ( nested )
        {
@@ -163,6 +185,14 @@ static mlt_consumer generate_consumer( mlt_consumer consumer, mlt_properties pro
                mlt_properties_inherit( nested_props, props );
 
                attach_normalisers( profile, MLT_CONSUMER_SERVICE(nested) );
+
+               // Relay the first available consumer-frame-show event
+               mlt_event event = mlt_properties_get_data( properties, "frame-show-event", NULL );
+               if ( !event )
+               {
+                       event = mlt_events_listen( nested_props, properties, "consumer-frame-show", (mlt_listener) on_frame_show );
+                       mlt_properties_set_data( properties, "frame-show-event", event, 0, /*mlt_event_close*/ NULL, NULL );
+               }
        }
        else
        {
@@ -325,7 +355,8 @@ static void foreach_consumer_put( mlt_consumer consumer, mlt_frame frame )
                        while ( nested_time <= self_time )
                        {
                                // put ideal number of samples into cloned frame
-                               mlt_frame clone_frame = mlt_frame_clone( frame, 0 );
+                               int deeply = index > 1 ? 1 : 0;
+                               mlt_frame clone_frame = mlt_frame_clone( frame, deeply );
                                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;
@@ -501,7 +532,6 @@ static void *consumer_thread( void *arg )
                                if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES(frame), "_speed" ) == 0 )
                                        foreach_consumer_refresh( consumer );
                                foreach_consumer_put( consumer, frame );
-                               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
                        }
                        else
                        {
@@ -517,7 +547,6 @@ static void *consumer_thread( void *arg )
                        {
                                // Send this termination frame to nested consumers for their cancellation
                                foreach_consumer_put( consumer, frame );
-                               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
                        }
                        if ( frame )
                                mlt_frame_close( frame );