17#include <CpTopologyGraphInterface.h>
18#include <mp/dtmflib.h>
19#include <mp/MprFromFile.h>
22#include <mp/MprEncode.h>
23#define DISABLE_STREAM_PLAYER
24#ifndef DISABLE_STREAM_PLAYER
25 #include <mp/MpStreamPlayer.h>
28#include <utl/CircularBufferPtr.h>
35#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
48 const std::shared_ptr<Data>& playAudioBuffer,
49 void* recordingCircularBuffer)
56 mRecordingCircularBuffer((CircularBufferPtr*)recordingCircularBuffer)
58 mRecordingCircularBuffer(nullptr)
63 if(recordingCircularBuffer != 0)
65 ErrLog(<<
"recordingCircularBuffer specified but recon is not compiled with support for CircularBuffer");
77#ifndef DISABLE_STREAM_PLAYER
78 mStreamPlayer->removeListener(
this);
79 mStreamPlayer->destroy();
97 if (mSipXResourceName.
empty())
101 WarningLog(<<
"SipXMediaResourceParticipant::startResource no available allocation for media participant of type=" <<
getResourceType());
130 WarningLog(<<
"SipXMediaResourceParticipant::startResource invalid tone identifier: " <<
getMediaUrl().host());
135 OsStatus status = OS_FAILED;
145 UtlString encodeName(DEFAULT_ENCODE_RESOURCE_NAME);
147 status = MprEncode::startTone(encodeName, *
getMediaInterface()->getInterface()->getMsgQ(), toneid);
157 WarningLog(<<
"SipXMediaResourceParticipant::startResource Participant " << partHandle <<
" no longer exists or invalid");
169 if(status == OS_SUCCESS)
175 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling startTone: " << status);
185 InfoLog(<<
"SipXMediaResourceParticipant playing, handle=" <<
mHandle <<
" filepath=" << filepath);
193 OsStatus status = mediaInterface->
getInterface()->playAudio(mSipXResourceName.
c_str(),
200 if(status == OS_SUCCESS)
206 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling playAudio: " << status);
216 InfoLog(<<
"SipXMediaResourceParticipant playing, handle=" <<
mHandle <<
" cacheKey=" << cacheKey);
224 OsStatus status = mediaInterface->
getInterface()->playBuffer((
char*)buffer->
data(),
231 OsStatus status = mediaInterface->
getInterface()->playBuffer(mSipXResourceName.
c_str(),
232 (
char*)buffer->
data(),
233 (
unsigned long)buffer->
size(),
241 if (status == OS_SUCCESS)
247 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling playAudio: " << status);
252 WarningLog(<<
"SipXMediaResourceParticipant::startResource media not found in cache, key: " <<
getMediaUrl().host());
261 InfoLog(<<
"SipXMediaResourceParticipant playing, handle=" <<
mHandle <<
" audioBufferType=" << audioBufferType);
267 if (buffer && buffer->
size() > 0)
271 OsStatus status = mediaInterface->
getInterface()->playBuffer((
char*)buffer->
data(),
278 OsStatus status = mediaInterface->
getInterface()->playBuffer(mSipXResourceName.
c_str(),
279 (
char*)buffer->
data(),
280 (
unsigned long)buffer->
size(),
288 if (status == OS_SUCCESS)
294 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling playAudio: " << status);
299 WarningLog(<<
"SipXMediaResourceParticipant::startResource buffer type, but no audio buffer was provided.");
304 WarningLog(<<
"SipXMediaResourceParticipant::startResource buffer type is not recognized: " << audioBufferType);
315 int flags = STREAM_SOUND_LOCAL | STREAM_SOUND_REMOTE;
317#ifndef DISABLE_STREAM_PLAYER
319 if(status == OS_SUCCESS)
321 mStreamPlayer->addListener(
this);
322 status = mStreamPlayer->realize(FALSE );
323 if(status != OS_SUCCESS)
325 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling StreamPlayer::realize: " << status);
334 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling createPlayer: " << status);
344 ErrLog(<<
"support for Record was not enabled at compile time");
346 int silenceTimeMs = -1;
360 else if (numChannels > 2)
366 CpMediaInterface::CpAudioFileFormat format = CpMediaInterface::CP_WAVE_PCM_16;
373 format = CpMediaInterface::CP_WAVE_MULAW;
378 format = CpMediaInterface::CP_WAVE_ALAW;
383 format = CpMediaInterface::CP_WAVE_GSM;
388 format = CpMediaInterface::CP_OGG_OPUS;
399 unsigned long recordingBufferNotificationWatermark = mRecordingCircularBuffer->getCapacity() / 5 * 4;
401 InfoLog(<<
"SipXMediaResourceParticipant recording to CircularBuffer, handle=" <<
mHandle <<
", format=" << formatString <<
", maxDurationMs=" <<
getDurationMs() <<
", silenceTimeMs=" << silenceTimeMs <<
", circularBufferCapacity=" << mRecordingCircularBuffer->getCapacity() <<
", recordingBufferNotificationWatermark=" << recordingBufferNotificationWatermark);
404 mRecordingCircularBuffer->addRef();
406 OsStatus status = mediaInterface->
getInterface()->recordCircularBufferAudio(
407 mSipXResourceName.
c_str(),
408 *mRecordingCircularBuffer,
410 recordingBufferNotificationWatermark,
416 if (status == OS_SUCCESS)
418 mRecordingCircularBuffer = 0;
423 mRecordingCircularBuffer->release();
424 mRecordingCircularBuffer = 0;
425 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling recordCircularBufferAudio: " << status);
436 InfoLog(<<
"SipXMediaResourceParticipant recording, handle=" <<
mHandle <<
" filepath=" << filepath <<
", format=" << formatString <<
", append=" << (append ?
"YES" :
"NO") <<
", maxDurationMs=" <<
getDurationMs() <<
", silenceTimeMs=" << silenceTimeMs);
452 OsStatus status = mediaInterface->
getInterface()->recordAudio(
453 mSipXResourceName.
c_str(),
461 if (status == OS_SUCCESS)
467 WarningLog(<<
"SipXMediaResourceParticipant::startResource error calling recordAudio: " << status);
474 WarningLog(<<
"SipXMediaResourceParticipant::startResource invalid resource type: " <<
getMediaUrl().scheme());
485 bool okToDeleteNow =
true;
493 OsStatus status = OS_FAILED;
503 UtlString encodeName(DEFAULT_ENCODE_RESOURCE_NAME);
505 status = MprEncode::stopTone(encodeName, *
getMediaInterface()->getInterface()->getMsgQ());
512 WarningLog(<<
"SipXMediaResourceParticipant::stopResource participant " << partHandle <<
" no longer exists or invalid");
523 if (status != OS_SUCCESS)
525 WarningLog(<<
"SipXMediaResourceParticipant::stopResource error calling stopTone: " << status);
539 if (status != OS_SUCCESS)
541 WarningLog(<<
"SipXMediaResourceParticipant::stopResource error calling stopAudio: " << status);
550#ifndef DISABLE_STREAM_PLAYER
551 OsStatus status = mStreamPlayer->stop();
552 if (status != OS_SUCCESS)
554 WarningLog(<<
"SipXMediaResourceParticipant::stopResource error calling StreamPlayer::stop: " << status);
558 okToDeleteNow =
false;
566#ifndef SIPX_NO_RECORD
568 if (status != OS_SUCCESS)
570 WarningLog(<<
"SipXMediaResourceParticipant::stopResource error calling stopRecordAudio: " << status);
582 return okToDeleteNow;
588 if (mPortOnBridge == -1)
593 if (mSipXResourceName.
empty())
597 WarningLog(<<
"SipXMediaResourceParticipant::getConnectionPortOnBridge no available allocation for media participant of type=" <<
getResourceType());
605 ErrLog(<<
"support for Record was not enabled at compile time");
607 getMediaInterface()->getInterface()->getResourceOutputPortOnBridge(mSipXResourceName.
c_str(), 0, mPortOnBridge);
612 getMediaInterface()->getInterface()->getResourceInputPortOnBridge(mSipXResourceName.
c_str(), 0, mPortOnBridge);
614 InfoLog(<<
"SipXMediaResourceParticipant getConnectionPortOnBridge, handle=" <<
mHandle <<
", mPortOnBridge=" << mPortOnBridge);
617 return mPortOnBridge;
623 InfoLog(<<
"SipXMediaResourceParticipant::playerRealized: handle=" <<
mHandle);
625#ifndef DISABLE_STREAM_PLAYER
628 OsStatus status = mStreamPlayer->prefetch(FALSE);
629 if(status != OS_SUCCESS)
631 WarningLog(<<
"SipXMediaResourceParticipant::playerRealized error calling StreamPlayer::prefetch: " << status);
638 OsStatus status = mStreamPlayer->play(FALSE );
639 if(status != OS_SUCCESS)
641 WarningLog(<<
"SipXMediaResourceParticipant::playerRealized error calling StreamPlayer::play: " << status);
652 InfoLog(<<
"SipXMediaResourceParticipant::playerPrefetched: handle=" <<
mHandle);
654#ifndef DISABLE_STREAM_PLAYER
655 OsStatus status = mStreamPlayer->play(FALSE);
656 if(status != OS_SUCCESS)
658 WarningLog(<<
"SipXMediaResourceParticipant::playerPrefetched error calling StreamPlayer::play: " << status);
668 InfoLog(<<
"SipXMediaResourceParticipant::playerPlaying: handle=" <<
mHandle);
674 InfoLog(<<
"SipXMediaResourceParticipant::playerPaused: handle=" <<
mHandle);
680 InfoLog(<<
"SipXMediaResourceParticipant::playerStopped: handle=" <<
mHandle);
685#ifndef DISABLE_STREAM_PLAYER
686 OsStatus status = mStreamPlayer->rewind(FALSE);
687 if(status != OS_SUCCESS)
689 WarningLog(<<
"SipXMediaResourceParticipant::playerStopped error calling StreamPlayer::rewind: " << status);
705 InfoLog(<<
"SipXMediaResourceParticipant::playerFailed: handle=" <<
mHandle);
#define WarningLog(args_)
#define resip_assert(x)
This file needs to work for both C and C++ code.
static const struct nv flags[]
This class is one of two main classes of concern to an application using the UserAgent library.
void post(resip::Message *message)
This is the base class for a RemoteParticipant, LocalParticipant and a MediaResourceParticipant.
virtual void unregisterFromAllConversations()
ParticipantHandle mHandle
This is the base class for a SipXRemoteParticipant, SipXLocalParticipant and a SipXMediaResourceParti...
virtual std::shared_ptr< SipXMediaInterface > getMediaInterface()
This class represent a remote participant.
virtual int getMediaConnectionId()
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
char & at(size_type p)
Returns the character at the specified position.
int replace(const Data &match, const Data &target, int max=INT_MAX)
Replaces up to max occurrences of the bytes match with target.
unsigned long convertUnsignedLong() const
bool empty() const noexcept
Checks whether the Data is empty.
Data urlDecoded() const
Performs in-place HTTP URL un-escaping of a Data.
size_type size() const noexcept
Returns the number of bytes in this Data.
static Data from(const T &x)
Converts from arbitrary other type to Data.
int convertInt() const
Takes the contents of the Data and converts them to an integer.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
bool exists(const Param< Uri > ¶mType) const
const Data & param(const ExtensionParameter ¶m) const
Const accessor for non-natively-supported parameter types.
static const resip::Data ringTone("ring")
static const resip::Data recordingFormatWAVGSM("WAV_GSM")
static const resip::Data recordingFormatOGGOPUS("OGG_OPUS")
static const resip::Data recordingFormatWAVMULAW("WAV_MULAW")
static const resip::Data backspaceTone("backspace")
static const resip::Data holdingTone("holding")
unsigned int ParticipantHandle
static const resip::Data busyTone("busy")
static const resip::Data fastbusyTone("fastbusy")
static const resip::Data loudfastbusyTone("loudfastbusy")
static const resip::Data recordingFormatWAVALAW("WAV_ALAW")
static const resip::Data recordingFormatWAVPCM16("WAV_PCM16")
static const resip::Data callwaitingTone("callwaiting")
static const resip::Data ringbackTone("ringback")
static const resip::Data dialtoneTone("dialtone")
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)