JRTPLIB  3.11.2 (development version)
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  JRTPLIB_NO_COPY(RTPExternalTransmitter)
143 public:
146 
147  int Init(bool treadsafe);
148  int Create(size_t maxpacksize, const RTPTransmissionParams *transparams);
149  void Destroy();
150  RTPTransmissionInfo *GetTransmissionInfo();
151  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
152 
153  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
154  bool ComesFromThisTransmitter(const RTPAddress *addr);
155  size_t GetHeaderOverhead() { return headersize; }
156 
157  int Poll();
158  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
159  int AbortWait();
160 
161  int SendRTPData(const void *data,size_t len);
162  int SendRTCPData(const void *data,size_t len);
163 
164  int AddDestination(const RTPAddress &addr);
165  int DeleteDestination(const RTPAddress &addr);
166  void ClearDestinations();
167 
168  bool SupportsMulticasting();
169  int JoinMulticastGroup(const RTPAddress &addr);
170  int LeaveMulticastGroup(const RTPAddress &addr);
171  void LeaveAllMulticastGroups();
172 
173  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
174  int AddToIgnoreList(const RTPAddress &addr);
175  int DeleteFromIgnoreList(const RTPAddress &addr);
176  void ClearIgnoreList();
177  int AddToAcceptList(const RTPAddress &addr);
178  int DeleteFromAcceptList(const RTPAddress &addr);
179  void ClearAcceptList();
180  int SetMaximumPacketSize(size_t s);
181 
182  bool NewDataAvailable();
183  RTPRawPacket *GetNextPacket();
184 #ifdef RTPDEBUG
185  void Dump();
186 #endif // RTPDEBUG
187 
188  void InjectRTP(const void *data, size_t len, const RTPAddress &a);
189  void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
190  void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
191 private:
192  void FlushPackets();
193 
194  bool init;
195  bool created;
196  bool waitingfordata;
197  RTPExternalSender *sender;
198  RTPExternalPacketInjecter packetinjector;
199 
200  std::list<RTPRawPacket*> rawpacketlist;
201 
202  uint8_t *localhostname;
203  size_t localhostnamelength;
204 
205  size_t maxpacksize;
206  int headersize;
207 
208  RTPAbortDescriptors m_abortDesc;
209  int m_abortCount;
210 #ifdef RTP_SUPPORT_THREAD
211  jthread::JMutex mainmutex,waitmutex;
212  int threadsafe;
213 #endif // RTP_SUPPORT_THREAD
214 };
215 
216 inline void RTPExternalPacketInjecter::InjectRTP(const void *data, size_t len, const RTPAddress &a)
217 {
218  transmitter->InjectRTP(data, len, a);
219 }
220 
221 inline void RTPExternalPacketInjecter::InjectRTCP(const void *data, size_t len, const RTPAddress &a)
222 {
223  transmitter->InjectRTCP(data, len, a);
224 }
225 
226 inline void RTPExternalPacketInjecter::InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a)
227 {
228  transmitter->InjectRTPorRTCP(data, len, a);
229 }
230 
231 } // end namespace
232 
233 #endif // RTPTCPSOCKETTRANSMITTER_H
234 
235 
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
Interface to inject incoming RTP and RTCP packets into the library.
Definition: rtpexternaltransmitter.h:87
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:226
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:216
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:221
Base class to specify a mechanism to transmit RTP packets outside of this library.
Definition: rtpexternaltransmitter.h:64
virtual bool ComesFromThisSender(const RTPAddress *a)=0
Used to identify if an RTPAddress instance originated from this sender (to be able to detect own pack...
virtual bool SendRTCP(const void *data, size_t len)=0
This member function will be called when an RTCP packet needs to be transmitted.
virtual bool SendRTP(const void *data, size_t len)=0
This member function will be called when RTP data needs to be transmitted.
Additional information about the external transmission component.
Definition: rtpexternaltransmitter.h:121
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
Parameters to initialize a transmitter of type RTPExternalTransmitter.
Definition: rtpexternaltransmitter.h:106
RTPExternalTransmissionParams(RTPExternalSender *s, int headeroverhead)
Using this constructor you can specify which RTPExternalSender object you'll be using and how much th...
Definition: rtpexternaltransmitter.h:110
A transmission component which will use user specified functions to transmit the data and which will ...
Definition: rtpexternaltransmitter.h:141
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
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
@ ExternalProto
Specifies the transmitter which can send packets using an external mechanism, and which can have rece...
Definition: rtptransmitter.h:75