Index: gstffmpeg.c
===================================================================
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpeg.c,v
retrieving revision 1.27
diff -u -r1.27 gstffmpeg.c
--- gstffmpeg.c	13 Sep 2005 12:16:32 -0000	1.27
+++ gstffmpeg.c	13 Dec 2005 13:31:47 -0000
@@ -37,6 +37,31 @@
 
 GST_DEBUG_CATEGORY (ffmpeg_debug);
 
+static GStaticMutex gst_avcodec_mutex = G_STATIC_MUTEX_INIT;
+
+
+int
+gst_ffmpeg_avcodec_open (AVCodecContext *avctx, AVCodec *codec) {
+  int ret;
+
+  g_static_mutex_lock (&gst_avcodec_mutex);
+  ret = avcodec_open (avctx, codec);
+  g_static_mutex_unlock (&gst_avcodec_mutex);
+  
+  return ret;
+}
+
+int
+gst_ffmpeg_avcodec_close (AVCodecContext *avctx) {
+  int ret;
+  
+  g_static_mutex_lock (&gst_avcodec_mutex);
+  ret = avcodec_close (avctx);
+  g_static_mutex_unlock (&gst_avcodec_mutex);
+  
+  return ret;
+}
+
 #ifndef GST_DISABLE_GST_DEBUG
 static void
 gst_ffmpeg_log_callback (void * ptr, int level, const char * fmt, va_list vl)
Index: gstffmpeg.h
===================================================================
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpeg.h,v
retrieving revision 1.4
diff -u -r1.4 gstffmpeg.h
--- gstffmpeg.h	13 Sep 2005 12:16:32 -0000	1.4
+++ gstffmpeg.h	13 Dec 2005 13:31:48 -0000
@@ -51,6 +51,9 @@
 extern gboolean gst_ffmpegscale_register (GstPlugin * plugin);
 extern gboolean gst_ffmpegdeinterlace_register (GstPlugin * plugin);
 
+int gst_ffmpeg_avcodec_open (AVCodecContext *avctx, AVCodec *codec);
+int gst_ffmpeg_avcodec_close (AVCodecContext *avctx);
+
 G_END_DECLS
 
 extern URLProtocol gstreamer_protocol;
Index: gstffmpegdec.c
===================================================================
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegdec.c,v
retrieving revision 1.131
diff -u -r1.131 gstffmpegdec.c
--- gstffmpegdec.c	7 Dec 2005 12:14:34 -0000	1.131
+++ gstffmpegdec.c	13 Dec 2005 13:31:49 -0000
@@ -384,7 +384,7 @@
   }
 
   if (ffmpegdec->context->priv_data)
-    avcodec_close (ffmpegdec->context);
+    gst_ffmpeg_avcodec_close (ffmpegdec->context);
   ffmpegdec->opened = FALSE;
 
   if (ffmpegdec->context->palctrl) {
@@ -419,7 +419,7 @@
   GstFFMpegDecClass *oclass =
       (GstFFMpegDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
 
-  if (avcodec_open (ffmpegdec->context, oclass->in_plugin) < 0)
+  if (gst_ffmpeg_avcodec_open (ffmpegdec->context, oclass->in_plugin) < 0)
     goto could_not_open;
 
   ffmpegdec->opened = TRUE;
Index: gstffmpegenc.c
===================================================================
RCS file: /cvs/gstreamer/gst-ffmpeg/ext/ffmpeg/gstffmpegenc.c,v
retrieving revision 1.80
diff -u -r1.80 gstffmpegenc.c
--- gstffmpegenc.c	6 Dec 2005 19:57:08 -0000	1.80
+++ gstffmpegenc.c	13 Dec 2005 13:31:50 -0000
@@ -283,7 +283,7 @@
 
   /* close old session */
   if (ffmpegenc->opened) {
-    avcodec_close (ffmpegenc->context);
+    gst_ffmpeg_avcodec_close (ffmpegenc->context);
     ffmpegenc->opened = FALSE;
   }
 
@@ -338,17 +338,17 @@
   _shut_up_I_am_probing = TRUE;
   for (pixfmt = 0; pixfmt < PIX_FMT_NB; pixfmt++) {
     ctx->pix_fmt = pixfmt;
-    if (avcodec_open (ctx, oclass->in_plugin) >= 0 &&
+    if (gst_ffmpeg_avcodec_open (ctx, oclass->in_plugin) >= 0 &&
         ctx->pix_fmt == pixfmt) {
       ctx->width = -1;
       if (!caps)
         caps = gst_caps_new_empty ();
       gst_caps_append (caps,
           gst_ffmpeg_codectype_to_caps (oclass->in_plugin->type, ctx));
-      avcodec_close (ctx);
+      gst_ffmpeg_avcodec_close (ctx);
     }
     if (ctx->priv_data)
-      avcodec_close (ctx);
+      gst_ffmpeg_avcodec_close (ctx);
   }
   av_free (ctx);
   _shut_up_I_am_probing = FALSE;
@@ -376,7 +376,7 @@
 
   /* close old session */
   if (ffmpegenc->opened) {
-    avcodec_close (ffmpegenc->context);
+    gst_ffmpeg_avcodec_close (ffmpegenc->context);
     ffmpegenc->opened = FALSE;
   }
 
@@ -417,9 +417,9 @@
   pix_fmt = ffmpegenc->context->pix_fmt;
 
   /* open codec */
-  if (avcodec_open (ffmpegenc->context, oclass->in_plugin) < 0) {
+  if (gst_ffmpeg_avcodec_open (ffmpegenc->context, oclass->in_plugin) < 0) {
     if (ffmpegenc->context->priv_data)
-      avcodec_close (ffmpegenc->context);
+      gst_ffmpeg_avcodec_close (ffmpegenc->context);
     GST_DEBUG ("ffenc_%s: Failed to open FFMPEG codec",
         oclass->in_plugin->name);
     return FALSE;
@@ -427,7 +427,7 @@
 
   /* is the colourspace correct? */
   if (pix_fmt != ffmpegenc->context->pix_fmt) {
-    avcodec_close (ffmpegenc->context);
+    gst_ffmpeg_avcodec_close (ffmpegenc->context);
     GST_DEBUG ("ffenc_%s: AV wants different colourspace (%d given, %d wanted)",
         oclass->in_plugin->name, pix_fmt, ffmpegenc->context->pix_fmt);
     return FALSE;
@@ -452,7 +452,7 @@
       ffmpegenc->context, TRUE);
 
   if (!other_caps) {
-    avcodec_close (ffmpegenc->context);
+    gst_ffmpeg_avcodec_close (ffmpegenc->context);
     GST_DEBUG ("Unsupported codec - no caps found");
     return FALSE;
   }
@@ -476,7 +476,7 @@
   }
 
   if (!gst_pad_set_caps (ffmpegenc->srcpad, icaps)) {
-    avcodec_close (ffmpegenc->context);
+    gst_ffmpeg_avcodec_close (ffmpegenc->context);
     gst_caps_unref (icaps);
     return FALSE;
   }
@@ -711,7 +711,7 @@
   switch (transition) {
     case GST_STATE_CHANGE_PAUSED_TO_READY:
       if (ffmpegenc->opened) {
-        avcodec_close (ffmpegenc->context);
+        gst_ffmpeg_avcodec_close (ffmpegenc->context);
         ffmpegenc->opened = FALSE;
       }
       if (ffmpegenc->cache) {
