Permalink
Browse files

Provide avcodec_{open,close} mutex safety

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
  • Loading branch information...
1 parent ef1935d commit bca0f41cc6fc2f7928e96a3d44a22bba5cada673 @felipec committed May 23, 2011
Showing with 37 additions and 7 deletions.
  1. +2 −2 gstav_adec.c
  2. +1 −1 gstav_h263enc.c
  3. +1 −1 gstav_h264enc.c
  4. +2 −2 gstav_vdec.c
  5. +1 −1 gstav_venc.c
  6. +24 −0 plugin.c
  7. +6 −0 plugin.h
View
@@ -185,7 +185,7 @@ pad_chain(GstPad *pad, GstBuffer *buf)
int hdr = self->header_func(self, buf);
if (!hdr) {
self->got_header = true;
- if (avcodec_open(self->av_ctx, self->codec) < 0) {
+ if (gst_av_codec_open(self->av_ctx, self->codec) < 0) {
ret = GST_FLOW_ERROR;
goto leave;
}
@@ -295,7 +295,7 @@ change_state(GstElement *element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
if (self->av_ctx) {
- avcodec_close(self->av_ctx);
+ gst_av_codec_close(self->av_ctx);
av_freep(&self->av_ctx);
}
av_free_packet(&self->pkt);
View
@@ -58,7 +58,7 @@ change_state(GstElement *element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
if (base->av_ctx) {
- avcodec_close(base->av_ctx);
+ gst_av_codec_close(base->av_ctx);
av_freep(&base->av_ctx);
}
break;
View
@@ -97,7 +97,7 @@ change_state(GstElement *element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
if (base->av_ctx) {
- avcodec_close(base->av_ctx);
+ gst_av_codec_close(base->av_ctx);
av_freep(&base->av_ctx);
}
break;
View
@@ -73,7 +73,7 @@ pad_chain(GstPad *pad, GstBuffer *buf)
GstStructure *struc;
self->initialized = true;
- if (avcodec_open(ctx, self->codec) < 0) {
+ if (gst_av_codec_open(ctx, self->codec) < 0) {
ret = GST_FLOW_ERROR;
goto leave;
}
@@ -160,7 +160,7 @@ change_state(GstElement *element, GstStateChange transition)
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
if (self->av_ctx) {
- avcodec_close(self->av_ctx);
+ gst_av_codec_close(self->av_ctx);
av_freep(&self->av_ctx);
}
break;
View
@@ -44,7 +44,7 @@ pad_chain(GstPad *pad, GstBuffer *buf)
GstStructure *struc;
self->initialized = true;
- if (avcodec_open(ctx, self->codec) < 0) {
+ if (gst_av_codec_open(ctx, self->codec) < 0) {
ret = GST_FLOW_ERROR;
goto leave;
}
View
@@ -18,6 +18,30 @@
GstDebugCategory *gstav_debug;
+static GStaticMutex gst_av_codec_mutex = G_STATIC_MUTEX_INIT;
+
+int gst_av_codec_open(AVCodecContext *avctx, AVCodec *codec)
+{
+ int ret;
+
+ g_static_mutex_lock (&gst_av_codec_mutex);
+ ret = avcodec_open (avctx, codec);
+ g_static_mutex_unlock (&gst_av_codec_mutex);
+
+ return ret;
+}
+
+int gst_av_codec_close(AVCodecContext *avctx)
+{
+ int ret;
+
+ g_static_mutex_lock (&gst_av_codec_mutex);
+ ret = avcodec_close (avctx);
+ g_static_mutex_unlock (&gst_av_codec_mutex);
+
+ return ret;
+}
+
static gboolean
plugin_init(GstPlugin *plugin)
{
View
@@ -14,4 +14,10 @@
extern GstDebugCategory *gstav_debug;
+struct AVCodecContext;
+struct AVCodec;
+
+int gst_av_codec_open(struct AVCodecContext *avctx, struct AVCodec *codec);
+int gst_av_codec_close(struct AVCodecContext *avctx);
+
#endif /* PLUGIN_H */

0 comments on commit bca0f41

Please sign in to comment.