CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

RtpReceiver.h
Go to the documentation of this file.
1 //
2 // RtpReceiver.h -- a unit generator that listens on an RTP socket for incoming audio buffers.
3 //
4 // The server is assumed to be on a remote machine, and is a CSL program that uses a RemoteIO
5 // port for output.
6 //
7 // The response packet format starts with the same header, followed by raw sample data as
8 // non-interleaved floats, followed by the magic number as a packet footer.
9 //
10 // To set this up, the server must be a CSL program, and the RemoteIO object must know what port it
11 // it listens to. The client (this RtpReceiver) needs to know the server's hostname and port.
12 // The client first sends the server an "introduction" packet so that the server can open a
13 // response socket. Then the client can send the server sample buffer requests.
14 //
15 // Note to self: The RTP receiver is triggered from a separate thread, and tries to put incoming
16 // packets into the RingBuffer at the correct places.
17 //
18
19 #ifndef CSL_RTPRECEIVER_H
20 #define CSL_RTPRECEIVER_H
21
22 #include "CSL_Core.h"
23 #include "CslRtpSession.h"
24 #include "ThreadUtilities.h"
25
26
27
28 namespace csl {
29
30 // Useful macros for managing packet I/O
31 // TODO: This should be a variable that can be adjusted or set on the constructor
32 #define RTP_BUFFER_SIZE (4410)
33
34 // Default I/O port (ought to use PortMapper to pass port #s as cmd-line options)
35
36 #define CSL_DEFAULT_CLIENT_PORT 5004 // Default port for RTP listening (RTCP transmitted on port RTP+1)
37 #define CSL_DEFAULT_SERVER_PORT 5006 // Default port for sending RTP packets (RTCP xmitted on port RTP+1)
38
39 //#define RTP_TIMING // Print out the timing code
40
41 // Remote commands
42
43 // The RTP read loop; this is spawned as a separate thread
44
45 extern "C" void * RTP_read_loop(void * inst);
46
47 // Thread utilities
48
49 typedef void * (*THREAD_START_ROUTINE)(void *);
50 extern "C" int CSL_CreateThread(THREAD_START_ROUTINE pfnThreadProc, void * pvParam);
51
52 //
53 ////// RtpReceiver class //////
54 //
55 // Inherited from UnitGenerator:
56 // frameRate, numChannels
57
58 class RtpReceiver : public CslRtpSession, UnitGenerator {
59
60 public:
61
62 /// Default constructor initializes an RtpReceiver with default 20ms bufSize
63 RtpReceiver(unsigned chans = 1);
64 ~RtpReceiver(); ///< Class destructor
65
66 /// Accessors used by the reader thread
67 unsigned bufferSize() { return mBufferFrames; };
68 unsigned remotePort() { return mRemotePort; };
69
70 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (Exception);
71
72 void setLocalPort(unsigned localPort);
73 void setBufferSize(unsigned bufferSize);
74
75 bool addRtpSource(char* remoteIP, unsigned short remotePort);
76 bool removeRtpSource();
77 void printError(int rtperr);
78
79
80 protected: // Internal ring buffer data
81 bool createRtpSession();
82
83 unsigned mNumChans; // The default # of channels sent over RTP
84 SynchPthread mRtpMutex;
85 unsigned mBufferFrames; ///< the size of the RTP ring buffer (in FRAMES)
86
87 unsigned long mRemoteIP;
88 unsigned short mRemotePort;
89 unsigned long mLocalIP;
90 unsigned short mLocalPort;
91
92 RtpBufferState mBufferState;
93
94 RTPUDPv4TransmissionParams * mTransparams; // We are using UDP over IPv4
95 RTPSessionParams * mSessparams;
96 RTPIPv4Address * mAddress;
97
98 unsigned mLastPacketNumber; ///< The ID of the last packet received
99
100
101
102
103 };
104
105 }
106
107 #endif
108