Commit 5b101e4a authored by Benjamin Berg's avatar Benjamin Berg
Browse files

Only run sink discovery while the sink list is visible

It is not a good idea to continously run the P2P find operation as it
requires changing channels on the card and could have major impacts on
wifi performance. So turn discovery off as soon as the sink list is not
visible.
parent dcca72ce
......@@ -163,6 +163,7 @@ sink_notify_state_cb (GnomeScreencastWindow *self, GParamSpec *pspec, Screencast
gtk_container_foreach (GTK_CONTAINER (self->error_sink_list), remove_widget, self->error_sink_list);
gtk_stack_set_visible_child_name (self->step_stack, "find");
g_object_set (self->meta_provider, "discover", TRUE, NULL);
g_signal_handlers_disconnect_by_data (self->stream_sink, self);
g_clear_object (&self->stream_sink);
......@@ -203,6 +204,7 @@ find_sink_list_row_activated_cb (GnomeScreencastWindow *self, ScreencastSinkRow
self,
G_CONNECT_SWAPPED);
g_object_set (self->meta_provider, "discover", FALSE, NULL);
gtk_stack_set_visible_child_name (self->step_stack, "connect");
gtk_container_add (GTK_CONTAINER (self->connect_sink_list),
GTK_WIDGET (screencast_sink_row_new (self->stream_sink)));
......
......@@ -24,9 +24,17 @@ struct _ScreencastDummyProvider
{
GObject parent_instance;
gboolean discover;
GPtrArray *sinks;
};
enum {
PROP_DISCOVER = 1,
PROP_LAST = PROP_DISCOVER,
};
static void screencast_dummy_provider_provider_iface_init (ScreencastProviderIface *iface);
static GList * screencast_dummy_provider_provider_get_sinks (ScreencastProvider *provider);
......@@ -35,6 +43,47 @@ G_DEFINE_TYPE_EXTENDED (ScreencastDummyProvider, screencast_dummy_provider, G_TY
screencast_dummy_provider_provider_iface_init);
)
static void
screencast_dummy_provider_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ScreencastDummyProvider *self = SCREENCAST_DUMMY_PROVIDER (object);
switch (prop_id)
{
case PROP_DISCOVER:
g_value_set_boolean (value, self->discover);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
screencast_dummy_provider_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ScreencastDummyProvider *self = SCREENCAST_DUMMY_PROVIDER (object);
switch (prop_id)
{
case PROP_DISCOVER:
self->discover = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
screencast_dummy_provider_finalize (GObject *object)
{
......@@ -50,12 +99,17 @@ screencast_dummy_provider_class_init (ScreencastDummyProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = screencast_dummy_provider_get_property;
object_class->set_property = screencast_dummy_provider_set_property;
object_class->finalize = screencast_dummy_provider_finalize;
g_object_class_override_property (object_class, PROP_DISCOVER, "discover");
}
static void
screencast_dummy_provider_init (ScreencastDummyProvider *dummy_provider)
{
dummy_provider->discover = TRUE;
dummy_provider->sinks = g_ptr_array_new_with_free_func (g_object_unref);
g_ptr_array_add (dummy_provider->sinks, screencast_dummy_wfd_sink_new ());
......
......@@ -24,11 +24,19 @@ struct _ScreencastMetaProvider
{
GObject parent_instance;
gboolean discover;
GHashTable *deduplicate;
GPtrArray *sinks;
GPtrArray *providers;
};
enum {
PROP_DISCOVER = 1,
PROP_LAST = PROP_DISCOVER,
};
static void screencast_meta_provider_provider_iface_init (ScreencastProviderIface *iface);
static GList * screencast_meta_provider_provider_get_sinks (ScreencastProvider *provider);
......@@ -146,6 +154,50 @@ provider_sink_removed_cb (ScreencastMetaProvider *meta_provider, ScreencastSink
deduplicate_add_meta_sink (meta_provider, meta_sink);
}
static void
screencast_meta_provider_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ScreencastMetaProvider *self = SCREENCAST_META_PROVIDER (object);
switch (prop_id)
{
case PROP_DISCOVER:
g_value_set_boolean (value, self->discover);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
screencast_meta_provider_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ScreencastMetaProvider *self = SCREENCAST_META_PROVIDER (object);
switch (prop_id)
{
case PROP_DISCOVER:
self->discover = g_value_get_boolean (value);
for (gint i = 0; i < self->providers->len; i++)
g_object_set (g_ptr_array_index (self->providers, i), "discover", self->discover, NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
screencast_meta_provider_finalize (GObject *object)
{
......@@ -168,12 +220,18 @@ screencast_meta_provider_class_init (ScreencastMetaProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = screencast_meta_provider_get_property;
object_class->set_property = screencast_meta_provider_set_property;
object_class->finalize = screencast_meta_provider_finalize;
g_object_class_override_property (object_class, PROP_DISCOVER, "discover");
}
static void
screencast_meta_provider_init (ScreencastMetaProvider *meta_provider)
{
meta_provider->discover = TRUE;
meta_provider->sinks = g_ptr_array_new_with_free_func (g_object_unref);
meta_provider->providers = g_ptr_array_new_with_free_func (g_object_unref);
......
......@@ -60,6 +60,13 @@ screencast_provider_default_init (ScreencastProviderIface *iface)
NULL,
G_TYPE_NONE,
1, SCREENCAST_TYPE_SINK);
g_object_interface_install_property (iface,
g_param_spec_boolean ("discover",
"Discover",
"Whether discovery is turned on",
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
/**
......
......@@ -29,13 +29,17 @@ struct _ScreencastWFDP2PProvider
NMClient *nm_client;
NMDevice *nm_device;
gboolean discover;
guint p2p_find_source_id;
};
enum {
PROP_CLIENT = 1,
PROP_DEVICE,
PROP_LAST
PROP_DISCOVER,
PROP_LAST = PROP_DISCOVER,
};
static void screencast_wfd_p2p_provider_provider_iface_init (ScreencastProviderIface *iface);
......@@ -106,6 +110,10 @@ screencast_wfd_p2p_provider_get_property (GObject *object,
g_value_set_object (value, provider->nm_device);
break;
case PROP_DISCOVER:
g_value_set_boolean (value, provider->discover);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -153,7 +161,8 @@ screencast_wfd_p2p_provider_set_property (GObject *object,
G_CONNECT_SWAPPED);
nm_device_p2p_wifi_start_find (NM_DEVICE_P2P_WIFI (provider->nm_device), NULL, NULL);
provider->p2p_find_source_id = g_timeout_add_seconds (20, device_restart_find_timeout, provider);
if (provider->discover)
provider->p2p_find_source_id = g_timeout_add_seconds (20, device_restart_find_timeout, provider);
peers = nm_device_p2p_wifi_get_peers (NM_DEVICE_P2P_WIFI (provider->nm_device));
for (gint i = 0; i < peers->len; i++)
......@@ -161,6 +170,27 @@ screencast_wfd_p2p_provider_set_property (GObject *object,
break;
case PROP_DISCOVER:
provider->discover = g_value_get_boolean (value);
g_debug ("WfdP2PProvider: Discover is now set to %d", provider->discover);
if (provider->discover)
{
nm_device_p2p_wifi_start_find (NM_DEVICE_P2P_WIFI (provider->nm_device), NULL, NULL);
if (!provider->p2p_find_source_id)
provider->p2p_find_source_id = g_timeout_add_seconds (20, device_restart_find_timeout, provider);
}
else
{
if (provider->p2p_find_source_id)
g_source_remove (provider->p2p_find_source_id);
provider->p2p_find_source_id = 0;
nm_device_p2p_wifi_stop_find (NM_DEVICE_P2P_WIFI (provider->nm_device), NULL, NULL);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -206,6 +236,8 @@ screencast_wfd_p2p_provider_class_init (ScreencastWFDP2PProviderClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, props);
g_object_class_override_property (object_class, PROP_DISCOVER, "discover");
}
static void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment