X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_consumer.c;h=0f2a97f93e9253c780567efb1cdbbd4eb39ba00a;hb=95f429b56026f5897ebad9060608b6631dcf7515;hp=edea67eaa2f499280666a1e1e5c131efc649cebb;hpb=9596911e0c624a73e354ecabfa9a565503d0ddf0;p=melted diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index edea67e..0f2a97f 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -28,6 +28,8 @@ #include #include +static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ); + /** Public final methods */ @@ -83,10 +85,19 @@ int mlt_consumer_init( mlt_consumer this, void *child ) // Hmm - default all consumers to yuv422 :-/ this->format = mlt_image_yuv422; + + mlt_events_register( properties, "consumer-frame-show", ( mlt_transmitter )mlt_consumer_frame_show ); + mlt_events_register( properties, "consumer-stopped", NULL ); } return error; } +static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) +{ + if ( listener != NULL ) + listener( owner, this, ( mlt_frame )args[ 0 ] ); +} + /** Create a new consumer. */ @@ -108,7 +119,7 @@ mlt_consumer mlt_consumer_new( ) mlt_service mlt_consumer_service( mlt_consumer this ) { - return &this->parent; + return this != NULL ? &this->parent : NULL; } /** Get the consumer properties. @@ -116,7 +127,7 @@ mlt_service mlt_consumer_service( mlt_consumer this ) mlt_properties mlt_consumer_properties( mlt_consumer this ) { - return mlt_service_properties( &this->parent ); + return this != NULL ? mlt_service_properties( &this->parent ) : NULL; } /** Connect the consumer to the producer. @@ -155,10 +166,6 @@ int mlt_consumer_start( mlt_consumer this ) // Set the test card on the consumer mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); } - - // Check and run an ante command - if ( mlt_properties_get( properties, "ante" ) ) - system( mlt_properties_get( properties, "ante" ) ); } } else @@ -167,6 +174,10 @@ int mlt_consumer_start( mlt_consumer this ) mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL ); } + // Check and run an ante command + if ( mlt_properties_get( properties, "ante" ) ) + system( mlt_properties_get( properties, "ante" ) ); + // Set the real_time preference this->real_time = mlt_properties_get_int( properties, "real_time" ); @@ -422,6 +433,18 @@ static void consumer_read_ahead_stop( mlt_consumer this ) } } +void mlt_consumer_purge( mlt_consumer this ) +{ + if ( this->ahead ) + { + pthread_mutex_lock( &this->mutex ); + while ( mlt_deque_count( this->queue ) ) + mlt_frame_close( mlt_deque_pop_back( this->queue ) ); + pthread_cond_broadcast( &this->cond ); + pthread_mutex_unlock( &this->mutex ); + } +} + mlt_frame mlt_consumer_rt_frame( mlt_consumer this ) { // Frame to return @@ -439,9 +462,10 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer this ) if ( this->ahead == 0 ) { int buffer = mlt_properties_get_int( properties, "buffer" ); + int prefill = mlt_properties_get_int( properties, "prefill" ); consumer_read_ahead_start( this ); if ( buffer > 1 ) - size = buffer; + size = prefill > 0 && prefill < buffer ? prefill : buffer; } // Get frame from queue @@ -464,6 +488,15 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer this ) return frame; } +/** Callback for the implementation to indicate a stopped condition. +*/ + +void mlt_consumer_stopped( mlt_consumer this ) +{ + mlt_properties_set_int( mlt_consumer_properties( this ), "running", 0 ); + mlt_events_fire( mlt_consumer_properties( this ), "consumer-stopped", NULL ); +} + /** Stop the consumer. */ @@ -507,15 +540,19 @@ int mlt_consumer_is_stopped( mlt_consumer this ) void mlt_consumer_close( mlt_consumer this ) { - // Get the childs close function - void ( *consumer_close )( ) = this->close; + if ( this != NULL && mlt_properties_dec_ref( mlt_consumer_properties( this ) ) <= 0 ) + { + // Get the childs close function + void ( *consumer_close )( ) = this->close; - // Make sure it only gets called once - this->close = NULL; + // Make sure it only gets called once + this->close = NULL; + this->parent.close = NULL; - // Call the childs close if available - if ( consumer_close != NULL ) - consumer_close( this ); - else - mlt_service_close( &this->parent ); + // Call the childs close if available + if ( consumer_close != NULL ) + consumer_close( this ); + else + mlt_service_close( &this->parent ); + } }