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