ext/ffmpeg/gstffmpegmux.c: Only set the mux->opened flag after we've successfully written the header. This way we don...

Original commit message from CVS:
* ext/ffmpeg/gstffmpegmux.c: (gst_ffmpegmux_request_new_pad),
(gst_ffmpegmux_setcaps), (gst_ffmpegmux_collected):
Only set the mux->opened flag after we've successfully written the
header. This way we don't crash in mysterious ways if we can't write
the header for some reason (e.g. due to having accepted caps the
format doesn't really allow), then return a GST_FLOW_ERROR, and
then still receive another buffer afterwards despite having previously
returned FLOW_ERROR (#403168).
Also some minor logging improvements.
This commit is contained in:
Tim-Philipp Müller 2007-02-09 16:17:50 +00:00
parent 5ad0d8bfee
commit a23114785a
3 changed files with 83 additions and 64 deletions

View file

@ -1,3 +1,15 @@
2007-02-09 Tim-Philipp Müller <tim at centricular dot net>
* ext/ffmpeg/gstffmpegmux.c: (gst_ffmpegmux_request_new_pad),
(gst_ffmpegmux_setcaps), (gst_ffmpegmux_collected):
Only set the mux->opened flag after we've successfully written the
header. This way we don't crash in mysterious ways if we can't write
the header for some reason (e.g. due to having accepted caps the
format doesn't really allow), then return a GST_FLOW_ERROR, and
then still receive another buffer afterwards despite having previously
returned FLOW_ERROR (#403168).
Also some minor logging improvements.
2007-01-26 Wim Taymans <wim@fluendo.com>
Patch by: Mark Nauwelaerts <manauw@skynet.be>

2
common

@ -1 +1 @@
Subproject commit 8ba5dffb5ee7e7daea1030f6b34bfef10f9801a3
Subproject commit de43a8f3c629983e0bea0b8eb617e52ed35a6cda

View file

@ -107,13 +107,15 @@ static GHashTable *global_plugins;
/* A number of functon prototypes are given so we can refer to them later. */
static void gst_ffmpegmux_class_init (GstFFMpegMuxClass * klass);
static void gst_ffmpegmux_base_init (gpointer g_class);
static void gst_ffmpegmux_init (GstFFMpegMux * ffmpegmux, GstFFMpegMuxClass * g_class);
static void gst_ffmpegmux_init (GstFFMpegMux * ffmpegmux,
GstFFMpegMuxClass * g_class);
static void gst_ffmpegmux_finalize (GObject * object);
static gboolean gst_ffmpegmux_setcaps (GstPad * pad, GstCaps * caps);
static GstPad *gst_ffmpegmux_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * name);
static GstFlowReturn gst_ffmpegmux_collected (GstCollectPads * pads, gpointer user_data);
static GstFlowReturn gst_ffmpegmux_collected (GstCollectPads * pads,
gpointer user_data);
static gboolean gst_ffmpegmux_sink_event (GstPad * pad, GstEvent * event);
@ -265,14 +267,16 @@ gst_ffmpegmux_request_new_pad (GstElement * element,
/* create pad */
pad = gst_pad_new_from_template (templ, padname);
collect_pad = (GstFFMpegMuxPad *)
gst_collect_pads_add_pad (ffmpegmux->collect, pad, sizeof (GstFFMpegMuxPad));
gst_collect_pads_add_pad (ffmpegmux->collect, pad,
sizeof (GstFFMpegMuxPad));
collect_pad->padnum = ffmpegmux->context->nb_streams;
/* small hack to put our own event pad function and chain up to collect pad */
ffmpegmux->event_function = GST_PAD_EVENTFUNC (pad);
gst_pad_set_event_function (pad, gst_ffmpegmux_sink_event);
gst_pad_set_event_function (pad,
GST_DEBUG_FUNCPTR (gst_ffmpegmux_sink_event));
gst_pad_set_setcaps_function (pad, gst_ffmpegmux_setcaps);
gst_pad_set_setcaps_function (pad, GST_DEBUG_FUNCPTR (gst_ffmpegmux_setcaps));
gst_element_add_pad (element, pad);
/* AVStream needs to be created */
@ -315,9 +319,11 @@ gst_ffmpegmux_setcaps (GstPad * pad, GstCaps * caps)
/* for the format-specific guesses, we'll go to
* our famous codec mapper */
if (gst_ffmpeg_caps_to_codecid (caps, st->codec) != CODEC_ID_NONE) {
GST_LOG_OBJECT (pad, "accepted caps %" GST_PTR_FORMAT, caps);
return TRUE;
}
GST_LOG_OBJECT (pad, "rejecting caps %" GST_PTR_FORMAT, caps);
return FALSE;
}
@ -466,9 +472,6 @@ gst_ffmpegmux_collected (GstCollectPads * pads, gpointer user_data)
return GST_FLOW_ERROR;
}
/* we're now opened */
ffmpegmux->opened = TRUE;
/* now open the mux format */
if (av_write_header (ffmpegmux->context) < 0) {
GST_ELEMENT_ERROR (ffmpegmux, LIBRARY, SETTINGS, (NULL),
@ -476,6 +479,9 @@ gst_ffmpegmux_collected (GstCollectPads * pads, gpointer user_data)
return GST_FLOW_ERROR;
}
/* we're now opened */
ffmpegmux->opened = TRUE;
/* flush the header so it will be used as streamheader */
put_flush_packet (&ffmpegmux->context->pb);
}
@ -541,7 +547,9 @@ next_pad:
pkt.flags |= PKT_FLAG_KEY;
if (GST_BUFFER_DURATION_IS_VALID (buf))
pkt.duration = gst_util_uint64_scale_int(GST_BUFFER_DURATION (buf), AV_TIME_BASE, GST_SECOND);
pkt.duration =
gst_util_uint64_scale_int (GST_BUFFER_DURATION (buf), AV_TIME_BASE,
GST_SECOND);
else
pkt.duration = 0;
av_write_frame (ffmpegmux->context, &pkt);
@ -697,8 +705,7 @@ gst_ffmpegmux_register (GstPlugin * plugin)
/* create the type now */
type = g_type_register_static (GST_TYPE_ELEMENT, type_name, &typeinfo, 0);
g_type_add_interface_static (type, GST_TYPE_TAG_SETTER,
&tag_setter_info);
g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, &tag_setter_info);
if (!gst_element_register (plugin, type_name, GST_RANK_NONE, type)) {
g_free (type_name);
gst_caps_unref (srccaps);