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 program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "mlt_playlist.h"
24 #include "mlt_tractor.h"
25 #include "mlt_field.h"
26 #include "mlt_frame.h"
27 #include "mlt_transition.h"
33 /** Virtual playlist entry.
36 typedef struct playlist_entry_s
38 mlt_producer producer;
39 mlt_position frame_in;
40 mlt_position frame_out;
41 mlt_position frame_count;
42 mlt_position producer_length;
46 struct playlist_entry_s *mix_in;
47 struct playlist_entry_s *mix_out;
51 /** Private definition.
56 struct mlt_producer_s parent;
57 struct mlt_producer_s blank;
61 playlist_entry **list;
64 /** Forward declarations
67 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
68 static int mlt_playlist_unmix( mlt_playlist this, int clip );
69 static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out );
74 mlt_playlist mlt_playlist_init( )
76 mlt_playlist this = calloc( sizeof( struct mlt_playlist_s ), 1 );
79 mlt_producer producer = &this->parent;
81 // Construct the producer
82 mlt_producer_init( producer, this );
84 // Override the producer get_frame
85 producer->get_frame = producer_get_frame;
87 // Define the destructor
88 producer->close = ( mlt_destructor )mlt_playlist_close;
89 producer->close_object = this;
92 mlt_producer_init( &this->blank, NULL );
93 mlt_properties_set( mlt_producer_properties( &this->blank ), "mlt_service", "blank" );
94 mlt_properties_set( mlt_producer_properties( &this->blank ), "resource", "blank" );
96 // Indicate that this producer is a playlist
97 mlt_properties_set_data( mlt_playlist_properties( this ), "playlist", this, 0, NULL, NULL );
99 // Specify the eof condition
100 mlt_properties_set( mlt_playlist_properties( this ), "eof", "pause" );
101 mlt_properties_set( mlt_playlist_properties( this ), "resource", "<playlist>" );
102 mlt_properties_set( mlt_playlist_properties( this ), "mlt_type", "mlt_producer" );
103 mlt_properties_set_position( mlt_playlist_properties( this ), "in", 0 );
104 mlt_properties_set_position( mlt_playlist_properties( this ), "out", 0 );
105 mlt_properties_set_position( mlt_playlist_properties( this ), "length", 0 );
108 this->list = malloc( this->size * sizeof( playlist_entry * ) );
114 /** Get the producer associated to this playlist.
117 mlt_producer mlt_playlist_producer( mlt_playlist this )
119 return this != NULL ? &this->parent : NULL;
122 /** Get the service associated to this playlist.
125 mlt_service mlt_playlist_service( mlt_playlist this )
127 return mlt_producer_service( &this->parent );
130 /** Get the propertues associated to this playlist.
133 mlt_properties mlt_playlist_properties( mlt_playlist this )
135 return mlt_producer_properties( &this->parent );
138 /** Refresh the playlist after a clip has been changed.
141 static int mlt_playlist_virtual_refresh( mlt_playlist this )
143 // Obtain the properties
144 mlt_properties properties = mlt_playlist_properties( this );
146 // Get the fps of the first producer
147 double fps = mlt_properties_get_double( properties, "first_fps" );
149 mlt_position frame_count = 0;
151 for ( i = 0; i < this->count; i ++ )
154 mlt_producer producer = this->list[ i ]->producer;
155 int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
160 // Inherit it from the producer
161 fps = mlt_producer_get_fps( producer );
163 else if ( fps != mlt_properties_get_double( mlt_producer_properties( producer ), "fps" ) )
165 // Generate a warning for now - the following attempt to fix may fail
166 fprintf( stderr, "Warning: fps mismatch on playlist producer %d\n", this->count );
168 // It should be safe to impose fps on an image producer, but not necessarily safe for video
169 mlt_properties_set_double( mlt_producer_properties( producer ), "fps", fps );
172 // Check if the length of the producer has changed
173 if ( this->list[ i ]->producer_length != current_length )
175 // This clip should be removed...
176 if ( this->list[ i ]->frame_in > current_length )
178 this->list[ i ]->frame_count = 0;
179 this->list[ i ]->frame_in = 0;
180 this->list[ i ]->frame_out = 0;
182 else if ( this->list[ i ]->frame_out >= current_length )
184 this->list[ i ]->frame_out = current_length - 1;
185 this->list[ i ]->frame_count = this->list[ i ]->frame_out - this->list[ i ]->frame_in + 1;
188 // Update the producer_length
189 this->list[ i ]->producer_length = current_length;
192 // Update the frame_count for this clip
193 frame_count += this->list[ i ]->frame_count;
196 // Refresh all properties
197 mlt_properties_set_double( properties, "first_fps", fps );
198 mlt_properties_set_double( properties, "fps", fps == 0 ? 25 : fps );
199 mlt_events_block( properties, properties );
200 mlt_properties_set_position( properties, "length", frame_count );
201 mlt_events_unblock( properties, properties );
202 mlt_properties_set_position( properties, "out", frame_count - 1 );
207 /** Listener for producers on the playlist.
210 static void mlt_playlist_listener( mlt_producer producer, mlt_playlist this )
212 mlt_playlist_virtual_refresh( this );
215 /** Append to the virtual playlist.
218 static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer producer, mlt_position in, mlt_position out )
220 mlt_properties properties = mlt_producer_properties( producer );
222 // Check that we have room
223 if ( this->count >= this->size )
226 this->list = realloc( this->list, ( this->size + 10 ) * sizeof( playlist_entry * ) );
227 for ( i = this->size; i < this->size + 10; i ++ ) this->list[ i ] = NULL;
231 this->list[ this->count ] = calloc( sizeof( playlist_entry ), 1 );
232 this->list[ this->count ]->producer = producer;
233 this->list[ this->count ]->frame_in = in;
234 this->list[ this->count ]->frame_out = out;
235 this->list[ this->count ]->frame_count = out - in + 1;
236 this->list[ this->count ]->producer_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
237 this->list[ this->count ]->event = mlt_events_listen( properties, this, "producer-changed", ( mlt_listener )mlt_playlist_listener );
238 mlt_event_inc_ref( this->list[ this->count ]->event );
240 mlt_properties_set( properties, "eof", "pause" );
242 mlt_producer_set_speed( producer, 0 );
246 mlt_properties_inc_ref( properties );
248 return mlt_playlist_virtual_refresh( this );
251 /** Seek in the virtual playlist.
254 static mlt_service mlt_playlist_virtual_seek( mlt_playlist this )
256 // Default producer to blank
257 mlt_producer producer = NULL;
259 // Map playlist position to real producer in virtual playlist
260 mlt_position position = mlt_producer_frame( &this->parent );
262 mlt_position original = position;
264 // Total number of frames
267 // Get the properties
268 mlt_properties properties = mlt_playlist_properties( this );
270 // Get the eof handling
271 char *eof = mlt_properties_get( properties, "eof" );
273 // Index for the main loop
276 // Loop for each producer until found
277 for ( i = 0; i < this->count; i ++ )
279 // Increment the total
280 total += this->list[ i ]->frame_count;
282 // Check if the position indicates that we have found the clip
283 if ( position < this->list[ i ]->frame_count )
285 // Found it, now break
286 producer = this->list[ i ]->producer;
291 // Decrement position by length of this entry
292 position -= this->list[ i ]->frame_count;
296 // Seek in real producer to relative position
297 if ( producer != NULL )
299 position += this->list[ i ]->frame_in;
300 mlt_producer_seek( producer, position );
302 else if ( !strcmp( eof, "pause" ) && total > 0 )
304 playlist_entry *entry = this->list[ this->count - 1 ];
305 mlt_producer this_producer = mlt_playlist_producer( this );
306 mlt_producer_seek( this_producer, original - 1 );
307 producer = entry->producer;
308 mlt_producer_seek( producer, entry->frame_out );
309 mlt_producer_set_speed( this_producer, 0 );
310 mlt_producer_set_speed( producer, 0 );
312 else if ( !strcmp( eof, "loop" ) && total > 0 )
314 playlist_entry *entry = this->list[ 0 ];
315 mlt_producer this_producer = mlt_playlist_producer( this );
316 mlt_producer_seek( this_producer, 0 );
317 producer = entry->producer;
318 mlt_producer_seek( producer, entry->frame_in );
322 producer = &this->blank;
325 return mlt_producer_service( producer );
328 /** Invoked when a producer indicates that it has prematurely reached its end.
331 static mlt_producer mlt_playlist_virtual_set_out( mlt_playlist this )
333 // Default producer to blank
334 mlt_producer producer = &this->blank;
336 // Map playlist position to real producer in virtual playlist
337 mlt_position position = mlt_producer_frame( &this->parent );
339 // Loop through the virtual playlist
342 for ( i = 0; i < this->count; i ++ )
344 if ( position < this->list[ i ]->frame_count )
346 // Found it, now break
347 producer = this->list[ i ]->producer;
352 // Decrement position by length of this entry
353 position -= this->list[ i ]->frame_count;
357 // Seek in real producer to relative position
358 if ( i < this->count && this->list[ i ]->frame_out != position )
360 // Update the frame_count for the changed clip (hmmm)
361 this->list[ i ]->frame_out = position;
362 this->list[ i ]->frame_count = this->list[ i ]->frame_out - this->list[ i ]->frame_in + 1;
364 // Refresh the playlist
365 mlt_playlist_virtual_refresh( this );
371 /** Obtain the current clips index.
374 int mlt_playlist_current_clip( mlt_playlist this )
376 // Map playlist position to real producer in virtual playlist
377 mlt_position position = mlt_producer_frame( &this->parent );
379 // Loop through the virtual playlist
382 for ( i = 0; i < this->count; i ++ )
384 if ( position < this->list[ i ]->frame_count )
386 // Found it, now break
391 // Decrement position by length of this entry
392 position -= this->list[ i ]->frame_count;
399 /** Obtain the current clips producer.
402 mlt_producer mlt_playlist_current( mlt_playlist this )
404 int i = mlt_playlist_current_clip( this );
405 if ( i < this->count )
406 return this->list[ i ]->producer;
411 /** Get the position which corresponds to the start of the next clip.
414 mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index )
416 mlt_position position = 0;
417 int absolute_clip = index;
420 // Determine the absolute clip
423 case mlt_whence_relative_start:
424 absolute_clip = index;
427 case mlt_whence_relative_current:
428 absolute_clip = mlt_playlist_current_clip( this ) + index;
431 case mlt_whence_relative_end:
432 absolute_clip = this->count - index;
436 // Check that we're in a valid range
437 if ( absolute_clip < 0 )
439 else if ( absolute_clip > this->count )
440 absolute_clip = this->count;
442 // Now determine the position
443 for ( i = 0; i < absolute_clip; i ++ )
444 position += this->list[ i ]->frame_count;
449 /** Get all the info about the clip specified.
452 int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index )
454 int error = index < 0 || index >= this->count;
455 memset( info, 0, sizeof( mlt_playlist_clip_info ) );
458 mlt_producer producer = this->list[ index ]->producer;
459 mlt_properties properties = mlt_producer_properties( producer );
461 info->producer = producer;
462 info->start = mlt_playlist_clip( this, mlt_whence_relative_start, index );
463 info->resource = mlt_properties_get( properties, "resource" );
464 info->frame_in = this->list[ index ]->frame_in;
465 info->frame_out = this->list[ index ]->frame_out;
466 info->frame_count = this->list[ index ]->frame_count;
467 info->length = mlt_producer_get_length( producer );
468 info->fps = mlt_producer_get_fps( producer );
469 info->event = this->list[ index ]->event;
472 // Determine the consuming filter service
473 if ( info->producer != NULL )
475 info->service = mlt_producer_service( info->producer );
476 while ( mlt_service_consumer( info->service ) != NULL )
477 info->service = mlt_service_consumer( info->service );
483 /** Get number of clips in the playlist.
486 int mlt_playlist_count( mlt_playlist this )
491 /** Clear the playlist.
494 int mlt_playlist_clear( mlt_playlist this )
497 for ( i = 0; i < this->count; i ++ )
499 mlt_event_close( this->list[ i ]->event );
500 mlt_producer_close( this->list[ i ]->producer );
503 mlt_properties_set_double( mlt_playlist_properties( this ), "first_fps", 0 );
504 return mlt_playlist_virtual_refresh( this );
507 /** Append a producer to the playlist.
510 int mlt_playlist_append( mlt_playlist this, mlt_producer producer )
512 // Append to virtual list
513 return mlt_playlist_virtual_append( this, producer, 0, mlt_producer_get_playtime( producer ) - 1 );
516 /** Append a producer to the playlist with in/out points.
519 int mlt_playlist_append_io( mlt_playlist this, mlt_producer producer, mlt_position in, mlt_position out )
521 // Append to virtual list
522 if ( in != -1 && out != -1 )
523 return mlt_playlist_virtual_append( this, producer, in, out );
525 return mlt_playlist_append( this, producer );
528 /** Append a blank to the playlist of a given length.
531 int mlt_playlist_blank( mlt_playlist this, mlt_position length )
533 // Append to the virtual list
534 return mlt_playlist_virtual_append( this, &this->blank, 0, length );
537 /** Insert a producer into the playlist.
540 int mlt_playlist_insert( mlt_playlist this, mlt_producer producer, int where, mlt_position in, mlt_position out )
543 mlt_events_block( mlt_playlist_properties( this ), this );
544 mlt_playlist_append_io( this, producer, in, out );
546 // Move to the position specified
547 mlt_playlist_move( this, this->count - 1, where );
548 mlt_events_unblock( mlt_playlist_properties( this ), this );
550 return mlt_playlist_virtual_refresh( this );
553 /** Remove an entry in the playlist.
556 int mlt_playlist_remove( mlt_playlist this, int where )
558 int error = where < 0 || where >= this->count;
559 if ( error == 0 && mlt_playlist_unmix( this, where ) != 0 )
561 // We need to know the current clip and the position within the playlist
562 int current = mlt_playlist_current_clip( this );
563 mlt_position position = mlt_producer_position( mlt_playlist_producer( this ) );
565 // We need all the details about the clip we're removing
566 mlt_playlist_clip_info where_info;
567 playlist_entry *entry = this->list[ where ];
573 mlt_playlist_get_clip_info( this, &where_info, where );
575 // Make sure the clip to be removed is valid and correct if necessary
578 if ( where >= this->count )
579 where = this->count - 1;
581 // Close the producer associated to the clip info
582 mlt_event_close( entry->event );
583 mlt_producer_close( entry->producer );
584 if ( entry->mix_in != NULL )
585 entry->mix_in->mix_out = NULL;
586 if ( entry->mix_out != NULL )
587 entry->mix_out->mix_in = NULL;
589 // Reorganise the list
590 for ( i = where + 1; i < this->count; i ++ )
591 this->list[ i - 1 ] = this->list[ i ];
595 if ( where == current )
596 mlt_producer_seek( mlt_playlist_producer( this ), where_info.start );
597 else if ( where < current && this->count > 0 )
598 mlt_producer_seek( mlt_playlist_producer( this ), position - where_info.frame_count );
599 else if ( this->count == 0 )
600 mlt_producer_seek( mlt_playlist_producer( this ), 0 );
605 // Refresh the playlist
606 mlt_playlist_virtual_refresh( this );
612 /** Move an entry in the playlist.
615 int mlt_playlist_move( mlt_playlist this, int src, int dest )
619 /* We need to ensure that the requested indexes are valid and correct it as necessary */
622 if ( src >= this->count )
623 src = this->count - 1;
627 if ( dest >= this->count )
628 dest = this->count - 1;
630 if ( src != dest && this->count > 1 )
632 int current = mlt_playlist_current_clip( this );
633 mlt_position position = mlt_producer_position( mlt_playlist_producer( this ) );
634 playlist_entry *src_entry = NULL;
636 // We need all the details about the current clip
637 mlt_playlist_clip_info current_info;
639 mlt_playlist_get_clip_info( this, ¤t_info, current );
640 position -= current_info.start;
642 if ( current == src )
644 else if ( current > src && current < dest )
646 else if ( current == dest )
649 src_entry = this->list[ src ];
652 for ( i = src; i > dest; i -- )
653 this->list[ i ] = this->list[ i - 1 ];
657 for ( i = src; i < dest; i ++ )
658 this->list[ i ] = this->list[ i + 1 ];
660 this->list[ dest ] = src_entry;
662 mlt_playlist_get_clip_info( this, ¤t_info, current );
663 mlt_producer_seek( mlt_playlist_producer( this ), current_info.start + position );
664 mlt_playlist_virtual_refresh( this );
670 /** Resize the current clip.
673 int mlt_playlist_resize_clip( mlt_playlist this, int clip, mlt_position in, mlt_position out )
675 int error = clip < 0 || clip >= this->count;
676 if ( error == 0 && mlt_playlist_resize_mix( this, clip, in, out ) != 0 )
678 playlist_entry *entry = this->list[ clip ];
679 mlt_producer producer = entry->producer;
683 if ( out <= -1 || out >= mlt_producer_get_playtime( producer ) )
684 out = mlt_producer_get_playtime( producer ) - 1;
693 entry->frame_in = in;
694 entry->frame_out = out;
695 entry->frame_count = out - in + 1;
696 mlt_playlist_virtual_refresh( this );
701 /** Split a clip on the playlist at the given position.
704 int mlt_playlist_split( mlt_playlist this, int clip, mlt_position position )
706 int error = clip < 0 || clip >= this->count;
709 playlist_entry *entry = this->list[ clip ];
710 playlist_entry *new_entry = NULL;
711 if ( position > 0 && position < entry->frame_count )
713 int in = entry->frame_in;
714 int out = entry->frame_out;
715 mlt_events_block( mlt_playlist_properties( this ), this );
716 mlt_playlist_resize_clip( this, clip, in, in + position );
717 mlt_playlist_insert( this, entry->producer, clip + 1, in + position + 1, out );
718 new_entry = this->list[ clip + 1 ];
719 new_entry->mix_out = entry->mix_out;
720 new_entry->mix_out_length = entry->mix_out_length;
721 if ( entry->mix_out != NULL )
722 entry->mix_out->mix_in = new_entry;
723 entry->mix_out = NULL;
724 entry->mix_out_length = 0;
725 mlt_events_unblock( mlt_playlist_properties( this ), this );
726 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL );
736 /** Join 1 or more consecutive clips.
739 int mlt_playlist_join( mlt_playlist this, int clip, int count, int merge )
741 int error = clip < 0 || ( clip + 1 ) >= this->count;
745 mlt_playlist new_clip = mlt_playlist_init( );
746 mlt_events_block( mlt_playlist_properties( this ), this );
747 if ( clip + count >= this->count )
748 count = this->count - clip;
749 for ( i = 0; i <= count; i ++ )
751 playlist_entry *entry = this->list[ clip ];
752 mlt_playlist_append_io( new_clip, entry->producer, entry->frame_in, entry->frame_out );
753 mlt_playlist_remove( this, clip );
755 mlt_events_unblock( mlt_playlist_properties( this ), this );
756 mlt_playlist_insert( this, mlt_playlist_producer( new_clip ), clip, 0, -1 );
757 mlt_playlist_close( new_clip );
762 int mlt_playlist_mix( mlt_playlist this, int clip, int length, mlt_transition transition )
764 int error = ( clip < 0 || clip + 1 >= this->count ) && this->list[ clip ]->mix_out != NULL;
767 playlist_entry *mix = NULL;
768 playlist_entry *clip_a = this->list[ clip ];
769 playlist_entry *clip_b = this->list[ clip + 1 ];
770 mlt_tractor tractor = mlt_tractor_new( );
771 mlt_playlist track_a = mlt_playlist_init( );
772 mlt_playlist track_b = mlt_playlist_init( );
773 mlt_properties_set_int( mlt_tractor_properties( tractor ), "mlt_mix", 1 );
774 mlt_events_block( mlt_playlist_properties( this ), this );
775 mlt_playlist_resize_clip( this, clip, clip_a->frame_in, clip_a->frame_out - length );
776 mlt_playlist_resize_clip( this, clip + 1, clip_b->frame_in + length, clip_b->frame_out );
777 mlt_tractor_set_track( tractor, mlt_playlist_producer( track_a ), 0 );
778 mlt_tractor_set_track( tractor, mlt_playlist_producer( track_b ), 1 );
779 mlt_playlist_append_io( track_a, clip_a->producer, clip_a->frame_out + 1, clip_a->frame_out + length );
780 mlt_playlist_append_io( track_b, clip_b->producer, clip_b->frame_in - length, clip_b->frame_in - 1 );
781 mlt_playlist_insert( this, mlt_tractor_producer( tractor ), clip + 1, -1, -1 );
783 // Store mix info so that we can manipulate clips on either side
784 mix = this->list[ clip + 1 ];
785 mix->mix_in = clip_a;
786 mix->mix_out = clip_b;
787 mix->mix_out_length = length;
788 mix->mix_in_length = length;
789 clip_a->mix_out = mix;
790 clip_a->mix_out_length = length;
791 clip_b->mix_in = mix;
792 clip_b->mix_in_length = length;
794 if ( transition != NULL )
796 mlt_field field = mlt_tractor_field( tractor );
797 mlt_field_plant_transition( field, transition, 0, 1 );
798 mlt_transition_set_in_and_out( transition, 0, length - 1 );
800 mlt_events_unblock( mlt_playlist_properties( this ), this );
801 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL );
802 mlt_playlist_close( track_a );
803 mlt_playlist_close( track_b );
804 mlt_tractor_close( tractor );
809 static int mlt_playlist_unmix( mlt_playlist this, int clip )
811 int error = ( clip < 0 || clip >= this->count );
813 // Ensure that the clip request is actually a mix
816 mlt_producer producer = this->list[ clip ]->producer;
817 mlt_properties properties = mlt_producer_properties( producer );
818 error = !mlt_properties_get_int( properties, "mlt_mix" );
823 playlist_entry *mix = this->list[ clip ];
824 playlist_entry *clip_a = mix->mix_in;
825 playlist_entry *clip_b = mix->mix_out;
826 int length = mix->mix_in_length;
827 mlt_events_block( mlt_playlist_properties( this ), this );
829 if ( clip_a != NULL )
831 clip_a->frame_out += length;
832 clip_a->frame_count += length;
833 clip_a->mix_out = NULL;
834 clip_a->mix_out_length = 0;
837 if ( clip_b != NULL )
839 clip_b->frame_in -= length;
840 clip_b->frame_count += length;
841 clip_b->mix_in = NULL;
842 clip_b->mix_in_length = 0;
845 mlt_properties_set_int( mlt_producer_properties( mix->producer ), "mlt_mix", 0 );
846 mlt_playlist_remove( this, clip );
847 mlt_events_unblock( mlt_playlist_properties( this ), this );
848 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL );
853 static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out )
855 int error = ( clip < 0 || clip >= this->count );
857 // Ensure that the clip request is actually a mix
860 mlt_producer producer = this->list[ clip ]->producer;
861 mlt_properties properties = mlt_producer_properties( producer );
862 error = !mlt_properties_get_int( properties, "mlt_mix" );
867 playlist_entry *mix = this->list[ clip ];
868 playlist_entry *clip_a = mix->mix_in;
869 playlist_entry *clip_b = mix->mix_out;
870 int length = out - in + 1;
871 int length_diff = length - mix->mix_in_length;
872 mlt_events_block( mlt_playlist_properties( this ), this );
874 if ( clip_a != NULL )
876 clip_a->frame_out -= length_diff;
877 clip_a->frame_count -= length_diff;
878 clip_a->mix_out_length -= length_diff;
881 if ( clip_b != NULL )
883 clip_b->frame_in += length_diff;
884 clip_b->frame_count -= length_diff;
885 clip_b->mix_in_length -= length_diff;
889 mix->frame_out = length - 1;
890 mix->frame_count = length;
891 mix->mix_in_length = length;
892 mix->mix_out_length = length;
894 mlt_events_unblock( mlt_playlist_properties( this ), this );
895 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL );
900 /** Get the current frame.
903 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
905 // Get this mlt_playlist
906 mlt_playlist this = producer->child;
908 // Get the real producer
909 mlt_service real = mlt_playlist_virtual_seek( this );
912 mlt_service_get_frame( real, frame, index );
914 // Check if we're at the end of the clip
915 mlt_properties properties = mlt_frame_properties( *frame );
916 if ( mlt_properties_get_int( properties, "end_of_clip" ) )
917 mlt_playlist_virtual_set_out( this );
919 // Check for notifier and call with appropriate argument
920 mlt_properties playlist_properties = mlt_producer_properties( producer );
921 void ( *notifier )( void * ) = mlt_properties_get_data( playlist_properties, "notifier", NULL );
922 if ( notifier != NULL )
924 void *argument = mlt_properties_get_data( playlist_properties, "notifier_arg", NULL );
925 notifier( argument );
928 // Update position on the frame we're creating
929 mlt_frame_set_position( *frame, mlt_producer_frame( producer ) );
931 // Position ourselves on the next frame
932 mlt_producer_prepare_next( producer );
937 /** Close the playlist.
940 void mlt_playlist_close( mlt_playlist this )
942 if ( this != NULL && mlt_properties_dec_ref( mlt_playlist_properties( this ) ) <= 0 )
945 this->parent.close = NULL;
946 for ( i = 0; i < this->count; i ++ )
948 mlt_event_close( this->list[ i ]->event );
949 mlt_producer_close( this->list[ i ]->producer );
950 free( this->list[ i ] );
952 mlt_producer_close( &this->blank );
953 mlt_producer_close( &this->parent );