Advertisement
Guest User

xwax-tcp-0.6.unfinished_but_working.patch

a guest
Apr 29th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.30 KB | None | 0 0
  1. diff -Naru ../xwax-0.6/alsa.c ../xwax-engine/alsa.c
  2. --- ../xwax-0.6/alsa.c  2009-09-03 23:31:08.000000000 +0200
  3. +++ ../xwax-engine/alsa.c   2009-12-15 09:21:58.000000000 +0100
  4. @@ -327,7 +327,7 @@
  5.          
  6.          if(r < 0) {
  7.              if(r == -EPIPE) {
  8. -                fputs("ALSA: capture xrun.\n", stderr);
  9. +                //fputs("ALSA: capture xrun.\n", stderr);
  10.  
  11.                  r = snd_pcm_prepare(alsa->capture.pcm);
  12.                  if(r < 0) {
  13. @@ -359,7 +359,7 @@
  14.          
  15.          if(r < 0) {
  16.              if(r == -EPIPE) {
  17. -                fputs("ALSA: playback xrun.\n", stderr);
  18. +                //fputs("ALSA: playback xrun.\n", stderr);
  19.                  
  20.                  r = snd_pcm_prepare(alsa->playback.pcm) < 0;
  21.                  if(r < 0) {
  22. diff -Naru ../xwax-0.6/.config ../xwax-engine/.config
  23. --- ../xwax-0.6/.config 1970-01-01 01:00:00.000000000 +0100
  24. +++ ../xwax-engine/.config  2010-01-07 18:55:23.000000000 +0100
  25. @@ -0,0 +1,2 @@
  26. +ALSA = yes
  27. +TCP = yes
  28. diff -Naru ../xwax-0.6/configure ../xwax-engine/configure
  29. --- ../xwax-0.6/configure   2009-09-03 23:31:08.000000000 +0200
  30. +++ ../xwax-engine/configure    2009-11-08 14:50:06.000000000 +0100
  31. @@ -23,11 +23,12 @@
  32.  
  33.  ALSA=0
  34.  JACK=0
  35. +TCP=0
  36.  
  37.  while [ $# -ge 1 ]; do
  38.     case $1 in
  39.     --help)
  40. -       echo "Usage: configure [--enable-alsa] [--enable-jack]"
  41. +       echo "Usage: configure [--enable-alsa] [--enable-jack] [--enable-tcp]"
  42.         exit 0
  43.         ;;
  44.     --enable-alsa)
  45. @@ -36,6 +37,9 @@
  46.     --enable-jack)
  47.         JACK=1
  48.         ;;
  49. +   --enable-tcp)
  50. +                TCP=1
  51. +                ;;
  52.     esac
  53.  
  54.     shift
  55. @@ -59,6 +63,13 @@
  56.     echo "JACK disabled"
  57.  fi
  58.  
  59. +if [ $TCP = 1 ]; then
  60. +       echo "TCP enabled"
  61. +       echo "TCP = yes" >> $OUTPUT
  62. +else
  63. +       echo "TCP disabled"
  64. +fi
  65. +
  66.  # Explain the next step
  67.  
  68.  echo "Be sure to run 'make clean' if you have changed the configuration."
  69. diff -Naru ../xwax-0.6/interface.c ../xwax-engine/interface.c
  70. --- ../xwax-0.6/interface.c 2009-10-25 19:37:58.000000000 +0100
  71. +++ ../xwax-engine/interface.c  2009-12-16 06:42:32.000000000 +0100
  72. @@ -27,6 +27,15 @@
  73.  #include <sys/stat.h>
  74.  #include <sys/types.h>
  75.  
  76. +#ifdef WITH_TCP
  77. +#include <sys/socket.h>
  78. +#include <arpa/inet.h>
  79. +#include <errno.h>
  80. +#include <fcntl.h>
  81. +
  82. +#define MAXBUF         1024
  83. +#endif
  84. +
  85.  #include <SDL.h>
  86.  #include <SDL_ttf.h>
  87.  
  88. @@ -1115,6 +1124,46 @@
  89.      in->listing = NULL;
  90.  }
  91.  
  92. +#ifdef WITH_TCP
  93. +int do_loading_net (struct player_t *pl, char *arg)
  94. +{
  95. +   int len, rc;
  96. +   struct record_t lr;
  97. +
  98. +   len = strlen(arg);
  99. +
  100. +   /*
  101. +    * Check if we can open it - otherwise it would crash the ongoing performance.
  102. +    */
  103. +   rc = open(arg, O_RDONLY);
  104. +   if (rc < 0) {
  105. +       printf("Loading track from remote command: %s FAILED: %s\n", arg, strerror(errno));
  106. +       fflush(stdout);
  107. +       return -1;
  108. +   } else {
  109. +       close(rc);
  110. +       printf("Loading track from remote command: %s\n", arg);
  111. +   }
  112. +
  113. +   /*
  114. +    * Just fill all of them with the path, we don't care so much about titles at that point.
  115. +    * FIXME: in the future, the network client could provide the Title/Artist information
  116. +    * with delimiters. Doing that at this point can potentially crash the running performance.
  117. +    */
  118. +   lr.pathname = strndup(arg, len);
  119. +   lr.artist = strndup(arg, len);
  120. +   lr.title = strndup(arg, len);
  121. +
  122. +   do_loading(pl->track, &lr);
  123. +
  124. +   return 0;
  125. +}
  126. +#endif
  127. +
  128. +int interface_net_recue (struct player_t *pl, char *arg)
  129. +{
  130. +   player_recue(pl);
  131. +}
  132.  
  133.  int interface_run(struct interface_t *in)
  134.  {
  135. @@ -1136,6 +1185,27 @@
  136.      struct listing_t *results, *refine, *ltmp, la, lb;
  137.      struct player_t *pl;
  138.  
  139. +#ifdef WITH_TCP
  140. +      fd_set master;
  141. +      fd_set read_fds;
  142. +      struct sockaddr_in saddr;
  143. +      struct sockaddr_in caddr;
  144. +      int fdmax;
  145. +      int listener;
  146. +      int newfd;
  147. +      char buf[1024];
  148. +      int nbytes;
  149. +      int yes = 1;
  150. +      int addrlen;
  151. +      int j, s, ii, fail, netrc, curfd;
  152. +
  153. +      char buffer[MAXBUF];
  154. +      char arg[MAXBUF];
  155. +      char command;
  156. +      struct timeval tv;
  157. +#endif
  158. +
  159. +
  160.      finished = 0;
  161.      
  162.      listing_init(&la);
  163. @@ -1190,9 +1260,167 @@
  164.      /* The final action is to add the timer which triggers refresh */
  165.  
  166.      timer = SDL_AddTimer(REFRESH, ticker, (void*)in);
  167. +#ifdef WITH_TCP
  168.  
  169. -    while(!finished && SDL_WaitEvent(&event) >= 0) {
  170. +    /* No timeout */
  171. +    tv.tv_sec = 0;
  172. +    tv.tv_usec = 0;
  173. +
  174. +    /* Clear fd sets */
  175. +    FD_ZERO (&master);
  176. +    FD_ZERO (&read_fds);
  177. +
  178. +    /* get the listener */
  179. +    if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
  180. +       perror ("socket()");
  181. +        exit (1);
  182. +    }
  183. +
  184. +    if (setsockopt (listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (int)) == -1) {
  185. +       perror ("setsockopt()");
  186. +       exit (1);
  187. +   }
  188. +
  189. +    saddr.sin_family = AF_INET;
  190. +   saddr.sin_addr.s_addr = INADDR_ANY;
  191. +   saddr.sin_port = htons (in->tcpport);
  192. +   memset (&(saddr.sin_zero), '\0', 8);
  193. +
  194. +   if (bind (listener, (struct sockaddr *) &saddr, sizeof (saddr)) == -1) {
  195. +       perror ("bind()");
  196. +       exit (1);
  197. +    }
  198. +
  199. +    int flags = fcntl(listener, F_GETFL,0);
  200. +    fcntl(listener, F_SETFL, flags | O_NONBLOCK,0);
  201.  
  202. +    if (listen (listener, 10) == -1) {
  203. +       perror ("listen()");
  204. +       exit (1);
  205. +    }
  206. +
  207. +   FD_SET (listener, &master);
  208. +    
  209. +   fdmax = listener;
  210. +   read_fds = master;
  211. +
  212. +   /*
  213. +    * FIXME: do we need the select condition?
  214. +    */
  215. +   while(  !finished &&
  216. +           (((s = select (fdmax + 1, &read_fds, NULL, NULL, &tv)) > 0) ||
  217. +           (SDL_WaitEvent(&event) >= 0 ))) {
  218. +
  219. +
  220. +       if (s == -1) {
  221. +           perror ("select()");
  222. +           exit (1);
  223. +       }
  224. +
  225. +       if (s > 0) {
  226. +
  227. +       /*
  228. +        * Loop through connections, get data
  229. +        */
  230. +        for (curfd = 0; curfd <= fdmax; curfd++) {
  231. +
  232. +           if (FD_ISSET (curfd, &read_fds)) {
  233. +
  234. +               if (curfd == listener) {
  235. +
  236. +                   addrlen = sizeof (caddr);
  237. +
  238. +                   if ((newfd = accept (listener, (struct sockaddr *) &caddr, &addrlen)) == -1) {
  239. +                       perror ("accept()");
  240. +                   } else {
  241. +                       FD_SET (newfd, &master);
  242. +                       if (newfd > fdmax) {
  243. +                           fdmax = newfd;
  244. +                       }
  245. +
  246. +                       printf ("New connection from %s\n",
  247. +                               inet_ntoa (caddr.sin_addr));
  248. +                   }
  249. +
  250. +               } else {
  251. +                   if ((nbytes = recv (curfd, buffer, MAXBUF, 0)) <= 0) {
  252. +                       if (nbytes == 0)
  253. +                           printf ("Socket disconnected: %d\n", curfd);
  254. +                       else
  255. +                           perror ("recv()");
  256. +
  257. +                       close (curfd);
  258. +                       FD_CLR (curfd, &master);
  259. +
  260. +                   } else {
  261. +
  262. +                       /*
  263. +                        * First char is the command FIXME: check length of command first
  264. +                        */
  265. +                       command = buffer[0];
  266. +
  267. +                       /*
  268. +                        * The third is the deck
  269. +                        */
  270. +                       deck = atoi(&buffer[2]);
  271. +
  272. +                       /*
  273. +                        * loop through the string to the next \n or \0, save it as argument to the command
  274. +                        */
  275. +                       ii=0;
  276. +                       memset(&arg, '\0', MAXBUF);
  277. +
  278. +                       while (ii < MAXBUF && buffer[ii] != '\0' && buffer[ii] != '\r' && buffer[ii] != '\n')
  279. +                           ii++;
  280. +                           if (ii > 4) {
  281. +                               strncpy (arg, &buffer[4], ii-4);
  282. +                               arg[ii-4]='\0';
  283. +                           }
  284. +
  285. +                           printf ("Remote command %s received for deck %i, argument: %s\n", &command, deck, arg);
  286. +
  287. +                           fail=0;
  288. +
  289. +                           /*
  290. +                            * Check if we have a legal number, perform the command
  291. +                            */
  292. +                           if (deck >= 0 && deck < 4 && (pl = in->player[deck])) {
  293. +                               switch(command) {
  294. +                                   case'l':
  295. +                                       netrc = do_loading_net(pl, arg);
  296. +                                       break;
  297. +                                   case 'c':
  298. +                                       netrc = interface_net_recue(pl, arg);
  299. +                                       break;
  300. +                                   case 'd':
  301. +                                       player_disconnect_timecoder(pl);
  302. +                                       break;
  303. +                                   case 'r':
  304. +                                       player_connect_timecoder(pl, in->timecoder[deck]);
  305. +                                       break;
  306. +                                   case 's':
  307. +                                       /* implement stats here */
  308. +                                       printf("Sorry, stats not implemented yet");
  309. +                                       break;
  310. +                                   netrc=1;
  311. +                               }
  312. +                           } else {
  313. +                               netrc=1;
  314. +                           }
  315. +                           if (FD_ISSET (curfd, &read_fds)) {
  316. +                               if (fail == 1 || netrc < 0)
  317. +                                   send(curfd, "FAIL\n", 6, 0);
  318. +                               else
  319. +                                   send(curfd, "OK\n", 4, 0);
  320. +                           }
  321. +                       }
  322. +                   }
  323. +               }
  324. +           }
  325. +       }
  326. +#else
  327. +    while(!finished && SDL_WaitEvent(&event) >= 0) {
  328. +#endif
  329.          switch(event.type) {
  330.              
  331.          case SDL_QUIT:
  332. @@ -1424,6 +1652,7 @@
  333.              decks_update = UPDATE_NONE;
  334.          }
  335.  
  336. +        read_fds = master;
  337.      } /* main loop */
  338.  
  339.      SDL_RemoveTimer(timer);
  340. diff -Naru ../xwax-0.6/interface.h ../xwax-engine/interface.h
  341. --- ../xwax-0.6/interface.h 2009-09-03 23:31:08.000000000 +0200
  342. +++ ../xwax-engine/interface.h  2009-11-08 14:50:06.000000000 +0100
  343. @@ -33,6 +33,7 @@
  344.      struct player_t *player[MAX_PLAYERS];
  345.      struct timecoder_t *timecoder[MAX_TIMECODERS];
  346.      struct listing_t *listing;
  347. +    int tcpport;
  348.  };
  349.  
  350.  void interface_init(struct interface_t *in);
  351. diff -Naru ../xwax-0.6/library.c ../xwax-engine/library.c
  352. --- ../xwax-0.6/library.c   2009-09-03 23:31:08.000000000 +0200
  353. +++ ../xwax-engine/library.c    2009-12-15 00:09:54.000000000 +0100
  354. @@ -59,11 +59,21 @@
  355.      free(li->record);
  356.  }
  357.  
  358. +/*
  359. + * library_add adds a single record_t to a previously allocated library_t->entries but
  360. + * reallocates memory for library_t->entries if sizeof(library_t->size) is met.
  361. + * The added record of type record_t must be malloc'd prior to adding it to the library.
  362. + * Adding a statically defined record_t would work, but free() in library_clear will crash.
  363. + */
  364.  
  365.  int library_add(struct library_t *li, struct record_t *lr)
  366.  {
  367.      struct record_t *ln;
  368. -
  369. +    /*
  370. +     * Starts out with sizeof(BLOCK) == 256 in library_init, doubles every time
  371. +     * limit is reached, 512, 1024, 2048 ... thus doing nicely for small to very
  372. +     * large collections.
  373. +     */
  374.      if(li->entries == li->size) {
  375.          fprintf(stderr, "Allocating library space (%d entries reached)...\n",
  376.                  li->size);
  377. @@ -77,7 +87,10 @@
  378.          li->record = ln;
  379.          li->size *= 2;
  380.      }
  381. -
  382. +    /*
  383. +     * He is adding the pointer to a static record. how can that be freed?
  384. +     * It isn't, only the listing is freed ... WTF
  385. +     */
  386.      li->record[li->entries++] = *lr;
  387.  
  388.      return 0;
  389. @@ -88,7 +101,7 @@
  390.   * If the empty string is read, *s is set to NULL. Return 0 on success,
  391.   * -1 on error or EOF */
  392.  
  393. -static int get_field(FILE *fp, char delim, char **f)
  394. +int get_field(FILE *fp, char delim, char **f)
  395.  {
  396.      char *s = NULL;
  397.      size_t n, z;
  398. @@ -164,6 +177,9 @@
  399.      }
  400.  
  401.      for(;;) {
  402. +       /*
  403. +        * WTF? No malloc()?!
  404. +        */
  405.          struct record_t d;
  406.  
  407.          if(get_field(fp, '\t', &d.pathname) != 0)
  408. diff -Naru ../xwax-0.6/library.h ../xwax-engine/library.h
  409. --- ../xwax-0.6/library.h   2009-09-03 23:31:08.000000000 +0200
  410. +++ ../xwax-engine/library.h    2009-12-15 00:09:38.000000000 +0100
  411. @@ -35,5 +35,5 @@
  412.  void library_clear(struct library_t *li);
  413.  int library_add(struct library_t *li, struct record_t *lr);
  414.  int library_import(struct library_t *li, const char *scan, const char *path);
  415. -
  416. +int get_field(FILE *fp, char delim, char **f);
  417.  #endif
  418. diff -Naru ../xwax-0.6/Makefile ../xwax-engine/Makefile
  419. --- ../xwax-0.6/Makefile    2009-09-03 23:31:08.000000000 +0200
  420. +++ ../xwax-engine/Makefile 2009-12-15 00:01:28.000000000 +0100
  421. @@ -49,6 +49,12 @@
  422.  DEVICE_LIBS += $(JACK_LIBS)
  423.  endif
  424.  
  425. +ifdef TCP
  426. +DEVICE_OBJS += xwax.o interface.o library.o
  427. +DEVICE_CPPFLAGS += -DWITH_TCP
  428. +DEVICE_LIBS +=
  429. +endif
  430. +
  431.  # Rules
  432.  
  433.  .PHONY:        clean
  434. @@ -57,7 +63,7 @@
  435.  xwax:      LDLIBS += $(SDL_LIBS) $(DEVICE_LIBS)
  436.  xwax:      LDFLAGS += -pthread
  437.  
  438. -interface.o:   CFLAGS += $(SDL_CFLAGS)
  439. +interface.o:   CFLAGS += $(SDL_CFLAGS) $(DEVICE_CPPFLAGS)
  440.  
  441.  xwax.o:        CFLAGS += $(DEVICE_CPPFLAGS)
  442.  
  443. diff -Naru ../xwax-0.6/xwax.c ../xwax-engine/xwax.c
  444. --- ../xwax-0.6/xwax.c  2009-09-03 23:31:08.000000000 +0200
  445. +++ ../xwax-engine/xwax.c   2009-11-08 14:50:06.000000000 +0100
  446. @@ -128,6 +128,11 @@
  447.        "  -j <name>      Create a JACK deck with the given name\n\n");
  448.  #endif
  449.  
  450. +#ifdef WITH_TCP
  451. +     fprintf(fd, "TCP options:\n"
  452. +     "  -p port        TCP port to listen on (dangerous)\n\n");
  453. +#endif
  454. +
  455.      fprintf(fd, "Device options, -t and -i apply to subsequent devices.\n"
  456.        "Option -s applies to subsequent directories.\n"
  457.        "Decks and audio directories can be specified multiple times.\n\n"
  458. @@ -368,6 +373,16 @@
  459.  
  460.              argv += 2;
  461.              argc -= 2;
  462. +#ifdef WITH_TCP
  463. +        } else if(!strcmp(argv[0], "-p")) {
  464. +
  465. +            /* set the tcp port */
  466. +
  467. +            iface.tcpport=atoi(argv[1]);
  468. +
  469. +            argv += 2;
  470. +            argc -= 2;
  471. +#endif
  472.  
  473.          } else if(!strcmp(argv[0], "-s")) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement