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.
This commit is contained in:
Tim-Philipp Müller 2007-05-24 17:00:21 +00:00
parent 59e42fc5df
commit d2977ff4eb
2 changed files with 23 additions and 9 deletions

View file

@ -1,3 +1,9 @@
2007-05-24 Tim-Philipp Müller <tim at centricular dot net>
* 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.
2007-05-24 Wim Taymans <wim@fluendo.com>
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_parse_methods):

View file

@ -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