tcp: print warning if someone tries to add clients in NULL state
authorTim-Philipp Müller <tim@centricular.net>
Sun, 2 Dec 2012 12:54:17 +0000 (12:54 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Sun, 2 Dec 2012 12:54:17 +0000 (12:54 +0000)
And mention this in docs.

https://bugzilla.gnome.org/show_bug.cgi?id=689326

gst/tcp/gstmultifdsink.c
gst/tcp/gstmultihandlesink.c
tests/check/elements/multifdsink.c

index db046d4..a4f6ee9 100644 (file)
@@ -27,6 +27,9 @@
  * file descriptors can be added to multifdsink by emitting the #GstMultiFdSink::add signal. 
  * For each descriptor added, the #GstMultiFdSink::client-added signal will be called.
  *
+ * The multifdsink element needs to be set into READY, PAUSED or PLAYING state
+ * before operations such as adding clients are possible.
+ *
  * As of version 0.10.8, a client can also be added with the #GstMultiFdSink::add-full signal
  * that allows for more control over what and how much data a client 
  * initially receives.
index eedc787..9b9eb64 100644 (file)
@@ -656,6 +656,12 @@ gst_multi_handle_sink_add_full (GstMultiHandleSink * sink,
   GstMultiHandleSinkClass *mhsinkclass =
       GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
 
+  if (!sink->running) {
+    g_warning ("Element %s must be set to READY, PAUSED or PLAYING state "
+        "before clients can be added", GST_OBJECT_NAME (sink));
+    return;
+  }
+
   mhsinkclass->handle_debug (handle, debug);
   GST_DEBUG_OBJECT (sink, "%s adding client, sync_method %d, "
       "min_format %d, min_value %" G_GUINT64_FORMAT
index f34b652..60567fb 100644 (file)
@@ -141,6 +141,19 @@ GST_START_TEST (test_add_client)
 
 GST_END_TEST;
 
+GST_START_TEST (test_add_client_in_null_state)
+{
+  GstElement *sink;
+
+  sink = setup_multifdsink ();
+
+  ASSERT_WARNING (g_signal_emit_by_name (sink, "add", 99));
+
+  cleanup_multifdsink (sink);
+}
+
+GST_END_TEST;
+
 #define fail_unless_read(msg,fd,size,ref) \
 G_STMT_START { \
   char data[size + 1]; \
@@ -800,6 +813,7 @@ multifdsink_suite (void)
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_no_clients);
   tcase_add_test (tc_chain, test_add_client);
+  tcase_add_test (tc_chain, test_add_client_in_null_state);
   tcase_add_test (tc_chain, test_streamheader);
   tcase_add_test (tc_chain, test_change_streamheader);
   tcase_add_test (tc_chain, test_burst_client_bytes);