From: lilo_booter Date: Wed, 11 Feb 2004 13:09:48 +0000 (+0000) Subject: Miracle mods - clean working, test card fix, silence dv when not playing X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=48377c7457b33c7e08e648d57187cd4a60f78a3d;p=melted Miracle mods - clean working, test card fix, silence dv when not playing git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@133 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/docs/testing-20040110.txt b/docs/testing-20040110.txt index 731f9e8..622300b 100644 --- a/docs/testing-20040110.txt +++ b/docs/testing-20040110.txt @@ -20,7 +20,6 @@ XFER Incorrect Behaviour ------------------------------------------------------------------------------ -CLEAN removes all clips (as opposed to leaving the currently playing one) Different Intentional Behaviour diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 853f9d5..314facd 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -24,20 +24,6 @@ #include #include -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. */ @@ -77,7 +63,7 @@ mlt_properties mlt_frame_properties( mlt_frame this ) 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. @@ -85,7 +71,7 @@ int mlt_frame_is_test_card( mlt_frame this ) 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. @@ -182,62 +168,56 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for } 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; @@ -247,31 +227,29 @@ uint8_t *mlt_frame_get_alpha_mask( mlt_frame this ) { 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; } diff --git a/src/miracle/miracle_unit.c b/src/miracle/miracle_unit.c index 7003717..f784d3a 100644 --- a/src/miracle/miracle_unit.c +++ b/src/miracle/miracle_unit.c @@ -84,6 +84,21 @@ miracle_unit miracle_unit_init( int index, char *constructor ) 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. */ @@ -186,6 +201,35 @@ static void clear_unit( miracle_unit unit ) 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. */ @@ -193,7 +237,6 @@ void miracle_unit_report_list( miracle_unit unit, valerie_response response ) { 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 ); @@ -203,11 +246,9 @@ void miracle_unit_report_list( miracle_unit unit, valerie_response response ) { 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, @@ -253,6 +294,7 @@ valerie_error_code miracle_unit_insert( miracle_unit unit, char *clip, int index { 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 ); @@ -276,7 +318,7 @@ valerie_error_code miracle_unit_remove( miracle_unit unit, int index ) 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; @@ -370,6 +412,28 @@ int miracle_unit_has_terminated( miracle_unit unit ) 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; } @@ -393,7 +457,6 @@ int miracle_unit_get_status( miracle_unit unit, valerie_status status ) 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 ); @@ -404,20 +467,14 @@ int miracle_unit_get_status( miracle_unit unit, valerie_status status ) 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 ); diff --git a/src/miracle/miracle_unit_commands.c b/src/miracle/miracle_unit_commands.c index f38ff3a..4e6fb17 100644 --- a/src/miracle/miracle_unit_commands.c +++ b/src/miracle/miracle_unit_commands.c @@ -400,8 +400,7 @@ int miracle_get_unit_property( command_argument cmd_arg ) 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 ) @@ -409,13 +408,12 @@ int miracle_transfer( command_argument cmd_arg ) 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; } diff --git a/src/modules/dv/consumer_libdv.c b/src/modules/dv/consumer_libdv.c index e9dbb56..3d6f6f1 100644 --- a/src/modules/dv/consumer_libdv.c +++ b/src/modules/dv/consumer_libdv.c @@ -201,9 +201,6 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram // 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 ) { @@ -212,6 +209,7 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram 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" ) ); @@ -219,6 +217,9 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram // 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" ) || @@ -237,7 +238,7 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram // 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 @@ -259,6 +260,9 @@ static void consumer_encode_audio( mlt_consumer this, uint8_t *dv_frame, mlt_fra // 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 ); @@ -279,14 +283,14 @@ static void consumer_encode_audio( mlt_consumer this, uint8_t *dv_frame, mlt_fra 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 ); @@ -295,9 +299,12 @@ static void consumer_encode_audio( mlt_consumer this, uint8_t *dv_frame, mlt_fra 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 ); diff --git a/src/valerie/valerie_notifier.c b/src/valerie/valerie_notifier.c index 9c44650..5e34043 100644 --- a/src/valerie/valerie_notifier.c +++ b/src/valerie/valerie_notifier.c @@ -37,14 +37,12 @@ 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; } @@ -58,14 +56,10 @@ void valerie_notifier_get( valerie_notifier this, valerie_status status, int uni { 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 ); } @@ -80,24 +74,13 @@ int valerie_notifier_wait( valerie_notifier this, valerie_status status ) 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; } @@ -137,7 +120,6 @@ void valerie_notifier_close( valerie_notifier this ) if ( this != NULL ) { pthread_mutex_destroy( &this->mutex ); - pthread_mutex_destroy( &this->cond_mutex ); pthread_cond_destroy( &this->cond ); free( this ); } diff --git a/src/valerie/valerie_notifier.h b/src/valerie/valerie_notifier.h index bc123ed..9751c08 100644 --- a/src/valerie/valerie_notifier.h +++ b/src/valerie/valerie_notifier.h @@ -40,7 +40,6 @@ extern "C" 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 ];