diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2007-05-24 17:00:21 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2007-05-24 17:00:21 +0000 |
commit | d2977ff4eba46efb99930f89614c1105a2ebc1af (patch) | |
tree | 9502123dfee539ccbe635dc9d8f4db943e34af41 /ext | |
parent | 59e42fc5df8ef1334551f3e162d5ee67e8a65ef5 (diff) |
ext/flac/gstflacenc.c: Don't crash in chain function if setcaps hasn't been called.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_sink_setcaps),
(gst_flac_enc_chain):
Don't crash in chain function if setcaps hasn't been called.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/flac/gstflacenc.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index b257681b..255d6c76 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -373,8 +373,8 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps) GstFlacEnc *flacenc; GstStructure *structure; FLAC__SeekableStreamEncoderState state; + gint depth, chans, rate, width; - /* takes a ref on flacenc */ flacenc = GST_FLAC_ENC (gst_pad_get_parent (pad)); if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) != @@ -383,11 +383,17 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps) structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "channels", &flacenc->channels) - || !gst_structure_get_int (structure, "depth", &flacenc->depth) - || !gst_structure_get_int (structure, "rate", &flacenc->sample_rate)) - /* we got caps incompatible with the template? */ - g_return_val_if_reached (FALSE); + if (!gst_structure_get_int (structure, "channels", &chans) || + !gst_structure_get_int (structure, "width", &width) || + !gst_structure_get_int (structure, "depth", &depth) || + !gst_structure_get_int (structure, "rate", &rate)) { + GST_DEBUG_OBJECT (flacenc, "incomplete caps: %" GST_PTR_FORMAT, caps); + return FALSE; + } + + flacenc->channels = chans; + flacenc->depth = depth; + flacenc->sample_rate = rate; caps = gst_caps_new_simple ("audio/x-flac", "channels", G_TYPE_INT, flacenc->channels, @@ -662,7 +668,11 @@ gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer) gulong i; FLAC__bool res; - flacenc = GST_FLAC_ENC (gst_pad_get_parent (pad)); + flacenc = GST_FLAC_ENC (GST_PAD_PARENT (pad)); + + /* make sure setcaps has been called and the encoder is setup */ + if (G_UNLIKELY (flacenc->depth == 0)) + return GST_FLOW_NOT_NEGOTIATED; depth = flacenc->depth; @@ -692,8 +702,6 @@ gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer) g_free (data); - gst_object_unref (flacenc); - if (res) return GST_FLOW_OK; else |