
Definition at line 51 of file RTPInterface.cpp.
anonymous enum [private] |
| AWAITING_DOLLAR | |
| AWAITING_STREAM_CHANNEL_ID | |
| AWAITING_SIZE1 | |
| AWAITING_SIZE2 | |
| AWAITING_PACKET_DATA |
Definition at line 77 of file RTPInterface.cpp.
00077 { AWAITING_DOLLAR, AWAITING_STREAM_CHANNEL_ID, AWAITING_SIZE1, AWAITING_SIZE2, AWAITING_PACKET_DATA } fTCPReadingState;
| SocketDescriptor::SocketDescriptor | ( | UsageEnvironment & | env, | |
| int | socketNum | |||
| ) |
Definition at line 313 of file RTPInterface.cpp.
00314 :fEnv(env), fOurSocketNum(socketNum), 00315 fSubChannelHashTable(HashTable::create(ONE_WORD_HASH_KEYS)), 00316 fServerRequestAlternativeByteHandler(NULL), fServerRequestAlternativeByteHandlerClientData(NULL), 00317 fTCPReadingState(AWAITING_DOLLAR) { 00318 }
| SocketDescriptor::~SocketDescriptor | ( | ) | [virtual] |
Definition at line 320 of file RTPInterface.cpp.
References fSubChannelHashTable.
00320 { 00321 delete fSubChannelHashTable; 00322 }
| void SocketDescriptor::registerRTPInterface | ( | unsigned char | streamChannelId, | |
| RTPInterface * | rtpInterface | |||
| ) |
Definition at line 324 of file RTPInterface.cpp.
References HashTable::Add(), fEnv, fOurSocketNum, fSubChannelHashTable, HashTable::IsEmpty(), UsageEnvironment::taskScheduler(), and tcpReadHandler().
Referenced by RTPInterface::startNetworkReading().
00325 { 00326 Boolean isFirstRegistration = fSubChannelHashTable->IsEmpty(); 00327 fSubChannelHashTable->Add((char const*)(long)streamChannelId, 00328 rtpInterface); 00329 00330 if (isFirstRegistration) { 00331 // Arrange to handle reads on this TCP socket: 00332 TaskScheduler::BackgroundHandlerProc* handler 00333 = (TaskScheduler::BackgroundHandlerProc*)&tcpReadHandler; 00334 fEnv.taskScheduler(). 00335 turnOnBackgroundReadHandling(fOurSocketNum, handler, this); 00336 } 00337 }
| RTPInterface * SocketDescriptor::lookupRTPInterface | ( | unsigned char | streamChannelId | ) |
Definition at line 340 of file RTPInterface.cpp.
References fSubChannelHashTable, and HashTable::Lookup().
Referenced by tcpReadHandler1().
00340 { 00341 char const* lookupArg = (char const*)(long)streamChannelId; 00342 return (RTPInterface*)(fSubChannelHashTable->Lookup(lookupArg)); 00343 }
| void SocketDescriptor::deregisterRTPInterface | ( | unsigned char | streamChannelId | ) |
Definition at line 346 of file RTPInterface.cpp.
References fEnv, fOurSocketNum, fSubChannelHashTable, HashTable::IsEmpty(), HashTable::Remove(), removeSocketDescription(), UsageEnvironment::taskScheduler(), and TaskScheduler::turnOffBackgroundReadHandling().
Referenced by deregisterSocket().
00346 { 00347 fSubChannelHashTable->Remove((char const*)(long)streamChannelId); 00348 00349 if (fSubChannelHashTable->IsEmpty()) { 00350 // No more interfaces are using us, so it's curtains for us now 00351 fEnv.taskScheduler().turnOffBackgroundReadHandling(fOurSocketNum); 00352 removeSocketDescription(fEnv, fOurSocketNum); 00353 delete this; 00354 } 00355 }
| void SocketDescriptor::setServerRequestAlternativeByteHandler | ( | ServerRequestAlternativeByteHandler * | handler, | |
| void * | clientData | |||
| ) | [inline] |
Definition at line 61 of file RTPInterface.cpp.
References fServerRequestAlternativeByteHandler, and fServerRequestAlternativeByteHandlerClientData.
Referenced by RTPInterface::setServerRequestAlternativeByteHandler().
00061 { 00062 fServerRequestAlternativeByteHandler = handler; 00063 fServerRequestAlternativeByteHandlerClientData = clientData; 00064 }
| void SocketDescriptor::tcpReadHandler | ( | SocketDescriptor * | , | |
| int | mask | |||
| ) | [static, private] |
Definition at line 357 of file RTPInterface.cpp.
References tcpReadHandler1().
Referenced by registerRTPInterface().
00357 { 00358 socketDescriptor->tcpReadHandler1(mask); 00359 }
| void SocketDescriptor::tcpReadHandler1 | ( | int | mask | ) | [private] |
Definition at line 361 of file RTPInterface.cpp.
References AWAITING_DOLLAR, AWAITING_PACKET_DATA, AWAITING_SIZE1, AWAITING_SIZE2, AWAITING_STREAM_CHANNEL_ID, fEnv, RTPInterface::fNextTCPReadSize, RTPInterface::fNextTCPReadStreamChannelId, RTPInterface::fNextTCPReadStreamSocketNum, fOurSocketNum, RTPInterface::fOwner, RTPInterface::fReadHandlerProc, fServerRequestAlternativeByteHandler, fServerRequestAlternativeByteHandlerClientData, fSizeByte1, fStreamChannelId, fTCPReadingState, lookupRTPInterface(), NULL, readSocket(), size, UsageEnvironment::taskScheduler(), and TaskScheduler::turnOffBackgroundReadHandling().
Referenced by tcpReadHandler().
00361 { 00362 // We expect the following data over the TCP channel: 00363 // optional RTSP command or response bytes (before the first '$' character) 00364 // a '$' character 00365 // a 1-byte channel id 00366 // a 2-byte packet size (in network byte order) 00367 // the packet data. 00368 // However, because the socket is being read asynchronously, this data might arrive in pieces. 00369 00370 u_int8_t c; 00371 struct sockaddr_in fromAddress; 00372 if (fTCPReadingState != AWAITING_PACKET_DATA) { 00373 int result = readSocket(fEnv, fOurSocketNum, &c, 1, fromAddress); 00374 if (result != 1) { // error reading TCP socket, or no more data available 00375 if (result < 0) { // error 00376 fEnv.taskScheduler().turnOffBackgroundReadHandling(fOurSocketNum); // stops further calls to us 00377 } 00378 return; 00379 } 00380 } 00381 00382 switch (fTCPReadingState) { 00383 case AWAITING_DOLLAR: { 00384 if (c == '$') { 00385 fTCPReadingState = AWAITING_STREAM_CHANNEL_ID; 00386 } else { 00387 // This character is part of a RTSP request or command, which is handled separately: 00388 if (fServerRequestAlternativeByteHandler != NULL) { 00389 (*fServerRequestAlternativeByteHandler)(fServerRequestAlternativeByteHandlerClientData, c); 00390 } 00391 } 00392 break; 00393 } 00394 case AWAITING_STREAM_CHANNEL_ID: { 00395 // The byte that we read is the stream channel id. 00396 if (lookupRTPInterface(c) != NULL) { // sanity check 00397 fStreamChannelId = c; 00398 fTCPReadingState = AWAITING_SIZE1; 00399 } else { 00400 // This wasn't a stream channel id that we expected. We're (somehow) in a strange state. Try to recover: 00401 fTCPReadingState = AWAITING_DOLLAR; 00402 } 00403 break; 00404 } 00405 case AWAITING_SIZE1: { 00406 // The byte that we read is the first (high) byte of the 16-bit RTP or RTCP packet 'size'. 00407 fSizeByte1 = c; 00408 fTCPReadingState = AWAITING_SIZE2; 00409 break; 00410 } 00411 case AWAITING_SIZE2: { 00412 // The byte that we read is the second (low) byte of the 16-bit RTP or RTCP packet 'size'. 00413 unsigned short size = (fSizeByte1<<8)|c; 00414 00415 // Record the information about the packet data that will be read next: 00416 RTPInterface* rtpInterface = lookupRTPInterface(fStreamChannelId); 00417 if (rtpInterface != NULL) { 00418 rtpInterface->fNextTCPReadSize = size; 00419 rtpInterface->fNextTCPReadStreamSocketNum = fOurSocketNum; 00420 rtpInterface->fNextTCPReadStreamChannelId = fStreamChannelId; 00421 } 00422 fTCPReadingState = AWAITING_PACKET_DATA; 00423 break; 00424 } 00425 case AWAITING_PACKET_DATA: { 00426 // Call the appropriate read handler to get the packet data from the TCP stream: 00427 RTPInterface* rtpInterface = lookupRTPInterface(fStreamChannelId); 00428 if (rtpInterface != NULL) { 00429 if (rtpInterface->fNextTCPReadSize == 0) { 00430 // We've already read all the data for this packet. 00431 fTCPReadingState = AWAITING_DOLLAR; 00432 break; 00433 } 00434 if (rtpInterface->fReadHandlerProc != NULL) { 00435 #ifdef DEBUG 00436 fprintf(stderr, "SocketDescriptor::tcpReadHandler() reading %d bytes on channel %d\n", rtpInterface->fNextTCPReadSize, rtpInterface->fNextTCPReadStreamChannelId); 00437 #endif 00438 rtpInterface->fReadHandlerProc(rtpInterface->fOwner, mask); 00439 } 00440 } 00441 return; 00442 } 00443 } 00444 }
UsageEnvironment& SocketDescriptor::fEnv [private] |
Definition at line 71 of file RTPInterface.cpp.
Referenced by deregisterRTPInterface(), registerRTPInterface(), and tcpReadHandler1().
int SocketDescriptor::fOurSocketNum [private] |
Definition at line 72 of file RTPInterface.cpp.
Referenced by deregisterRTPInterface(), registerRTPInterface(), and tcpReadHandler1().
HashTable* SocketDescriptor::fSubChannelHashTable [private] |
Definition at line 73 of file RTPInterface.cpp.
Referenced by deregisterRTPInterface(), lookupRTPInterface(), registerRTPInterface(), and ~SocketDescriptor().
ServerRequestAlternativeByteHandler* SocketDescriptor::fServerRequestAlternativeByteHandler [private] |
Definition at line 74 of file RTPInterface.cpp.
Referenced by setServerRequestAlternativeByteHandler(), and tcpReadHandler1().
void* SocketDescriptor::fServerRequestAlternativeByteHandlerClientData [private] |
Definition at line 75 of file RTPInterface.cpp.
Referenced by setServerRequestAlternativeByteHandler(), and tcpReadHandler1().
u_int8_t SocketDescriptor::fStreamChannelId [private] |
u_int8_t SocketDescriptor::fSizeByte1 [private] |
enum { ... } SocketDescriptor::fTCPReadingState [private] |
Referenced by tcpReadHandler1().
1.5.2