2 * mlt_playlist.c -- playlist service class
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
23 #include "mlt_playlist.h"
24 #include "mlt_tractor.h"
25 #include "mlt_multitrack.h"
26 #include "mlt_field.h"
27 #include "mlt_frame.h"
28 #include "mlt_transition.h"
34 /** Virtual playlist entry.
37 struct playlist_entry_s
39 mlt_producer producer;
40 mlt_position frame_in;
41 mlt_position frame_out;
42 mlt_position frame_count;
44 mlt_position producer_length;
46 int preservation_hack;
49 /** Forward declarations
52 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
53 static int mlt_playlist_unmix( mlt_playlist this, int clip );
54 static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out );
59 mlt_playlist mlt_playlist_init( )
61 mlt_playlist this = calloc( sizeof( struct mlt_playlist_s ), 1 );
64 mlt_producer producer = &this->parent;
66 // Construct the producer
67 mlt_producer_init( producer, this );
69 // Override the producer get_frame
70 producer->get_frame = producer_get_frame;
72 // Define the destructor
73 producer->close = ( mlt_destructor )mlt_playlist_close;
74 producer->close_object = this;
77 mlt_producer_init( &this->blank, NULL );
78 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank ), "mlt_service", "blank" );
79 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank ), "resource", "blank" );
81 // Indicate that this producer is a playlist
82 mlt_properties_set_data( MLT_PLAYLIST_PROPERTIES( this ), "playlist", this, 0, NULL, NULL );
84 // Specify the eof condition
85 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "eof", "pause" );
86 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "resource", "<playlist>" );
87 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "mlt_type", "mlt_producer" );
88 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "in", 0 );
89 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "out", -1 );
90 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "length", 0 );
93 this->list = malloc( this->size * sizeof( playlist_entry * ) );
99 /** Get the producer associated to this playlist.
102 mlt_producer mlt_playlist_producer( mlt_playlist this )
104 return this != NULL ? &this->parent : NULL;
107 /** Get the service associated to this playlist.
110 mlt_service mlt_playlist_service( mlt_playlist this )
112 return MLT_PRODUCER_SERVICE( &this->parent );
115 /** Get the propertues associated to this playlist.
118 mlt_properties mlt_playlist_properties( mlt_playlist this )
120 return MLT_PRODUCER_PROPERTIES( &this->parent );
123 /** Refresh the playlist after a clip has been changed.
126 static int mlt_playlist_virtual_refresh( mlt_playlist this )
128 // Obtain the properties
129 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
131 // Get the fps of the first producer
132 double fps = mlt_properties_get_double( properties, "first_fps" );
134 mlt_position frame_count = 0;
136 for ( i = 0; i < this->count; i ++ )
139 mlt_producer producer = this->list[ i ]->producer;
140 int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
145 // Inherit it from the producer
146 fps = mlt_producer_get_fps( producer );
148 else if ( fps != mlt_properties_get_double( MLT_PRODUCER_PROPERTIES( producer ), "fps" ) )
150 // Generate a warning for now - the following attempt to fix may fail
151 fprintf( stderr, "Warning: fps mismatch on playlist producer %d\n", this->count );
153 // It should be safe to impose fps on an image producer, but not necessarily safe for video
154 mlt_properties_set_double( MLT_PRODUCER_PROPERTIES( producer ), "fps", fps );
157 // Check if the length of the producer has changed
158 if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
159 this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
161 // This clip should be removed...
162 if ( current_length < 1 )
164 this->list[ i ]->frame_in = 0;
165 this->list[ i ]->frame_out = -1;
166 this->list[ i ]->frame_count = 0;
170 this->list[ i ]->frame_in = mlt_producer_get_in( producer );
171 this->list[ i ]->frame_out = mlt_producer_get_out( producer );
172 this->list[ i ]->frame_count = current_length;
175 // Update the producer_length
176 this->list[ i ]->producer_length = current_length;
179 // Calculate the frame_count
180 this->list[ i ]->frame_count = ( this->list[ i ]->frame_out - this->list[ i ]->frame_in + 1 ) * this->list[ i ]->repeat;
182 // Update the frame_count for this clip
183 frame_count += this->list[ i ]->frame_count;
186 // Refresh all properties
187 mlt_properties_set_double( properties, "first_fps", fps );
188 mlt_properties_set_double( properties, "fps", fps == 0 ? 25 : fps );
189 mlt_events_block( properties, properties );
190 mlt_properties_set_position( properties, "length", frame_count );
191 mlt_events_unblock( properties, properties );
192 mlt_properties_set_position( properties, "out", frame_count - 1 );
197 /** Listener for producers on the playlist.
200 static void mlt_playlist_listener( mlt_producer producer, mlt_playlist this )
202 mlt_playlist_virtual_refresh( this );
205 /** Append to the virtual playlist.
208 static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer source, mlt_position in, mlt_position out )
210 mlt_producer producer = NULL;
211 mlt_properties properties = NULL;
212 mlt_properties parent = NULL;
214 // If we have a cut, then use the in/out points from the cut
215 if ( mlt_producer_is_blank( source ) )
217 // Make sure the blank is long enough to accomodate the length specified
218 if ( out - in + 1 > mlt_producer_get_length( &this->blank ) )
220 mlt_properties blank_props = MLT_PRODUCER_PROPERTIES( &this->blank );
221 mlt_events_block( blank_props, blank_props );
222 mlt_producer_set_in_and_out( &this->blank, in, out );
223 mlt_events_unblock( blank_props, blank_props );
226 // Now make sure the cut comes from this this->blank
227 if ( source == NULL )
229 producer = mlt_producer_cut( &this->blank, in, out );
231 else if ( !mlt_producer_is_cut( source ) || mlt_producer_cut_parent( source ) != &this->blank )
233 producer = mlt_producer_cut( &this->blank, in, out );
238 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer ) );
241 properties = MLT_PRODUCER_PROPERTIES( producer );
243 else if ( mlt_producer_is_cut( source ) )
247 in = mlt_producer_get_in( producer );
248 if ( out == -1 || out > mlt_producer_get_out( producer ) )
249 out = mlt_producer_get_out( producer );
250 properties = MLT_PRODUCER_PROPERTIES( producer );
251 mlt_properties_inc_ref( properties );
255 producer = mlt_producer_cut( source, in, out );
256 if ( in == -1 || in < mlt_producer_get_in( producer ) )
257 in = mlt_producer_get_in( producer );
258 if ( out == -1 || out > mlt_producer_get_out( producer ) )
259 out = mlt_producer_get_out( producer );
260 properties = MLT_PRODUCER_PROPERTIES( producer );
263 // Fetch the cuts parent properties
264 parent = MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( producer ) );
266 // Remove fezzik normalisers for fx cuts
267 if ( mlt_properties_get_int( parent, "meta.fx_cut" ) )
269 mlt_service service = MLT_PRODUCER_SERVICE( mlt_producer_cut_parent( producer ) );
270 mlt_filter filter = mlt_service_filter( service, 0 );
271 while ( filter != NULL && mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik" ) )
273 mlt_service_detach( service, filter );
274 filter = mlt_service_filter( service, 0 );
276 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer ), "meta.fx_cut", 1 );
279 // Check that we have room
280 if ( this->count >= this->size )
283 this->list = realloc( this->list, ( this->size + 10 ) * sizeof( playlist_entry * ) );
284 for ( i = this->size; i < this->size + 10; i ++ ) this->list[ i ] = NULL;
289 this->list[ this->count ] = calloc( sizeof( playlist_entry ), 1 );
290 if ( this->list[ this->count ] != NULL )
292 this->list[ this->count ]->producer = producer;
293 this->list[ this->count ]->frame_in = in;
294 this->list[ this->count ]->frame_out = out;
295 this->list[ this->count ]->frame_count = out - in + 1;
296 this->list[ this->count ]->repeat = 1;
297 this->list[ this->count ]->producer_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
298 this->list[ this->count ]->event = mlt_events_listen( parent, this, "producer-changed", ( mlt_listener )mlt_playlist_listener );
299 mlt_event_inc_ref( this->list[ this->count ]->event );
300 mlt_properties_set( properties, "eof", "pause" );
301 mlt_producer_set_speed( producer, 0 );
305 return mlt_playlist_virtual_refresh( this );
308 static mlt_producer mlt_playlist_locate( mlt_playlist this, mlt_position *position, int *clip, int *total )
310 // Default producer to NULL
311 mlt_producer producer = NULL;
313 // Loop for each producer until found
314 for ( *clip = 0; *clip < this->count; *clip += 1 )
316 // Increment the total
317 *total += this->list[ *clip ]->frame_count;
319 // Check if the position indicates that we have found the clip
320 // Note that 0 length clips get skipped automatically
321 if ( *position < this->list[ *clip ]->frame_count )
323 // Found it, now break
324 producer = this->list[ *clip ]->producer;
329 // Decrement position by length of this entry
330 *position -= this->list[ *clip ]->frame_count;
337 /** Seek in the virtual playlist.
340 static mlt_service mlt_playlist_virtual_seek( mlt_playlist this, int *progressive )
342 // Map playlist position to real producer in virtual playlist
343 mlt_position position = mlt_producer_frame( &this->parent );
345 // Keep the original position since we change it while iterating through the list
346 mlt_position original = position;
348 // Clip index and total
352 // Locate the producer for the position
353 mlt_producer producer = mlt_playlist_locate( this, &position, &i, &total );
355 // Get the properties
356 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
358 // Get the eof handling
359 char *eof = mlt_properties_get( properties, "eof" );
361 // Seek in real producer to relative position
362 if ( producer != NULL )
364 int count = this->list[ i ]->frame_count / this->list[ i ]->repeat;
365 *progressive = count == 1;
366 mlt_producer_seek( producer, (int)position % count );
368 else if ( !strcmp( eof, "pause" ) && total > 0 )
370 playlist_entry *entry = this->list[ this->count - 1 ];
371 int count = entry->frame_count / entry->repeat;
372 mlt_producer this_producer = MLT_PLAYLIST_PRODUCER( this );
373 mlt_producer_seek( this_producer, original - 1 );
374 producer = entry->producer;
375 mlt_producer_seek( producer, (int)entry->frame_out % count );
376 mlt_producer_set_speed( this_producer, 0 );
377 mlt_producer_set_speed( producer, 0 );
378 *progressive = count == 1;
380 else if ( !strcmp( eof, "loop" ) && total > 0 )
382 playlist_entry *entry = this->list[ 0 ];
383 mlt_producer this_producer = MLT_PLAYLIST_PRODUCER( this );
384 mlt_producer_seek( this_producer, 0 );
385 producer = entry->producer;
386 mlt_producer_seek( producer, 0 );
390 producer = &this->blank;
393 return MLT_PRODUCER_SERVICE( producer );
396 /** Invoked when a producer indicates that it has prematurely reached its end.
399 static mlt_producer mlt_playlist_virtual_set_out( mlt_playlist this )
401 // Default producer to blank
402 mlt_producer producer = &this->blank;
404 // Map playlist position to real producer in virtual playlist
405 mlt_position position = mlt_producer_frame( &this->parent );
407 // Loop through the virtual playlist
410 for ( i = 0; i < this->count; i ++ )
412 if ( position < this->list[ i ]->frame_count )
414 // Found it, now break
415 producer = this->list[ i ]->producer;
420 // Decrement position by length of this entry
421 position -= this->list[ i ]->frame_count;
425 // Seek in real producer to relative position
426 if ( i < this->count && this->list[ i ]->frame_out != position )
428 // Update the frame_count for the changed clip (hmmm)
429 this->list[ i ]->frame_out = position;
430 this->list[ i ]->frame_count = this->list[ i ]->frame_out - this->list[ i ]->frame_in + 1;
432 // Refresh the playlist
433 mlt_playlist_virtual_refresh( this );
439 /** Obtain the current clips index.
442 int mlt_playlist_current_clip( mlt_playlist this )
444 // Map playlist position to real producer in virtual playlist
445 mlt_position position = mlt_producer_frame( &this->parent );
447 // Loop through the virtual playlist
450 for ( i = 0; i < this->count; i ++ )
452 if ( position < this->list[ i ]->frame_count )
454 // Found it, now break
459 // Decrement position by length of this entry
460 position -= this->list[ i ]->frame_count;
467 /** Obtain the current clips producer.
470 mlt_producer mlt_playlist_current( mlt_playlist this )
472 int i = mlt_playlist_current_clip( this );
473 if ( i < this->count )
474 return this->list[ i ]->producer;
479 /** Get the position which corresponds to the start of the next clip.
482 mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index )
484 mlt_position position = 0;
485 int absolute_clip = index;
488 // Determine the absolute clip
491 case mlt_whence_relative_start:
492 absolute_clip = index;
495 case mlt_whence_relative_current:
496 absolute_clip = mlt_playlist_current_clip( this ) + index;
499 case mlt_whence_relative_end:
500 absolute_clip = this->count - index;
504 // Check that we're in a valid range
505 if ( absolute_clip < 0 )
507 else if ( absolute_clip > this->count )
508 absolute_clip = this->count;
510 // Now determine the position
511 for ( i = 0; i < absolute_clip; i ++ )
512 position += this->list[ i ]->frame_count;
517 /** Get all the info about the clip specified.
520 int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index )
522 int error = index < 0 || index >= this->count;
523 memset( info, 0, sizeof( mlt_playlist_clip_info ) );
526 mlt_producer producer = mlt_producer_cut_parent( this->list[ index ]->producer );
527 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
529 info->producer = producer;
530 info->cut = this->list[ index ]->producer;
531 info->start = mlt_playlist_clip( this, mlt_whence_relative_start, index );
532 info->resource = mlt_properties_get( properties, "resource" );
533 info->frame_in = this->list[ index ]->frame_in;
534 info->frame_out = this->list[ index ]->frame_out;
535 info->frame_count = this->list[ index ]->frame_count;
536 info->repeat = this->list[ index ]->repeat;
537 info->length = mlt_producer_get_length( producer );
538 info->fps = mlt_producer_get_fps( producer );
544 /** Get number of clips in the playlist.
547 int mlt_playlist_count( mlt_playlist this )
552 /** Clear the playlist.
555 int mlt_playlist_clear( mlt_playlist this )
558 for ( i = 0; i < this->count; i ++ )
560 mlt_event_close( this->list[ i ]->event );
561 mlt_producer_close( this->list[ i ]->producer );
564 mlt_properties_set_double( MLT_PLAYLIST_PROPERTIES( this ), "first_fps", 0 );
565 return mlt_playlist_virtual_refresh( this );
568 /** Append a producer to the playlist.
571 int mlt_playlist_append( mlt_playlist this, mlt_producer producer )
573 // Append to virtual list
574 return mlt_playlist_virtual_append( this, producer, 0, mlt_producer_get_playtime( producer ) - 1 );
577 /** Append a producer to the playlist with in/out points.
580 int mlt_playlist_append_io( mlt_playlist this, mlt_producer producer, mlt_position in, mlt_position out )
582 // Append to virtual list
583 if ( in != -1 && out != -1 )
584 return mlt_playlist_virtual_append( this, producer, in, out );
586 return mlt_playlist_append( this, producer );
589 /** Append a blank to the playlist of a given length.
592 int mlt_playlist_blank( mlt_playlist this, mlt_position length )
594 // Append to the virtual list
595 return mlt_playlist_virtual_append( this, &this->blank, 0, length );
598 /** Insert a producer into the playlist.
601 int mlt_playlist_insert( mlt_playlist this, mlt_producer producer, int where, mlt_position in, mlt_position out )
604 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
605 mlt_playlist_append_io( this, producer, in, out );
607 // Move to the position specified
608 mlt_playlist_move( this, this->count - 1, where );
609 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
611 return mlt_playlist_virtual_refresh( this );
614 /** Remove an entry in the playlist.
617 int mlt_playlist_remove( mlt_playlist this, int where )
619 int error = where < 0 || where >= this->count;
620 if ( error == 0 && mlt_playlist_unmix( this, where ) != 0 )
622 // We need to know the current clip and the position within the playlist
623 int current = mlt_playlist_current_clip( this );
624 mlt_position position = mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
626 // We need all the details about the clip we're removing
627 mlt_playlist_clip_info where_info;
628 playlist_entry *entry = this->list[ where ];
629 mlt_properties properties = MLT_PRODUCER_PROPERTIES( entry->producer );
635 mlt_playlist_get_clip_info( this, &where_info, where );
637 // Make sure the clip to be removed is valid and correct if necessary
640 if ( where >= this->count )
641 where = this->count - 1;
643 // Reorganise the list
644 for ( i = where + 1; i < this->count; i ++ )
645 this->list[ i - 1 ] = this->list[ i ];
648 if ( entry->preservation_hack == 0 )
650 // Decouple from mix_in/out if necessary
651 if ( mlt_properties_get_data( properties, "mix_in", NULL ) != NULL )
653 mlt_properties mix = mlt_properties_get_data( properties, "mix_in", NULL );
654 mlt_properties_set_data( mix, "mix_out", NULL, 0, NULL, NULL );
656 if ( mlt_properties_get_data( properties, "mix_out", NULL ) != NULL )
658 mlt_properties mix = mlt_properties_get_data( properties, "mix_out", NULL );
659 mlt_properties_set_data( mix, "mix_in", NULL, 0, NULL, NULL );
662 if ( mlt_properties_ref_count( MLT_PRODUCER_PROPERTIES( entry->producer ) ) == 1 )
663 mlt_producer_clear( entry->producer );
666 // Close the producer associated to the clip info
667 mlt_event_close( entry->event );
668 mlt_producer_close( entry->producer );
671 if ( where == current )
672 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), where_info.start );
673 else if ( where < current && this->count > 0 )
674 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), position - where_info.frame_count );
675 else if ( this->count == 0 )
676 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), 0 );
681 // Refresh the playlist
682 mlt_playlist_virtual_refresh( this );
688 /** Move an entry in the playlist.
691 int mlt_playlist_move( mlt_playlist this, int src, int dest )
695 /* We need to ensure that the requested indexes are valid and correct it as necessary */
698 if ( src >= this->count )
699 src = this->count - 1;
703 if ( dest >= this->count )
704 dest = this->count - 1;
706 if ( src != dest && this->count > 1 )
708 int current = mlt_playlist_current_clip( this );
709 mlt_position position = mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
710 playlist_entry *src_entry = NULL;
712 // We need all the details about the current clip
713 mlt_playlist_clip_info current_info;
715 mlt_playlist_get_clip_info( this, ¤t_info, current );
716 position -= current_info.start;
718 if ( current == src )
720 else if ( current > src && current < dest )
722 else if ( current == dest )
725 src_entry = this->list[ src ];
728 for ( i = src; i > dest; i -- )
729 this->list[ i ] = this->list[ i - 1 ];
733 for ( i = src; i < dest; i ++ )
734 this->list[ i ] = this->list[ i + 1 ];
736 this->list[ dest ] = src_entry;
738 mlt_playlist_get_clip_info( this, ¤t_info, current );
739 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), current_info.start + position );
740 mlt_playlist_virtual_refresh( this );
746 /** Repeat the specified clip n times.
749 int mlt_playlist_repeat_clip( mlt_playlist this, int clip, int repeat )
751 int error = repeat < 1 || clip < 0 || clip >= this->count;
754 playlist_entry *entry = this->list[ clip ];
755 entry->repeat = repeat;
756 mlt_playlist_virtual_refresh( this );
761 /** Resize the specified clip.
764 int mlt_playlist_resize_clip( mlt_playlist this, int clip, mlt_position in, mlt_position out )
766 int error = clip < 0 || clip >= this->count;
767 if ( error == 0 && mlt_playlist_resize_mix( this, clip, in, out ) != 0 )
769 playlist_entry *entry = this->list[ clip ];
770 mlt_producer producer = entry->producer;
771 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
773 mlt_events_block( properties, properties );
775 if ( mlt_producer_is_blank( producer ) )
777 // Make sure the blank is long enough to accomodate the length specified
778 if ( out - in + 1 > mlt_producer_get_length( &this->blank ) )
780 mlt_properties blank_props = MLT_PRODUCER_PROPERTIES( &this->blank );
781 mlt_properties_set_int( blank_props, "length", out - in + 1 );
782 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer ), "length", out - in + 1 );
783 mlt_producer_set_in_and_out( &this->blank, 0, out - in );
789 if ( out <= -1 || out >= mlt_producer_get_length( producer ) )
790 out = mlt_producer_get_length( producer ) - 1;
799 mlt_producer_set_in_and_out( producer, in, out );
800 mlt_events_unblock( properties, properties );
801 mlt_playlist_virtual_refresh( this );
806 /** Split a clip on the playlist at the given position.
809 int mlt_playlist_split( mlt_playlist this, int clip, mlt_position position )
811 int error = clip < 0 || clip >= this->count;
814 playlist_entry *entry = this->list[ clip ];
815 position = position < 0 ? entry->frame_count + position - 1 : position;
816 if ( position >= 0 && position < entry->frame_count - 1 )
818 int in = entry->frame_in;
819 int out = entry->frame_out;
820 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
821 mlt_playlist_resize_clip( this, clip, in, in + position );
822 if ( !mlt_producer_is_blank( entry->producer ) )
825 mlt_properties entry_properties = MLT_PRODUCER_PROPERTIES( entry->producer );
826 mlt_producer split = mlt_producer_cut( entry->producer, in + position + 1, out );
827 mlt_properties split_properties = MLT_PRODUCER_PROPERTIES( split );
828 mlt_playlist_insert( this, split, clip + 1, 0, -1 );
829 for ( i = 0; i < mlt_properties_count( entry_properties ); i ++ )
831 char *name = mlt_properties_get_name( entry_properties, i );
832 if ( name != NULL && !strncmp( name, "meta.", 5 ) )
833 mlt_properties_set( split_properties, name, mlt_properties_get_value( entry_properties, i ) );
835 mlt_producer_close( split );
839 mlt_playlist_insert( this, &this->blank, clip + 1, 0, out - position - 1 );
841 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
842 mlt_playlist_virtual_refresh( this );
852 /** Split the playlist at the absolute position.
855 int mlt_playlist_split_at( mlt_playlist this, mlt_position position, int left )
857 int result = this == NULL ? -1 : 0;
860 if ( position >= 0 && position < mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) ) )
862 int clip = mlt_playlist_get_clip_index_at( this, position );
863 mlt_playlist_clip_info info;
864 mlt_playlist_get_clip_info( this, &info, clip );
865 if ( left && position != info.start )
866 mlt_playlist_split( this, clip, position - info.start - 1 );
868 mlt_playlist_split( this, clip, position - info.start );
871 else if ( position <= 0 )
877 result = mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
883 /** Join 1 or more consecutive clips.
886 int mlt_playlist_join( mlt_playlist this, int clip, int count, int merge )
888 int error = clip < 0 || clip >= this->count;
892 mlt_playlist new_clip = mlt_playlist_init( );
893 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
894 if ( clip + count >= this->count )
895 count = this->count - clip - 1;
896 for ( i = 0; i <= count; i ++ )
898 playlist_entry *entry = this->list[ clip ];
899 mlt_playlist_append( new_clip, entry->producer );
900 mlt_playlist_repeat_clip( new_clip, i, entry->repeat );
901 entry->preservation_hack = 1;
902 mlt_playlist_remove( this, clip );
904 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
905 mlt_playlist_insert( this, MLT_PLAYLIST_PRODUCER( new_clip ), clip, 0, -1 );
906 mlt_playlist_close( new_clip );
911 /** Mix consecutive clips for a specified length and apply transition if specified.
914 int mlt_playlist_mix( mlt_playlist this, int clip, int length, mlt_transition transition )
916 int error = ( clip < 0 || clip + 1 >= this->count );
919 playlist_entry *clip_a = this->list[ clip ];
920 playlist_entry *clip_b = this->list[ clip + 1 ];
921 mlt_producer track_a = NULL;
922 mlt_producer track_b = NULL;
923 mlt_tractor tractor = mlt_tractor_new( );
924 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
926 // Check length is valid for both clips and resize if necessary.
927 int max_size = clip_a->frame_count > clip_b->frame_count ? clip_a->frame_count : clip_b->frame_count;
928 length = length > max_size ? max_size : length;
930 // Create the a and b tracks/cuts if necessary - note that no cuts are required if the length matches
931 if ( length != clip_a->frame_count )
932 track_a = mlt_producer_cut( clip_a->producer, clip_a->frame_out - length + 1, clip_a->frame_out );
934 track_a = clip_a->producer;
936 if ( length != clip_b->frame_count )
937 track_b = mlt_producer_cut( clip_b->producer, clip_b->frame_in, clip_b->frame_in + length - 1 );
939 track_b = clip_b->producer;
941 // Set the tracks on the tractor
942 mlt_tractor_set_track( tractor, track_a, 0 );
943 mlt_tractor_set_track( tractor, track_b, 1 );
945 // Insert the mix object into the playlist
946 mlt_playlist_insert( this, MLT_TRACTOR_PRODUCER( tractor ), clip + 1, -1, -1 );
947 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor ), "mlt_mix", tractor, 0, NULL, NULL );
949 // Attach the transition
950 if ( transition != NULL )
952 mlt_field field = mlt_tractor_field( tractor );
953 mlt_field_plant_transition( field, transition, 0, 1 );
954 mlt_transition_set_in_and_out( transition, 0, length - 1 );
957 // Close our references to the tracks if we created new cuts above (the tracks can still be used here)
958 if ( track_a != clip_a->producer )
959 mlt_producer_close( track_a );
960 if ( track_b != clip_b->producer )
961 mlt_producer_close( track_b );
963 // Check if we have anything left on the right hand clip
964 if ( track_b == clip_b->producer )
966 clip_b->preservation_hack = 1;
967 mlt_playlist_remove( this, clip + 2 );
969 else if ( clip_b->frame_out - clip_b->frame_in > length )
971 mlt_playlist_resize_clip( this, clip + 2, clip_b->frame_in + length, clip_b->frame_out );
972 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_b->producer ), "mix_in", tractor, 0, NULL, NULL );
973 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor ), "mix_out", clip_b->producer, 0, NULL, NULL );
977 mlt_producer_clear( clip_b->producer );
978 mlt_playlist_remove( this, clip + 2 );
981 // Check if we have anything left on the left hand clip
982 if ( track_a == clip_a->producer )
984 clip_a->preservation_hack = 1;
985 mlt_playlist_remove( this, clip );
987 else if ( clip_a->frame_out - clip_a->frame_in > length )
989 mlt_playlist_resize_clip( this, clip, clip_a->frame_in, clip_a->frame_out - length );
990 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_a->producer ), "mix_out", tractor, 0, NULL, NULL );
991 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor ), "mix_in", clip_a->producer, 0, NULL, NULL );
995 mlt_producer_clear( clip_a->producer );
996 mlt_playlist_remove( this, clip );
999 // Unblock and force a fire off of change events to listeners
1000 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1001 mlt_playlist_virtual_refresh( this );
1002 mlt_tractor_close( tractor );
1007 /** Add a transition to an existing mix.
1010 int mlt_playlist_mix_add( mlt_playlist this, int clip, mlt_transition transition )
1012 mlt_producer producer = mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip ) );
1013 mlt_properties properties = producer != NULL ? MLT_PRODUCER_PROPERTIES( producer ) : NULL;
1014 mlt_tractor tractor = properties != NULL ? mlt_properties_get_data( properties, "mlt_mix", NULL ) : NULL;
1015 int error = transition == NULL || tractor == NULL;
1018 mlt_field field = mlt_tractor_field( tractor );
1019 mlt_field_plant_transition( field, transition, 0, 1 );
1020 mlt_transition_set_in_and_out( transition, 0, this->list[ clip ]->frame_count - 1 );
1025 /** Return the clip at the clip index.
1028 mlt_producer mlt_playlist_get_clip( mlt_playlist this, int clip )
1030 if ( clip >= 0 && clip < this->count )
1031 return this->list[ clip ]->producer;
1035 /** Return the clip at the specified position.
1038 mlt_producer mlt_playlist_get_clip_at( mlt_playlist this, mlt_position position )
1040 int index = 0, total = 0;
1041 return mlt_playlist_locate( this, &position, &index, &total );
1044 /** Return the clip index of the specified position.
1047 int mlt_playlist_get_clip_index_at( mlt_playlist this, mlt_position position )
1049 int index = 0, total = 0;
1050 mlt_playlist_locate( this, &position, &index, &total );
1054 /** Determine if the clip is a mix.
1057 int mlt_playlist_clip_is_mix( mlt_playlist this, int clip )
1059 mlt_producer producer = mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip ) );
1060 mlt_properties properties = producer != NULL ? MLT_PRODUCER_PROPERTIES( producer ) : NULL;
1061 mlt_tractor tractor = properties != NULL ? mlt_properties_get_data( properties, "mlt_mix", NULL ) : NULL;
1062 return tractor != NULL;
1065 /** Remove a mixed clip - ensure that the cuts included in the mix find their way
1066 back correctly on to the playlist.
1069 static int mlt_playlist_unmix( mlt_playlist this, int clip )
1071 int error = ( clip < 0 || clip >= this->count );
1073 // Ensure that the clip request is actually a mix
1076 mlt_producer producer = mlt_producer_cut_parent( this->list[ clip ]->producer );
1077 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
1078 error = mlt_properties_get_data( properties, "mlt_mix", NULL ) == NULL ||
1079 this->list[ clip ]->preservation_hack;
1084 playlist_entry *mix = this->list[ clip ];
1085 mlt_tractor tractor = ( mlt_tractor )mlt_producer_cut_parent( mix->producer );
1086 mlt_properties properties = MLT_TRACTOR_PROPERTIES( tractor );
1087 mlt_producer clip_a = mlt_properties_get_data( properties, "mix_in", NULL );
1088 mlt_producer clip_b = mlt_properties_get_data( properties, "mix_out", NULL );
1089 int length = mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor ) );
1090 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1092 if ( clip_a != NULL )
1094 mlt_producer_set_in_and_out( clip_a, mlt_producer_get_in( clip_a ), mlt_producer_get_out( clip_a ) + length );
1098 mlt_producer cut = mlt_tractor_get_track( tractor, 0 );
1099 mlt_playlist_insert( this, cut, clip, -1, -1 );
1103 if ( clip_b != NULL )
1105 mlt_producer_set_in_and_out( clip_b, mlt_producer_get_in( clip_b ) - length, mlt_producer_get_out( clip_b ) );
1109 mlt_producer cut = mlt_tractor_get_track( tractor, 1 );
1110 mlt_playlist_insert( this, cut, clip + 1, -1, -1 );
1113 mlt_properties_set_data( properties, "mlt_mix", NULL, 0, NULL, NULL );
1114 mlt_playlist_remove( this, clip );
1115 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1116 mlt_playlist_virtual_refresh( this );
1121 static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out )
1123 int error = ( clip < 0 || clip >= this->count );
1125 // Ensure that the clip request is actually a mix
1128 mlt_producer producer = mlt_producer_cut_parent( this->list[ clip ]->producer );
1129 mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
1130 error = mlt_properties_get_data( properties, "mlt_mix", NULL ) == NULL;
1135 playlist_entry *mix = this->list[ clip ];
1136 mlt_tractor tractor = ( mlt_tractor )mlt_producer_cut_parent( mix->producer );
1137 mlt_properties properties = MLT_TRACTOR_PROPERTIES( tractor );
1138 mlt_producer clip_a = mlt_properties_get_data( properties, "mix_in", NULL );
1139 mlt_producer clip_b = mlt_properties_get_data( properties, "mix_out", NULL );
1140 mlt_producer track_a = mlt_tractor_get_track( tractor, 0 );
1141 mlt_producer track_b = mlt_tractor_get_track( tractor, 1 );
1142 int length = out - in + 1;
1143 int length_diff = length - mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor ) );
1144 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1146 if ( clip_a != NULL )
1147 mlt_producer_set_in_and_out( clip_a, mlt_producer_get_in( clip_a ), mlt_producer_get_out( clip_a ) - length_diff );
1149 if ( clip_b != NULL )
1150 mlt_producer_set_in_and_out( clip_b, mlt_producer_get_in( clip_b ) + length_diff, mlt_producer_get_out( clip_b ) );
1152 mlt_producer_set_in_and_out( track_a, mlt_producer_get_in( track_a ) - length_diff, mlt_producer_get_out( track_a ) );
1153 mlt_producer_set_in_and_out( track_b, mlt_producer_get_in( track_b ), mlt_producer_get_out( track_b ) + length_diff );
1154 mlt_producer_set_in_and_out( MLT_MULTITRACK_PRODUCER( mlt_tractor_multitrack( tractor ) ), in, out );
1155 mlt_producer_set_in_and_out( MLT_TRACTOR_PRODUCER( tractor ), in, out );
1156 mlt_properties_set_position( MLT_PRODUCER_PROPERTIES( mix->producer ), "length", out - in + 1 );
1157 mlt_producer_set_in_and_out( mix->producer, in, out );
1159 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1160 mlt_playlist_virtual_refresh( this );
1165 /** Consolodate adjacent blank producers.
1168 void mlt_playlist_consolidate_blanks( mlt_playlist this, int keep_length )
1173 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1175 mlt_events_block( properties, properties );
1176 for ( i = 1; i < this->count; i ++ )
1178 playlist_entry *left = this->list[ i - 1 ];
1179 playlist_entry *right = this->list[ i ];
1181 if ( mlt_producer_is_blank( left->producer ) && mlt_producer_is_blank( right->producer ) )
1183 mlt_playlist_resize_clip( this, i - 1, 0, left->frame_count + right->frame_count - 1 );
1184 mlt_playlist_remove( this, i -- );
1188 if ( !keep_length && this->count > 0 )
1190 playlist_entry *last = this->list[ this->count - 1 ];
1191 if ( mlt_producer_is_blank( last->producer ) )
1192 mlt_playlist_remove( this, this->count - 1 );
1195 mlt_events_unblock( properties, properties );
1196 mlt_playlist_virtual_refresh( this );
1200 /** Determine if the specified clip index is a blank.
1203 int mlt_playlist_is_blank( mlt_playlist this, int clip )
1205 return this == NULL || mlt_producer_is_blank( mlt_playlist_get_clip( this, clip ) );
1208 /** Determine if the specified position is a blank.
1211 int mlt_playlist_is_blank_at( mlt_playlist this, mlt_position position )
1213 return this == NULL || mlt_producer_is_blank( mlt_playlist_get_clip_at( this, position ) );
1216 /** Replace the specified clip with a blank and return the clip.
1219 mlt_producer mlt_playlist_replace_with_blank( mlt_playlist this, int clip )
1221 mlt_producer producer = NULL;
1222 if ( !mlt_playlist_is_blank( this, clip ) )
1224 playlist_entry *entry = this->list[ clip ];
1225 int in = entry->frame_in;
1226 int out = entry->frame_out;
1227 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1228 producer = entry->producer;
1229 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer ) );
1230 mlt_events_block( properties, properties );
1231 mlt_playlist_remove( this, clip );
1232 mlt_playlist_blank( this, out - in );
1233 mlt_playlist_move( this, this->count - 1, clip );
1234 mlt_events_unblock( properties, properties );
1235 mlt_playlist_virtual_refresh( this );
1236 mlt_producer_set_in_and_out( producer, in, out );
1241 void mlt_playlist_insert_blank( mlt_playlist this, int clip, int length )
1243 if ( this != NULL && length >= 0 )
1245 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1246 mlt_events_block( properties, properties );
1247 mlt_playlist_blank( this, length );
1248 mlt_playlist_move( this, this->count - 1, clip );
1249 mlt_events_unblock( properties, properties );
1250 mlt_playlist_virtual_refresh( this );
1254 void mlt_playlist_pad_blanks( mlt_playlist this, mlt_position position, int length, int find )
1256 if ( this != NULL && length != 0 )
1258 int clip = mlt_playlist_get_clip_index_at( this, position );
1259 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1260 mlt_events_block( properties, properties );
1261 if ( find && clip < this->count && !mlt_playlist_is_blank( this, clip ) )
1263 if ( clip < this->count && mlt_playlist_is_blank( this, clip ) )
1265 mlt_playlist_clip_info info;
1266 mlt_playlist_get_clip_info( this, &info, clip );
1267 if ( info.frame_out + length > info.frame_in )
1268 mlt_playlist_resize_clip( this, clip, info.frame_in, info.frame_out + length );
1270 mlt_playlist_remove( this, clip );
1272 else if ( find && clip < this->count && length > 0 )
1274 mlt_playlist_insert_blank( this, clip, length );
1276 mlt_events_unblock( properties, properties );
1277 mlt_playlist_virtual_refresh( this );
1281 int mlt_playlist_insert_at( mlt_playlist this, mlt_position position, mlt_producer producer, int mode )
1283 int ret = this == NULL || position < 0 || producer == NULL;
1286 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1287 int length = mlt_producer_get_playtime( producer );
1288 int clip = mlt_playlist_get_clip_index_at( this, position );
1289 mlt_playlist_clip_info info;
1290 mlt_playlist_get_clip_info( this, &info, clip );
1291 mlt_events_block( properties, this );
1292 if ( clip < this->count && mlt_playlist_is_blank( this, clip ) )
1294 // Split and move to new clip if need be
1295 if ( position != info.start && mlt_playlist_split( this, clip, position - info.start ) == 0 )
1296 mlt_playlist_get_clip_info( this, &info, ++ clip );
1298 // Split again if need be
1299 if ( length < info.frame_count )
1300 mlt_playlist_split( this, clip, length - 1 );
1303 mlt_playlist_remove( this, clip );
1306 mlt_playlist_insert( this, producer, clip, -1, -1 );
1309 else if ( clip < this->count )
1311 if ( position > info.start + info.frame_count / 2 )
1313 if ( mode == 1 && clip < this->count && mlt_playlist_is_blank( this, clip ) )
1315 mlt_playlist_get_clip_info( this, &info, clip );
1316 if ( length < info.frame_count )
1317 mlt_playlist_split( this, clip, length );
1318 mlt_playlist_remove( this, clip );
1320 mlt_playlist_insert( this, producer, clip, -1, -1 );
1326 mlt_playlist_blank( this, position - mlt_properties_get_int( properties, "length" ) );
1327 mlt_playlist_append( this, producer );
1328 ret = this->count - 1;
1330 mlt_events_unblock( properties, this );
1331 mlt_playlist_virtual_refresh( this );
1340 int mlt_playlist_clip_start( mlt_playlist this, int clip )
1342 mlt_playlist_clip_info info;
1343 if ( mlt_playlist_get_clip_info( this, &info, clip ) == 0 )
1345 return clip < 0 ? 0 : mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1348 int mlt_playlist_clip_length( mlt_playlist this, int clip )
1350 mlt_playlist_clip_info info;
1351 if ( mlt_playlist_get_clip_info( this, &info, clip ) == 0 )
1352 return info.frame_count;
1356 int mlt_playlist_blanks_from( mlt_playlist this, int clip, int bounded )
1359 mlt_playlist_clip_info info;
1360 if ( this != NULL && clip < this->count )
1362 mlt_playlist_get_clip_info( this, &info, clip );
1363 if ( mlt_playlist_is_blank( this, clip ) )
1364 count += info.frame_count;
1366 bounded = this->count;
1367 for ( clip ++; clip < this->count && bounded >= 0; clip ++ )
1369 mlt_playlist_get_clip_info( this, &info, clip );
1370 if ( mlt_playlist_is_blank( this, clip ) )
1371 count += info.frame_count;
1379 int mlt_playlist_remove_region( mlt_playlist this, mlt_position position, int length )
1381 int index = mlt_playlist_get_clip_index_at( this, position );
1382 if ( index >= 0 && index < this->count )
1384 mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
1385 int clip_start = mlt_playlist_clip_start( this, index );
1386 int clip_length = mlt_playlist_clip_length( this, index );
1387 int list_length = mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1388 mlt_events_block( properties, this );
1390 if ( position + length > list_length )
1391 length -= ( position + length - list_length );
1393 if ( clip_start < position )
1395 mlt_playlist_split( this, index ++, position - clip_start );
1396 clip_length -= position - clip_start;
1401 if ( mlt_playlist_clip_length( this, index ) > length )
1402 mlt_playlist_split( this, index, length );
1403 length -= mlt_playlist_clip_length( this, index );
1404 mlt_playlist_remove( this, index );
1407 mlt_playlist_consolidate_blanks( this, 0 );
1408 mlt_events_unblock( properties, this );
1409 mlt_playlist_virtual_refresh( this );
1411 // Just to be sure, we'll get the clip index again...
1412 index = mlt_playlist_get_clip_index_at( this, position );
1417 int mlt_playlist_move_region( mlt_playlist this, mlt_position position, int length, int new_position )
1425 /** Get the current frame.
1428 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
1430 // Check that we have a producer
1431 if ( producer == NULL )
1433 *frame = mlt_frame_init( );
1437 // Get this mlt_playlist
1438 mlt_playlist this = producer->child;
1440 // Need to ensure the frame is deinterlaced when repeating 1 frame
1441 int progressive = 0;
1443 // Get the real producer
1444 mlt_service real = mlt_playlist_virtual_seek( this, &progressive );
1446 // Check that we have a producer
1449 *frame = mlt_frame_init( );
1454 if ( !mlt_properties_get_int( MLT_SERVICE_PROPERTIES( real ), "meta.fx_cut" ) )
1456 mlt_service_get_frame( real, frame, index );
1460 mlt_producer parent = mlt_producer_cut_parent( ( mlt_producer )real );
1461 *frame = mlt_frame_init( );
1462 mlt_properties_set_int( MLT_FRAME_PROPERTIES( *frame ), "fx_cut", 1 );
1463 mlt_frame_push_service( *frame, NULL );
1464 mlt_frame_push_audio( *frame, NULL );
1465 mlt_service_apply_filters( MLT_PRODUCER_SERVICE( parent ), *frame, 0 );
1466 mlt_service_apply_filters( real, *frame, 0 );
1467 mlt_deque_pop_front( MLT_FRAME_IMAGE_STACK( *frame ) );
1468 mlt_deque_pop_front( MLT_FRAME_AUDIO_STACK( *frame ) );
1471 // Check if we're at the end of the clip
1472 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
1473 if ( mlt_properties_get_int( properties, "end_of_clip" ) )
1474 mlt_playlist_virtual_set_out( this );
1476 // Set the consumer progressive property
1479 mlt_properties_set_int( properties, "consumer_deinterlace", progressive );
1480 mlt_properties_set_int( properties, "test_audio", 1 );
1483 // Check for notifier and call with appropriate argument
1484 mlt_properties playlist_properties = MLT_PRODUCER_PROPERTIES( producer );
1485 void ( *notifier )( void * ) = mlt_properties_get_data( playlist_properties, "notifier", NULL );
1486 if ( notifier != NULL )
1488 void *argument = mlt_properties_get_data( playlist_properties, "notifier_arg", NULL );
1489 notifier( argument );
1492 // Update position on the frame we're creating
1493 mlt_frame_set_position( *frame, mlt_producer_frame( producer ) );
1495 // Position ourselves on the next frame
1496 mlt_producer_prepare_next( producer );
1501 /** Close the playlist.
1504 void mlt_playlist_close( mlt_playlist this )
1506 if ( this != NULL && mlt_properties_dec_ref( MLT_PLAYLIST_PROPERTIES( this ) ) <= 0 )
1509 this->parent.close = NULL;
1510 for ( i = 0; i < this->count; i ++ )
1512 mlt_event_close( this->list[ i ]->event );
1513 mlt_producer_close( this->list[ i ]->producer );
1514 free( this->list[ i ] );
1516 mlt_producer_close( &this->blank );
1517 mlt_producer_close( &this->parent );