-/*
- * mlt_playlist.c -- playlist service class
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
+/**
+ * \file mlt_playlist.c
+ * \brief playlist service class
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
+ * \author Charles Yates <charles.yates@pandora.be>
*
- * This program is distributed in the hope that it will be useful,
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "config.h"
-
#include "mlt_playlist.h"
#include "mlt_tractor.h"
#include "mlt_multitrack.h"
#include <stdlib.h>
#include <string.h>
-/** Virtual playlist entry.
+/** \brief virtual playlist entry
*/
struct playlist_entry_s
this->size = 10;
this->list = malloc( this->size * sizeof( playlist_entry * ) );
}
-
+
return this;
}
{
// Obtain the properties
mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
-
- // Get the fps of the first producer
- double fps = mlt_properties_get_double( properties, "first_fps" );
int i = 0;
mlt_position frame_count = 0;
{
// Get the producer
mlt_producer producer = this->list[ i ]->producer;
- int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
-
- // If fps is 0
- if ( fps == 0 )
+ if ( producer )
{
- // Inherit it from the producer
- fps = mlt_producer_get_fps( producer );
- }
- else if ( fps != mlt_properties_get_double( MLT_PRODUCER_PROPERTIES( producer ), "fps" ) )
- {
- // Generate a warning for now - the following attempt to fix may fail
- fprintf( stderr, "Warning: fps mismatch on playlist producer %d\n", this->count );
+ int current_length = mlt_producer_get_out( producer ) - mlt_producer_get_in( producer ) + 1;
- // It should be safe to impose fps on an image producer, but not necessarily safe for video
- mlt_properties_set_double( MLT_PRODUCER_PROPERTIES( producer ), "fps", fps );
- }
-
- // Check if the length of the producer has changed
- if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
- this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
- {
- // This clip should be removed...
- if ( current_length < 1 )
+ // Check if the length of the producer has changed
+ if ( this->list[ i ]->frame_in != mlt_producer_get_in( producer ) ||
+ this->list[ i ]->frame_out != mlt_producer_get_out( producer ) )
{
- this->list[ i ]->frame_in = 0;
- this->list[ i ]->frame_out = -1;
- this->list[ i ]->frame_count = 0;
- }
- else
- {
- this->list[ i ]->frame_in = mlt_producer_get_in( producer );
- this->list[ i ]->frame_out = mlt_producer_get_out( producer );
- this->list[ i ]->frame_count = current_length;
- }
+ // This clip should be removed...
+ if ( current_length < 1 )
+ {
+ this->list[ i ]->frame_in = 0;
+ this->list[ i ]->frame_out = -1;
+ this->list[ i ]->frame_count = 0;
+ }
+ else
+ {
+ this->list[ i ]->frame_in = mlt_producer_get_in( producer );
+ this->list[ i ]->frame_out = mlt_producer_get_out( producer );
+ this->list[ i ]->frame_count = current_length;
+ }
- // Update the producer_length
- this->list[ i ]->producer_length = current_length;
+ // Update the producer_length
+ this->list[ i ]->producer_length = current_length;
+ }
}
// Calculate the frame_count
}
// Refresh all properties
- mlt_properties_set_double( properties, "first_fps", fps );
- mlt_properties_set_double( properties, "fps", fps == 0 ? 25 : fps );
mlt_events_block( properties, properties );
mlt_properties_set_position( properties, "length", frame_count );
mlt_events_unblock( properties, properties );
mlt_service_detach( service, filter );
filter = mlt_service_filter( service, 0 );
}
+ mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer ), "meta.fx_cut", 1 );
}
// Check that we have room
// Get the properties
mlt_properties properties = MLT_PLAYLIST_PROPERTIES( this );
+ // Automatically close previous producers if requested
+ if ( i > 1 // keep immediate previous in case app wants to get info about what just finished
+ && position < 2 // tolerate off-by-one error on going to next clip
+ && mlt_properties_get_int( properties, "autoclose" ) )
+ {
+ int j;
+ // They might have jumped ahead!
+ for ( j = 0; j < i - 1; j++ )
+ {
+ mlt_service_lock( MLT_PRODUCER_SERVICE( this->list[ j ]->producer ) );
+ mlt_producer p = this->list[ j ]->producer;
+ if ( p )
+ {
+ this->list[ j ]->producer = NULL;
+ mlt_service_unlock( MLT_PRODUCER_SERVICE( p ) );
+ mlt_producer_close( p );
+ }
+ // If p is null, the lock will not have been "taken"
+ }
+ }
+
// Get the eof handling
char *eof = mlt_properties_get( properties, "eof" );
{
int count = this->list[ i ]->frame_count / this->list[ i ]->repeat;
*progressive = count == 1;
- mlt_producer_seek( producer, position % count );
+ mlt_producer_seek( producer, (int)position % count );
}
else if ( !strcmp( eof, "pause" ) && total > 0 )
{
mlt_producer this_producer = MLT_PLAYLIST_PRODUCER( this );
mlt_producer_seek( this_producer, original - 1 );
producer = entry->producer;
- mlt_producer_seek( producer, entry->frame_out % count );
+ mlt_producer_seek( producer, (int)entry->frame_out % count );
mlt_producer_set_speed( this_producer, 0 );
mlt_producer_set_speed( producer, 0 );
*progressive = count == 1;
int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index )
{
- int error = index < 0 || index >= this->count;
+ int error = index < 0 || index >= this->count || this->list[ index ]->producer == NULL;
memset( info, 0, sizeof( mlt_playlist_clip_info ) );
if ( !error )
{
mlt_producer_close( this->list[ i ]->producer );
}
this->count = 0;
- mlt_properties_set_double( MLT_PLAYLIST_PROPERTIES( this ), "first_fps", 0 );
return mlt_playlist_virtual_refresh( this );
}
int mlt_playlist_blank( mlt_playlist this, mlt_position length )
{
// Append to the virtual list
- return mlt_playlist_virtual_append( this, &this->blank, 0, length );
+ if (length >= 0)
+ return mlt_playlist_virtual_append( this, &this->blank, 0, length );
+ else
+ return 1;
}
/** Insert a producer into the playlist.
// Loop variable
int i = 0;
- // Get the clip info
+ // Get the clip info
mlt_playlist_get_clip_info( this, &where_info, where );
// Make sure the clip to be removed is valid and correct if necessary
- if ( where < 0 )
+ if ( where < 0 )
where = 0;
if ( where >= this->count )
where = this->count - 1;
mlt_properties mix = mlt_properties_get_data( properties, "mix_out", NULL );
mlt_properties_set_data( mix, "mix_in", NULL, 0, NULL, NULL );
}
-
+
if ( mlt_properties_ref_count( MLT_PRODUCER_PROPERTIES( entry->producer ) ) == 1 )
mlt_producer_clear( entry->producer );
}
int i;
/* We need to ensure that the requested indexes are valid and correct it as necessary */
- if ( src < 0 )
+ if ( src < 0 )
src = 0;
if ( src >= this->count )
src = this->count - 1;
- if ( dest < 0 )
+ if ( dest < 0 )
dest = 0;
if ( dest >= this->count )
dest = this->count - 1;
-
+
if ( src != dest && this->count > 1 )
{
int current = mlt_playlist_current_clip( this );
/** Return the clip at the specified position.
*/
-mlt_producer mlt_playlist_get_clip_at( mlt_playlist this, int position )
+mlt_producer mlt_playlist_get_clip_at( mlt_playlist this, mlt_position position )
{
int index = 0, total = 0;
return mlt_playlist_locate( this, &position, &index, &total );
/** Return the clip index of the specified position.
*/
-int mlt_playlist_get_clip_index_at( mlt_playlist this, int position )
+int mlt_playlist_get_clip_index_at( mlt_playlist this, mlt_position position )
{
int index = 0, total = 0;
mlt_playlist_locate( this, &position, &index, &total );
static int mlt_playlist_unmix( mlt_playlist this, int clip )
{
- int error = ( clip < 0 || clip >= this->count );
+ int error = ( clip < 0 || clip >= this->count );
// Ensure that the clip request is actually a mix
if ( error == 0 )
static int mlt_playlist_resize_mix( mlt_playlist this, int clip, int in, int out )
{
- int error = ( clip < 0 || clip >= this->count );
+ int error = ( clip < 0 || clip >= this->count );
// Ensure that the clip request is actually a mix
if ( error == 0 )
/** Determine if the specified position is a blank.
*/
-int mlt_playlist_is_blank_at( mlt_playlist this, int position )
+int mlt_playlist_is_blank_at( mlt_playlist this, mlt_position position )
{
return this == NULL || mlt_producer_is_blank( mlt_playlist_get_clip_at( this, position ) );
}
}
}
-void mlt_playlist_pad_blanks( mlt_playlist this, int position, int length, int find )
+void mlt_playlist_pad_blanks( mlt_playlist this, mlt_position position, int length, int find )
{
if ( this != NULL && length != 0 )
{
}
}
-int mlt_playlist_insert_at( mlt_playlist this, int position, mlt_producer producer, int mode )
+int mlt_playlist_insert_at( mlt_playlist this, mlt_position position, mlt_producer producer, int mode )
{
int ret = this == NULL || position < 0 || producer == NULL;
if ( ret == 0 )
if ( clip < this->count && mlt_playlist_is_blank( this, clip ) )
{
// Split and move to new clip if need be
- if ( position != info.start && mlt_playlist_split( this, clip, position - info.start ) == 0 )
+ if ( position != info.start && mlt_playlist_split( this, clip, position - info.start - 1 ) == 0 )
mlt_playlist_get_clip_info( this, &info, ++ clip );
// Split again if need be
mlt_playlist_insert( this, producer, clip, -1, -1 );
ret = clip;
}
- else
+ else
{
- if ( mode == 1 )
- mlt_playlist_blank( this, position - mlt_properties_get_int( properties, "length" ) );
+ if ( mode == 1 ) {
+ if ( position == info.start )
+ mlt_playlist_remove( this, clip );
+ else
+ mlt_playlist_blank( this, position - mlt_properties_get_int( properties, "length" ) - 1 );
+ }
mlt_playlist_append( this, producer );
ret = this->count - 1;
}
return count;
}
-int mlt_playlist_remove_region( mlt_playlist this, int position, int length )
+int mlt_playlist_remove_region( mlt_playlist this, mlt_position position, int length )
{
int index = mlt_playlist_get_clip_index_at( this, position );
if ( index >= 0 && index < this->count )
length -= mlt_playlist_clip_length( this, index );
mlt_playlist_remove( this, index );
}
-
+
mlt_playlist_consolidate_blanks( this, 0 );
mlt_events_unblock( properties, this );
mlt_playlist_virtual_refresh( this );
return index;
}
-int mlt_playlist_move_region( mlt_playlist this, int position, int length, int new_position )
+int mlt_playlist_move_region( mlt_playlist this, mlt_position position, int length, int new_position )
{
if ( this != NULL )
{
// Check that we have a producer
if ( producer == NULL )
{
- *frame = mlt_frame_init( );
- return 0;
+ *frame = NULL;
+ return -1;
}
// Get this mlt_playlist
// Check that we have a producer
if ( real == NULL )
{
- *frame = mlt_frame_init( );
+ *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
return 0;
}
// Get the frame
- mlt_service_get_frame( real, frame, index );
+ if ( !mlt_properties_get_int( MLT_SERVICE_PROPERTIES( real ), "meta.fx_cut" ) )
+ {
+ mlt_service_get_frame( real, frame, index );
+ }
+ else
+ {
+ mlt_producer parent = mlt_producer_cut_parent( ( mlt_producer )real );
+ *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( parent ) );
+ mlt_properties_set_int( MLT_FRAME_PROPERTIES( *frame ), "fx_cut", 1 );
+ mlt_frame_push_service( *frame, NULL );
+ mlt_frame_push_audio( *frame, NULL );
+ mlt_service_apply_filters( MLT_PRODUCER_SERVICE( parent ), *frame, 0 );
+ mlt_service_apply_filters( real, *frame, 0 );
+ mlt_deque_pop_front( MLT_FRAME_IMAGE_STACK( *frame ) );
+ mlt_deque_pop_front( MLT_FRAME_AUDIO_STACK( *frame ) );
+ }
// Check if we're at the end of the clip
mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );