summaryrefslogtreecommitdiffstats
path: root/lib/libshout-idjc/examples
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2021-01-08 16:23:14 +0100
committerDaniel Schürmann <daschuer@mixxx.org>2021-01-08 23:51:56 +0100
commitc844c8514308707d605602499b391ba14072433b (patch)
treebe94eb9392a68216f0946ace55a4d825c545a618 /lib/libshout-idjc/examples
parent029b40539380119bcd80a28e53607b2530d1b548 (diff)
Renamed libshout folder to libshout-idjc
Diffstat (limited to 'lib/libshout-idjc/examples')
-rw-r--r--lib/libshout-idjc/examples/Makefile.am14
-rw-r--r--lib/libshout-idjc/examples/example.c86
-rw-r--r--lib/libshout-idjc/examples/nonblocking.c108
3 files changed, 208 insertions, 0 deletions
diff --git a/lib/libshout-idjc/examples/Makefile.am b/lib/libshout-idjc/examples/Makefile.am
new file mode 100644
index 0000000000..72a1209eaa
--- /dev/null
+++ b/lib/libshout-idjc/examples/Makefile.am
@@ -0,0 +1,14 @@
+## Process this file with automake to create Makefile.in
+
+AUTOMAKE_OPTIONS = foreign
+
+noinst_PROGRAMS = example nonblocking
+
+example_SOURCES = example.c
+example_LDADD = $(top_builddir)/src/libshout.la @SHOUT_LIBDEPS@
+
+nonblocking_SOURCES = nonblocking.c
+nonblocking_LDADD = $(top_builddir)/src/libshout.la @SHOUT_LIBDEPS@
+
+AM_CFLAGS = @XIPH_CFLAGS@
+AM_CPPFLAGS = @XIPH_CPPFLAGS@ -I$(top_builddir)/include
diff --git a/lib/libshout-idjc/examples/example.c b/lib/libshout-idjc/examples/example.c
new file mode 100644
index 0000000000..e1f6c149a9
--- /dev/null
+++ b/lib/libshout-idjc/examples/example.c
@@ -0,0 +1,86 @@
+/* example.c: Demonstration of the libshout API.
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <shout/shout.h>
+
+int main()
+{
+ shout_t *shout;
+ unsigned char buff[4096];
+ long read, ret, total;
+
+ shout_init();
+
+ if (!(shout = shout_new())) {
+ printf("Could not allocate shout_t\n");
+ return 1;
+ }
+
+ if (shout_set_host(shout, "127.0.0.1") != SHOUTERR_SUCCESS) {
+ printf("Error setting hostname: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
+ printf("Error setting protocol: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS) {
+ printf("Error setting port: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_password(shout, "hackme") != SHOUTERR_SUCCESS) {
+ printf("Error setting password: %s\n", shout_get_error(shout));
+ return 1;
+ }
+ if (shout_set_mount(shout, "/example.ogg") != SHOUTERR_SUCCESS) {
+ printf("Error setting mount: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
+ printf("Error setting user: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
+ printf("Error setting user: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_open(shout) == SHOUTERR_SUCCESS) {
+ printf("Connected to server...\n");
+ total = 0;
+ while (1) {
+ read = fread(buff, 1, sizeof(buff), stdin);
+ total = total + read;
+
+ if (read > 0) {
+ ret = shout_send(shout, buff, read);
+ if (ret != SHOUTERR_SUCCESS) {
+ printf("DEBUG: Send error: %s\n", shout_get_error(shout));
+ break;
+ }
+ } else {
+ break;
+ }
+
+ shout_sync(shout);
+ }
+ } else {
+ printf("Error connecting: %s\n", shout_get_error(shout));
+ }
+
+ shout_close(shout);
+
+ shout_shutdown();
+
+ return 0;
+}
diff --git a/lib/libshout-idjc/examples/nonblocking.c b/lib/libshout-idjc/examples/nonblocking.c
new file mode 100644
index 0000000000..1458cf80a0
--- /dev/null
+++ b/lib/libshout-idjc/examples/nonblocking.c
@@ -0,0 +1,108 @@
+/* -*- c-basic-offset: 8; -*-
+ * example.c: Demonstration of the libshout API.
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <shout/shout.h>
+
+int main()
+{
+ shout_t *shout;
+ unsigned char buff[4096];
+ long read, ret, total;
+
+ shout_init();
+
+ if (!(shout = shout_new())) {
+ printf("Could not allocate shout_t\n");
+ return 1;
+ }
+
+ if (shout_set_host(shout, "127.0.0.1") != SHOUTERR_SUCCESS) {
+ printf("Error setting hostname: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
+ printf("Error setting protocol: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS) {
+ printf("Error setting port: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_password(shout, "hackme") != SHOUTERR_SUCCESS) {
+ printf("Error setting password: %s\n", shout_get_error(shout));
+ return 1;
+ }
+ if (shout_set_mount(shout, "/example.ogg") != SHOUTERR_SUCCESS) {
+ printf("Error setting mount: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
+ printf("Error setting user: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
+ printf("Error setting user: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ if (shout_set_nonblocking(shout, 1) != SHOUTERR_SUCCESS) {
+ printf("Error setting non-blocking mode: %s\n", shout_get_error(shout));
+ return 1;
+ }
+
+ ret = shout_open(shout);
+ if (ret == SHOUTERR_SUCCESS)
+ ret = SHOUTERR_CONNECTED;
+
+ if (ret == SHOUTERR_BUSY)
+ printf("Connection pending...\n");
+
+ while (ret == SHOUTERR_BUSY) {
+ usleep(10000);
+ ret = shout_get_connected(shout);
+ }
+
+ if (ret == SHOUTERR_CONNECTED) {
+ printf("Connected to server...\n");
+ total = 0;
+ while (1) {
+ read = fread(buff, 1, sizeof(buff), stdin);
+ total = total + read;
+
+ if (read > 0) {
+ ret = shout_send(shout, buff, read);
+ if (ret != SHOUTERR_SUCCESS) {
+ printf("DEBUG: Send error: %s\n", shout_get_error(shout));
+ break;
+ }
+ } else {
+ break;
+ }
+ if (shout_queuelen(shout) > 0)
+ printf("DEBUG: queue length: %d\n",
+ (int)shout_queuelen(shout));
+
+ shout_sync(shout);
+ }
+ } else {
+ printf("Error connecting: %s\n", shout_get_error(shout));
+ }
+
+ shout_close(shout);
+
+ shout_shutdown();
+
+ return 0;
+}