]> git.sesse.net Git - mlt/commitdiff
mlt_consumer.c, mlt_frame.c, mlt_multitrack.c, mlt_playlist.c,
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 4 Dec 2007 08:04:30 +0000 (08:04 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Tue, 4 Dec 2007 08:04:30 +0000 (08:04 +0000)
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
src/framework/mlt_frame.c
src/framework/mlt_multitrack.c
src/framework/mlt_playlist.c
src/framework/mlt_producer.c
src/modules/avformat/producer_avformat.c
src/modules/core/filter_data_show.c
src/modules/dv/producer_libdv.c
src/modules/inigo/producer_inigo.c
src/modules/vorbis/producer_vorbis.c
src/modules/westley/producer_westley.c

index 0f3264fd40bec4be70be3ad17c2880ec86349fa9..eb7254037ac809bba33ffcd125aab9c1c5aebb2d 100644 (file)
@@ -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.
index 52de88d9ea40757ab28e936f3dcfb1ccfdaed079..a34579edf83b4585d2c085d4db0509f4ebb34bb1 100644 (file)
@@ -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
index 6b21a2b76798dbb80b7efe2b4d5d03356e755040..929d4bd31a31d0a397b45a63a6b8fd6bcdaa724d 100644 (file)
@@ -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.
index eac06425a87b7c7390b7178fc117ce22d83e1b1b..240c523ef1bde847b79761564ea506b68ac1a136 100644 (file)
@@ -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 );
 }
 
index 56d1d3f36fa8d935b03abae7341670264bb91730..5d3963c5e52e42f0413842b5ef5ee6eab54c0043 100644 (file)
@@ -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 )
index 03b62b67d4f60a8989e1256b322726e7417c9cfd..aad08028d533393ef9dc3a93b313daa4e0d050e5 100644 (file)
@@ -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
index e77ef97226ae231b9156d60628fd1f68d5bde5c4..3dfd7cb914cb4c830088a622bfee090ece6f946d 100644 (file)
@@ -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 );
                                                                }
index 0a6189fb12b938cf32fd310da2d47a6270d62455..a7c10b34dc3a1e8cdf88470c1f2c9e4ad2577f0f 100644 (file)
@@ -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 )
                                {
index 95e99b250c11eee356f3c9d6eb61481f9caf990e..6de55781299f453dd609778084d769a97ea7b0a4 100644 (file)
@@ -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 );
 
index 328e91e5fd33652d43d769e6c982fa72df719d07..982808bcf59d1521e73f5d11ff121e2c9f120b1c 100644 (file)
@@ -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 );
index 9e276302445a28cb342c1695efa18f686c2352eb..b440761693fb0323eacad8577139bc21a671f0c0 100644 (file)
@@ -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" );