]> git.sesse.net Git - mlt/commitdiff
drain nested consumers of multi consumer
authorDan Dennedy <dan@dennedy.org>
Mon, 28 Nov 2011 21:49:04 +0000 (13:49 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 28 Nov 2011 21:49:04 +0000 (13:49 -0800)
src/modules/core/consumer_multi.c

index 566c95f8f63a267c4744c1ac64a5caba0e2d51b3..90223bbdbee14cd7fb47ea86dae3ae8499689067 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
+#include <sys/time.h>
 
 // Forward references
 static int start( mlt_consumer consumer );
@@ -379,11 +380,27 @@ static void foreach_consumer_stop( mlt_consumer consumer )
        mlt_consumer nested = NULL;
        char key[30];
        int index = 0;
+       struct timespec tm = { 0, 1000 * 1000 };
 
        do {
                snprintf( key, sizeof(key), "%d.consumer", index++ );
                nested = mlt_properties_get_data( properties, key, NULL );
-               if ( nested ) mlt_consumer_stop( nested );
+               if ( nested )
+               {
+                       // Let consumer with terminate_on_pause stop on their own
+                       if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES(nested), "terminate_on_pause" ) )
+                       {
+                               // Send additional dummy frame to unlatch nested consumer's threads
+                               mlt_consumer_put_frame( nested, mlt_frame_init( MLT_CONSUMER_SERVICE(consumer) ) );
+                               // wait for stop
+                               while ( !mlt_consumer_is_stopped( nested ) )
+                                       nanosleep( &tm, NULL );
+                       }
+                       else
+                       {
+                               mlt_consumer_stop( nested );
+                       }
+               }
        } while ( nested );
 }
 
@@ -496,7 +513,14 @@ static void *consumer_thread( void *arg )
                }
                else
                {
-                       if ( frame ) mlt_frame_close( frame );
+                       if ( frame && terminated )
+                       {
+                               // 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 );
                        terminated = 1;
                }
        }