| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <sys/types.h> |
| 6 |
#include <sys/stat.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <rplay.h> |
| 9 |
|
| 10 |
main(int argc, char **argv) |
| 11 |
{ |
| 12 |
FILE *fp; |
| 13 |
int rptp_fd, size, n, nwritten; |
| 14 |
struct stat st; |
| 15 |
char *id; |
| 16 |
char line[RPTP_MAX_LINE]; |
| 17 |
char response[RPTP_MAX_LINE]; |
| 18 |
char buf[8000]; |
| 19 |
|
| 20 |
|
| 21 |
if (stat(argv[1], &st) < 0) |
| 22 |
{ |
| 23 |
perror(argv[1]); |
| 24 |
exit(1); |
| 25 |
} |
| 26 |
size = st.st_size; |
| 27 |
|
| 28 |
fp = fopen(argv[1], "r"); |
| 29 |
if (fp == NULL) |
| 30 |
{ |
| 31 |
perror(argv[1]); |
| 32 |
exit(1); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
rptp_fd = rptp_open(rplay_default_host(), RPTP_PORT, response, sizeof(response)); |
| 37 |
if (rptp_fd < 0) |
| 38 |
{ |
| 39 |
rptp_perror(rplay_default_host()); |
| 40 |
exit(1); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
sprintf(line, "play input=flow input-storage=none sound=%s", argv[1]); |
| 45 |
switch (rptp_command(rptp_fd, line, response, sizeof(response))) |
| 46 |
{ |
| 47 |
case -1: |
| 48 |
rptp_perror(argv[0]); |
| 49 |
exit(1); |
| 50 |
|
| 51 |
case 1: |
| 52 |
fprintf(stderr, "%s\n", rptp_parse(response, "error")); |
| 53 |
exit(1); |
| 54 |
|
| 55 |
case 0: |
| 56 |
break; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
id = rptp_parse(response, "id"); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
while (size > 0) |
| 65 |
{ |
| 66 |
n = fread(buf, 1, sizeof(buf), fp); |
| 67 |
|
| 68 |
|
| 69 |
sprintf(line, "put id=%s size=%d", id, n); |
| 70 |
switch (rptp_command(rptp_fd, line, response, sizeof(response))) |
| 71 |
{ |
| 72 |
case -1: |
| 73 |
rptp_perror(argv[0]); |
| 74 |
exit(1); |
| 75 |
|
| 76 |
case 1: |
| 77 |
fprintf(stderr, "%s\n", rptp_parse(response, "error")); |
| 78 |
exit(1); |
| 79 |
|
| 80 |
case 0: |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
nwritten = rptp_write(rptp_fd, buf, n); |
| 85 |
if (nwritten != n) |
| 86 |
{ |
| 87 |
rptp_perror("flow"); |
| 88 |
break; |
| 89 |
} |
| 90 |
size -= nwritten; |
| 91 |
} |
| 92 |
|
| 93 |
fclose(fp); |
| 94 |
|
| 95 |
|
| 96 |
sprintf(line, "done id=%s", id); |
| 97 |
switch (rptp_command(rptp_fd, line, response, sizeof(response))) |
| 98 |
{ |
| 99 |
case -1: |
| 100 |
rptp_perror(argv[0]); |
| 101 |
exit(1); |
| 102 |
|
| 103 |
case 1: |
| 104 |
fprintf(stderr, "%s\n", rptp_parse(response, "error")); |
| 105 |
exit(1); |
| 106 |
|
| 107 |
case 0: |
| 108 |
break; |
| 109 |
} |
| 110 |
|
| 111 |
exit(0); |
| 112 |
} |