sipxmedialib  Version 3.3
MprRtpDispatcher.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2016 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2007-2008 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // $$
9 
10 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>
11 
12 #ifndef _MprRtpDispatcher_h_
13 #define _MprRtpDispatcher_h_
14 
15 // SYSTEM INCLUDES
16 // APPLICATION INCLUDES
17 #include <mp/MpResource.h>
18 //#include "mp/MpEvents.h"
19 #include <mp/MpRtpBuf.h>
21 #include <utl/UtlString.h>
22 #include <utl/UtlInt.h>
23 #include <os/OsMsgQ.h>
24 #include <os/OsDateTime.h>
25 #include <os/OsLock.h>
26 
27 // DEFINES
28 // MACROS
29 // EXTERNAL FUNCTIONS
30 // EXTERNAL VARIABLES
31 // CONSTANTS
32 // STRUCTS
33 // TYPEDEFS
34 // FORWARD DECLARATIONS
35 class OsMsgDispatcher;
36 
43 {
44 /* //////////////////////////// PUBLIC //////////////////////////////////// */
45 public:
46 
48  {
51  };
52 
53 /* ============================ CREATORS ================================== */
55 
56 
58  MprRtpDispatcher(const UtlString& rName, int connectionId);
65  virtual ~MprRtpDispatcher();
67 
69 
70 /* ============================ MANIPULATORS ============================== */
72 
73 
75  virtual OsStatus pushPacket(MpRtpBufPtr &pRtp) = 0;
76 
78  virtual void checkRtpStreamsActivity() = 0;
79 
81  virtual UtlBoolean connectOutput(int outputIdx, MpResource* pushRtpToResource) = 0;
82 
84  virtual UtlBoolean disconnectOutput(int outputIdx) = 0;
85 
87  inline void setNotificationDispatcher(OsMsgDispatcher *pMsgQ);
92  inline void setNotificationsEnabled(UtlBoolean enabled);
94 
96  inline void setConnectionId(MpConnectionID connectionId);
97 
99  inline void setRtpInactivityTimeout(const OsTime &inactiveTime);
105  static inline
107  void setDefaultRtpInactivityTimeout(const OsTime &inactiveTime);
114 
115 /* ============================ ACCESSORS ================================= */
117 
118 
120 
121 /* ============================ INQUIRY =================================== */
123 
124 
125  // Returns true, if notifications are enabled to be sent.
126  inline UtlBoolean areNotificationsEnabled() const;
127 
129 
130 /* //////////////////////////// PROTECTED ///////////////////////////////// */
131 protected:
132 
133 // The below define is to work around brokenness in VC6. Details follow.
134 // In MSVC6, MprRtpDispatcherActiveSsrcs::lookupRtpStream fails to compile
135 // properly with MpRtpStream defined here as protected, as VC6 erroneously
136 // specifies that it 'cannot access protected struct decalred in class 'MprRtpDispatcher'
137 // despite the fact that MprRtpDispatcherActiveSrcs derives from
138 // this class, and defines lookupRtpStream as protected.
139 // So, to work around this, if we're compiling with VC6, then make the
140 // struct public (which exposes it more than we want)...
141 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
142 public:
143 #endif
144 
151  struct MpRtpStream : public UtlInt
152  {
154  : mStreamId(-1)
156  , mAddress(0)
157  , mPort(-1)
158  , mpOutputResource(NULL)
159  {}
160 
161  int mStreamId;
162  OsTime mLastPacketTime;
164  UtlBoolean mStreamActive;
165  int mAddress;
166  int mPort;
168 
173  inline void pushPacket(MpRtpBufPtr &pRtp);
174 
176  inline void activate(int fromIp, int fromPort);
177 
179  inline void deactivate();
180 
182  UtlBoolean timeoutDeactivate(const OsTime &timeout);
187  inline UtlBoolean isActive() const;
189 
191  inline RtpSRC getSSRC() const;
192 
194  inline void setSSRC(RtpSRC ssrc);
203  OsStatus postStreamNotif(OsMsgDispatcher *pMsgQ,
205  const UtlString &resourceName,
206  MpConnectionID connId,
208  };
209 // The below define is to work around brokenness in VC6. Details above the
210 // struct definition.
211 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
212 protected:
213 #endif
214 
215  OsMutex mMutex;
216  UtlString mResourceName;
219  OsMsgDispatcher* mpEventMsgQ;
221 
223 
225  static OsTime smDefaultRtpInactiveTime;
226 
227 /* //////////////////////////// PRIVATE /////////////////////////////////// */
228 private:
229 
231  MprRtpDispatcher(const MprRtpDispatcher& rMprRtpDispatcher);
232 
235 
236 };
237 
238 /* ============================ INLINE METHODS ============================ */
239 
241 {
242  OsLock lock(mMutex);
243  mpEventMsgQ = pMsgQ;
244 }
245 
247 {
248  mNotificationsEnabled = enabled;
249 }
250 
252 {
253  OsLock lock(mMutex);
254  mConnectionId = connectionId;
255 }
256 
257 void MprRtpDispatcher::setRtpInactivityTimeout(const OsTime &inactiveTime)
258 {
259  OsLock lock(mMutex);
260  mRtpInactiveTime = inactiveTime;
261 }
262 
263 void MprRtpDispatcher::setDefaultRtpInactivityTimeout(const OsTime &inactiveTime)
264 {
265  smDefaultRtpInactiveTime = inactiveTime;
266 }
267 
269 {
270  return mNotificationsEnabled;
271 }
272 
275 {
276  OsDateTime::getCurTime(mLastPacketTime);
277  mpOutputResource->pushBuffer(0, // input port on resource
278  pRtp);
279 }
280 
282 void MprRtpDispatcher::MpRtpStream::activate(int fromIp, int fromPort)
283 {
284  // Make sure that the output resource has been enabled
285  // otherwise no audio
287  {
288  // Reset decoder in preparation to handle new stream
291  }
292 
293  // Mark stream as active and save sender IP.
295  mAddress = fromIp;
296  mPort = fromPort;
297 
298 // printf("Stream %X activated\n", getSSRC());
299 }
300 
303 {
304  // Mark stream as inactive
306 
307 // printf("Stream %X deactivated\n", getSSRC());
308 }
309 
311 {
312  return mStreamActive;
313 }
314 
316 {
317  return getValue();
318 }
319 
321 {
322  // Reset decoder if this is not the first time setSSRC() is called.
323  // Note, that we deliberately does not check whether SSRC really changed.
324  // We trust caller to perform this check. Furthermore some broken
325  // implementations does not change SSRC on a new stream start.
326  if (mAddress != 0 && mpOutputResource != NULL)
327  {
329  }
330 
331  setValue(ssrc);
332 }
333 
334 #endif // _MprRtpDispatcher_h_
virtual OsStatus pushPacket(MpRtpBufPtr &pRtp)=0
Dispatch RTP packet.
UtlBoolean mNotificationsEnabled
Are notifications enabled?
Definition: MprRtpDispatcher.h:220
RtpStreamAffinity
Definition: MprRtpDispatcher.h:47
int mAddress
IP address of the stream source.
Definition: MprRtpDispatcher.h:165
Information, specific for an RTP stream.
Definition: MprRtpDispatcher.h:151
MprRtpDispatcher & operator=(const MprRtpDispatcher &rhs)
Assignment operator (not implemented for this class)
RtpSRC getSSRC() const
Get stream SSRC.
Definition: MprRtpDispatcher.h:315
void setSSRC(RtpSRC ssrc)
Set stream SSRC.
Definition: MprRtpDispatcher.h:320
MpRtpStream()
Definition: MprRtpDispatcher.h:153
void activate(int fromIp, int fromPort)
Mark stream as active.
Definition: MprRtpDispatcher.h:282
Class for RTP stream dispatcher abstraction.
Definition: MprRtpDispatcher.h:42
virtual UtlBoolean disconnectOutput(int outputIdx)=0
Disconnect output from the previously given resource.
Smart pointer to MpRtpBuf.
Definition: MpRtpBuf.h:348
void setNotificationDispatcher(OsMsgDispatcher *pMsgQ)
Set notification dispatcher.
Definition: MprRtpDispatcher.h:240
UtlBoolean mStreamActive
Is this stream active or not?
Definition: MprRtpDispatcher.h:164
void deactivate()
Mark stream as inactive.
Definition: MprRtpDispatcher.h:302
UtlString mResourceName
Definition: MprRtpDispatcher.h:216
OsTime mRtpInactiveTime
inactive if does not receive RTP packets.
Definition: MprRtpDispatcher.h:222
OsStatus postStreamNotif(OsMsgDispatcher *pMsgQ, const UtlString &resourceName, MpConnectionID connId, MprnRtpStreamActivityMsg::StreamState state) const
Send notification on stream activation/deactivation.
Definition: MprRtpDispatcher.cpp:86
void setNotificationsEnabled(UtlBoolean enabled)
Enable/disable notifications.
Definition: MprRtpDispatcher.h:246
void pushPacket(MpRtpBufPtr &pRtp)
Push packet to the stream for processing.
Definition: MprRtpDispatcher.h:274
MprRtpDispatcher(const UtlString &rName, int connectionId)
Constructor.
Definition: MprRtpDispatcher.cpp:39
virtual UtlBoolean connectOutput(int outputIdx, MpResource *pushRtpToResource)=0
Connect output to the given resource.
interface rtpts_t rtpts_t ssrc_t ssrc
Definition: ISetSenderStatistics.h:68
virtual void checkRtpStreamsActivity()=0
Check activity of the RTP streams and send notifications if needed.
void setConnectionId(MpConnectionID connectionId)
Set ID of the connection to which this resource belongs.
Definition: MprRtpDispatcher.h:251
MpConnectionID mConnectionId
ConnID to send in event notifications.
Definition: MprRtpDispatcher.h:218
static OsTime smDefaultRtpInactiveTime
Default value for mRtpInactiveTime.
Definition: MprRtpDispatcher.h:225
MpResource * mpOutputResource
Definition: MprRtpDispatcher.h:167
virtual UtlBoolean enable()
Enable this resource.
Definition: MpResource.cpp:145
virtual ~MprRtpDispatcher()
Destructor.
Definition: MprRtpDispatcher.cpp:50
void setRtpInactivityTimeout(const OsTime &inactiveTime)
Set stream activity timeout.
Definition: MprRtpDispatcher.h:257
static void setDefaultRtpInactivityTimeout(const OsTime &inactiveTime)
Set default stream activity timeout.
Definition: MprRtpDispatcher.h:263
int MpConnectionID
Flowgraph connection ID.
Definition: MpTypes.h:56
uint32_t RtpSRC
RTP SSRC or CSRC identifier.
Definition: MpTypes.h:61
virtual OsStatus pushBuffer(int inputPort, MpBufPtr &inputBuffer)
Receive buffer asynchronously from resource at given input port.
Definition: MpResource.cpp:229
virtual void reset()
This method is invoked for resources that care about stream discontinuities.
Definition: MpResource.cpp:161
UtlBoolean timeoutDeactivate(const OsTime &timeout)
Mark stream as inactive, if timeout occurred.
Definition: MprRtpDispatcher.cpp:62
UtlBoolean areNotificationsEnabled() const
Definition: MprRtpDispatcher.h:268
OsTime mLastPacketTime
Time of last packet receive.
Definition: MprRtpDispatcher.h:163
int mPort
Port of the stream source.
Definition: MprRtpDispatcher.h:166
Definition: MprRtpDispatcher.h:49
Abstract base class for all media processing objects.
Definition: MpResource.h:56
#define TRUE
Definition: PlgDefsV1.h:41
#define FALSE
Definition: PlgDefsV1.h:37
Definition: MprRtpDispatcher.h:50
StreamState
Definition: MprnRtpStreamActivityMsg.h:42
UtlBoolean isActive() const
Is this stream marked as active?
Definition: MprRtpDispatcher.h:310
int mStreamId
Definition: MprRtpDispatcher.h:161
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
OsMutex mMutex
Mutex to synchronize access to this resource.
Definition: MprRtpDispatcher.h:215
OsMsgDispatcher * mpEventMsgQ
MsgQ for event notifications.
Definition: MprRtpDispatcher.h:219