3 * \brief abstraction for all consumer services
6 * Copyright (C) 2003-2010 Ushodaya Enterprises Limited
7 * \author Charles Yates <charles.yates@pandora.be>
8 * \author Dan Dennedy <dan@dennedy.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "mlt_consumer.h"
26 #include "mlt_factory.h"
27 #include "mlt_producer.h"
28 #include "mlt_frame.h"
29 #include "mlt_profile.h"
37 /** Define this if you want an automatic deinterlace (if necessary) when the
38 * consumer's producer is not running at normal speed.
40 #undef DEINTERLACE_ON_NOT_NORMAL_SPEED
42 /** This is not the ideal place for this, but it is needed by VDPAU as well.
44 pthread_mutex_t mlt_sdl_mutex = PTHREAD_MUTEX_INITIALIZER;
46 static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service self, void **args );
47 static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service self, void **args );
48 static void mlt_consumer_property_changed( mlt_properties owner, mlt_consumer self, char *name );
49 static void apply_profile_properties( mlt_consumer self, mlt_profile profile, mlt_properties properties );
50 static void on_consumer_frame_show( mlt_properties owner, mlt_consumer self, mlt_frame frame );
52 /** Initialize a consumer service.
54 * \public \memberof mlt_consumer_s
55 * \param self the consumer to initialize
56 * \param child a pointer to the object for the subclass
57 * \param profile the \p mlt_profile_s to use (optional but recommended,
58 * uses the environment variable MLT if self is NULL)
59 * \return true if there was an error
62 int mlt_consumer_init( mlt_consumer self, void *child, mlt_profile profile )
65 memset( self, 0, sizeof( struct mlt_consumer_s ) );
67 error = mlt_service_init( &self->parent, self );
70 // Get the properties from the service
71 mlt_properties properties = MLT_SERVICE_PROPERTIES( &self->parent );
73 // Apply profile to properties
74 if ( profile == NULL )
76 // Normally the application creates the profile and controls its lifetime
77 // This is the fallback exception handling
78 profile = mlt_profile_init( NULL );
79 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
80 mlt_properties_set_data( properties, "_profile", profile, 0, (mlt_destructor)mlt_profile_close, NULL );
82 apply_profile_properties( self, profile, properties );
84 // Default rescaler for all consumers
85 mlt_properties_set( properties, "rescale", "bilinear" );
87 // Default read ahead buffer size
88 mlt_properties_set_int( properties, "buffer", 25 );
89 mlt_properties_set_int( properties, "drop_max", 5 );
91 // Default audio frequency and channels
92 mlt_properties_set_int( properties, "frequency", 48000 );
93 mlt_properties_set_int( properties, "channels", 2 );
95 // Default of all consumers is real time
96 mlt_properties_set_int( properties, "real_time", 1 );
98 // Default to environment test card
99 mlt_properties_set( properties, "test_card", mlt_environment( "MLT_TEST_CARD" ) );
101 // Hmm - default all consumers to yuv422 :-/
102 self->format = mlt_image_yuv422;
103 mlt_properties_set( properties, "mlt_image_format", mlt_image_format_name( self->format ) );
104 mlt_properties_set( properties, "mlt_audio_format", mlt_audio_format_name( mlt_audio_s16 ) );
106 mlt_events_register( properties, "consumer-frame-show", ( mlt_transmitter )mlt_consumer_frame_show );
107 mlt_events_register( properties, "consumer-frame-render", ( mlt_transmitter )mlt_consumer_frame_render );
108 mlt_events_register( properties, "consumer-stopped", NULL );
109 mlt_events_listen( properties, self, "consumer-frame-show", ( mlt_listener )on_consumer_frame_show );
111 // Register a property-changed listener to handle the profile property -
112 // subsequent properties can override the profile
113 self->event_listener = mlt_events_listen( properties, self, "property-changed", ( mlt_listener )mlt_consumer_property_changed );
115 // Create the push mutex and condition
116 pthread_mutex_init( &self->put_mutex, NULL );
117 pthread_cond_init( &self->put_cond, NULL );
123 /** Convert the profile into properties on the consumer.
125 * \private \memberof mlt_consumer_s
126 * \param self a consumer
127 * \param profile a profile
128 * \param properties a properties list (typically, the consumer's)
131 static void apply_profile_properties( mlt_consumer self, mlt_profile profile, mlt_properties properties )
133 mlt_event_block( self->event_listener );
134 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
135 mlt_properties_set_int( properties, "frame_rate_num", profile->frame_rate_num );
136 mlt_properties_set_int( properties, "frame_rate_den", profile->frame_rate_den );
137 mlt_properties_set_int( properties, "width", profile->width );
138 mlt_properties_set_int( properties, "height", profile->height );
139 mlt_properties_set_int( properties, "progressive", profile->progressive );
140 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
141 mlt_properties_set_int( properties, "sample_aspect_num", profile->sample_aspect_num );
142 mlt_properties_set_int( properties, "sample_aspect_den", profile->sample_aspect_den );
143 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
144 mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
145 mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num );
146 mlt_properties_set_int( properties, "colorspace", profile->colorspace );
147 mlt_event_unblock( self->event_listener );
150 /** The property-changed event listener
152 * \private \memberof mlt_consumer_s
153 * \param owner the events object
154 * \param self the consumer
155 * \param name the name of the property that changed
158 static void mlt_consumer_property_changed( mlt_properties owner, mlt_consumer self, char *name )
160 if ( !strcmp( name, "mlt_profile" ) )
163 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
165 // Get the current profile
166 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
168 // Load the new profile
169 mlt_profile new_profile = mlt_profile_init( mlt_properties_get( properties, name ) );
174 if ( profile != NULL )
176 free( profile->description );
177 memcpy( profile, new_profile, sizeof( struct mlt_profile_s ) );
178 profile->description = strdup( new_profile->description );
182 profile = new_profile;
185 // Apply to properties
186 apply_profile_properties( self, profile, properties );
187 mlt_profile_close( new_profile );
190 else if ( !strcmp( name, "frame_rate_num" ) )
192 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
193 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
196 profile->frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" );
197 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
200 else if ( !strcmp( name, "frame_rate_den" ) )
202 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
203 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
206 profile->frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" );
207 mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) );
210 else if ( !strcmp( name, "width" ) )
212 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
213 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
215 profile->width = mlt_properties_get_int( properties, "width" );
217 else if ( !strcmp( name, "height" ) )
219 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
220 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
222 profile->height = mlt_properties_get_int( properties, "height" );
224 else if ( !strcmp( name, "progressive" ) )
226 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
227 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
229 profile->progressive = mlt_properties_get_int( properties, "progressive" );
231 else if ( !strcmp( name, "sample_aspect_num" ) )
233 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
234 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
237 profile->sample_aspect_num = mlt_properties_get_int( properties, "sample_aspect_num" );
238 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
241 else if ( !strcmp( name, "sample_aspect_den" ) )
243 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
244 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
245 profile->sample_aspect_den = mlt_properties_get_int( properties, "sample_aspect_den" );
247 mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) );
249 else if ( !strcmp( name, "display_aspect_num" ) )
251 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
252 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
255 profile->display_aspect_num = mlt_properties_get_int( properties, "display_aspect_num" );
256 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
259 else if ( !strcmp( name, "display_aspect_den" ) )
261 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
262 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
265 profile->display_aspect_den = mlt_properties_get_int( properties, "display_aspect_den" );
266 mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) );
269 else if ( !strcmp( name, "colorspace" ) )
271 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
272 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
274 profile->colorspace = mlt_properties_get_int( properties, "colorspace" );
278 /** The transmitter for the consumer-frame-show event
280 * Invokes the listener.
282 * \private \memberof mlt_consumer_s
283 * \param listener a function pointer that will be invoked
284 * \param owner the events object that will be passed to \p listener
285 * \param self a service that will be passed to \p listener
286 * \param args an array of pointers - the first entry is passed as a string to \p listener
289 static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service self, void **args )
291 if ( listener != NULL )
292 listener( owner, self, ( mlt_frame )args[ 0 ] );
295 /** The transmitter for the consumer-frame-render event
297 * Invokes the listener.
299 * \private \memberof mlt_consumer_s
300 * \param listener a function pointer that will be invoked
301 * \param owner the events object that will be passed to \p listener
302 * \param self a service that will be passed to \p listener
303 * \param args an array of pointers - the first entry is passed as a string to \p listener
306 static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service self, void **args )
308 if ( listener != NULL )
309 listener( owner, self, ( mlt_frame )args[ 0 ] );
312 /** A listener on the consumer-frame-show event
314 * Saves the position of the frame shown.
316 * \private \memberof mlt_consumer_s
317 * \param owner the events object
318 * \param consumer the consumer on which this event occurred
319 * \param frame the frame that was shown
322 static void on_consumer_frame_show( mlt_properties owner, mlt_consumer consumer, mlt_frame frame )
325 consumer->position = mlt_frame_get_position( frame );
328 /** Create a new consumer.
330 * \public \memberof mlt_consumer_s
331 * \param profile a profile (optional, but recommended)
332 * \return a new consumer
335 mlt_consumer mlt_consumer_new( mlt_profile profile )
337 // Create the memory for the structure
338 mlt_consumer self = malloc( sizeof( struct mlt_consumer_s ) );
342 mlt_consumer_init( self, NULL, profile );
348 /** Get the parent service object.
350 * \public \memberof mlt_consumer_s
351 * \param self a consumer
352 * \return the parent service class
353 * \see MLT_CONSUMER_SERVICE
356 mlt_service mlt_consumer_service( mlt_consumer self )
358 return self != NULL ? &self->parent : NULL;
361 /** Get the consumer properties.
363 * \public \memberof mlt_consumer_s
364 * \param self a consumer
365 * \return the consumer's properties list
366 * \see MLT_CONSUMER_PROPERTIES
369 mlt_properties mlt_consumer_properties( mlt_consumer self )
371 return self != NULL ? MLT_SERVICE_PROPERTIES( &self->parent ) : NULL;
374 /** Connect the consumer to the producer.
376 * \public \memberof mlt_consumer_s
377 * \param self a consumer
378 * \param producer a producer
379 * \return > 0 warning, == 0 success, < 0 serious error,
380 * 1 = this service does not accept input,
381 * 2 = the producer is invalid,
382 * 3 = the producer is already registered with this consumer
385 int mlt_consumer_connect( mlt_consumer self, mlt_service producer )
387 return mlt_service_connect_producer( &self->parent, producer, 0 );
390 /** Start the consumer.
392 * \public \memberof mlt_consumer_s
393 * \param self a consumer
394 * \return true if there was an error
397 int mlt_consumer_start( mlt_consumer self )
399 if ( !mlt_consumer_is_stopped( self ) )
402 // Stop listening to the property-changed event
403 mlt_event_block( self->event_listener );
406 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
408 // Determine if there's a test card producer
409 char *test_card = mlt_properties_get( properties, "test_card" );
411 // Just to make sure nothing is hanging around...
413 self->put_active = 1;
416 if ( test_card != NULL )
418 if ( mlt_properties_get_data( properties, "test_card_producer", NULL ) == NULL )
420 // Create a test card producer
421 mlt_profile profile = mlt_service_profile( MLT_CONSUMER_SERVICE( self ) );
422 mlt_producer producer = mlt_factory_producer( profile, NULL, test_card );
424 // Do we have a producer
425 if ( producer != NULL )
427 // Test card should loop I guess...
428 mlt_properties_set( MLT_PRODUCER_PROPERTIES( producer ), "eof", "loop" );
429 //mlt_producer_set_speed( producer, 0 );
430 //mlt_producer_set_in_and_out( producer, 0, 0 );
432 // Set the test card on the consumer
433 mlt_properties_set_data( properties, "test_card_producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
439 // Allow the hash table to speed things up
440 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
443 // Set the frame duration in microseconds for the frame-dropping heuristic
444 int frame_duration = 1000000 / mlt_properties_get_int( properties, "frame_rate_num" ) *
445 mlt_properties_get_int( properties, "frame_rate_den" );
446 mlt_properties_set_int( properties, "frame_duration", frame_duration );
448 // Check and run an ante command
449 if ( mlt_properties_get( properties, "ante" ) )
450 if ( system( mlt_properties_get( properties, "ante" ) ) == -1 )
451 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_ERROR, "system(%s) failed!\n", mlt_properties_get( properties, "ante" ) );
453 // Set the real_time preference
454 self->real_time = mlt_properties_get_int( properties, "real_time" );
456 // For worker threads implementation, buffer must be at least # threads
457 if ( abs( self->real_time ) > 1 && mlt_properties_get_int( properties, "buffer" ) <= abs( self->real_time ) )
458 mlt_properties_set_int( properties, "_buffer", abs( self->real_time ) + 1 );
460 // Get the image format to use for rendering threads
461 const char* format = mlt_properties_get( properties, "mlt_image_format" );
464 if ( !strcmp( format, "rgb24" ) )
465 self->format = mlt_image_rgb24;
466 else if ( !strcmp( format, "rgb24a" ) )
467 self->format = mlt_image_rgb24a;
468 else if ( !strcmp( format, "yuv420p" ) )
469 self->format = mlt_image_yuv420p;
470 else if ( !strcmp( format, "none" ) )
471 self->format = mlt_image_none;
473 self->format = mlt_image_yuv422;
477 if ( self->start != NULL )
478 return self->start( self );
483 /** An alternative method to feed frames into the consumer.
485 * Only valid if the consumer itself is not connected.
487 * \public \memberof mlt_consumer_s
488 * \param self a consumer
489 * \param frame a frame
490 * \return true (ignore self for now)
493 int mlt_consumer_put_frame( mlt_consumer self, mlt_frame frame )
497 // Get the service assoicated to the consumer
498 mlt_service service = MLT_CONSUMER_SERVICE( self );
500 if ( mlt_service_producer( service ) == NULL )
504 pthread_mutex_lock( &self->put_mutex );
505 while ( self->put_active && self->put != NULL )
507 gettimeofday( &now, NULL );
508 tm.tv_sec = now.tv_sec + 1;
509 tm.tv_nsec = now.tv_usec * 1000;
510 pthread_cond_timedwait( &self->put_cond, &self->put_mutex, &tm );
512 if ( self->put_active && self->put == NULL )
515 mlt_frame_close( frame );
516 pthread_cond_broadcast( &self->put_cond );
517 pthread_mutex_unlock( &self->put_mutex );
521 mlt_frame_close( frame );
527 /** Protected method for consumer to get frames from connected service
529 * \public \memberof mlt_consumer_s
530 * \param self a consumer
534 mlt_frame mlt_consumer_get_frame( mlt_consumer self )
537 mlt_frame frame = NULL;
539 // Get the service assoicated to the consumer
540 mlt_service service = MLT_CONSUMER_SERVICE( self );
542 // Get the consumer properties
543 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
546 if ( mlt_service_producer( service ) == NULL && mlt_properties_get_int( properties, "put_mode" ) )
550 pthread_mutex_lock( &self->put_mutex );
551 while ( self->put_active && self->put == NULL )
553 gettimeofday( &now, NULL );
554 tm.tv_sec = now.tv_sec + 1;
555 tm.tv_nsec = now.tv_usec * 1000;
556 pthread_cond_timedwait( &self->put_cond, &self->put_mutex, &tm );
560 pthread_cond_broadcast( &self->put_cond );
561 pthread_mutex_unlock( &self->put_mutex );
563 mlt_service_apply_filters( service, frame, 0 );
565 else if ( mlt_service_producer( service ) != NULL )
567 mlt_service_get_frame( service, &frame, 0 );
571 frame = mlt_frame_init( service );
576 // Get the frame properties
577 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
579 // Get the test card producer
580 mlt_producer test_card = mlt_properties_get_data( properties, "test_card_producer", NULL );
582 // Attach the test frame producer to it.
583 if ( test_card != NULL )
584 mlt_properties_set_data( frame_properties, "test_card_producer", test_card, 0, NULL, NULL );
586 // Pass along the interpolation and deinterlace options
587 // TODO: get rid of consumer_deinterlace and use profile.progressive
588 mlt_properties_set( frame_properties, "rescale.interp", mlt_properties_get( properties, "rescale" ) );
589 mlt_properties_set_int( frame_properties, "consumer_deinterlace", mlt_properties_get_int( properties, "progressive" ) | mlt_properties_get_int( properties, "deinterlace" ) );
590 mlt_properties_set( frame_properties, "deinterlace_method", mlt_properties_get( properties, "deinterlace_method" ) );
591 mlt_properties_set_int( frame_properties, "consumer_tff", mlt_properties_get_int( properties, "top_field_first" ) );
598 /** Compute the time difference between now and a time value.
600 * \private \memberof mlt_consumer_s
601 * \param time1 a time value to be compared against now
602 * \return the difference in microseconds
605 static inline long time_difference( struct timeval *time1 )
607 struct timeval time2;
608 time2.tv_sec = time1->tv_sec;
609 time2.tv_usec = time1->tv_usec;
610 gettimeofday( time1, NULL );
611 return time1->tv_sec * 1000000 + time1->tv_usec - time2.tv_sec * 1000000 - time2.tv_usec;
614 /** The thread procedure for asynchronously pulling frames through the service
615 * network connected to a consumer.
617 * \private \memberof mlt_consumer_s
618 * \param arg a consumer
621 static void *consumer_read_ahead_thread( void *arg )
623 // The argument is the consumer
624 mlt_consumer self = arg;
626 // Get the properties of the consumer
627 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
629 // Get the width and height
630 int width = mlt_properties_get_int( properties, "width" );
631 int height = mlt_properties_get_int( properties, "height" );
633 // See if video is turned off
634 int video_off = mlt_properties_get_int( properties, "video_off" );
635 int preview_off = mlt_properties_get_int( properties, "preview_off" );
636 int preview_format = mlt_properties_get_int( properties, "preview_format" );
638 // Get the audio settings
639 mlt_audio_format afmt = mlt_audio_s16;
640 const char *format = mlt_properties_get( properties, "mlt_audio_format" );
643 if ( !strcmp( format, "none" ) )
644 afmt = mlt_audio_none;
645 else if ( !strcmp( format, "s32" ) )
646 afmt = mlt_audio_s32;
647 else if ( !strcmp( format, "s32le" ) )
648 afmt = mlt_audio_s32le;
649 else if ( !strcmp( format, "float" ) )
650 afmt = mlt_audio_float;
651 else if ( !strcmp( format, "f32le" ) )
652 afmt = mlt_audio_f32le;
655 double fps = mlt_properties_get_double( properties, "fps" );
656 int channels = mlt_properties_get_int( properties, "channels" );
657 int frequency = mlt_properties_get_int( properties, "frequency" );
661 // See if audio is turned off
662 int audio_off = mlt_properties_get_int( properties, "audio_off" );
664 // Get the maximum size of the buffer
665 int buffer = mlt_properties_get_int( properties, "buffer" ) + 1;
667 // General frame variable
668 mlt_frame frame = NULL;
669 uint8_t *image = NULL;
674 // Average time for get_frame and get_image
677 int64_t time_process = 0;
679 mlt_position pos = 0;
680 mlt_position start_pos = 0;
681 mlt_position last_pos = 0;
682 int frame_duration = mlt_properties_get_int( properties, "frame_duration" );
683 int drop_max = mlt_properties_get_int( properties, "drop_max" );
685 if ( preview_off && preview_format != 0 )
686 self->format = preview_format;
688 // Get the first frame
689 frame = mlt_consumer_get_frame( self );
693 // Get the image of the first frame
696 mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-frame-render", frame, NULL );
697 mlt_frame_get_image( frame, &image, &self->format, &width, &height, 0 );
702 samples = mlt_sample_calculator( fps, frequency, counter++ );
703 mlt_frame_get_audio( frame, &audio, &afmt, &frequency, &channels, &samples );
707 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
708 last_pos = start_pos = pos = mlt_frame_get_position( frame );
711 // Get the starting time (can ignore the times above)
712 gettimeofday( &ante, NULL );
714 // Continue to read ahead
715 while ( self->ahead )
717 // Put the current frame into the queue
718 pthread_mutex_lock( &self->queue_mutex );
719 while( self->ahead && mlt_deque_count( self->queue ) >= buffer )
720 pthread_cond_wait( &self->queue_cond, &self->queue_mutex );
721 mlt_deque_push_back( self->queue, frame );
722 pthread_cond_broadcast( &self->queue_cond );
723 pthread_mutex_unlock( &self->queue_mutex );
725 // Get the next frame
726 frame = mlt_consumer_get_frame( self );
728 // If there's no frame, we're probably stopped...
731 pos = mlt_frame_get_position( frame );
733 // Increment the counter used for averaging processing cost
736 // All non-normal playback frames should be shown
737 if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "_speed" ) != 1 )
739 #ifdef DEINTERLACE_ON_NOT_NORMAL_SPEED
740 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "consumer_deinterlace", 1 );
742 // Indicate seeking or trick-play
746 // If skip flag not set or frame-dropping disabled
747 if ( !skip_next || self->real_time == -1 )
751 // Reset width/height - could have been changed by previous mlt_frame_get_image
752 width = mlt_properties_get_int( properties, "width" );
753 height = mlt_properties_get_int( properties, "height" );
756 mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-frame-render", frame, NULL );
757 mlt_frame_get_image( frame, &image, &self->format, &width, &height, 0 );
760 // Indicate the rendered image is available.
761 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
763 // Reset consecutively-skipped counter
766 else // Skip image processing
768 // Increment the number of consecutively-skipped frames
771 // If too many (1 sec) consecutively-skipped frames
772 if ( skipped > drop_max )
774 // Reset cost tracker
777 mlt_log_verbose( self, "too many frames dropped - forcing next frame\n" );
781 // Always process audio
784 samples = mlt_sample_calculator( fps, frequency, counter++ );
785 mlt_frame_get_audio( frame, &audio, &afmt, &frequency, &channels, &samples );
788 // Get the time to process this frame
789 int64_t time_current = time_difference( &ante );
791 // If the current time is not suddenly some large amount
792 if ( time_current < time_process / count * 20 || !time_process || count < 5 )
794 // Accumulate the cost for processing this frame
795 time_process += time_current;
799 mlt_log_debug( self, "current %"PRId64" threshold %"PRId64" count %d\n",
800 time_current, (int64_t) (time_process / count * 20), count );
801 // Ignore the cost of this frame's time
805 // Determine if we started, resumed, or seeked
806 if ( pos != last_pos + 1 )
810 // Do not skip the first 20% of buffer at start, resume, or seek
811 if ( pos - start_pos <= buffer / 5 + 1 )
813 // Reset cost tracker
821 // Only consider skipping if the buffer level is low (or really small)
822 if ( mlt_deque_count( self->queue ) <= buffer / 5 + 1 )
824 // Skip next frame if average cost exceeds frame duration.
825 if ( time_process / count > frame_duration )
828 mlt_log_debug( self, "avg usec %"PRId64" (%"PRId64"/%d) duration %d\n",
829 time_process/count, time_process, count, frame_duration);
833 // Remove the last frame
834 mlt_frame_close( frame );
839 /** Locate the first unprocessed frame in the queue.
841 * When playing with realtime behavior, we do not use the true head, but
842 * rather an adjusted process_head. The process_head is adjusted based on
843 * the rate of frame-dropping or recovery from frame-dropping. The idea is
844 * that as the level of frame-dropping increases to move the process_head
845 * closer to the tail because the frames are not completing processing prior
846 * to their playout! Then, as frames are not dropped the process_head moves
847 * back closer to the head of the queue so that worker threads can work
848 * ahead of the playout point (queue head).
850 * \private \memberof mlt_consumer_s
851 * \param self a consumer
852 * \return an index into the queue
855 static inline int first_unprocessed_frame( mlt_consumer self )
857 int index = self->real_time <= 0 ? 0 : self->process_head;
858 while ( index < mlt_deque_count( self->queue ) && MLT_FRAME( mlt_deque_peek( self->queue, index ) )->is_processing )
863 /** The worker thread procedure for parallel processing frames.
865 * \private \memberof mlt_consumer_s
866 * \param arg a consumer
869 static void *consumer_worker_thread( void *arg )
871 // The argument is the consumer
872 mlt_consumer self = arg;
874 // Get the properties of the consumer
875 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
877 // Get the width and height
878 int width = mlt_properties_get_int( properties, "width" );
879 int height = mlt_properties_get_int( properties, "height" );
880 mlt_image_format format = self->format;
882 // See if video is turned off
883 int video_off = mlt_properties_get_int( properties, "video_off" );
884 int preview_off = mlt_properties_get_int( properties, "preview_off" );
885 int preview_format = mlt_properties_get_int( properties, "preview_format" );
887 // General frame variable
888 mlt_frame frame = NULL;
889 uint8_t *image = NULL;
891 if ( preview_off && preview_format != 0 )
892 format = preview_format;
894 // Continue to read ahead
895 while ( self->ahead )
897 // Get the next unprocessed frame from the work queue
898 pthread_mutex_lock( &self->queue_mutex );
899 int index = first_unprocessed_frame( self );
900 while ( self->ahead && index >= mlt_deque_count( self->queue ) )
902 mlt_log_debug( MLT_CONSUMER_SERVICE(self), "waiting in worker index = %d queue count = %d\n",
903 index, mlt_deque_count( self->queue ) );
904 pthread_cond_wait( &self->queue_cond, &self->queue_mutex );
905 index = first_unprocessed_frame( self );
908 // Mark the frame for processing
909 frame = mlt_deque_peek( self->queue, index );
912 mlt_log_debug( MLT_CONSUMER_SERVICE(self), "worker processing index = %d frame %d queue count = %d\n",
913 index, mlt_frame_get_position(frame), mlt_deque_count( self->queue ) );
914 frame->is_processing = 1;
915 mlt_properties_inc_ref( MLT_FRAME_PROPERTIES( frame ) );
917 pthread_mutex_unlock( &self->queue_mutex );
919 // If there's no frame, we're probably stopped...
923 #ifdef DEINTERLACE_ON_NOT_NORMAL_SPEED
924 // All non normal playback frames should be shown
925 if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "_speed" ) != 1 )
926 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "consumer_deinterlace", 1 );
932 // Fetch width/height again
933 width = mlt_properties_get_int( properties, "width" );
934 height = mlt_properties_get_int( properties, "height" );
935 mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-frame-render", frame, NULL );
936 mlt_frame_get_image( frame, &image, &format, &width, &height, 0 );
938 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
939 mlt_frame_close( frame );
941 // Tell a waiting thread (non-realtime main consumer thread) that we are done.
942 pthread_mutex_lock( &self->done_mutex );
943 pthread_cond_broadcast( &self->done_cond );
944 pthread_mutex_unlock( &self->done_mutex );
950 /** Start the read/render thread.
952 * \private \memberof mlt_consumer_s
953 * \param self a consumer
956 static void consumer_read_ahead_start( mlt_consumer self )
961 // Create the frame queue
962 self->queue = mlt_deque_init( );
964 // Create the queue mutex
965 pthread_mutex_init( &self->queue_mutex, NULL );
967 // Create the condition
968 pthread_cond_init( &self->queue_cond, NULL );
970 // Create the read ahead
971 if ( mlt_properties_get( MLT_CONSUMER_PROPERTIES( self ), "priority" ) )
973 struct sched_param priority;
974 priority.sched_priority = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( self ), "priority" );
975 pthread_attr_t thread_attributes;
976 pthread_attr_init( &thread_attributes );
977 pthread_attr_setschedpolicy( &thread_attributes, SCHED_OTHER );
978 pthread_attr_setschedparam( &thread_attributes, &priority );
979 pthread_attr_setinheritsched( &thread_attributes, PTHREAD_EXPLICIT_SCHED );
980 pthread_attr_setscope( &thread_attributes, PTHREAD_SCOPE_SYSTEM );
981 if ( pthread_create( &self->ahead_thread, &thread_attributes, consumer_read_ahead_thread, self ) < 0 )
982 pthread_create( &self->ahead_thread, NULL, consumer_read_ahead_thread, self );
983 pthread_attr_destroy( &thread_attributes );
987 pthread_create( &self->ahead_thread, NULL, consumer_read_ahead_thread, self );
992 /** Start the worker threads.
994 * \private \memberof mlt_consumer_s
995 * \param self a consumer
998 static void consumer_work_start( mlt_consumer self )
1000 int n = abs( self->real_time );
1001 pthread_t *thread = calloc( 1, sizeof( pthread_t ) * n );
1003 // We're running now
1005 self->threads = thread;
1007 // These keep track of the accelleration of frame dropping or recovery.
1008 self->consecutive_dropped = 0;
1009 self->consecutive_rendered = 0;
1011 // This is the position in the queue from which to look for a frame to process.
1012 // If we always start from the head, then we may likely not complete processing
1013 // before the frame is played out.
1014 self->process_head = 0;
1016 // Create the queues
1017 self->queue = mlt_deque_init();
1018 self->worker_threads = mlt_deque_init();
1020 // Create the mutexes
1021 pthread_mutex_init( &self->queue_mutex, NULL );
1022 pthread_mutex_init( &self->done_mutex, NULL );
1024 // Create the conditions
1025 pthread_cond_init( &self->queue_cond, NULL );
1026 pthread_cond_init( &self->done_cond, NULL );
1028 // Create the read ahead
1029 if ( mlt_properties_get( MLT_CONSUMER_PROPERTIES( self ), "priority" ) )
1032 struct sched_param priority;
1033 pthread_attr_t thread_attributes;
1035 priority.sched_priority = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( self ), "priority" );
1036 pthread_attr_init( &thread_attributes );
1037 pthread_attr_setschedpolicy( &thread_attributes, SCHED_OTHER );
1038 pthread_attr_setschedparam( &thread_attributes, &priority );
1039 pthread_attr_setinheritsched( &thread_attributes, PTHREAD_EXPLICIT_SCHED );
1040 pthread_attr_setscope( &thread_attributes, PTHREAD_SCOPE_SYSTEM );
1044 if ( pthread_create( thread, &thread_attributes, consumer_worker_thread, self ) < 0 )
1045 if ( pthread_create( thread, NULL, consumer_worker_thread, self ) == 0 )
1046 mlt_deque_push_back( self->worker_threads, thread );
1049 pthread_attr_destroy( &thread_attributes );
1056 if ( pthread_create( thread, NULL, consumer_worker_thread, self ) == 0 )
1057 mlt_deque_push_back( self->worker_threads, thread );
1064 /** Stop the read/render thread.
1066 * \private \memberof mlt_consumer_s
1067 * \param self a consumer
1070 static void consumer_read_ahead_stop( mlt_consumer self )
1072 // Make sure we're running
1073 if ( self->started )
1075 // Inform thread to stop
1078 // Broadcast to the condition in case it's waiting
1079 pthread_mutex_lock( &self->queue_mutex );
1080 pthread_cond_broadcast( &self->queue_cond );
1081 pthread_mutex_unlock( &self->queue_mutex );
1083 // Broadcast to the put condition in case it's waiting
1084 pthread_mutex_lock( &self->put_mutex );
1085 pthread_cond_broadcast( &self->put_cond );
1086 pthread_mutex_unlock( &self->put_mutex );
1089 pthread_join( self->ahead_thread, NULL );
1092 // Destroy the frame queue mutex
1093 pthread_mutex_destroy( &self->queue_mutex );
1095 // Destroy the condition
1096 pthread_cond_destroy( &self->queue_cond );
1099 while ( mlt_deque_count( self->queue ) )
1100 mlt_frame_close( mlt_deque_pop_back( self->queue ) );
1103 mlt_deque_close( self->queue );
1107 /** Stop the worker threads.
1109 * \private \memberof mlt_consumer_s
1110 * \param self a consumer
1113 static void consumer_work_stop( mlt_consumer self )
1115 // Make sure we're running
1116 if ( self->started )
1118 // Inform thread to stop
1121 // Broadcast to the queue condition in case it's waiting
1122 pthread_mutex_lock( &self->queue_mutex );
1123 pthread_cond_broadcast( &self->queue_cond );
1124 pthread_mutex_unlock( &self->queue_mutex );
1126 // Broadcast to the put condition in case it's waiting
1127 pthread_mutex_lock( &self->put_mutex );
1128 pthread_cond_broadcast( &self->put_cond );
1129 pthread_mutex_unlock( &self->put_mutex );
1131 // Broadcast to the done condition in case it's waiting
1132 pthread_mutex_lock( &self->done_mutex );
1133 pthread_cond_broadcast( &self->done_cond );
1134 pthread_mutex_unlock( &self->done_mutex );
1138 while ( ( thread = mlt_deque_pop_back( self->worker_threads ) ) )
1139 pthread_join( *thread, NULL );
1141 // Deallocate the array of threads
1142 if ( self->threads )
1143 free( self->threads );
1145 // Indicate that worker threads no longer running
1148 // Destroy the mutexes
1149 pthread_mutex_destroy( &self->queue_mutex );
1150 pthread_mutex_destroy( &self->done_mutex );
1152 // Destroy the conditions
1153 pthread_cond_destroy( &self->queue_cond );
1154 pthread_cond_destroy( &self->done_cond );
1157 while ( mlt_deque_count( self->queue ) )
1158 mlt_frame_close( mlt_deque_pop_back( self->queue ) );
1161 mlt_deque_close( self->queue );
1162 mlt_deque_close( self->worker_threads );
1166 /** Flush the read/render thread's buffer.
1168 * \public \memberof mlt_consumer_s
1169 * \param self a consumer
1172 void mlt_consumer_purge( mlt_consumer self )
1176 pthread_mutex_lock( &self->queue_mutex );
1177 while ( mlt_deque_count( self->queue ) )
1178 mlt_frame_close( mlt_deque_pop_back( self->queue ) );
1179 pthread_cond_broadcast( &self->queue_cond );
1180 pthread_mutex_unlock( &self->queue_mutex );
1184 /** Use multiple worker threads and a work queue.
1187 static mlt_frame worker_get_frame( mlt_consumer self, mlt_properties properties )
1190 mlt_frame frame = NULL;
1192 double fps = mlt_properties_get_double( properties, "fps" );
1193 int threads = abs( self->real_time );
1194 int buffer = mlt_properties_get_int( properties, "_buffer" );
1195 buffer = buffer > 0 ? buffer : mlt_properties_get_int( properties, "buffer" );
1196 // This is a heuristic to determine a suitable minimum buffer size for the number of threads.
1197 int headroom = 2 + threads * threads;
1198 buffer = buffer < headroom ? headroom : buffer;
1200 // Start worker threads if not already started.
1201 if ( ! self->ahead )
1203 int prefill = mlt_properties_get_int( properties, "prefill" );
1204 prefill = prefill > 0 && prefill < buffer ? prefill : buffer;
1206 consumer_work_start( self );
1208 // Fill the work queue.
1210 while ( self->ahead && i-- )
1212 frame = mlt_consumer_get_frame( self );
1215 pthread_mutex_lock( &self->queue_mutex );
1216 mlt_deque_push_back( self->queue, frame );
1217 pthread_cond_signal( &self->queue_cond );
1218 pthread_mutex_unlock( &self->queue_mutex );
1223 while ( self->ahead && first_unprocessed_frame( self ) < prefill )
1225 pthread_mutex_lock( &self->done_mutex );
1226 pthread_cond_wait( &self->done_cond, &self->done_mutex );
1227 pthread_mutex_unlock( &self->done_mutex );
1229 self->process_head = threads;
1232 // mlt_log_verbose( MLT_CONSUMER_SERVICE(self), "size %d done count %d work count %d process_head %d\n",
1233 // threads, first_unprocessed_frame( self ), mlt_deque_count( self->queue ), self->process_head );
1235 // Feed the work queue
1236 while ( self->ahead && mlt_deque_count( self->queue ) < buffer )
1238 frame = mlt_consumer_get_frame( self );
1241 pthread_mutex_lock( &self->queue_mutex );
1242 mlt_deque_push_back( self->queue, frame );
1243 pthread_cond_signal( &self->queue_cond );
1244 pthread_mutex_unlock( &self->queue_mutex );
1247 // Wait if not realtime.
1248 mlt_frame head_frame = MLT_FRAME( mlt_deque_peek_front( self->queue ) );
1249 while ( self->ahead && self->real_time < 0 &&
1250 !( head_frame && mlt_properties_get_int( MLT_FRAME_PROPERTIES( head_frame ), "rendered" ) ) )
1252 pthread_mutex_lock( &self->done_mutex );
1253 pthread_cond_wait( &self->done_cond, &self->done_mutex );
1254 pthread_mutex_unlock( &self->done_mutex );
1257 // Get the frame from the queue.
1258 pthread_mutex_lock( &self->queue_mutex );
1259 frame = mlt_deque_pop_front( self->queue );
1260 pthread_mutex_unlock( &self->queue_mutex );
1262 // Adapt the worker process head to the runtime conditions.
1263 if ( self->real_time > 0 )
1265 if ( frame && mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "rendered" ) )
1267 self->consecutive_dropped = 0;
1268 if ( self->process_head > threads && self->consecutive_rendered >= self->process_head )
1269 self->process_head--;
1271 self->consecutive_rendered++;
1275 self->consecutive_rendered = 0;
1276 if ( self->process_head < buffer - threads && self->consecutive_dropped > threads )
1277 self->process_head++;
1279 self->consecutive_dropped++;
1281 // mlt_log_verbose( MLT_CONSUMER_SERVICE(self), "dropped %d rendered %d process_head %d\n",
1282 // self->consecutive_dropped, self->consecutive_rendered, self->process_head );
1284 // Check for too many consecutively dropped frames
1285 if ( self->consecutive_dropped > mlt_properties_get_int( properties, "drop_max" ) )
1287 int orig_buffer = mlt_properties_get_int( properties, "buffer" );
1288 int prefill = mlt_properties_get_int( properties, "prefill" );
1289 mlt_log_verbose( self, "too many frames dropped - " );
1291 // If using a default low-latency buffer level (SDL) and below the limit
1292 if ( ( orig_buffer == 1 || prefill == 1 ) && buffer < (threads + 1) * 10 )
1294 // Auto-scale the buffer to compensate
1295 mlt_log_verbose( self, "increasing buffer to %d\n", buffer + threads );
1296 mlt_properties_set_int( properties, "_buffer", buffer + threads );
1297 self->consecutive_dropped = fps / 2;
1301 // Tell the consumer to render it
1302 mlt_log_verbose( self, "forcing next frame\n" );
1303 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
1304 self->consecutive_dropped = 0;
1312 /** Get the next frame from the producer connected to a consumer.
1314 * Typically, one uses this instead of \p mlt_consumer_get_frame to make
1315 * the asynchronous/real-time behavior configurable at runtime.
1316 * You should close the frame returned from this when you are done with it.
1318 * \public \memberof mlt_consumer_s
1319 * \param self a consumer
1323 mlt_frame mlt_consumer_rt_frame( mlt_consumer self )
1326 mlt_frame frame = NULL;
1328 // Get the properties
1329 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
1331 // Check if the user has requested real time or not
1332 if ( self->real_time > 1 || self->real_time < -1 )
1335 return worker_get_frame( self, properties );
1337 else if ( self->real_time == 1 || self->real_time == -1 )
1341 // Is the read ahead running?
1342 if ( self->ahead == 0 )
1344 int buffer = mlt_properties_get_int( properties, "buffer" );
1345 int prefill = mlt_properties_get_int( properties, "prefill" );
1346 consumer_read_ahead_start( self );
1348 size = prefill > 0 && prefill < buffer ? prefill : buffer;
1351 // Get frame from queue
1352 pthread_mutex_lock( &self->queue_mutex );
1353 while( self->ahead && mlt_deque_count( self->queue ) < size )
1354 pthread_cond_wait( &self->queue_cond, &self->queue_mutex );
1355 frame = mlt_deque_pop_front( self->queue );
1356 pthread_cond_broadcast( &self->queue_cond );
1357 pthread_mutex_unlock( &self->queue_mutex );
1359 else // real_time == 0
1361 // Get the frame in non real time
1362 frame = mlt_consumer_get_frame( self );
1364 // This isn't true, but from the consumers perspective it is
1365 if ( frame != NULL )
1366 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "rendered", 1 );
1372 /** Callback for the implementation to indicate a stopped condition.
1374 * \public \memberof mlt_consumer_s
1375 * \param self a consumer
1378 void mlt_consumer_stopped( mlt_consumer self )
1380 mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( self ), "running", 0 );
1381 mlt_events_fire( MLT_CONSUMER_PROPERTIES( self ), "consumer-stopped", NULL );
1382 mlt_event_unblock( self->event_listener );
1385 /** Stop the consumer.
1387 * \public \memberof mlt_consumer_s
1388 * \param self a consumer
1389 * \return true if there was an error
1392 int mlt_consumer_stop( mlt_consumer self )
1394 // Get the properies
1395 mlt_properties properties = MLT_CONSUMER_PROPERTIES( self );
1398 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_DEBUG, "stopping put waiting\n" );
1399 pthread_mutex_lock( &self->put_mutex );
1400 self->put_active = 0;
1401 pthread_cond_broadcast( &self->put_cond );
1402 pthread_mutex_unlock( &self->put_mutex );
1404 // Stop the consumer
1405 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_DEBUG, "stopping consumer\n" );
1407 // Cancel the read ahead threads
1409 if ( self->started )
1411 // Unblock the consumer calling mlt_consumer_rt_frame
1412 pthread_mutex_lock( &self->queue_mutex );
1413 pthread_cond_broadcast( &self->queue_cond );
1414 pthread_mutex_unlock( &self->queue_mutex );
1417 // Invoke the child callback
1418 if ( self->stop != NULL )
1421 // Check if the user has requested real time or not and stop if necessary
1422 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_DEBUG, "stopping read_ahead\n" );
1423 if ( abs( self->real_time ) == 1 )
1424 consumer_read_ahead_stop( self );
1425 else if ( abs( self->real_time ) > 1 )
1426 consumer_work_stop( self );
1428 // Kill the test card
1429 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
1431 // Check and run a post command
1432 if ( mlt_properties_get( properties, "post" ) )
1433 if (system( mlt_properties_get( properties, "post" ) ) == -1 )
1434 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_ERROR, "system(%s) failed!\n", mlt_properties_get( properties, "post" ) );
1436 mlt_log( MLT_CONSUMER_SERVICE( self ), MLT_LOG_DEBUG, "stopped\n" );
1441 /** Determine if the consumer is stopped.
1443 * \public \memberof mlt_consumer_s
1444 * \param self a consumer
1445 * \return true if the consumer is stopped
1448 int mlt_consumer_is_stopped( mlt_consumer self )
1450 // Check if the consumer is stopped
1451 if ( self->is_stopped != NULL )
1452 return self->is_stopped( self );
1457 /** Close and destroy the consumer.
1459 * \public \memberof mlt_consumer_s
1460 * \param self a consumer
1463 void mlt_consumer_close( mlt_consumer self )
1465 if ( self != NULL && mlt_properties_dec_ref( MLT_CONSUMER_PROPERTIES( self ) ) <= 0 )
1467 // Get the childs close function
1468 void ( *consumer_close )( ) = self->close;
1470 if ( consumer_close )
1473 //mlt_consumer_stop( self );
1476 consumer_close( self );
1480 // Make sure it only gets called once
1481 self->parent.close = NULL;
1483 // Destroy the push mutex and condition
1484 pthread_mutex_destroy( &self->put_mutex );
1485 pthread_cond_destroy( &self->put_cond );
1487 mlt_service_close( &self->parent );
1492 /** Get the position of the last frame shown.
1494 * \public \memberof mlt_consumer_s
1495 * \param consumer a consumer
1496 * \return the position
1499 mlt_position mlt_consumer_position( mlt_consumer consumer )
1501 return consumer->position;