Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naru ../xwax-0.6/alsa.c ../xwax-engine/alsa.c
- --- ../xwax-0.6/alsa.c 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/alsa.c 2009-12-15 09:21:58.000000000 +0100
- @@ -327,7 +327,7 @@
- if(r < 0) {
- if(r == -EPIPE) {
- - fputs("ALSA: capture xrun.\n", stderr);
- + //fputs("ALSA: capture xrun.\n", stderr);
- r = snd_pcm_prepare(alsa->capture.pcm);
- if(r < 0) {
- @@ -359,7 +359,7 @@
- if(r < 0) {
- if(r == -EPIPE) {
- - fputs("ALSA: playback xrun.\n", stderr);
- + //fputs("ALSA: playback xrun.\n", stderr);
- r = snd_pcm_prepare(alsa->playback.pcm) < 0;
- if(r < 0) {
- diff -Naru ../xwax-0.6/.config ../xwax-engine/.config
- --- ../xwax-0.6/.config 1970-01-01 01:00:00.000000000 +0100
- +++ ../xwax-engine/.config 2010-01-07 18:55:23.000000000 +0100
- @@ -0,0 +1,2 @@
- +ALSA = yes
- +TCP = yes
- diff -Naru ../xwax-0.6/configure ../xwax-engine/configure
- --- ../xwax-0.6/configure 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/configure 2009-11-08 14:50:06.000000000 +0100
- @@ -23,11 +23,12 @@
- ALSA=0
- JACK=0
- +TCP=0
- while [ $# -ge 1 ]; do
- case $1 in
- --help)
- - echo "Usage: configure [--enable-alsa] [--enable-jack]"
- + echo "Usage: configure [--enable-alsa] [--enable-jack] [--enable-tcp]"
- exit 0
- ;;
- --enable-alsa)
- @@ -36,6 +37,9 @@
- --enable-jack)
- JACK=1
- ;;
- + --enable-tcp)
- + TCP=1
- + ;;
- esac
- shift
- @@ -59,6 +63,13 @@
- echo "JACK disabled"
- fi
- +if [ $TCP = 1 ]; then
- + echo "TCP enabled"
- + echo "TCP = yes" >> $OUTPUT
- +else
- + echo "TCP disabled"
- +fi
- +
- # Explain the next step
- echo "Be sure to run 'make clean' if you have changed the configuration."
- diff -Naru ../xwax-0.6/interface.c ../xwax-engine/interface.c
- --- ../xwax-0.6/interface.c 2009-10-25 19:37:58.000000000 +0100
- +++ ../xwax-engine/interface.c 2009-12-16 06:42:32.000000000 +0100
- @@ -27,6 +27,15 @@
- #include <sys/stat.h>
- #include <sys/types.h>
- +#ifdef WITH_TCP
- +#include <sys/socket.h>
- +#include <arpa/inet.h>
- +#include <errno.h>
- +#include <fcntl.h>
- +
- +#define MAXBUF 1024
- +#endif
- +
- #include <SDL.h>
- #include <SDL_ttf.h>
- @@ -1115,6 +1124,46 @@
- in->listing = NULL;
- }
- +#ifdef WITH_TCP
- +int do_loading_net (struct player_t *pl, char *arg)
- +{
- + int len, rc;
- + struct record_t lr;
- +
- + len = strlen(arg);
- +
- + /*
- + * Check if we can open it - otherwise it would crash the ongoing performance.
- + */
- + rc = open(arg, O_RDONLY);
- + if (rc < 0) {
- + printf("Loading track from remote command: %s FAILED: %s\n", arg, strerror(errno));
- + fflush(stdout);
- + return -1;
- + } else {
- + close(rc);
- + printf("Loading track from remote command: %s\n", arg);
- + }
- +
- + /*
- + * Just fill all of them with the path, we don't care so much about titles at that point.
- + * FIXME: in the future, the network client could provide the Title/Artist information
- + * with delimiters. Doing that at this point can potentially crash the running performance.
- + */
- + lr.pathname = strndup(arg, len);
- + lr.artist = strndup(arg, len);
- + lr.title = strndup(arg, len);
- +
- + do_loading(pl->track, &lr);
- +
- + return 0;
- +}
- +#endif
- +
- +int interface_net_recue (struct player_t *pl, char *arg)
- +{
- + player_recue(pl);
- +}
- int interface_run(struct interface_t *in)
- {
- @@ -1136,6 +1185,27 @@
- struct listing_t *results, *refine, *ltmp, la, lb;
- struct player_t *pl;
- +#ifdef WITH_TCP
- + fd_set master;
- + fd_set read_fds;
- + struct sockaddr_in saddr;
- + struct sockaddr_in caddr;
- + int fdmax;
- + int listener;
- + int newfd;
- + char buf[1024];
- + int nbytes;
- + int yes = 1;
- + int addrlen;
- + int j, s, ii, fail, netrc, curfd;
- +
- + char buffer[MAXBUF];
- + char arg[MAXBUF];
- + char command;
- + struct timeval tv;
- +#endif
- +
- +
- finished = 0;
- listing_init(&la);
- @@ -1190,9 +1260,167 @@
- /* The final action is to add the timer which triggers refresh */
- timer = SDL_AddTimer(REFRESH, ticker, (void*)in);
- +#ifdef WITH_TCP
- - while(!finished && SDL_WaitEvent(&event) >= 0) {
- + /* No timeout */
- + tv.tv_sec = 0;
- + tv.tv_usec = 0;
- +
- + /* Clear fd sets */
- + FD_ZERO (&master);
- + FD_ZERO (&read_fds);
- +
- + /* get the listener */
- + if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
- + perror ("socket()");
- + exit (1);
- + }
- +
- + if (setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (int)) == -1) {
- + perror ("setsockopt()");
- + exit (1);
- + }
- +
- + saddr.sin_family = AF_INET;
- + saddr.sin_addr.s_addr = INADDR_ANY;
- + saddr.sin_port = htons (in->tcpport);
- + memset (&(saddr.sin_zero), '\0', 8);
- +
- + if (bind (listener, (struct sockaddr *) &saddr, sizeof (saddr)) == -1) {
- + perror ("bind()");
- + exit (1);
- + }
- +
- + int flags = fcntl(listener, F_GETFL,0);
- + fcntl(listener, F_SETFL, flags | O_NONBLOCK,0);
- + if (listen (listener, 10) == -1) {
- + perror ("listen()");
- + exit (1);
- + }
- +
- + FD_SET (listener, &master);
- +
- + fdmax = listener;
- + read_fds = master;
- +
- + /*
- + * FIXME: do we need the select condition?
- + */
- + while( !finished &&
- + (((s = select (fdmax + 1, &read_fds, NULL, NULL, &tv)) > 0) ||
- + (SDL_WaitEvent(&event) >= 0 ))) {
- +
- +
- + if (s == -1) {
- + perror ("select()");
- + exit (1);
- + }
- +
- + if (s > 0) {
- +
- + /*
- + * Loop through connections, get data
- + */
- + for (curfd = 0; curfd <= fdmax; curfd++) {
- +
- + if (FD_ISSET (curfd, &read_fds)) {
- +
- + if (curfd == listener) {
- +
- + addrlen = sizeof (caddr);
- +
- + if ((newfd = accept (listener, (struct sockaddr *) &caddr, &addrlen)) == -1) {
- + perror ("accept()");
- + } else {
- + FD_SET (newfd, &master);
- + if (newfd > fdmax) {
- + fdmax = newfd;
- + }
- +
- + printf ("New connection from %s\n",
- + inet_ntoa (caddr.sin_addr));
- + }
- +
- + } else {
- + if ((nbytes = recv (curfd, buffer, MAXBUF, 0)) <= 0) {
- + if (nbytes == 0)
- + printf ("Socket disconnected: %d\n", curfd);
- + else
- + perror ("recv()");
- +
- + close (curfd);
- + FD_CLR (curfd, &master);
- +
- + } else {
- +
- + /*
- + * First char is the command FIXME: check length of command first
- + */
- + command = buffer[0];
- +
- + /*
- + * The third is the deck
- + */
- + deck = atoi(&buffer[2]);
- +
- + /*
- + * loop through the string to the next \n or \0, save it as argument to the command
- + */
- + ii=0;
- + memset(&arg, '\0', MAXBUF);
- +
- + while (ii < MAXBUF && buffer[ii] != '\0' && buffer[ii] != '\r' && buffer[ii] != '\n')
- + ii++;
- + if (ii > 4) {
- + strncpy (arg, &buffer[4], ii-4);
- + arg[ii-4]='\0';
- + }
- +
- + printf ("Remote command %s received for deck %i, argument: %s\n", &command, deck, arg);
- +
- + fail=0;
- +
- + /*
- + * Check if we have a legal number, perform the command
- + */
- + if (deck >= 0 && deck < 4 && (pl = in->player[deck])) {
- + switch(command) {
- + case'l':
- + netrc = do_loading_net(pl, arg);
- + break;
- + case 'c':
- + netrc = interface_net_recue(pl, arg);
- + break;
- + case 'd':
- + player_disconnect_timecoder(pl);
- + break;
- + case 'r':
- + player_connect_timecoder(pl, in->timecoder[deck]);
- + break;
- + case 's':
- + /* implement stats here */
- + printf("Sorry, stats not implemented yet");
- + break;
- + netrc=1;
- + }
- + } else {
- + netrc=1;
- + }
- + if (FD_ISSET (curfd, &read_fds)) {
- + if (fail == 1 || netrc < 0)
- + send(curfd, "FAIL\n", 6, 0);
- + else
- + send(curfd, "OK\n", 4, 0);
- + }
- + }
- + }
- + }
- + }
- + }
- +#else
- + while(!finished && SDL_WaitEvent(&event) >= 0) {
- +#endif
- switch(event.type) {
- case SDL_QUIT:
- @@ -1424,6 +1652,7 @@
- decks_update = UPDATE_NONE;
- }
- + read_fds = master;
- } /* main loop */
- SDL_RemoveTimer(timer);
- diff -Naru ../xwax-0.6/interface.h ../xwax-engine/interface.h
- --- ../xwax-0.6/interface.h 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/interface.h 2009-11-08 14:50:06.000000000 +0100
- @@ -33,6 +33,7 @@
- struct player_t *player[MAX_PLAYERS];
- struct timecoder_t *timecoder[MAX_TIMECODERS];
- struct listing_t *listing;
- + int tcpport;
- };
- void interface_init(struct interface_t *in);
- diff -Naru ../xwax-0.6/library.c ../xwax-engine/library.c
- --- ../xwax-0.6/library.c 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/library.c 2009-12-15 00:09:54.000000000 +0100
- @@ -59,11 +59,21 @@
- free(li->record);
- }
- +/*
- + * library_add adds a single record_t to a previously allocated library_t->entries but
- + * reallocates memory for library_t->entries if sizeof(library_t->size) is met.
- + * The added record of type record_t must be malloc'd prior to adding it to the library.
- + * Adding a statically defined record_t would work, but free() in library_clear will crash.
- + */
- int library_add(struct library_t *li, struct record_t *lr)
- {
- struct record_t *ln;
- -
- + /*
- + * Starts out with sizeof(BLOCK) == 256 in library_init, doubles every time
- + * limit is reached, 512, 1024, 2048 ... thus doing nicely for small to very
- + * large collections.
- + */
- if(li->entries == li->size) {
- fprintf(stderr, "Allocating library space (%d entries reached)...\n",
- li->size);
- @@ -77,7 +87,10 @@
- li->record = ln;
- li->size *= 2;
- }
- -
- + /*
- + * He is adding the pointer to a static record. how can that be freed?
- + * It isn't, only the listing is freed ... WTF
- + */
- li->record[li->entries++] = *lr;
- return 0;
- @@ -88,7 +101,7 @@
- * If the empty string is read, *s is set to NULL. Return 0 on success,
- * -1 on error or EOF */
- -static int get_field(FILE *fp, char delim, char **f)
- +int get_field(FILE *fp, char delim, char **f)
- {
- char *s = NULL;
- size_t n, z;
- @@ -164,6 +177,9 @@
- }
- for(;;) {
- + /*
- + * WTF? No malloc()?!
- + */
- struct record_t d;
- if(get_field(fp, '\t', &d.pathname) != 0)
- diff -Naru ../xwax-0.6/library.h ../xwax-engine/library.h
- --- ../xwax-0.6/library.h 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/library.h 2009-12-15 00:09:38.000000000 +0100
- @@ -35,5 +35,5 @@
- void library_clear(struct library_t *li);
- int library_add(struct library_t *li, struct record_t *lr);
- int library_import(struct library_t *li, const char *scan, const char *path);
- -
- +int get_field(FILE *fp, char delim, char **f);
- #endif
- diff -Naru ../xwax-0.6/Makefile ../xwax-engine/Makefile
- --- ../xwax-0.6/Makefile 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/Makefile 2009-12-15 00:01:28.000000000 +0100
- @@ -49,6 +49,12 @@
- DEVICE_LIBS += $(JACK_LIBS)
- endif
- +ifdef TCP
- +DEVICE_OBJS += xwax.o interface.o library.o
- +DEVICE_CPPFLAGS += -DWITH_TCP
- +DEVICE_LIBS +=
- +endif
- +
- # Rules
- .PHONY: clean
- @@ -57,7 +63,7 @@
- xwax: LDLIBS += $(SDL_LIBS) $(DEVICE_LIBS)
- xwax: LDFLAGS += -pthread
- -interface.o: CFLAGS += $(SDL_CFLAGS)
- +interface.o: CFLAGS += $(SDL_CFLAGS) $(DEVICE_CPPFLAGS)
- xwax.o: CFLAGS += $(DEVICE_CPPFLAGS)
- diff -Naru ../xwax-0.6/xwax.c ../xwax-engine/xwax.c
- --- ../xwax-0.6/xwax.c 2009-09-03 23:31:08.000000000 +0200
- +++ ../xwax-engine/xwax.c 2009-11-08 14:50:06.000000000 +0100
- @@ -128,6 +128,11 @@
- " -j <name> Create a JACK deck with the given name\n\n");
- #endif
- +#ifdef WITH_TCP
- + fprintf(fd, "TCP options:\n"
- + " -p port TCP port to listen on (dangerous)\n\n");
- +#endif
- +
- fprintf(fd, "Device options, -t and -i apply to subsequent devices.\n"
- "Option -s applies to subsequent directories.\n"
- "Decks and audio directories can be specified multiple times.\n\n"
- @@ -368,6 +373,16 @@
- argv += 2;
- argc -= 2;
- +#ifdef WITH_TCP
- + } else if(!strcmp(argv[0], "-p")) {
- +
- + /* set the tcp port */
- +
- + iface.tcpport=atoi(argv[1]);
- +
- + argv += 2;
- + argc -= 2;
- +#endif
- } else if(!strcmp(argv[0], "-s")) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement