JRTPLIB  3.9.0
rtpexternaltransmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2011 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 <list>
44 
45 #ifdef RTP_SUPPORT_THREAD
46  #include <jthread/jmutex.h>
47 #endif // RTP_SUPPORT_THREAD
48 
49 namespace jrtplib
50 {
51 
52 class RTPExternalTransmitter;
53 
63 {
64 public:
65  RTPExternalSender() { }
66  virtual ~RTPExternalSender() { }
67 
69  virtual bool SendRTP(const void *data, size_t len) = 0;
70 
72  virtual bool SendRTCP(const void *data, size_t len) = 0;
73 
75  virtual bool ComesFromThisSender(const RTPAddress *a) = 0;
76 };
77 
86 {
87 public:
88  RTPExternalPacketInjecter(RTPExternalTransmitter *trans) { transmitter = trans; }
90 
92  void InjectRTP(const void *data, size_t len, const RTPAddress &a);
93 
95  void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
96 
98  void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
99 private:
100  RTPExternalTransmitter *transmitter;
101 };
102 
105 {
106 public:
109  RTPExternalTransmissionParams(RTPExternalSender *s, int headeroverhead):RTPTransmissionParams(RTPTransmitter::ExternalProto) { sender = s; headersize = headeroverhead; }
110 
111  RTPExternalSender *GetSender() const { return sender; }
112  int GetAdditionalHeaderSize() const { return headersize; }
113 private:
114  RTPExternalSender *sender;
115  int headersize;
116 };
117 
120 {
121 public:
123 
126  RTPExternalPacketInjecter *GetPacketInjector() const { return packetinjector; }
127 private:
128  RTPExternalPacketInjecter *packetinjector;
129 };
130 
140 {
141 public:
144 
145  int Init(bool treadsafe);
146  int Create(size_t maxpacksize, const RTPTransmissionParams *transparams);
147  void Destroy();
148  RTPTransmissionInfo *GetTransmissionInfo();
149  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
150 
151  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
152  bool ComesFromThisTransmitter(const RTPAddress *addr);
153  size_t GetHeaderOverhead() { return headersize; }
154 
155  int Poll();
156  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
157  int AbortWait();
158 
159  int SendRTPData(const void *data,size_t len);
160  int SendRTCPData(const void *data,size_t len);
161 
162  int AddDestination(const RTPAddress &addr);
163  int DeleteDestination(const RTPAddress &addr);
164  void ClearDestinations();
165 
166  bool SupportsMulticasting();
167  int JoinMulticastGroup(const RTPAddress &addr);
168  int LeaveMulticastGroup(const RTPAddress &addr);
169  void LeaveAllMulticastGroups();
170 
171  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
172  int AddToIgnoreList(const RTPAddress &addr);
173  int DeleteFromIgnoreList(const RTPAddress &addr);
174  void ClearIgnoreList();
175  int AddToAcceptList(const RTPAddress &addr);
176  int DeleteFromAcceptList(const RTPAddress &addr);
177  void ClearAcceptList();
178  int SetMaximumPacketSize(size_t s);
179 
180  bool NewDataAvailable();
181  RTPRawPacket *GetNextPacket();
182 #ifdef RTPDEBUG
183  void Dump();
184 #endif // RTPDEBUG
185 
186  void InjectRTP(const void *data, size_t len, const RTPAddress &a);
187  void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
188  void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
189 private:
190  void FlushPackets();
191 
192  bool init;
193  bool created;
194  bool waitingfordata;
195  RTPExternalSender *sender;
196  RTPExternalPacketInjecter packetinjector;
197 
198  std::list<RTPRawPacket*> rawpacketlist;
199 
200  uint8_t *localhostname;
201  size_t localhostnamelength;
202 
203  size_t maxpacksize;
204  int headersize;
205 
206  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
207 #if (defined(WIN32) || defined(_WIN32_WCE))
208  SOCKET abortdesc[2];
209 #else
210  int abortdesc[2];
211 #endif // WIN32
212  int CreateAbortDescriptors();
213  void DestroyAbortDescriptors();
214  void AbortWaitInternal();
215 #ifdef RTP_SUPPORT_THREAD
216  jthread::JMutex mainmutex,waitmutex;
217  int threadsafe;
218 #endif // RTP_SUPPORT_THREAD
219 };
220 
221 inline void RTPExternalPacketInjecter::InjectRTP(const void *data, size_t len, const RTPAddress &a)
222 {
223  transmitter->InjectRTP(data, len, a);
224 }
225 
226 inline void RTPExternalPacketInjecter::InjectRTCP(const void *data, size_t len, const RTPAddress &a)
227 {
228  transmitter->InjectRTCP(data, len, a);
229 }
230 
231 inline void RTPExternalPacketInjecter::InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a)
232 {
233  transmitter->InjectRTPorRTCP(data, len, a);
234 }
235 
236 } // end namespace
237 
238 #endif // RTPTCPSOCKETTRANSMITTER_H
239 
240 
A transmission component which will use user specified functions to transmit the data and which will ...
Definition: rtpexternaltransmitter.h:139
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:104
Base class for transmission parameters.
Definition: rtptransmitter.h:227
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:226
RTPExternalPacketInjecter * GetPacketInjector() const
Tells you which RTPExternalPacketInjecter you need to use to pass RTP or RTCP data on to the transmis...
Definition: rtpexternaltransmitter.h:126
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:231
virtual bool SendRTP(const void *data, size_t len)=0
This member function will be called when RTP data needs to be transmitted.
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'll be using and how much th...
Definition: rtpexternaltransmitter.h:109
Additional information about the external transmission component.
Definition: rtpexternaltransmitter.h:119
Interface to inject incoming RTP and RTCP packets into the library.
Definition: rtpexternaltransmitter.h:85
Base class to specify a mechanism to transmit RTP packets outside of this library.
Definition: rtpexternaltransmitter.h:62
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:61
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:78
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:80
A memory manager.
Definition: rtpmemorymanager.h:147
Specifies the transmitter which can send packets using an external mechanism, and which can have rece...
Definition: rtptransmitter.h:73
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:246
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 ComesFromThisSender(const RTPAddress *a)=0
Used to identify if an RTPAddress instance originated from this sender (to be able to detect own pack...
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:221