[gnome-network-displays/cc-tmp: 16/80] cc: add strong connect message
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-network-displays/cc-tmp: 16/80] cc: add strong connect message
- Date: Fri, 9 Sep 2022 12:03:49 +0000 (UTC)
commit abc9f0b10ca3d0d482ba8c545678011c99d10af6
Author: Anupam Kumar <kyteinsky gmail com>
Date: Wed Jul 27 15:20:30 2022 +0530
cc: add strong connect message
src/cc/cc-comm.c | 40 ++++++++++++++++++++--------------------
src/cc/cc-comm.h | 2 ++
src/nd-cc-sink.c | 33 ++++++++++++++++++++++++++-------
3 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 42c74ce..8088e28 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -47,6 +47,17 @@ cc_comm_dump_message (guint8 *msg, gsize length)
g_debug ("%s", line->str);
}
+static void
+cc_comm_dump_json_message (Castchannel__CastMessage *message)
+{
+ g_debug ("{ source_id: %s, destination_id: %s, namespace_: %s, payload_type: %d, payload_utf8: %s }",
+ message->source_id,
+ message->destination_id,
+ message->namespace_,
+ message->payload_type,
+ message->payload_utf8);
+}
+
static void
cc_comm_parse_received_data(uint8_t * input_buffer, gssize input_size)
{
@@ -59,12 +70,8 @@ cc_comm_parse_received_data(uint8_t * input_buffer, gssize input_size)
return;
}
- g_debug("CcComm: Received data: { source_id: %s, destination_id: %s, namespace_: %s, payload_type: %d,
payload_utf8: %s }",
- message->source_id,
- message->destination_id,
- message->namespace_,
- message->payload_type,
- message->payload_utf8);
+ g_debug("CcComm: Received data:");
+ cc_comm_dump_json_message (message);
castchannel__cast_message__free_unpacked(message, NULL);
}
@@ -148,7 +155,7 @@ cc_comm_message_read_cb (GObject *source_object,
}
// dump the received message and try to parse it
- cc_comm_dump_message (comm->message_buffer, io_bytes);
+ // cc_comm_dump_message (comm->message_buffer, io_bytes);
cc_comm_parse_received_data (comm->message_buffer, io_bytes);
// go for another round
@@ -334,7 +341,6 @@ static gboolean
cc_comm_tls_send (CcComm * comm,
uint8_t * message,
gssize size,
- gboolean expect_input,
GError **error)
{
GOutputStream *ostream;
@@ -347,8 +353,8 @@ cc_comm_tls_send (CcComm * comm,
return FALSE;
}
- g_debug ("Writing data to Chromecast command channel:");
- cc_comm_dump_message (message, size);
+ // g_debug ("Writing data to Chromecast command channel:");
+ // cc_comm_dump_message (message, size);
ostream = g_io_stream_get_output_stream (G_IO_STREAM (comm->con));
@@ -372,9 +378,6 @@ cc_comm_tls_send (CcComm * comm,
return TRUE;
}
-// TODO: build strong connect messaage
-
-
// builds message based on available types
static Castchannel__CastMessage
cc_comm_build_message (gchar *namespace_,
@@ -412,11 +415,8 @@ cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_p
{
Castchannel__CastMessage message;
guint32 packed_size = 0;
- gboolean expect_input = TRUE;
g_autofree uint8_t *sock_buffer = NULL;
- g_debug("CcComm: Send request: %d", message_type);
-
switch (message_type)
{
case MESSAGE_TYPE_CONNECT:
@@ -424,8 +424,7 @@ cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_p
"urn:x-cast:com.google.cast.tp.connection",
CASTCHANNEL__CAST_MESSAGE__PAYLOAD_TYPE__STRING,
NULL,
- "{\"type\":\"CONNECT\"}");
- expect_input = FALSE;
+ "{ \"type\": \"CONNECT\", \"userAgent\": \"GND/0.90.5 (X11; Linux x86_64)\", \"connType\": 0,
\"origin\": {}, \"senderInfo\": { \"sdkType\": 2, \"version\": \"X11; Linux x86_64\", \"browserVersion\":
\"X11; Linux x86_64\", \"platform\": 6, \"connectionType\": 1 } }");
break;
case MESSAGE_TYPE_DISCONNECT:
@@ -434,7 +433,6 @@ cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_p
CASTCHANNEL__CAST_MESSAGE__PAYLOAD_TYPE__STRING,
NULL,
"{ \"type\": \"CLOSE\" }");
- expect_input = FALSE;
break;
case MESSAGE_TYPE_PING:
@@ -472,10 +470,12 @@ cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_p
memcpy(sock_buffer, &packed_size_be, 4);
castchannel__cast_message__pack(&message, 4 + sock_buffer);
+ g_debug ("CcComm: Sending message:");
+ cc_comm_dump_json_message (&message);
+
return cc_comm_tls_send (comm,
sock_buffer,
packed_size+4,
- expect_input,
error);
}
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 6c8b9ea..f511d68 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -29,6 +29,8 @@ struct _CcComm
/*< public >*/
GIOStream *con;
+ gchar *sender_id;
+
guint8 *header_buffer;
guint8 *message_buffer;
};
diff --git a/src/nd-cc-sink.c b/src/nd-cc-sink.c
index a8ed37c..05dfc13 100644
--- a/src/nd-cc-sink.c
+++ b/src/nd-cc-sink.c
@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// #include <time.h>
+
#include "gnome-network-displays-config.h"
#include "nd-cc-sink.h"
#include "cc/cc-client.h"
@@ -315,6 +317,7 @@ nd_cc_sink_sink_start_stream (NdSink *sink)
{
NdCCSink *self = ND_CC_SINK (sink);
g_autoptr(GError) error = NULL;
+ // gchar six_digits[6];
g_return_val_if_fail (self->state == ND_SINK_STATE_DISCONNECTED, NULL);
@@ -339,23 +342,39 @@ nd_cc_sink_sink_start_stream (NdSink *sink)
}
// open up a virtual connection to the device
- cc_comm_send_request(&self->comm, MESSAGE_TYPE_CONNECT, NULL, NULL);
+ if (!cc_comm_send_request(&self->comm, MESSAGE_TYPE_CONNECT, NULL, NULL))
+ {
+ self->state = ND_SINK_STATE_ERROR;
+ g_object_notify (G_OBJECT (self), "state");
+ g_clear_object (&self->server);
+
+ return NULL;
+ }
+
+ // sprintf (six_digits, "%ld", time (NULL) % 1000000);
+ // self->comm.sender_id = "sender-";
+ // strncat (self->comm.sender_id, six_digits, 6);
+
+ // set sender_id after connection (sender-xxxxxx)
+ self->comm.sender_id = "sender-547784";
// send pings to device every 5 seconds
self->ping_timeout_handle = g_timeout_add_seconds(5, G_SOURCE_FUNC (cc_comm_send_ping), &self->comm);
+ cc_comm_send_ping (&self->comm);
// send req to get status
+ g_debug("NdCCSink: Get Status");
cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{\"type\": \"GET_STATUS\"}", NULL);
// send req to open youtube
- g_debug("NdCCSink: Launching YouTube");
- cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"LAUNCH\", \"appId\": \"YouTube\",
\"requestId\": 1 }", NULL);
+ // g_debug("NdCCSink: Launching YouTube");
+ // cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"LAUNCH\", \"appId\":
\"YouTube\", \"requestId\": 1 }", NULL);
- g_debug("NdCCSink: Get Status Again");
- cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{\"type\": \"GET_STATUS\"}", NULL);
+ // g_debug("NdCCSink: Get Status Again");
+ // cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{\"type\": \"GET_STATUS\"}", NULL);
- g_debug ("NdCCSink: Mute the TV");
- cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"SET_VOLUME\", \"volume\": {
\"muted\": true } }", NULL);
+ // g_debug ("NdCCSink: Mute the Chromecast");
+ // cc_comm_send_request(&self->comm, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"SET_VOLUME\", \"volume\": {
\"muted\": true } }", NULL);
self->server = wfd_server_new ();
self->server_source_id = gst_rtsp_server_attach (GST_RTSP_SERVER (self->server), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]