liveMedia/include/RTPInterface.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2015 Live Networks, Inc.  All rights reserved.
00018 // An abstraction of a network interface used for RTP (or RTCP).
00019 // (This allows the RTP-over-TCP hack (RFC 2326, section 10.12) to
00020 // be implemented transparently.)
00021 // C++ header
00022 
00023 #ifndef _RTP_INTERFACE_HH
00024 #define _RTP_INTERFACE_HH
00025 
00026 #ifndef _MEDIA_HH
00027 #include <Media.hh>
00028 #endif
00029 #ifndef _GROUPSOCK_HH
00030 #include "Groupsock.hh"
00031 #endif
00032 
00033 // Typedef for an optional auxilliary handler function, to be called
00034 // when each new packet is read:
00035 typedef void AuxHandlerFunc(void* clientData, unsigned char* packet,
00036                             unsigned& packetSize);
00037 
00038 typedef void ServerRequestAlternativeByteHandler(void* instance, u_int8_t requestByte);
00039 // A hack that allows a handler for RTP/RTCP packets received over TCP to process RTSP commands that may also appear within
00040 // the same TCP connection.  A RTSP server implementation would supply a function like this - as a parameter to
00041 // "ServerMediaSubsession::startStream()".
00042 
00043 class tcpStreamRecord {
00044 public:
00045   tcpStreamRecord(int streamSocketNum, unsigned char streamChannelId,
00046                   tcpStreamRecord* next);
00047   virtual ~tcpStreamRecord();
00048 
00049 public:
00050   tcpStreamRecord* fNext;
00051   int fStreamSocketNum;
00052   unsigned char fStreamChannelId;
00053 };
00054 
00055 class RTPInterface {
00056 public:
00057   RTPInterface(Medium* owner, Groupsock* gs);
00058   virtual ~RTPInterface();
00059 
00060   Groupsock* gs() const { return fGS; }
00061 
00062   void setStreamSocket(int sockNum, unsigned char streamChannelId);
00063   void addStreamSocket(int sockNum, unsigned char streamChannelId);
00064   void removeStreamSocket(int sockNum, unsigned char streamChannelId);
00065   static void setServerRequestAlternativeByteHandler(UsageEnvironment& env, int socketNum,
00066                                                      ServerRequestAlternativeByteHandler* handler, void* clientData);
00067   static void clearServerRequestAlternativeByteHandler(UsageEnvironment& env, int socketNum);
00068 
00069   Boolean sendPacket(unsigned char* packet, unsigned packetSize);
00070   void startNetworkReading(TaskScheduler::BackgroundHandlerProc*
00071                            handlerProc);
00072   Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize,
00073                      // out parameters:
00074                      unsigned& bytesRead, struct sockaddr_in& fromAddress,
00075                      int& tcpSocketNum, unsigned char& tcpStreamChannelId,
00076                      Boolean& packetReadWasIncomplete);
00077   // Note: If "tcpSocketNum" < 0, then the packet was received over UDP, and "tcpStreamChannelId"
00078   //   is undefined (and irrelevant).
00079   // Otherwise (if "tcpSocketNum" >= 0), the packet was received (interleaved) over TCP, and
00080   //   "tcpStreamChannelId" will return the channel id.
00081 
00082   void stopNetworkReading();
00083 
00084   UsageEnvironment& envir() const { return fOwner->envir(); }
00085 
00086   void setAuxilliaryReadHandler(AuxHandlerFunc* handlerFunc,
00087                                 void* handlerClientData) {
00088     fAuxReadHandlerFunc = handlerFunc;
00089     fAuxReadHandlerClientData = handlerClientData;
00090   }
00091 
00092 private:
00093   // Helper functions for sending a RTP or RTCP packet over a TCP connection:
00094   Boolean sendRTPorRTCPPacketOverTCP(unsigned char* packet, unsigned packetSize,
00095                                      int socketNum, unsigned char streamChannelId);
00096   Boolean sendDataOverTCP(int socketNum, u_int8_t const* data, unsigned dataSize, Boolean forceSendToSucceed);
00097 
00098 private:
00099   friend class SocketDescriptor;
00100   Medium* fOwner;
00101   Groupsock* fGS;
00102   tcpStreamRecord* fTCPStreams; // optional, for RTP-over-TCP streaming/receiving
00103 
00104   unsigned short fNextTCPReadSize;
00105     // how much data (if any) is available to be read from the TCP stream
00106   int fNextTCPReadStreamSocketNum;
00107   unsigned char fNextTCPReadStreamChannelId;
00108   TaskScheduler::BackgroundHandlerProc* fReadHandlerProc; // if any
00109 
00110   AuxHandlerFunc* fAuxReadHandlerFunc;
00111   void* fAuxReadHandlerClientData;
00112 };
00113 
00114 #endif

Generated on Wed Dec 17 07:45:02 2014 for live by  doxygen 1.5.2