JRTPLIB  3.11.2 (development version)
rtptcptransmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTPTCPTRANSMITTER_H
38 
39 #define RTPTCPTRANSMITTER_H
40 
41 #include "rtpconfig.h"
42 #include "rtptransmitter.h"
43 #include "rtpsocketutil.h"
44 #include "rtpabortdescriptors.h"
45 #include <map>
46 #include <list>
47 #include <vector>
48 
49 #ifdef RTP_SUPPORT_THREAD
50  #include <jthread/jmutex.h>
51 #endif // RTP_SUPPORT_THREAD
52 
53 namespace jrtplib
54 {
55 
57 class JRTPLIB_IMPORTEXPORT RTPTCPTransmissionParams : public RTPTransmissionParams
58 {
59 public:
61 
65  void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc) { m_pAbortDesc = desc; }
66 
70  RTPAbortDescriptors *GetCreatedAbortDescriptors() const { return m_pAbortDesc; }
71 private:
72  RTPAbortDescriptors *m_pAbortDesc;
73 };
74 
75 inline RTPTCPTransmissionParams::RTPTCPTransmissionParams() : RTPTransmissionParams(RTPTransmitter::TCPProto)
76 {
77  m_pAbortDesc = 0;
78 }
79 
81 class JRTPLIB_IMPORTEXPORT RTPTCPTransmissionInfo : public RTPTransmissionInfo
82 {
83 public:
86 };
87 
88 // TODO: this is for IPv4, and will only be valid if one rtp packet is in one tcp frame
89 #define RTPTCPTRANS_HEADERSIZE (20+20+2) // 20 IP, 20 TCP, 2 for framing (RFC 4571)
90 
112 class JRTPLIB_IMPORTEXPORT RTPTCPTransmitter : public RTPTransmitter
113 {
114  JRTPLIB_NO_COPY(RTPTCPTransmitter)
115 public:
118 
119  int Init(bool treadsafe);
120  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
121  void Destroy();
122  RTPTransmissionInfo *GetTransmissionInfo();
123  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
124 
125  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
126  bool ComesFromThisTransmitter(const RTPAddress *addr);
127  size_t GetHeaderOverhead() { return RTPTCPTRANS_HEADERSIZE; }
128 
129  int Poll();
130  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
131  int AbortWait();
132 
133  int SendRTPData(const void *data,size_t len);
134  int SendRTCPData(const void *data,size_t len);
135 
136  int AddDestination(const RTPAddress &addr);
137  int DeleteDestination(const RTPAddress &addr);
138  void ClearDestinations();
139 
140  bool SupportsMulticasting();
141  int JoinMulticastGroup(const RTPAddress &addr);
142  int LeaveMulticastGroup(const RTPAddress &addr);
143  void LeaveAllMulticastGroups();
144 
145  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
146  int AddToIgnoreList(const RTPAddress &addr);
147  int DeleteFromIgnoreList(const RTPAddress &addr);
148  void ClearIgnoreList();
149  int AddToAcceptList(const RTPAddress &addr);
150  int DeleteFromAcceptList(const RTPAddress &addr);
151  void ClearAcceptList();
152  int SetMaximumPacketSize(size_t s);
153 
154  bool NewDataAvailable();
155  RTPRawPacket *GetNextPacket();
156 #ifdef RTPDEBUG
157  void Dump();
158 #endif // RTPDEBUG
159 protected:
161  virtual void OnSendError(SocketType sock);
163  virtual void OnReceiveError(SocketType sock);
164 private:
165  class SocketData
166  {
167  public:
168  SocketData();
169  ~SocketData();
170  void Reset();
171 
172  uint8_t m_lengthBuffer[2];
173  int m_lengthBufferOffset;
174  int m_dataLength;
175  int m_dataBufferOffset;
176  uint8_t *m_pDataBuffer;
177 
178  uint8_t *ExtractDataBuffer() { uint8_t *pTmp = m_pDataBuffer; m_pDataBuffer = 0; return pTmp; }
179  int ProcessAvailableBytes(SocketType sock, int availLen, bool &complete, RTPMemoryManager *pMgr);
180  };
181 
182  int SendRTPRTCPData(const void *data,size_t len);
183  void FlushPackets();
184  int PollSocket(SocketType sock, SocketData &sdata);
185  void ClearDestSockets();
186  int ValidateSocket(SocketType s);
187 
188  bool m_init;
189  bool m_created;
190  bool m_waitingForData;
191 
192  std::map<SocketType, SocketData> m_destSockets;
193  std::vector<SocketType> m_tmpSocks;
194  std::vector<int8_t> m_tmpFlags;
195  std::vector<uint8_t> m_localHostname;
196  size_t m_maxPackSize;
197 
198  std::list<RTPRawPacket*> m_rawpacketlist;
199 
200  RTPAbortDescriptors m_abortDesc;
201  RTPAbortDescriptors *m_pAbortDesc; // in case an external one was specified
202 
203 #ifdef RTP_SUPPORT_THREAD
204  jthread::JMutex m_mainMutex, m_waitMutex;
205  bool m_threadsafe;
206 #endif // RTP_SUPPORT_THREAD
207 };
208 
209 inline void RTPTCPTransmitter::OnSendError(SocketType) { }
210 inline void RTPTCPTransmitter::OnReceiveError(SocketType) { }
211 
212 } // end namespace
213 
214 #endif // RTPTCPTRANSMITTER_H
215 
Helper class for several RTPTransmitter instances, to be able to cancel a call to 'select',...
Definition: rtpabortdescriptors.h:65
This class is an abstract class which is used to specify destinations, multicast groups etc.
Definition: rtpaddress.h:51
A memory manager.
Definition: rtpmemorymanager.h:151
This class is used by the transmission component to store the incoming RTP and RTCP data in.
Definition: rtprawpacket.h:53
Additional information about the TCP transmitter.
Definition: rtptcptransmitter.h:82
Parameters for the TCP transmitter.
Definition: rtptcptransmitter.h:58
RTPAbortDescriptors * GetCreatedAbortDescriptors() const
If non-null, this RTPAbortDescriptors instance will be used internally, which can be useful when crea...
Definition: rtptcptransmitter.h:70
void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc)
If non null, the specified abort descriptors will be used to cancel the function that's waiting for p...
Definition: rtptcptransmitter.h:65
A TCP transmission component.
Definition: rtptcptransmitter.h:113
virtual void OnReceiveError(SocketType sock)
By overriding this function you can be notified of an error when receiving from a socket.
Definition: rtptcptransmitter.h:210
virtual void OnSendError(SocketType sock)
By overriding this function you can be notified of an error when sending over a socket.
Definition: rtptcptransmitter.h:209
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:86
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:249
Base class for transmission parameters.
Definition: rtptransmitter.h:230
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:63
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:81
@ TCPProto
Specifies the internal TCP transmitter.
Definition: rtptransmitter.h:74