SocketDescriptor Class Reference

Collaboration diagram for SocketDescriptor:

Collaboration graph
[legend]

Public Member Functions

 SocketDescriptor (UsageEnvironment &env, int socketNum)
virtual ~SocketDescriptor ()
void registerRTPInterface (unsigned char streamChannelId, RTPInterface *rtpInterface)
RTPInterfacelookupRTPInterface (unsigned char streamChannelId)
void deregisterRTPInterface (unsigned char streamChannelId)

Static Private Member Functions

static void tcpReadHandler (SocketDescriptor *, int mask)

Private Attributes

UsageEnvironmentfEnv
int fOurSocketNum
HashTablefSubChannelHashTable

Detailed Description

Definition at line 49 of file RTPInterface.cpp.


Constructor & Destructor Documentation

SocketDescriptor::SocketDescriptor ( UsageEnvironment env,
int  socketNum 
)

Definition at line 278 of file RTPInterface.cpp.

SocketDescriptor::~SocketDescriptor (  )  [virtual]

Definition at line 283 of file RTPInterface.cpp.

References fSubChannelHashTable.

00283                                     {
00284   delete fSubChannelHashTable;
00285 }


Member Function Documentation

void SocketDescriptor::registerRTPInterface ( unsigned char  streamChannelId,
RTPInterface rtpInterface 
)

Definition at line 287 of file RTPInterface.cpp.

References HashTable::Add(), fEnv, fOurSocketNum, fSubChannelHashTable, HashTable::IsEmpty(), UsageEnvironment::taskScheduler(), and tcpReadHandler().

00288                                                                         {
00289   Boolean isFirstRegistration = fSubChannelHashTable->IsEmpty();
00290   fSubChannelHashTable->Add((char const*)(long)streamChannelId,
00291                             rtpInterface);
00292 
00293   if (isFirstRegistration) {
00294     // Arrange to handle reads on this TCP socket:
00295     TaskScheduler::BackgroundHandlerProc* handler
00296       = (TaskScheduler::BackgroundHandlerProc*)&tcpReadHandler;
00297     fEnv.taskScheduler().
00298       turnOnBackgroundReadHandling(fOurSocketNum, handler, this);
00299   }
00300 }

RTPInterface * SocketDescriptor::lookupRTPInterface ( unsigned char  streamChannelId  ) 

Definition at line 303 of file RTPInterface.cpp.

References fSubChannelHashTable, and HashTable::Lookup().

Referenced by tcpReadHandler().

00303                                                   {
00304   char const* lookupArg = (char const*)(long)streamChannelId;
00305   return (RTPInterface*)(fSubChannelHashTable->Lookup(lookupArg));
00306 }

void SocketDescriptor::deregisterRTPInterface ( unsigned char  streamChannelId  ) 

Definition at line 309 of file RTPInterface.cpp.

References fEnv, fOurSocketNum, fSubChannelHashTable, HashTable::IsEmpty(), HashTable::Remove(), removeSocketDescription(), UsageEnvironment::taskScheduler(), and TaskScheduler::turnOffBackgroundReadHandling().

00309                                                       {
00310   fSubChannelHashTable->Remove((char const*)(long)streamChannelId);
00311 
00312   if (fSubChannelHashTable->IsEmpty()) {
00313     // No more interfaces are using us, so it's curtains for us now
00314     fEnv.taskScheduler().turnOffBackgroundReadHandling(fOurSocketNum);
00315     removeSocketDescription(fEnv, fOurSocketNum);
00316     delete this;
00317   }
00318 }

void SocketDescriptor::tcpReadHandler ( SocketDescriptor ,
int  mask 
) [static, private]

Definition at line 320 of file RTPInterface.cpp.

References env, fEnv, RTPInterface::fNextTCPReadSize, RTPInterface::fNextTCPReadStreamChannelId, RTPInterface::fNextTCPReadStreamSocketNum, fOurSocketNum, RTPInterface::fOwner, RTPInterface::fReadHandlerProc, lookupRTPInterface(), NULL, readSocket(), readSocketExact(), size, UsageEnvironment::taskScheduler(), and TaskScheduler::turnOffBackgroundReadHandling().

Referenced by registerRTPInterface().

00321                                                 {
00322   do {
00323     UsageEnvironment& env = socketDescriptor->fEnv; // abbrev
00324     int socketNum = socketDescriptor->fOurSocketNum;
00325 
00326     // Begin by reading and discarding any characters that aren't '$'.
00327     // Any such characters are probably regular RTSP responses or
00328     // commands from the server.  At present, we can't do anything with
00329     // these, because we have taken complete control of reading this socket.
00330     // (Later, fix) #####
00331     unsigned char c;
00332     struct sockaddr_in fromAddress;
00333     struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0;
00334     do {
00335       int result = readSocket(env, socketNum, &c, 1, fromAddress, &timeout);
00336       if (result != 1) { // error reading TCP socket
00337         if (result < 0) {
00338           env.taskScheduler().turnOffBackgroundReadHandling(socketNum); // stops further calls to us
00339         }
00340         return;
00341       }
00342     } while (c != '$');
00343 
00344     // The next byte is the stream channel id:
00345     unsigned char streamChannelId;
00346     if (readSocket(env, socketNum, &streamChannelId, 1, fromAddress)
00347         != 1) break;
00348     RTPInterface* rtpInterface
00349       = socketDescriptor->lookupRTPInterface(streamChannelId);
00350     if (rtpInterface == NULL) break; // we're not interested in this channel
00351 
00352     // The next two bytes are the RTP or RTCP packet size (in network order)
00353     unsigned short size;
00354     if (readSocketExact(env, socketNum, (unsigned char*)&size, 2,
00355                         fromAddress) != 2) break;
00356     rtpInterface->fNextTCPReadSize = ntohs(size);
00357     rtpInterface->fNextTCPReadStreamSocketNum = socketNum;
00358     rtpInterface->fNextTCPReadStreamChannelId = streamChannelId;
00359 #ifdef DEBUG
00360     fprintf(stderr, "SocketDescriptor::tcpReadHandler() reading %d bytes on channel %d\n", rtpInterface->fNextTCPReadSize, streamChannelId);
00361 #endif
00362 
00363     // Now that we have the data set up, call this subchannel's
00364     // read handler:
00365     if (rtpInterface->fReadHandlerProc != NULL) {
00366       rtpInterface->fReadHandlerProc(rtpInterface->fOwner, mask);
00367     }
00368 
00369   } while (0);
00370 }


Field Documentation

UsageEnvironment& SocketDescriptor::fEnv [private]

Definition at line 63 of file RTPInterface.cpp.

Referenced by deregisterRTPInterface(), registerRTPInterface(), and tcpReadHandler().

int SocketDescriptor::fOurSocketNum [private]

Definition at line 64 of file RTPInterface.cpp.

Referenced by deregisterRTPInterface(), registerRTPInterface(), and tcpReadHandler().

HashTable* SocketDescriptor::fSubChannelHashTable [private]

Definition at line 65 of file RTPInterface.cpp.

Referenced by deregisterRTPInterface(), lookupRTPInterface(), registerRTPInterface(), and ~SocketDescriptor().


The documentation for this class was generated from the following file:
Generated on Tue Oct 7 15:40:11 2008 for live by  doxygen 1.5.2