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
21 #include "mlt_playlist.h"
22 #include "mlt_tractor.h"
23 #include "mlt_multitrack.h"
24 #include "mlt_field.h"
25 #include "mlt_frame.h"
26 #include "mlt_transition.h"
32 /** Virtual playlist entry.
35 struct playlist_entry_s
37 mlt_producer producer
;
38 mlt_position frame_in
;
39 mlt_position frame_out
;
40 mlt_position frame_count
;
42 mlt_position producer_length
;
44 int preservation_hack
;
47 /** Forward declarations
50 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
);
51 static int mlt_playlist_unmix( mlt_playlist
this, int clip
);
52 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
);
57 mlt_playlist
mlt_playlist_init( )
59 mlt_playlist
this = calloc( sizeof( struct mlt_playlist_s
), 1 );
62 mlt_producer producer
= &this->parent
;
64 // Construct the producer
65 mlt_producer_init( producer
, this );
67 // Override the producer get_frame
68 producer
->get_frame
= producer_get_frame
;
70 // Define the destructor
71 producer
->close
= ( mlt_destructor
)mlt_playlist_close
;
72 producer
->close_object
= this;
75 mlt_producer_init( &this->blank
, NULL
);
76 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank
), "mlt_service", "blank" );
77 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank
), "resource", "blank" );
79 // Indicate that this producer is a playlist
80 mlt_properties_set_data( MLT_PLAYLIST_PROPERTIES( this ), "playlist", this, 0, NULL
, NULL
);
82 // Specify the eof condition
83 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "eof", "pause" );
84 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "resource", "<playlist>" );
85 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "mlt_type", "mlt_producer" );
86 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "in", 0 );
87 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "out", -1 );
88 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "length", 0 );
91 this->list
= malloc( this->size
* sizeof( playlist_entry
* ) );
97 /** Get the producer associated to this playlist.
100 mlt_producer
mlt_playlist_producer( mlt_playlist
this )
102 return this != NULL ?
&this->parent
: NULL
;
105 /** Get the service associated to this playlist.
108 mlt_service
mlt_playlist_service( mlt_playlist
this )
110 return MLT_PRODUCER_SERVICE( &this->parent
);
113 /** Get the propertues associated to this playlist.
116 mlt_properties
mlt_playlist_properties( mlt_playlist
this )
118 return MLT_PRODUCER_PROPERTIES( &this->parent
);
121 /** Refresh the playlist after a clip has been changed.
124 static int mlt_playlist_virtual_refresh( mlt_playlist
this )
126 // Obtain the properties
127 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
129 mlt_position frame_count
= 0;
131 for ( i
= 0; i
< this->count
; i
++ )
134 mlt_producer producer
= this->list
[ i
]->producer
;
137 int current_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
139 // Check if the length of the producer has changed
140 if ( this->list
[ i
]->frame_in
!= mlt_producer_get_in( producer
) ||
141 this->list
[ i
]->frame_out
!= mlt_producer_get_out( producer
) )
143 // This clip should be removed...
144 if ( current_length
< 1 )
146 this->list
[ i
]->frame_in
= 0;
147 this->list
[ i
]->frame_out
= -1;
148 this->list
[ i
]->frame_count
= 0;
152 this->list
[ i
]->frame_in
= mlt_producer_get_in( producer
);
153 this->list
[ i
]->frame_out
= mlt_producer_get_out( producer
);
154 this->list
[ i
]->frame_count
= current_length
;
157 // Update the producer_length
158 this->list
[ i
]->producer_length
= current_length
;
162 // Calculate the frame_count
163 this->list
[ i
]->frame_count
= ( this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1 ) * this->list
[ i
]->repeat
;
165 // Update the frame_count for this clip
166 frame_count
+= this->list
[ i
]->frame_count
;
169 // Refresh all properties
170 mlt_events_block( properties
, properties
);
171 mlt_properties_set_position( properties
, "length", frame_count
);
172 mlt_events_unblock( properties
, properties
);
173 mlt_properties_set_position( properties
, "out", frame_count
- 1 );
178 /** Listener for producers on the playlist.
181 static void mlt_playlist_listener( mlt_producer producer
, mlt_playlist
this )
183 mlt_playlist_virtual_refresh( this );
186 /** Append to the virtual playlist.
189 static int mlt_playlist_virtual_append( mlt_playlist
this, mlt_producer source
, mlt_position in
, mlt_position out
)
191 mlt_producer producer
= NULL
;
192 mlt_properties properties
= NULL
;
193 mlt_properties parent
= NULL
;
195 // If we have a cut, then use the in/out points from the cut
196 if ( mlt_producer_is_blank( source
) )
198 // Make sure the blank is long enough to accomodate the length specified
199 if ( out
- in
+ 1 > mlt_producer_get_length( &this->blank
) )
201 mlt_properties blank_props
= MLT_PRODUCER_PROPERTIES( &this->blank
);
202 mlt_events_block( blank_props
, blank_props
);
203 mlt_producer_set_in_and_out( &this->blank
, in
, out
);
204 mlt_events_unblock( blank_props
, blank_props
);
207 // Now make sure the cut comes from this this->blank
208 if ( source
== NULL
)
210 producer
= mlt_producer_cut( &this->blank
, in
, out
);
212 else if ( !mlt_producer_is_cut( source
) || mlt_producer_cut_parent( source
) != &this->blank
)
214 producer
= mlt_producer_cut( &this->blank
, in
, out
);
219 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer
) );
222 properties
= MLT_PRODUCER_PROPERTIES( producer
);
224 else if ( mlt_producer_is_cut( source
) )
228 in
= mlt_producer_get_in( producer
);
229 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
230 out
= mlt_producer_get_out( producer
);
231 properties
= MLT_PRODUCER_PROPERTIES( producer
);
232 mlt_properties_inc_ref( properties
);
236 producer
= mlt_producer_cut( source
, in
, out
);
237 if ( in
== -1 || in
< mlt_producer_get_in( producer
) )
238 in
= mlt_producer_get_in( producer
);
239 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
240 out
= mlt_producer_get_out( producer
);
241 properties
= MLT_PRODUCER_PROPERTIES( producer
);
244 // Fetch the cuts parent properties
245 parent
= MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( producer
) );
247 // Remove fezzik normalisers for fx cuts
248 if ( mlt_properties_get_int( parent
, "meta.fx_cut" ) )
250 mlt_service service
= MLT_PRODUCER_SERVICE( mlt_producer_cut_parent( producer
) );
251 mlt_filter filter
= mlt_service_filter( service
, 0 );
252 while ( filter
!= NULL
&& mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "_fezzik" ) )
254 mlt_service_detach( service
, filter
);
255 filter
= mlt_service_filter( service
, 0 );
257 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer
), "meta.fx_cut", 1 );
260 // Check that we have room
261 if ( this->count
>= this->size
)
264 this->list
= realloc( this->list
, ( this->size
+ 10 ) * sizeof( playlist_entry
* ) );
265 for ( i
= this->size
; i
< this->size
+ 10; i
++ ) this->list
[ i
] = NULL
;
270 this->list
[ this->count
] = calloc( sizeof( playlist_entry
), 1 );
271 if ( this->list
[ this->count
] != NULL
)
273 this->list
[ this->count
]->producer
= producer
;
274 this->list
[ this->count
]->frame_in
= in
;
275 this->list
[ this->count
]->frame_out
= out
;
276 this->list
[ this->count
]->frame_count
= out
- in
+ 1;
277 this->list
[ this->count
]->repeat
= 1;
278 this->list
[ this->count
]->producer_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
279 this->list
[ this->count
]->event
= mlt_events_listen( parent
, this, "producer-changed", ( mlt_listener
)mlt_playlist_listener
);
280 mlt_event_inc_ref( this->list
[ this->count
]->event
);
281 mlt_properties_set( properties
, "eof", "pause" );
282 mlt_producer_set_speed( producer
, 0 );
286 return mlt_playlist_virtual_refresh( this );
289 static mlt_producer
mlt_playlist_locate( mlt_playlist
this, mlt_position
*position
, int *clip
, int *total
)
291 // Default producer to NULL
292 mlt_producer producer
= NULL
;
294 // Loop for each producer until found
295 for ( *clip
= 0; *clip
< this->count
; *clip
+= 1 )
297 // Increment the total
298 *total
+= this->list
[ *clip
]->frame_count
;
300 // Check if the position indicates that we have found the clip
301 // Note that 0 length clips get skipped automatically
302 if ( *position
< this->list
[ *clip
]->frame_count
)
304 // Found it, now break
305 producer
= this->list
[ *clip
]->producer
;
310 // Decrement position by length of this entry
311 *position
-= this->list
[ *clip
]->frame_count
;
318 /** Seek in the virtual playlist.
321 static mlt_service
mlt_playlist_virtual_seek( mlt_playlist
this, int *progressive
)
323 // Map playlist position to real producer in virtual playlist
324 mlt_position position
= mlt_producer_frame( &this->parent
);
326 // Keep the original position since we change it while iterating through the list
327 mlt_position original
= position
;
329 // Clip index and total
333 // Locate the producer for the position
334 mlt_producer producer
= mlt_playlist_locate( this, &position
, &i
, &total
);
336 // Get the properties
337 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
339 // Automatically close previous producers if requested
340 if ( i
> 1 // keep immediate previous in case app wants to get info about what just finished
341 && position
< 2 // tolerate off-by-one error on going to next clip
342 && mlt_properties_get_int( properties
, "autoclose" ) )
345 // They might have jumped ahead!
346 for ( j
= 0; j
< i
- 1; j
++ )
348 mlt_service_lock( MLT_PRODUCER_SERVICE( this->list
[ j
]->producer
) );
349 mlt_producer p
= this->list
[ j
]->producer
;
352 this->list
[ j
]->producer
= NULL
;
353 mlt_service_unlock( MLT_PRODUCER_SERVICE( p
) );
354 mlt_producer_close( p
);
356 // If p is null, the lock will not have been "taken"
360 // Get the eof handling
361 char *eof
= mlt_properties_get( properties
, "eof" );
363 // Seek in real producer to relative position
364 if ( producer
!= NULL
)
366 int count
= this->list
[ i
]->frame_count
/ this->list
[ i
]->repeat
;
367 *progressive
= count
== 1;
368 mlt_producer_seek( producer
, (int)position
% count
);
370 else if ( !strcmp( eof
, "pause" ) && total
> 0 )
372 playlist_entry
*entry
= this->list
[ this->count
- 1 ];
373 int count
= entry
->frame_count
/ entry
->repeat
;
374 mlt_producer this_producer
= MLT_PLAYLIST_PRODUCER( this );
375 mlt_producer_seek( this_producer
, original
- 1 );
376 producer
= entry
->producer
;
377 mlt_producer_seek( producer
, (int)entry
->frame_out
% count
);
378 mlt_producer_set_speed( this_producer
, 0 );
379 mlt_producer_set_speed( producer
, 0 );
380 *progressive
= count
== 1;
382 else if ( !strcmp( eof
, "loop" ) && total
> 0 )
384 playlist_entry
*entry
= this->list
[ 0 ];
385 mlt_producer this_producer
= MLT_PLAYLIST_PRODUCER( this );
386 mlt_producer_seek( this_producer
, 0 );
387 producer
= entry
->producer
;
388 mlt_producer_seek( producer
, 0 );
392 producer
= &this->blank
;
395 return MLT_PRODUCER_SERVICE( producer
);
398 /** Invoked when a producer indicates that it has prematurely reached its end.
401 static mlt_producer
mlt_playlist_virtual_set_out( mlt_playlist
this )
403 // Default producer to blank
404 mlt_producer producer
= &this->blank
;
406 // Map playlist position to real producer in virtual playlist
407 mlt_position position
= mlt_producer_frame( &this->parent
);
409 // Loop through the virtual playlist
412 for ( i
= 0; i
< this->count
; i
++ )
414 if ( position
< this->list
[ i
]->frame_count
)
416 // Found it, now break
417 producer
= this->list
[ i
]->producer
;
422 // Decrement position by length of this entry
423 position
-= this->list
[ i
]->frame_count
;
427 // Seek in real producer to relative position
428 if ( i
< this->count
&& this->list
[ i
]->frame_out
!= position
)
430 // Update the frame_count for the changed clip (hmmm)
431 this->list
[ i
]->frame_out
= position
;
432 this->list
[ i
]->frame_count
= this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1;
434 // Refresh the playlist
435 mlt_playlist_virtual_refresh( this );
441 /** Obtain the current clips index.
444 int mlt_playlist_current_clip( mlt_playlist
this )
446 // Map playlist position to real producer in virtual playlist
447 mlt_position position
= mlt_producer_frame( &this->parent
);
449 // Loop through the virtual playlist
452 for ( i
= 0; i
< this->count
; i
++ )
454 if ( position
< this->list
[ i
]->frame_count
)
456 // Found it, now break
461 // Decrement position by length of this entry
462 position
-= this->list
[ i
]->frame_count
;
469 /** Obtain the current clips producer.
472 mlt_producer
mlt_playlist_current( mlt_playlist
this )
474 int i
= mlt_playlist_current_clip( this );
475 if ( i
< this->count
)
476 return this->list
[ i
]->producer
;
481 /** Get the position which corresponds to the start of the next clip.
484 mlt_position
mlt_playlist_clip( mlt_playlist
this, mlt_whence whence
, int index
)
486 mlt_position position
= 0;
487 int absolute_clip
= index
;
490 // Determine the absolute clip
493 case mlt_whence_relative_start
:
494 absolute_clip
= index
;
497 case mlt_whence_relative_current
:
498 absolute_clip
= mlt_playlist_current_clip( this ) + index
;
501 case mlt_whence_relative_end
:
502 absolute_clip
= this->count
- index
;
506 // Check that we're in a valid range
507 if ( absolute_clip
< 0 )
509 else if ( absolute_clip
> this->count
)
510 absolute_clip
= this->count
;
512 // Now determine the position
513 for ( i
= 0; i
< absolute_clip
; i
++ )
514 position
+= this->list
[ i
]->frame_count
;
519 /** Get all the info about the clip specified.
522 int mlt_playlist_get_clip_info( mlt_playlist
this, mlt_playlist_clip_info
*info
, int index
)
524 int error
= index
< 0 || index
>= this->count
|| this->list
[ index
]->producer
== NULL
;
525 memset( info
, 0, sizeof( mlt_playlist_clip_info
) );
528 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ index
]->producer
);
529 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
531 info
->producer
= producer
;
532 info
->cut
= this->list
[ index
]->producer
;
533 info
->start
= mlt_playlist_clip( this, mlt_whence_relative_start
, index
);
534 info
->resource
= mlt_properties_get( properties
, "resource" );
535 info
->frame_in
= this->list
[ index
]->frame_in
;
536 info
->frame_out
= this->list
[ index
]->frame_out
;
537 info
->frame_count
= this->list
[ index
]->frame_count
;
538 info
->repeat
= this->list
[ index
]->repeat
;
539 info
->length
= mlt_producer_get_length( producer
);
540 info
->fps
= mlt_producer_get_fps( producer
);
546 /** Get number of clips in the playlist.
549 int mlt_playlist_count( mlt_playlist
this )
554 /** Clear the playlist.
557 int mlt_playlist_clear( mlt_playlist
this )
560 for ( i
= 0; i
< this->count
; i
++ )
562 mlt_event_close( this->list
[ i
]->event
);
563 mlt_producer_close( this->list
[ i
]->producer
);
566 return mlt_playlist_virtual_refresh( this );
569 /** Append a producer to the playlist.
572 int mlt_playlist_append( mlt_playlist
this, mlt_producer producer
)
574 // Append to virtual list
575 return mlt_playlist_virtual_append( this, producer
, 0, mlt_producer_get_playtime( producer
) - 1 );
578 /** Append a producer to the playlist with in/out points.
581 int mlt_playlist_append_io( mlt_playlist
this, mlt_producer producer
, mlt_position in
, mlt_position out
)
583 // Append to virtual list
584 if ( in
!= -1 && out
!= -1 )
585 return mlt_playlist_virtual_append( this, producer
, in
, out
);
587 return mlt_playlist_append( this, producer
);
590 /** Append a blank to the playlist of a given length.
593 int mlt_playlist_blank( mlt_playlist
this, mlt_position length
)
595 // Append to the virtual list
597 return mlt_playlist_virtual_append( this, &this->blank
, 0, length
);
602 /** Insert a producer into the playlist.
605 int mlt_playlist_insert( mlt_playlist
this, mlt_producer producer
, int where
, mlt_position in
, mlt_position out
)
608 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
609 mlt_playlist_append_io( this, producer
, in
, out
);
611 // Move to the position specified
612 mlt_playlist_move( this, this->count
- 1, where
);
613 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
615 return mlt_playlist_virtual_refresh( this );
618 /** Remove an entry in the playlist.
621 int mlt_playlist_remove( mlt_playlist
this, int where
)
623 int error
= where
< 0 || where
>= this->count
;
624 if ( error
== 0 && mlt_playlist_unmix( this, where
) != 0 )
626 // We need to know the current clip and the position within the playlist
627 int current
= mlt_playlist_current_clip( this );
628 mlt_position position
= mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
630 // We need all the details about the clip we're removing
631 mlt_playlist_clip_info where_info
;
632 playlist_entry
*entry
= this->list
[ where
];
633 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( entry
->producer
);
639 mlt_playlist_get_clip_info( this, &where_info
, where
);
641 // Make sure the clip to be removed is valid and correct if necessary
644 if ( where
>= this->count
)
645 where
= this->count
- 1;
647 // Reorganise the list
648 for ( i
= where
+ 1; i
< this->count
; i
++ )
649 this->list
[ i
- 1 ] = this->list
[ i
];
652 if ( entry
->preservation_hack
== 0 )
654 // Decouple from mix_in/out if necessary
655 if ( mlt_properties_get_data( properties
, "mix_in", NULL
) != NULL
)
657 mlt_properties mix
= mlt_properties_get_data( properties
, "mix_in", NULL
);
658 mlt_properties_set_data( mix
, "mix_out", NULL
, 0, NULL
, NULL
);
660 if ( mlt_properties_get_data( properties
, "mix_out", NULL
) != NULL
)
662 mlt_properties mix
= mlt_properties_get_data( properties
, "mix_out", NULL
);
663 mlt_properties_set_data( mix
, "mix_in", NULL
, 0, NULL
, NULL
);
666 if ( mlt_properties_ref_count( MLT_PRODUCER_PROPERTIES( entry
->producer
) ) == 1 )
667 mlt_producer_clear( entry
->producer
);
670 // Close the producer associated to the clip info
671 mlt_event_close( entry
->event
);
672 mlt_producer_close( entry
->producer
);
675 if ( where
== current
)
676 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), where_info
.start
);
677 else if ( where
< current
&& this->count
> 0 )
678 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), position
- where_info
.frame_count
);
679 else if ( this->count
== 0 )
680 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), 0 );
685 // Refresh the playlist
686 mlt_playlist_virtual_refresh( this );
692 /** Move an entry in the playlist.
695 int mlt_playlist_move( mlt_playlist
this, int src
, int dest
)
699 /* We need to ensure that the requested indexes are valid and correct it as necessary */
702 if ( src
>= this->count
)
703 src
= this->count
- 1;
707 if ( dest
>= this->count
)
708 dest
= this->count
- 1;
710 if ( src
!= dest
&& this->count
> 1 )
712 int current
= mlt_playlist_current_clip( this );
713 mlt_position position
= mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
714 playlist_entry
*src_entry
= NULL
;
716 // We need all the details about the current clip
717 mlt_playlist_clip_info current_info
;
719 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
720 position
-= current_info
.start
;
722 if ( current
== src
)
724 else if ( current
> src
&& current
< dest
)
726 else if ( current
== dest
)
729 src_entry
= this->list
[ src
];
732 for ( i
= src
; i
> dest
; i
-- )
733 this->list
[ i
] = this->list
[ i
- 1 ];
737 for ( i
= src
; i
< dest
; i
++ )
738 this->list
[ i
] = this->list
[ i
+ 1 ];
740 this->list
[ dest
] = src_entry
;
742 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
743 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), current_info
.start
+ position
);
744 mlt_playlist_virtual_refresh( this );
750 /** Repeat the specified clip n times.
753 int mlt_playlist_repeat_clip( mlt_playlist
this, int clip
, int repeat
)
755 int error
= repeat
< 1 || clip
< 0 || clip
>= this->count
;
758 playlist_entry
*entry
= this->list
[ clip
];
759 entry
->repeat
= repeat
;
760 mlt_playlist_virtual_refresh( this );
765 /** Resize the specified clip.
768 int mlt_playlist_resize_clip( mlt_playlist
this, int clip
, mlt_position in
, mlt_position out
)
770 int error
= clip
< 0 || clip
>= this->count
;
771 if ( error
== 0 && mlt_playlist_resize_mix( this, clip
, in
, out
) != 0 )
773 playlist_entry
*entry
= this->list
[ clip
];
774 mlt_producer producer
= entry
->producer
;
775 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
777 mlt_events_block( properties
, properties
);
779 if ( mlt_producer_is_blank( producer
) )
781 // Make sure the blank is long enough to accomodate the length specified
782 if ( out
- in
+ 1 > mlt_producer_get_length( &this->blank
) )
784 mlt_properties blank_props
= MLT_PRODUCER_PROPERTIES( &this->blank
);
785 mlt_properties_set_int( blank_props
, "length", out
- in
+ 1 );
786 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer
), "length", out
- in
+ 1 );
787 mlt_producer_set_in_and_out( &this->blank
, 0, out
- in
);
793 if ( out
<= -1 || out
>= mlt_producer_get_length( producer
) )
794 out
= mlt_producer_get_length( producer
) - 1;
803 mlt_producer_set_in_and_out( producer
, in
, out
);
804 mlt_events_unblock( properties
, properties
);
805 mlt_playlist_virtual_refresh( this );
810 /** Split a clip on the playlist at the given position.
813 int mlt_playlist_split( mlt_playlist
this, int clip
, mlt_position position
)
815 int error
= clip
< 0 || clip
>= this->count
;
818 playlist_entry
*entry
= this->list
[ clip
];
819 position
= position
< 0 ? entry
->frame_count
+ position
- 1 : position
;
820 if ( position
>= 0 && position
< entry
->frame_count
- 1 )
822 int in
= entry
->frame_in
;
823 int out
= entry
->frame_out
;
824 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
825 mlt_playlist_resize_clip( this, clip
, in
, in
+ position
);
826 if ( !mlt_producer_is_blank( entry
->producer
) )
829 mlt_properties entry_properties
= MLT_PRODUCER_PROPERTIES( entry
->producer
);
830 mlt_producer split
= mlt_producer_cut( entry
->producer
, in
+ position
+ 1, out
);
831 mlt_properties split_properties
= MLT_PRODUCER_PROPERTIES( split
);
832 mlt_playlist_insert( this, split
, clip
+ 1, 0, -1 );
833 for ( i
= 0; i
< mlt_properties_count( entry_properties
); i
++ )
835 char *name
= mlt_properties_get_name( entry_properties
, i
);
836 if ( name
!= NULL
&& !strncmp( name
, "meta.", 5 ) )
837 mlt_properties_set( split_properties
, name
, mlt_properties_get_value( entry_properties
, i
) );
839 mlt_producer_close( split
);
843 mlt_playlist_insert( this, &this->blank
, clip
+ 1, 0, out
- position
- 1 );
845 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
846 mlt_playlist_virtual_refresh( this );
856 /** Split the playlist at the absolute position.
859 int mlt_playlist_split_at( mlt_playlist
this, mlt_position position
, int left
)
861 int result
= this == NULL ?
-1 : 0;
864 if ( position
>= 0 && position
< mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) ) )
866 int clip
= mlt_playlist_get_clip_index_at( this, position
);
867 mlt_playlist_clip_info info
;
868 mlt_playlist_get_clip_info( this, &info
, clip
);
869 if ( left
&& position
!= info
.start
)
870 mlt_playlist_split( this, clip
, position
- info
.start
- 1 );
872 mlt_playlist_split( this, clip
, position
- info
.start
);
875 else if ( position
<= 0 )
881 result
= mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
887 /** Join 1 or more consecutive clips.
890 int mlt_playlist_join( mlt_playlist
this, int clip
, int count
, int merge
)
892 int error
= clip
< 0 || clip
>= this->count
;
896 mlt_playlist new_clip
= mlt_playlist_init( );
897 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
898 if ( clip
+ count
>= this->count
)
899 count
= this->count
- clip
- 1;
900 for ( i
= 0; i
<= count
; i
++ )
902 playlist_entry
*entry
= this->list
[ clip
];
903 mlt_playlist_append( new_clip
, entry
->producer
);
904 mlt_playlist_repeat_clip( new_clip
, i
, entry
->repeat
);
905 entry
->preservation_hack
= 1;
906 mlt_playlist_remove( this, clip
);
908 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
909 mlt_playlist_insert( this, MLT_PLAYLIST_PRODUCER( new_clip
), clip
, 0, -1 );
910 mlt_playlist_close( new_clip
);
915 /** Mix consecutive clips for a specified length and apply transition if specified.
918 int mlt_playlist_mix( mlt_playlist
this, int clip
, int length
, mlt_transition transition
)
920 int error
= ( clip
< 0 || clip
+ 1 >= this->count
);
923 playlist_entry
*clip_a
= this->list
[ clip
];
924 playlist_entry
*clip_b
= this->list
[ clip
+ 1 ];
925 mlt_producer track_a
= NULL
;
926 mlt_producer track_b
= NULL
;
927 mlt_tractor tractor
= mlt_tractor_new( );
928 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
930 // Check length is valid for both clips and resize if necessary.
931 int max_size
= clip_a
->frame_count
> clip_b
->frame_count ? clip_a
->frame_count
: clip_b
->frame_count
;
932 length
= length
> max_size ? max_size
: length
;
934 // Create the a and b tracks/cuts if necessary - note that no cuts are required if the length matches
935 if ( length
!= clip_a
->frame_count
)
936 track_a
= mlt_producer_cut( clip_a
->producer
, clip_a
->frame_out
- length
+ 1, clip_a
->frame_out
);
938 track_a
= clip_a
->producer
;
940 if ( length
!= clip_b
->frame_count
)
941 track_b
= mlt_producer_cut( clip_b
->producer
, clip_b
->frame_in
, clip_b
->frame_in
+ length
- 1 );
943 track_b
= clip_b
->producer
;
945 // Set the tracks on the tractor
946 mlt_tractor_set_track( tractor
, track_a
, 0 );
947 mlt_tractor_set_track( tractor
, track_b
, 1 );
949 // Insert the mix object into the playlist
950 mlt_playlist_insert( this, MLT_TRACTOR_PRODUCER( tractor
), clip
+ 1, -1, -1 );
951 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mlt_mix", tractor
, 0, NULL
, NULL
);
953 // Attach the transition
954 if ( transition
!= NULL
)
956 mlt_field field
= mlt_tractor_field( tractor
);
957 mlt_field_plant_transition( field
, transition
, 0, 1 );
958 mlt_transition_set_in_and_out( transition
, 0, length
- 1 );
961 // Close our references to the tracks if we created new cuts above (the tracks can still be used here)
962 if ( track_a
!= clip_a
->producer
)
963 mlt_producer_close( track_a
);
964 if ( track_b
!= clip_b
->producer
)
965 mlt_producer_close( track_b
);
967 // Check if we have anything left on the right hand clip
968 if ( track_b
== clip_b
->producer
)
970 clip_b
->preservation_hack
= 1;
971 mlt_playlist_remove( this, clip
+ 2 );
973 else if ( clip_b
->frame_out
- clip_b
->frame_in
> length
)
975 mlt_playlist_resize_clip( this, clip
+ 2, clip_b
->frame_in
+ length
, clip_b
->frame_out
);
976 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_b
->producer
), "mix_in", tractor
, 0, NULL
, NULL
);
977 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mix_out", clip_b
->producer
, 0, NULL
, NULL
);
981 mlt_producer_clear( clip_b
->producer
);
982 mlt_playlist_remove( this, clip
+ 2 );
985 // Check if we have anything left on the left hand clip
986 if ( track_a
== clip_a
->producer
)
988 clip_a
->preservation_hack
= 1;
989 mlt_playlist_remove( this, clip
);
991 else if ( clip_a
->frame_out
- clip_a
->frame_in
> length
)
993 mlt_playlist_resize_clip( this, clip
, clip_a
->frame_in
, clip_a
->frame_out
- length
);
994 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_a
->producer
), "mix_out", tractor
, 0, NULL
, NULL
);
995 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mix_in", clip_a
->producer
, 0, NULL
, NULL
);
999 mlt_producer_clear( clip_a
->producer
);
1000 mlt_playlist_remove( this, clip
);
1003 // Unblock and force a fire off of change events to listeners
1004 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1005 mlt_playlist_virtual_refresh( this );
1006 mlt_tractor_close( tractor
);
1011 /** Add a transition to an existing mix.
1014 int mlt_playlist_mix_add( mlt_playlist
this, int clip
, mlt_transition transition
)
1016 mlt_producer producer
= mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip
) );
1017 mlt_properties properties
= producer
!= NULL ?
MLT_PRODUCER_PROPERTIES( producer
) : NULL
;
1018 mlt_tractor tractor
= properties
!= NULL ?
mlt_properties_get_data( properties
, "mlt_mix", NULL
) : NULL
;
1019 int error
= transition
== NULL
|| tractor
== NULL
;
1022 mlt_field field
= mlt_tractor_field( tractor
);
1023 mlt_field_plant_transition( field
, transition
, 0, 1 );
1024 mlt_transition_set_in_and_out( transition
, 0, this->list
[ clip
]->frame_count
- 1 );
1029 /** Return the clip at the clip index.
1032 mlt_producer
mlt_playlist_get_clip( mlt_playlist
this, int clip
)
1034 if ( clip
>= 0 && clip
< this->count
)
1035 return this->list
[ clip
]->producer
;
1039 /** Return the clip at the specified position.
1042 mlt_producer
mlt_playlist_get_clip_at( mlt_playlist
this, mlt_position position
)
1044 int index
= 0, total
= 0;
1045 return mlt_playlist_locate( this, &position
, &index
, &total
);
1048 /** Return the clip index of the specified position.
1051 int mlt_playlist_get_clip_index_at( mlt_playlist
this, mlt_position position
)
1053 int index
= 0, total
= 0;
1054 mlt_playlist_locate( this, &position
, &index
, &total
);
1058 /** Determine if the clip is a mix.
1061 int mlt_playlist_clip_is_mix( mlt_playlist
this, int clip
)
1063 mlt_producer producer
= mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip
) );
1064 mlt_properties properties
= producer
!= NULL ?
MLT_PRODUCER_PROPERTIES( producer
) : NULL
;
1065 mlt_tractor tractor
= properties
!= NULL ?
mlt_properties_get_data( properties
, "mlt_mix", NULL
) : NULL
;
1066 return tractor
!= NULL
;
1069 /** Remove a mixed clip - ensure that the cuts included in the mix find their way
1070 back correctly on to the playlist.
1073 static int mlt_playlist_unmix( mlt_playlist
this, int clip
)
1075 int error
= ( clip
< 0 || clip
>= this->count
);
1077 // Ensure that the clip request is actually a mix
1080 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ clip
]->producer
);
1081 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
1082 error
= mlt_properties_get_data( properties
, "mlt_mix", NULL
) == NULL
||
1083 this->list
[ clip
]->preservation_hack
;
1088 playlist_entry
*mix
= this->list
[ clip
];
1089 mlt_tractor tractor
= ( mlt_tractor
)mlt_producer_cut_parent( mix
->producer
);
1090 mlt_properties properties
= MLT_TRACTOR_PROPERTIES( tractor
);
1091 mlt_producer clip_a
= mlt_properties_get_data( properties
, "mix_in", NULL
);
1092 mlt_producer clip_b
= mlt_properties_get_data( properties
, "mix_out", NULL
);
1093 int length
= mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor
) );
1094 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1096 if ( clip_a
!= NULL
)
1098 mlt_producer_set_in_and_out( clip_a
, mlt_producer_get_in( clip_a
), mlt_producer_get_out( clip_a
) + length
);
1102 mlt_producer cut
= mlt_tractor_get_track( tractor
, 0 );
1103 mlt_playlist_insert( this, cut
, clip
, -1, -1 );
1107 if ( clip_b
!= NULL
)
1109 mlt_producer_set_in_and_out( clip_b
, mlt_producer_get_in( clip_b
) - length
, mlt_producer_get_out( clip_b
) );
1113 mlt_producer cut
= mlt_tractor_get_track( tractor
, 1 );
1114 mlt_playlist_insert( this, cut
, clip
+ 1, -1, -1 );
1117 mlt_properties_set_data( properties
, "mlt_mix", NULL
, 0, NULL
, NULL
);
1118 mlt_playlist_remove( this, clip
);
1119 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1120 mlt_playlist_virtual_refresh( this );
1125 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
)
1127 int error
= ( clip
< 0 || clip
>= this->count
);
1129 // Ensure that the clip request is actually a mix
1132 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ clip
]->producer
);
1133 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
1134 error
= mlt_properties_get_data( properties
, "mlt_mix", NULL
) == NULL
;
1139 playlist_entry
*mix
= this->list
[ clip
];
1140 mlt_tractor tractor
= ( mlt_tractor
)mlt_producer_cut_parent( mix
->producer
);
1141 mlt_properties properties
= MLT_TRACTOR_PROPERTIES( tractor
);
1142 mlt_producer clip_a
= mlt_properties_get_data( properties
, "mix_in", NULL
);
1143 mlt_producer clip_b
= mlt_properties_get_data( properties
, "mix_out", NULL
);
1144 mlt_producer track_a
= mlt_tractor_get_track( tractor
, 0 );
1145 mlt_producer track_b
= mlt_tractor_get_track( tractor
, 1 );
1146 int length
= out
- in
+ 1;
1147 int length_diff
= length
- mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor
) );
1148 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1150 if ( clip_a
!= NULL
)
1151 mlt_producer_set_in_and_out( clip_a
, mlt_producer_get_in( clip_a
), mlt_producer_get_out( clip_a
) - length_diff
);
1153 if ( clip_b
!= NULL
)
1154 mlt_producer_set_in_and_out( clip_b
, mlt_producer_get_in( clip_b
) + length_diff
, mlt_producer_get_out( clip_b
) );
1156 mlt_producer_set_in_and_out( track_a
, mlt_producer_get_in( track_a
) - length_diff
, mlt_producer_get_out( track_a
) );
1157 mlt_producer_set_in_and_out( track_b
, mlt_producer_get_in( track_b
), mlt_producer_get_out( track_b
) + length_diff
);
1158 mlt_producer_set_in_and_out( MLT_MULTITRACK_PRODUCER( mlt_tractor_multitrack( tractor
) ), in
, out
);
1159 mlt_producer_set_in_and_out( MLT_TRACTOR_PRODUCER( tractor
), in
, out
);
1160 mlt_properties_set_position( MLT_PRODUCER_PROPERTIES( mix
->producer
), "length", out
- in
+ 1 );
1161 mlt_producer_set_in_and_out( mix
->producer
, in
, out
);
1163 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1164 mlt_playlist_virtual_refresh( this );
1169 /** Consolodate adjacent blank producers.
1172 void mlt_playlist_consolidate_blanks( mlt_playlist
this, int keep_length
)
1177 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1179 mlt_events_block( properties
, properties
);
1180 for ( i
= 1; i
< this->count
; i
++ )
1182 playlist_entry
*left
= this->list
[ i
- 1 ];
1183 playlist_entry
*right
= this->list
[ i
];
1185 if ( mlt_producer_is_blank( left
->producer
) && mlt_producer_is_blank( right
->producer
) )
1187 mlt_playlist_resize_clip( this, i
- 1, 0, left
->frame_count
+ right
->frame_count
- 1 );
1188 mlt_playlist_remove( this, i
-- );
1192 if ( !keep_length
&& this->count
> 0 )
1194 playlist_entry
*last
= this->list
[ this->count
- 1 ];
1195 if ( mlt_producer_is_blank( last
->producer
) )
1196 mlt_playlist_remove( this, this->count
- 1 );
1199 mlt_events_unblock( properties
, properties
);
1200 mlt_playlist_virtual_refresh( this );
1204 /** Determine if the specified clip index is a blank.
1207 int mlt_playlist_is_blank( mlt_playlist
this, int clip
)
1209 return this == NULL
|| mlt_producer_is_blank( mlt_playlist_get_clip( this, clip
) );
1212 /** Determine if the specified position is a blank.
1215 int mlt_playlist_is_blank_at( mlt_playlist
this, mlt_position position
)
1217 return this == NULL
|| mlt_producer_is_blank( mlt_playlist_get_clip_at( this, position
) );
1220 /** Replace the specified clip with a blank and return the clip.
1223 mlt_producer
mlt_playlist_replace_with_blank( mlt_playlist
this, int clip
)
1225 mlt_producer producer
= NULL
;
1226 if ( !mlt_playlist_is_blank( this, clip
) )
1228 playlist_entry
*entry
= this->list
[ clip
];
1229 int in
= entry
->frame_in
;
1230 int out
= entry
->frame_out
;
1231 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1232 producer
= entry
->producer
;
1233 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer
) );
1234 mlt_events_block( properties
, properties
);
1235 mlt_playlist_remove( this, clip
);
1236 mlt_playlist_blank( this, out
- in
);
1237 mlt_playlist_move( this, this->count
- 1, clip
);
1238 mlt_events_unblock( properties
, properties
);
1239 mlt_playlist_virtual_refresh( this );
1240 mlt_producer_set_in_and_out( producer
, in
, out
);
1245 void mlt_playlist_insert_blank( mlt_playlist
this, int clip
, int length
)
1247 if ( this != NULL
&& length
>= 0 )
1249 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1250 mlt_events_block( properties
, properties
);
1251 mlt_playlist_blank( this, length
);
1252 mlt_playlist_move( this, this->count
- 1, clip
);
1253 mlt_events_unblock( properties
, properties
);
1254 mlt_playlist_virtual_refresh( this );
1258 void mlt_playlist_pad_blanks( mlt_playlist
this, mlt_position position
, int length
, int find
)
1260 if ( this != NULL
&& length
!= 0 )
1262 int clip
= mlt_playlist_get_clip_index_at( this, position
);
1263 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1264 mlt_events_block( properties
, properties
);
1265 if ( find
&& clip
< this->count
&& !mlt_playlist_is_blank( this, clip
) )
1267 if ( clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1269 mlt_playlist_clip_info info
;
1270 mlt_playlist_get_clip_info( this, &info
, clip
);
1271 if ( info
.frame_out
+ length
> info
.frame_in
)
1272 mlt_playlist_resize_clip( this, clip
, info
.frame_in
, info
.frame_out
+ length
);
1274 mlt_playlist_remove( this, clip
);
1276 else if ( find
&& clip
< this->count
&& length
> 0 )
1278 mlt_playlist_insert_blank( this, clip
, length
);
1280 mlt_events_unblock( properties
, properties
);
1281 mlt_playlist_virtual_refresh( this );
1285 int mlt_playlist_insert_at( mlt_playlist
this, mlt_position position
, mlt_producer producer
, int mode
)
1287 int ret
= this == NULL
|| position
< 0 || producer
== NULL
;
1290 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1291 int length
= mlt_producer_get_playtime( producer
);
1292 int clip
= mlt_playlist_get_clip_index_at( this, position
);
1293 mlt_playlist_clip_info info
;
1294 mlt_playlist_get_clip_info( this, &info
, clip
);
1295 mlt_events_block( properties
, this );
1296 if ( clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1298 // Split and move to new clip if need be
1299 if ( position
!= info
.start
&& mlt_playlist_split( this, clip
, position
- info
.start
- 1 ) == 0 )
1300 mlt_playlist_get_clip_info( this, &info
, ++ clip
);
1302 // Split again if need be
1303 if ( length
< info
.frame_count
)
1304 mlt_playlist_split( this, clip
, length
- 1 );
1307 mlt_playlist_remove( this, clip
);
1310 mlt_playlist_insert( this, producer
, clip
, -1, -1 );
1313 else if ( clip
< this->count
)
1315 if ( position
> info
.start
+ info
.frame_count
/ 2 )
1317 if ( mode
== 1 && clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1319 mlt_playlist_get_clip_info( this, &info
, clip
);
1320 if ( length
< info
.frame_count
)
1321 mlt_playlist_split( this, clip
, length
);
1322 mlt_playlist_remove( this, clip
);
1324 mlt_playlist_insert( this, producer
, clip
, -1, -1 );
1330 if ( position
== info
.start
)
1331 mlt_playlist_remove( this, clip
);
1333 mlt_playlist_blank( this, position
- mlt_properties_get_int( properties
, "length" ) - 1 );
1335 mlt_playlist_append( this, producer
);
1336 ret
= this->count
- 1;
1338 mlt_events_unblock( properties
, this );
1339 mlt_playlist_virtual_refresh( this );
1348 int mlt_playlist_clip_start( mlt_playlist
this, int clip
)
1350 mlt_playlist_clip_info info
;
1351 if ( mlt_playlist_get_clip_info( this, &info
, clip
) == 0 )
1353 return clip
< 0 ?
0 : mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1356 int mlt_playlist_clip_length( mlt_playlist
this, int clip
)
1358 mlt_playlist_clip_info info
;
1359 if ( mlt_playlist_get_clip_info( this, &info
, clip
) == 0 )
1360 return info
.frame_count
;
1364 int mlt_playlist_blanks_from( mlt_playlist
this, int clip
, int bounded
)
1367 mlt_playlist_clip_info info
;
1368 if ( this != NULL
&& clip
< this->count
)
1370 mlt_playlist_get_clip_info( this, &info
, clip
);
1371 if ( mlt_playlist_is_blank( this, clip
) )
1372 count
+= info
.frame_count
;
1374 bounded
= this->count
;
1375 for ( clip
++; clip
< this->count
&& bounded
>= 0; clip
++ )
1377 mlt_playlist_get_clip_info( this, &info
, clip
);
1378 if ( mlt_playlist_is_blank( this, clip
) )
1379 count
+= info
.frame_count
;
1387 int mlt_playlist_remove_region( mlt_playlist
this, mlt_position position
, int length
)
1389 int index
= mlt_playlist_get_clip_index_at( this, position
);
1390 if ( index
>= 0 && index
< this->count
)
1392 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1393 int clip_start
= mlt_playlist_clip_start( this, index
);
1394 int clip_length
= mlt_playlist_clip_length( this, index
);
1395 int list_length
= mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1396 mlt_events_block( properties
, this );
1398 if ( position
+ length
> list_length
)
1399 length
-= ( position
+ length
- list_length
);
1401 if ( clip_start
< position
)
1403 mlt_playlist_split( this, index
++, position
- clip_start
);
1404 clip_length
-= position
- clip_start
;
1409 if ( mlt_playlist_clip_length( this, index
) > length
)
1410 mlt_playlist_split( this, index
, length
);
1411 length
-= mlt_playlist_clip_length( this, index
);
1412 mlt_playlist_remove( this, index
);
1415 mlt_playlist_consolidate_blanks( this, 0 );
1416 mlt_events_unblock( properties
, this );
1417 mlt_playlist_virtual_refresh( this );
1419 // Just to be sure, we'll get the clip index again...
1420 index
= mlt_playlist_get_clip_index_at( this, position
);
1425 int mlt_playlist_move_region( mlt_playlist
this, mlt_position position
, int length
, int new_position
)
1433 /** Get the current frame.
1436 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
1438 // Check that we have a producer
1439 if ( producer
== NULL
)
1445 // Get this mlt_playlist
1446 mlt_playlist
this = producer
->child
;
1448 // Need to ensure the frame is deinterlaced when repeating 1 frame
1449 int progressive
= 0;
1451 // Get the real producer
1452 mlt_service real
= mlt_playlist_virtual_seek( this, &progressive
);
1454 // Check that we have a producer
1457 *frame
= mlt_frame_init( MLT_PRODUCER_SERVICE( producer
) );
1462 if ( !mlt_properties_get_int( MLT_SERVICE_PROPERTIES( real
), "meta.fx_cut" ) )
1464 mlt_service_get_frame( real
, frame
, index
);
1468 mlt_producer parent
= mlt_producer_cut_parent( ( mlt_producer
)real
);
1469 *frame
= mlt_frame_init( MLT_PRODUCER_SERVICE( parent
) );
1470 mlt_properties_set_int( MLT_FRAME_PROPERTIES( *frame
), "fx_cut", 1 );
1471 mlt_frame_push_service( *frame
, NULL
);
1472 mlt_frame_push_audio( *frame
, NULL
);
1473 mlt_service_apply_filters( MLT_PRODUCER_SERVICE( parent
), *frame
, 0 );
1474 mlt_service_apply_filters( real
, *frame
, 0 );
1475 mlt_deque_pop_front( MLT_FRAME_IMAGE_STACK( *frame
) );
1476 mlt_deque_pop_front( MLT_FRAME_AUDIO_STACK( *frame
) );
1479 // Check if we're at the end of the clip
1480 mlt_properties properties
= MLT_FRAME_PROPERTIES( *frame
);
1481 if ( mlt_properties_get_int( properties
, "end_of_clip" ) )
1482 mlt_playlist_virtual_set_out( this );
1484 // Set the consumer progressive property
1487 mlt_properties_set_int( properties
, "consumer_deinterlace", progressive
);
1488 mlt_properties_set_int( properties
, "test_audio", 1 );
1491 // Check for notifier and call with appropriate argument
1492 mlt_properties playlist_properties
= MLT_PRODUCER_PROPERTIES( producer
);
1493 void ( *notifier
)( void * ) = mlt_properties_get_data( playlist_properties
, "notifier", NULL
);
1494 if ( notifier
!= NULL
)
1496 void *argument
= mlt_properties_get_data( playlist_properties
, "notifier_arg", NULL
);
1497 notifier( argument
);
1500 // Update position on the frame we're creating
1501 mlt_frame_set_position( *frame
, mlt_producer_frame( producer
) );
1503 // Position ourselves on the next frame
1504 mlt_producer_prepare_next( producer
);
1509 /** Close the playlist.
1512 void mlt_playlist_close( mlt_playlist
this )
1514 if ( this != NULL
&& mlt_properties_dec_ref( MLT_PLAYLIST_PROPERTIES( this ) ) <= 0 )
1517 this->parent
.close
= NULL
;
1518 for ( i
= 0; i
< this->count
; i
++ )
1520 mlt_event_close( this->list
[ i
]->event
);
1521 mlt_producer_close( this->list
[ i
]->producer
);
1522 free( this->list
[ i
] );
1524 mlt_producer_close( &this->blank
);
1525 mlt_producer_close( &this->parent
);