Incorrect Behaviour
------------------------------------------------------------------------------
-CLEAN removes all clips (as opposed to leaving the currently playing one)
Different Intentional Behaviour
#include <stdlib.h>
#include <string.h>
-typedef struct
-{
- mlt_image_format vfmt;
- int width;
- int height;
- uint8_t *image;
- uint8_t *alpha;
- mlt_audio_format afmt;
- int16_t *audio;
-}
-frame_test;
-
-static frame_test test_card = { mlt_image_none, 0, 0, NULL, NULL, mlt_audio_none, NULL };
-
/** Constructor for a frame.
*/
int mlt_frame_is_test_card( mlt_frame this )
{
- return ( this->stack_get_image_size == 0 && mlt_properties_get_data( mlt_frame_properties( this ), "image", NULL ) == NULL );
+ return mlt_properties_get_int( mlt_frame_properties( this ), "test_image" );
}
/** Check if we have a way to derive something than test audio.
int mlt_frame_is_test_audio( mlt_frame this )
{
- return this->get_audio == NULL;
+ return this->get_audio == NULL || mlt_properties_get_int( mlt_frame_properties( this ), "test_audio" );
}
/** Get the aspect ratio of the frame.
}
else
{
- if ( test_card.vfmt != *format || test_card.width != *width || test_card.height != *height || test_card.image == NULL )
- {
- uint8_t *p;
- uint8_t *q;
-
- test_card.vfmt = *format;
- test_card.width = *width == 0 ? 720 : *width;
- test_card.height = *height == 0 ? 576 : *height;
-
- switch( *format )
- {
- case mlt_image_none:
- break;
- case mlt_image_rgb24:
- test_card.image = realloc( test_card.image, test_card.width * test_card.height * 3 );
- memset( test_card.image, 255, test_card.width * test_card.height * 3 );
- break;
- case mlt_image_rgb24a:
- test_card.image = realloc( test_card.image, test_card.width * test_card.height * 4 );
- memset( test_card.image, 255, test_card.width * test_card.height * 4 );
- break;
- case mlt_image_yuv422:
- test_card.image = realloc( test_card.image, test_card.width * test_card.height * 2 );
- p = test_card.image;
- q = test_card.image + test_card.width * test_card.height * 2;
- while ( p != q )
- {
- *p ++ = 255;
- *p ++ = 128;
- }
- break;
- case mlt_image_yuv420p:
- test_card.image = realloc( test_card.image, test_card.width * test_card.height * 3 / 2 );
- memset( test_card.image, 255, test_card.width * test_card.height * 3 / 2 );
- break;
- }
- }
+ uint8_t *p;
+ uint8_t *q;
+ int size = 0;
- *width = test_card.width;
- *height = test_card.height;
- *buffer = test_card.image;
+ *width = *width == 0 ? 720 : *width;
+ *height = *height == 0 ? 576 : *height;
+ size = *width * *height;
mlt_properties_set_int( properties, "width", *width );
mlt_properties_set_int( properties, "height", *height );
- if ( writable )
+ switch( *format )
{
- uint8_t *copy = malloc( *width * *height * 2 );
- memcpy( copy, *buffer, *width * *height * 2 );
- mlt_properties_set_data( properties, "image", copy, *width * *height * 2, free, NULL );
- *buffer = copy;
- }
- else
- {
- mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
+ case mlt_image_none:
+ size = 0;
+ *buffer = NULL;
+ break;
+ case mlt_image_rgb24:
+ size *= 3;
+ *buffer = malloc( size );
+ if ( *buffer )
+ memset( *buffer, 255, size );
+ break;
+ case mlt_image_rgb24a:
+ size *= 4;
+ *buffer = malloc( size );
+ if ( *buffer )
+ memset( *buffer, 255, size );
+ break;
+ case mlt_image_yuv422:
+ size *= 2;
+ *buffer = malloc( size );
+ p = *buffer;
+ q = p + size;
+ while ( p != NULL && p != q )
+ {
+ *p ++ = 255;
+ *p ++ = 128;
+ }
+ break;
+ case mlt_image_yuv420p:
+ size = size * 3 / 2;
+ *buffer = malloc( size );
+ if ( *buffer )
+ memset( *buffer, 255, size );
+ break;
}
+
+ mlt_properties_set_data( properties, "image", *buffer, size, free, NULL );
+ mlt_properties_set_int( properties, "test_image", 1 );
}
return 0;
{
if ( this->get_alpha_mask != NULL )
return this->get_alpha_mask( this );
- return test_card.alpha;
+ return NULL;
}
int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
+ mlt_properties properties = mlt_frame_properties( this );
+
if ( this->get_audio != NULL )
{
return this->get_audio( this, buffer, format, frequency, channels, samples );
}
else
{
- if ( *samples <= 0 )
- *samples = 1920;
- if ( *channels <= 0 )
- *channels = 2;
- if ( *frequency <= 0 )
- *frequency = 48000;
- if ( test_card.audio == NULL || test_card.afmt != *format )
- {
- test_card.afmt = *format;
- test_card.audio = realloc( test_card.audio, *samples * *channels * sizeof( int16_t ) );
- memset( test_card.audio, 0, *samples * *channels * sizeof( int16_t ) );
- }
-
- *buffer = test_card.audio;
+ int size = 0;
+ *samples = *samples <= 0 ? 1920 : *samples;
+ *channels = *channels <= 0 ? 2 : *channels;
+ *frequency = *frequency <= 0 ? 48000 : *frequency;
+ size = *samples * *channels * sizeof( int16_t );
+ *buffer = malloc( size );
+ if ( *buffer != NULL )
+ memset( *buffer, 0, size );
+ mlt_properties_set_data( properties, "audio", *buffer, size, free, NULL );
+ mlt_properties_set_int( properties, "test_audio", 1 );
}
return 0;
}
return this;
}
+static char *strip_root( miracle_unit unit, char *file )
+{
+ mlt_properties properties = unit->properties;
+ char *root = mlt_properties_get( properties, "root" );
+ if ( file != NULL && root != NULL )
+ {
+ int length = strlen( root );
+ if ( root[ length - 1 ] == '/' )
+ length --;
+ if ( !strncmp( file, root, length ) )
+ file += length;
+ }
+ return file;
+}
+
/** Communicate the current status to all threads waiting on the notifier.
*/
update_generation( unit );
}
+/** Wipe all but the playing clip from the unit.
+*/
+
+static void clean_unit( miracle_unit unit )
+{
+ mlt_properties properties = unit->properties;
+ mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
+ mlt_playlist_clip_info info;
+ int current = mlt_playlist_current_clip( playlist );
+ mlt_producer producer = mlt_playlist_producer( playlist );
+ mlt_position position = mlt_producer_frame( producer );
+ double speed = mlt_producer_get_speed( producer );
+ mlt_playlist_get_clip_info( playlist, &info, current );
+
+ if ( info.resource != NULL )
+ {
+ void *instance = mlt_properties_get_data( unit->producers, info.resource, NULL );
+ position -= info.start;
+ mlt_properties_set_data( unit->producers, info.resource, instance, 0, NULL, NULL );
+ clear_unit( unit );
+ mlt_playlist_append_io( playlist, instance, info.frame_in, info.frame_out );
+ mlt_properties_set_data( unit->producers, info.resource, instance, 0, ( mlt_destructor )mlt_producer_close, NULL );
+ mlt_producer_seek( producer, position );
+ mlt_producer_set_speed( producer, speed );
+ }
+
+ update_generation( unit );
+}
+
/** Generate a report on all loaded clips.
*/
{
int i;
mlt_properties properties = unit->properties;
- char *root_dir = mlt_properties_get( properties, "root" );
int generation = mlt_properties_get_int( properties, "generation" );
mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
{
mlt_playlist_clip_info info;
mlt_playlist_get_clip_info( playlist , &info, i );
- char *resource = info.resource;
- if ( root_dir != NULL && !strncmp( resource, root_dir, strlen( root_dir ) ) )
- resource += strlen( root_dir );
valerie_response_printf( response, 10240, "%d \"%s\" %lld %lld %lld %lld %.2f\n",
- i, resource,
+ i,
+ strip_root( unit, info.resource ),
info.frame_in,
info.frame_out,
info.frame_count,
{
mlt_properties properties = unit->properties;
mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
+ fprintf( stderr, "inserting clip %s before %d\n", clip, index );
mlt_playlist_insert( playlist, instance, index, in, out );
miracle_log( LOG_DEBUG, "inserted clip %s at %d", clip, index );
update_generation( unit );
valerie_error_code miracle_unit_clean( miracle_unit unit )
{
- clear_unit( unit );
+ clean_unit( unit );
miracle_log( LOG_DEBUG, "Cleaned playlist" );
miracle_unit_status_communicate( unit );
return valerie_ok;
int miracle_unit_transfer( miracle_unit dest_unit, miracle_unit src_unit )
{
+ int i;
+ mlt_properties dest_properties = dest_unit->properties;
+ mlt_playlist dest_playlist = mlt_properties_get_data( dest_properties, "playlist", NULL );
+ mlt_properties src_properties = src_unit->properties;
+ mlt_playlist src_playlist = mlt_properties_get_data( src_properties, "playlist", NULL );
+
+ for ( i = 0; i < mlt_playlist_count( src_playlist ); i ++ )
+ {
+ mlt_playlist_clip_info info;
+ mlt_playlist_get_clip_info( src_playlist, &info, i );
+ mlt_producer producer = locate_producer( dest_unit, info.resource );
+ if ( producer != NULL )
+ {
+ mlt_playlist_append_io( dest_playlist, producer, info.frame_in, info.frame_out );
+ if ( i == 0 )
+ {
+ miracle_unit_change_position( dest_unit, mlt_playlist_count( dest_playlist ) - 1, 0 );
+ clean_unit( dest_unit );
+ }
+ }
+ }
+
return 0;
}
if ( !error )
{
mlt_properties properties = unit->properties;
- char *root_dir = mlt_properties_get( properties, "root" );
mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
mlt_producer producer = mlt_playlist_producer( playlist );
mlt_producer clip = mlt_playlist_current( playlist );
if ( info.resource != NULL && strcmp( info.resource, "" ) )
{
- if ( root_dir == NULL || strncmp( info.resource, root_dir, strlen( root_dir ) ) )
- strncpy( status->clip, info.resource, sizeof( status->clip ) );
- else
- strncpy( status->clip, info.resource + strlen( root_dir ), sizeof( status->clip ) );
+ strncpy( status->clip, strip_root( unit, info.resource ), sizeof( status->clip ) );
status->speed = (int)( mlt_producer_get_speed( producer ) * 1000.0 );
status->fps = mlt_producer_get_fps( producer );
status->in = info.frame_in;
status->out = info.frame_out;
status->position = mlt_producer_position( clip );
status->length = mlt_producer_get_length( clip );
- if ( root_dir == NULL || strncmp( info.resource, root_dir, strlen( root_dir ) ) )
- strncpy( status->tail_clip, info.resource, sizeof( status->tail_clip ) );
- else
- strncpy( status->clip, info.resource + strlen( root_dir ), sizeof( status->clip ) );
+ strncpy( status->tail_clip, strip_root( unit, info.resource ), sizeof( status->tail_clip ) );
status->tail_in = info.frame_in;
status->tail_out = info.frame_out;
status->tail_position = mlt_producer_position( clip );
int miracle_transfer( command_argument cmd_arg )
{
- /*
- dv_unit src_unit = miracle_get_unit(cmd_arg->unit);
+ miracle_unit src_unit = miracle_get_unit(cmd_arg->unit);
int dest_unit_id = -1;
char *string = (char*) cmd_arg->argument;
if ( string != NULL && ( string[ 0 ] == 'U' || string[ 0 ] == 'u' ) && strlen( string ) > 1 )
if ( src_unit != NULL && dest_unit_id != -1 )
{
- dv_unit dest_unit = miracle_get_unit( dest_unit_id );
- if ( dest_unit != NULL && !dv_unit_is_offline(dest_unit) && dest_unit != src_unit )
+ miracle_unit dest_unit = miracle_get_unit( dest_unit_id );
+ if ( dest_unit != NULL && !miracle_unit_is_offline(dest_unit) && dest_unit != src_unit )
{
- dv_unit_transfer( dest_unit, src_unit );
+ miracle_unit_transfer( dest_unit, src_unit );
return RESPONSE_SUCCESS;
}
}
- */
return RESPONSE_INVALID_UNIT;
}
// This will hold the size of the dv frame
int size = 0;
- // determine if this a test card
- int is_test = mlt_frame_is_test_card( frame );
-
// If we get an encoder, then encode the image
if ( encoder != NULL )
{
int width = mlt_properties_get_int( this_properties, "width" );
int height = mlt_properties_get_int( this_properties, "height" );
uint8_t *image = NULL;
+ int is_test = 0;
if ( mlt_properties_get( this_properties, "rescale" ) != NULL )
mlt_properties_set( mlt_frame_properties( frame ), "rescale.interp", mlt_properties_get( this_properties, "rescale" ) );
// Get the image
mlt_frame_get_image( frame, &image, &fmt, &width, &height, 0 );
+ // determine if this a test card
+ is_test = mlt_frame_is_test_card( frame );
+
// Check that we get what we expected
if ( fmt != mlt_image_yuv422 ||
width != mlt_properties_get_int( this_properties, "width" ) ||
// Process the frame
if ( size != 0 && !( mlt_properties_get_int( this_properties, "was_test_card" ) && is_test ) )
{
- if ( mlt_properties_get_int( mlt_frame_properties( frame ), "top_field_first" ) == 0 )
+ if ( mlt_properties_get_int( mlt_frame_properties( frame ), "top_field_first" ) )
image += width * 2;
// Encode the image
// Get the properties of the consumer
mlt_properties this_properties = mlt_consumer_properties( this );
+ // Get the properties of the frame
+ mlt_properties frame_properties = mlt_frame_properties( frame );
+
// Obtain the dv_encoder
dv_encoder_t *encoder = libdv_get_encoder( this, frame );
time_t start = time( NULL );
int height = mlt_properties_get_int( this_properties, "height" );
int is_pal = height == 576;
- int is_wide = 0;
+ int is_wide = mlt_properties_get_double( frame_properties, "fps" ) == ( ( double ) 16.0 / 9.0 );
// Temporary - audio buffer allocation
int16_t *audio_buffers[ 4 ];
int i = 0;
int j = 0;
for ( i = 0 ; i < 4; i ++ )
- audio_buffers[ i ] = malloc( 2 * DV_AUDIO_MAX_SAMPLES );
+ audio_buffers[ i ] = calloc( 1, 2 * DV_AUDIO_MAX_SAMPLES );
// Get the audio
mlt_frame_get_audio( frame, &pcm, &fmt, &frequency, &channels, &samples );
encoder->samples_this_frame = samples;
// Fill the audio buffers correctly
- for ( i = 0; i < samples; i ++ )
- for ( j = 0; j < channels; j++ )
- audio_buffers[ j ][ i ] = *pcm ++;
+ if ( mlt_properties_get_double( frame_properties, "_speed" ) == 1.0 )
+ {
+ for ( i = 0; i < samples; i ++ )
+ for ( j = 0; j < channels; j++ )
+ audio_buffers[ j ][ i ] = *pcm ++;
+ }
// Encode audio on frame
dv_encode_full_audio( encoder, audio_buffers, channels, frequency, dv_frame );
valerie_notifier valerie_notifier_init( )
{
- valerie_notifier this = malloc( sizeof( valerie_notifier_t ) );
+ valerie_notifier this = calloc( 1, sizeof( valerie_notifier_t ) );
if ( this != NULL )
{
int index = 0;
- memset( this, 0, sizeof( valerie_notifier_t ) );
pthread_mutex_init( &this->mutex, NULL );
pthread_cond_init( &this->cond, NULL );
- pthread_mutex_init( &this->cond_mutex, NULL );
for ( index = 0; index < MAX_UNITS; index ++ )
this->store[ index ].unit = index;
}
{
pthread_mutex_lock( &this->mutex );
if ( unit >= 0 && unit < MAX_UNITS )
- {
valerie_status_copy( status, &this->store[ unit ] );
- }
else
- {
memset( status, 0, sizeof( valerie_status_t ) );
- status->unit = unit;
- }
+ status->unit = unit;
status->dummy = time( NULL );
pthread_mutex_unlock( &this->mutex );
}
int error = 0;
memset( status, 0, sizeof( valerie_status_t ) );
-
- pthread_mutex_lock( &this->cond_mutex );
gettimeofday( &now, NULL );
timeout.tv_sec = now.tv_sec + 1;
timeout.tv_nsec = now.tv_usec * 1000;
- if ( pthread_cond_timedwait( &this->cond, &this->cond_mutex, &timeout ) != ETIMEDOUT )
- {
- pthread_mutex_lock( &this->mutex );
- valerie_status_copy( status, &this->last );
- pthread_mutex_unlock( &this->mutex );
- }
- else
- {
- pthread_mutex_lock( &this->mutex );
- valerie_status_copy( status, &this->last );
- pthread_mutex_unlock( &this->mutex );
- }
- pthread_mutex_unlock( &this->cond_mutex );
+ pthread_mutex_lock( &this->mutex );
+ pthread_cond_timedwait( &this->cond, &this->mutex, &timeout );
+ valerie_status_copy( status, &this->last );
+ pthread_mutex_unlock( &this->mutex );
return error;
}
if ( this != NULL )
{
pthread_mutex_destroy( &this->mutex );
- pthread_mutex_destroy( &this->cond_mutex );
pthread_cond_destroy( &this->cond );
free( this );
}
typedef struct
{
pthread_mutex_t mutex;
- pthread_mutex_t cond_mutex;
pthread_cond_t cond;
valerie_status_t last;
valerie_status_t store[ MAX_UNITS ];