From 0cbaf64858fe0e9e11b5b14691ff11b7ca8e9027 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Mon, 3 May 2004 12:20:20 +0000 Subject: [PATCH] minor clean ups; added a null consumer for easier valgrind testing git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@302 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/Makefile | 2 +- src/framework/mlt_consumer.c | 11 ++- src/modules/avformat/consumer_avformat.c | 7 +- src/modules/avformat/producer_avformat.c | 2 +- src/modules/core/Makefile | 3 +- src/modules/core/configure | 4 + src/modules/core/consumer_null.c | 173 ++++++++++++++++++++++++++++++ src/modules/core/consumer_null.h | 28 +++++ src/modules/core/factory.c | 3 + src/modules/core/producer_noise.c | 13 ++- src/modules/fezzik/producer_hold.c | 10 ++ src/modules/sdl/consumer_sdl.c | 2 - src/modules/vorbis/producer_vorbis.c | 2 +- 13 files changed, 250 insertions(+), 10 deletions(-) create mode 100644 src/modules/core/consumer_null.c create mode 100644 src/modules/core/consumer_null.h diff --git a/src/framework/Makefile b/src/framework/Makefile index bd364da..7a60973 100644 --- a/src/framework/Makefile +++ b/src/framework/Makefile @@ -22,7 +22,7 @@ OBJS = mlt_frame.o \ SRCS := $(OBJS:.o=.c) -CFLAGS += -pthread -DPREFIX="\"$(prefix)\"" +CFLAGS += -rdynamic -DPREFIX="\"$(prefix)\"" LDFLAGS += -lm $(LIBDL) -lpthread diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 86bed30..92d1927 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -274,7 +274,16 @@ static void *consumer_read_ahead_thread( void *arg ) frame = mlt_consumer_get_frame( this ); // Get the image of the first frame - mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 ); + if ( !video_off ) + mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 ); + + if ( !audio_off ) + { + samples = mlt_sample_calculator( fps, frequency, counter++ ); + mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples ); + frame->get_audio = NULL; + } + mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 1 ); // Get the starting time (can ignore the times above) diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 52fe9da..d4782cb 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -489,8 +489,8 @@ static void *consumer_thread( void *arg ) uint8_t *image; mlt_image_format img_fmt = mlt_image_yuv422; - // Fo receiving audio samples back from the fifo - int16_t buffer[ 48000 * 2 ]; + // For receiving audio samples back from the fifo + int16_t *buffer = av_malloc( 48000 * 2 ); int count = 0; // Allocate the context @@ -591,6 +591,8 @@ static void *consumer_thread( void *arg ) if ( audio_st ) audio_input_frame_size = open_audio( oc, audio_st, audio_outbuf_size ); + fprintf( stderr, "%d\n", audio_input_frame_size ); + // Open the output file, if needed if ( !( fmt->flags & AVFMT_NOFILE ) ) { @@ -794,6 +796,7 @@ static void *consumer_thread( void *arg ) av_free( input->data[0] ); av_free( input ); av_free( video_outbuf ); + av_free( buffer ); // Free the stream av_free(oc); diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index e50f2c1..dc92689 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -994,7 +994,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index mlt_frame_set_position( *frame, mlt_producer_position( this ) ); // Set the position of this producer - mlt_properties_set_position( mlt_frame_properties( *frame ), "avformat_position", mlt_producer_get_in( this ) + mlt_producer_position( this ) ); + mlt_properties_set_position( mlt_frame_properties( *frame ), "avformat_position", mlt_producer_position( this ) ); // Set up the video producer_set_up_video( this, *frame ); diff --git a/src/modules/core/Makefile b/src/modules/core/Makefile index 841d4e8..6ca6439 100644 --- a/src/modules/core/Makefile +++ b/src/modules/core/Makefile @@ -20,7 +20,8 @@ OBJS = factory.o \ transition_composite.o \ transition_luma.o \ transition_mix.o \ - transition_region.o + transition_region.o \ + consumer_null.o ASM_OBJS = composite_line_yuv_mmx.o diff --git a/src/modules/core/configure b/src/modules/core/configure index b3b3a2b..9373d83 100755 --- a/src/modules/core/configure +++ b/src/modules/core/configure @@ -30,4 +30,8 @@ mix libmltcore.so region libmltcore.so EOF +cat << EOF >> ../consumers.dat +null libmltcore.so +EOF + fi diff --git a/src/modules/core/consumer_null.c b/src/modules/core/consumer_null.c new file mode 100644 index 0000000..ae456b5 --- /dev/null +++ b/src/modules/core/consumer_null.c @@ -0,0 +1,173 @@ +/* + * consumer_null.c -- a null consumer + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +// Local header files +#include "consumer_null.h" + +// mlt Header files +#include + +// System header files +#include +#include +#include +#include + +// Forward references. +static int consumer_start( mlt_consumer this ); +static int consumer_stop( mlt_consumer this ); +static int consumer_is_stopped( mlt_consumer this ); +static void *consumer_thread( void *arg ); +static void consumer_close( mlt_consumer this ); + +/** Initialise the dv consumer. +*/ + +mlt_consumer consumer_null_init( char *arg ) +{ + // Allocate the consumer + mlt_consumer this = mlt_consumer_new( ); + + // If memory allocated and initialises without error + if ( this != NULL ) + { + // Assign close callback + this->close = consumer_close; + + // Set up start/stop/terminated callbacks + this->start = consumer_start; + this->stop = consumer_stop; + this->is_stopped = consumer_is_stopped; + } + + // Return this + return this; +} + +/** Start the consumer. +*/ + +static int consumer_start( mlt_consumer this ) +{ + // Get the properties + mlt_properties properties = mlt_consumer_properties( this ); + + // Check that we're not already running + if ( !mlt_properties_get_int( properties, "running" ) ) + { + // Allocate a thread + pthread_t *thread = calloc( 1, sizeof( pthread_t ) ); + pthread_attr_t thread_attributes; + + // Assign the thread to properties + mlt_properties_set_data( properties, "thread", thread, sizeof( pthread_t ), free, NULL ); + + // Set the running state + mlt_properties_set_int( properties, "running", 1 ); + + // Inherit the scheduling priority + pthread_attr_init( &thread_attributes ); + pthread_attr_setinheritsched( &thread_attributes, PTHREAD_INHERIT_SCHED ); + + // Create the thread + pthread_create( thread, &thread_attributes, consumer_thread, this ); + } + return 0; +} + +/** Stop the consumer. +*/ + +static int consumer_stop( mlt_consumer this ) +{ + // Get the properties + mlt_properties properties = mlt_consumer_properties( this ); + + // Check that we're running + if ( mlt_properties_get_int( properties, "running" ) ) + { + // Get the thread + pthread_t *thread = mlt_properties_get_data( properties, "thread", NULL ); + + // Stop the thread + mlt_properties_set_int( properties, "running", 0 ); + + // Wait for termination + pthread_join( *thread, NULL ); + } + + return 0; +} + +/** Determine if the consumer is stopped. +*/ + +static int consumer_is_stopped( mlt_consumer this ) +{ + // Get the properties + mlt_properties properties = mlt_consumer_properties( this ); + return !mlt_properties_get_int( properties, "running" ); +} + +/** The main thread - the argument is simply the consumer. +*/ + +static void *consumer_thread( void *arg ) +{ + // Map the argument to the object + mlt_consumer this = arg; + + // Get the properties + mlt_properties properties = mlt_consumer_properties( this ); + + // Frame and size + mlt_frame frame = NULL; + + // Loop while running + while( mlt_properties_get_int( properties, "running" ) ) + { + // Get the frame + frame = mlt_consumer_rt_frame( this ); + + // Check that we have a frame to work with + if ( frame != NULL ) + { + // Close the frame + mlt_frame_close( frame ); + } + } + + return NULL; +} + +/** Close the consumer. +*/ + +static void consumer_close( mlt_consumer this ) +{ + // Stop the consumer + mlt_consumer_stop( this ); + + // Close the parent + mlt_consumer_close( this ); + + // Free the memory + free( this ); +} diff --git a/src/modules/core/consumer_null.h b/src/modules/core/consumer_null.h new file mode 100644 index 0000000..5803455 --- /dev/null +++ b/src/modules/core/consumer_null.h @@ -0,0 +1,28 @@ +/* + * consumer_null.h -- null consumer + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _CONSUMER_NULL_H_ +#define _CONSUMER_NULL_H + +#include + +extern mlt_consumer consumer_null_init( char *arg ); + +#endif diff --git a/src/modules/core/factory.c b/src/modules/core/factory.c index c832a9c..f8a5fb4 100644 --- a/src/modules/core/factory.c +++ b/src/modules/core/factory.c @@ -38,6 +38,7 @@ #include "transition_luma.h" #include "transition_mix.h" #include "transition_region.h" +#include "consumer_null.h" void *mlt_create_producer( char *id, void *arg ) { @@ -92,5 +93,7 @@ void *mlt_create_transition( char *id, void *arg ) void *mlt_create_consumer( char *id, void *arg ) { + if ( !strcmp( id, "null" ) ) + return consumer_null_init( arg ); return NULL; } diff --git a/src/modules/core/producer_noise.c b/src/modules/core/producer_noise.c index 9afe385..f4c63a4 100644 --- a/src/modules/core/producer_noise.c +++ b/src/modules/core/producer_noise.c @@ -42,6 +42,7 @@ static unsigned inline int fast_rand( ) // Foward declarations static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ); +static void producer_close( mlt_producer this ); /** Initialise. */ @@ -54,8 +55,12 @@ mlt_producer producer_noise_init( void *arg ) // Initialise the producer if ( this != NULL ) { + // Synthetic - aspect ratio of 1 + mlt_properties_set_double( mlt_producer_properties( this ), "aspect_ratio", 1 ); + // Callback registration this->get_frame = producer_get_frame; + this->close = producer_close; } return this; @@ -124,7 +129,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form { int16_t *p = *buffer + size / 2; while ( p != *buffer ) - *( -- p ) = fast_rand( ) & 0xff; + *( -- p ) = fast_rand( ) & 0x0f00; } // Set the buffer for destruction @@ -166,4 +171,10 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index return 0; } +static void producer_close( mlt_producer this ) +{ + this->close = NULL; + mlt_producer_close( this ); + free( this ); +} diff --git a/src/modules/fezzik/producer_hold.c b/src/modules/fezzik/producer_hold.c index d1fdf08..6c33877 100644 --- a/src/modules/fezzik/producer_hold.c +++ b/src/modules/fezzik/producer_hold.c @@ -28,6 +28,7 @@ // Forward references static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ); +static void producer_close( mlt_producer this ); /** Constructor for the frame holding producer. Basically, all this producer does is provide a producer wrapper for the requested producer, allows the specifcation of @@ -61,6 +62,7 @@ mlt_producer producer_hold_init( char *arg ) // Override the get_frame method this->get_frame = producer_get_frame; + this->close = producer_close; } else { @@ -187,3 +189,11 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index return 0; } + +static void producer_close( mlt_producer this ) +{ + this->close = NULL; + mlt_producer_close( this ); + free( this ); +} + diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index aac59c8..84daf73 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -630,8 +630,6 @@ static void *consumer_thread( void *arg ) } // internal cleanup - if ( init_audio == 0 ) - SDL_AudioQuit( ); if ( this->sdl_overlay != NULL ) SDL_FreeYUVOverlay( this->sdl_overlay ); SDL_Quit( ); diff --git a/src/modules/vorbis/producer_vorbis.c b/src/modules/vorbis/producer_vorbis.c index 35fd3a2..46cae76 100644 --- a/src/modules/vorbis/producer_vorbis.c +++ b/src/modules/vorbis/producer_vorbis.c @@ -327,7 +327,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index mlt_frame_set_position( *frame, mlt_producer_position( this ) ); // Set the position of this producer - mlt_properties_set_position( mlt_frame_properties( *frame ), "vorbis_position", mlt_producer_get_in( this ) + mlt_producer_position( this ) ); + mlt_properties_set_position( mlt_frame_properties( *frame ), "vorbis_position", mlt_producer_position( this ) ); // Set up the audio producer_set_up_audio( this, *frame ); -- 1.7.4.4