GSource *isource, *tosource;
GByteArray *current_message;
gchar *http_version;
+ gboolean waiting_200_ok;
} Client;
static const char *known_mimetypes[] = {
static GstElement *multisocketsink = NULL;
static gboolean started = FALSE;
static gchar *content_type;
+G_LOCK_DEFINE_STATIC (caps);
+static gboolean caps_resolved = FALSE;
static void
remove_client (Client * client)
if (g_str_has_prefix (lines[0], "HEAD")) {
gchar **parts = g_strsplit (lines[0], " ", -1);
+ gboolean ok = FALSE;
g_free (client->http_version);
client->http_version = g_strdup ("HTTP/1.0");
if (parts[1] && strcmp (parts[1], "/") == 0) {
- send_response_200_ok (client);
+ G_LOCK (caps);
+ if (caps_resolved)
+ send_response_200_ok (client);
+ else
+ client->waiting_200_ok = TRUE;
+ G_UNLOCK (caps);
+ ok = TRUE;
} else {
send_response_404_not_found (client);
}
g_strfreev (parts);
+
+ if (ok && !started) {
+ g_print ("Starting pipeline\n");
+ if (gst_element_set_state (pipeline,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
+ g_print ("Failed to start pipeline\n");
+ g_main_loop_quit (loop);
+ }
+ started = TRUE;
+ }
} else if (g_str_has_prefix (lines[0], "GET")) {
gchar **parts = g_strsplit (lines[0], " ", -1);
gboolean ok = FALSE;
client->http_version = g_strdup ("HTTP/1.0");
if (parts[1] && strcmp (parts[1], "/") == 0) {
- send_response_200_ok (client);
+ G_LOCK (caps);
+ if (caps_resolved)
+ send_response_200_ok (client);
+ else
+ client->waiting_200_ok = TRUE;
+ G_UNLOCK (caps);
ok = TRUE;
} else {
send_response_404_not_found (client);
g_print ("New connection %s\n", client->name);
+ client->waiting_200_ok = FALSE;
client->http_version = g_strdup ("");
client->connection = g_object_ref (connection);
client->socket = g_socket_connection_get_socket (connection);
GstPad *src_pad;
GstCaps *src_caps;
GstStructure *gstrc;
+ GList *l;
src_pad = (GstPad *) obj;
src_caps = gst_pad_get_current_caps (src_pad);
}
gst_caps_unref (src_caps);
+
+ /* Send 200 OK to those clients waiting for it */
+ G_LOCK (caps);
+
+ caps_resolved = TRUE;
+
+ G_LOCK (clients);
+ for (l = clients; l; l = l->next) {
+ Client *cl = l->data;
+ if (cl->waiting_200_ok) {
+ send_response_200_ok (cl);
+ cl->waiting_200_ok = FALSE;
+ break;
+ }
+ }
+ G_UNLOCK (clients);
+
+ G_UNLOCK (caps);
}
int