]> git.sesse.net Git - mlt/commitdiff
Memory pooling part 2 and other optimisations
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 20 Feb 2004 14:56:24 +0000 (14:56 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Fri, 20 Feb 2004 14:56:24 +0000 (14:56 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@158 d19143bc-622f-0410-bfdd-b5b2a6649095

23 files changed:
src/albino/Makefile
src/framework/Makefile
src/framework/mlt_frame.c
src/framework/mlt_multitrack.c
src/framework/mlt_pool.c
src/framework/mlt_pool.h
src/framework/mlt_properties.c
src/humperdink/Makefile
src/inigo/Makefile
src/miracle/Makefile
src/modules/avformat/producer_avformat.c
src/modules/core/producer_ppm.c
src/modules/core/transition_luma.c
src/modules/dv/producer_libdv.c
src/modules/ffmpeg/producer_ffmpeg.c
src/modules/gtk2/filter_rescale.c
src/modules/gtk2/producer_pango.c
src/modules/gtk2/producer_pixbuf.c
src/modules/resample/filter_resample.c
src/modules/sdl/consumer_sdl.c
src/modules/vorbis/producer_vorbis.c
src/tests/Makefile
src/valerie/Makefile

index 7507b8a808d4d4b039a5b01c1dc254fb4c33d7ee..d294f577b8cb71d6612e9cee2134938bb235eb47 100644 (file)
@@ -6,6 +6,11 @@ CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic
 
 LDFLAGS = -L ../valerie -L ../miracle -L ../framework -lmiracle -lmlt -lvalerie
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 SRCS := $(OBJS:.o=.c)
 
 all: $(TARGET)
index ae67859e39b0b564942c41e2663d5b4b9d85fe32..52174e3522875ba8535068d6bc34aed21dcbce42 100644 (file)
@@ -24,6 +24,11 @@ CFLAGS = -g -O3 -Wall -D_FILE_OFFSET_BITS=64 -pthread
 
 LDFLAGS = -lm -ldl -lpthread
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 all:   $(TARGET)
 
 $(TARGET): $(OBJS)
index a62ed7ac59fbb9622fc14a5f413d5e4acd83b66a..d0e08e38af9b5f2dea7301dc0b5b5f8240a38cd8 100644 (file)
@@ -212,7 +212,6 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for
        }
        else
        {
-               void *release = NULL;
                uint8_t *p;
                uint8_t *q;
                int size = 0;
@@ -233,21 +232,21 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for
                        case mlt_image_rgb24:
                                size *= 3;
                                size += *width * 3;
-                               *buffer = mlt_pool_allocate( size, &release );
+                               *buffer = mlt_pool_alloc( size );
                                if ( *buffer )
                                        memset( *buffer, 255, size );
                                break;
                        case mlt_image_rgb24a:
                                size *= 4;
                                size += *width * 4;
-                               *buffer = mlt_pool_allocate( size, &release );
+                               *buffer = mlt_pool_alloc( size );
                                if ( *buffer )
                                        memset( *buffer, 255, size );
                                break;
                        case mlt_image_yuv422:
                                size *= 2;
                                size += *width * 2;
-                               *buffer = mlt_pool_allocate( size, &release );
+                               *buffer = mlt_pool_alloc( size );
                                p = *buffer;
                                q = p + size;
                                while ( p != NULL && p != q )
@@ -258,14 +257,13 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for
                                break;
                        case mlt_image_yuv420p:
                                size = size * 3 / 2;
-                               *buffer = mlt_pool_allocate( size, &release );
+                               *buffer = mlt_pool_alloc( size );
                                if ( *buffer )
                                        memset( *buffer, 255, size );
                                break;
                }
 
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", *buffer, size, NULL, NULL );
+               mlt_properties_set_data( properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "test_image", 1 );
        }
 
@@ -290,16 +288,14 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for
        else
        {
                int size = 0;
-               void *release = NULL;
                *samples = *samples <= 0 ? 1920 : *samples;
                *channels = *channels <= 0 ? 2 : *channels;
                *frequency = *frequency <= 0 ? 48000 : *frequency;
                size = *samples * *channels * sizeof( int16_t );
-               *buffer = mlt_pool_allocate( size, &release );
+               *buffer = mlt_pool_alloc( size );
                if ( *buffer != NULL )
                        memset( *buffer, 0, size );
-               mlt_properties_set_data( properties, "audio_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "audio", *buffer, size, NULL, NULL );
+               mlt_properties_set_data( properties, "audio", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "test_audio", 1 );
        }
        return 0;
@@ -465,7 +461,6 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        uint8_t *in_middle = input + istride * ( iheight / 2 ) + ( iwidth / 2 ) * 2;
        int in_line = - in_y_range * istride - in_x_range * 2;
 
-       uint8_t black[ 2 ] = { 0, 128 };
        int elements;
 
        // Fill whole section with black
@@ -474,8 +469,8 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        elements = blank_elements;
        while ( elements -- )
        {
-               *out_line ++ = black[ 0 ];
-               *out_line ++ = black[ 1 ];
+               *out_line ++ = 0;
+               *out_line ++ = 128;
        }
 
        int active_width = 2 * iwidth;
@@ -491,8 +486,8 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
                elements = inactive_width;
                while ( elements -- )
                {
-                       *out_ptr ++ = black[ 0 ];
-                       *out_ptr ++ = black[ 1 ];
+                       *out_ptr ++ = 0;
+                       *out_ptr ++ = 128;
                }
 
                // We're in the input range for this row.
@@ -503,8 +498,8 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
                elements = inactive_width;
                while ( elements -- )
                {
-                       *out_ptr ++ = black[ 0 ];
-                       *out_ptr ++ = black[ 1 ];
+                       *out_ptr ++ = 0;
+                       *out_ptr ++ = 128;
                }
 
                // Move to next input line
@@ -518,8 +513,8 @@ void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input
        elements = blank_elements;
        while ( elements -- )
        {
-               *out_line ++ = black[ 0 ];
-               *out_line ++ = black[ 1 ];
+               *out_line ++ = 0;
+               *out_line ++ = 128;
        }
 }
 
@@ -541,15 +536,13 @@ uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight )
        if ( iwidth != owidth || iheight != oheight )
        {
                // Create the output image
-               void *release = NULL;
-               uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+               uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                // Call the generic resize
                mlt_resize_yuv422( output, owidth, oheight, input, iwidth, iheight );
 
                // Now update the frame
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+               mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "width", owidth );
                mlt_properties_set_int( properties, "height", oheight );
 
