static void handle_set_media_message (SnraClient * client, GstStructure * s) { const gchar *protocol, *path; int port; GstClockTime base_time; gint64 tmp; gchar *uri; gboolean paused; protocol = gst_structure_get_string (s, "resource-protocol"); path = gst_structure_get_string (s, "resource-path"); if (protocol == NULL || path == NULL) return; /* Invalid message */ if (!snra_json_structure_get_int (s, "resource-port", &port)) return; if (!snra_json_structure_get_int64 (s, "base-time", &tmp)) return; /* Invalid message */ if (!snra_json_structure_get_boolean (s, "paused", &paused)) return; base_time = (GstClockTime) (tmp); if (client->player == NULL) { construct_player (client); if (client->player == NULL) return; } else { gst_element_set_state (client->player, GST_STATE_NULL); } uri = g_strdup_printf ("%s://%s:%d%s", protocol, client->connected_server, port, path); g_print ("Playing URI %s base_time %" GST_TIME_FORMAT "\n", uri, GST_TIME_ARGS (base_time)); g_object_set (client->player, "uri", uri, NULL); g_free (uri); gst_element_set_start_time (client->player, GST_CLOCK_TIME_NONE); gst_element_set_base_time (client->player, base_time); gst_pipeline_use_clock (GST_PIPELINE (client->player), client->net_clock); if (client->enabled) { if (paused) client->state = GST_STATE_PAUSED; else client->state = GST_STATE_PLAYING; } else { client->state = DISABLED_STATE; } gst_element_set_state (client->player, client->state); }
static void handle_player_set_media_message (SnraClient * client, GstStructure * s) { const gchar *protocol, *path, *language; int port; gint64 tmp; protocol = gst_structure_get_string (s, "resource-protocol"); path = gst_structure_get_string (s, "resource-path"); if (protocol == NULL || path == NULL) return; /* Invalid message */ if (!snra_json_structure_get_int (s, "resource-port", &port)) return; if (!snra_json_structure_get_int64 (s, "base-time", &tmp)) return; /* Invalid message */ client->base_time = (GstClockTime) (tmp); if (!snra_json_structure_get_int64 (s, "position", &tmp)) return; /* Invalid message */ client->position = (GstClockTime) (tmp); if (!snra_json_structure_get_boolean (s, "paused", &client->paused)) return; g_free (client->language); language = gst_structure_get_string (s, "language"); client->language = g_strdup (language ? language : "en"); g_free (client->uri); client->uri = g_strdup_printf ("%s://%s:%d%s", protocol, client->connected_server, port, path); if (client->enabled) set_media (client); g_object_notify (G_OBJECT (client), "language"); g_object_notify (G_OBJECT (client), "media-uri"); }
static void handle_enrol_message (SnraClient * client, GstStructure * s) { int clock_port; gint64 tmp; GstClockTime cur_time; gchar *server_ip_str = NULL; gdouble new_vol; if (!snra_json_structure_get_int (s, "clock-port", &clock_port)) return; /* Invalid message */ if (!snra_json_structure_get_int64 (s, "current-time", &tmp)) return; /* Invalid message */ cur_time = (GstClockTime) (tmp); if (snra_json_structure_get_double (s, "volume-level", &new_vol)) { if (client->player == NULL) construct_player (client); if (client->player) { //g_print ("New volume %g\n", new_vol); g_object_set (G_OBJECT (client->player), "volume", new_vol, "mute", (gboolean) (new_vol == 0.0), NULL); } } snra_json_structure_get_boolean (s, "enabled", &client->enabled); snra_json_structure_get_boolean (s, "paused", &client->paused); #if GLIB_CHECK_VERSION(2,22,0) { GResolver *resolver = g_resolver_get_default (); GList *names; if (resolver == NULL) return; names = g_resolver_lookup_by_name (resolver, client->connected_server, NULL, NULL); if (names) { server_ip_str = g_inet_address_to_string ((GInetAddress *) (names->data)); g_resolver_free_addresses (names); } g_object_unref (resolver); } #else { struct addrinfo *names = NULL; if (getaddrinfo (client->connected_server, NULL, NULL, &names)) return; if (names) { char hbuf[NI_MAXHOST]; if (getnameinfo (names->ai_addr, names->ai_addrlen, hbuf, sizeof (hbuf), NULL, 0, NI_NUMERICHOST) == 0) { server_ip_str = g_strdup (hbuf); } freeaddrinfo (names); } } #endif if (server_ip_str) { g_print ("Creating net clock at %s:%d time %" GST_TIME_FORMAT "\n", server_ip_str, clock_port, GST_TIME_ARGS (cur_time)); if (client->net_clock) gst_object_unref (client->net_clock); client->net_clock = gst_net_client_clock_new ("net_clock", server_ip_str, clock_port, cur_time); g_free (server_ip_str); } }