example.c 1.83 KB
Newer Older
1
/* example.c: Demonstration of the libshout API. */
Jack Moffitt's avatar
Jack Moffitt committed
2
3
4
5
6
7
8
9
10

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <shout/shout.h>

int main()
{
11
	shout_t *shout;
Jack Moffitt's avatar
Jack Moffitt committed
12
13
14
	char buff[4096];
	long read, ret, total;

15
16
	shout_init();

17
18
19
20
	if (!(shout = shout_new())) {
		printf("Could not allocate shout_t\n");
		return 1;
	}
Jack Moffitt's avatar
Jack Moffitt committed
21

22
23
24
25
	if (shout_set_host(shout, "127.0.0.1") != SHOUTERR_SUCCESS) {
		printf("Error setting hostname: %s\n", shout_get_error(shout));
		return 1;
	}
26

brendan's avatar
brendan committed
27
28
29
30
	if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
		printf("Error setting protocol: %s\n", shout_get_error(shout));
		return 1;
	}
31

brendan's avatar
brendan committed
32
33
34
35
	if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS) {
		printf("Error setting port: %s\n", shout_get_error(shout));
		return 1;
	}
36

37
38
39
40
41
42
43
44
	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;
	}
45

brendan's avatar
brendan committed
46
47
48
49
	if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) {
		printf("Error setting user: %s\n", shout_get_error(shout));
		return 1;
	}
50

51
	if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
brendan's avatar
brendan committed
52
53
54
		printf("Error setting user: %s\n", shout_get_error(shout));
		return 1;
	}
Jack Moffitt's avatar
Jack Moffitt committed
55

56
	if (shout_open(shout) == SHOUTERR_SUCCESS) {
Jack Moffitt's avatar
Jack Moffitt committed
57
58
59
		printf("Connected to server...\n");
		total = 0;
		while (1) {
60
			read = fread(buff, 1, sizeof(buff), stdin);
Jack Moffitt's avatar
Jack Moffitt committed
61
62
63
			total = total + read;

			if (read > 0) {
64
65
66
				ret = shout_send(shout, buff, read);
				if (ret != SHOUTERR_SUCCESS) {
					printf("DEBUG: Send error: %s\n", shout_get_error(shout));
Jack Moffitt's avatar
Jack Moffitt committed
67
68
69
70
71
72
					break;
				}
			} else {
				break;
			}

73
			shout_sync(shout);
Jack Moffitt's avatar
Jack Moffitt committed
74
75
		}
	} else {
76
		printf("Error connecting: %s\n", shout_get_error(shout));
Jack Moffitt's avatar
Jack Moffitt committed
77
78
	}

79
	shout_close(shout);
Jack Moffitt's avatar
Jack Moffitt committed
80

81
82
	shout_shutdown();

Jack Moffitt's avatar
Jack Moffitt committed
83
84
	return 0;
}