Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <>.)
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2021 Live Networks, Inc. All rights reserved.
18 // An abstraction of a network interface used for RTP (or RTCP).
19 // (This allows the RTP-over-TCP hack (RFC 2326, section 10.12) to
20 // be implemented transparently.)
21 // C++ header
23 #ifndef _RTP_INTERFACE_HH
24 #define _RTP_INTERFACE_HH
26 #ifndef _MEDIA_HH
27 #include <Media.hh>
28 #endif
29 #ifndef _GROUPSOCK_HH
30 #include "Groupsock.hh"
31 #endif
33 // Typedef for an optional auxilliary handler function, to be called
34 // when each new packet is read:
35 typedef void AuxHandlerFunc(void* clientData, unsigned char* packet,
36  unsigned& packetSize);
38 typedef void ServerRequestAlternativeByteHandler(void* instance, u_int8_t requestByte);
39 // A hack that allows a handler for RTP/RTCP packets received over TCP to process RTSP commands that may also appear within
40 // the same TCP connection. A RTSP server implementation would supply a function like this - as a parameter to
41 // "ServerMediaSubsession::startStream()".
43 class RTPInterface {
44 public:
46  virtual ~RTPInterface();
48  Groupsock* gs() const { return fGS; }
50  void setStreamSocket(int sockNum, unsigned char streamChannelId);
51  void addStreamSocket(int sockNum, unsigned char streamChannelId);
52  void removeStreamSocket(int sockNum, unsigned char streamChannelId);
54  ServerRequestAlternativeByteHandler* handler, void* clientData);
57  Boolean sendPacket(unsigned char* packet, unsigned packetSize);
59  handlerProc);
60  Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize,
61  // out parameters:
62  unsigned& bytesRead, struct sockaddr_storage& fromAddress,
63  int& tcpSocketNum, unsigned char& tcpStreamChannelId,
64  Boolean& packetReadWasIncomplete);
65  // Note: If "tcpSocketNum" < 0, then the packet was received over UDP, and "tcpStreamChannelId"
66  // is undefined (and irrelevant).
69  // Otherwise (if "tcpSocketNum" >= 0), the packet was received (interleaved) over TCP, and
70  // "tcpStreamChannelId" will return the channel id.
74  UsageEnvironment& envir() const { return fOwner->envir(); }
77  void* handlerClientData) {
78  fAuxReadHandlerFunc = handlerFunc;
79  fAuxReadHandlerClientData = handlerClientData;
80  }
82  void forgetOurGroupsock() { fGS = NULL; }
83  // This may be called - *only immediately prior* to deleting this - to prevent our destructor
84  // from turning off background reading on the 'groupsock'. (This is in case the 'groupsock'
85  // is also being read from elsewhere.)
87 private:
88  // Helper functions for sending a RTP or RTCP packet over a TCP connection:
89  Boolean sendRTPorRTCPPacketOverTCP(unsigned char* packet, unsigned packetSize,
90  int socketNum, unsigned char streamChannelId);
91  Boolean sendDataOverTCP(int socketNum, u_int8_t const* data, unsigned dataSize, Boolean forceSendToSucceed);
93 private:
94  friend class SocketDescriptor;
97  class tcpStreamRecord* fTCPStreams; // optional, for RTP-over-TCP streaming/receiving
99  unsigned short fNextTCPReadSize;
100  // how much data (if any) is available to be read from the TCP stream
107 };
109 #endif
unsigned char Boolean
Definition: Boolean.hh:25
void AuxHandlerFunc(void *clientData, unsigned char *packet, unsigned &packetSize)
Definition: RTPInterface.hh:35
void ServerRequestAlternativeByteHandler(void *instance, u_int8_t requestByte)
Definition: RTPInterface.hh:38
#define NULL
Definition: Media.hh:50
UsageEnvironment & envir() const
Definition: Media.hh:59
virtual ~RTPInterface()
void removeStreamSocket(int sockNum, unsigned char streamChannelId)
Groupsock * fGS
Definition: RTPInterface.hh:96
Groupsock * gs() const
Definition: RTPInterface.hh:48
Boolean handleRead(unsigned char *buffer, unsigned bufferMaxSize, unsigned &bytesRead, struct sockaddr_storage &fromAddress, int &tcpSocketNum, unsigned char &tcpStreamChannelId, Boolean &packetReadWasIncomplete)
AuxHandlerFunc * fAuxReadHandlerFunc
unsigned char fNextTCPReadStreamChannelId
void stopNetworkReading()
int fNextTCPReadStreamSocketNum
TaskScheduler::BackgroundHandlerProc * fReadHandlerProc
static void clearServerRequestAlternativeByteHandler(UsageEnvironment &env, int socketNum)
unsigned short fNextTCPReadSize
Definition: RTPInterface.hh:99
void setStreamSocket(int sockNum, unsigned char streamChannelId)
Boolean sendDataOverTCP(int socketNum, u_int8_t const *data, unsigned dataSize, Boolean forceSendToSucceed)
void startNetworkReading(TaskScheduler::BackgroundHandlerProc *handlerProc)
UsageEnvironment & envir() const
Definition: RTPInterface.hh:74
Medium * fOwner
Definition: RTPInterface.hh:95
void addStreamSocket(int sockNum, unsigned char streamChannelId)
void forgetOurGroupsock()
Definition: RTPInterface.hh:82
RTPInterface(Medium *owner, Groupsock *gs)
Boolean sendPacket(unsigned char *packet, unsigned packetSize)
void setAuxilliaryReadHandler(AuxHandlerFunc *handlerFunc, void *handlerClientData)
Definition: RTPInterface.hh:76
class tcpStreamRecord * fTCPStreams
Definition: RTPInterface.hh:97
friend class SocketDescriptor
Definition: RTPInterface.hh:94
Boolean sendRTPorRTCPPacketOverTCP(unsigned char *packet, unsigned packetSize, int socketNum, unsigned char streamChannelId)
static void setServerRequestAlternativeByteHandler(UsageEnvironment &env, int socketNum, ServerRequestAlternativeByteHandler *handler, void *clientData)
void * fAuxReadHandlerClientData
void BackgroundHandlerProc(void *clientData, int mask)
void * packet