7#include <CpTopologyGraphInterface.h>
8#include <mp/MpResourceTopology.h>
9#include <mi/MiNotification.h>
10#include <mi/MiDtmfNotf.h>
11#include <mi/MiRtpStreamActivityNotf.h>
12#include <mi/MiIntNotf.h>
20#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
23 mConversationManager(conversationManager),
24 mMediaInterface(mediaInterface),
25 mAllowLoggingDTMFDigits(true)
27 InfoLog(<<
"SipXMediaInterface: CpTopologyGraphInterface created: 0x" << std::hex << mMediaInterface);
45 InfoLog(<<
"~SipXMediaInterface: releasing CpTopologyGraphInterface: 0x" << std::hex << mMediaInterface);
46 mMediaInterface->release();
53 OsStatus ret = mMediaInterface->createConnection(connectionId, rtpSocket, rtcpSocket, isMulticast);
62 OsStatus ret = mMediaInterface->createConnection(connectionId, localAddress, localPort);
70 resip::Lock lock(mConnectionIdToParticipantHandleMapMutex);
71 mConnectionIdToPartipantHandleMap[connectionId] = partHandle;
78 OsStatus ret = mMediaInterface->deleteConnection(connectionId);
80 resip::Lock lock(mConnectionIdToParticipantHandleMapMutex);
81 mConnectionIdToPartipantHandleMap.erase(connectionId);
87SipXMediaInterface::getParticipantHandleForConnectionId(
int connectionId)
90 resip::Lock lock(mConnectionIdToParticipantHandleMapMutex);
91 auto it = mConnectionIdToPartipantHandleMap.find(connectionId);
92 if (it != mConnectionIdToPartipantHandleMap.end())
94 partHandle = it->second;
104 std::list<MediaResourceAllocationInfo>& resourceInfos = getAllocationResourceInfos(resourceType);
106 for (
auto it = resourceInfos.begin(); it != resourceInfos.end(); it++)
108 if (it->mSipXResourceName == sipXResourceName)
111 partHandle = it->mAllocatedParticipantHandle;
127 resip_assert(mMediaResourceAllocations.find(resourceType) != mMediaResourceAllocations.end());
128 return mMediaResourceAllocations[resourceType];
135 std::list<MediaResourceAllocationInfo>& resourceInfos = getAllocationResourceInfos(resourceType);
137 for (
auto it = resourceInfos.begin(); it != resourceInfos.end(); it++)
139 if (it->mAllocatedParticipantHandle == 0)
141 allocatedResourceName = it->mSipXResourceName;
142 it->mAllocatedParticipantHandle = partHandle;
153 std::list<MediaResourceAllocationInfo>& resourceInfos = getAllocationResourceInfos(resourceType);
155 for (
auto it = resourceInfos.begin(); it != resourceInfos.end(); it++)
157 if (it->mAllocatedParticipantHandle == partHandle)
159 it->mAllocatedParticipantHandle = 0;
166SipXMediaInterface::post(
const OsMsg& msg)
168 if((OsMsg::MsgTypes)msg.getMsgType() == OsMsg::MI_NOTF_MSG)
170 MiNotification* pNotfMsg = (MiNotification*)&msg;
171 switch((MiNotification::NotfType)pNotfMsg->getType())
173 case MiNotification::MI_NOTF_PLAY_STARTED:
174 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_PLAY_STARTED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
176 case MiNotification::MI_NOTF_PLAY_PAUSED:
177 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_PLAY_PAUSED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
179 case MiNotification::MI_NOTF_PLAY_RESUMED:
180 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_PLAY_RESUMED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
182 case MiNotification::MI_NOTF_PLAY_STOPPED:
183 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_PLAY_STOPPED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
185 case MiNotification::MI_NOTF_PLAY_FINISHED:
190 mConversationManager.
post(mevent);
191 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_PLAY_FINISHED, sourceId=" << pNotfMsg->getSourceId().data() <<
192 ", connectionId=" << pNotfMsg->getConnectionId() <<
", participantHandle=" << partHandle);
195 case MiNotification::MI_NOTF_PLAY_ERROR:
200 mConversationManager.
post(mevent);
201 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_PLAY_ERROR, sourceId=" << pNotfMsg->getSourceId().data() <<
202 ", connectionId=" << pNotfMsg->getConnectionId() <<
", participantHandle=" << partHandle);
205 case MiNotification::MI_NOTF_PROGRESS:
206 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_PROGRESS, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
208 case MiNotification::MI_NOTF_RECORD_STARTED:
209 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_RECORD_STARTED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
211#ifndef SIPX_NO_RECORD
212 case MiNotification::MI_NOTF_RECORD_PAUSED:
213 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_RECORD_PAUSED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
215 case MiNotification::MI_NOTF_RECORD_RESUMED:
216 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_RECORD_RESUMED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
219 case MiNotification::MI_NOTF_RECORD_STOPPED:
220 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_RECORD_STOPPED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
222 case MiNotification::MI_NOTF_RECORD_FINISHED:
227 mConversationManager.
post(mevent);
228 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_RECORD_FINISHED, sourceId=" << pNotfMsg->getSourceId().data() <<
229 ", connectionId=" << pNotfMsg->getConnectionId() <<
", participantHandle=" << partHandle);
232 case MiNotification::MI_NOTF_RECORD_ERROR:
237 mConversationManager.
post(mevent);
238 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_RECORD_ERROR, sourceId=" << pNotfMsg->getSourceId().data() <<
239 ", connectionId=" << pNotfMsg->getConnectionId() <<
", participantHandle=" << partHandle);
242 case MiNotification::MI_NOTF_DTMF_RECEIVED:
244 MiDtmfNotf* pDtmfNotfMsg = (MiDtmfNotf*)&msg;
246 int duration = pDtmfNotfMsg->getDuration();
247 int durationMS = duration;
250 int rtpClockRate = 8000;
251 durationMS = (duration * 1000) / rtpClockRate;
252 StackLog(<<
"RTP clock rate = " << rtpClockRate <<
"Hz, duration (timestamp units) = " << duration <<
" = " << durationMS <<
"ms");
255 ParticipantHandle partHandle = getParticipantHandleForConnectionId(pNotfMsg->getConnectionId());
257 if (mAllowLoggingDTMFDigits)
259 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_DTMF_RECEIVED, sourceId=" << pNotfMsg->getSourceId().data() <<
260 ", connectionId=" << pNotfMsg->getConnectionId() <<
261 ", participantHandle=" << partHandle <<
262 ", keyCode=" << pDtmfNotfMsg->getKeyCode() <<
263 ", state=" << pDtmfNotfMsg->getKeyPressState() <<
264 ", duration=" << pDtmfNotfMsg->getDuration());
268 InfoLog(<<
"SipXMediaInterface: received MI_NOTF_DTMF_RECEIVED, sourceId=" << pNotfMsg->getSourceId().data() <<
269 ", connectionId=" << pNotfMsg->getConnectionId() <<
270 ", participantHandle=" << partHandle <<
271 ", keyCode=<HIDDEN>" <<
272 ", state=" << pDtmfNotfMsg->getKeyPressState() <<
273 ", duration=" << pDtmfNotfMsg->getDuration());
277 DtmfEvent* devent =
new DtmfEvent(mConversationManager, partHandle, pDtmfNotfMsg->getKeyCode(), durationMS, pDtmfNotfMsg->getKeyPressState()==MiDtmfNotf::KEY_UP);
278 mConversationManager.
post(devent);
281 case MiNotification::MI_NOTF_DELAY_SPEECH_STARTED:
282 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_DELAY_SPEECH_STARTED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
284 case MiNotification::MI_NOTF_DELAY_NO_DELAY:
285 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_DELAY_NO_DELAY, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
287 case MiNotification::MI_NOTF_DELAY_QUIESCENCE:
288 InfoLog( <<
"SipXMediaInterface: received MI_NOTF_DELAY_QUIESCENCE, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
290 case MiNotification::MI_NOTF_RX_STREAM_ACTIVITY:
292 MiRtpStreamActivityNotf* pRtpStreamActivityNotfMsg = (MiRtpStreamActivityNotf*)&msg;
294 DebugLog( <<
"SipXMediaInterface: received MI_NOTF_RX_STREAM_ACTIVITY, sourceId=" << pNotfMsg->getSourceId().data() <<
295 ", connectionId=" << pNotfMsg->getConnectionId() <<
296 ", state=" << (pRtpStreamActivityNotfMsg->getState() == MiRtpStreamActivityNotf::STREAM_START ?
"STREAM_START" :
297 pRtpStreamActivityNotfMsg->getState() == MiRtpStreamActivityNotf::STREAM_STOP ?
"STREAM_STOP" :
298 pRtpStreamActivityNotfMsg->getState() == MiRtpStreamActivityNotf::STREAM_CHANGE ?
"STREAM_CHANGE" :
299 Data(pRtpStreamActivityNotfMsg->getState()).c_str()) <<
300 ", ssrc=" << pRtpStreamActivityNotfMsg->getSsrc() <<
301 ", address=" << pRtpStreamActivityNotfMsg->getAddress() <<
302 ", port=" << pRtpStreamActivityNotfMsg->getPort());
305 case MiNotification::MI_NOTF_ENERGY_LEVEL:
313 case MiNotification::MI_NOTF_VOICE_STARTED:
315#ifndef SIPX_NO_RECORD
317 DebugLog(<<
"MediaInterface: received MI_NOTF_VOICE_STARTED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId() <<
", direction=" << (direction ==
MediaEvent::DIRECTION_IN ?
"IN" :
"OUT"));
318 ParticipantHandle partHandle = getParticipantHandleForConnectionId(pNotfMsg->getConnectionId());
322 mConversationManager.
post(mevent);
326 case MiNotification::MI_NOTF_VOICE_STOPPED:
328#ifndef SIPX_NO_RECORD
330 DebugLog(<<
"MediaInterface: received MI_NOTF_VOICE_STOPPED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId() <<
", direction=" << (direction ==
MediaEvent::DIRECTION_IN ?
"IN" :
"OUT"));
331 ParticipantHandle partHandle = getParticipantHandleForConnectionId(pNotfMsg->getConnectionId());
335 mConversationManager.
post(mevent);
339#ifndef SIPX_NO_RECORD
340 case MiNotification::MI_NOTF_TONE_DETECT_ON:
341 InfoLog(<<
"MediaInterface: received MI_NOTF_TONE_DETECT_ON, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
344 case MiNotification::MI_NOTF_H264_SPS:
345 InfoLog(<<
"MediaInterface: received MI_NOTF_H264_SPS, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
347 case MiNotification::MI_NOTF_H264_PPS:
348 InfoLog( <<
"MediaInterface: received MI_NOTF_H264_PPS, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
350#ifndef SIPX_NO_RECORD
351 case MiNotification::MI_NOTF_TONE_DETECT_OFF:
352 InfoLog( <<
"MediaInterface: received MI_NOTF_TONE_DETECT_OFF, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
354 case MiNotification::MI_NOTF_RECORDER_CIRCULARBUFFER_WATERMARK_REACHED:
355 WarningLog(<<
"MediaInterface: received MI_NOTF_RECORDER_CIRCULARBUFFER_WATERMARK_REACHED, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
357 case MiNotification::MI_NOTF_INPUT_DEVICE_NOT_PRESENT:
358 InfoLog(<<
"MediaInterface: received MI_NOTF_INPUT_DEVICE_NOT_PRESENT, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
360 case MiNotification::MI_NOTF_OUTPUT_DEVICE_NOT_PRESENT:
361 InfoLog(<<
"MediaInterface: received MI_NOTF_OUTPUT_DEVICE_NOT_PRESENT, sourceId=" << pNotfMsg->getSourceId().data() <<
", connectionId=" << pNotfMsg->getConnectionId());
366 InfoLog(<<
"SipXMediaInterface: unrecognized MiNotification type = " << pNotfMsg->getType());
371 InfoLog(<<
"SipXMediaInterface: unrecognized message type = " << msg.getMsgType());
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
This class is one of two main classes of concern to an application using the UserAgent library.
void post(resip::Message *message)
MediaStackAdapter & getMediaStackAdapter()
This class represents the data passed in a DTMF event.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...