From a07c3da76259d6ba479d800ffecc5617a9ad158f Mon Sep 17 00:00:00 2001 From: ddennedy Date: Tue, 4 Dec 2007 08:04:30 +0000 Subject: [PATCH] mlt_consumer.c, mlt_frame.c, mlt_multitrack.c, mlt_playlist.c, mlt_producer.c, producer_avformat.c, filter_data_show.c, producer_libdv.c, producer_inigo.c, producer_vorbis.c, producer_westley.c: remove statefulness of frame rate through framework and modules, and allow consumer properties to override profile settings. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1040 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_consumer.c | 60 ++++++++++++++++++++++++++++- src/framework/mlt_frame.c | 2 +- src/framework/mlt_multitrack.c | 19 --------- src/framework/mlt_playlist.c | 21 ---------- src/framework/mlt_producer.c | 6 +-- src/modules/avformat/producer_avformat.c | 23 ++++------- src/modules/core/filter_data_show.c | 2 +- src/modules/dv/producer_libdv.c | 4 +- src/modules/inigo/producer_inigo.c | 1 - src/modules/vorbis/producer_vorbis.c | 13 +----- src/modules/westley/producer_westley.c | 4 +- 11 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 0f3264f..eb72540 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -91,6 +91,7 @@ int mlt_consumer_init( mlt_consumer this, void *child ) static void apply_profile_properties( mlt_profile profile, mlt_properties properties ) { + mlt_event_block( g_event_listener ); mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) ); mlt_properties_set_int( properties, "frame_rate_num", profile->frame_rate_num ); mlt_properties_set_int( properties, "frame_rate_den", profile->frame_rate_den ); @@ -103,6 +104,7 @@ static void apply_profile_properties( mlt_profile profile, mlt_properties proper mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) ); mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num ); mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num ); + mlt_event_unblock( g_event_listener ); } static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name ) @@ -115,12 +117,60 @@ static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, // Locate the profile mlt_profile_select( mlt_properties_get( properties, "profile" ) ); - // Stop listening to this - mlt_event_block( g_event_listener ); - // Apply to properties apply_profile_properties( mlt_profile_get(), properties ); } + else if ( !strcmp( name, "frame_rate_num" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" ); + mlt_properties_set_double( properties, "fps", mlt_profile_fps( NULL ) ); + } + else if ( !strcmp( name, "frame_rate_den" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" ); + mlt_properties_set_double( properties, "fps", mlt_profile_fps( NULL ) ); + } + else if ( !strcmp( name, "width" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->width = mlt_properties_get_int( properties, "width" ); + } + else if ( !strcmp( name, "height" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->height = mlt_properties_get_int( properties, "height" ); + } + else if ( !strcmp( name, "progressive" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->progressive = mlt_properties_get_int( properties, "progressive" ); + } + else if ( !strcmp( name, "sample_aspect_num" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->sample_aspect_num = mlt_properties_get_int( properties, "sample_aspect_num" ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( NULL ) ); + } + else if ( !strcmp( name, "sample_aspect_den" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->sample_aspect_den = mlt_properties_get_int( properties, "sample_aspect_den" ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( NULL ) ); + } + else if ( !strcmp( name, "display_aspect_num" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->display_aspect_num = mlt_properties_get_int( properties, "display_aspect_num" ); + mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( NULL ) ); + } + else if ( !strcmp( name, "display_aspect_den" ) ) + { + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + mlt_profile_get()->display_aspect_den = mlt_properties_get_int( properties, "display_aspect_den" ); + mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( NULL ) ); + } } static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) @@ -180,6 +230,9 @@ int mlt_consumer_connect( mlt_consumer this, mlt_service producer ) int mlt_consumer_start( mlt_consumer this ) { + // Stop listening to the property-changed event + mlt_event_block( g_event_listener ); + // Get the properies mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); @@ -658,6 +711,7 @@ void mlt_consumer_stopped( mlt_consumer this ) { mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( this ), "running", 0 ); mlt_events_fire( MLT_CONSUMER_PROPERTIES( this ), "consumer-stopped", NULL ); + mlt_event_unblock( g_event_listener ); } /** Stop the consumer. diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 52de88d..a34579e 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -445,7 +445,7 @@ unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h ) mlt_audio_format format = mlt_audio_pcm; int frequency = 32000; // lower frequency available? int channels = 2; - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_profile_fps( NULL ); int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) ); // Get the pcm data diff --git a/src/framework/mlt_multitrack.c b/src/framework/mlt_multitrack.c index 6b21a2b..929d4bd 100644 --- a/src/framework/mlt_multitrack.c +++ b/src/framework/mlt_multitrack.c @@ -102,9 +102,6 @@ void mlt_multitrack_refresh( mlt_multitrack this ) // We need to ensure that the multitrack reports the longest track as its length mlt_position length = 0; - // We need to ensure that fps are the same on all services - double fps = 0; - // Obtain stats on all connected services for ( i = 0; i < this->count; i ++ ) { @@ -122,21 +119,6 @@ void mlt_multitrack_refresh( mlt_multitrack this ) // Determine the longest length //if ( !mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( producer ), "hide" ) ) length = mlt_producer_get_playtime( producer ) > length ? mlt_producer_get_playtime( producer ) : length; - - // Handle fps - if ( fps == 0 ) - { - // This is the first producer, so it controls the fps - fps = mlt_producer_get_fps( producer ); - } - else if ( fps != mlt_producer_get_fps( producer ) ) - { - // Generate a warning for now - the following attempt to fix may fail - fprintf( stderr, "Warning: fps mismatch on track %d\n", i ); - - // 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 ); - } } } @@ -145,7 +127,6 @@ void mlt_multitrack_refresh( mlt_multitrack this ) mlt_properties_set_position( properties, "length", length ); mlt_events_unblock( properties, properties ); mlt_properties_set_position( properties, "out", length - 1 ); - mlt_properties_set_double( properties, "fps", fps ); } /** Listener for producers on the playlist. diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index eac0642..240c523 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -127,9 +127,6 @@ static int mlt_playlist_virtual_refresh( mlt_playlist 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; @@ -139,21 +136,6 @@ static int mlt_playlist_virtual_refresh( mlt_playlist this ) 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 ) - { - // 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 ); - - // 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 ) ) @@ -184,8 +166,6 @@ static int mlt_playlist_virtual_refresh( mlt_playlist this ) } // 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 ); @@ -561,7 +541,6 @@ int mlt_playlist_clear( mlt_playlist this ) 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 ); } diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index 56d1d3f..5d3963c 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -85,9 +85,6 @@ int mlt_producer_init( mlt_producer this, void *child ) mlt_properties_set( properties, "mlt_type", "mlt_producer" ); mlt_properties_set_position( properties, "_position", 0.0 ); mlt_properties_set_double( properties, "_frame", 0 ); - mlt_properties_set_double( properties, "fps", mlt_profile_fps( NULL ) ); - mlt_properties_set_int( properties, "frame_rate_num", mlt_profile_get()->frame_rate_num ); - mlt_properties_set_int( properties, "frame_rate_den", mlt_profile_get()->frame_rate_den ); mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( NULL ) ); mlt_properties_set_double( properties, "_speed", 1.0 ); mlt_properties_set_position( properties, "in", 0 ); @@ -292,7 +289,7 @@ double mlt_producer_get_speed( mlt_producer this ) double mlt_producer_get_fps( mlt_producer this ) { - return mlt_properties_get_double( MLT_PRODUCER_PROPERTIES( this ), "fps" ); + return mlt_profile_fps( NULL ); } /** Set the in and out points. @@ -440,7 +437,6 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind // Copy the fps and speed of the producer onto the frame properties = MLT_FRAME_PROPERTIES( *frame ); mlt_properties_set_double( properties, "_speed", speed ); - mlt_properties_set_double( properties, "fps", mlt_producer_get_fps( this ) ); mlt_properties_set_int( properties, "test_audio", mlt_frame_is_test_audio( *frame ) ); mlt_properties_set_int( properties, "test_image", mlt_frame_is_test_card( *frame ) ); if ( mlt_properties_get_data( properties, "_producer", NULL ) == NULL ) diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 03b62b6..aad0802 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -165,7 +165,7 @@ static int producer_open( mlt_producer this, char *file ) mlt_properties properties = MLT_PRODUCER_PROPERTIES( this ); // We will treat everything with the producer fps - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_producer_get_fps( this ); // Lock the mutex now avformat_lock( ); @@ -203,11 +203,13 @@ static int producer_open( mlt_producer this, char *file ) params->width = 640; params->height = 480; params->time_base= (AVRational){1,25}; - params->device = file; + // params->device = file; params->channels = 2; params->sample_rate = 48000; } + // XXX: this does not work anymore since avdevice + // TODO: make producer_avddevice? // Parse out params mrl = strchr( file, '?' ); while ( mrl ) @@ -368,14 +370,7 @@ static int producer_open( mlt_producer this, char *file ) static double producer_time_of_frame( mlt_producer this, mlt_position position ) { - // Get the properties - mlt_properties properties = MLT_PRODUCER_PROPERTIES( this ); - - // Obtain the fps - double fps = mlt_properties_get_double( properties, "fps" ); - - // Do the calc - return ( double )position / fps; + return ( double )position / mlt_producer_get_fps( this ); } static inline void convert_image( AVFrame *frame, uint8_t *buffer, int pix_fmt, mlt_image_format format, int width, int height ) @@ -489,7 +484,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form // We may want to use the source fps if available double source_fps = mlt_properties_get_double( properties, "source_fps" ); - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_producer_get_fps( this ); // This is the physical frame position in the source int req_position = ( int )( position / fps * source_fps + 0.5 ); @@ -735,7 +730,7 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame ) } else { - int is_pal = mlt_properties_get_double( properties, "fps" ) == 25.0; + int is_pal = mlt_producer_get_fps( this ) == 25.0; aspect_ratio = is_pal ? 59.0/54.0 : 10.0/11.0; } @@ -743,10 +738,10 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame ) source_fps = ( double )codec_context->time_base.den / ( codec_context->time_base.num == 0 ? 1 : codec_context->time_base.num ); // We'll use fps if it's available - if ( source_fps > 0 && source_fps < 30 ) + if ( source_fps > 0 ) mlt_properties_set_double( properties, "source_fps", source_fps ); else - mlt_properties_set_double( properties, "source_fps", mlt_properties_get_double( properties, "fps" ) ); + mlt_properties_set_double( properties, "source_fps", mlt_producer_get_fps( this ) ); mlt_properties_set_double( properties, "aspect_ratio", aspect_ratio ); // Set the width and height diff --git a/src/modules/core/filter_data_show.c b/src/modules/core/filter_data_show.c index e77ef97..3dfd7cb 100644 --- a/src/modules/core/filter_data_show.c +++ b/src/modules/core/filter_data_show.c @@ -206,7 +206,7 @@ static int process_feed( mlt_properties feed, mlt_filter filter, mlt_frame frame { // special case: replace #timecode# with current frame timecode int pos = mlt_properties_get_int( feed, "position" ); - char *tc = frame_to_timecode( pos, mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "fps" ) ); + char *tc = frame_to_timecode( pos, mlt_profile_fps( NULL ) ); strcat( result, tc ); free( tc ); } diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 0a6189f..a7c10b3 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -163,7 +163,7 @@ mlt_producer producer_libdv_init( char *filename ) destroy = 1; else mlt_properties_pass( properties, MLT_PRODUCER_PROPERTIES( this->alternative ), "" ); - this->is_pal = mlt_properties_get_int( properties, "fps" ) == 25; + this->is_pal = ( ( int ) mlt_producer_get_fps( producer ) ) == 25; } else { @@ -241,7 +241,7 @@ static int producer_collect_info( producer_libdv this ) // Calculate default in/out points double fps = this->is_pal ? 25 : 30000.0 / 1001.0; - if ( mlt_properties_get_double( properties, "fps" ) == fps ) + if ( mlt_producer_get_fps( &this->parent ) == fps ) { if ( this->frames_in_file > 0 ) { diff --git a/src/modules/inigo/producer_inigo.c b/src/modules/inigo/producer_inigo.c index 95e99b2..6de5578 100644 --- a/src/modules/inigo/producer_inigo.c +++ b/src/modules/inigo/producer_inigo.c @@ -435,7 +435,6 @@ mlt_producer producer_inigo_init( char **argv ) mlt_properties_set_data( props, "group", group, 0, ( mlt_destructor )mlt_properties_close, NULL ); mlt_properties_set_position( props, "length", mlt_producer_get_out( MLT_MULTITRACK_PRODUCER( multitrack ) ) + 1 ); mlt_producer_set_in_and_out( prod, 0, mlt_producer_get_out( MLT_MULTITRACK_PRODUCER( multitrack ) ) ); - mlt_properties_set_double( props, "fps", mlt_producer_get_fps( MLT_MULTITRACK_PRODUCER( multitrack ) ) ); if ( title != NULL ) mlt_properties_set( props, "title", strchr( title, '/' ) ? strrchr( title, '/' ) + 1 : title ); diff --git a/src/modules/vorbis/producer_vorbis.c b/src/modules/vorbis/producer_vorbis.c index 328e91e..982808b 100644 --- a/src/modules/vorbis/producer_vorbis.c +++ b/src/modules/vorbis/producer_vorbis.c @@ -164,7 +164,7 @@ static int producer_open( mlt_producer this, char *file ) double length = ov_time_total( ov, -1 ); // We will treat everything with the producer fps - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_producer_get_fps( this ); // Set out and length of file mlt_properties_set_position( properties, "out", ( length * fps ) - 1 ); @@ -194,14 +194,7 @@ static int producer_open( mlt_producer this, char *file ) static double producer_time_of_frame( mlt_producer this, mlt_position position ) { - // Get the properties - mlt_properties properties = MLT_PRODUCER_PROPERTIES( this ); - - // Obtain the fps - double fps = mlt_properties_get_double( properties, "fps" ); - - // Do the calc - return ( double )position / fps; + return ( double )position / mlt_producer_get_fps( this ); } /** Get the audio from a frame. @@ -228,7 +221,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form mlt_position expected = mlt_properties_get_position( properties, "audio_expected" ); // Get the fps for this producer - double fps = mlt_properties_get_double( properties, "fps" ); + double fps = mlt_producer_get_fps( this ); // Get the vorbis info vorbis_info *vi = ov_info( ov, -1 ); diff --git a/src/modules/westley/producer_westley.c b/src/modules/westley/producer_westley.c index 9e27630..b440761 100644 --- a/src/modules/westley/producer_westley.c +++ b/src/modules/westley/producer_westley.c @@ -540,7 +540,7 @@ static void on_end_producer( deserialise_context context, const xmlChar *name ) if ( strchr( mlt_properties_get( properties, "clipBegin" ), ':' ) ) // Parse clock value in = parse_clock_value( mlt_properties_get( properties, "clipBegin" ), - mlt_properties_get_double( mlt_producer_properties( MLT_PRODUCER( producer ) ), "fps" ) ); + mlt_producer_get_fps( MLT_PRODUCER( producer ) ) ); else // Parse frames value in = mlt_properties_get_position( properties, "clipBegin" ); @@ -554,7 +554,7 @@ static void on_end_producer( deserialise_context context, const xmlChar *name ) if ( strchr( mlt_properties_get( properties, "clipEnd" ), ':' ) ) // Parse clock value out = parse_clock_value( mlt_properties_get( properties, "clipEnd" ), - mlt_properties_get_double( mlt_producer_properties( MLT_PRODUCER( producer ) ), "fps" ) ); + mlt_producer_get_fps( MLT_PRODUCER( producer ) ) ); else // Parse frames value out = mlt_properties_get_position( properties, "clipEnd" ); -- 1.7.4.4