diff -uNr lame3.58/Makefile lame3.58-rtp/Makefile --- lame3.58/Makefile Mon Dec 13 23:08:46 1999 +++ lame3.58-rtp/Makefile Mon Dec 20 13:39:29 1999 @@ -76,8 +76,9 @@ # these options were suggested with egcs-990524 # CC = egcs #egcc for Debian systems -# CC_OPTS = -O9 -fomit-frame-pointer -march=pentiumpro \ -# -ffast-math -funroll-loops + CC = egcc + CC_OPTS = -O2 -fomit-frame-pointer -march=pentiumpro \ + -fstrict-aliasing -ffast-math -funroll-loops -malign-double @@ -197,8 +198,6 @@ endif - - # 10/99 added -D__NO_MATH_INLINES to fix a bug in *all* versions of # gcc 2.8+ as of 10/99. @@ -288,3 +287,7 @@ testg: $(PGM) ./lame -h -g ../test/castanets.wav +CC_OPTS += -DRTP +c_sources += rtp.c + +lame: rtp.o diff -uNr lame3.58/doit.sh lame3.58-rtp/doit.sh --- lame3.58/doit.sh Thu Jan 1 01:00:00 1970 +++ lame3.58-rtp/doit.sh Mon Dec 20 13:39:29 1999 @@ -0,0 +1 @@ +arecord -b 16 -s 22050 -w | ./lame --rtp 224.17.23.42:5004:2 -b 56 - /dev/null diff -uNr lame3.58/lame.c lame3.58-rtp/lame.c --- lame3.58/lame.c Sun Dec 12 22:14:55 1999 +++ lame3.58-rtp/lame.c Mon Dec 20 13:39:29 1999 @@ -40,6 +40,9 @@ #include "id3tag.h" #include "get_audio.h" +#ifdef RTP +#include "rtp.h" +#endif /* Global flags. defined extern in globalflags.h */ @@ -73,6 +76,11 @@ int VBR_max_bitrate; /* 256kbs */ int voice_mode; +#ifdef RTP +struct rtpheader RTPheader; +struct sockaddr_in rtpsi; +int rtpsocket=-1; +#endif /* Global variable definitions for "musicin.c" */ @@ -169,6 +177,9 @@ #ifdef HAVEGTK fprintf(stderr," -g run graphical analysis on \n"); #endif +#ifdef RTP + fprintf(stderr," --rtp ip:port:ttl send MPEG stream via RTP\n"); +#endif display_bitrates(2); exit(1); } @@ -291,6 +302,37 @@ #endif } #ifndef _BLADEDLL +#ifdef RTP + else if (strcmp(token, "rtp")==0) { + char *tmp=strchr(nextArg,':'); + int port,ttl; + if (!tmp) { + fprintf(stderr,"usage: lame --rtp ip:port:ttl\n"); + exit(1); + } + *tmp++=0; + port=atoi(tmp); + if (port<=0) { + fprintf(stderr,"usage: lame --rtp ip:port:ttl\n"); + exit(1); + } + tmp=strchr(tmp,':'); + if (!tmp) { + fprintf(stderr,"usage: lame --rtp ip:port:ttl\n"); + exit(1); + } + *tmp++=0; + ttl=atoi(tmp); + if (tmp<=0) { + fprintf(stderr,"usage: lame --rtp ip:port:ttl\n"); + exit(1); + } + rtpsocket=makesocket(nextArg,port,ttl,&rtpsi); + srand(getpid() ^ time(0)); + initrtp(&RTPheader); + argUsed=1; + } +#endif /* options for ID3 tag */ else if (strcmp(token, "tt")==0) { id3tag.used=1; argUsed = 1; @@ -1160,6 +1202,12 @@ } #ifndef _BLADEDLL +#ifdef RTP + if (rtpsocket>0) { + write_buffer(&bs); + empty_buffer(&bs); + } +#endif /********************** status display *****************************/ if (!gtkflag && !silent) { int mod = info->version == 0 ? 100 : 20; diff -uNr lame3.58/rtp.c lame3.58-rtp/rtp.c --- lame3.58/rtp.c Thu Jan 1 01:00:00 1970 +++ lame3.58-rtp/rtp.c Mon Dec 20 15:09:50 1999 @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rtpbits { + int sequence:16; /* sequence number: random */ + int pt:7; /* payload type: 14 for MPEG audio */ + int m:1; /* marker: 0 */ + int cc:4; /* number of CSRC identifiers: 0 */ + int x:1; /* number of extension headers: 0 */ + int p:1; /* is there padding appended: 0 */ + int v:2; /* version: 2 */ +}; + +struct rtpheader { /* in network byte order */ + struct rtpbits b; + int timestamp; /* start: random */ + int ssrc; /* random */ + int iAudioHeader; /* =0?! */ +}; + +void initrtp(struct rtpheader *foo) { + foo->b.v=2; + foo->b.p=0; + foo->b.x=0; + foo->b.cc=0; + foo->b.m=0; + foo->b.pt=14; /* MPEG Audio */ +#ifdef FEFE + foo->b.sequence=42; + foo->timestamp=0; +#else + foo->b.sequence=rand() & 65535; + foo->timestamp=rand(); +#endif + foo->ssrc=rand(); + foo->iAudioHeader=0; +} + +int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, void *data, int len) { + char *buf=alloca(len+sizeof(struct rtpheader)); + int *cast=(int *)foo; + int *outcast=(int *)buf; + outcast[0]=htonl(cast[0]); + outcast[1]=htonl(cast[1]); + outcast[2]=htonl(cast[2]); + outcast[3]=htonl(cast[3]); + memmove(buf+sizeof(struct rtpheader),data,len); + return sendto(fd,buf,len+sizeof(*foo),0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr)); +/* return write(fd,buf,len+sizeof(*foo))==len+sizeof(*foo); */ +} + +int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) { + int iRet, iLoop = 1; + struct sockaddr_in sin; + char cTtl = (char)TTL; + char cLoop=0; + + int iSocket = socket( AF_INET, SOCK_DGRAM, 0 ); + if (iSocket < 0) { + fprintf(stderr,"socket() failed.\n"); + exit(1); + } + + sSockAddr->sin_family = sin.sin_family = AF_INET; + sSockAddr->sin_port = sin.sin_port = htons(port); + sSockAddr->sin_addr.s_addr = inet_addr(szAddr); + + iRet = setsockopt(iSocket, SOL_SOCKET, SO_REUSEADDR, &iLoop, sizeof(int)); + if (iRet < 0) { + fprintf(stderr,"setsockopt SO_REUSEADDR failed\n"); + exit(1); + } + + iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_TTL, &cTtl, sizeof(char)); + if (iRet < 0) { + fprintf(stderr,"setsockopt IP_MULTICAST_TTL failed. multicast in kernel?\n"); + exit(1); + } + + cLoop = 1; /* !? */ + iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_LOOP, + &cLoop, sizeof(char)); + if (iRet < 0) { + fprintf(stderr,"setsockopt IP_MULTICAST_LOOP failed. multicast in kernel?\n"); + exit(1); + } + + return iSocket; +} diff -uNr lame3.58/rtp.h lame3.58-rtp/rtp.h --- lame3.58/rtp.h Thu Jan 1 01:00:00 1970 +++ lame3.58-rtp/rtp.h Mon Dec 20 15:08:50 1999 @@ -0,0 +1,23 @@ +#include +#include + +struct rtpbits { + int sequence:16; /* sequence number: random */ + int pt:7; /* payload type: 14 for MPEG audio */ + int m:1; /* marker: 0 */ + int cc:4; /* number of CSRC identifiers: 0 */ + int x:1; /* number of extension headers: 0 */ + int p:1; /* is there padding appended: 0 */ + int v:2; /* version: 2 */ +}; + +struct rtpheader { /* in network byte order */ + struct rtpbits b; + int timestamp; /* start: random */ + int ssrc; /* random */ +}; + +void initrtp(struct rtpheader *foo); +int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, void *data, int len); +int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr); + diff -uNr lame3.58/util.c lame3.58-rtp/util.c --- lame3.58/util.c Fri Dec 10 02:57:32 1999 +++ lame3.58-rtp/util.c Mon Dec 20 13:39:29 1999 @@ -2,6 +2,14 @@ #include "globalflags.h" #include +#ifdef RTP +#include "rtp.h" + +extern struct rtpheader RTPheader; +extern struct sockaddr_in rtpsi; +extern int rtpsocket; +#endif + /*********************************************************************** * * Global Variable Definitions @@ -289,6 +297,11 @@ fprintf(stderr,"error en fwrite()\n"); exit(1); } +#ifdef RTP + sendrtp(rtpsocket,&rtpsi,&RTPheader,tmpbuf,bs->buf_size-minimum); + RTPheader.timestamp+=5; + RTPheader.b.sequence++; +#endif free(tmpbuf); }