2 * mlt_consumer.c -- abstraction for all consumer services
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "mlt_consumer.h"
23 #include "mlt_factory.h"
24 #include "mlt_producer.h"
25 #include "mlt_frame.h"
26 #include "mlt_profile.h"
33 static void mlt_consumer_frame_render( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
34 static void mlt_consumer_frame_show( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
35 static void mlt_consumer_property_changed( mlt_service owner
, mlt_consumer
this, char *name
);
36 static void apply_profile_properties( mlt_consumer
this, mlt_profile profile
, mlt_properties properties
);
38 /** Public final methods
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 // Check and run an ante command
327 if ( mlt_properties_get( properties
, "ante" ) )
328 system( mlt_properties_get( properties
, "ante" ) );
330 // Set the real_time preference
331 this->real_time
= mlt_properties_get_int( properties
, "real_time" );
334 if ( this->start
!= NULL
)
335 return this->start( this );
340 /** An alternative method to feed frames into the consumer - only valid if
341 the consumer itself is not connected.
344 int mlt_consumer_put_frame( mlt_consumer
this, mlt_frame frame
)
348 // Get the service assoicated to the consumer
349 mlt_service service
= MLT_CONSUMER_SERVICE( this );
351 if ( mlt_service_producer( service
) == NULL
)
355 pthread_mutex_lock( &this->put_mutex
);
356 while ( this->put_active
&& this->put
!= NULL
)
358 gettimeofday( &now
, NULL
);
359 tm
.tv_sec
= now
.tv_sec
+ 1;
360 tm
.tv_nsec
= now
.tv_usec
* 1000;
361 pthread_cond_timedwait( &this->put_cond
, &this->put_mutex
, &tm
);
363 if ( this->put_active
&& this->put
== NULL
)
366 mlt_frame_close( frame
);
367 pthread_cond_broadcast( &this->put_cond
);
368 pthread_mutex_unlock( &this->put_mutex
);
372 mlt_frame_close( frame
);
378 /** Protected method for consumer to get frames from connected service
381 mlt_frame
mlt_consumer_get_frame( mlt_consumer
this )
384 mlt_frame frame
= NULL
;
386 // Get the service assoicated to the consumer
387 mlt_service service
= MLT_CONSUMER_SERVICE( this );
389 // Get the consumer properties
390 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
393 if ( mlt_service_producer( service
) == NULL
&& mlt_properties_get_int( properties
, "put_mode" ) )
397 pthread_mutex_lock( &this->put_mutex
);
398 while ( this->put_active
&& this->put
== NULL
)
400 gettimeofday( &now
, NULL
);
401 tm
.tv_sec
= now
.tv_sec
+ 1;
402 tm
.tv_nsec
= now
.tv_usec
* 1000;
403 pthread_cond_timedwait( &this->put_cond
, &this->put_mutex
, &tm
);
407 pthread_cond_broadcast( &this->put_cond
);
408 pthread_mutex_unlock( &this->put_mutex
);
410 mlt_service_apply_filters( service
, frame
, 0 );
412 else if ( mlt_service_producer( service
) != NULL
)
414 mlt_service_get_frame( service
, &frame
, 0 );
418 frame
= mlt_frame_init( service
);
423 // Get the frame properties
424 mlt_properties frame_properties
= MLT_FRAME_PROPERTIES( frame
);
426 // Get the test card producer
427 mlt_producer test_card
= mlt_properties_get_data( properties
, "test_card_producer", NULL
);
429 // Attach the test frame producer to it.
430 if ( test_card
!= NULL
)
431 mlt_properties_set_data( frame_properties
, "test_card_producer", test_card
, 0, NULL
, NULL
);
433 // Attach the rescale property
434 mlt_properties_set( frame_properties
, "rescale.interp", mlt_properties_get( properties
, "rescale" ) );
436 // Aspect ratio and other jiggery pokery
437 mlt_properties_set_double( frame_properties
, "consumer_aspect_ratio", mlt_properties_get_double( properties
, "aspect_ratio" ) );
438 mlt_properties_set_int( frame_properties
, "consumer_deinterlace", mlt_properties_get_int( properties
, "progressive" ) | mlt_properties_get_int( properties
, "deinterlace" ) );
439 mlt_properties_set( frame_properties
, "deinterlace_method", mlt_properties_get( properties
, "deinterlace_method" ) );
446 static inline long time_difference( struct timeval
*time1
)
448 struct timeval time2
;
449 time2
.tv_sec
= time1
->tv_sec
;
450 time2
.tv_usec
= time1
->tv_usec
;
451 gettimeofday( time1
, NULL
);
452 return time1
->tv_sec
* 1000000 + time1
->tv_usec
- time2
.tv_sec
* 1000000 - time2
.tv_usec
;
455 static void *consumer_read_ahead_thread( void *arg
)
457 // The argument is the consumer
458 mlt_consumer
this = arg
;
460 // Get the properties of the consumer
461 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
463 // Get the width and height
464 int width
= mlt_properties_get_int( properties
, "width" );
465 int height
= mlt_properties_get_int( properties
, "height" );
467 // See if video is turned off
468 int video_off
= mlt_properties_get_int( properties
, "video_off" );
469 int preview_off
= mlt_properties_get_int( properties
, "preview_off" );
470 int preview_format
= mlt_properties_get_int( properties
, "preview_format" );
472 // Get the audio settings
473 mlt_audio_format afmt
= mlt_audio_pcm
;
475 double fps
= mlt_properties_get_double( properties
, "fps" );
476 int channels
= mlt_properties_get_int( properties
, "channels" );
477 int frequency
= mlt_properties_get_int( properties
, "frequency" );
481 // See if audio is turned off
482 int audio_off
= mlt_properties_get_int( properties
, "audio_off" );
484 // Get the maximum size of the buffer
485 int buffer
= mlt_properties_get_int( properties
, "buffer" ) + 1;
487 // General frame variable
488 mlt_frame frame
= NULL
;
489 uint8_t *image
= NULL
;
494 // Average time for get_frame and get_image
497 int64_t time_wait
= 0;
498 int64_t time_frame
= 0;
499 int64_t time_process
= 0;
501 mlt_service lock_object
= NULL
;
503 if ( preview_off
&& preview_format
!= 0 )
504 this->format
= preview_format
;
506 // Get the first frame
507 frame
= mlt_consumer_get_frame( this );
509 // Get the lock object
510 lock_object
= mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame
), "consumer_lock_service", NULL
);
513 if ( lock_object
) mlt_service_lock( lock_object
);
515 // Get the image of the first frame
518 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame
, NULL
);
519 mlt_frame_get_image( frame
, &image
, &this->format
, &width
, &height
, 0 );
524 samples
= mlt_sample_calculator( fps
, frequency
, counter
++ );
525 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
528 // Unlock the lock object
529 if ( lock_object
) mlt_service_unlock( lock_object
);
532 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
534 // Get the starting time (can ignore the times above)
535 gettimeofday( &ante
, NULL
);
537 // Continue to read ahead
538 while ( this->ahead
)
540 // Fetch width/height again
541 width
= mlt_properties_get_int( properties
, "width" );
542 height
= mlt_properties_get_int( properties
, "height" );
544 // Put the current frame into the queue
545 pthread_mutex_lock( &this->mutex
);
546 while( this->ahead
&& mlt_deque_count( this->queue
) >= buffer
)
547 pthread_cond_wait( &this->cond
, &this->mutex
);
548 mlt_deque_push_back( this->queue
, frame
);
549 pthread_cond_broadcast( &this->cond
);
550 pthread_mutex_unlock( &this->mutex
);
552 time_wait
+= time_difference( &ante
);
554 // Get the next frame
555 frame
= mlt_consumer_get_frame( this );
556 time_frame
+= time_difference( &ante
);
558 // If there's no frame, we're probably stopped...
562 // Attempt to fetch the lock object
563 lock_object
= mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame
), "consumer_lock_service", NULL
);
565 // Increment the count
568 // Lock if there's a lock object
569 if ( lock_object
) mlt_service_lock( lock_object
);
571 // All non normal playback frames should be shown
572 if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame
), "_speed" ) != 1 )
574 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "consumer_deinterlace", 1 );
586 // Get the image, mark as rendered and time it
589 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame
, NULL
);
590 mlt_frame_get_image( frame
, &image
, &this->format
, &width
, &height
, 0 );
592 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
596 // Increment the number of sequentially skipped frames
600 // If we've reached an unacceptable level, reset everything
611 // Always process audio
614 samples
= mlt_sample_calculator( fps
, frequency
, counter
++ );
615 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
618 // Increment the time take for this frame
619 time_process
+= time_difference( &ante
);
621 // Determine if the next frame should be skipped
622 if ( mlt_deque_count( this->queue
) <= 5 && ( ( time_wait
+ time_frame
+ time_process
) / count
) > 40000 )
625 // Unlock if there's a lock object
626 if ( lock_object
) mlt_service_unlock( lock_object
);
629 // Remove the last frame
630 mlt_frame_close( frame
);
635 static void consumer_read_ahead_start( mlt_consumer
this )
640 // Create the frame queue
641 this->queue
= mlt_deque_init( );
644 pthread_mutex_init( &this->mutex
, NULL
);
646 // Create the condition
647 pthread_cond_init( &this->cond
, NULL
);
649 // Create the read ahead
650 pthread_create( &this->ahead_thread
, NULL
, consumer_read_ahead_thread
, this );
653 static void consumer_read_ahead_stop( mlt_consumer
this )
655 // Make sure we're running
658 // Inform thread to stop
661 // Broadcast to the condition in case it's waiting
662 pthread_mutex_lock( &this->mutex
);
663 pthread_cond_broadcast( &this->cond
);
664 pthread_mutex_unlock( &this->mutex
);
666 // Broadcast to the put condition in case it's waiting
667 pthread_mutex_lock( &this->put_mutex
);
668 pthread_cond_broadcast( &this->put_cond
);
669 pthread_mutex_unlock( &this->put_mutex
);
672 pthread_join( this->ahead_thread
, NULL
);
675 pthread_mutex_destroy( &this->mutex
);
677 // Destroy the condition
678 pthread_cond_destroy( &this->cond
);
681 while ( mlt_deque_count( this->queue
) )
682 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
685 mlt_deque_close( this->queue
);
689 void mlt_consumer_purge( mlt_consumer
this )
693 pthread_mutex_lock( &this->mutex
);
694 while ( mlt_deque_count( this->queue
) )
695 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
696 pthread_cond_broadcast( &this->cond
);
697 pthread_mutex_unlock( &this->mutex
);
701 mlt_frame
mlt_consumer_rt_frame( mlt_consumer
this )
704 mlt_frame frame
= NULL
;
706 // Get the properties
707 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
709 // Check if the user has requested real time or not
710 if ( this->real_time
)
714 // Is the read ahead running?
715 if ( this->ahead
== 0 )
717 int buffer
= mlt_properties_get_int( properties
, "buffer" );
718 int prefill
= mlt_properties_get_int( properties
, "prefill" );
719 consumer_read_ahead_start( this );
721 size
= prefill
> 0 && prefill
< buffer ? prefill
: buffer
;
724 // Get frame from queue
725 pthread_mutex_lock( &this->mutex
);
726 while( this->ahead
&& mlt_deque_count( this->queue
) < size
)
727 pthread_cond_wait( &this->cond
, &this->mutex
);
728 frame
= mlt_deque_pop_front( this->queue
);
729 pthread_cond_broadcast( &this->cond
);
730 pthread_mutex_unlock( &this->mutex
);
734 // Get the frame in non real time
735 frame
= mlt_consumer_get_frame( this );
737 // This isn't true, but from the consumers perspective it is
739 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
745 /** Callback for the implementation to indicate a stopped condition.
748 void mlt_consumer_stopped( mlt_consumer
this )
750 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "running", 0 );
751 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-stopped", NULL
);
752 mlt_event_unblock( this->event_listener
);
755 /** Stop the consumer.
758 int mlt_consumer_stop( mlt_consumer
this )
761 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
762 char *debug
= mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "debug" );
765 if ( debug
) fprintf( stderr
, "%s: stopping put waiting\n", debug
);
766 pthread_mutex_lock( &this->put_mutex
);
767 this->put_active
= 0;
768 pthread_cond_broadcast( &this->put_cond
);
769 pthread_mutex_unlock( &this->put_mutex
);
772 if ( debug
) fprintf( stderr
, "%s: stopping consumer\n", debug
);
773 if ( this->stop
!= NULL
)
776 // Check if the user has requested real time or not and stop if necessary
777 if ( debug
) fprintf( stderr
, "%s: stopping read_ahead\n", debug
);
778 if ( mlt_properties_get_int( properties
, "real_time" ) )
779 consumer_read_ahead_stop( this );
781 // Kill the test card
782 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
784 // Check and run a post command
785 if ( mlt_properties_get( properties
, "post" ) )
786 system( mlt_properties_get( properties
, "post" ) );
788 if ( debug
) fprintf( stderr
, "%s: stopped\n", debug
);
793 /** Determine if the consumer is stopped.
796 int mlt_consumer_is_stopped( mlt_consumer
this )
798 // Check if the consumer is stopped
799 if ( this->is_stopped
!= NULL
)
800 return this->is_stopped( this );
805 /** Close the consumer.
808 void mlt_consumer_close( mlt_consumer
this )
810 if ( this != NULL
&& mlt_properties_dec_ref( MLT_CONSUMER_PROPERTIES( this ) ) <= 0 )
812 // Get the childs close function
813 void ( *consumer_close
)( ) = this->close
;
815 if ( consumer_close
)
818 //mlt_consumer_stop( this );
821 consumer_close( this );
825 // Make sure it only gets called once
826 this->parent
.close
= NULL
;
828 // Destroy the push mutex and condition
829 pthread_mutex_destroy( &this->put_mutex
);
830 pthread_cond_destroy( &this->put_cond
);
832 mlt_service_close( &this->parent
);