]> git.sesse.net Git - mlt/commitdiff
Add service locks for parallelism.
authorDan Dennedy <dan@dennedy.org>
Fri, 5 Mar 2010 05:28:16 +0000 (21:28 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 24 Jan 2011 02:09:43 +0000 (18:09 -0800)
RGB filters and transitions from frei0r and burningtv are still not safe
enough.

19 files changed:
src/modules/avformat/filter_avresample.c
src/modules/avformat/filter_swscale.c
src/modules/avformat/producer_avformat.c
src/modules/core/filter_data_show.c
src/modules/core/filter_luma.c
src/modules/core/filter_watermark.c
src/modules/core/producer_colour.c
src/modules/core/transition_composite.c
src/modules/core/transition_luma.c
src/modules/core/transition_region.c
src/modules/effectv/filter_burn.c
src/modules/frei0r/filter_frei0r.c
src/modules/frei0r/producer_frei0r.c
src/modules/frei0r/transition_frei0r.c
src/modules/gtk2/producer_pango.c
src/modules/gtk2/producer_pixbuf.c
src/modules/kdenlive/filter_freeze.c
src/modules/kdenlive/producer_framebuffer.c
src/modules/resample/filter_resample.c

index 38e0d57123945923a82c05817cd89ebb49103809..f78dff87814a642da4cf37ce07ecbe6ce66ab174 100644 (file)
@@ -42,6 +42,8 @@ static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
        // Get the filter properties
        mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
 
+       mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
+
        // Get the resample information
        int output_rate = mlt_properties_get_int( filter_properties, "frequency" );
        int16_t *sample_buffer = mlt_properties_get_data( filter_properties, "buffer", NULL );
@@ -128,6 +130,8 @@ static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                        mlt_properties_set_int( filter_properties, "last_frequency", *frequency );
                }
 
+               mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
                // Resample the audio
                used = audio_resample( resample, sample_buffer, *buffer, *samples );
                int size = used * *channels * sizeof( int16_t );
@@ -146,6 +150,10 @@ static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                *samples = used;
                *frequency = output_rate;
        }
+       else
+       {
+               mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+       }
 
        return 0;
 }
index 0fd7f0bdfb7b2885391d90240e02799924112481..990be78786b6c9fe98c88b212eeef4ae372f7628 100644 (file)
@@ -47,7 +47,7 @@ static inline int convert_mlt_to_av_cs( mlt_image_format format )
                        break;
                case mlt_image_rgb24a:
                case mlt_image_opengl:
-                       value = PIX_FMT_RGB32;
+                       value = PIX_FMT_RGBA;
                        break;
                case mlt_image_yuv422:
                        value = PIX_FMT_YUYV422;
index 4860a933c70240eade3e539c181877bac360af58..8c4171b705ce599d312d90ef7ce328c13949e3a7 100644 (file)
@@ -947,6 +947,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
 {
        // Get the producer
        producer_avformat this = mlt_frame_pop_service( frame );
+       mlt_service_lock( MLT_PRODUCER_SERVICE(this->parent) );
        mlt_producer producer = this->parent;
 
        // Get the properties from the frame
@@ -1134,7 +1135,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                }
        }
 
