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)
LDFLAGS = -lm -ldl -lpthread
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
all: $(TARGET)
$(TARGET): $(OBJS)
}
else
{
- void *release = NULL;
uint8_t *p;
uint8_t *q;
int size = 0;
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 )
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 );
}
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;
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
elements = blank_elements;
while ( elements -- )
{
- *out_line ++ = black[ 0 ];
- *out_line ++ = black[ 1 ];
+ *out_line ++ = 0;
+ *out_line ++ = 128;
}
int active_width = 2 * iwidth;
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.
elements = inactive_width;
while ( elements -- )
{
- *out_ptr ++ = black[ 0 ];
- *out_ptr ++ = black[ 1 ];
+ *out_ptr ++ = 0;
+ *out_ptr ++ = 128;
}
// Move to next input line
elements = blank_elements;
while ( elements -- )
{
- *out_line ++ = black[ 0 ];
- *out_line ++ = black[ 1 ];
+ *out_line ++ = 0;
+ *out_line ++ = 128;
}
}
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 );
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;
}
// 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 );
}
// Refresh our stats
- mlt_multitrack_refresh( this );
+ //mlt_multitrack_refresh( this );
}
return 0;
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;
/** 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 )
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 );
}
}
}
// 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 ) );
}
}
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
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 ];
/** 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;
// 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.
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.
#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( );
// 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 ) );
}
LDFLAGS = -L ../valerie -lvalerie
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
SRCS := $(OBJS:.o=.c)
all: $(TARGET)
LDFLAGS = -L ../framework -lmlt
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
SRCS := $(OBJS:.o=.c)
all: $(TARGET)
LDFLAGS = -L ../valerie -lvalerie -L ../framework -lmlt
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
SRCS := $(OBJS:.o=.c)
all: $(TARGET)
}
/** 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 )
// 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
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
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
{
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 )
{
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 )
{
// 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 )
{
// 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
{
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 )
{
// 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
{
mlt_properties_set_int( properties, "audio_used", audio_used );
// Release the temporary audio
- mlt_pool_release( temp_release );
+ mlt_pool_release( temp );
}
else
{
// 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 )
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 );
static void luma_read_pgm( FILE *f, float **map, int *width, int *height )
{
- void *release = NULL;
uint8_t *data = NULL;
while (1)
{
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;
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;
break;
}
- if ( release != NULL )
- mlt_pool_release( release );
+ if ( data != NULL )
+ mlt_pool_release( data );
}
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 );
}
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 );
}
{
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 )
{
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;
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;
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;
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
// 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 );
// 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;
}
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 );
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 );
}
else
{
- mlt_pool_release( release );
+ mlt_pool_release( data );
}
// Update timecode on the frame we're creating
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 -- )
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 );
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;
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 );
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 ) )
{
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 ),
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
{
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,
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
{
}
// 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 );
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;
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;
}
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;
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 ),
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
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 );
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
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;
}
dest += stride;
}
- mlt_pool_release( release );
+ mlt_pool_release( bitmap.buffer );
g_object_unref( layout );
g_object_unref( context );
g_object_unref( fontmap );
int width;
int height;
- void *image_release;
uint8_t *image;
- void *alpha_release;
uint8_t *alpha;
};
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;
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 ),
//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
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 );
// 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;
{
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;
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
{
#include "consumer_sdl.h"
#include <framework/mlt_frame.h>
+#include <framework/mlt_deque.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
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 ];
int width;
int height;
int playing;
- mlt_frame *queue;
- int size;
- int count;
int sdl_flags;
SDL_Surface *sdl_screen;
SDL_Overlay *sdl_overlay;
// 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;
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;
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 );
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 );
}
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;
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;
// 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
// 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
{
LDFLAGS = -L ../framework -lmlt
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
all: $(TARGET)
pango: pango.o
LDFLAGS=-ldv -lpthread
+ifeq ($(MLT_GPROF),true)
+CFLAGS+=-p
+LDFLAGS+=-p
+endif
+
all: $(TARGET)
$(TARGET): $(OBJS)