JRTPLIB  3.11.1
rtpexternaltransmitter.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 RTPEXTERNALTRANSMITTER_H
38 
39 #define RTPEXTERNALTRANSMITTER_H
40 
41 #include "rtpconfig.h"
42 #include "rtptransmitter.h"
43 #include "rtpabortdescriptors.h"
44 #include <list>
45 
46 #ifdef RTP_SUPPORT_THREAD
47  #include <jthread/jmutex.h>
48 #endif // RTP_SUPPORT_THREAD
49 
50 namespace jrtplib
51 {
52 
53 class RTPExternalTransmitter;
54 
63 class JRTPLIB_IMPORTEXPORT RTPExternalSender
64 {
65 public:
66  RTPExternalSender() { }
67  virtual ~RTPExternalSender() { }
68 
70  virtual bool SendRTP(const void *data, size_t len) = 0;
71 
73  virtual bool SendRTCP(const void *data, size_t len) = 0;
74 
76  virtual bool ComesFromThisSender(const RTPAddress *a) = 0;
77 };
78 
86 class JRTPLIB_IMPORTEXPORT RTPExternalPacketInjecter
87 {
88 public:
89  RTPExternalPacketInjecter(RTPExternalTransmitter *trans) { transmitter = trans; }
91 
93  void InjectRTP(const void *data, size_t len, const RTPAddress &a);
94 
96  void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
97 
99  void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
100 private:
101  RTPExternalTransmitter *transmitter;
102 };
103 
105 class JRTPLIB_IMPORTEXPORT RTPExternalTransmissionParams : public RTPTransmissionParams
106 {
107 public:
110  RTPExternalTransmissionParams(RTPExternalSender *s, int headeroverhead):RTPTransmissionParams(RTPTransmitter::ExternalProto) { sender = s; headersize = headeroverhead; }
111 
112  RTPExternalSender *GetSender() const { return sender; }
113  int GetAdditionalHeaderSize() const { return headersize; }
114 private:
115  RTPExternalSender *sender;
116  int headersize;
117 };
118 
120 class JRTPLIB_IMPORTEXPORT RTPExternalTransmissionInfo : public RTPTransmissionInfo
121 {
122 public:
124 
127  RTPExternalPacketInjecter *GetPacketInjector() const { return packetinjector; }
128 private:
129  RTPExternalPacketInjecter *packetinjector;
130 };
131 
140 class JRTPLIB_IMPORTEXPORT RTPExternalTransmitter : public RTPTransmitter
141 {
142 public:
145 
146  int Init(bool treadsafe);
147  int Create(size_t maxpacksize, const RTPTransmissionParams *transparams);
148  void Destroy();
149  RTPTransmissionInfo *GetTransmissionInfo();
150  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
151 
152  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
153  bool ComesFromThisTransmitter(const RTPAddress *addr);
154  size_t GetHeaderOverhead() { return headersize; }
155 
156  int Poll();
157  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
158  int AbortWait();
159 
160  int SendRTPData(const void *data,size_t len);
161  int SendRTCPData(const void *data,size_t len);
162 
163  int AddDestination(const RTPAddress &addr);
164  int DeleteDestination(const RTPAddress &addr);
165  void ClearDestinations();
166 
167  bool SupportsMulticasting();
168  int JoinMulticastGroup(const RTPAddress &addr);
169  int LeaveMulticastGroup(const RTPAddress &addr);
170  void LeaveAllMulticastGroups();
171 
172  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
173  int AddToIgnoreList(const RTPAddress &addr);
174  int DeleteFromIgnoreList(const RTPAddress &addr);
175  void ClearIgnoreList();
176  int AddToAcceptList(const RTPAddress &addr);
177  int DeleteFromAcceptList(const RTPAddress &addr);
178  void ClearAcceptList();
179  int SetMaximumPacketSize(size_t s);
180 
181  bool NewDataAvailable();
182  RTPRawPacket *GetNextPacket();
183 #ifdef RTPDEBUG
184  void Dump();
185 #endif // RTPDEBUG
186 
187  void InjectRTP(const void *data, size_t len, const RTPAddress &a);
188  void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
189  void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
190 private:
191  void FlushPackets();
192 
193  bool init;
194  bool created;
195  bool waitingfordata;
196  RTPExternalSender *sender;
197  RTPExternalPacketInjecter packetinjector;
198 
199  std::list<RTPRawPacket*> rawpacketlist;
200 
201  uint8_t *localhostname;
202  size_t localhostnamelength;
203 
204  size_t maxpacksize;
205  int headersize;
206 
207  RTPAbortDescriptors m_abortDesc;
208 #ifdef RTP_SUPPORT_THREAD
209  jthread::JMutex mainmutex,waitmutex;
210  int threadsafe;
211 #endif // RTP_SUPPORT_THREAD
212 };
213 
214 inline void RTPExternalPacketInjecter::InjectRTP(const void *data, size_t len, const RTPAddress &a)
215 {
216  transmitter->InjectRTP(data, len, a);
217 }
218 
219 inline void RTPExternalPacketInjecter::InjectRTCP(const void *data, size_t len, const RTPAddress &a)
220 {
221  transmitter->InjectRTCP(data, len, a);
222 }
223 
224 inline void RTPExternalPacketInjecter::InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a)
225 {
226  transmitter->InjectRTPorRTCP(data, len, a);
227 }
228 
229 } // end namespace
230 
231 #endif // RTPTCPSOCKETTRANSMITTER_H
232 
233 
A transmission component which will use user specified functions to transmit the data and which will ...
Definition: rtpexternaltransmitter.h:140
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:51
Parameters to initialize a transmitter of type RTPExternalTransmitter.
Definition: rtpexternaltransmitter.h:105
Base class for transmission parameters.
Definition: rtptransmitter.h:229
void InjectRTCP(const void *data, size_t len, const RTPAddress &a)
This function can be called to insert an RTCP packet into the transmission component.
Definition: rtpexternaltransmitter.h:219
RTPExternalPacketInjecter * GetPacketInjector() const
Tells you which RTPExternalPacketInjecter you need to use to pass RTP or RTCP data on to the transmis...
Definition: rtpexternaltransmitter.h:127
void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a)
Use this function to inject an RTP or RTCP packet and the transmitter will try to figure out which ty...
Definition: rtpexternaltransmitter.h:224
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:50
RTPExternalTransmissionParams(RTPExternalSender *s, int headeroverhead)
Using this constructor you can specify which RTPExternalSender object you&#39;ll be using and how much th...
Definition: rtpexternaltransmitter.h:110
Additional information about the external transmission component.
Definition: rtpexternaltransmitter.h:120
Interface to inject incoming RTP and RTCP packets into the library.
Definition: rtpexternaltransmitter.h:86
Base class to specify a mechanism to transmit RTP packets outside of this library.
Definition: rtpexternaltransmitter.h:63
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
Definition: rtpfaketransmitter.h:64
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:84
A memory manager.
Definition: rtpmemorymanager.h:150
Specifies the transmitter which can send packets using an external mechanism, and which can have rece...
Definition: rtptransmitter.h:75
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
void InjectRTP(const void *data, size_t len, const RTPAddress &a)
This function can be called to insert an RTP packet into the transmission component.
Definition: rtpexternaltransmitter.h:214