-       // Duplicate the last image if necessary (see comment on rawvideo below)
+       // Duplicate the last image if necessary
        if ( this->av_frame && this->av_frame->linesize[0] && this->got_picture && this->seekable
                 && ( paused
                          || this->current_position == req_position
@@ -1402,6 +1403,8 @@ exit_get_image:
        mlt_properties_set_int( properties, "meta.media.top_field_first", this->top_field_first );
        mlt_properties_set_int( properties, "meta.media.progressive", mlt_properties_get_int( frame_properties, "progressive" ) );
 
+       mlt_service_unlock( MLT_PRODUCER_SERVICE(this->parent) );
+
        return !this->got_picture;
 }
 
@@ -1720,8 +1723,10 @@ static int seek_audio( producer_avformat this, mlt_position position, double tim
                                timestamp = 0;
 
                        // Set to the real timecode
+                       avformat_lock();
                        if ( av_seek_frame( context, -1, timestamp, AVSEEK_FLAG_BACKWARD ) != 0 )
                                paused = 1;
+                       avformat_unlock();
 
                        // Clear the usage in the audio buffer
                        int i = MAX_AUDIO_STREAMS + 1;
@@ -1794,7 +1799,9 @@ static int decode_audio( producer_avformat this, int *ignore, AVPacket pkt, int
                                // Copy to audio buffer while resampling
                                int16_t *source = decode_buffer;
                                int16_t *dest = &audio_buffer[ audio_used * channels ];
+                               avformat_lock();
                                audio_used += audio_resample( resample, dest, source, convert_samples );
+                               avformat_unlock();
                        }
                        else
                        {
@@ -1847,6 +1854,8 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
        // Get the producer
        producer_avformat this = mlt_frame_pop_audio( frame );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE(this->parent) );
+       
        // Obtain the frame number of this frame
        mlt_position position = mlt_properties_get_position( MLT_FRAME_PROPERTIES( frame ), "avformat_position" );
 
@@ -1944,7 +1953,9 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                        }
 
                        // Read a packet
+                       avformat_lock();
                        ret = av_read_frame( context, &pkt );
+                       avformat_unlock();
 
                        // We only deal with audio from the selected audio index
                        if ( ret >= 0 && pkt.data && pkt.size > 0 && ( pkt.stream_index == this->audio_index ||
@@ -2035,6 +2046,8 @@ static int producer_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
        if ( !paused )
                this->audio_expected = position + 1;
 
+       mlt_service_unlock( MLT_PRODUCER_SERVICE(this->parent) );
+
        return 0;
 }
 
index 54c3511193db4d965b5e24405a36d2197d140abc..73d7d778f243fcc6c599be29da3e8258de637955 100644 (file)
@@ -300,12 +300,16 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Get the frame properties
        mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
 
+       mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
+
        // Track specific
        process_queue( mlt_properties_get_data( frame_properties, "data_queue", NULL ), frame, filter );
 
        // Global
        process_queue( mlt_properties_get_data( frame_properties, "global_queue", NULL ), frame, filter );
 
+       mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
        // Need to get the image
        return mlt_frame_get_image( frame, image, format, width, height, 1 );
 }
index 28b2d6ee6573d5f17d74dfd041f7f82d23060253..0a146bebfce49d5aeba678f190a5b4abe70efe6f 100644 (file)
@@ -37,6 +37,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        int error = 0;
        mlt_filter filter = mlt_frame_pop_service( this );
        mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
+
+       mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
+
        mlt_transition luma = mlt_properties_get_data( properties, "luma", NULL );
        mlt_frame b_frame = mlt_properties_get_data( properties, "frame", NULL );
        mlt_properties b_frame_props = b_frame ? MLT_FRAME_PROPERTIES( b_frame ) : NULL;
@@ -111,6 +114,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                }
        }
 
+       mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
        return error;
 }
 
index e1e95d62f6cf3b6f34d0915b53ddfba3069919f2..bb9ffd889ac7924d68fbb3f8a7819d65e5ee3dc3 100644 (file)
@@ -42,6 +42,8 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Get the properties of the filter
        mlt_properties properties = MLT_FILTER_PROPERTIES( this );
 
+       mlt_service_lock( MLT_FILTER_SERVICE( this ) );
+
        // Get the producer from the filter
        mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
 
@@ -115,6 +117,8 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                mlt_properties_pass( producer_properties, properties, "producer." );
        }
 
+       mlt_service_unlock( MLT_FILTER_SERVICE( this ) );
+
        // Only continue if we have both producer and composite
        if ( composite != NULL && producer != NULL )
        {
index a43adedaadc21f351ac174f030fe3fed85526660..8667e4534684849b6b88283d6897dfdde5d3403c 100644 (file)
@@ -99,6 +99,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Obtain the producer for this frame
        mlt_producer producer = mlt_properties_get_data( properties, "producer_colour", NULL );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
+
        // Obtain properties of producer
        mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
 
@@ -154,6 +156,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                mlt_properties_set_int( producer_props, "_format", *format );
                mlt_properties_set( producer_props, "_resource", now );
 
+               mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
+
                switch ( *format )
                {
                case mlt_image_yuv422:
@@ -204,6 +208,10 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                        break;
                }
        }
+       else
+       {
+               mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
+       }
 
        // Create the alpha channel
        int alpha_size = *width * *height;
index 2e29ac809f50f08a1938548b7e22fb83544608d0..14e00575519a52f53c2bdc6c9c8ba34bae5088b1 100644 (file)
@@ -1223,7 +1223,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                        int field;
                        
                        double luma_softness = mlt_properties_get_double( properties, "softness" );
+                       mlt_service_lock( MLT_TRANSITION_SERVICE( this ) );
                        uint16_t *luma_bitmap = get_luma( this, properties, width_b, height_b );
