Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add option to send debug message, set up ZeroMQ

  • Loading branch information...
commit 0b43f3c51027a75839480e134cdaa5077417334b 1 parent 44549a5
Paul Betts paulcbetts authored
Showing with 64 additions and 3 deletions.
  1. 0  README
  2. +1 −1  src/Makefile.am
  3. +63 −2 src/gst_playd.c
0  README
View
No changes.
2  src/Makefile.am
View
@@ -11,7 +11,7 @@ gst_playd_CFLAGS = \
$(LIBZMQ_CFLAGS) \
$(GST_CFLAGS)
-gst_playd_LDFLAGS = \
+gst_playd_LDADD = \
$(GLIB_LIBS) \
$(LIBZMQ_LIBS) \
$(GST_LIBS)
65 src/gst_playd.c
View
@@ -23,29 +23,90 @@
#include <glib.h>
#include <glib/goption.h>
+#include <zmq.h>
#define EXIT_FAILURE 1
static gboolean verbose = FALSE;
static char* client_message = NULL;
+static int icecast_port = 8000;
static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
{ "send-message", 's', 0, G_OPTION_ARG_STRING, &client_message, "Send a message to a running gst_playd and exit", NULL },
+ { "port", 'p', 0, G_OPTION_ARG_INT, &icecast_port, "Set the port that Icecast will bind to", NULL },
+ { NULL },
};
+struct timer_closure {
+ void* zmq_context;
+ const char* address;
+};
+
+static char* zeromq_address_from_port(int port)
+{
+ return g_strdup_printf("tcp://*:%d", port + 10000);
+}
+
+static gboolean send_client_message(void* zmq_context, const char* message, const char* address)
+{
+ gboolean ret = TRUE;
+ int linger = 5*1000;
+ void* sock = zmq_socket(zmq_context, ZMQ_REQ);
+ zmq_setsockopt(sock, ZMQ_LINGER, &linger, sizeof(int));
+
+ g_warning("Connecting to %s", address);
+ if (!zmq_connect(sock, address)) {
+ g_warning("Failed to connect: %s", zmq_strerror(zmq_errno()));
+ ret = FALSE; goto out;
+ }
+
+ zmq_msg_t msg;
+ zmq_msg_init_data(&msg, message, sizeof(char) * strlen(message), NULL, NULL);
+ zmq_send(sock, &msg, ZMQ_NOBLOCK);
+
+out:
+ if (sock) {
+ if (!zmq_close(sock)) {
+ g_warning("Failed to close socket: %s", zmq_strerror(zmq_errno()));
+ ret = FALSE;
+ }
+ }
+
+ return ret;
+}
+
int main (int argc, char **argv)
{
+ int ret = 0;
+
GError* err = NULL;
GOptionContext* ctx;
+ void* zmq_ctx = NULL;
+
ctx = g_option_context_new(" - A GStreamer backend daemon for Play");
g_option_context_add_main_entries(ctx, entries, "");
+
if (!g_option_context_parse(ctx, &argc, &argv, &err)) {
+ g_error("WE ARE HERE");
g_error("Option parsing failed: %s", err->message);
- return 1;
+ ret = EXIT_FAILURE;
+ goto out;
}
+ zmq_ctx = zmq_init(1);
+
+ if (client_message) {
+ char* address = zeromq_address_from_port(icecast_port);
+ ret = send_client_message(zmq_ctx, client_message, address) ? 0 : 1;
+ g_free(address);
+ goto out;
+ }
+
+out:
+ if (zmq_ctx) zmq_term(zmq_ctx);
+
g_option_context_free(ctx);
- return 0;
+ return ret;
}
Please sign in to comment.
Something went wrong with that request. Please try again.