pulse, speexenc, rtpgsmpay: don't use g_assert() for error handling

Don't use g_assert() for error handling, even if they're highly unlikely.
Either we *know* that something can't happen, in which case we
should just not handle it, or we think something can happen, but it is
very very unlikely that it will ever happen, in which case we should
handle it like any other error instead of asserting.

g_assert() is best left for conditions we have control of, like checking
internal consistency of our code, not checking return values of external
code.

Fixes a bunch of warnings when compiling with -DG_DISABLE_ASSERT:
gstrtpgsmpay.c: In function 'gst_rtp_gsm_pay_handle_buffer':
gstrtpgsmpay.c:130:17: warning: variable 'rtpgsmpay' set but not used
gstspeexenc.c: In function 'gst_speex_enc_encode':
gstspeexenc.c:904:19: warning: variable 'written' set but not used
pulsesink.c: In function 'gst_pulsesink_change_state':
pulsesink.c:2725:9: warning: variable 'res' set but not used
pulsesrc.c: In function 'gst_pulsesrc_change_state':
pulsesrc.c:1253:7: warning: variable 'e' set but not used
This commit is contained in:
Tim-Philipp Müller 2011-04-16 18:10:24 +01:00
parent b005dfea5b
commit f325935314
4 changed files with 19 additions and 12 deletions

View file

@ -1072,8 +1072,8 @@ gst_pulseringbuffer_start (GstRingBuffer * buf)
/* EOS needs running clock */
if (GST_BASE_SINK_CAST (psink)->eos ||
g_atomic_int_get (&GST_BASE_AUDIO_SINK (psink)->abidata.
ABI.eos_rendering))
g_atomic_int_get (&GST_BASE_AUDIO_SINK (psink)->abidata.ABI.
eos_rendering))
gst_pulsering_set_corked (pbuf, FALSE, FALSE);
pa_threaded_mainloop_unlock (mainloop);
@ -2722,7 +2722,6 @@ gst_pulsesink_change_state (GstElement * element, GstStateChange transition)
{
GstPulseSink *pulsesink = GST_PULSESINK (element);
GstStateChangeReturn ret;
guint res;
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
@ -2732,8 +2731,7 @@ gst_pulsesink_change_state (GstElement * element, GstStateChange transition)
if (!(mainloop = pa_threaded_mainloop_new ()))
goto mainloop_failed;
mainloop_ref_ct = 1;
res = pa_threaded_mainloop_start (mainloop);
g_assert (res == 0);
pa_threaded_mainloop_start (mainloop);
g_mutex_unlock (pa_shared_resource_mutex);
} else {
GST_INFO_OBJECT (element, "reusing pa main loop thread");

View file

@ -1112,7 +1112,7 @@ gst_pulsesrc_success_cb (pa_stream * s, int success, void *userdata)
{
GstPulseSrc *pulsesrc = GST_PULSESRC_CAST (userdata);
pulsesrc->operation_success = !!success;
pulsesrc->operation_success = ! !success;
pa_threaded_mainloop_signal (pulsesrc->mainloop, 0);
}
@ -1250,15 +1250,13 @@ gst_pulsesrc_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret;
GstPulseSrc *this = GST_PULSESRC_CAST (element);
int e;
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
this->mainloop = pa_threaded_mainloop_new ();
g_assert (this->mainloop);
e = pa_threaded_mainloop_start (this->mainloop);
g_assert (e == 0);
pa_threaded_mainloop_start (this->mainloop);
if (!this->mixer)
this->mixer =

View file

@ -934,7 +934,12 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
written = speex_bits_write (&enc->bits,
(gchar *) GST_BUFFER_DATA (outbuf), outsize);
g_assert (written == outsize);
if (G_UNLIKELY (written != outsize)) {
GST_ERROR_OBJECT (enc, "short write: %d < %d bytes", written, outsize);
GST_BUFFER_SIZE (outbuf) = written;
}
speex_bits_reset (&enc->bits);
if (!dtx_ret)

View file

@ -143,9 +143,15 @@ gst_rtp_gsm_pay_handle_buffer (GstBaseRTPPayload * basepayload,
/* FIXME, only one GSM frame per RTP packet for now */
payload_len = size;
/* FIXME, just error out for now */
if (payload_len > GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay)) {
GST_ELEMENT_ERROR (rtpgsmpay, STREAM, ENCODE, (NULL),
("payload_len %u > mtu %u", payload_len,
GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay)));
return GST_FLOW_ERROR;
}
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
/* FIXME, assert for now */
g_assert (payload_len <= GST_BASE_RTP_PAYLOAD_MTU (rtpgsmpay));
/* copy timestamp and duration */
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;