home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: guido.van.rossum@cwi.nl (Guido van Rossum)
- Subject: v26i240: radio - UDP broadcast/receive utilities for audio data, V2.0, Patch04
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: guido.van.rossum@cwi.nl (Guido van Rossum)
- Posting-Number: Volume 26, Issue 240
- Archive-Name: radio2.0.2/patch04
-
- This is official patch number 4 for radio version 2.0, bringing it up
- to patch level 4, or version 2.0.4. See the blurb a little further
- below if you don't know what radio is.
-
- Changes in 2.0 patchlevel 4
- ---------------------------
-
- Fix broken info reply from broadcast (no port was filled in).
-
- Made port numbers in info messages from radio/broadcast positive
- integers.
-
- Some new debug messages in radio.c.
-
- Port to HP-UX by Philippe-Andre Prindeville <philipp@res.enst.fr>.
- (This uses the raw interface to the hardware. Philippe-Andre has
- tried to use the AAPI library but can't get it to work properly. If
- you think you can get the AAPI version working, let me know and I'll
- send you his AAPI patches.)
-
- The following improvements are thanks to Andreas Stolcke
- <stolcke@ICSI.Berkeley.EDU>:
-
- It is now possible to have multiple broadcast processes running on the
- same host; the transmission socket is no longer bound to a fixed port
- (you may have to zero the control port with -c 0 if your system
- doesn't have the SO_REUSEPORT socket option).
-
- Radio -r is now implemented by filtering packets based on sender's
- address rather than connecting to a fixed port.
-
- Fixed integer overflow in broadcast -t after about 35 minutes.
-
- Ignore tune requests to invalid port numbers.
-
- Fixed unused variable in "bad broadcast address" error message.
-
- Let opensock() return -1 on error.
-
- ******************
- * What is radio? *
- ******************
-
- If you have a local area network full of workstations with audio
- capabilities and at least one FM/AM radio or other audio source, you
- can broadcast the audio over the network, and let other users listen
- to it.
-
- This software works for Sun Sparcs running SunOS 4.0 or 4.1, for SGI
- Indigo or Personal IRIS 4D/30 or 4D/35 workstations running SGI IRIX
- 4.0 or 3.3.2, NeXT workstations (running version 2.1), DECstations
- equipped with DEC lofi, machines running the AudioFile audio server
- from DEC CRL, and HP machines with audio hardware. At CWI, versions
- of it have been in continuous use on a mix of Sun and SGI system types
- for almost two years; version 1.0 (patchlevel 4) was last tested on a
- NeXT. (I've heard that the program doesn't work on NeXT 3.1; if you
- fix it please send me the changes!)
-
- Man pages for "radio" and "broadcast" are provided.
-
- The implementation continuously transmits UDP broadcast packets of
- 1400 bytes each (i.e. less than six per second), which contain the
- data in U-LAW format (8000 samples/second, 1 byte/sample,
- logarithmically encoded). On a typical ethernet, this uses about 1
- percent of the net available bandwith. Some loss of UDP packets is
- tolerated by the receiving program (this is heard as short
- interruptions of the sound). Every now and then, a short "station
- call" packet is transmitted as well, for the benefit of advanced
- listening programs.
-
- If you missed a part of the posting of radio, you can ftp the whole
- source from ftp.cwi.nl [192.16.184.180], file /pub/radio2.0.*.tar.Z,
- or from the comp.sources.unix archives.
-
- Enjoy,
-
- --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
-
- Prereq: 3
-
- *** pl3/patchlevel.h Fri May 7 16:29:01 1993
- --- ./patchlevel.h Mon May 17 10:48:51 1993
- ***************
- *** 1 ****
- ! #define PATCHLEVEL 3
- --- 1 ----
- ! #define PATCHLEVEL 4
- *** pl3/Makefile Fri May 7 16:28:59 1993
- --- ./Makefile Mon May 10 21:27:11 1993
- ***************
- *** 27,30 ****
- @echo 'You must use "make sun4.0", "make sun4.1",'
- ! @echo '"make next", "make sgi", "make lofi" or'
- ! @echo '"make audiofile"'
- exit 1
- --- 27,30 ----
- @echo 'You must use "make sun4.0", "make sun4.1",'
- ! @echo '"make next", "make sgi", "make hpux",'
- ! @echo '"make lofi" or "make audiofile"'
- exit 1
- ***************
- *** 52,53 ****
- --- 52,66 ----
- make all sndulaw
- +
- + hpux: # HPUX 8.07
- + make all 'LIBS=-lX11' \
- + CC="cc -Aa" \
- + CFLAGS="-D_HPUX_SOURCE +e -I/usr/include/X11R4"
- +
- + # If you are using the AAPI (Audio Application Programming Interface),
- + # use the next 3 lines instead and don't forget to edit radio.h.
- +
- + #hpux: # HPUX 8.07
- + # make all 'LIBS=-lX11' \
- + # CC="cc -Aa" \
- + # CFLAGS="-D_HPUX_SOURCE +e -I/usr/include/Motif1.1 -I/usr/include/X11R4"
-
- *** pl3/README Fri May 7 16:28:59 1993
- --- ./README Tue May 11 16:37:06 1993
- ***************
- *** 3,5 ****
-
- ! This is Radio version 2.0, patchlevel 3 (a.k.a. 2.0.3).
-
- --- 3,5 ----
-
- ! This is Radio version 2.0, patchlevel 4 (a.k.a. 2.0.4).
-
- ***************
- *** 13,20 ****
- 4.0 or 3.3.2, NeXT workstations (running version 2.1), DECstations
- ! equipped with DEC lofi, and machines running the Audio File audio
- ! server from DEC CRL. At CWI, versions of it have been in continuous
- ! use on a mix of Sun and SGI system types for almost two years; version
- ! 1.0 (patchlevel 4) was last tested on a NeXT. (I've heard that the
- ! program doesn't work on NeXT 3.1; if you fix it please send me the
- ! changes!)
-
- --- 13,20 ----
- 4.0 or 3.3.2, NeXT workstations (running version 2.1), DECstations
- ! equipped with DEC lofi, machines running the AudioFile audio server
- ! from DEC CRL, and HP machines with audio hardware. At CWI, versions
- ! of it have been in continuous use on a mix of Sun and SGI system types
- ! for almost two years; version 1.0 (patchlevel 4) was last tested on a
- ! NeXT. (I've heard that the program doesn't work on NeXT 3.1; if you
- ! fix it please send me the changes!)
-
- ***************
- *** 53,54 ****
- --- 53,90 ----
-
- + Changes in 2.0 patchlevel 4
- + ---------------------------
- +
- + Fix broken info reply from broadcast (no port was filled in).
- +
- + Made port numbers in info messages from radio/broadcast positive
- + integers.
- +
- + Some new debug messages in radio.c.
- +
- + Port to HP-UX by Philippe-Andre Prindeville <philipp@res.enst.fr>.
- + (This uses the raw interface to the hardware. Philippe-Andre has
- + tried to use the AAPI library but can't get it to work properly. If
- + you think you can get the AAPI version working, let me know and I'll
- + send you his AAPI patches.)
- +
- + The following improvements are thanks to Andreas Stolcke
- + <stolcke@ICSI.Berkeley.EDU>:
- +
- + It is now possible to have multiple broadcast processes running on the
- + same host; the transmission socket is no longer bound to a fixed port
- + (you may have to zero the control port with -c 0 if your system
- + doesn't have the SO_REUSEPORT socket option).
- +
- + Radio -r is now implemented by filtering packets based on sender's
- + address rather than connecting to a fixed port.
- +
- + Fixed integer overflow in broadcast -t after about 35 minutes.
- +
- + Ignore tune requests to invalid port numbers.
- +
- + Fixed unused variable in "bad broadcast address" error message.
- +
- + Let opensock() return -1 on error.
- +
- +
- Changes in 2.0 patchlevel 3
- ***************
- *** 61,66 ****
-
- ! Radio can now also be used with DEC CRL's AudioFile server or with DEC
- ! LoFi hardware (these options require additional software available
- ! elsewhere). When compiled for AudioFile, broadcast can optionally
- ! record data directly from the server.
-
- --- 97,103 ----
-
- ! Thanks to George Neville-Neil, radio can now also be used with DEC
- ! CRL's AudioFile server or with DEC LoFi hardware (these options
- ! require additional software available elsewhere). When compiled for
- ! AudioFile, broadcast can optionally record data directly from the
- ! server.
-
- ***************
- *** 221,225 ****
- For a DECStation with LoFi hardware, you need to fetch either the LoFi
- ! library by <gnn@cs.utwente.nl> or the DEC CRL AudioFile software
- ! distribution. LoFiLib is available for ftp from pegasus.cs.utwente.nl
- ! in /pub/audio/libminilofi.tar.Z. AudioFile is available for ftp from
- crl.dec.com in /pub/DEC/AF/AF2R2.tar.Z. Also get the patches from the
- --- 258,263 ----
- For a DECStation with LoFi hardware, you need to fetch either the LoFi
- ! library by George Neville-Neil <gnn@cs.utwente.nl> (based on code by
- ! DEC CRL) or the DEC CRL AudioFile software distribution. LoFiLib is
- ! available for ftp from pegasus.cs.utwente.nl in
- ! /pub/audio/libminilofi.tar.Z. AudioFile is available for ftp from
- crl.dec.com in /pub/DEC/AF/AF2R2.tar.Z. Also get the patches from the
- *** pl3/broadcast.c Fri May 7 16:29:00 1993
- --- ./broadcast.c Tue May 11 16:20:48 1993
- ***************
- *** 86,87 ****
- --- 86,92 ----
-
- + #ifdef __hpux
- + #include <sys/rtprio.h>
- + #include "audio_filehdr.h" /* borrowed from a Sun */
- + #endif
- +
- #ifdef __sgi
- ***************
- *** 170,172 ****
- sprintf(infostring, "radio:S:%s:%d:%d:%s:%ld:",
- ! name, port, transmitting, logfile, age);
- n = strlen(infostring);
- --- 175,177 ----
- sprintf(infostring, "radio:S:%s:%d:%d:%s:%ld:",
- ! name, 0xffff & port, transmitting, logfile, age);
- n = strlen(infostring);
- ***************
- *** 199,201 ****
- {
- - char *broadcastaddr = NULL;
- char real_buf[HEADERSIZE + 3 + BUFFERSIZE];
- --- 204,205 ----
- ***************
- *** 309,311 ****
-
- ! s = opensock("data", (char *)NULL, SENDPORT, (char *)NULL, 0, 1);
-
- --- 313,317 ----
-
- ! s = opensock("data", (char *)NULL, 0, (char *)NULL, 0, 1);
- ! if (s < 0)
- ! exit(1);
-
- ***************
- *** 316,318 ****
- "%s: bad broadcast address '%s'\n",
- ! progname, broadcastaddr);
- exit(2);
- --- 322,324 ----
- "%s: bad broadcast address '%s'\n",
- ! progname, DEFMCAST);
- exit(2);
- ***************
- *** 335,337 ****
- "%s: bad broadcast address '%s'\n",
- ! progname, broadcastaddr);
- exit(2);
- --- 341,343 ----
- "%s: bad broadcast address '%s'\n",
- ! progname, argv[optind]);
- exit(2);
- ***************
- *** 356,357 ****
- --- 362,365 ----
- ctls = opensock("control", (char *)NULL, ctlport, (char *)NULL, 0, 0);
- + if (ctls < 0)
- + exit(1);
-
- ***************
- *** 368,369 ****
- --- 376,381 ----
- #endif
- + #ifdef __hpux
- + Audio_filehdr hp;
- + fread((char *) &hp, sizeof(Audio_filehdr), 1, stdin);
- + #endif
- }
- ***************
- *** 372,373 ****
- --- 384,390 ----
-
- + #ifdef __hpux
- + n = rtprio(0, 50);
- + if (n == -1) perror("rtprio");
- + #endif
- +
- real_buf[0] = AUDIO_TYPE;
- ***************
- *** 514,516 ****
- strncmp(buf, "radio:s", 7) == 0) {
- ! sendinfo(ctls, &ctlsin, ctlsinsize);
- }
- --- 531,534 ----
- strncmp(buf, "radio:s", 7) == 0) {
- ! sendinfo(ctls, &ctlsin, ctlsinsize,
- ! dftport);
- }
- ***************
- *** 570,574 ****
-
- ! tsleep = ((double) bytes/(double) rate) * 1000000
- ! - ((tnow.tv_sec - tstart.tv_sec) * 1000000
- ! + tnow.tv_usec - tstart.tv_usec);
- if (tsleep > 0) {
- --- 588,592 ----
-
- ! tsleep = ((double) bytes/(double) rate
- ! - (tnow.tv_sec - tstart.tv_sec)) * 1000000
- ! + (tnow.tv_usec - tstart.tv_usec);
- if (tsleep > 0) {
- *** pl3/broadcast.man Fri May 7 16:29:00 1993
- --- ./broadcast.man Mon May 10 10:20:36 1993
- ***************
- *** 56,58 ****
- packets through.
- ! Each transmission station should run on a different host though.
- .SH OPTIONS
- --- 56,60 ----
- packets through.
- ! Multiple transmission stations may reside on the same host, but on some
- ! systems they need to have different control ports specified with the
- ! \-c option.
- .SH OPTIONS
- ***************
- *** 86,90 ****
- Note that this option only has an effect if your machine supports multicasts
- ! and you specify a multicast address with the
- ! .B \-b
- ! option.
- .TP 10
- --- 88,91 ----
- Note that this option only has an effect if your machine supports multicasts
- ! and you specify a multicast address to send to (or the default is a
- ! multicast address).
- .TP 10
- *** pl3/radio.c Fri May 7 16:29:02 1993
- --- ./radio.c Tue May 11 16:40:00 1993
- ***************
- *** 103,104 ****
- --- 103,117 ----
- #endif /* USE_SUN */
- +
- + #ifdef USE_HP
- + #include <netinet/tcp.h>
- + #include <sys/audio.h>
- +
- + int one = 1;
- + int interruptable = 1;
- + long status;
- + int external = 0;
- + FILE *astream = NULL, *wstream = NULL;
- +
- + #undef index
- + #endif /* USE_HP */
-
- ***************
- *** 172,174 ****
- int s, ctls, curs;
- ! struct sockaddr from;
- int fromlen;
- --- 185,187 ----
- int s, ctls, curs;
- ! struct sockaddr_in from;
- int fromlen;
- ***************
- *** 182,183 ****
- --- 195,197 ----
- char *remotename = (char *) NULL;
- + struct sockaddr_in remoteaddr;
- struct timeval timeout;
- ***************
- *** 185,186 ****
- --- 199,203 ----
- struct adpcm_state state;
- + #ifdef USE_HP
- + int pcnt;
- + #endif /* USE_HP */
- #ifdef USE_AL
- ***************
- *** 207,209 ****
- /* Always change these two macros and the following switch together! */
- ! #define OPTIONS "c:dfl:m:np:r:stv:"
- #define USAGE "usage: %s [options]\n\
- --- 224,226 ----
- /* Always change these two macros and the following switch together! */
- ! #define OPTIONS "c:dfl:m:np:r:stv:x"
- #define USAGE "usage: %s [options]\n\
- ***************
- *** 243,244 ****
- --- 260,267 ----
- remotename = optarg;
- + if (setipaddr(remotename, &remoteaddr) < 0) {
- + fprintf(stderr,
- + "radio: %s: bad remote name\n",
- + remotename);
- + exit(2);
- + }
- break;
- ***************
- *** 255,257 ****
- case 'n':
- ! #ifdef USE_SUN
- interruptable = 0;
- --- 278,280 ----
- case 'n':
- ! #if defined(USE_SUN) || defined(USE_HP)
- interruptable = 0;
- ***************
- *** 275,276 ****
- --- 298,305 ----
- break;
- + case 'x':
- + #if defined(USE_HP)
- + external = -1;
- + #else
- + fprintf(stderr, "(-x not supported here)\n");
- + #endif
- }
- ***************
- *** 303,306 ****
- ctls = -1;
-
- - s = opensock("data", localname, receiveport, remotename, SENDPORT, 0);
- #ifdef HAVE_MCAST
- --- 332,337 ----
- ctls = -1;
- + s = opensock("data", localname, receiveport, (char *)NULL, 0, 0);
- + if (s < 0)
- + exit(1);
-
- #ifdef HAVE_MCAST
- ***************
- *** 313,314 ****
- --- 344,348 ----
- packetcount = 0;
- + #ifdef USE_HP
- + pcnt = 0;
- + #endif
-
- ***************
- *** 321,323 ****
- FD_ZERO(&inputset);
- ! FD_SET(s, &inputset);
- if (ctls >= 0)
- --- 355,358 ----
- FD_ZERO(&inputset);
- ! if (s >= 0)
- ! FD_SET(s, &inputset);
- if (ctls >= 0)
- ***************
- *** 347,349 ****
- n = recvfrom(curs, buf, HEADERSIZE + BUFFERSIZE, 0,
- ! &from, &fromlen);
- if (n <= 0) {
- --- 382,384 ----
- n = recvfrom(curs, buf, HEADERSIZE + BUFFERSIZE, 0,
- ! (struct stockaddr *)&from, &fromlen);
- if (n <= 0) {
- ***************
- *** 369,371 ****
- if (pdebug)
- ! fprintf(stderr, "control packet\n");
- switch(buf[6]) {
- --- 404,407 ----
- if (pdebug)
- ! fprintf(stderr,
- ! "control packet: '%s'\n", buf);
- switch(buf[6]) {
- ***************
- *** 377,381 ****
- case 'S': /* Status from broadcast */
- - if (pdebug)
- - fprintf(stderr,
- - "Status %s\n", buf);
- break;
- --- 413,414 ----
- ***************
- *** 396,400 ****
- close(s);
- ! s = opensock("new data", localname,
- ! receiveport, remotename,
- ! SENDPORT, 0);
- #ifdef HAVE_MCAST
- --- 429,439 ----
- close(s);
- ! s = opensock("new data",
- ! localname, receiveport,
- ! (char *)NULL, 0, 0);
- ! /*
- ! * ignore ports that we cannot reveive
- ! * on (e.g., because of permissions).
- ! */
- ! if (s < 0)
- ! break;
- #ifdef HAVE_MCAST
- ***************
- *** 408,411 ****
- sprintf(buf, "radio:I:%d:%d:%s.%d",
- ! !pausing, receiveport,
- VERSION, PATCHLEVEL);
- sendto(curs, buf, strlen(buf), 0,
- --- 447,454 ----
- sprintf(buf, "radio:I:%d:%d:%s.%d",
- ! !pausing, 0xffff&receiveport,
- VERSION, PATCHLEVEL);
- + if (pdebug)
- + fprintf(stderr,
- + "sending info '%s'\n",
- + buf);
- sendto(curs, buf, strlen(buf), 0,
- ***************
- *** 441,443 ****
- }
- ! else if (!pausing) {
- encoding = PCM_64;
- --- 484,492 ----
- }
- ! else if (!pausing &&
- ! /*
- ! * filter out any packets we're not interested in
- ! */
- ! (!remotename ||
- ! from.sin_addr.s_addr == remoteaddr.sin_addr.s_addr))
- {
- !
- encoding = PCM_64;
- ***************
- *** 577,578 ****
- --- 626,640 ----
- #endif /* USE_AF */
- + #ifdef USE_HP
- + if (!filter) {
- + ++pcnt;
- + if (fwrite(buf, 1, n, wstream) != n) {
- + perror("fwrite wstream");
- + break;
- + }
- + if (pcnt == PCKWIN) {
- + fclose(wstream);
- + wstream = astream;
- + }
- + }
- + #endif /* USE_HP */
- if (filter || tee) {
- ***************
- *** 656,658 ****
-
- -
- #ifdef USE_SUN
- --- 718,719 ----
- ***************
- *** 725,727 ****
- --- 786,830 ----
-
- +
- #endif /* USE_SUN */
- +
- + #ifdef USE_HP
- +
- + void open_speaker()
- + {
- + struct audio_gains ag;
- + int streamSocket;
- + long gain;
- + char buf[80];
- + char *p;
- +
- + p = (external ? "/dev/audioEU" : "/dev/audioIU");
- + astream = fopen(p, "w");
- + if (astream == NULL) {
- + perror("fopen: /dev/audioIU");
- + exit(1);
- + }
- +
- + if (volume >= 0) { /* user has specified a volume... */
- + if (ioctl(fileno(astream), AUDIO_GET_GAINS, &ag) < 0)
- + perror("ioctl: AUDIO_GET_GAINS");
- +
- + ag.transmit_gain = ((volume *
- + (AUDIO_MAX_GAIN - AUDIO_OFF_GAIN))
- + / 100) + AUDIO_OFF_GAIN;
- +
- + if (ioctl(fileno(astream), AUDIO_SET_GAINS, &ag) < 0)
- + perror("ioctl: AUDIO_SET_GAINS");
- + }
- +
- + wstream = fdopen(dup(fileno(astream)), "w");
- +
- + setvbuf(astream, NULL, _IONBF, 0);
- + setvbuf(wstream, NULL, _IOFBF, BUFFERSIZE * PCKWIN);
- + }
- +
- + void close_speaker()
- + {
- + fclose(astream);
- + }
- + #endif /* USE_HP */
-
- *** pl3/radio.h Fri May 7 16:29:02 1993
- --- ./radio.h Mon May 10 21:30:44 1993
- ***************
- *** 29,31 ****
- #define RCVPORT 54321
- - #define SENDPORT 54318
- #define INFOPORT 54317
- --- 29,30 ----
- ***************
- *** 75,76 ****
- --- 74,82 ----
- #define USE_NX
- + #endif
- +
- + #ifdef __hpux
- + #define USE_HP
- + /* #define UseAAPI */ /* No good */
- + #define CHECK_X_SERVER
- + #define PCKWIN 5
- #endif
- *** pl3/radio.man Fri May 7 16:29:02 1993
- --- ./radio.man Sat May 8 23:13:39 1993
- ***************
- *** 85,89 ****
- Multicast group.
- ! This only makes sense if the same multicast group is passed to the
- ! .B \-b
- ! option of
- .IR broadcast (1).
- --- 85,87 ----
- Multicast group.
- ! This only makes sense if the same multicast group is passed as address to
- .IR broadcast (1).
- *** pl3/socklib.c Fri May 7 16:29:03 1993
- --- ./socklib.c Mon May 10 09:44:07 1993
- ***************
- *** 54,56 ****
- perror(desc);
- ! exit(1);
- }
- --- 54,56 ----
- perror(desc);
- ! return -1;
- }
- ***************
- *** 81,83 ****
- perror(desc);
- ! exit(1);
- }
- --- 81,84 ----
- perror(desc);
- ! close(s);
- ! return -1;
- }
- ***************
- *** 92,94 ****
- perror(desc);
- ! exit(1);
- }
- --- 93,96 ----
- perror(desc);
- ! close(s);
- ! return -1;
- }
- ***************
- *** 102,104 ****
- perror(desc);
- ! exit(1);
- }
- --- 104,107 ----
- perror(desc);
- ! close(s);
- ! return -1;
- }
-