JRTPLIB  3.11.1
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 public:
117 
118  int Init(bool treadsafe);
119  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
120  void Destroy();
121  RTPTransmissionInfo *GetTransmissionInfo();
122  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
123 
124  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
125  bool ComesFromThisTransmitter(const RTPAddress *addr);
126  size_t GetHeaderOverhead() { return RTPTCPTRANS_HEADERSIZE; }
127 
128  int Poll();
129  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
130  int AbortWait();
131 
132  int SendRTPData(const void *data,size_t len);
133  int SendRTCPData(const void *data,size_t len);
134 
135  int AddDestination(const RTPAddress &addr);
136  int DeleteDestination(const RTPAddress &addr);
137  void ClearDestinations();
138 
139  bool SupportsMulticasting();
140  int JoinMulticastGroup(const RTPAddress &addr);
141  int LeaveMulticastGroup(const RTPAddress &addr);
142  void LeaveAllMulticastGroups();
143 
144  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
145  int AddToIgnoreList(const RTPAddress &addr);
146  int DeleteFromIgnoreList(const RTPAddress &addr);
147  void ClearIgnoreList();
148  int AddToAcceptList(const RTPAddress &addr);
149  int DeleteFromAcceptList(const RTPAddress &addr);
150  void ClearAcceptList();
151  int SetMaximumPacketSize(size_t s);
152 
153  bool NewDataAvailable();
154  RTPRawPacket *GetNextPacket();
155 #ifdef RTPDEBUG
156  void Dump();
157 #endif // RTPDEBUG
158 protected:
160  virtual void OnSendError(SocketType sock);
162  virtual void OnReceiveError(SocketType sock);
163 private:
164  class SocketData
165  {
166  public:
167  SocketData();
168  ~SocketData();
169  void Reset();
170 
171  uint8_t m_lengthBuffer[2];
172  int m_lengthBufferOffset;
173  int m_dataLength;
174  int m_dataBufferOffset;
175  uint8_t *m_pDataBuffer;
176 
177  uint8_t *ExtractDataBuffer() { uint8_t *pTmp = m_pDataBuffer; m_pDataBuffer = 0; return pTmp; }
178  int ProcessAvailableBytes(SocketType sock, int availLen, bool &complete, RTPMemoryManager *pMgr);
179  };
180 
181  int SendRTPRTCPData(const void *data,size_t len);
182  void FlushPackets();
183  int PollSocket(SocketType sock, SocketData &sdata);
184  void ClearDestSockets();
185  int ValidateSocket(SocketType s);
186 
187  bool m_init;
188  bool m_created;
189  bool m_waitingForData;
190 
191  std::map<SocketType, SocketData> m_destSockets;
192  std::vector<SocketType> m_tmpSocks;
193  std::vector<int8_t> m_tmpFlags;
194  std::vector<uint8_t> m_localHostname;
195  size_t m_maxPackSize;
196 
197  std::list<RTPRawPacket*> m_rawpacketlist;
198 
199  RTPAbortDescriptors m_abortDesc;
200  RTPAbortDescriptors *m_pAbortDesc; // in case an external one was specified
201 
202 #ifdef RTP_SUPPORT_THREAD
203  jthread::JMutex m_mainMutex, m_waitMutex;
204  bool m_threadsafe;
205 #endif // RTP_SUPPORT_THREAD
206 };
207 
208 inline void RTPTCPTransmitter::OnSendError(SocketType) { }
209 inline void RTPTCPTransmitter::OnReceiveError(SocketType) { }
210 
211 } // end namespace
212 
213 #endif // RTPTCPTRANSMITTER_H
214 
virtual void OnReceiveError(SocketType sock)
By overriding this function you can be notified of an error when receiving from a socket...
Definition: rtptcptransmitter.h:209
Specifies the internal TCP transmitter.
Definition: rtptransmitter.h:74
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:51
Base class for transmission parameters.
Definition: rtptransmitter.h:229
RTPAbortDescriptors * GetCreatedAbortDescriptors() const
If non-null, this RTPAbortDescriptors instance will be used internally, which can be useful when crea...
Definition: rtptcptransmitter.h:70
A TCP transmission component.
Definition: rtptcptransmitter.h:112
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:50
void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc)
If non null, the specified abort descriptors will be used to cancel the function that&#39;s waiting for p...
Definition: rtptcptransmitter.h:65
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:62
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:80
Parameters for the TCP transmitter.
Definition: rtptcptransmitter.h:57
Definition: rtpfaketransmitter.h:64
Additional information about the TCP transmitter.
Definition: rtptcptransmitter.h:81
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:84
A memory manager.
Definition: rtpmemorymanager.h:150
virtual void OnSendError(SocketType sock)
By overriding this function you can be notified of an error when sending over a socket.
Definition: rtptcptransmitter.h:208
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:248
Helper class for several RTPTransmitter instances, to be able to cancel a call to &#39;select&#39;...
Definition: rtpabortdescriptors.h:64