@@ -578,8 +571,7 @@ uint8_t *mlt_frame_rescale_yuv422( mlt_frame this, int owidth, int oheight )
        if ( iwidth != owidth || iheight != oheight )
        {
                // Create the output image
-               void *release = NULL;
-               uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+               uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                // Calculate strides
                int istride = iwidth * 2;
@@ -642,8 +634,7 @@ uint8_t *mlt_frame_rescale_yuv422( mlt_frame this, int owidth, int oheight )
        }
 
                // Now update the frame
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+               mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "width", owidth );
                mlt_properties_set_int( properties, "height", oheight );
 
index c9ea81ce6c820ac1a2fe5b3be1bd1f3297d22300..ca3103acc2483dcc7c71924719d310841aa4a511 100644 (file)
@@ -394,7 +394,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int ind
                }
 
                // Refresh our stats
-               mlt_multitrack_refresh( this );
+               //mlt_multitrack_refresh( this );
        }
 
        return 0;
index ab51392345fabec8228f3c8a033e3e41fb47e350..16d1e1d4fd3ca0608ffa888c27c94e408f9d8bb9 100644 (file)
@@ -38,15 +38,12 @@ typedef struct mlt_pool_s
        pthread_mutex_t lock;
        mlt_deque stack;
        int size;
+       int count;
 }
 *mlt_pool;
 
-/** Private release structure
-*/
-
 typedef struct mlt_release_s
 {
-       void *ptr;
        mlt_pool pool;
 }
 *mlt_release;
@@ -79,10 +76,10 @@ static mlt_pool pool_init( int size )
 /** Get an item from the pool.
 */
 
-static mlt_release pool_fetch( mlt_pool this )
+static void *pool_fetch( mlt_pool this )
 {
        // We will generate a release object
-       mlt_release release = NULL;
+       void *ptr = NULL;
 
        // Sanity check
        if ( this != NULL )
@@ -94,21 +91,21 @@ static mlt_release pool_fetch( mlt_pool this )
                if ( mlt_deque_count( this->stack ) != 0 )
                {
                        // Pop the top of the stack
-                       release = mlt_deque_pop_back( this->stack );
+                       ptr = mlt_deque_pop_back( this->stack );
                }
                else
                {
                        // We need to generate a release item
-                       release = calloc( 1, sizeof( struct mlt_release_s ) );
+                       mlt_release release = malloc( sizeof( struct mlt_release_s ) + this->size );
 
                        // Initialise it
                        if ( release != NULL )
                        {
-                               // Allocate the real memory
-                               release->ptr = malloc( this->size );
-
                                // Assign the pool
                                release->pool = this;
+
+                               // Determine the ptr
+                               ptr = ( void * )release + sizeof( struct mlt_release_s );
                        }
                }
 
@@ -117,42 +114,44 @@ static mlt_release pool_fetch( mlt_pool this )
        }
 
        // Return the generated release object
-       return release;
+       return ptr;
 }
 
 /** Return an item to the pool.
 */
 
-static void pool_return( mlt_pool this, mlt_release that )
+static void pool_return( void *ptr )
 {
        // Sanity checks
-       if ( this != NULL && that != NULL )
+       if ( ptr != NULL )
        {
-               // Ensure that the pools match
-               if ( this == that->pool )
+               // Get the release pointer
+               mlt_release that = ( void * )ptr - sizeof( struct mlt_release_s );
+
+               // Get the pool
+               mlt_pool this = that->pool;
+
+               if ( this != NULL )
                {
                        // Lock the pool
                        pthread_mutex_lock( &this->lock );
 
                        // Push the that back back on to the stack
-                       mlt_deque_push_back( this->stack, that );
+                       mlt_deque_push_back( this->stack, ptr );
 
                        // Unlock the pool
                        pthread_mutex_unlock( &this->lock );
 
                        // Ensure that we don't clean up
-                       that = NULL;
+                       ptr = NULL;
                }
        }
 
        // Tidy up - this will only occur if the returned item is incorrect
-       if ( that != NULL )
+       if ( ptr != NULL )
        {
-               // Free the memory
-               free( that->ptr );
-
                // Free the release itself
-               free( that );
+               free( ptr - sizeof( struct mlt_release_s ) );
        }
 }
 
