00001 // 00002 // RtpReceiver.h -- a unit generator that listens on an RTP socket for incoming audio buffers. 00003 // 00004 // The server is assumed to be on a remote machine, and is a CSL program that uses a RemoteIO 00005 // port for output. 00006 // 00007 // The response packet format starts with the same header, followed by raw sample data as 00008 // non-interleaved floats, followed by the magic number as a packet footer. 00009 // 00010 // To set this up, the server must be a CSL program, and the RemoteIO object must know what port it 00011 // it listens to. The client (this RtpReceiver) needs to know the server's hostname and port. 00012 // The client first sends the server an "introduction" packet so that the server can open a 00013 // response socket. Then the client can send the server sample buffer requests. 00014 // 00015 // Note to self: The RTP receiver is triggered from a separate thread, and tries to put incoming 00016 // packets into the RingBuffer at the correct places. 00017 // 00018 00019 #ifndef CSL_RTPRECEIVER_H 00020 #define CSL_RTPRECEIVER_H 00021 00022 #include "CSL_Core.h" 00023 #include "CslRtpSession.h" 00024 #include "ThreadUtilities.h" 00025 00026 00027 00028 namespace csl { 00029 00030 // Useful macros for managing packet I/O 00031 // TODO: This should be a variable that can be adjusted or set on the constructor 00032 #define RTP_BUFFER_SIZE (4410) 00033 00034 // Default I/O port (ought to use PortMapper to pass port #s as cmd-line options) 00035 00036 #define CSL_DEFAULT_CLIENT_PORT 5004 // Default port for RTP listening (RTCP transmitted on port RTP+1) 00037 #define CSL_DEFAULT_SERVER_PORT 5006 // Default port for sending RTP packets (RTCP xmitted on port RTP+1) 00038 00039 //#define RTP_TIMING // Print out the timing code 00040 00041 // Remote commands 00042 00043 // The RTP read loop; this is spawned as a separate thread 00044 00045 extern "C" void * RTP_read_loop(void * inst); 00046 00047 // Thread utilities 00048 00049 typedef void * (*THREAD_START_ROUTINE)(void *); 00050 extern "C" int CSL_CreateThread(THREAD_START_ROUTINE pfnThreadProc, void * pvParam); 00051 00052 // 00054 // 00055 // Inherited from UnitGenerator: 00056 // frameRate, numChannels 00057 00058 class RtpReceiver : public CslRtpSession, UnitGenerator { 00059 00060 public: 00061 00063 RtpReceiver(unsigned chans = 1); 00064 ~RtpReceiver(); 00065 00067 unsigned bufferSize() { return mBufferFrames; }; 00068 unsigned remotePort() { return mRemotePort; }; 00069 00070 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (Exception); 00071 00072 void setLocalPort(unsigned localPort); 00073 void setBufferSize(unsigned bufferSize); 00074 00075 bool addRtpSource(char* remoteIP, unsigned short remotePort); 00076 bool removeRtpSource(); 00077 void printError(int rtperr); 00078 00079 00080 protected: // Internal ring buffer data 00081 bool createRtpSession(); 00082 00083 unsigned mNumChans; // The default # of channels sent over RTP 00084 SynchPthread mRtpMutex; 00085 unsigned mBufferFrames; 00086 00087 unsigned long mRemoteIP; 00088 unsigned short mRemotePort; 00089 unsigned long mLocalIP; 00090 unsigned short mLocalPort; 00091 00092 RtpBufferState mBufferState; 00093 00094 RTPUDPv4TransmissionParams * mTransparams; // We are using UDP over IPv4 00095 RTPSessionParams * mSessparams; 00096 RTPIPv4Address * mAddress; 00097 00098 unsigned mLastPacketNumber; 00099 00100 00101 00102 00103 }; 00104 00105 } 00106 00107 #endif 00108
1.4.5-20051010