+                       mlt_service_unlock( MLT_TRANSITION_SERVICE( this ) );
                        char *operator = mlt_properties_get( properties, "operator" );
 
                        alpha_b = alpha_b == NULL ? mlt_frame_get_alpha_mask( b_frame ) : alpha_b;
index 67a044d46f9f90e06f6d930757c529accaf904e5..52ea292a25ce23c77d1ec1c0de7da109d9689fa9 100644 (file)
@@ -368,6 +368,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
        // This compositer is yuv422 only
        *format = mlt_image_yuv422;
 
+       mlt_service_lock( MLT_TRANSITION_SERVICE( transition ) );
+
        // The cached luma map information
        int luma_width = mlt_properties_get_int( properties, "width" );
        int luma_height = mlt_properties_get_int( properties, "height" );
@@ -480,6 +482,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                }
        }
 
+       mlt_service_unlock( MLT_TRANSITION_SERVICE( transition ) );
+
        // Arbitrary composite defaults
        float mix = position_calculate( transition, a_frame );
        float frame_delta = delta_calculate( transition, a_frame );
index bd0721207b95d0ac9d901fba8b0e0ff30caadb8a..9524dfc9556aef4cc6aefb1cfa144126f32d082e 100644 (file)
@@ -152,6 +152,8 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for
        // Get the properties of the transition
        mlt_properties properties = MLT_TRANSITION_PROPERTIES( this );
 
+       mlt_service_lock( MLT_TRANSITION_SERVICE( this ) );
+
        // Get the composite from the transition
        mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL );
 
@@ -386,6 +388,8 @@ static int transition_get_image( mlt_frame frame, uint8_t **image, mlt_image_for
                error = mlt_frame_get_image( frame, image, format, width, height, 0 );
        }
 
+       mlt_service_unlock( MLT_TRANSITION_SERVICE( this ) );
+
        return error;
 }
 
index 42a1f2d877d777ba28199ae42c8ac6d9a9ab0870..aefa76cf119b9bf081085ad929ad72a450fb10a1 100644 (file)
@@ -103,8 +103,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                unsigned char v, w;
                RGB32 a, b;
 
-               diff = mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), 
-                                               "_diff", NULL );
+               mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
+
+               diff = mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), "_diff", NULL );
                if (diff == NULL)
                {
                        diff = mlt_pool_alloc(video_area*sizeof(unsigned char));
@@ -112,8 +113,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                        diff, video_area*sizeof(unsigned char), mlt_pool_release, NULL );
                }
 
-               buffer = mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), 
-                                               "_buffer", NULL );
+               buffer = mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), "_buffer", NULL );
                if (buffer == NULL)
                {
                        buffer = mlt_pool_alloc(video_area*sizeof(unsigned char));
@@ -122,7 +122,6 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                        buffer, video_area*sizeof(unsigned char), mlt_pool_release, NULL );
                }
 
-
                if (burn_foreground == 1) {
                        /* to burn the foreground, we need a background */
                        background = mlt_properties_get_data( MLT_FILTER_PROPERTIES( filter ), 
@@ -136,6 +135,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        }
                }
 
+               mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
                if (burn_foreground == 1) {
                        image_bgsubtract_y(diff, background, src, video_area, y_threshold);
                } else {
index fde17336f1b19f2cde8113d57374840918e1bd9b..046597eadc771e2ed4aced07f483b2342f2901a4 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "frei0r_helper.h"
 #include <string.h>
+
 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
 {
 
@@ -36,8 +37,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                mlt_position time = mlt_properties_get_position( properties, "_filter_position" );
                double position = ( double )( time ) / ( double )( length );
                
+               mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
                process_frei0r_item( filter_type, position, properties, this, image, width, height );
-               
+               mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
        }
 
        return error;
index 0f16c862d3cfc50b9e985791475138bc32114ef7..291ee47f7b51dbd633c948f85200f52d3d088759 100644 (file)
@@ -54,7 +54,9 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                mlt_position out = mlt_producer_get_out( producer );
                mlt_position time = mlt_frame_get_position( frame );
                double position = ( double )( time - in ) / ( double )( out - in + 1 );
+               mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
                process_frei0r_item( producer_type, position, producer_props, frame, buffer, width, height );
+               mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
        }
 
     return 0;
index df0226d1f028676d2ea94c2fc08e4f6fbd3f6a18..b1aaf8ba69609212041b345740f982461f052e49 100644 (file)
@@ -59,7 +59,9 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 
        float pos=( float )( position - in ) / ( float )( out - in + 1 );
        
