From 0eaa66100c7dbf8f0ea182faf0c9902c5fd9b114 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Fri, 4 Nov 2005 22:37:13 +0000 Subject: Added lock/unlock around find/open/close ffmpeg calls. CVS patchset: 7794 CVS date: 2005/11/04 22:37:13 --- src/libffmpeg/audio_decoder.c | 17 +++++++++++++---- src/libffmpeg/video_decoder.c | 12 ++++++++++-- src/libffmpeg/xine_decoder.c | 4 +++- src/libffmpeg/xine_decoder.h | 4 +++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/libffmpeg/audio_decoder.c b/src/libffmpeg/audio_decoder.c index 42a773138..38a152c0c 100644 --- a/src/libffmpeg/audio_decoder.c +++ b/src/libffmpeg/audio_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: audio_decoder.c,v 1.21 2005/10/30 00:32:52 miguelfreitas Exp $ + * $Id: audio_decoder.c,v 1.22 2005/11/04 22:37:14 tmattern Exp $ * * xine audio decoder plugin using ffmpeg * @@ -142,7 +142,9 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++) if(ff_audio_lookup[i].type == codec_type) { + pthread_mutex_lock (&ffmpeg_lock); this->codec = avcodec_find_decoder(ff_audio_lookup[i].id); + pthread_mutex_unlock (&ffmpeg_lock); _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, ff_audio_lookup[i].name); break; @@ -240,13 +242,15 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) { if( !this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock (&ffmpeg_lock); xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("ffmpeg_audio_dec: couldn't open decoder\n")); _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0); return; } - + pthread_mutex_unlock (&ffmpeg_lock); this->decoder_ok = 1; } @@ -334,9 +338,11 @@ static void ff_audio_reset (audio_decoder_t *this_gen) { this->size = 0; /* try to reset the wma decoder */ - if( this->context && this->decoder_ok ) { + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); avcodec_open (this->context, this->codec); + pthread_mutex_unlock (&ffmpeg_lock); } } @@ -347,8 +353,11 @@ static void ff_audio_dispose (audio_decoder_t *this_gen) { ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; - if( this->context && this->decoder_ok ) + if( this->context && this->decoder_ok ) { + pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); + pthread_mutex_unlock (&ffmpeg_lock); + } if (this->output_open) this->stream->audio_out->close (this->stream->audio_out, this->stream); diff --git a/src/libffmpeg/video_decoder.c b/src/libffmpeg/video_decoder.c index a94a4a115..656af6fd3 100644 --- a/src/libffmpeg/video_decoder.c +++ b/src/libffmpeg/video_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: video_decoder.c,v 1.58 2005/10/29 19:52:34 tmmm Exp $ + * $Id: video_decoder.c,v 1.59 2005/11/04 22:37:14 tmattern Exp $ * * xine video decoder plugin using ffmpeg * @@ -282,7 +282,9 @@ static void init_video_codec (ff_video_decoder_t *this, int codec_type) { for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++) if(ff_video_lookup[i].type == codec_type) { + pthread_mutex_lock(&ffmpeg_lock); this->codec = avcodec_find_decoder(ff_video_lookup[i].id); + pthread_mutex_unlock(&ffmpeg_lock); _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, ff_video_lookup[i].name); break; @@ -313,8 +315,11 @@ static void init_video_codec (ff_video_decoder_t *this, int codec_type) { * this flag here in case we are going to use direct rendering */ if(this->codec->capabilities & CODEC_CAP_DR1) { this->context->flags |= CODEC_FLAG_EMU_EDGE; - } + } + + pthread_mutex_lock(&ffmpeg_lock); if (avcodec_open (this->context, this->codec) < 0) { + pthread_mutex_unlock(&ffmpeg_lock); xprintf (this->stream->xine, XINE_VERBOSITY_LOG, _("ffmpeg_video_dec: couldn't open decoder\n")); free(this->context); @@ -322,6 +327,7 @@ static void init_video_codec (ff_video_decoder_t *this, int codec_type) { _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0); return; } + pthread_mutex_unlock(&ffmpeg_lock); lprintf("lavc decoder opened\n"); @@ -1332,7 +1338,9 @@ static void ff_dispose (video_decoder_t *this_gen) { lprintf ("ff_dispose\n"); if (this->decoder_ok) { + pthread_mutex_lock(&ffmpeg_lock); avcodec_close (this->context); + pthread_mutex_unlock(&ffmpeg_lock); this->stream->video_out->close(this->stream->video_out, this->stream); this->decoder_ok = 0; diff --git a/src/libffmpeg/xine_decoder.c b/src/libffmpeg/xine_decoder.c index 6cf35d3dd..600f14102 100644 --- a/src/libffmpeg/xine_decoder.c +++ b/src/libffmpeg/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.166 2005/10/29 19:52:34 tmmm Exp $ + * $Id: xine_decoder.c,v 1.167 2005/11/04 22:37:14 tmattern Exp $ * * xine decoder plugin using ffmpeg * @@ -36,6 +36,7 @@ */ pthread_once_t once_control = PTHREAD_ONCE_INIT; +pthread_mutex_t ffmpeg_lock; void avcodec_register_all(void) { @@ -133,6 +134,7 @@ void avcodec_register_all(void) } void init_once_routine(void) { + pthread_mutex_init(&ffmpeg_lock, NULL); avcodec_init(); avcodec_register_all(); } diff --git a/src/libffmpeg/xine_decoder.h b/src/libffmpeg/xine_decoder.h index 1c98f7ff1..4a8fcf171 100644 --- a/src/libffmpeg/xine_decoder.h +++ b/src/libffmpeg/xine_decoder.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.h,v 1.5 2005/02/20 09:36:02 valtri Exp $ + * $Id: xine_decoder.h,v 1.6 2005/11/04 22:37:13 tmattern Exp $ * */ @@ -50,4 +50,6 @@ extern decoder_info_t dec_info_ffmpeg_audio; extern pthread_once_t once_control; void init_once_routine(void); +extern pthread_mutex_t ffmpeg_lock; + #endif -- cgit v1.2.3