From: lilo_booter Date: Fri, 20 Feb 2004 14:56:24 +0000 (+0000) Subject: Memory pooling part 2 and other optimisations X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=0b288164cbeb9a3c98107d439d86844be13ba910;p=melted Memory pooling part 2 and other optimisations git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@158 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/albino/Makefile b/src/albino/Makefile index 7507b8a..d294f57 100644 --- a/src/albino/Makefile +++ b/src/albino/Makefile @@ -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) diff --git a/src/framework/Makefile b/src/framework/Makefile index ae67859..52174e3 100644 --- a/src/framework/Makefile +++ b/src/framework/Makefile @@ -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) diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index a62ed7a..d0e08e3 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -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 ); diff --git a/src/framework/mlt_multitrack.c b/src/framework/mlt_multitrack.c index c9ea81c..ca3103a 100644 --- a/src/framework/mlt_multitrack.c +++ b/src/framework/mlt_multitrack.c @@ -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; diff --git a/src/framework/mlt_pool.c b/src/framework/mlt_pool.c index ab51392..16d1e1d 100644 --- a/src/framework/mlt_pool.c +++ b/src/framework/mlt_pool.c @@ -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. diff --git a/src/framework/mlt_pool.h b/src/framework/mlt_pool.h index 2775cb3..87ef08b 100644 --- a/src/framework/mlt_pool.h +++ b/src/framework/mlt_pool.h @@ -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( ); diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index b781660..d830e44 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -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 ) ); } diff --git a/src/humperdink/Makefile b/src/humperdink/Makefile index 86fc404..b8aba7a 100644 --- a/src/humperdink/Makefile +++ b/src/humperdink/Makefile @@ -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) diff --git a/src/inigo/Makefile b/src/inigo/Makefile index b9e0b5d..6fac85d 100644 --- a/src/inigo/Makefile +++ b/src/inigo/Makefile @@ -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) diff --git a/src/miracle/Makefile b/src/miracle/Makefile index bae78c2..445a812 100644 --- a/src/miracle/Makefile +++ b/src/miracle/Makefile @@ -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) diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index 605c002..a02f7cb 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -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, ¤t_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 { diff --git a/src/modules/core/producer_ppm.c b/src/modules/core/producer_ppm.c index ba09c3b..9865f80 100644 --- a/src/modules/core/producer_ppm.c +++ b/src/modules/core/producer_ppm.c @@ -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 ); diff --git a/src/modules/core/transition_luma.c b/src/modules/core/transition_luma.c index 167d4cf..c55a88b 100644 --- a/src/modules/core/transition_luma.c +++ b/src/modules/core/transition_luma.c @@ -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 ); } diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 02bef1f..b346b72 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -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 diff --git a/src/modules/ffmpeg/producer_ffmpeg.c b/src/modules/ffmpeg/producer_ffmpeg.c index b3f32ee..cc76130 100644 --- a/src/modules/ffmpeg/producer_ffmpeg.c +++ b/src/modules/ffmpeg/producer_ffmpeg.c @@ -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 ); diff --git a/src/modules/gtk2/filter_rescale.c b/src/modules/gtk2/filter_rescale.c index 049e68a..f70c039 100644 --- a/src/modules/gtk2/filter_rescale.c +++ b/src/modules/gtk2/filter_rescale.c @@ -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 ); diff --git a/src/modules/gtk2/producer_pango.c b/src/modules/gtk2/producer_pango.c index bed28f9..b7e8411 100644 --- a/src/modules/gtk2/producer_pango.c +++ b/src/modules/gtk2/producer_pango.c @@ -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 ); diff --git a/src/modules/gtk2/producer_pixbuf.c b/src/modules/gtk2/producer_pixbuf.c index d77d731..b73d64b 100644 --- a/src/modules/gtk2/producer_pixbuf.c +++ b/src/modules/gtk2/producer_pixbuf.c @@ -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 ); diff --git a/src/modules/resample/filter_resample.c b/src/modules/resample/filter_resample.c index ce07eb0..f40384c 100644 --- a/src/modules/resample/filter_resample.c +++ b/src/modules/resample/filter_resample.c @@ -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 { diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index 2e5f70c..1be99ce 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -20,6 +20,7 @@ #include "consumer_sdl.h" #include +#include #include #include #include @@ -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; diff --git a/src/modules/vorbis/producer_vorbis.c b/src/modules/vorbis/producer_vorbis.c index 3557cb4..35fd3a2 100644 --- a/src/modules/vorbis/producer_vorbis.c +++ b/src/modules/vorbis/producer_vorbis.c @@ -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 { diff --git a/src/tests/Makefile b/src/tests/Makefile index 263d72e..e6883dd 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -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 diff --git a/src/valerie/Makefile b/src/valerie/Makefile index 6fa6d0a..7322577 100644 --- a/src/valerie/Makefile +++ b/src/valerie/Makefile @@ -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)