webrtc: fix an off-by-one calculating low-threshold
authorMatthew Waters <matthew@centricular.com>
Wed, 6 May 2020 05:36:19 +0000 (15:36 +1000)
committerMatthew Waters <matthew@centricular.com>
Wed, 6 May 2020 05:49:58 +0000 (15:49 +1000)
We were not signalling low-threshold when the previous amount was at
exactly the low-threshold mark.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1247>

ext/webrtc/webrtcdatachannel.c
tests/check/elements/webrtcbin.c

index 9e1e3ef..0eb9f85 100644 (file)
@@ -527,7 +527,9 @@ _parse_control_packet (GstWebRTCDataChannel * channel, guint8 * data,
       g_set_error (error, GST_WEBRTC_BIN_ERROR,
           GST_WEBRTC_BIN_ERROR_DATA_CHANNEL_FAILURE,
           "Could not send ack packet");
+      return ret;
     }
+
     return ret;
   } else {
     g_set_error (error, GST_WEBRTC_BIN_ERROR,
@@ -1042,7 +1044,11 @@ on_appsrc_data (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
     CHANNEL_LOCK (channel);
     prev_amount = channel->buffered_amount;
     channel->buffered_amount -= size;
-    if (prev_amount > channel->buffered_amount_low_threshold &&
+    GST_TRACE_OBJECT (channel, "checking low-threshold: prev %"
+        G_GUINT64_FORMAT " low-threshold %" G_GUINT64_FORMAT " buffered %"
+        G_GUINT64_FORMAT, prev_amount, channel->buffered_amount_low_threshold,
+        channel->buffered_amount);
+    if (prev_amount >= channel->buffered_amount_low_threshold &&
         channel->buffered_amount < channel->buffered_amount_low_threshold) {
       _channel_enqueue_task (channel, (ChannelTask) _emit_low_threshold,
           NULL, NULL);
index eeb733d..27da1d5 100644 (file)
@@ -1846,7 +1846,7 @@ have_data_channel_check_low_threshold_emitted (struct test_webrtc *t,
 
   g_signal_connect (our, "on-error", G_CALLBACK (on_channel_error_not_reached),
       NULL);
-  g_signal_emit_by_name (our, "send-string", "DATA");
+  g_signal_emit_by_name (our, "send-string", "A");
 }
 
 GST_START_TEST (test_data_channel_low_threshold)