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
21 #include "mlt_consumer.h"
22 #include "mlt_factory.h"
23 #include "mlt_producer.h"
24 #include "mlt_frame.h"
25 #include "mlt_profile.h"
32 static void mlt_consumer_frame_render( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
33 static void mlt_consumer_frame_show( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
34 static void mlt_consumer_property_changed( mlt_service owner
, mlt_consumer
this, char *name
);
35 static void apply_profile_properties( mlt_consumer
this, mlt_profile profile
, mlt_properties properties
);
37 /** Public final methods
40 int mlt_consumer_init( mlt_consumer
this, void *child
, mlt_profile profile
)
43 memset( this, 0, sizeof( struct mlt_consumer_s
) );
45 error
= mlt_service_init( &this->parent
, this );
48 // Get the properties from the service
49 mlt_properties properties
= MLT_SERVICE_PROPERTIES( &this->parent
);
51 // Apply profile to properties
52 if ( profile
== NULL
)
54 // Normally the application creates the profile and controls its lifetime
55 // This is the fallback exception handling
56 profile
= mlt_profile_init( NULL
);
57 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
58 mlt_properties_set_data( properties
, "_profile", profile
, 0, (mlt_destructor
)mlt_profile_close
, NULL
);
60 apply_profile_properties( this, profile
, properties
);
62 // Default rescaler for all consumers
63 mlt_properties_set( properties
, "rescale", "bilinear" );
65 // Default read ahead buffer size
66 mlt_properties_set_int( properties
, "buffer", 25 );
68 // Default audio frequency and channels
69 mlt_properties_set_int( properties
, "frequency", 48000 );
70 mlt_properties_set_int( properties
, "channels", 2 );
72 // Default of all consumers is real time
73 mlt_properties_set_int( properties
, "real_time", 1 );
75 // Default to environment test card
76 mlt_properties_set( properties
, "test_card", mlt_environment( "MLT_TEST_CARD" ) );
78 // Hmm - default all consumers to yuv422 :-/
79 this->format
= mlt_image_yuv422
;
81 mlt_events_register( properties
, "consumer-frame-show", ( mlt_transmitter
)mlt_consumer_frame_show
);
82 mlt_events_register( properties
, "consumer-frame-render", ( mlt_transmitter
)mlt_consumer_frame_render
);
83 mlt_events_register( properties
, "consumer-stopped", NULL
);
85 // Register a property-changed listener to handle the profile property -
86 // subsequent properties can override the profile
87 this->event_listener
= mlt_events_listen( properties
, this, "property-changed", ( mlt_listener
)mlt_consumer_property_changed
);
89 // Create the push mutex and condition
90 pthread_mutex_init( &this->put_mutex
, NULL
);
91 pthread_cond_init( &this->put_cond
, NULL
);
97 static void apply_profile_properties( mlt_consumer
this, mlt_profile profile
, mlt_properties properties
)
99 mlt_event_block( this->event_listener
);
100 mlt_properties_set_double( properties
, "fps", mlt_profile_fps( profile
) );
101 mlt_properties_set_int( properties
, "frame_rate_num", profile
->frame_rate_num
);
102 mlt_properties_set_int( properties
, "frame_rate_den", profile
->frame_rate_den
);
103 mlt_properties_set_int( properties
, "width", profile
->width
);
104 mlt_properties_set_int( properties
, "height", profile
->height
);
105 mlt_properties_set_int( properties
, "progressive", profile
->progressive
);
106 mlt_properties_set_double( properties
, "aspect_ratio", mlt_profile_sar( profile
) );
107 mlt_properties_set_int( properties
, "sample_aspect_num", profile
->sample_aspect_num
);
108 mlt_properties_set_int( properties
, "sample_aspect_den", profile
->sample_aspect_den
);
109 mlt_properties_set_double( properties
, "display_ratio", mlt_profile_dar( profile
) );
110 mlt_properties_set_int( properties
, "display_aspect_num", profile
->display_aspect_num
);
111 mlt_properties_set_int( properties
, "display_aspect_num", profile
->display_aspect_num
);
112 mlt_event_unblock( this->event_listener
);
115 static void mlt_consumer_property_changed( mlt_service owner
, mlt_consumer
this, char *name
)
117 if ( !strcmp( name
, "profile" ) )
120 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
122 // Get the current profile
123 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
125 // Load the new profile
126 mlt_profile new_profile
= mlt_profile_init( mlt_properties_get( properties
, name
) );
131 if ( profile
!= NULL
)
133 free( profile
->description
);
134 memcpy( profile
, new_profile
, sizeof( struct mlt_profile_s
) );
135 profile
->description
= strdup( new_profile
->description
);
136 mlt_profile_close( new_profile
);
140 profile
= new_profile
;
143 // Apply to properties
144 apply_profile_properties( this, profile
, properties
);
147 else if ( !strcmp( name
, "frame_rate_num" ) )
149 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
150 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
153 profile
->frame_rate_num
= mlt_properties_get_int( properties
, "frame_rate_num" );
154 mlt_properties_set_double( properties
, "fps", mlt_profile_fps( profile
) );
157 else if ( !strcmp( name
, "frame_rate_den" ) )
159 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
160 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
163 profile
->frame_rate_den
= mlt_properties_get_int( properties
, "frame_rate_den" );
164 mlt_properties_set_double( properties
, "fps", mlt_profile_fps( profile
) );
167 else if ( !strcmp( name
, "width" ) )
169 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
170 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
172 profile
->width
= mlt_properties_get_int( properties
, "width" );
174 else if ( !strcmp( name
, "height" ) )
176 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
177 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
179 profile
->height
= mlt_properties_get_int( properties
, "height" );
181 else if ( !strcmp( name
, "progressive" ) )
183 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
184 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
186 profile
->progressive
= mlt_properties_get_int( properties
, "progressive" );
188 else if ( !strcmp( name
, "sample_aspect_num" ) )
190 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
191 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
192 profile
->sample_aspect_num
= mlt_properties_get_int( properties
, "sample_aspect_num" );
194 mlt_properties_set_double( properties
, "aspect_ratio", mlt_profile_sar( profile
) );
196 else if ( !strcmp( name
, "sample_aspect_den" ) )
198 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
199 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
200 profile
->sample_aspect_den
= mlt_properties_get_int( properties
, "sample_aspect_den" );
202 mlt_properties_set_double( properties
, "aspect_ratio", mlt_profile_sar( profile
) );
204 else if ( !strcmp( name
, "display_aspect_num" ) )
206 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
207 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
210 profile
->display_aspect_num
= mlt_properties_get_int( properties
, "display_aspect_num" );
211 mlt_properties_set_double( properties
, "display_ratio", mlt_profile_dar( profile
) );
214 else if ( !strcmp( name
, "display_aspect_den" ) )
216 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
217 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
220 profile
->display_aspect_den
= mlt_properties_get_int( properties
, "display_aspect_den" );
221 mlt_properties_set_double( properties
, "display_ratio", mlt_profile_dar( profile
) );
226 static void mlt_consumer_frame_show( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
)
228 if ( listener
!= NULL
)
229 listener( owner
, this, ( mlt_frame
)args
[ 0 ] );
232 static void mlt_consumer_frame_render( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
)
234 if ( listener
!= NULL
)
235 listener( owner
, this, ( mlt_frame
)args
[ 0 ] );
238 /** Create a new consumer.
241 mlt_consumer
mlt_consumer_new( mlt_profile profile
)
243 // Create the memory for the structure
244 mlt_consumer
this = malloc( sizeof( struct mlt_consumer_s
) );
248 mlt_consumer_init( this, NULL
, profile
);
254 /** Get the parent service object.
257 mlt_service
mlt_consumer_service( mlt_consumer
this )
259 return this != NULL ?
&this->parent
: NULL
;
262 /** Get the consumer properties.
265 mlt_properties
mlt_consumer_properties( mlt_consumer
this )
267 return this != NULL ?
MLT_SERVICE_PROPERTIES( &this->parent
) : NULL
;
270 /** Connect the consumer to the producer.
273 int mlt_consumer_connect( mlt_consumer
this, mlt_service producer
)
275 return mlt_service_connect_producer( &this->parent
, producer
, 0 );
278 /** Start the consumer.
281 int mlt_consumer_start( mlt_consumer
this )
283 // Stop listening to the property-changed event
284 mlt_event_block( this->event_listener
);
287 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
289 // Determine if there's a test card producer
290 char *test_card
= mlt_properties_get( properties
, "test_card" );
292 // Just to make sure nothing is hanging around...
293 mlt_frame_close( this->put
);
295 this->put_active
= 1;
298 if ( test_card
!= NULL
)
300 if ( mlt_properties_get_data( properties
, "test_card_producer", NULL
) == NULL
)
302 // Create a test card producer
303 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( this ) );
304 mlt_producer producer
= mlt_factory_producer( profile
, NULL
, test_card
);
306 // Do we have a producer
307 if ( producer
!= NULL
)
309 // Test card should loop I guess...
310 mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer
), "eof", "loop" );
311 //mlt_producer_set_speed( producer, 0 );
312 //mlt_producer_set_in_and_out( producer, 0, 0 );
314 // Set the test card on the consumer
315 mlt_properties_set_data( properties
, "test_card_producer", producer
, 0, ( mlt_destructor
)mlt_producer_close
, NULL
);
321 // Allow the hash table to speed things up
322 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
325 // Check and run an ante command
326 if ( mlt_properties_get( properties
, "ante" ) )
327 system( mlt_properties_get( properties
, "ante" ) );
329 // Set the real_time preference
330 this->real_time
= mlt_properties_get_int( properties
, "real_time" );
333 if ( this->start
!= NULL
)
334 return this->start( this );
339 /** An alternative method to feed frames into the consumer - only valid if
340 the consumer itself is not connected.
343 int mlt_consumer_put_frame( mlt_consumer
this, mlt_frame frame
)
347 // Get the service assoicated to the consumer
348 mlt_service service
= MLT_CONSUMER_SERVICE( this );
350 if ( mlt_service_producer( service
) == NULL
)
354 pthread_mutex_lock( &this->put_mutex
);
355 while ( this->put_active
&& this->put
!= NULL
)
357 gettimeofday( &now
, NULL
);
358 tm
.tv_sec
= now
.tv_sec
+ 1;
359 tm
.tv_nsec
= now
.tv_usec
* 1000;
360 pthread_cond_timedwait( &this->put_cond
, &this->put_mutex
, &tm
);
362 if ( this->put_active
&& this->put
== NULL
)
365 mlt_frame_close( frame
);
366 pthread_cond_broadcast( &this->put_cond
);
367 pthread_mutex_unlock( &this->put_mutex
);
371 mlt_frame_close( frame
);
377 /** Protected method for consumer to get frames from connected service
380 mlt_frame
mlt_consumer_get_frame( mlt_consumer
this )
383 mlt_frame frame
= NULL
;
385 // Get the service assoicated to the consumer
386 mlt_service service
= MLT_CONSUMER_SERVICE( this );
388 // Get the consumer properties
389 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
392 if ( mlt_service_producer( service
) == NULL
&& mlt_properties_get_int( properties
, "put_mode" ) )
396 pthread_mutex_lock( &this->put_mutex
);
397 while ( this->put_active
&& this->put
== NULL
)
399 gettimeofday( &now
, NULL
);
400 tm
.tv_sec
= now
.tv_sec
+ 1;
401 tm
.tv_nsec
= now
.tv_usec
* 1000;
402 pthread_cond_timedwait( &this->put_cond
, &this->put_mutex
, &tm
);
406 pthread_cond_broadcast( &this->put_cond
);
407 pthread_mutex_unlock( &this->put_mutex
);
409 mlt_service_apply_filters( service
, frame
, 0 );
411 else if ( mlt_service_producer( service
) != NULL
)
413 mlt_service_get_frame( service
, &frame
, 0 );
417 frame
= mlt_frame_init( service
);
422 // Get the frame properties
423 mlt_properties frame_properties
= MLT_FRAME_PROPERTIES( frame
);
425 // Get the test card producer
426 mlt_producer test_card
= mlt_properties_get_data( properties
, "test_card_producer", NULL
);
428 // Attach the test frame producer to it.
429 if ( test_card
!= NULL
)
430 mlt_properties_set_data( frame_properties
, "test_card_producer", test_card
, 0, NULL
, NULL
);
432 // Attach the rescale property
433 mlt_properties_set( frame_properties
, "rescale.interp", mlt_properties_get( properties
, "rescale" ) );
435 // Aspect ratio and other jiggery pokery
436 mlt_properties_set_double( frame_properties
, "consumer_aspect_ratio", mlt_properties_get_double( properties
, "aspect_ratio" ) );
437 mlt_properties_set_int( frame_properties
, "consumer_deinterlace", mlt_properties_get_int( properties
, "progressive" ) | mlt_properties_get_int( properties
, "deinterlace" ) );
438 mlt_properties_set( frame_properties
, "deinterlace_method", mlt_properties_get( properties
, "deinterlace_method" ) );
445 static inline long time_difference( struct timeval
*time1
)
447 struct timeval time2
;
448 time2
.tv_sec
= time1
->tv_sec
;
449 time2
.tv_usec
= time1
->tv_usec
;
450 gettimeofday( time1
, NULL
);
451 return time1
->tv_sec
* 1000000 + time1
->tv_usec
- time2
.tv_sec
* 1000000 - time2
.tv_usec
;
454 static void *consumer_read_ahead_thread( void *arg
)
456 // The argument is the consumer
457 mlt_consumer
this = arg
;
459 // Get the properties of the consumer
460 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
462 // Get the width and height
463 int width
= mlt_properties_get_int( properties
, "width" );
464 int height
= mlt_properties_get_int( properties
, "height" );
466 // See if video is turned off
467 int video_off
= mlt_properties_get_int( properties
, "video_off" );
468 int preview_off
= mlt_properties_get_int( properties
, "preview_off" );
469 int preview_format
= mlt_properties_get_int( properties
, "preview_format" );
471 // Get the audio settings
472 mlt_audio_format afmt
= mlt_audio_pcm
;
474 double fps
= mlt_properties_get_double( properties
, "fps" );
475 int channels
= mlt_properties_get_int( properties
, "channels" );
476 int frequency
= mlt_properties_get_int( properties
, "frequency" );
480 // See if audio is turned off
481 int audio_off
= mlt_properties_get_int( properties
, "audio_off" );
483 // Get the maximum size of the buffer
484 int buffer
= mlt_properties_get_int( properties
, "buffer" ) + 1;
486 // General frame variable
487 mlt_frame frame
= NULL
;
488 uint8_t *image
= NULL
;
493 // Average time for get_frame and get_image
496 int64_t time_wait
= 0;
497 int64_t time_frame
= 0;
498 int64_t time_process
= 0;
500 mlt_service lock_object
= NULL
;
502 if ( preview_off
&& preview_format
!= 0 )
503 this->format
= preview_format
;
505 // Get the first frame
506 frame
= mlt_consumer_get_frame( this );
508 // Get the lock object
509 lock_object
= mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame
), "consumer_lock_service", NULL
);
512 if ( lock_object
) mlt_service_lock( lock_object
);
514 // Get the image of the first frame
517 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame
, NULL
);
518 mlt_frame_get_image( frame
, &image
, &this->format
, &width
, &height
, 0 );
523 samples
= mlt_sample_calculator( fps
, frequency
, counter
++ );
524 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
527 // Unlock the lock object
528 if ( lock_object
) mlt_service_unlock( lock_object
);
531 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
533 // Get the starting time (can ignore the times above)
534 gettimeofday( &ante
, NULL
);
536 // Continue to read ahead
537 while ( this->ahead
)
539 // Fetch width/height again
540 width
= mlt_properties_get_int( properties
, "width" );
541 height
= mlt_properties_get_int( properties
, "height" );
543 // Put the current frame into the queue
544 pthread_mutex_lock( &this->mutex
);
545 while( this->ahead
&& mlt_deque_count( this->queue
) >= buffer
)
546 pthread_cond_wait( &this->cond
, &this->mutex
);
547 mlt_deque_push_back( this->queue
, frame
);
548 pthread_cond_broadcast( &this->cond
);
549 pthread_mutex_unlock( &this->mutex
);
551 time_wait
+= time_difference( &ante
);
553 // Get the next frame
554 frame
= mlt_consumer_get_frame( this );
555 time_frame
+= time_difference( &ante
);
557 // If there's no frame, we're probably stopped...
561 // Attempt to fetch the lock object
562 lock_object
= mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame
), "consumer_lock_service", NULL
);
564 // Increment the count
567 // Lock if there's a lock object
568 if ( lock_object
) mlt_service_lock( lock_object
);
570 // All non normal playback frames should be shown
571 if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame
), "_speed" ) != 1 )
573 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "consumer_deinterlace", 1 );
583 if ( !skip_next
|| this->real_time
== -1 )
585 // Get the image, mark as rendered and time it
588 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-frame-render", frame
, NULL
);
589 mlt_frame_get_image( frame
, &image
, &this->format
, &width
, &height
, 0 );
591 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
595 // Increment the number of sequentially skipped frames
599 // If we've reached an unacceptable level, reset everything
610 // Always process audio
613 samples
= mlt_sample_calculator( fps
, frequency
, counter
++ );
614 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
617 // Increment the time take for this frame
618 time_process
+= time_difference( &ante
);
620 // Determine if the next frame should be skipped
621 if ( mlt_deque_count( this->queue
) <= 5 && ( ( time_wait
+ time_frame
+ time_process
) / count
) > 40000 )
624 // Unlock if there's a lock object
625 if ( lock_object
) mlt_service_unlock( lock_object
);
628 // Remove the last frame
629 mlt_frame_close( frame
);
634 static void consumer_read_ahead_start( mlt_consumer
this )
639 // Create the frame queue
640 this->queue
= mlt_deque_init( );
643 pthread_mutex_init( &this->mutex
, NULL
);
645 // Create the condition
646 pthread_cond_init( &this->cond
, NULL
);
648 // Create the read ahead
649 pthread_create( &this->ahead_thread
, NULL
, consumer_read_ahead_thread
, this );
652 static void consumer_read_ahead_stop( mlt_consumer
this )
654 // Make sure we're running
657 // Inform thread to stop
660 // Broadcast to the condition in case it's waiting
661 pthread_mutex_lock( &this->mutex
);
662 pthread_cond_broadcast( &this->cond
);
663 pthread_mutex_unlock( &this->mutex
);
665 // Broadcast to the put condition in case it's waiting
666 pthread_mutex_lock( &this->put_mutex
);
667 pthread_cond_broadcast( &this->put_cond
);
668 pthread_mutex_unlock( &this->put_mutex
);
671 pthread_join( this->ahead_thread
, NULL
);
674 pthread_mutex_destroy( &this->mutex
);
676 // Destroy the condition
677 pthread_cond_destroy( &this->cond
);
680 while ( mlt_deque_count( this->queue
) )
681 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
684 mlt_deque_close( this->queue
);
688 void mlt_consumer_purge( mlt_consumer
this )
692 pthread_mutex_lock( &this->mutex
);
693 while ( mlt_deque_count( this->queue
) )
694 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
695 pthread_cond_broadcast( &this->cond
);
696 pthread_mutex_unlock( &this->mutex
);
700 mlt_frame
mlt_consumer_rt_frame( mlt_consumer
this )
703 mlt_frame frame
= NULL
;
705 // Get the properties
706 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
708 // Check if the user has requested real time or not
709 if ( this->real_time
)
713 // Is the read ahead running?
714 if ( this->ahead
== 0 )
716 int buffer
= mlt_properties_get_int( properties
, "buffer" );
717 int prefill
= mlt_properties_get_int( properties
, "prefill" );
718 consumer_read_ahead_start( this );
720 size
= prefill
> 0 && prefill
< buffer ? prefill
: buffer
;
723 // Get frame from queue
724 pthread_mutex_lock( &this->mutex
);
725 while( this->ahead
&& mlt_deque_count( this->queue
) < size
)
726 pthread_cond_wait( &this->cond
, &this->mutex
);
727 frame
= mlt_deque_pop_front( this->queue
);
728 pthread_cond_broadcast( &this->cond
);
729 pthread_mutex_unlock( &this->mutex
);
733 // Get the frame in non real time
734 frame
= mlt_consumer_get_frame( this );
736 // This isn't true, but from the consumers perspective it is
738 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "rendered", 1 );
744 /** Callback for the implementation to indicate a stopped condition.
747 void mlt_consumer_stopped( mlt_consumer
this )
749 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "running", 0 );
750 mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-stopped", NULL
);
751 mlt_event_unblock( this->event_listener
);
754 /** Stop the consumer.
757 int mlt_consumer_stop( mlt_consumer
this )
760 mlt_properties properties
= MLT_CONSUMER_PROPERTIES( this );
761 char *debug
= mlt_properties_get( MLT_CONSUMER_PROPERTIES( this ), "debug" );
764 if ( debug
) fprintf( stderr
, "%s: stopping put waiting\n", debug
);
765 pthread_mutex_lock( &this->put_mutex
);
766 this->put_active
= 0;
767 pthread_cond_broadcast( &this->put_cond
);
768 pthread_mutex_unlock( &this->put_mutex
);
771 if ( debug
) fprintf( stderr
, "%s: stopping consumer\n", debug
);
772 if ( this->stop
!= NULL
)
775 // Check if the user has requested real time or not and stop if necessary
776 if ( debug
) fprintf( stderr
, "%s: stopping read_ahead\n", debug
);
777 if ( mlt_properties_get_int( properties
, "real_time" ) )
778 consumer_read_ahead_stop( this );
780 // Kill the test card
781 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
783 // Check and run a post command
784 if ( mlt_properties_get( properties
, "post" ) )
785 system( mlt_properties_get( properties
, "post" ) );
787 if ( debug
) fprintf( stderr
, "%s: stopped\n", debug
);
792 /** Determine if the consumer is stopped.
795 int mlt_consumer_is_stopped( mlt_consumer
this )
797 // Check if the consumer is stopped
798 if ( this->is_stopped
!= NULL
)
799 return this->is_stopped( this );
804 /** Close the consumer.
807 void mlt_consumer_close( mlt_consumer
this )
809 if ( this != NULL
&& mlt_properties_dec_ref( MLT_CONSUMER_PROPERTIES( this ) ) <= 0 )
811 // Get the childs close function
812 void ( *consumer_close
)( ) = this->close
;
814 if ( consumer_close
)
817 //mlt_consumer_stop( this );
820 consumer_close( this );
824 // Make sure it only gets called once
825 this->parent
.close
= NULL
;
827 // Destroy the push mutex and condition
828 pthread_mutex_destroy( &this->put_mutex
);
829 pthread_cond_destroy( &this->put_cond
);
831 mlt_service_close( &this->parent
);