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
!= &this->blank
&&
174 ( this->list
[ i
]->frame_in
!= mlt_producer_get_in( producer
) ||
175 this->list
[ i
]->frame_out
!= mlt_producer_get_out( producer
) ) )
177 // This clip should be removed...
178 if ( current_length
== 1 )
180 this->list
[ i
]->frame_in
= 0;
181 this->list
[ i
]->frame_out
= 0;
182 this->list
[ i
]->frame_count
= 0;
186 this->list
[ i
]->frame_in
= mlt_producer_get_in( producer
);
187 this->list
[ i
]->frame_out
= mlt_producer_get_out( producer
);
188 this->list
[ i
]->frame_count
= current_length
;
191 // Update the producer_length
192 this->list
[ i
]->producer_length
= current_length
;
195 // Update the frame_count for this clip
196 frame_count
+= this->list
[ i
]->frame_count
;
199 // Refresh all properties
200 mlt_properties_set_double( properties
, "first_fps", fps
);
201 mlt_properties_set_double( properties
, "fps", fps
== 0 ?
25 : fps
);
202 mlt_events_block( properties
, properties
);
203 mlt_properties_set_position( properties
, "length", frame_count
);
204 mlt_events_unblock( properties
, properties
);
205 mlt_properties_set_position( properties
, "out", frame_count
- 1 );
210 /** Listener for producers on the playlist.
213 static void mlt_playlist_listener( mlt_producer producer
, mlt_playlist
this )
215 mlt_playlist_virtual_refresh( this );
218 /** Append to the virtual playlist.
221 static int mlt_playlist_virtual_append( mlt_playlist
this, mlt_producer source
, mlt_position in
, mlt_position out
)
223 mlt_producer producer
= NULL
;
224 mlt_properties properties
= NULL
;
226 // If we have a cut, then use the in/out points from the cut
227 if ( &this->blank
== source
)
230 properties
= mlt_producer_properties( producer
);
231 mlt_properties_inc_ref( properties
);
233 else if ( mlt_producer_is_cut( source
) )
237 in
= mlt_producer_get_in( producer
);
238 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
239 out
= mlt_producer_get_out( producer
);
240 properties
= mlt_producer_properties( producer
);
241 mlt_properties_inc_ref( properties
);
245 producer
= mlt_producer_cut( source
, in
, out
);
246 if ( in
== -1 || in
< mlt_producer_get_in( producer
) )
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
);
254 // Check that we have room
255 if ( this->count
>= this->size
)
258 this->list
= realloc( this->list
, ( this->size
+ 10 ) * sizeof( playlist_entry
* ) );
259 for ( i
= this->size
; i
< this->size
+ 10; i
++ ) this->list
[ i
] = NULL
;
263 this->list
[ this->count
] = calloc( sizeof( playlist_entry
), 1 );
264 this->list
[ this->count
]->producer
= producer
;
265 this->list
[ this->count
]->frame_in
= in
;
266 this->list
[ this->count
]->frame_out
= out
;
267 this->list
[ this->count
]->frame_count
= out
- in
+ 1;
268 this->list
[ this->count
]->producer_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
269 this->list
[ this->count
]->event
= mlt_events_listen( properties
, this, "producer-changed", ( mlt_listener
)mlt_playlist_listener
);
270 mlt_event_inc_ref( this->list
[ this->count
]->event
);
272 mlt_properties_set( mlt_producer_properties( source
), "eof", "pause" );
273 mlt_properties_set( properties
, "eof", "pause" );
275 mlt_producer_set_speed( source
, 0 );
276 mlt_producer_set_speed( producer
, 0 );
280 return mlt_playlist_virtual_refresh( this );
283 /** Seek in the virtual playlist.
286 static mlt_service
mlt_playlist_virtual_seek( mlt_playlist
this )
288 // Default producer to blank
289 mlt_producer producer
= NULL
;
291 // Map playlist position to real producer in virtual playlist
292 mlt_position position
= mlt_producer_frame( &this->parent
);
294 mlt_position original
= position
;
296 // Total number of frames
299 // Get the properties
300 mlt_properties properties
= mlt_playlist_properties( this );
302 // Get the eof handling
303 char *eof
= mlt_properties_get( properties
, "eof" );
305 // Index for the main loop
308 // Loop for each producer until found
309 for ( i
= 0; i
< this->count
; i
++ )
311 // Increment the total
312 total
+= this->list
[ i
]->frame_count
;
314 // Check if the position indicates that we have found the clip
315 if ( position
< this->list
[ i
]->frame_count
)
317 // Found it, now break
318 producer
= this->list
[ i
]->producer
;
323 // Decrement position by length of this entry
324 position
-= this->list
[ i
]->frame_count
;
328 // Seek in real producer to relative position
329 if ( producer
!= NULL
)
331 mlt_producer_seek( producer
, position
);
333 else if ( !strcmp( eof
, "pause" ) && total
> 0 )
335 playlist_entry
*entry
= this->list
[ this->count
- 1 ];
336 mlt_producer this_producer
= mlt_playlist_producer( this );
337 mlt_producer_seek( this_producer
, original
- 1 );
338 producer
= entry
->producer
;
339 mlt_producer_seek( producer
, entry
->frame_out
);
340 mlt_producer_set_speed( this_producer
, 0 );
341 mlt_producer_set_speed( producer
, 0 );
343 else if ( !strcmp( eof
, "loop" ) && total
> 0 )
345 playlist_entry
*entry
= this->list
[ 0 ];
346 mlt_producer this_producer
= mlt_playlist_producer( this );
347 mlt_producer_seek( this_producer
, 0 );
348 producer
= entry
->producer
;
349 mlt_producer_seek( producer
, 0 );
353 producer
= &this->blank
;
356 return mlt_producer_service( producer
);
359 /** Invoked when a producer indicates that it has prematurely reached its end.
362 static mlt_producer
mlt_playlist_virtual_set_out( mlt_playlist
this )
364 // Default producer to blank
365 mlt_producer producer
= &this->blank
;
367 // Map playlist position to real producer in virtual playlist
368 mlt_position position
= mlt_producer_frame( &this->parent
);
370 // Loop through the virtual playlist
373 for ( i
= 0; i
< this->count
; i
++ )
375 if ( position
< this->list
[ i
]->frame_count
)
377 // Found it, now break
378 producer
= this->list
[ i
]->producer
;
383 // Decrement position by length of this entry
384 position
-= this->list
[ i
]->frame_count
;
388 // Seek in real producer to relative position
389 if ( i
< this->count
&& this->list
[ i
]->frame_out
!= position
)
391 // Update the frame_count for the changed clip (hmmm)
392 this->list
[ i
]->frame_out
= position
;
393 this->list
[ i
]->frame_count
= this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1;
395 // Refresh the playlist
396 mlt_playlist_virtual_refresh( this );
402 /** Obtain the current clips index.
405 int mlt_playlist_current_clip( mlt_playlist
this )
407 // Map playlist position to real producer in virtual playlist
408 mlt_position position
= mlt_producer_frame( &this->parent
);
410 // Loop through the virtual playlist
413 for ( i
= 0; i
< this->count
; i
++ )
415 if ( position
< this->list
[ i
]->frame_count
)
417 // Found it, now break
422 // Decrement position by length of this entry
423 position
-= this->list
[ i
]->frame_count
;
430 /** Obtain the current clips producer.
433 mlt_producer
mlt_playlist_current( mlt_playlist
this )
435 int i
= mlt_playlist_current_clip( this );
436 if ( i
< this->count
)
437 return this->list
[ i
]->producer
;
442 /** Get the position which corresponds to the start of the next clip.
445 mlt_position
mlt_playlist_clip( mlt_playlist
this, mlt_whence whence
, int index
)
447 mlt_position position
= 0;
448 int absolute_clip
= index
;
451 // Determine the absolute clip
454 case mlt_whence_relative_start
:
455 absolute_clip
= index
;
458 case mlt_whence_relative_current
:
459 absolute_clip
= mlt_playlist_current_clip( this ) + index
;
462 case mlt_whence_relative_end
:
463 absolute_clip
= this->count
- index
;
467 // Check that we're in a valid range
468 if ( absolute_clip
< 0 )
470 else if ( absolute_clip
> this->count
)
471 absolute_clip
= this->count
;
473 // Now determine the position
474 for ( i
= 0; i
< absolute_clip
; i
++ )
475 position
+= this->list
[ i
]->frame_count
;
480 /** Get all the info about the clip specified.
483 int mlt_playlist_get_clip_info( mlt_playlist
this, mlt_playlist_clip_info
*info
, int index
)
485 int error
= index
< 0 || index
>= this->count
;
486 memset( info
, 0, sizeof( mlt_playlist_clip_info
) );
489 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ index
]->producer
);
490 mlt_properties properties
= mlt_producer_properties( producer
);
492 info
->producer
= producer
;
493 info
->cut
= this->list
[ index
]->producer
;
494 info
->start
= mlt_playlist_clip( this, mlt_whence_relative_start
, index
);
495 info
->resource
= mlt_properties_get( properties
, "resource" );
496 info
->frame_in
= this->list
[ index
]->frame_in
;
497 info
->frame_out
= this->list
[ index
]->frame_out
;
498 info
->frame_count
= this->list
[ index
]->frame_count
;
499 info
->length
= mlt_producer_get_length( producer
);
500 info
->fps
= mlt_producer_get_fps( producer
);
501 info
->event
= this->list
[ index
]->event
;
507 /** Get number of clips in the playlist.
510 int mlt_playlist_count( mlt_playlist
this )
515 /** Clear the playlist.
518 int mlt_playlist_clear( mlt_playlist
this )
521 for ( i
= 0; i
< this->count
; i
++ )
523 mlt_event_close( this->list
[ i
]->event
);
524 mlt_producer_close( this->list
[ i
]->producer
);
527 mlt_properties_set_double( mlt_playlist_properties( this ), "first_fps", 0 );
528 return mlt_playlist_virtual_refresh( this );
531 /** Append a producer to the playlist.
534 int mlt_playlist_append( mlt_playlist
this, mlt_producer producer
)
536 // Append to virtual list
537 return mlt_playlist_virtual_append( this, producer
, 0, mlt_producer_get_playtime( producer
) - 1 );
540 /** Append a producer to the playlist with in/out points.
543 int mlt_playlist_append_io( mlt_playlist
this, mlt_producer producer
, mlt_position in
, mlt_position out
)
545 // Append to virtual list
546 if ( in
!= -1 && out
!= -1 )
547 return mlt_playlist_virtual_append( this, producer
, in
, out
);
549 return mlt_playlist_append( this, producer
);
552 /** Append a blank to the playlist of a given length.
555 int mlt_playlist_blank( mlt_playlist
this, mlt_position length
)
557 // Append to the virtual list
558 return mlt_playlist_virtual_append( this, &this->blank
, 0, length
);
561 /** Insert a producer into the playlist.
564 int mlt_playlist_insert( mlt_playlist
this, mlt_producer producer
, int where
, mlt_position in
, mlt_position out
)
567 mlt_events_block( mlt_playlist_properties( this ), this );
568 mlt_playlist_append_io( this, producer
, in
, out
);
570 // Move to the position specified
571 mlt_playlist_move( this, this->count
- 1, where
);
572 mlt_events_unblock( mlt_playlist_properties( this ), this );
574 return mlt_playlist_virtual_refresh( this );
577 /** Remove an entry in the playlist.
580 int mlt_playlist_remove( mlt_playlist
this, int where
)
582 int error
= where
< 0 || where
>= this->count
;
583 if ( error
== 0 && mlt_playlist_unmix( this, where
) != 0 )
585 // We need to know the current clip and the position within the playlist
586 int current
= mlt_playlist_current_clip( this );
587 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
589 // We need all the details about the clip we're removing
590 mlt_playlist_clip_info where_info
;
591 playlist_entry
*entry
= this->list
[ where
];
597 mlt_playlist_get_clip_info( this, &where_info
, where
);
599 // Make sure the clip to be removed is valid and correct if necessary
602 if ( where
>= this->count
)
603 where
= this->count
- 1;
605 // Close the producer associated to the clip info
606 mlt_event_close( entry
->event
);
607 mlt_producer_close( entry
->producer
);
608 if ( entry
->mix_in
!= NULL
)
609 entry
->mix_in
->mix_out
= NULL
;
610 if ( entry
->mix_out
!= NULL
)
611 entry
->mix_out
->mix_in
= NULL
;
613 // Reorganise the list
614 for ( i
= where
+ 1; i
< this->count
; i
++ )
615 this->list
[ i
- 1 ] = this->list
[ i
];
619 if ( where
== current
)
620 mlt_producer_seek( mlt_playlist_producer( this ), where_info
.start
);
621 else if ( where
< current
&& this->count
> 0 )
622 mlt_producer_seek( mlt_playlist_producer( this ), position
- where_info
.frame_count
);
623 else if ( this->count
== 0 )
624 mlt_producer_seek( mlt_playlist_producer( this ), 0 );
629 // Refresh the playlist
630 mlt_playlist_virtual_refresh( this );
636 /** Move an entry in the playlist.
639 int mlt_playlist_move( mlt_playlist
this, int src
, int dest
)
643 /* We need to ensure that the requested indexes are valid and correct it as necessary */
646 if ( src
>= this->count
)
647 src
= this->count
- 1;
651 if ( dest
>= this->count
)
652 dest
= this->count
- 1;
654 if ( src
!= dest
&& this->count
> 1 )
656 int current
= mlt_playlist_current_clip( this );
657 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
658 playlist_entry
*src_entry
= NULL
;
660 // We need all the details about the current clip
661 mlt_playlist_clip_info current_info
;
663 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
664 position
-= current_info
.start
;
666 if ( current
== src
)
668 else if ( current
> src
&& current
< dest
)
670 else if ( current
== dest
)
673 src_entry
= this->list
[ src
];
676 for ( i
= src
; i
> dest
; i
-- )
677 this->list
[ i
] = this->list
[ i
- 1 ];
681 for ( i
= src
; i
< dest
; i
++ )
682 this->list
[ i
] = this->list
[ i
+ 1 ];
684 this->list
[ dest
] = src_entry
;
686 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
687 mlt_producer_seek( mlt_playlist_producer( this ), current_info
.start
+ position
);
688 mlt_playlist_virtual_refresh( this );
694 /** Resize the current clip.
697 int mlt_playlist_resize_clip( mlt_playlist
this, int clip
, mlt_position in
, mlt_position out
)
699 int error
= clip
< 0 || clip
>= this->count
;
700 if ( error
== 0 && mlt_playlist_resize_mix( this, clip
, in
, out
) != 0 )
702 playlist_entry
*entry
= this->list
[ clip
];
703 mlt_producer producer
= entry
->producer
;
707 if ( out
<= -1 || out
>= mlt_producer_get_length( producer
) )
708 out
= mlt_producer_get_length( producer
) - 1;
717 mlt_producer_set_in_and_out( producer
, in
, out
);
722 /** Split a clip on the playlist at the given position.
725 int mlt_playlist_split( mlt_playlist
this, int clip
, mlt_position position
)
727 int error
= clip
< 0 || clip
>= this->count
;
730 playlist_entry
*entry
= this->list
[ clip
];
731 if ( position
> 0 && position
< entry
->frame_count
)
733 mlt_producer parent
= mlt_producer_cut_parent( entry
->producer
);
734 mlt_producer split
= NULL
;
735 int in
= entry
->frame_in
;
736 int out
= entry
->frame_out
;
737 mlt_events_block( mlt_playlist_properties( this ), this );
738 mlt_playlist_resize_clip( this, clip
, in
, in
+ position
);
739 split
= mlt_producer_cut( parent
, in
+ position
+ 1, out
);
740 mlt_playlist_insert( this, split
, clip
+ 1, -1, -1 );
741 mlt_events_unblock( mlt_playlist_properties( this ), this );
742 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
752 /** Join 1 or more consecutive clips.
755 int mlt_playlist_join( mlt_playlist
this, int clip
, int count
, int merge
)
757 int error
= clip
< 0 || ( clip
+ 1 ) >= this->count
;
761 mlt_playlist new_clip
= mlt_playlist_init( );
762 mlt_events_block( mlt_playlist_properties( this ), this );
763 if ( clip
+ count
>= this->count
)
764 count
= this->count
- clip
;
765 for ( i
= 0; i
<= count
; i
++ )
767 playlist_entry
*entry
= this->list
[ clip
];
768 mlt_playlist_append( new_clip
, entry
->producer
);
769 mlt_playlist_remove( this, clip
);
771 mlt_events_unblock( mlt_playlist_properties( this ), this );
772 mlt_playlist_insert( this, mlt_playlist_producer( new_clip
), clip
, 0, -1 );
773 mlt_playlist_close( new_clip
);
778 int mlt_playlist_mix( mlt_playlist
this, int clip
, int length
, mlt_transition transition
)
780 int error
= ( clip
< 0 || clip
+ 1 >= this->count
) && this->list
[ clip
]->mix_out
!= NULL
;
783 playlist_entry
*clip_a
= this->list
[ clip
];
784 playlist_entry
*clip_b
= this->list
[ clip
+ 1 ];
785 mlt_producer track_a
;
786 mlt_producer track_b
;
787 mlt_tractor tractor
= mlt_tractor_new( );
788 mlt_events_block( mlt_playlist_properties( this ), this );
790 track_a
= mlt_producer_cut( clip_a
->producer
, clip_a
->frame_out
- length
+ 1, clip_a
->frame_out
);
791 mlt_properties_set_int( mlt_producer_properties( track_a
), "cut", 1 );
792 track_b
= mlt_producer_cut( clip_b
->producer
, clip_b
->frame_in
, clip_b
->frame_in
+ length
- 1 );
793 mlt_properties_set_int( mlt_producer_properties( track_b
), "cut", 1 );
795 mlt_playlist_resize_clip( this, clip
, clip_a
->frame_in
, clip_a
->frame_out
- length
+ 1 );
796 mlt_playlist_resize_clip( this, clip
+ 1, clip_b
->frame_in
+ length
, clip_b
->frame_out
);
798 mlt_tractor_set_track( tractor
, track_a
, 0 );
799 mlt_tractor_set_track( tractor
, track_b
, 1 );
800 mlt_playlist_insert( this, mlt_tractor_producer( tractor
), clip
+ 1, -1, -1 );
801 mlt_properties_set_data( mlt_tractor_properties( tractor
), "mlt_mix", tractor
, 0, NULL
, NULL
);
803 if ( transition
!= NULL
)
805 mlt_field field
= mlt_tractor_field( tractor
);
806 mlt_field_plant_transition( field
, transition
, 0, 1 );
807 mlt_transition_set_in_and_out( transition
, 0, length
- 1 );
810 if ( clip_b
->frame_count
<= 0 )
811 mlt_playlist_remove( this, clip
+ 2 );
813 if ( clip_a
->frame_count
<= 0 )
814 mlt_playlist_remove( this, clip
);
816 mlt_events_unblock( mlt_playlist_properties( this ), this );
817 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
818 mlt_producer_close( track_a
);
819 mlt_producer_close( track_b
);
820 mlt_tractor_close( tractor
);
825 static int mlt_playlist_unmix( mlt_playlist
this, int clip
)
827 int error
= ( clip
< 0 || clip
>= this->count
);
829 // Ensure that the clip request is actually a mix
832 mlt_producer producer
= this->list
[ clip
]->producer
;
833 mlt_properties properties
= mlt_producer_properties( producer
);
834 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
839 playlist_entry
*mix
= this->list
[ clip
];
840 playlist_entry
*clip_a
= mix
->mix_in
;
841 playlist_entry
*clip_b
= mix
->mix_out
;
842 int length
= mix
->mix_in_length
;
843 mlt_events_block( mlt_playlist_properties( this ), this );
845 if ( clip_a
!= NULL
)
847 clip_a
->frame_out
+= length
;
848 clip_a
->frame_count
+= length
;
849 clip_a
->mix_out
= NULL
;
850 clip_a
->mix_out_length
= 0;
854 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
855 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 0 );
856 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
857 mlt_playlist_insert( this, producer
, clip
, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
861 if ( clip_b
!= NULL
)
863 clip_b
->frame_in
-= length
;
864 clip_b
->frame_count
+= length
;
865 clip_b
->mix_in
= NULL
;
866 clip_b
->mix_in_length
= 0;
870 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
871 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 1 );
872 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
873 mlt_playlist_insert( this, producer
, clip
+ 1, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
876 mlt_properties_set_int( mlt_producer_properties( mix
->producer
), "mlt_mix", 0 );
877 mlt_playlist_remove( this, clip
);
878 mlt_events_unblock( mlt_playlist_properties( this ), this );
879 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
884 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
)
886 int error
= ( clip
< 0 || clip
>= this->count
);
888 // Ensure that the clip request is actually a mix
891 mlt_producer producer
= this->list
[ clip
]->producer
;
892 mlt_properties properties
= mlt_producer_properties( producer
);
893 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
898 playlist_entry
*mix
= this->list
[ clip
];
899 playlist_entry
*clip_a
= mix
->mix_in
;
900 playlist_entry
*clip_b
= mix
->mix_out
;
901 int length
= out
- in
+ 1;
902 int length_diff
= length
- mix
->mix_in_length
;
903 mlt_events_block( mlt_playlist_properties( this ), this );
905 if ( clip_a
!= NULL
)
907 clip_a
->frame_out
-= length_diff
;
908 clip_a
->frame_count
-= length_diff
;
909 clip_a
->mix_out_length
-= length_diff
;
912 if ( clip_b
!= NULL
)
914 clip_b
->frame_in
+= length_diff
;
915 clip_b
->frame_count
-= length_diff
;
916 clip_b
->mix_in_length
-= length_diff
;
920 mix
->frame_out
= length
- 1;
921 mix
->frame_count
= length
;
922 mix
->mix_in_length
= length
;
923 mix
->mix_out_length
= length
;
925 mlt_events_unblock( mlt_playlist_properties( this ), this );
926 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
931 /** Get the current frame.
934 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
936 // Get this mlt_playlist
937 mlt_playlist
this = producer
->child
;
939 // Get the real producer
940 mlt_service real
= mlt_playlist_virtual_seek( this );
943 mlt_service_get_frame( real
, frame
, index
);
945 // Check if we're at the end of the clip
946 mlt_properties properties
= mlt_frame_properties( *frame
);
947 if ( mlt_properties_get_int( properties
, "end_of_clip" ) )
948 mlt_playlist_virtual_set_out( this );
950 // Check for notifier and call with appropriate argument
951 mlt_properties playlist_properties
= mlt_producer_properties( producer
);
952 void ( *notifier
)( void * ) = mlt_properties_get_data( playlist_properties
, "notifier", NULL
);
953 if ( notifier
!= NULL
)
955 void *argument
= mlt_properties_get_data( playlist_properties
, "notifier_arg", NULL
);
956 notifier( argument
);
959 // Update position on the frame we're creating
960 mlt_frame_set_position( *frame
, mlt_producer_frame( producer
) );
962 // Position ourselves on the next frame
963 mlt_producer_prepare_next( producer
);
968 /** Close the playlist.
971 void mlt_playlist_close( mlt_playlist
this )
973 if ( this != NULL
&& mlt_properties_dec_ref( mlt_playlist_properties( this ) ) <= 0 )
976 this->parent
.close
= NULL
;
977 for ( i
= 0; i
< this->count
; i
++ )
979 mlt_event_close( this->list
[ i
]->event
);
980 mlt_producer_close( this->list
[ i
]->producer
);
981 free( this->list
[ i
] );
983 mlt_producer_close( &this->blank
);
984 mlt_producer_close( &this->parent
);