mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
ext/ffmpeg/: Do proper locking around avcodec_open() and avcodec_close()
Original commit message from CVS: * ext/ffmpeg/gstffmpeg.c: (gst_ffmpeg_avcodec_open), (gst_ffmpeg_avcodec_close): * ext/ffmpeg/gstffmpeg.h: * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_close), (gst_ffmpegdec_open): * ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_dispose), (gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps), (gst_ffmpegenc_change_state): Do proper locking around avcodec_open() and avcodec_close() (fixes #322254, patch by: Sebastien Cote and Luca Ognibene).
This commit is contained in:
parent
83e9f5a5a0
commit
38dc71e266
5 changed files with 54 additions and 13 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2005-12-16 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* ext/ffmpeg/gstffmpeg.c: (gst_ffmpeg_avcodec_open),
|
||||||
|
(gst_ffmpeg_avcodec_close):
|
||||||
|
* ext/ffmpeg/gstffmpeg.h:
|
||||||
|
* ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_close),
|
||||||
|
(gst_ffmpegdec_open):
|
||||||
|
* ext/ffmpeg/gstffmpegenc.c: (gst_ffmpegenc_dispose),
|
||||||
|
(gst_ffmpegenc_getcaps), (gst_ffmpegenc_setcaps),
|
||||||
|
(gst_ffmpegenc_change_state):
|
||||||
|
Do proper locking around avcodec_open() and avcodec_close()
|
||||||
|
(fixes #322254, patch by: Sebastien Cote and Luca Ognibene).
|
||||||
|
|
||||||
2005-12-10 Tim-Philipp Müller <tim at centricular dot net>
|
2005-12-10 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* gst-libs/ext/Makefile.am:
|
* gst-libs/ext/Makefile.am:
|
||||||
|
|
|
@ -37,6 +37,31 @@
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY (ffmpeg_debug);
|
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
|
#ifndef GST_DISABLE_GST_DEBUG
|
||||||
static void
|
static void
|
||||||
gst_ffmpeg_log_callback (void * ptr, int level, const char * fmt, va_list vl)
|
gst_ffmpeg_log_callback (void * ptr, int level, const char * fmt, va_list vl)
|
||||||
|
|
|
@ -51,6 +51,9 @@ extern gboolean gst_ffmpegcsp_register (GstPlugin * plugin);
|
||||||
extern gboolean gst_ffmpegscale_register (GstPlugin * plugin);
|
extern gboolean gst_ffmpegscale_register (GstPlugin * plugin);
|
||||||
extern gboolean gst_ffmpegdeinterlace_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
|
G_END_DECLS
|
||||||
|
|
||||||
extern URLProtocol gstreamer_protocol;
|
extern URLProtocol gstreamer_protocol;
|
||||||
|
|
|
@ -384,7 +384,7 @@ gst_ffmpegdec_close (GstFFMpegDec * ffmpegdec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ffmpegdec->context->priv_data)
|
if (ffmpegdec->context->priv_data)
|
||||||
avcodec_close (ffmpegdec->context);
|
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||||
ffmpegdec->opened = FALSE;
|
ffmpegdec->opened = FALSE;
|
||||||
|
|
||||||
if (ffmpegdec->context->palctrl) {
|
if (ffmpegdec->context->palctrl) {
|
||||||
|
@ -419,7 +419,7 @@ gst_ffmpegdec_open (GstFFMpegDec * ffmpegdec)
|
||||||
GstFFMpegDecClass *oclass =
|
GstFFMpegDecClass *oclass =
|
||||||
(GstFFMpegDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
|
(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;
|
goto could_not_open;
|
||||||
|
|
||||||
ffmpegdec->opened = TRUE;
|
ffmpegdec->opened = TRUE;
|
||||||
|
|
|
@ -283,7 +283,7 @@ gst_ffmpegenc_dispose (GObject * object)
|
||||||
|
|
||||||
/* close old session */
|
/* close old session */
|
||||||
if (ffmpegenc->opened) {
|
if (ffmpegenc->opened) {
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
ffmpegenc->opened = FALSE;
|
ffmpegenc->opened = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,17 +338,17 @@ gst_ffmpegenc_getcaps (GstPad * pad)
|
||||||
_shut_up_I_am_probing = TRUE;
|
_shut_up_I_am_probing = TRUE;
|
||||||
for (pixfmt = 0; pixfmt < PIX_FMT_NB; pixfmt++) {
|
for (pixfmt = 0; pixfmt < PIX_FMT_NB; pixfmt++) {
|
||||||
ctx->pix_fmt = 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->pix_fmt == pixfmt) {
|
||||||
ctx->width = -1;
|
ctx->width = -1;
|
||||||
if (!caps)
|
if (!caps)
|
||||||
caps = gst_caps_new_empty ();
|
caps = gst_caps_new_empty ();
|
||||||
gst_caps_append (caps,
|
gst_caps_append (caps,
|
||||||
gst_ffmpeg_codectype_to_caps (oclass->in_plugin->type, ctx));
|
gst_ffmpeg_codectype_to_caps (oclass->in_plugin->type, ctx));
|
||||||
avcodec_close (ctx);
|
gst_ffmpeg_avcodec_close (ctx);
|
||||||
}
|
}
|
||||||
if (ctx->priv_data)
|
if (ctx->priv_data)
|
||||||
avcodec_close (ctx);
|
gst_ffmpeg_avcodec_close (ctx);
|
||||||
}
|
}
|
||||||
av_free (ctx);
|
av_free (ctx);
|
||||||
_shut_up_I_am_probing = FALSE;
|
_shut_up_I_am_probing = FALSE;
|
||||||
|
@ -376,7 +376,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
|
|
||||||
/* close old session */
|
/* close old session */
|
||||||
if (ffmpegenc->opened) {
|
if (ffmpegenc->opened) {
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
ffmpegenc->opened = FALSE;
|
ffmpegenc->opened = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,9 +417,9 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
pix_fmt = ffmpegenc->context->pix_fmt;
|
pix_fmt = ffmpegenc->context->pix_fmt;
|
||||||
|
|
||||||
/* open codec */
|
/* 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)
|
if (ffmpegenc->context->priv_data)
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
GST_DEBUG ("ffenc_%s: Failed to open FFMPEG codec",
|
GST_DEBUG ("ffenc_%s: Failed to open FFMPEG codec",
|
||||||
oclass->in_plugin->name);
|
oclass->in_plugin->name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -427,7 +427,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
|
|
||||||
/* is the colourspace correct? */
|
/* is the colourspace correct? */
|
||||||
if (pix_fmt != ffmpegenc->context->pix_fmt) {
|
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)",
|
GST_DEBUG ("ffenc_%s: AV wants different colourspace (%d given, %d wanted)",
|
||||||
oclass->in_plugin->name, pix_fmt, ffmpegenc->context->pix_fmt);
|
oclass->in_plugin->name, pix_fmt, ffmpegenc->context->pix_fmt);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -452,7 +452,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
ffmpegenc->context, TRUE);
|
ffmpegenc->context, TRUE);
|
||||||
|
|
||||||
if (!other_caps) {
|
if (!other_caps) {
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
GST_DEBUG ("Unsupported codec - no caps found");
|
GST_DEBUG ("Unsupported codec - no caps found");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_pad_set_caps (ffmpegenc->srcpad, icaps)) {
|
if (!gst_pad_set_caps (ffmpegenc->srcpad, icaps)) {
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
gst_caps_unref (icaps);
|
gst_caps_unref (icaps);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -711,7 +711,7 @@ gst_ffmpegenc_change_state (GstElement * element, GstStateChange transition)
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
if (ffmpegenc->opened) {
|
if (ffmpegenc->opened) {
|
||||||
avcodec_close (ffmpegenc->context);
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||||
ffmpegenc->opened = FALSE;
|
ffmpegenc->opened = FALSE;
|
||||||
}
|
}
|
||||||
if (ffmpegenc->cache) {
|
if (ffmpegenc->cache) {
|
||||||
|
|
Loading…
Reference in a new issue