+       mlt_service_lock( MLT_TRANSITION_SERVICE( transition ) );
        process_frei0r_item( transition_type, pos, properties, !invert ? a_frame : b_frame, images, width, height );
+       mlt_service_unlock( MLT_TRANSITION_SERVICE( transition ) );
        
        *width = mlt_properties_get_int( !invert ? a_props : b_props, "width" );
         *height = mlt_properties_get_int( !invert ? a_props : b_props, "height" );
index 7c85ae881f4ec20003b97b3e52e6e683dfd35955..814541b2b399028fcb100c2252d82288da3b6cef 100644 (file)
@@ -466,6 +466,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        *width = mlt_properties_get_int( properties, "rescale_width" );
        *height = mlt_properties_get_int( properties, "rescale_height" );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( &this->parent ) );
+
        // Refresh the image
        pthread_mutex_lock( &pango_mutex );
        refresh_image( frame, *width, *height );
@@ -492,6 +494,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        }
 
        pthread_mutex_unlock( &pango_mutex );
+       mlt_service_unlock( MLT_PRODUCER_SERVICE( &this->parent ) );
 
        return error;
 }
index 6fd127d6fe6f211c4017081f02ff98367cb70000..ab4aa66c0e9178ff1cec1a8522b7d3752fd989ae 100644 (file)
@@ -461,6 +461,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        *width = mlt_properties_get_int( properties, "rescale_width" );
        *height = mlt_properties_get_int( properties, "rescale_height" );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( &this->parent ) );
+
        // Refresh the image
        refresh_image( this, frame, *width, *height );
 
@@ -492,6 +494,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        // Release references and locks
        pthread_mutex_unlock( &this->mutex );
        mlt_cache_item_close( this->image_cache );
+       mlt_service_unlock( MLT_PRODUCER_SERVICE( &this->parent ) );
 
        return error;
 }
index 3198ff318805ba782c08918fd852491f66664876..c4768e27e074d2df89059b40996a61979debfe38 100755 (executable)
@@ -50,6 +50,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        }
 
        if (do_freeze == 1) {
+               mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
                freeze_frame = mlt_properties_get_data( properties, "freeze_frame", NULL );
                if ( freeze_frame == NULL || mlt_properties_get_position( properties, "_frame" ) != pos )
                {
@@ -99,6 +100,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                memcpy( image_copy, buffer, size );
                *image = image_copy;
                mlt_properties_set_data( props, "image", *image, size, ( mlt_destructor ) mlt_pool_release, NULL );
+               mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
                return error;
        }
 
index 8e436125f9e2ab23a97c9342bc070aaf071181ea..64c9ce07ae2628f9ad49b0cac5b26cd314dcd3dc 100644 (file)
@@ -41,6 +41,8 @@ static int framebuffer_get_image( mlt_frame this, uint8_t **image, mlt_image_for
        int index = ( int )mlt_frame_pop_service( this );
        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
 
+       mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
+
        // Frame properties objects
        mlt_properties frame_properties = MLT_FRAME_PROPERTIES( this );
        mlt_frame first_frame = mlt_properties_get_data( properties, "first_frame", NULL );
@@ -179,6 +181,7 @@ static int framebuffer_get_image( mlt_frame this, uint8_t **image, mlt_image_for
                mlt_properties_set_int( properties, "_output_format", *format );
        
        }
+       mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );
 
        // Create a copy
        uint8_t *image_copy = mlt_pool_alloc( size );
index 8a4543ee40ffad7ab8839e91d40c3bb7065daccb..4533a0b2704fdf08f9a931c2a116150401f797ee 100644 (file)
@@ -63,6 +63,9 @@ static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                        *format = mlt_audio_float;
                        mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
                }
+
+               mlt_service_lock( MLT_FILTER_SERVICE(filter) );
+
                float *input_buffer = mlt_properties_get_data( filter_properties, "input_buffer", NULL );
                float *output_buffer = mlt_properties_get_data( filter_properties, "output_buffer", NULL );
                SRC_DATA data;
@@ -119,9 +122,13 @@ static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format
                        // Update output variables
                        *samples = data.output_frames_gen;
                        *frequency = output_rate;
+
                }
                else
+               {
                        mlt_log_error( MLT_FILTER_SERVICE( filter ), "%s %d,%d,%d\n", src_strerror( error ), *frequency, *samples, output_rate );
+               }
+               mlt_service_unlock( MLT_FILTER_SERVICE(filter) );
        }
 
        return error;