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
]->frame_in
!= mlt_producer_get_in( producer
) ||
174 this->list
[ i
]->frame_out
!= mlt_producer_get_out( producer
) );
176 // This clip should be removed...
177 if ( current_length
== 1 )
179 this->list
[ i
]->frame_in
= 0;
180 this->list
[ i
]->frame_out
= 0;
181 this->list
[ i
]->frame_count
= 0;
185 this->list
[ i
]->frame_in
= mlt_producer_get_in( producer
);
186 this->list
[ i
]->frame_out
= mlt_producer_get_out( producer
);
187 this->list
[ i
]->frame_count
= current_length
;
190 // Update the producer_length
191 this->list
[ i
]->producer_length
= current_length
;
194 // Update the frame_count for this clip
195 frame_count
+= this->list
[ i
]->frame_count
;
198 // Refresh all properties
199 mlt_properties_set_double( properties
, "first_fps", fps
);
200 mlt_properties_set_double( properties
, "fps", fps
== 0 ?
25 : fps
);
201 mlt_events_block( properties
, properties
);
202 mlt_properties_set_position( properties
, "length", frame_count
);
203 mlt_events_unblock( properties
, properties
);
204 mlt_properties_set_position( properties
, "out", frame_count
- 1 );
209 /** Listener for producers on the playlist.
212 static void mlt_playlist_listener( mlt_producer producer
, mlt_playlist
this )
214 mlt_playlist_virtual_refresh( this );
217 /** Append to the virtual playlist.
220 static int mlt_playlist_virtual_append( mlt_playlist
this, mlt_producer source
, mlt_position in
, mlt_position out
)
222 mlt_producer producer
= mlt_producer_is_cut( source
) ? source
: mlt_producer_cut( source
, in
, out
);
223 mlt_properties properties
= mlt_producer_properties( producer
);
225 // If we have a cut, then use the in/out points from the cut
226 if ( mlt_producer_is_cut( source
) )
228 mlt_properties_inc_ref( properties
);
229 in
= mlt_producer_get_in( source
);
230 out
= mlt_producer_get_out( source
);
233 // Check that we have room
234 if ( this->count
>= this->size
)
237 this->list
= realloc( this->list
, ( this->size
+ 10 ) * sizeof( playlist_entry
* ) );
238 for ( i
= this->size
; i
< this->size
+ 10; i
++ ) this->list
[ i
] = NULL
;
242 this->list
[ this->count
] = calloc( sizeof( playlist_entry
), 1 );
243 this->list
[ this->count
]->producer
= producer
;
244 this->list
[ this->count
]->frame_in
= in
;
245 this->list
[ this->count
]->frame_out
= out
;
246 this->list
[ this->count
]->frame_count
= out
- in
+ 1;
247 this->list
[ this->count
]->producer_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
248 this->list
[ this->count
]->event
= mlt_events_listen( properties
, this, "producer-changed", ( mlt_listener
)mlt_playlist_listener
);
249 mlt_event_inc_ref( this->list
[ this->count
]->event
);
251 mlt_properties_set( properties
, "eof", "pause" );
253 mlt_producer_set_speed( producer
, 0 );
258 return mlt_playlist_virtual_refresh( this );
261 /** Seek in the virtual playlist.
264 static mlt_service
mlt_playlist_virtual_seek( mlt_playlist
this )
266 // Default producer to blank
267 mlt_producer producer
= NULL
;
269 // Map playlist position to real producer in virtual playlist
270 mlt_position position
= mlt_producer_frame( &this->parent
);
272 mlt_position original
= position
;
274 // Total number of frames
277 // Get the properties
278 mlt_properties properties
= mlt_playlist_properties( this );
280 // Get the eof handling
281 char *eof
= mlt_properties_get( properties
, "eof" );
283 // Index for the main loop
286 // Loop for each producer until found
287 for ( i
= 0; i
< this->count
; i
++ )
289 // Increment the total
290 total
+= this->list
[ i
]->frame_count
;
292 // Check if the position indicates that we have found the clip
293 if ( position
< this->list
[ i
]->frame_count
)
295 // Found it, now break
296 producer
= this->list
[ i
]->producer
;
301 // Decrement position by length of this entry
302 position
-= this->list
[ i
]->frame_count
;
306 // Seek in real producer to relative position
307 if ( producer
!= NULL
)
309 mlt_producer_seek( producer
, position
);
311 else if ( !strcmp( eof
, "pause" ) && total
> 0 )
313 playlist_entry
*entry
= this->list
[ this->count
- 1 ];
314 mlt_producer this_producer
= mlt_playlist_producer( this );
315 mlt_producer_seek( this_producer
, original
- 1 );
316 producer
= entry
->producer
;
317 mlt_producer_seek( producer
, entry
->frame_out
);
318 mlt_producer_set_speed( this_producer
, 0 );
319 mlt_producer_set_speed( producer
, 0 );
321 else if ( !strcmp( eof
, "loop" ) && total
> 0 )
323 playlist_entry
*entry
= this->list
[ 0 ];
324 mlt_producer this_producer
= mlt_playlist_producer( this );
325 mlt_producer_seek( this_producer
, 0 );
326 producer
= entry
->producer
;
327 mlt_producer_seek( producer
, 0 );
331 producer
= &this->blank
;
334 return mlt_producer_service( producer
);
337 /** Invoked when a producer indicates that it has prematurely reached its end.
340 static mlt_producer
mlt_playlist_virtual_set_out( mlt_playlist
this )
342 // Default producer to blank
343 mlt_producer producer
= &this->blank
;
345 // Map playlist position to real producer in virtual playlist
346 mlt_position position
= mlt_producer_frame( &this->parent
);
348 // Loop through the virtual playlist
351 for ( i
= 0; i
< this->count
; i
++ )
353 if ( position
< this->list
[ i
]->frame_count
)
355 // Found it, now break
356 producer
= this->list
[ i
]->producer
;
361 // Decrement position by length of this entry
362 position
-= this->list
[ i
]->frame_count
;
366 // Seek in real producer to relative position
367 if ( i
< this->count
&& this->list
[ i
]->frame_out
!= position
)
369 // Update the frame_count for the changed clip (hmmm)
370 this->list
[ i
]->frame_out
= position
;
371 this->list
[ i
]->frame_count
= this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1;
373 // Refresh the playlist
374 mlt_playlist_virtual_refresh( this );
380 /** Obtain the current clips index.
383 int mlt_playlist_current_clip( mlt_playlist
this )
385 // Map playlist position to real producer in virtual playlist
386 mlt_position position
= mlt_producer_frame( &this->parent
);
388 // Loop through the virtual playlist
391 for ( i
= 0; i
< this->count
; i
++ )
393 if ( position
< this->list
[ i
]->frame_count
)
395 // Found it, now break
400 // Decrement position by length of this entry
401 position
-= this->list
[ i
]->frame_count
;
408 /** Obtain the current clips producer.
411 mlt_producer
mlt_playlist_current( mlt_playlist
this )
413 int i
= mlt_playlist_current_clip( this );
414 if ( i
< this->count
)
415 return this->list
[ i
]->producer
;
420 /** Get the position which corresponds to the start of the next clip.
423 mlt_position
mlt_playlist_clip( mlt_playlist
this, mlt_whence whence
, int index
)
425 mlt_position position
= 0;
426 int absolute_clip
= index
;
429 // Determine the absolute clip
432 case mlt_whence_relative_start
:
433 absolute_clip
= index
;
436 case mlt_whence_relative_current
:
437 absolute_clip
= mlt_playlist_current_clip( this ) + index
;
440 case mlt_whence_relative_end
:
441 absolute_clip
= this->count
- index
;
445 // Check that we're in a valid range
446 if ( absolute_clip
< 0 )
448 else if ( absolute_clip
> this->count
)
449 absolute_clip
= this->count
;
451 // Now determine the position
452 for ( i
= 0; i
< absolute_clip
; i
++ )
453 position
+= this->list
[ i
]->frame_count
;
458 /** Get all the info about the clip specified.
461 int mlt_playlist_get_clip_info( mlt_playlist
this, mlt_playlist_clip_info
*info
, int index
)
463 int error
= index
< 0 || index
>= this->count
;
464 memset( info
, 0, sizeof( mlt_playlist_clip_info
) );
467 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ index
]->producer
);
468 mlt_properties properties
= mlt_producer_properties( producer
);
470 info
->producer
= producer
;
471 info
->start
= mlt_playlist_clip( this, mlt_whence_relative_start
, index
);
472 info
->resource
= mlt_properties_get( properties
, "resource" );
473 info
->frame_in
= this->list
[ index
]->frame_in
;
474 info
->frame_out
= this->list
[ index
]->frame_out
;
475 info
->frame_count
= this->list
[ index
]->frame_count
;
476 info
->length
= mlt_producer_get_length( producer
);
477 info
->fps
= mlt_producer_get_fps( producer
);
478 info
->event
= this->list
[ index
]->event
;
481 // Determine the consuming filter service
482 if ( info
->producer
!= NULL
)
484 info
->service
= mlt_producer_service( info
->producer
);
485 while ( mlt_service_consumer( info
->service
) != NULL
)
486 info
->service
= mlt_service_consumer( info
->service
);
492 /** Get number of clips in the playlist.
495 int mlt_playlist_count( mlt_playlist
this )
500 /** Clear the playlist.
503 int mlt_playlist_clear( mlt_playlist
this )
506 for ( i
= 0; i
< this->count
; i
++ )
508 mlt_event_close( this->list
[ i
]->event
);
509 mlt_producer_close( this->list
[ i
]->producer
);
512 mlt_properties_set_double( mlt_playlist_properties( this ), "first_fps", 0 );
513 return mlt_playlist_virtual_refresh( this );
516 /** Append a producer to the playlist.
519 int mlt_playlist_append( mlt_playlist
this, mlt_producer producer
)
521 // Append to virtual list
522 return mlt_playlist_virtual_append( this, producer
, 0, mlt_producer_get_playtime( producer
) - 1 );
525 /** Append a producer to the playlist with in/out points.
528 int mlt_playlist_append_io( mlt_playlist
this, mlt_producer producer
, mlt_position in
, mlt_position out
)
530 // Append to virtual list
531 if ( in
!= -1 && out
!= -1 )
532 return mlt_playlist_virtual_append( this, producer
, in
, out
);
534 return mlt_playlist_append( this, producer
);
537 /** Append a blank to the playlist of a given length.
540 int mlt_playlist_blank( mlt_playlist
this, mlt_position length
)
542 // Append to the virtual list
543 return mlt_playlist_virtual_append( this, &this->blank
, 0, length
);
546 /** Insert a producer into the playlist.
549 int mlt_playlist_insert( mlt_playlist
this, mlt_producer producer
, int where
, mlt_position in
, mlt_position out
)
552 mlt_events_block( mlt_playlist_properties( this ), this );
553 mlt_playlist_append_io( this, producer
, in
, out
);
555 // Move to the position specified
556 mlt_playlist_move( this, this->count
- 1, where
);
557 mlt_events_unblock( mlt_playlist_properties( this ), this );
559 return mlt_playlist_virtual_refresh( this );
562 /** Remove an entry in the playlist.
565 int mlt_playlist_remove( mlt_playlist
this, int where
)
567 int error
= where
< 0 || where
>= this->count
;
568 if ( error
== 0 && mlt_playlist_unmix( this, where
) != 0 )
570 // We need to know the current clip and the position within the playlist
571 int current
= mlt_playlist_current_clip( this );
572 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
574 // We need all the details about the clip we're removing
575 mlt_playlist_clip_info where_info
;
576 playlist_entry
*entry
= this->list
[ where
];
582 mlt_playlist_get_clip_info( this, &where_info
, where
);
584 // Make sure the clip to be removed is valid and correct if necessary
587 if ( where
>= this->count
)
588 where
= this->count
- 1;
590 // Close the producer associated to the clip info
591 mlt_event_close( entry
->event
);
592 mlt_producer_close( entry
->producer
);
593 if ( entry
->mix_in
!= NULL
)
594 entry
->mix_in
->mix_out
= NULL
;
595 if ( entry
->mix_out
!= NULL
)
596 entry
->mix_out
->mix_in
= NULL
;
598 // Reorganise the list
599 for ( i
= where
+ 1; i
< this->count
; i
++ )
600 this->list
[ i
- 1 ] = this->list
[ i
];
604 if ( where
== current
)
605 mlt_producer_seek( mlt_playlist_producer( this ), where_info
.start
);
606 else if ( where
< current
&& this->count
> 0 )
607 mlt_producer_seek( mlt_playlist_producer( this ), position
- where_info
.frame_count
);
608 else if ( this->count
== 0 )
609 mlt_producer_seek( mlt_playlist_producer( this ), 0 );
614 // Refresh the playlist
615 mlt_playlist_virtual_refresh( this );
621 /** Move an entry in the playlist.
624 int mlt_playlist_move( mlt_playlist
this, int src
, int dest
)
628 /* We need to ensure that the requested indexes are valid and correct it as necessary */
631 if ( src
>= this->count
)
632 src
= this->count
- 1;
636 if ( dest
>= this->count
)
637 dest
= this->count
- 1;
639 if ( src
!= dest
&& this->count
> 1 )
641 int current
= mlt_playlist_current_clip( this );
642 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
643 playlist_entry
*src_entry
= NULL
;
645 // We need all the details about the current clip
646 mlt_playlist_clip_info current_info
;
648 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
649 position
-= current_info
.start
;
651 if ( current
== src
)
653 else if ( current
> src
&& current
< dest
)
655 else if ( current
== dest
)
658 src_entry
= this->list
[ src
];
661 for ( i
= src
; i
> dest
; i
-- )
662 this->list
[ i
] = this->list
[ i
- 1 ];
666 for ( i
= src
; i
< dest
; i
++ )
667 this->list
[ i
] = this->list
[ i
+ 1 ];
669 this->list
[ dest
] = src_entry
;
671 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
672 mlt_producer_seek( mlt_playlist_producer( this ), current_info
.start
+ position
);
673 mlt_playlist_virtual_refresh( this );
679 /** Resize the current clip.
682 int mlt_playlist_resize_clip( mlt_playlist
this, int clip
, mlt_position in
, mlt_position out
)
684 int error
= clip
< 0 || clip
>= this->count
;
685 if ( error
== 0 && mlt_playlist_resize_mix( this, clip
, in
, out
) != 0 )
687 playlist_entry
*entry
= this->list
[ clip
];
688 mlt_producer producer
= entry
->producer
;
692 if ( out
<= -1 || out
>= mlt_producer_get_length( producer
) )
693 out
= mlt_producer_get_length( producer
) - 1;
702 mlt_producer_set_in_and_out( producer
, in
, out
);
707 /** Split a clip on the playlist at the given position.
710 int mlt_playlist_split( mlt_playlist
this, int clip
, mlt_position position
)
712 int error
= clip
< 0 || clip
>= this->count
;
715 playlist_entry
*entry
= this->list
[ clip
];
716 if ( position
> 0 && position
< entry
->frame_count
)
718 mlt_producer parent
= mlt_producer_cut_parent( entry
->producer
);
719 mlt_producer split
= NULL
;
720 int in
= entry
->frame_in
;
721 int out
= entry
->frame_out
;
722 mlt_events_block( mlt_playlist_properties( this ), this );
723 mlt_playlist_resize_clip( this, clip
, in
, in
+ position
);
724 split
= mlt_producer_cut( parent
, in
+ position
+ 1, out
);
725 mlt_playlist_insert( this, split
, clip
+ 1, -1, -1 );
726 mlt_events_unblock( mlt_playlist_properties( this ), this );
727 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
737 /** Join 1 or more consecutive clips.
740 int mlt_playlist_join( mlt_playlist
this, int clip
, int count
, int merge
)
742 int error
= clip
< 0 || ( clip
+ 1 ) >= this->count
;
746 mlt_playlist new_clip
= mlt_playlist_init( );
747 mlt_events_block( mlt_playlist_properties( this ), this );
748 if ( clip
+ count
>= this->count
)
749 count
= this->count
- clip
;
750 for ( i
= 0; i
<= count
; i
++ )
752 playlist_entry
*entry
= this->list
[ clip
];
753 mlt_playlist_append( new_clip
, entry
->producer
);
754 mlt_playlist_remove( this, clip
);
756 mlt_events_unblock( mlt_playlist_properties( this ), this );
757 mlt_playlist_insert( this, mlt_playlist_producer( new_clip
), clip
, 0, -1 );
758 mlt_playlist_close( new_clip
);
763 int mlt_playlist_mix( mlt_playlist
this, int clip
, int length
, mlt_transition transition
)
765 int error
= ( clip
< 0 || clip
+ 1 >= this->count
) && this->list
[ clip
]->mix_out
!= NULL
;
768 playlist_entry
*clip_a
= this->list
[ clip
];
769 playlist_entry
*clip_b
= this->list
[ clip
+ 1 ];
770 mlt_producer track_a
;
771 mlt_producer track_b
;
772 mlt_tractor tractor
= mlt_tractor_new( );
773 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
);
778 track_a
= mlt_producer_cut( mlt_producer_cut_parent( clip_a
->producer
), clip_a
->frame_out
+ 1, clip_a
->frame_out
+ length
);
779 track_b
= mlt_producer_cut( mlt_producer_cut_parent( clip_b
->producer
), clip_b
->frame_in
- length
, clip_b
->frame_in
- 1 );
780 mlt_tractor_set_track( tractor
, track_a
, 0 );
781 mlt_tractor_set_track( tractor
, track_b
, 1 );
782 mlt_playlist_insert( this, mlt_tractor_producer( tractor
), clip
+ 1, -1, -1 );
783 mlt_properties_set_data( mlt_tractor_properties( tractor
), "mlt_mix", tractor
, 0, NULL
, NULL
);
785 if ( transition
!= NULL
)
787 mlt_field field
= mlt_tractor_field( tractor
);
788 mlt_field_plant_transition( field
, transition
, 0, 1 );
789 mlt_transition_set_in_and_out( transition
, 0, length
- 1 );
792 if ( clip_b
->frame_count
<= 0 )
793 mlt_playlist_remove( this, clip
+ 2 );
795 if ( clip_a
->frame_count
<= 0 )
796 mlt_playlist_remove( this, clip
);
798 mlt_events_unblock( mlt_playlist_properties( this ), this );
799 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
800 mlt_producer_close( track_a
);
801 mlt_producer_close( track_b
);
802 mlt_tractor_close( tractor
);
807 static int mlt_playlist_unmix( mlt_playlist
this, int clip
)
809 int error
= ( clip
< 0 || clip
>= this->count
);
811 // Ensure that the clip request is actually a mix
814 mlt_producer producer
= this->list
[ clip
]->producer
;
815 mlt_properties properties
= mlt_producer_properties( producer
);
816 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
821 playlist_entry
*mix
= this->list
[ clip
];
822 playlist_entry
*clip_a
= mix
->mix_in
;
823 playlist_entry
*clip_b
= mix
->mix_out
;
824 int length
= mix
->mix_in_length
;
825 mlt_events_block( mlt_playlist_properties( this ), this );
827 if ( clip_a
!= NULL
)
829 clip_a
->frame_out
+= length
;
830 clip_a
->frame_count
+= length
;
831 clip_a
->mix_out
= NULL
;
832 clip_a
->mix_out_length
= 0;
836 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
837 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 0 );
838 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
839 mlt_playlist_insert( this, producer
, clip
, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
843 if ( clip_b
!= NULL
)
845 clip_b
->frame_in
-= length
;
846 clip_b
->frame_count
+= length
;
847 clip_b
->mix_in
= NULL
;
848 clip_b
->mix_in_length
= 0;
852 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
853 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 1 );
854 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
855 mlt_playlist_insert( this, producer
, clip
+ 1, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
858 mlt_properties_set_int( mlt_producer_properties( mix
->producer
), "mlt_mix", 0 );
859 mlt_playlist_remove( this, clip
);
860 mlt_events_unblock( mlt_playlist_properties( this ), this );
861 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
866 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
)
868 int error
= ( clip
< 0 || clip
>= this->count
);
870 // Ensure that the clip request is actually a mix
873 mlt_producer producer
= this->list
[ clip
]->producer
;
874 mlt_properties properties
= mlt_producer_properties( producer
);
875 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
880 playlist_entry
*mix
= this->list
[ clip
];
881 playlist_entry
*clip_a
= mix
->mix_in
;
882 playlist_entry
*clip_b
= mix
->mix_out
;
883 int length
= out
- in
+ 1;
884 int length_diff
= length
- mix
->mix_in_length
;
885 mlt_events_block( mlt_playlist_properties( this ), this );
887 if ( clip_a
!= NULL
)
889 clip_a
->frame_out
-= length_diff
;
890 clip_a
->frame_count
-= length_diff
;
891 clip_a
->mix_out_length
-= length_diff
;
894 if ( clip_b
!= NULL
)
896 clip_b
->frame_in
+= length_diff
;
897 clip_b
->frame_count
-= length_diff
;
898 clip_b
->mix_in_length
-= length_diff
;
902 mix
->frame_out
= length
- 1;
903 mix
->frame_count
= length
;
904 mix
->mix_in_length
= length
;
905 mix
->mix_out_length
= length
;
907 mlt_events_unblock( mlt_playlist_properties( this ), this );
908 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
913 /** Get the current frame.
916 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
918 // Get this mlt_playlist
919 mlt_playlist
this = producer
->child
;
921 // Get the real producer
922 mlt_service real
= mlt_playlist_virtual_seek( this );
925 mlt_service_get_frame( real
, frame
, index
);
927 // Check if we're at the end of the clip
928 mlt_properties properties
= mlt_frame_properties( *frame
);
929 if ( mlt_properties_get_int( properties
, "end_of_clip" ) )
930 mlt_playlist_virtual_set_out( this );
932 // Check for notifier and call with appropriate argument
933 mlt_properties playlist_properties
= mlt_producer_properties( producer
);
934 void ( *notifier
)( void * ) = mlt_properties_get_data( playlist_properties
, "notifier", NULL
);
935 if ( notifier
!= NULL
)
937 void *argument
= mlt_properties_get_data( playlist_properties
, "notifier_arg", NULL
);
938 notifier( argument
);
941 // Update position on the frame we're creating
942 mlt_frame_set_position( *frame
, mlt_producer_frame( producer
) );
944 // Position ourselves on the next frame
945 mlt_producer_prepare_next( producer
);
950 /** Close the playlist.
953 void mlt_playlist_close( mlt_playlist
this )
955 if ( this != NULL
&& mlt_properties_dec_ref( mlt_playlist_properties( this ) ) <= 0 )
958 this->parent
.close
= NULL
;
959 for ( i
= 0; i
< this->count
; i
++ )
961 mlt_event_close( this->list
[ i
]->event
);
962 mlt_producer_close( this->list
[ i
]->producer
);
963 free( this->list
[ i
] );
965 mlt_producer_close( &this->blank
);
966 mlt_producer_close( &this->parent
);