From f325935314d896cfc65328b904117711e927fba8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 16 Apr 2011 18:10:24 +0100 Subject: [PATCH] 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 --- ext/pulse/pulsesink.c | 8 +++----- ext/pulse/pulsesrc.c | 6 ++---- ext/speex/gstspeexenc.c | 7 ++++++- gst/rtp/gstrtpgsmpay.c | 10 ++++++++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index 2de72e3..e4fe6e3 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -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"); diff --git a/ext/pulse/pulsesrc.c b/ext/pulse/pulsesrc.c index 06fb206..ebb41c1 100644 --- a/ext/pulse/pulsesrc.c +++ b/ext/pulse/pulsesrc.c @@ -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 = diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c index 57dc41c..6ace2da 100644 --- a/ext/speex/gstspeexenc.c +++ b/ext/speex/gstspeexenc.c @@ -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) diff --git a/gst/rtp/gstrtpgsmpay.c b/gst/rtp/gstrtpgsmpay.c index ad984bc..479013e 100644 --- a/gst/rtp/gstrtpgsmpay.c +++ b/gst/rtp/gstrtpgsmpay.c @@ -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; -- 2.7.4