#define AUDIO_BUFFER_SIZE (1024 * 42)
#define VIDEO_BUFFER_SIZE (2048 * 1024)
-void avformat_lock( );
-void avformat_unlock( );
-
//
// This structure should be extended and made globally available in mlt
//
}
#endif
- avformat_lock();
-
// Continue if codec found and we can open it
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
if ( codec && avcodec_open2( c, codec, NULL ) >= 0 )
{
mlt_log_warning( NULL, "%s: Unable to encode audio - disabling audio output.\n", __FILE__ );
}
-
- avformat_unlock();
return audio_input_frame_size;
}
static void close_audio( AVFormatContext *oc, AVStream *st )
{
if ( st && st->codec )
- {
- avformat_lock();
avcodec_close( st->codec );
- avformat_unlock();
- }
}
/** Add a video output stream
video_enc->pix_fmt = codec->pix_fmts[ 0 ];
}
- // Open the codec safely
- avformat_lock();
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
int result = codec && avcodec_open2( video_enc, codec, NULL ) >= 0;
#else
int result = codec && avcodec_open( video_enc, codec ) >= 0;
#endif
- avformat_unlock();
return result;
}
{
if ( st && st->codec )
{
- avformat_lock();
av_freep( &st->codec->stats_in );
avcodec_close(st->codec);
- avformat_unlock();
}
}
// A static flag used to determine if avformat has been initialised
static int avformat_initialised = 0;
-// A locking mutex
-static pthread_mutex_t avformat_mutex;
-
-#if 0
-// These 3 functions should override the alloc functions in libavformat
-// but some formats or codecs seem to crash when used (wmv in particular)
-
-void *av_malloc( unsigned int size )
-{
- return mlt_pool_alloc( size );
-}
-
-void *av_realloc( void *ptr, unsigned int size )
-{
- return mlt_pool_realloc( ptr, size );
-}
-
-void av_free( void *ptr )
-{
- return mlt_pool_release( ptr );
-}
-#endif
-
static int avformat_lockmgr(void **mutex, enum AVLockOp op)
{
pthread_mutex_t** pmutex = (pthread_mutex_t**) mutex;
return 0;
}
-void avformat_destroy( void *ignore )
-{
- // Clean up
- // av_free_static( ); -XXX this is deprecated
-
- // Destroy the mutex
- pthread_mutex_destroy( &avformat_mutex );
-}
-
-void avformat_lock( )
-{
- // Lock the mutex now
- pthread_mutex_lock( &avformat_mutex );
-}
-
-void avformat_unlock( )
-{
- // Unlock the mutex now
- pthread_mutex_unlock( &avformat_mutex );
-}
-
static void avformat_init( )
{
// Initialise avformat if necessary
if ( avformat_initialised == 0 )
{
avformat_initialised = 1;
- pthread_mutex_init( &avformat_mutex, NULL );
av_lockmgr_register( &avformat_lockmgr );
av_register_all( );
#ifdef AVDEVICE
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(13<<8))
avformat_network_init();
#endif
- mlt_factory_register_for_clean_up( NULL, avformat_destroy );
av_log_set_level( mlt_log_get_level() );
}
}
#define MAX_AUDIO_STREAMS (10)
#define MAX_VDPAU_SURFACES (10)
-void avformat_lock( );
-void avformat_unlock( );
-
struct producer_avformat_s
{
mlt_producer parent;
mlt_deque apackets;
mlt_deque vpackets;
pthread_mutex_t packets_mutex;
+ pthread_mutex_t open_mutex;
#ifdef VDPAU
struct
{
else if ( self->seekable )
{
// Close the file to release resources for large playlists - reopen later as needed
- avformat_lock();
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
if ( self->audio_format )
avformat_close_input( &self->audio_format );
#endif
self->audio_format = NULL;
self->video_format = NULL;
- avformat_unlock();
}
}
if ( producer )
pthread_mutex_init( &self->audio_mutex, NULL );
pthread_mutex_init( &self->video_mutex, NULL );
pthread_mutex_init( &self->packets_mutex, NULL );
+ pthread_mutex_init( &self->open_mutex, NULL );
pthread_mutex_lock( &self->audio_mutex );
pthread_mutex_lock( &self->video_mutex );
}
if ( self->dummy_context )
{
- avformat_lock();
+ pthread_mutex_lock( &self->open_mutex );
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
avformat_close_input( &self->dummy_context );
#else
av_close_input_file( self->dummy_context );
#endif
- avformat_unlock();
self->dummy_context = NULL;
+ pthread_mutex_unlock( &self->open_mutex );
}
// Unlock the service
mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
pthread_mutex_lock( &self->audio_mutex );
+ pthread_mutex_lock( &self->open_mutex );
- avformat_lock();
if ( self->video_codec )
avcodec_close( self->video_codec );
self->video_codec = NULL;
#endif
self->dummy_context = NULL;
self->video_format = NULL;
- avformat_unlock();
+ pthread_mutex_unlock( &self->open_mutex );
int audio_index = self->audio_index;
int video_index = self->video_index;
AVCodec *codec = avcodec_find_decoder( codec_context->codec_id );
// If we don't have a codec and we can't initialise it, we can't do much more...
- avformat_lock( );
+ pthread_mutex_lock( &self->open_mutex );
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
#else
self->max_frequency = codec_context->sample_rate;
avcodec_close( codec_context );
}
- avformat_unlock( );
+ pthread_mutex_unlock( &self->open_mutex );
}
}
mlt_log_verbose( NULL, "[producer avformat] audio: total_streams %d max_stream %d total_channels %d max_channels %d\n",
codec_context->thread_count = thread_count;
// If we don't have a codec and we can't initialise it, we can't do much more...
- avformat_lock( );
+ pthread_mutex_lock( &self->open_mutex );
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
#else
{
// Remember that we can't use this later
self->video_index = -1;
- avformat_unlock( );
+ pthread_mutex_unlock( &self->open_mutex );
return 0;
}
- avformat_unlock( );
+ pthread_mutex_unlock( &self->open_mutex );
// Process properties as AVOptions
apply_properties( codec_context, properties, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
{
// Reset the video properties if the index changed
self->video_index = index;
- avformat_lock();
+ pthread_mutex_lock( &self->open_mutex );
if ( self->video_codec )
avcodec_close( self->video_codec );
self->video_codec = NULL;
- avformat_unlock();
+ pthread_mutex_unlock( &self->open_mutex );
}
// Get the frame properties
AVCodec *codec = avcodec_find_decoder( codec_context->codec_id );
// If we don't have a codec and we can't initialise it, we can't do much more...
- avformat_lock( );
+ pthread_mutex_lock( &self->open_mutex );
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
if ( codec && avcodec_open2( codec_context, codec, NULL ) >= 0 )
#else
// Remember that we can't use self later
self->audio_index = -1;
}
- avformat_unlock( );
+ pthread_mutex_unlock( &self->open_mutex );
// Process properties as AVOptions
apply_properties( codec_context, properties, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM );
// Update the audio properties if the index changed
if ( context && index > -1 && index != self->audio_index )
{
- avformat_lock();
+ pthread_mutex_lock( &self->open_mutex );
if ( self->audio_codec[ self->audio_index ] )
avcodec_close( self->audio_codec[ self->audio_index ] );
self->audio_codec[ self->audio_index ] = NULL;
- avformat_unlock();
+ pthread_mutex_unlock( &self->open_mutex );
}
if ( self->audio_index != -1 )
self->audio_index = index;
// Cleanup av contexts
av_free( self->av_frame );
- avformat_lock();
+ pthread_mutex_lock( &self->open_mutex );
int i;
for ( i = 0; i < MAX_AUDIO_STREAMS; i++ )
{
if ( self->video_format )
av_close_input_file( self->video_format );
#endif
- avformat_unlock();
+ pthread_mutex_unlock( &self->open_mutex );
#ifdef VDPAU
vdpau_producer_close( self );
#endif
pthread_mutex_destroy( &self->audio_mutex );
pthread_mutex_destroy( &self->video_mutex );
pthread_mutex_destroy( &self->packets_mutex );
+ pthread_mutex_destroy( &self->open_mutex );
// Cleanup the packet queues
AVPacket *pkt;