#include <RTPInterface.hh>
Collaboration diagram for RTPInterface:

Public Member Functions | |
| RTPInterface (Medium *owner, Groupsock *gs) | |
| virtual | ~RTPInterface () |
| Groupsock * | gs () const |
| void | setStreamSocket (int sockNum, unsigned char streamChannelId) |
| void | addStreamSocket (int sockNum, unsigned char streamChannelId) |
| void | removeStreamSocket (int sockNum, unsigned char streamChannelId) |
| void | sendPacket (unsigned char *packet, unsigned packetSize) |
| void | startNetworkReading (TaskScheduler::BackgroundHandlerProc *handlerProc) |
| Boolean | handleRead (unsigned char *buffer, unsigned bufferMaxSize, unsigned &bytesRead, struct sockaddr_in &fromAddress) |
| void | stopNetworkReading () |
| UsageEnvironment & | envir () const |
| void | setAuxilliaryReadHandler (AuxHandlerFunc *handlerFunc, void *handlerClientData) |
| int | nextTCPReadStreamSocketNum () const |
| unsigned char | nextTCPReadStreamChannelId () const |
Private Attributes | |
| Medium * | fOwner |
| Groupsock * | fGS |
| tcpStreamRecord * | fTCPStreams |
| unsigned short | fNextTCPReadSize |
| int | fNextTCPReadStreamSocketNum |
| unsigned char | fNextTCPReadStreamChannelId |
| TaskScheduler::BackgroundHandlerProc * | fReadHandlerProc |
| AuxHandlerFunc * | fAuxReadHandlerFunc |
| void * | fAuxReadHandlerClientData |
Friends | |
| class | SocketDescriptor |
Definition at line 50 of file RTPInterface.hh.
Definition at line 91 of file RTPInterface.cpp.
References envir(), fGS, increaseSendBufferTo(), makeSocketNonBlocking(), and Socket::socketNum().
00092 : fOwner(owner), fGS(gs), 00093 fTCPStreams(NULL), 00094 fNextTCPReadSize(0), fNextTCPReadStreamSocketNum(-1), 00095 fNextTCPReadStreamChannelId(0xFF), fReadHandlerProc(NULL), 00096 fAuxReadHandlerFunc(NULL), fAuxReadHandlerClientData(NULL) { 00097 // Make the socket non-blocking, even though it will be read from only asynchronously, when packets arrive. 00098 // The reason for this is that, in some OSs, reads on a blocking socket can (allegedly) sometimes block, 00099 // even if the socket was previously reported (e.g., by "select()") as having data available. 00100 // (This can supposedly happen if the UDP checksum fails, for example.) 00101 makeSocketNonBlocking(fGS->socketNum()); 00102 increaseSendBufferTo(envir(), fGS->socketNum(), 50*1024); 00103 }
| RTPInterface::~RTPInterface | ( | ) | [virtual] |
Definition at line 105 of file RTPInterface.cpp.
References fTCPStreams.
00105 { 00106 delete fTCPStreams; 00107 }
| Groupsock* RTPInterface::gs | ( | ) | const [inline] |
Definition at line 55 of file RTPInterface.hh.
References fGS.
Referenced by RTPSink::groupsockBeingUsed(), RTCPInstance::RTCPgs(), and RTPSource::RTPgs().
00055 { return fGS; }
| void RTPInterface::setStreamSocket | ( | int | sockNum, | |
| unsigned char | streamChannelId | |||
| ) |
Definition at line 111 of file RTPInterface.cpp.
References addStreamSocket(), fGS, and Groupsock::removeAllDestinations().
Referenced by RTCPInstance::addStreamSocket(), RTCPInstance::setStreamSocket(), RTPSource::setStreamSocket(), and RTPSink::setStreamSocket().
00112 { 00113 fGS->removeAllDestinations(); 00114 addStreamSocket(sockNum, streamChannelId); 00115 }
| void RTPInterface::addStreamSocket | ( | int | sockNum, | |
| unsigned char | streamChannelId | |||
| ) |
Definition at line 117 of file RTPInterface.cpp.
References fTCPStreams, NULL, RTPOverTCP_OK, and True.
Referenced by RTPSink::addStreamSocket(), and setStreamSocket().
00118 { 00119 if (sockNum < 0) return; 00120 else RTPOverTCP_OK = True; //##### HACK 00121 00122 for (tcpStreamRecord* streams = fTCPStreams; streams != NULL; 00123 streams = streams->fNext) { 00124 if (streams->fStreamSocketNum == sockNum 00125 && streams->fStreamChannelId == streamChannelId) { 00126 return; // we already have it 00127 } 00128 } 00129 00130 fTCPStreams = new tcpStreamRecord(sockNum, streamChannelId, fTCPStreams); 00131 }
| void RTPInterface::removeStreamSocket | ( | int | sockNum, | |
| unsigned char | streamChannelId | |||
| ) |
Definition at line 133 of file RTPInterface.cpp.
References fTCPStreams, and NULL.
Referenced by RTPSink::removeStreamSocket(), and RTCPInstance::removeStreamSocket().
00134 { 00135 for (tcpStreamRecord** streamsPtr = &fTCPStreams; *streamsPtr != NULL; 00136 streamsPtr = &((*streamsPtr)->fNext)) { 00137 if ((*streamsPtr)->fStreamSocketNum == sockNum 00138 && (*streamsPtr)->fStreamChannelId == streamChannelId) { 00139 // Remove the record pointed to by *streamsPtr : 00140 tcpStreamRecord* next = (*streamsPtr)->fNext; 00141 (*streamsPtr)->fNext = NULL; 00142 delete (*streamsPtr); 00143 *streamsPtr = next; 00144 return; 00145 } 00146 } 00147 }
| void RTPInterface::sendPacket | ( | unsigned char * | packet, | |
| unsigned | packetSize | |||
| ) |
Definition at line 149 of file RTPInterface.cpp.
References envir(), fGS, fTCPStreams, NULL, Groupsock::output(), sendRTPOverTCP(), and Groupsock::ttl().
Referenced by RTCPInstance::incomingReportHandler1(), RTCPInstance::sendBuiltPacket(), and MultiFramedRTPSink::sendPacketIfNecessary().
00149 { 00150 // Normal case: Send as a UDP packet: 00151 fGS->output(envir(), fGS->ttl(), packet, packetSize); 00152 00153 // Also, send over each of our TCP sockets: 00154 for (tcpStreamRecord* streams = fTCPStreams; streams != NULL; 00155 streams = streams->fNext) { 00156 sendRTPOverTCP(packet, packetSize, 00157 streams->fStreamSocketNum, streams->fStreamChannelId); 00158 } 00159 }
| void RTPInterface::startNetworkReading | ( | TaskScheduler::BackgroundHandlerProc * | handlerProc | ) |
Definition at line 162 of file RTPInterface.cpp.
References envir(), fGS, fOwner, fReadHandlerProc, fTCPStreams, if(), lookupSocketDescriptor(), NULL, SocketDescriptor, socketHashTable(), Socket::socketNum(), and UsageEnvironment::taskScheduler().
Referenced by RTCPInstance::addStreamSocket(), MultiFramedRTPSource::doGetNextFrame(), RTCPInstance::RTCPInstance(), and RTCPInstance::setStreamSocket().
00162 { 00163 // Normal case: Arrange to read UDP packets: 00164 envir().taskScheduler(). 00165 turnOnBackgroundReadHandling(fGS->socketNum(), handlerProc, fOwner); 00166 00167 // Also, receive RTP over TCP, on each of our TCP connections: 00168 fReadHandlerProc = handlerProc; 00169 for (tcpStreamRecord* streams = fTCPStreams; streams != NULL; 00170 streams = streams->fNext) { 00171 // Get a socket descriptor for "streams->fStreamSocketNum": 00172 SocketDescriptor* socketDescriptor 00173 = lookupSocketDescriptor(envir(), streams->fStreamSocketNum); 00174 if (socketDescriptor == NULL) { 00175 socketDescriptor 00176 = new SocketDescriptor(envir(), streams->fStreamSocketNum); 00177 socketHashTable(envir())->Add((char const*)(long)(streams->fStreamSocketNum), 00178 socketDescriptor); 00179 } 00180 00181 // Tell it about our subChannel: 00182 socketDescriptor->registerRTPInterface(streams->fStreamChannelId, this); 00183 } 00184 }
| Boolean RTPInterface::handleRead | ( | unsigned char * | buffer, | |
| unsigned | bufferMaxSize, | |||
| unsigned & | bytesRead, | |||
| struct sockaddr_in & | fromAddress | |||
| ) |
Definition at line 186 of file RTPInterface.cpp.
References envir(), False, fAuxReadHandlerClientData, fAuxReadHandlerFunc, fGS, fNextTCPReadSize, fNextTCPReadStreamSocketNum, Groupsock::handleRead(), NULL, readSocket(), RTPOverTCP_OK, and True.
Referenced by BufferedPacket::fillInData(), and RTCPInstance::incomingReportHandler1().
00189 { 00190 Boolean readSuccess; 00191 if (fNextTCPReadStreamSocketNum < 0) { 00192 // Normal case: read from the (datagram) 'groupsock': 00193 readSuccess = fGS->handleRead(buffer, bufferMaxSize, bytesRead, fromAddress); 00194 } else { 00195 // Read from the TCP connection: 00196 bytesRead = 0; 00197 unsigned totBytesToRead = fNextTCPReadSize; 00198 if (totBytesToRead > bufferMaxSize) totBytesToRead = bufferMaxSize; 00199 unsigned curBytesToRead = totBytesToRead; 00200 int curBytesRead; 00201 while ((curBytesRead = readSocket(envir(), fNextTCPReadStreamSocketNum, 00202 &buffer[bytesRead], curBytesToRead, 00203 fromAddress)) > 0) { 00204 bytesRead += curBytesRead; 00205 if (bytesRead >= totBytesToRead) break; 00206 curBytesToRead -= curBytesRead; 00207 } 00208 if (curBytesRead <= 0) { 00209 bytesRead = 0; 00210 readSuccess = False; 00211 RTPOverTCP_OK = False; // HACK ##### 00212 } else { 00213 readSuccess = True; 00214 } 00215 fNextTCPReadStreamSocketNum = -1; // default, for next time 00216 } 00217 00218 if (readSuccess && fAuxReadHandlerFunc != NULL) { 00219 // Also pass the newly-read packet data to our auxilliary handler: 00220 (*fAuxReadHandlerFunc)(fAuxReadHandlerClientData, buffer, bytesRead); 00221 } 00222 return readSuccess; 00223 }
| void RTPInterface::stopNetworkReading | ( | ) |
Definition at line 225 of file RTPInterface.cpp.
References envir(), fGS, fTCPStreams, if(), lookupSocketDescriptor(), NULL, Socket::socketNum(), UsageEnvironment::taskScheduler(), and TaskScheduler::turnOffBackgroundReadHandling().
Referenced by RTCPInstance::addStreamSocket(), MultiFramedRTPSource::doStopGettingFrames(), RTCPInstance::setStreamSocket(), MultiFramedRTPSource::~MultiFramedRTPSource(), and RTCPInstance::~RTCPInstance().
00225 { 00226 // Normal case 00227 envir().taskScheduler().turnOffBackgroundReadHandling(fGS->socketNum()); 00228 00229 // Also turn off read handling on each of our TCP connections: 00230 for (tcpStreamRecord* streams = fTCPStreams; streams != NULL; 00231 streams = streams->fNext) { 00232 SocketDescriptor* socketDescriptor 00233 = lookupSocketDescriptor(envir(), streams->fStreamSocketNum); 00234 if (socketDescriptor != NULL) { 00235 socketDescriptor->deregisterRTPInterface(streams->fStreamChannelId); 00236 // Note: This may delete "socketDescriptor", 00237 // if no more interfaces are using this socket 00238 } 00239 } 00240 }
| UsageEnvironment& RTPInterface::envir | ( | ) | const [inline] |
Definition at line 69 of file RTPInterface.hh.
References Medium::envir(), and fOwner.
Referenced by handleRead(), RTPInterface(), sendPacket(), startNetworkReading(), and stopNetworkReading().
| void RTPInterface::setAuxilliaryReadHandler | ( | AuxHandlerFunc * | handlerFunc, | |
| void * | handlerClientData | |||
| ) | [inline] |
Definition at line 71 of file RTPInterface.hh.
References fAuxReadHandlerClientData, and fAuxReadHandlerFunc.
Referenced by RTPSource::setAuxilliaryReadHandler(), and RTCPInstance::setAuxilliaryReadHandler().
00072 { 00073 fAuxReadHandlerFunc = handlerFunc; 00074 fAuxReadHandlerClientData = handlerClientData; 00075 }
| int RTPInterface::nextTCPReadStreamSocketNum | ( | ) | const [inline] |
Definition at line 78 of file RTPInterface.hh.
References fNextTCPReadStreamSocketNum.
Referenced by RTCPInstance::incomingReportHandler1().
00078 { return fNextTCPReadStreamSocketNum; }
| unsigned char RTPInterface::nextTCPReadStreamChannelId | ( | ) | const [inline] |
Definition at line 79 of file RTPInterface.hh.
References fNextTCPReadStreamChannelId.
Referenced by RTCPInstance::incomingReportHandler1().
00079 { return fNextTCPReadStreamChannelId; }
friend class SocketDescriptor [friend] |
Medium* RTPInterface::fOwner [private] |
Definition at line 83 of file RTPInterface.hh.
Referenced by envir(), startNetworkReading(), and SocketDescriptor::tcpReadHandler().
Groupsock* RTPInterface::fGS [private] |
Definition at line 84 of file RTPInterface.hh.
Referenced by gs(), handleRead(), RTPInterface(), sendPacket(), setStreamSocket(), startNetworkReading(), and stopNetworkReading().
tcpStreamRecord* RTPInterface::fTCPStreams [private] |
Definition at line 85 of file RTPInterface.hh.
Referenced by addStreamSocket(), removeStreamSocket(), sendPacket(), startNetworkReading(), stopNetworkReading(), and ~RTPInterface().
unsigned short RTPInterface::fNextTCPReadSize [private] |
Definition at line 87 of file RTPInterface.hh.
Referenced by handleRead(), and SocketDescriptor::tcpReadHandler().
int RTPInterface::fNextTCPReadStreamSocketNum [private] |
Definition at line 89 of file RTPInterface.hh.
Referenced by handleRead(), nextTCPReadStreamSocketNum(), and SocketDescriptor::tcpReadHandler().
unsigned char RTPInterface::fNextTCPReadStreamChannelId [private] |
Definition at line 90 of file RTPInterface.hh.
Referenced by nextTCPReadStreamChannelId(), and SocketDescriptor::tcpReadHandler().
Definition at line 91 of file RTPInterface.hh.
Referenced by startNetworkReading(), and SocketDescriptor::tcpReadHandler().
AuxHandlerFunc* RTPInterface::fAuxReadHandlerFunc [private] |
Definition at line 93 of file RTPInterface.hh.
Referenced by handleRead(), and setAuxilliaryReadHandler().
void* RTPInterface::fAuxReadHandlerClientData [private] |
Definition at line 94 of file RTPInterface.hh.
Referenced by handleRead(), and setAuxilliaryReadHandler().
1.5.2