3 * \brief abstraction for all consumer services
5 * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
6 * \author Charles Yates <charles.yates@pandora.be>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "mlt_consumer.h"
24 #include "mlt_factory.h"
25 #include "mlt_producer.h"
26 #include "mlt_frame.h"
27 #include "mlt_profile.h"
34 #undef DEINTERLACE_ON_NOT_NORMAL_SPEED
36 static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service this, void **args );
37 static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args );
38 static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name );
39 static void apply_profile_properties( mlt_consumer this, mlt_profile profile, mlt_properties properties );
41 int mlt_consumer_init( mlt_consumer this, void *child, mlt_profile profile )
44 memset( this, 0, sizeof( struct mlt_consumer_s ) );
46 error = mlt_service_init( &this->parent, this );
49 // Get the properties from the service
50 mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent );
52 // Apply profile to properties
53 if ( profile == NULL )
55 // Normally the application creates the profile and controls its lifetime
56 // This is the fallback exception handling
57 profile = mlt_profile_init( NULL );
58 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
59 mlt_properties_set_data( properties, "_profile", profile, 0, (mlt_destructor)mlt_profile_close, NULL );
61 apply_profile_properties( this, profile, properties );
63 // Default rescaler for all consumers
64 mlt_properties_set( properties, "rescale", "bilinear" );
66 // Default read ahead buffer size
67 mlt_properties_set_int( properties, "buffer", 25 );
69 // Default audio frequency and channels
70 mlt_properties_set_int( properties, "frequency", 48000 );
71 mlt_properties_set_int( properties, "channels", 2 );
73 // Default of all consumers is real time
74 mlt_properties_set_int( properties, "real_time", 1 );
76 // Default to environment test card
77 mlt_properties_set( properties, "test_card", mlt_environment( "MLT_TEST_CARD" ) );
79 // Hmm - default all consumers to yuv422 :-/
80 this->format = mlt_image_yuv422;
82 mlt_events_register( properties, "consumer-frame-show", ( mlt_transmitter )mlt_consumer_frame_show );
83 mlt_events_register( properties, "consumer-frame-render", ( mlt_transmitter )mlt_consumer_frame_render );
84 mlt_events_register( properties, "consumer-stopped", NULL );
86 // Register a property-changed listener to handle the profile property -
87 // subsequent properties can override the profile
88 this->event_listener = mlt_events_listen( properties, this, "property-changed", ( mlt_listener )mlt_consumer_property_changed );
90 // Create the push mutex and condition
91 pthread_mutex_init( &this->put_mutex, NULL );
92 pthread_cond_init( &this->put_cond, NULL );
98 static void apply_profile_properties( mlt_consumer this, mlt_profile profile, mlt_properties properties )
100 mlt_event_block( this->event_listener );
101 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
102 mlt_properties_set_int( properties, "frame_rate_num", profile->frame_rate_num );
103 mlt_properties_set_int( properties, "frame_rate_den", profile->frame_rate_den );
104 mlt_properties_set_int( properties, "width", profile->width );
105 mlt_properties_set_int( properties, "height", profile->height );
106 mlt_properties_set_int( properties, "progressive", profile->progressive );
107 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
108 mlt_properties_set_int( properties, "sample_aspect_num", profile->sample_aspect_num );
109 mlt_properties_set_int( properties, "sample_aspect_den", profile->sample_aspect_den );
110 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
111 mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
112 mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
113 mlt_event_unblock( this->event_listener );
116 static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name )
118 if ( !strcmp( name, "profile" ) )
121 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
123 // Get the current profile
124 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
126 // Load the new profile
127 mlt_profile new_profile = mlt_profile_init( mlt_properties_get( properties, name ) );
132 if ( profile != NULL )
134 free( profile->description );
135 memcpy( profile, new_profile, sizeof( struct mlt_profile_s ) );
136 profile->description = strdup( new_profile->description );
137 mlt_profile_close( new_profile );
141 profile = new_profile;
144 // Apply to properties
145 apply_profile_properties( this, profile, properties );
148 else if ( !strcmp( name, "frame_rate_num" ) )
150 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
151 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
154 profile->frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" );
155 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
158 else if ( !strcmp( name, "frame_rate_den" ) )
160 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
161 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
164 profile->frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" );
165 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
168 else if ( !strcmp( name, "width" ) )
170 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
171 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
173 profile->width = mlt_properties_get_int( properties, "width" );
175 else if ( !strcmp( name, "height" ) )
177 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
178 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
180 profile->height = mlt_properties_get_int( properties, "height" );
182 else if ( !strcmp( name, "progressive" ) )
184 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
185 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
187 profile->progressive = mlt_properties_get_int( properties, "progressive" );
189 else if ( !strcmp( name, "sample_aspect_num" ) )
191 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
192 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
193 profile->sample_aspect_num = mlt_properties_get_int( properties, "sample_aspect_num" );
195 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
197 else if ( !strcmp( name, "sample_aspect_den" ) )
199 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
200 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
201 profile->sample_aspect_den = mlt_properties_get_int( properties, "sample_aspect_den" );
203 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
205 else if ( !strcmp( name, "display_aspect_num" ) )
207 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
208 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
211 profile->display_aspect_num = mlt_properties_get_int( properties, "display_aspect_num" );
212 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
215 else if ( !strcmp( name, "display_aspect_den" ) )
217 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
218 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
221 profile->display_aspect_den = mlt_properties_get_int( properties, "display_aspect_den" );
222 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
227 static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args )
229 if ( listener != NULL )
230 listener( owner, this, ( mlt_frame )args[ 0 ] );
233 static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service this, void **args )
235 if ( listener != NULL )
236 listener( owner, this, ( mlt_frame )args[ 0 ] );
239 /** Create a new consumer.
242 mlt_consumer mlt_consumer_new( mlt_profile profile )
244 // Create the memory for the structure
245 mlt_consumer this = malloc( sizeof( struct mlt_consumer_s ) );
249 mlt_consumer_init( this, NULL, profile );
255 /** Get the parent service object.
258 mlt_service mlt_consumer_service( mlt_consumer this )
260 return this != NULL ? &this->parent : NULL;
263 /** Get the consumer properties.
266 mlt_properties mlt_consumer_properties( mlt_consumer this )
268 return this != NULL ? MLT_SERVICE_PROPERTIES( &this->parent ) : NULL;
271 /** Connect the consumer to the producer.
274 int mlt_consumer_connect( mlt_consumer this, mlt_service producer )
276 return mlt_service_connect_producer( &this->parent, producer, 0 );
279 /** Start the consumer.
282 int mlt_consumer_start( mlt_consumer this )
284 // Stop listening to the property-changed event
285 mlt_event_block( this->event_listener );
288 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
290 // Determine if there's a test card producer
291 char *test_card = mlt_properties_get( properties, "test_card" );
293 // Just to make sure nothing is hanging around...
294 mlt_frame_close( this->put );
296 this->put_active = 1;
299 if ( test_card != NULL )
301 if ( mlt_properties_get_data( properties, "test_card_producer", NULL ) == NULL )
303 // Create a test card producer
304 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
305 mlt_producer producer = mlt_factory_producer( profile, NULL, test_card );
307 // Do we have a producer
308 if ( producer != NULL )
310 // Test card should loop I guess...
311 mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" );
312 //mlt_producer_set_speed( producer, 0 );
313 //mlt_producer_set_in_and_out( producer, 0, 0 );
315 // Set the test card on the consumer
316 mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
322 // Allow the hash table to speed things up
323 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
326 // Set the frame duration in microseconds for the frame-dropping heuristic
327 int frame_duration = 1000000 / mlt_properties_get_int( properties, "frame_rate_num" ) *
328 mlt_properties_get_int( properties, "frame_rate_den" );
329 mlt_properties_set_int( properties, "frame_duration", frame_duration );
331 // Check and run an ante command
332 if ( mlt_properties_get( properties, "ante" ) )
333 system( mlt_properties_get( properties, "ante" ) );
335 // Set the real_time preference
336 this->real_time = mlt_properties_get_int( properties, "real_time" );
339 if ( this->start != NULL )
340 return this->start( this );
345 /** An alternative method to feed frames into the consumer - only valid if
346 the consumer itself is not connected.
349 int mlt_consumer_put_frame( mlt_consumer this, mlt_frame frame )
353 // Get the service assoicated to the consumer
354 mlt_service service = MLT_CONSUMER_SERVICE( this );
356 if ( mlt_service_producer( service ) == NULL )
360 pthread_mutex_lock( &this->put_mutex );
361 while ( this->put_active && this->put != NULL )
363 gettimeofday( &now, NULL );
364 tm.tv_sec = now.tv_sec + 1;
365 tm.tv_nsec = now.tv_usec * 1000;
366 pthread_cond_timedwait( &this->put_cond, &this->put_mutex, &tm );
368 if ( this->put_active && this->put == NULL )
371 mlt_frame_close( frame );
372 pthread_cond_broadcast( &this->put_cond );
373 pthread_mutex_unlock( &this->put_mutex );
377 mlt_frame_close( frame );
383 /** Protected method for consumer to get frames from connected service
386 mlt_frame mlt_consumer_get_frame( mlt_consumer this )
389 mlt_frame frame = NULL;
391 // Get the service assoicated to the consumer
392 mlt_service service = MLT_CONSUMER_SERVICE( this );
394 // Get the consumer properties
395 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
398 if ( mlt_service_producer( service ) == NULL && mlt_properties_get_int( properties, "put_mode" ) )
402 pthread_mutex_lock( &this->put_mutex );
403 while ( this->put_active && this->put == NULL )
405 gettimeofday( &now, NULL );
406 tm.tv_sec = now.tv_sec + 1;
407 tm.tv_nsec = now.tv_usec * 1000;
408 pthread_cond_timedwait( &this->put_cond, &this->put_mutex, &tm );
412 pthread_cond_broadcast( &this->put_cond );
413 pthread_mutex_unlock( &this->put_mutex );
415 mlt_service_apply_filters( service, frame, 0 );
417 else if ( mlt_service_producer( service ) != NULL )
419 mlt_service_get_frame( service, &frame, 0 );
423 frame = mlt_frame_init( service );
428 // Get the frame properties
429 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
431 // Get the test card producer
432 mlt_producer test_card = mlt_properties_get_data( properties, "test_card_producer", NULL );
434 // Attach the test frame producer to it.
435 if ( test_card != NULL )
436 mlt_properties_set_data( frame_properties, "test_card_producer", test_card, 0, NULL, NULL );
438 // Attach the rescale property
439 mlt_properties_set( frame_properties, "rescale.interp", mlt_properties_get( properties, "rescale" ) );
441 // Aspect ratio and other jiggery pokery
442 mlt_properties_set_double( frame_properties, "consumer_aspect_ratio", mlt_properties_get_double( properties, "aspect_ratio" ) );
443 mlt_properties_set_int( frame_properties, "consumer_deinterlace", mlt_properties_get_int( properties, "progressive" ) | mlt_properties_get_int( properties, "deinterlace" ) );
444 mlt_properties_set( frame_properties, "deinterlace_method", mlt_properties_get( properties, "deinterlace_method" ) );
451 static inline long time_difference( struct timeval *time1 )
453 struct timeval time2;
454 time2.tv_sec = time1->tv_sec;
455 time2.tv_usec = time1->tv_usec;
456 gettimeofday( time1, NULL );
457 return time1->tv_sec * 1000000 + time1->tv_usec - time2.tv_sec * 1000000 - time2.tv_usec;
460 static void *consumer_read_ahead_thread( void *arg )
462 // The argument is the consumer
463 mlt_consumer this = arg;
465 // Get the properties of the consumer
466 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
468 // Get the width and height
469 int width = mlt_properties_get_int( properties, "width" );
470 int height = mlt_properties_get_int( properties, "height" );
472 // See if video is turned off
473 int video_off = mlt_properties_get_int( properties, "video_off" );
474 int preview_off = mlt_properties_get_int( properties, "preview_off" );
475 int preview_format = mlt_properties_get_int( properties, "preview_format" );
477 // Get the audio settings
478 mlt_audio_format afmt = mlt_audio_pcm;
480 double fps = mlt_properties_get_double( properties, "fps" );
481 int channels = mlt_properties_get_int( properties, "channels" );
482 int frequency = mlt_properties_get_int( properties, "frequency" );
486 // See if audio is turned off
487 int audio_off = mlt_properties_get_int( properties, "audio_off" );
489 // Get the maximum size of the buffer
490 int buffer = mlt_properties_get_int( properties, "buffer" ) + 1;
492 // General frame variable
493 mlt_frame frame = NULL;
494 uint8_t *image = NULL;
499 // Average time for get_frame and get_image
502 int64_t time_wait = 0;
503 int64_t time_frame = 0;
504 int64_t time_process = 0;
506 mlt_service lock_object = NULL;
508 if ( preview_off && preview_format != 0 )
509 this->format = preview_format;
511 // Get the first frame
512 frame = mlt_consumer_get_frame( this );
514 // Get the lock object
515 lock_object = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "consumer_lock_service", NULL );
518 if ( lock_object ) mlt_service_lock( lock_object );
520 // Get the image of the first frame
523 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame, NULL );
524 mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 );
529 samples = mlt_sample_calculator( fps, frequency, counter++ );
530 mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples );
533 // Unlock the lock object
534 if ( lock_object ) mlt_service_unlock( lock_object );
537 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
539 // Get the starting time (can ignore the times above)
540 gettimeofday( &ante, NULL );
542 // Continue to read ahead
543 while ( this->ahead )
545 // Fetch width/height again
546 width = mlt_properties_get_int( properties, "width" );
547 height = mlt_properties_get_int( properties, "height" );
549 // Put the current frame into the queue
550 pthread_mutex_lock( &this->mutex );
551 while( this->ahead && mlt_deque_count( this->queue ) >= buffer )
552 pthread_cond_wait( &this->cond, &this->mutex );
553 mlt_deque_push_back( this->queue, frame );
554 pthread_cond_broadcast( &this->cond );
555 pthread_mutex_unlock( &this->mutex );
557 time_wait += time_difference( &ante );
559 // Get the next frame
560 frame = mlt_consumer_get_frame( this );
561 time_frame += time_difference( &ante );
563 // If there's no frame, we're probably stopped...
567 // Attempt to fetch the lock object
568 lock_object = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "consumer_lock_service", NULL );
570 // Increment the count
573 // Lock if there's a lock object
574 if ( lock_object ) mlt_service_lock( lock_object );
576 // All non normal playback frames should be shown
577 if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "_speed" ) != 1 )
579 #ifdef DEINTERLACE_ON_NOT_NORMAL_SPEED
580 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "consumer_deinterlace", 1 );
591 if ( !skip_next || this->real_time == -1 )
593 // Get the image, mark as rendered and time it
596 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame, NULL );
597 mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 );
599 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
603 // Increment the number of sequentially skipped frames
607 // If we've reached an unacceptable level, reset everything
618 // Always process audio
621 samples = mlt_sample_calculator( fps, frequency, counter++ );
622 mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples );
625 // Increment the time take for this frame
626 time_process += time_difference( &ante );
628 // Determine if the next frame should be skipped
629 if ( mlt_deque_count( this->queue ) <= 5 )
631 int frame_duration = mlt_properties_get_int( properties, "frame_duration" );
632 if ( ( ( time_wait + time_frame + time_process ) / count ) > frame_duration )
636 // Unlock if there's a lock object
637 if ( lock_object ) mlt_service_unlock( lock_object );
640 // Remove the last frame
641 mlt_frame_close( frame );
646 static void consumer_read_ahead_start( mlt_consumer this )
651 // Create the frame queue
652 this->queue = mlt_deque_init( );
655 pthread_mutex_init( &this->mutex, NULL );
657 // Create the condition
658 pthread_cond_init( &this->cond, NULL );
660 // Create the read ahead
661 if ( mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "priority" ) )
663 struct sched_param priority;
664 priority.sched_priority = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( this ), "priority" );
665 pthread_attr_t thread_attributes;
666 pthread_attr_init( &thread_attributes );
667 pthread_attr_setschedpolicy( &thread_attributes, SCHED_OTHER );
668 pthread_attr_setschedparam( &thread_attributes, &priority );
669 pthread_attr_setinheritsched( &thread_attributes, PTHREAD_EXPLICIT_SCHED );
670 pthread_attr_setscope( &thread_attributes, PTHREAD_SCOPE_SYSTEM );
671 if ( pthread_create( &this->ahead_thread, &thread_attributes, consumer_read_ahead_thread, this ) < 0 )
672 pthread_create( &this->ahead_thread, NULL, consumer_read_ahead_thread, this );
673 pthread_attr_destroy( &thread_attributes );
677 pthread_create( &this->ahead_thread, NULL, consumer_read_ahead_thread, this );
681 static void consumer_read_ahead_stop( mlt_consumer this )
683 // Make sure we're running
686 // Inform thread to stop
689 // Broadcast to the condition in case it's waiting
690 pthread_mutex_lock( &this->mutex );
691 pthread_cond_broadcast( &this->cond );
692 pthread_mutex_unlock( &this->mutex );
694 // Broadcast to the put condition in case it's waiting
695 pthread_mutex_lock( &this->put_mutex );
696 pthread_cond_broadcast( &this->put_cond );
697 pthread_mutex_unlock( &this->put_mutex );
700 pthread_join( this->ahead_thread, NULL );
703 pthread_mutex_destroy( &this->mutex );
705 // Destroy the condition
706 pthread_cond_destroy( &this->cond );
709 while ( mlt_deque_count( this->queue ) )
710 mlt_frame_close( mlt_deque_pop_back( this->queue ) );
713 mlt_deque_close( this->queue );
717 void mlt_consumer_purge( mlt_consumer this )
721 pthread_mutex_lock( &this->mutex );
722 while ( mlt_deque_count( this->queue ) )
723 mlt_frame_close( mlt_deque_pop_back( this->queue ) );
724 pthread_cond_broadcast( &this->cond );
725 pthread_mutex_unlock( &this->mutex );
729 mlt_frame mlt_consumer_rt_frame( mlt_consumer this )
732 mlt_frame frame = NULL;
734 // Get the properties
735 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
737 // Check if the user has requested real time or not
738 if ( this->real_time )
742 // Is the read ahead running?
743 if ( this->ahead == 0 )
745 int buffer = mlt_properties_get_int( properties, "buffer" );
746 int prefill = mlt_properties_get_int( properties, "prefill" );
747 consumer_read_ahead_start( this );
749 size = prefill > 0 && prefill < buffer ? prefill : buffer;
752 // Get frame from queue
753 pthread_mutex_lock( &this->mutex );
754 while( this->ahead && mlt_deque_count( this->queue ) < size )
755 pthread_cond_wait( &this->cond, &this->mutex );
756 frame = mlt_deque_pop_front( this->queue );
757 pthread_cond_broadcast( &this->cond );
758 pthread_mutex_unlock( &this->mutex );
762 // Get the frame in non real time
763 frame = mlt_consumer_get_frame( this );
765 // This isn't true, but from the consumers perspective it is
767 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
773 /** Callback for the implementation to indicate a stopped condition.
776 void mlt_consumer_stopped( mlt_consumer this )
778 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "running", 0 );
779 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-stopped", NULL );
780 mlt_event_unblock( this->event_listener );
783 /** Stop the consumer.
786 int mlt_consumer_stop( mlt_consumer this )
789 mlt_properties properties = MLT_CONSUMER_PROPERTIES( this );
790 char *debug = mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "debug" );
793 if ( debug ) fprintf( stderr, "%s: stopping put waiting\n", debug );
794 pthread_mutex_lock( &this->put_mutex );
795 this->put_active = 0;
796 pthread_cond_broadcast( &this->put_cond );
797 pthread_mutex_unlock( &this->put_mutex );
800 if ( debug ) fprintf( stderr, "%s: stopping consumer\n", debug );
801 if ( this->stop != NULL )
804 // Check if the user has requested real time or not and stop if necessary
805 if ( debug ) fprintf( stderr, "%s: stopping read_ahead\n", debug );
806 if ( mlt_properties_get_int( properties, "real_time" ) )
807 consumer_read_ahead_stop( this );
809 // Kill the test card
810 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
812 // Check and run a post command
813 if ( mlt_properties_get( properties, "post" ) )
814 system( mlt_properties_get( properties, "post" ) );
816 if ( debug ) fprintf( stderr, "%s: stopped\n", debug );
821 /** Determine if the consumer is stopped.
824 int mlt_consumer_is_stopped( mlt_consumer this )
826 // Check if the consumer is stopped
827 if ( this->is_stopped != NULL )
828 return this->is_stopped( this );
833 /** Close the consumer.
836 void mlt_consumer_close( mlt_consumer this )
838 if ( this != NULL && mlt_properties_dec_ref( MLT_CONSUMER_PROPERTIES( this ) ) <= 0 )
840 // Get the childs close function
841 void ( *consumer_close )( ) = this->close;
843 if ( consumer_close )
846 //mlt_consumer_stop( this );
849 consumer_close( this );
853 // Make sure it only gets called once
854 this->parent.close = NULL;
856 // Destroy the push mutex and condition
857 pthread_mutex_destroy( &this->put_mutex );
858 pthread_cond_destroy( &this->put_cond );
860 mlt_service_close( &this->parent );