@@ -164,13 +163,13 @@ static void pool_close( mlt_pool this )
        if ( this != NULL )
        {
                // We need to free up all items in the pool
-               mlt_release release = NULL;
+               void *release = NULL;
 
                // Iterate through the stack until depleted
                while ( ( release = mlt_deque_pop_back( this->stack ) ) != NULL )
                {
-                       // We'll return this item to NULL
-                       pool_return( NULL, release );
+                       // We'll free this item now
+                       free( release - sizeof( struct mlt_release_s ) );
                }
 
                // We can now close the stack
@@ -196,7 +195,7 @@ void mlt_pool_init( )
        pools = mlt_properties_new( );
 
        // Create the pools
-       for ( i = 8; i < 32; i ++ )
+       for ( i = 8; i < 31; i ++ )
        {
                // Each properties item needs a name
                char name[ 32 ];
@@ -215,16 +214,39 @@ void mlt_pool_init( )
 /** Allocate size bytes from the pool.
 */
 
+void *mlt_pool_alloc( int size )
+{
+       // This will be used to obtain the pool to use
+       mlt_pool pool = NULL;
+
+       // Determines the index of the pool to use
+       int index = 0;
+
+       // Minimum size pooled is 256 bytes
+       size = size >> 8;
+       while ( ( 1 << index ) < size )
+               index ++;
+
+       // Now get the pool at the index
+       pool = mlt_properties_get_data_at( pools, index + 1, NULL );
+
+       // Now get the real item
+       return pool_fetch( pool );
+}
+
+/** Allocate size bytes from the pool.
+*/
+
 void *mlt_pool_allocate( int size, void **release )
 {
        // This is the real release structure we'll return
-       mlt_release real = NULL;
+       void *real = NULL;
 
        // This will be used to obtain the pool to use
        mlt_pool pool = NULL;
 
        // Determines the index of the pool to use
-       int index = 1;
+       int index = 0;
 
        // Minimum size pooled is 256 bytes
        size = size >> 8;
@@ -237,18 +259,11 @@ void *mlt_pool_allocate( int size, void **release )
        // Now get the real item
        real = pool_fetch( pool );
 
-       // Deal with return
-       if ( real != NULL )
-       {
-               // Assign to release
-               *release = real;
-
-               // Return the pointer
-               return real->ptr;
-       }
-
+       // Assign to release
+       *release = real;
+       
        // Otherwise return a NULL to indicate failure
-       return NULL;
+       return real;
 }
 
 /** Release the allocated memory.
@@ -256,15 +271,8 @@ void *mlt_pool_allocate( int size, void **release )
 
 void mlt_pool_release( void *release )
 {
-       // Sanity check
-       if ( release != NULL )
-       {
-               // Get the real release structure
-               mlt_release real = release;
-
-               // Return to the pool
-               pool_return( real->pool, real );
-       }
+       // Return to the pool
+       pool_return( release );
 }
 
 /** Close the pool.
index 2775cb3a8ab9ff513471fa19fc9d3c9d3b8915d0..87ef08b7b547e01483950f581850421e6e9276cd 100644 (file)
@@ -22,6 +22,7 @@
 #define _MLT_POOL_H
 
 extern void mlt_pool_init( );
+extern void *mlt_pool_alloc( int size );
 extern void *mlt_pool_allocate( int size, void **release );
 extern void mlt_pool_release( void *release );
 extern void mlt_pool_close( );
index b78166043a709d6d6e0cb2bdfd3294e382683113..d830e44f7df3a3c7723ec69c664ad8343a5572af 100644 (file)
@@ -144,7 +144,7 @@ static mlt_property mlt_properties_add( mlt_properties this, char *name )
        // Check that we have space and resize if necessary
        if ( list->count == list->size )
        {
-               list->size += 10;
+               list->size += 50;
                list->name = realloc( list->name, list->size * sizeof( char * ) );
                list->value = realloc( list->value, list->size * sizeof( mlt_property ) );
        }
index 86fc4048c70605edbe02f94f5fc2d808d8c9d52c..b8aba7ac43c506aee42477a1a4f10ce0c5323da0 100644 (file)
@@ -8,6 +8,11 @@ CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic
 
 LDFLAGS = -L ../valerie -lvalerie
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 SRCS := $(OBJS:.o=.c)
 
 all: $(TARGET)
index b9e0b5db2fe617f86ff2f193a7a839b6a748f5e8..6fac85d684388cf07085bad317bdb895f5aec79e 100644 (file)
@@ -7,6 +7,11 @@ CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic
 
 LDFLAGS = -L ../framework -lmlt 
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 SRCS := $(OBJS:.o=.c)
 
 all: $(TARGET)
index bae78c2fdba6787322e0cdc4aac24476896daeb5..445a812932a43af4f1231a9eb542dec562aa03f7 100644 (file)
@@ -16,6 +16,11 @@ CFLAGS = -O3 -I .. -Wall -g -D_FILE_OFFSET_BITS=64 -pthread -rdynamic
 
 LDFLAGS = -L ../valerie -lvalerie -L ../framework -lmlt
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 SRCS := $(OBJS:.o=.c)
 
 all:           $(TARGET)
index 605c00276f1ae07627454c30c5ece3fe37a8c736..a02f7cb2444fe98f6e6fd39359543740d1162c04 100644 (file)
@@ -157,14 +157,6 @@ static void producer_codec_close( void *codec )
 }
 
 /** Open the file.
-
-       NOTE: We need to have a valid [PAL or NTSC] frame rate before we can determine the 
-       number of frames in the file. However, this is at odds with the way things work - the 
-       constructor needs to provide in/out points before the user of the producer is able
-       to specify properties :-/. However, the PAL/NTSC distinction applies to all producers
-       and while we currently accept whatever the producer provides, this will not work in
-       the more general case. Plans are afoot... and this one will work without modification
-       (in theory anyway ;-)).
 */
 
 static int producer_open( mlt_producer this, char *file )
@@ -186,7 +178,6 @@ static int producer_open( mlt_producer this, char *file )
 
        // Now attempt to open the file
        error = av_open_input_file( &context, file, NULL, 0, NULL );
-//     fprintf( stderr, "AVFORMAT: open %d %s\n", error, file );
        error = error < 0;
 
        // If successful, then try to get additional info
@@ -339,17 +330,13 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        if ( output == NULL )
        {
                int size = avpicture_get_size( PIX_FMT_YUV422, *width, *height );
-               void *frame_release = NULL;
-               void *buffer_release = NULL;
                size += *width * 2;
-               uint8_t *buf = mlt_pool_allocate( size, &buffer_release );
-               output = mlt_pool_allocate( sizeof( AVPicture ), &frame_release );
-               memset( output, 0, sizeof( AVPicture ) );
+               uint8_t *buf = mlt_pool_alloc( size );
+               output = mlt_pool_alloc( sizeof( AVPicture ) );
+               //memset( output, 0, sizeof( AVPicture ) );
                avpicture_fill( output, buf, PIX_FMT_YUV422, *width, *height );
-               mlt_properties_set_data( properties, "video_output_frame_release", frame_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "video_output_buffer_release", buffer_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "video_output_frame", output, 0, NULL, NULL );
-               mlt_properties_set_data( properties, "video_output_buffer", buf, 0, NULL, NULL );
+               mlt_properties_set_data( properties, "video_output_frame", output, 0, ( mlt_destructor )mlt_pool_release, NULL );
+               mlt_properties_set_data( properties, "video_output_buffer", buf, 0, ( mlt_destructor )mlt_pool_release, NULL );
        }
 
        // Seek if necessary
@@ -385,13 +372,11 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                uint8_t *image = mlt_properties_get_data( properties, "current_image", &size );
 
                // Duplicate it
-               void *release = NULL;
-               *buffer = mlt_pool_allocate( size, &release );
+               *buffer = mlt_pool_alloc( size );
                memcpy( *buffer, image, size );
 
                // Set this on the frame properties
-               mlt_properties_set_data( frame_properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( frame_properties, "image", *buffer, size, NULL, NULL );
+               mlt_properties_set_data( frame_properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
        }
        else
        {
@@ -399,8 +384,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                int got_picture = 0;
                AVFrame frame;
 
-               memset( &pkt, 0, sizeof( pkt ) );
-               memset( &frame, 0, sizeof( frame ) );
+               //memset( &pkt, 0, sizeof( pkt ) );
+               //memset( &frame, 0, sizeof( frame ) );
 
                while( ret >= 0 && !got_picture )
                {
@@ -413,8 +398,6 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                current_time = ( double )pkt.pts / 1000000.0;
 
                                // Decode the image
-                               // Wouldn't it be great if I could use this...
-                               //if ( (float)pkt.pts / 1000000.0 >= real_timecode )
                                ret = avcodec_decode_video( codec_context, &frame, &got_picture, pkt.data, pkt.size );
 
                                if ( got_picture )
@@ -445,24 +428,69 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                {
                        // Get current image and size
                        int size = 0;
-                       void *release = NULL;
                        uint8_t *image = mlt_properties_get_data( properties, "current_image", &size );
 
                        if ( image == NULL || size != *width * *height * 2 )
                        {
-                               void *current_image_release = NULL;
                                size = *width * ( *height + 1 ) * 2;
-                               image = mlt_pool_allocate( size, &current_image_release );
-                               mlt_properties_set_data( properties, "current_image_release", current_image_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                               mlt_properties_set_data( properties, "current_image", image, size, NULL, NULL );
+                               image = mlt_pool_alloc( size );
+                               mlt_properties_set_data( properties, "current_image", image, size, ( mlt_destructor )mlt_pool_release, NULL );
                        }
 
-                       *buffer = mlt_pool_allocate( size, &release );
-                       img_convert( output, PIX_FMT_YUV422, (AVPicture *)&frame, codec_context->pix_fmt, *width, *height );
-                       memcpy( image, output->data[ 0 ], size );
-                       memcpy( *buffer, output->data[ 0 ], size );
-                       mlt_properties_set_data( frame_properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( frame_properties, "image", *buffer, size, NULL, NULL );
+                       *buffer = mlt_pool_alloc( size );
+
+                       // EXPERIMENTAL IMAGE NORMALISATIONS
+                       if ( codec_context->pix_fmt == PIX_FMT_YUV420P )
+                       {
+                               register int i, j;
+                               register int half = *width >> 1;
+                               uint8_t *Y = ( ( AVPicture * )&frame )->data[ 0 ];
+                               uint8_t *U = ( ( AVPicture * )&frame )->data[ 1 ];
+                               uint8_t *V = ( ( AVPicture * )&frame )->data[ 2 ];
+                               register uint8_t *d = *buffer;
+                               register uint8_t *y, *u, *v;
+
+                               i = *height >> 1;
+                               while ( i -- )
+                               {
+                                       y = Y;
+                                       u = U;
+                                       v = V;
+                                       j = half;
+                                       while ( j -- )
+                                       {
+                                               *d ++ = *y ++;
+                                               *d ++ = *u ++;
+                                               *d ++ = *y ++;
+                                               *d ++ = *v ++;
+                                       }
+
+                                       Y += ( ( AVPicture * )&frame )->linesize[ 0 ];
+                                       y = Y;
+                                       u = U;
+                                       v = V;
+                                       j = half;
+                                       while ( j -- )
+                                       {
+                                               *d ++ = *y ++;
+                                               *d ++ = *u ++;
+                                               *d ++ = *y ++;
+                                               *d ++ = *v ++;
+                                       }
+
+                                       Y += ( ( AVPicture * )&frame )->linesize[ 0 ];
+                                       U += ( ( AVPicture * )&frame )->linesize[ 1 ];
+                                       V += ( ( AVPicture * )&frame )->linesize[ 2 ];
+                               }
+                       }
+                       else
+                       {
+                               img_convert( output, PIX_FMT_YUV422, (AVPicture *)&frame, codec_context->pix_fmt, *width, *height );
+                               memcpy( *buffer, output->data[ 0 ], size );
+                       }
+
+                       memcpy( image, *buffer, size );
+                       mlt_properties_set_data( frame_properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
 
                        if ( current_time == 0 && source_fps != 0 )
                        {
@@ -651,15 +679,11 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Check for audio buffer and create if necessary
        if ( audio_buffer == NULL )
        {
-               // Audio buffer release pointer
-               void *buffer_release = NULL;
-
                // Allocate the audio buffer
-               audio_buffer = mlt_pool_allocate( AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof( int16_t ), &buffer_release );
+               audio_buffer = mlt_pool_alloc( AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof( int16_t ) );
 
                // And store it on properties for reuse
-               mlt_properties_set_data( properties, "audio_buffer_release", buffer_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "audio_buffer", audio_buffer, 0, NULL, NULL );
+               mlt_properties_set_data( properties, "audio_buffer", audio_buffer, 0, ( mlt_destructor )mlt_pool_release, NULL );
        }
 
        // Seek if necessary
@@ -692,10 +716,9 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        {
                int ret = 0;
                int got_audio = 0;
-               void *temp_release = NULL;
-               int16_t *temp = mlt_pool_allocate( sizeof( int16_t ) * AVCODEC_MAX_AUDIO_FRAME_SIZE, &temp_release );
+               int16_t *temp = mlt_pool_alloc( sizeof( int16_t ) * AVCODEC_MAX_AUDIO_FRAME_SIZE );
 
-               memset( &pkt, 0, sizeof( pkt ) );
+               //memset( &pkt, 0, sizeof( pkt ) );
 
                while( ret >= 0 && !got_audio )
                {
@@ -774,13 +797,11 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                // Now handle the audio if we have enough
                if ( audio_used >= *samples )
                {
-                       void *buffer_release = NULL;
-                       *buffer = mlt_pool_allocate( *samples * *channels * sizeof( int16_t ), &buffer_release );
+                       *buffer = mlt_pool_alloc( *samples * *channels * sizeof( int16_t ) );
                        memcpy( *buffer, audio_buffer, *samples * *channels * sizeof( int16_t ) );
                        audio_used -= *samples;
                        memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * *channels * sizeof( int16_t ) );
-                       mlt_properties_set_data( frame_properties, "audio_release", buffer_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( frame_properties, "audio", *buffer, 0, NULL, NULL );
+                       mlt_properties_set_data( frame_properties, "audio", *buffer, 0, ( mlt_destructor )mlt_pool_release, NULL );
                }
                else
                {
@@ -793,7 +814,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                mlt_properties_set_int( properties, "audio_used", audio_used );
 
                // Release the temporary audio
-               mlt_pool_release( temp_release );
+               mlt_pool_release( temp );
        }
        else
        {
index ba09c3b420590fac56011111d72ede30d5fbd552..9865f80a05943760e4e5b26ebd8928d61b0dcc5e 100644 (file)
@@ -83,11 +83,9 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma
                // Convert to requested format
                if ( *format == mlt_image_yuv422 )
                {
-                       void *release = NULL;
-                       uint8_t *image = mlt_pool_allocate( *width * ( *height + 1 ) * 2, &release );
+                       uint8_t *image = mlt_pool_alloc( *width * ( *height + 1 ) * 2 );
                        mlt_convert_rgb24_to_yuv422( rgb, *width, *height, *width * 3, image );
-                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, NULL, NULL );
+                       mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                        *buffer = image;
                }
                else if ( *format == mlt_image_rgb24 )
@@ -225,15 +223,13 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        if ( video != NULL && read_ppm_header( video, &width, &height ) == 2 )
        {
                // Allocate an image
-               void *release = NULL;
-               uint8_t *image = mlt_pool_allocate( width * ( height + 1 ) * 3, &release );
+               uint8_t *image = mlt_pool_alloc( width * ( height + 1 ) * 3 );
                
                // Read it
                fread( image, width * height * 3, 1, video );
 
                // Pass the data on the frame properties
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", image, width * ( height + 1 ) * 3, NULL, NULL );
+               mlt_properties_set_data( properties, "image", image, width * ( height + 1 ) * 3, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "width", width );
                mlt_properties_set_int( properties, "height", height );
                mlt_properties_set_int( properties, "has_image", 1 );
index 167d4cfebd6a6af465b1912496d4270e7ce1ed83..c55a88b54182ea5f183a103209be0a5d06d11e3e 100644 (file)
@@ -250,7 +250,6 @@ static int transition_get_image( mlt_frame this, uint8_t **image, mlt_image_form
 
 static void luma_read_pgm( FILE *f, float **map, int *width, int *height )
 {
-       void *release = NULL;
        uint8_t *data = NULL;
        while (1)
        {
@@ -305,7 +304,7 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height )
                bpp = maxval > 255 ? 2 : 1;
                
                // allocate temporary storage for the raw data
-               data = mlt_pool_allocate( *width * *height * bpp, &release );
+               data = mlt_pool_alloc( *width * *height * bpp );
                if ( data == NULL )
                        break;
 
@@ -314,9 +313,7 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height )
                        break;
                
                // allocate the luma bitmap
-               // IRRIGATE ME
-               // Difficult here - need to change the function prototype....
-               *map =  p = (float*) malloc( *width * *height * sizeof( float ) );
+               *map = p = (float*)mlt_pool_alloc( *width * *height * sizeof( float ) );
                if ( *map == NULL )
                        break;
 
@@ -332,8 +329,8 @@ static void luma_read_pgm( FILE *f, float **map, int *width, int *height )
                break;
        }
                
-       if ( release != NULL )
-               mlt_pool_release( release );
+       if ( data != NULL )
+               mlt_pool_release( data );
 }
 
 
@@ -361,7 +358,7 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram
                pipe = fopen( luma_file, "r" );
                if ( pipe != NULL )
                {
-                       free( this->bitmap );
+                       mlt_pool_release( this->bitmap );
                        luma_read_pgm( pipe, &this->bitmap, &this->width, &this->height );
                        fclose( pipe );
                }
@@ -406,7 +403,7 @@ mlt_transition transition_luma_init( char *lumafile )
 static void transition_close( mlt_transition parent )
 {
        transition_luma *this = (transition_luma*) parent->child;
-       free( this->bitmap );
+       mlt_pool_release( this->bitmap );
        free( this->filename );
        free( this );
 }
index 02bef1f39f25a7f150b5488570ec123a7a57e0bb..b346b72de5cc44957d7ad60213b06b33a77ca0ad 100644 (file)
@@ -112,8 +112,7 @@ static int producer_collect_info( producer_libdv this )
 {
        int valid = 0;
 
-       void *release = NULL;
-       uint8_t *dv_data = mlt_pool_allocate( frame_size_625_50, &release );
+       uint8_t *dv_data = mlt_pool_alloc( frame_size_625_50 );
 
        if ( dv_data != NULL )
        {
@@ -157,7 +156,7 @@ static int producer_collect_info( producer_libdv this )
                        mlt_properties_set_double( properties, "aspect_ratio", dv_format_wide( this->dv_decoder ) ? 16.0/9.0 : 4.0/3.0 );
                }
 
-               mlt_pool_release( release );
+               mlt_pool_release( dv_data );
        }
 
        return valid;
@@ -188,12 +187,10 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma
        if ( *format == mlt_image_yuv422 )
        {
                // Allocate an image
-               void *release = NULL;
-               uint8_t *image = mlt_pool_allocate( *width * ( *height + 1 ) * 2, &release );
+               uint8_t *image = mlt_pool_alloc( *width * ( *height + 1 ) * 2 );
 
                // Pass to properties for clean up
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, NULL, NULL );
+               mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
 
                // Decode the image
                pitches[ 0 ] = *width * 2;
@@ -206,12 +203,10 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma
        else if ( *format == mlt_image_rgb24 )
        {
                // Allocate an image
-               void *release = NULL;
-               uint8_t *image = mlt_pool_allocate( *width * ( *height + 1 ) * 3, &release );
+               uint8_t *image = mlt_pool_alloc( *width * ( *height + 1 ) * 3 );
 
                // Pass to properties for clean up
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 3, NULL, NULL );
+               mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 3, ( mlt_destructor )mlt_pool_release, NULL );
 
                // Decode the frame
                pitches[ 0 ] = 720 * 3;
@@ -227,10 +222,8 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma
 
 static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
 {
-       void *release = NULL;
        int16_t *p;
        int i, j;
-       void *audio_release[ 4 ] = { NULL, NULL, NULL, NULL };
        int16_t *audio_channels[ 4 ];
        
        // Get the frames properties
@@ -253,14 +246,13 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma
 
        // Create a temporary workspace
        for ( i = 0; i < 4; i++ )
-               audio_channels[ i ] = mlt_pool_allocate( DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), &audio_release[ i ] );
+               audio_channels[ i ] = mlt_pool_alloc( DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) );
 
        // Create a workspace for the result
-       *buffer = mlt_pool_allocate( *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), &release );
+       *buffer = mlt_pool_alloc( *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) );
 
        // Pass the allocated audio buffer as a property
-       mlt_properties_set_data( properties, "audio_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-       mlt_properties_set_data( properties, "audio", *buffer, *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), NULL, NULL );
+       mlt_properties_set_data( properties, "audio", *buffer, *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), ( mlt_destructor )mlt_pool_release, NULL );
 
        // Decode the audio
        dv_decode_full_audio( decoder, dv_data, audio_channels );
@@ -273,7 +265,7 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma
 
        // Free the temporary work space
        for ( i = 0; i < 4; i++ )
-               mlt_pool_release( audio_release[ i ] );
+               mlt_pool_release( audio_channels[ i ] );
 
        return 0;
 }
@@ -281,8 +273,7 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma
 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
 {
        producer_libdv this = producer->child;
-       void *release = NULL;
-       uint8_t *data = mlt_pool_allocate( frame_size_625_50, &release );
+       uint8_t *data = mlt_pool_alloc( frame_size_625_50 );
        
        // Obtain the current frame number
        uint64_t position = mlt_producer_frame( producer );
@@ -305,8 +296,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
                mlt_properties_set_data( properties, "dv_decoder", this->dv_decoder, 0, NULL, NULL );
 
                // Pass the dv data
-               mlt_properties_set_data( properties, "dv_data_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "dv_data", data, frame_size_625_50, NULL, NULL );
+               mlt_properties_set_data( properties, "dv_data", data, frame_size_625_50, ( mlt_destructor )mlt_pool_release, NULL );
 
                // Update other info on the frame
                mlt_properties_set_int( properties, "width", 720 );
@@ -326,7 +316,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        }
        else
        {
-               mlt_pool_release( release );
+               mlt_pool_release( data );
        }
 
        // Update timecode on the frame we're creating
index b3f32ee4ee32e2d6d78048a931f5174207e0e275..cc7613084df086cd2aa71b01976932aae1cc7ad7 100644 (file)
@@ -465,8 +465,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
        if ( video != NULL && read_ffmpeg_header( this, &width, &height ) == 2 )
        {
                // Allocate an image
-               void *release = NULL;
-               uint8_t *image = mlt_pool_allocate( width * ( height + 1 ) * 2, &release );
+               uint8_t *image = mlt_pool_alloc( width * ( height + 1 ) * 2 );
                
                // Read it
                while( skip -- )
@@ -483,8 +482,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
                mlt_convert_yuv420p_to_yuv422( this->buffer, width, height, width, image );
 
                // Pass the data on the frame properties
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", image, width * ( height + 1 ) * 2, NULL, NULL );
+               mlt_properties_set_data( properties, "image", image, width * ( height + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                mlt_properties_set_int( properties, "width", width );
                mlt_properties_set_int( properties, "height", height );
                mlt_properties_set_int( properties, "has_image", 1 );
index 049e68af52d80b07617757ed5b025171ac7b3803..f70c039cfa4563476be1827efa021e05630e7e7c 100644 (file)
@@ -75,8 +75,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                if ( *format == mlt_image_yuv422 && strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                {
                        // Create the output image
-                       void *release = NULL;
-                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+                       uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                        // Calculate strides
                        int istride = iwidth * 2;
@@ -85,8 +84,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        yuv422_scale_simple( output, owidth, oheight, ostride, input, iwidth, iheight, istride, interp );
                
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );
 
@@ -98,8 +96,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        int bpp = (*format == mlt_image_rgb24a ? 4 : 3 );
                        
                        // Create the yuv image
-                       void *release = NULL;
-                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
+                       uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
 
                        if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                        {
@@ -114,8 +111,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       void *alpha_release = NULL;
-                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
+                                       uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( scaled ),
@@ -123,8 +119,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  gdk_pixbuf_get_rowstride( scaled ),
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
                                }
                                else
                                {
@@ -142,8 +137,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       void *alpha_release = NULL;
-                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
+                                       uint8_t *alpha = mlt_pool_alloc( owidth * ( oheight + 1 ) );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( input,
@@ -151,8 +145,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  owidth * 4,
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
                                }
                                else
                                {
@@ -165,8 +158,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        }
 
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );
 
index bed28f9b9fd44aae49c90f4b2be7c29fd916817f..b7e8411cbdfd05f81276a51b6d98f1d7151868e6 100644 (file)
@@ -31,9 +31,7 @@ struct producer_pango_s
        struct mlt_producer_s parent;
        int width;
        int height;
-       void *image_release;
        uint8_t *image;
-       void *alpha_release;
        uint8_t *alpha;
        char *fgcolor;
        char *bgcolor;
@@ -273,10 +271,8 @@ static void refresh_image( mlt_frame frame, int width, int height )
                rgba_color fgcolor = parse_color( this->fgcolor );
                rgba_color bgcolor = parse_color( this->bgcolor );
 
-               mlt_pool_release( this->image_release );
-               mlt_pool_release( this->alpha_release );
-               this->image_release = NULL;
-               this->alpha_release = NULL;
+               mlt_pool_release( this->image );
+               mlt_pool_release( this->alpha );
                this->image = NULL;
                this->alpha = NULL;
 
@@ -298,10 +294,8 @@ static void refresh_image( mlt_frame frame, int width, int height )
        }
        else if ( width > 0 && ( this->image == NULL || width != this->width || height != this->height ) )
        {
-               mlt_pool_release( this->image_release );
-               mlt_pool_release( this->alpha_release );
-               this->image_release = NULL;
-               this->alpha_release = NULL;
+               mlt_pool_release( this->image );
+               mlt_pool_release( this->alpha );
                this->image = NULL;
                this->alpha = NULL;
 
@@ -331,8 +325,8 @@ static void refresh_image( mlt_frame frame, int width, int height )
                this->height = height;
 
                // Allocate/define image
-               this->image = mlt_pool_allocate( width * ( height + 1 ) * 2, &this->image_release );
-               this->alpha = mlt_pool_allocate( this->width * this->height, &this->alpha_release );
+               this->image = mlt_pool_alloc( width * ( height + 1 ) * 2 );
+               this->alpha = mlt_pool_alloc( this->width * this->height );
 
                // Convert the image
                mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( pixbuf ),
@@ -384,16 +378,14 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        if ( writable )
        {
                // Clone our image
-               void *release = NULL;
-               uint8_t *copy = mlt_pool_allocate( size, &release );
+               uint8_t *copy = mlt_pool_alloc( size );
                memcpy( copy, image, size );
 
                // We're going to pass the copy on
                image = copy;
 
                // Now update properties so we free the copy after
-               mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", copy, size, NULL, NULL );
+               mlt_properties_set_data( properties, "image", copy, size, ( mlt_destructor )mlt_pool_release, NULL );
        }
 
        // Pass on the image
@@ -449,8 +441,8 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 static void producer_close( mlt_producer parent )
 {
        producer_pango this = parent->child;
-       mlt_pool_release( this->image_release );
-       mlt_pool_release( this->alpha_release );
+       mlt_pool_release( this->image );
+       mlt_pool_release( this->alpha );
        free( this->fgcolor );
        free( this->bgcolor );
        free( this->markup );
@@ -492,7 +484,6 @@ static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const
        uint8_t *src = NULL;
        uint8_t* dest = NULL;
        int stride;
-       void *release = NULL;
 
        pango_ft2_font_map_set_resolution( fontmap, 72, 72 );
        pango_layout_set_width( layout, -1 ); // set wrapping constraints
@@ -515,7 +506,7 @@ static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const
        bitmap.width     = w;
        bitmap.pitch     = 32 * ( ( w + 31 ) / 31 );
        bitmap.rows      = h;
-       bitmap.buffer    = mlt_pool_allocate( h * bitmap.pitch, &release );
+       bitmap.buffer    = mlt_pool_alloc( h * bitmap.pitch );
        bitmap.num_grays = 256;
        bitmap.pixel_mode = ft_pixel_mode_grays;
 
@@ -539,7 +530,7 @@ static GdkPixbuf *pango_get_pixbuf( const char *markup, const char *text, const
                }
                dest += stride;
        }
-       mlt_pool_release( release );
+       mlt_pool_release( bitmap.buffer );
        g_object_unref( layout );
        g_object_unref( context );
        g_object_unref( fontmap );
index d77d73103b18b27ceb8214858c9ca8773c132920..b73d64b1e20c5b3093161110609642c0024b4703 100644 (file)
@@ -44,9 +44,7 @@ struct producer_pixbuf_s
 
        int width;
        int height;
-       void *image_release;
        uint8_t *image;
-       void *alpha_release;
        uint8_t *alpha;
 };
 
@@ -181,20 +179,16 @@ static void refresh_image( mlt_frame frame, int width, int height )
                if ( width != this->width || height != this->height )
                {
                        pixbuf = mlt_properties_get_data( producer_props, "pixbuf", NULL );
-                       mlt_pool_release( this->image_release );
-                       mlt_pool_release( this->alpha_release );
-                       this->image_release = NULL;
-                       this->alpha_release = NULL;
+                       mlt_pool_release( this->image );
+                       mlt_pool_release( this->alpha );
                        this->image = NULL;
                        this->alpha = NULL;
                }
        }
        else if ( this->image == NULL || image_idx != this->image_idx )
        {
-               mlt_pool_release( this->image_release );
-               mlt_pool_release( this->alpha_release );
-               this->image_release = NULL;
-               this->alpha_release = NULL;
+               mlt_pool_release( this->image );
+               mlt_pool_release( this->alpha );
                this->image = NULL;
                this->alpha = NULL;
 
@@ -236,13 +230,13 @@ static void refresh_image( mlt_frame frame, int width, int height )
                this->height = height;
                
                // Allocate/define image
-               this->image = mlt_pool_allocate( width * ( height + 1 ) * 2, &this->image_release );
+               this->image = mlt_pool_alloc( width * ( height + 1 ) * 2 );
 
                // Extract YUV422 and alpha
                if ( gdk_pixbuf_get_has_alpha( pixbuf ) )
                {
                        // Allocate the alpha mask
-                       this->alpha = mlt_pool_allocate( this->width * this->height, &this->alpha_release );
+                       this->alpha = mlt_pool_alloc( this->width * this->height );
 
                        // Convert the image
                        mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( pixbuf ),
@@ -305,16 +299,14 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
        //if ( writable )
        {
                // Clone our image
-               void *release = NULL;
-               uint8_t *copy = mlt_pool_allocate( size, &release );
+               uint8_t *copy = mlt_pool_alloc( size );
                memcpy( copy, image, size );
 
                // We're going to pass the copy on
                image = copy;
 
                // Now update properties so we free the copy after
-               mlt_properties_set_data( properties, "image_release", release, 0, mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "image", copy, size, NULL, NULL );
+               mlt_properties_set_data( properties, "image", copy, size, mlt_pool_release, NULL );
        }
 
        // Pass on the image
@@ -368,7 +360,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 static void producer_close( mlt_producer parent )
 {
        producer_pixbuf this = parent->child;
-       free( this->image );
+       mlt_pool_release( this->image );
        parent->close = NULL;
        mlt_producer_close( parent );
        free( this );
index ce07eb07b73a2ce37e824846641a42d8c9786f9c..f40384c1b97dcf9345fa8ae3de8263c56cc25945 100644 (file)
@@ -54,12 +54,12 @@ static int resample_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Get the producer's audio
        mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
 
-       //fprintf( stderr, "resample_get_audio: output_rate %d\n", output_rate );
-       
        // Return now if now work to do
        if ( output_rate == *frequency )
                return 0;
 
+       //fprintf( stderr, "resample_get_audio: input_rate %d output_rate %d\n", *frequency, output_rate );
+       
        // Convert to floating point
        for ( i = 0; i < *samples * *channels; ++i )
                input_buffer[ i ] = ( float )( (*buffer)[ i ] ) / 32768;
@@ -76,10 +76,8 @@ static int resample_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        {
                if ( data.output_frames_gen > *samples )
                {
-                       void *release = NULL;
-                       *buffer = mlt_pool_allocate( data.output_frames_gen * *channels * sizeof( int16_t ), &release );
-                       mlt_properties_set_data( properties, "audio_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( properties, "audio", *buffer, *channels * data.output_frames_gen * 2, NULL, NULL );
+                       *buffer = mlt_pool_alloc( data.output_frames_gen * *channels * sizeof( int16_t ) );
+                       mlt_properties_set_data( properties, "audio", *buffer, *channels * data.output_frames_gen * 2, mlt_pool_release, NULL );
                }
                *samples = data.output_frames_gen;
                *frequency = output_rate;
@@ -143,19 +141,15 @@ mlt_filter filter_resample_init( char *arg )
                SRC_STATE *state = src_new( RESAMPLE_TYPE, 2 /* channels */, &error );
                if ( error == 0 )
                {
-                       void *input_release = NULL;
-                       void *input_buffer = mlt_pool_allocate( BUFFER_LEN, &input_release );
-                       void *output_release = NULL;
-                       void *output_buffer = mlt_pool_allocate( BUFFER_LEN, &output_release );
+                       void *input_buffer = mlt_pool_alloc( BUFFER_LEN );
+                       void *output_buffer = mlt_pool_alloc( BUFFER_LEN );
                        this->process = filter_process;
                        if ( arg != NULL )
                                mlt_properties_set_int( mlt_filter_properties( this ), "frequency", atoi( arg ) );
                        mlt_properties_set_int( mlt_filter_properties( this ), "channels", 2 );
                        mlt_properties_set_data( mlt_filter_properties( this ), "state", state, 0, (mlt_destructor)src_delete, NULL );
-                       mlt_properties_set_data( mlt_filter_properties( this ), "input_release", input_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( mlt_filter_properties( this ), "input_buffer", input_buffer, BUFFER_LEN, NULL, NULL );
-                       mlt_properties_set_data( mlt_filter_properties( this ), "output_release", output_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( mlt_filter_properties( this ), "output_buffer", output_buffer, BUFFER_LEN, NULL, NULL );
+                       mlt_properties_set_data( mlt_filter_properties( this ), "input_buffer", input_buffer, BUFFER_LEN, mlt_pool_release, NULL );
+                       mlt_properties_set_data( mlt_filter_properties( this ), "output_buffer", output_buffer, BUFFER_LEN, mlt_pool_release, NULL );
                }
                else
                {
index 2e5f70c751d5f06e84433330c11617da6a3807d8..1be99ce49fbd045e87dd02267efd15e0c6fecd60 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "consumer_sdl.h"
 #include <framework/mlt_frame.h>
+#include <framework/mlt_deque.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -36,8 +37,7 @@ struct consumer_sdl_s
 {
        struct mlt_consumer_s parent;
        mlt_properties properties;
-       int format;
-       int video;
+       mlt_deque queue;
        pthread_t thread;
        int running;
        uint8_t audio_buffer[ 4096 * 3 ];
@@ -50,9 +50,6 @@ struct consumer_sdl_s
        int width;
        int height;
        int playing;
-       mlt_frame *queue;
-       int size;
-       int count;
        int sdl_flags;
        SDL_Surface *sdl_screen;
        SDL_Overlay *sdl_overlay;
@@ -81,6 +78,9 @@ mlt_consumer consumer_sdl_init( char *arg )
        // If no malloc'd and consumer init ok
        if ( this != NULL && mlt_consumer_init( &this->parent, this ) == 0 )
        {
+               // Create the queue
+               this->queue = mlt_deque_init( );
+
                // Get the parent consumer object
                mlt_consumer parent = &this->parent;
 
@@ -119,7 +119,7 @@ mlt_consumer consumer_sdl_init( char *arg )
                this->window_height = this->height;
                
                // Set the sdl flags
-               this->sdl_flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_RESIZABLE;
+               this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_RESIZABLE;
 
                // Allow thread to be started/stopped
                parent->start = consumer_start;
@@ -329,23 +329,13 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                return 0;
        }
 
-       if ( this->count == this->size )
-       {
-               this->size += 25;
-               this->queue = realloc( this->queue, sizeof( mlt_frame ) * this->size );
-       }
-       this->queue[ this->count ++ ] = frame;
+       // Push this frame to the back of the queue
+       mlt_deque_push_back( this->queue, frame );
 
        if ( this->playing )
        {
-               // We're working on the oldest frame now
-               frame = this->queue[ 0 ];
-
-               // Shunt the frames in the queue down
-               int i = 0;
-               for ( i = 1; i < this->count; i ++ )
-                       this->queue[ i - 1 ] = this->queue[ i ];
-               this->count --;
+               // Get the frame at the front of the queue
+               frame = mlt_deque_pop_front( this->queue );
 
                // Get the image, width and height
                mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
@@ -447,7 +437,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                        this->buffer = this->sdl_overlay->pixels[ 0 ];
                        if ( SDL_LockYUVOverlay( this->sdl_overlay ) >= 0 )
                        {
-                               mlt_resize_yuv422( this->buffer, this->width - (this->width % 4 ), this->height- (this->height % 2 ), image, width, height );
+                               memcpy( this->buffer, image, width * height * 2 );
                                SDL_UnlockYUVOverlay( this->sdl_overlay );
                                SDL_DisplayYUVOverlay( this->sdl_overlay, &this->sdl_screen->clip_rect );
                        }
@@ -462,12 +452,13 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
        if ( frame != NULL )
                mlt_frame_close( frame );
 
-       if ( this->count )
+       if ( mlt_deque_count( this->queue ) )
        {
                // Tell the producers about our scale relative to the normalisation
-               mlt_properties_set_double( mlt_frame_properties( this->queue[ this->count - 1 ] ), "consumer_scale",
+               frame = mlt_deque_peek_front( this->queue );
+               mlt_properties_set_double( mlt_frame_properties( frame ), "consumer_scale",
                        ( double )height / mlt_properties_get_double( properties, "height" ) );
-               mlt_frame_get_image( this->queue[ this->count - 1 ], &image, &vfmt, &width, &height, 0 );
+               mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
        }
 
        return 0;
@@ -518,8 +509,8 @@ static void *consumer_thread( void *arg )
                SDL_FreeYUVOverlay( this->sdl_overlay );
        SDL_Quit( );
 
-       while( -- this->count >= 0 )
-               mlt_frame_close( this->queue[ this->count ] );
+       while( mlt_deque_count( this->queue ) )
+               mlt_frame_close( mlt_deque_pop_back( this->queue ) );
 
        this->sdl_screen = NULL;
        this->sdl_overlay = NULL;
index 3557cb4feeb6f0e24b03b32094a5780a61ea562c..35fd3a2c09b1ec996741406211daa30b408c550a 100644 (file)
@@ -203,15 +203,11 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
        // Check for audio buffer and create if necessary
        if ( audio_buffer == NULL )
        {
-               // Release pointer
-               void *release = NULL;
-
                // Allocate the audio buffer
-               audio_buffer = mlt_pool_allocate( 131072 * sizeof( int16_t ), &release );
+               audio_buffer = mlt_pool_alloc( 131072 * sizeof( int16_t ) );
 
                // And store it on properties for reuse
-               mlt_properties_set_data( properties, "audio_buffer_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-               mlt_properties_set_data( properties, "audio_buffer", audio_buffer, 0, NULL, NULL );
+               mlt_properties_set_data( properties, "audio_buffer", audio_buffer, 0, mlt_pool_release, NULL );
        }
 
        // Seek if necessary
@@ -274,13 +270,11 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form
                // Now handle the audio if we have enough
                if ( audio_used >= *samples )
                {
-                       void *release = NULL;
-                       *buffer = mlt_pool_allocate( *samples * *channels * sizeof( int16_t ), &release );
+                       *buffer = mlt_pool_alloc( *samples * *channels * sizeof( int16_t ) );
                        memcpy( *buffer, audio_buffer, *samples * *channels * sizeof( int16_t ) );
                        audio_used -= *samples;
                        memmove( audio_buffer, &audio_buffer[ *samples * *channels ], audio_used * *channels * sizeof( int16_t ) );
-                       mlt_properties_set_data( frame_properties, "audio_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
-                       mlt_properties_set_data( frame_properties, "audio", *buffer, 0, NULL, NULL );
+                       mlt_properties_set_data( frame_properties, "audio", *buffer, 0, mlt_pool_release, NULL );
                }
                else
                {
index 263d72eb5b77fba333fd2872c32090e7cf3f1182..e6883dd8959f7a585b2ef0bfc8620969b8f46548 100644 (file)
@@ -4,6 +4,11 @@ CFLAGS = -O3 -I .. -Wall -rdynamic -pthread
 
 LDFLAGS = -L ../framework -lmlt 
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 all: $(TARGET)
 
 pango:         pango.o
index 6fa6d0a136cfd436ef811f47e2f3dff6bda4bb3b..7322577fb736a8f05707808c83037331b8424a80 100644 (file)
@@ -17,6 +17,11 @@ CFLAGS=-O3 -Wall -g -D_FILE_OFFSET_BITS=64 -pthread
 
 LDFLAGS=-ldv -lpthread
 
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
 all: $(TARGET)
 
 $(TARGET): $(OBJS)