]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_consumer.c
Return a sensible size for glsl image types.
[mlt] / src / framework / mlt_consumer.c
index f9eb80651338ede8a5bd8c870dba7b14314b89d4..74b946d403641d0f5a48d4633dd26c743fb43580 100644 (file)
@@ -140,6 +140,7 @@ int mlt_consumer_init( mlt_consumer self, void *child, mlt_profile profile )
                mlt_events_register( properties, "consumer-frame-render", ( mlt_transmitter )mlt_consumer_frame_render );
                mlt_events_register( properties, "consumer-thread-started", NULL );
                mlt_events_register( properties, "consumer-thread-stopped", NULL );
+               mlt_events_register( properties, "consumer-stopping", NULL );
                mlt_events_register( properties, "consumer-stopped", NULL );
                mlt_events_listen( properties, self, "consumer-frame-show", ( mlt_listener )on_consumer_frame_show );
 
@@ -178,7 +179,7 @@ static void apply_profile_properties( mlt_consumer self, mlt_profile profile, ml
        mlt_properties_set_int( properties, "sample_aspect_den", profile->sample_aspect_den );
        mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile )  );
        mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
-       mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
+       mlt_properties_set_int( properties, "display_aspect_den", profile->display_aspect_den );
        mlt_properties_set_int( properties, "colorspace", profile->colorspace );
        mlt_event_unblock( priv->event_listener );
 }
@@ -806,6 +807,9 @@ static void *consumer_read_ahead_thread( void *arg )
                        continue;
                pos = mlt_frame_get_position( frame );
 
+               // WebVfx uses this to setup a consumer-stopping event handler.
+               mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), "consumer", self, 0, NULL, NULL );
+
                // Increment the counter used for averaging processing cost
                count ++;
 
@@ -908,7 +912,6 @@ static void *consumer_read_ahead_thread( void *arg )
 
        // Remove the last frame
        mlt_frame_close( frame );
-       mlt_events_fire( properties, "consumer-thread-stopped", NULL );
 
        return NULL;
 }
@@ -990,7 +993,7 @@ static void *consumer_worker_thread( void *arg )
                frame = mlt_deque_peek( priv->queue, index );
                if ( frame )
                {
-                       mlt_log_debug( MLT_CONSUMER_SERVICE(self), "worker processing index = %d frame %d queue count = %d\n",
+                       mlt_log_debug( MLT_CONSUMER_SERVICE(self), "worker processing index = %d frame " MLT_POSITION_FMT " queue count = %d\n",
                                index, mlt_frame_get_position(frame), mlt_deque_count( priv->queue ) );
                        frame->is_processing = 1;
                        mlt_properties_inc_ref( MLT_FRAME_PROPERTIES( frame ) );
@@ -1001,6 +1004,9 @@ static void *consumer_worker_thread( void *arg )
                if ( frame == NULL )
                        continue;
 
+               // WebVfx uses this to setup a consumer-stopping event handler.
+               mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), "consumer", self, 0, NULL, NULL );
+
 #ifdef DEINTERLACE_ON_NOT_NORMAL_SPEED
                // All non normal playback frames should be shown
                if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "_speed" ) != 1 )
@@ -1024,7 +1030,6 @@ static void *consumer_worker_thread( void *arg )
                pthread_cond_broadcast( &priv->done_cond );
                pthread_mutex_unlock( &priv->done_mutex );
        }
-       mlt_events_fire( properties, "consumer-thread-stopped", NULL );
 
        return NULL;
 }
@@ -1039,6 +1044,9 @@ static void consumer_read_ahead_start( mlt_consumer self )
 {
        consumer_private *priv = self->local;
 
+       if ( priv->started )
+               return;
+
        // We're running now
        priv->ahead = 1;
 
@@ -1083,7 +1091,12 @@ static void consumer_work_start( mlt_consumer self )
 {
        consumer_private *priv = self->local;
        int n = abs( priv->real_time );
-       pthread_t *thread = calloc( 1, sizeof( pthread_t ) * n );
+       pthread_t *thread;
+
+       if ( priv->started )
+               return;
+
+       thread = calloc( 1, sizeof( pthread_t ) * n );
 
        // We're running now
        priv->ahead = 1;
@@ -1168,6 +1181,7 @@ static void consumer_read_ahead_stop( mlt_consumer self )
 #endif
                // Inform thread to stop
                priv->ahead = 0;
+               mlt_events_fire( MLT_CONSUMER_PROPERTIES(self), "consumer-stopping", NULL );
 
                // Broadcast to the condition in case it's waiting
                pthread_mutex_lock( &priv->queue_mutex );
@@ -1194,6 +1208,8 @@ static void consumer_read_ahead_stop( mlt_consumer self )
 
                // Close the queue
                mlt_deque_close( priv->queue );
+
+               mlt_events_fire( MLT_CONSUMER_PROPERTIES(self), "consumer-thread-stopped", NULL );
        }
 }
 
@@ -1218,6 +1234,7 @@ static void consumer_work_stop( mlt_consumer self )
 #endif
                // Inform thread to stop
                priv->ahead = 0;
+               mlt_events_fire( MLT_CONSUMER_PROPERTIES(self), "consumer-stopping", NULL );
 
                // Broadcast to the queue condition in case it's waiting
                pthread_mutex_lock( &priv->queue_mutex );
@@ -1258,6 +1275,8 @@ static void consumer_work_stop( mlt_consumer self )
                // Close the queues
                mlt_deque_close( priv->queue );
                mlt_deque_close( priv->worker_threads );
+
+               mlt_events_fire( MLT_CONSUMER_PROPERTIES(self), "consumer-thread-stopped", NULL );
        }
 }
 
@@ -1281,14 +1300,15 @@ void mlt_consumer_purge( mlt_consumer self )
                pthread_cond_broadcast( &priv->put_cond );
                pthread_mutex_unlock( &priv->put_mutex );
 
-               if ( priv->started && priv->real_time )
-                       pthread_mutex_lock( &priv->queue_mutex );
-
                if ( self->purge )
                        self->purge( self );
 
+               if ( priv->started && priv->real_time )
+                       pthread_mutex_lock( &priv->queue_mutex );
+
                while ( priv->started && mlt_deque_count( priv->queue ) )
                        mlt_frame_close( mlt_deque_pop_back( priv->queue ) );
+
                if ( priv->started && priv->real_time )
                {
                        priv->is_purge = 1;
@@ -1508,7 +1528,12 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer self )
 
                // This isn't true, but from the consumers perspective it is
                if ( frame != NULL )
+               {
                        mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
+
+                       // WebVfx uses this to setup a consumer-stopping event handler.
+                       mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), "consumer", self, 0, NULL, NULL );
+               }
        }
 
        return frame;
@@ -1551,7 +1576,6 @@ int mlt_consumer_stop( mlt_consumer self )
        mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_DEBUG, "stopping consumer\n" );
        
        // Cancel the read ahead threads
-       priv->ahead = 0;
        if ( priv->started )
        {
                // Unblock the consumer calling mlt_consumer_rt_frame