reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
MediaResourceParticipant.cxx
Go to the documentation of this file.
1#include "BridgeMixer.hxx"
2#include "ReconSubsystem.hxx"
5#include "Conversation.hxx"
6#include "UserAgent.hxx"
7
8#include <rutil/Log.hxx>
9#include <rutil/Logger.hxx>
12
14#include "RemoteParticipant.hxx"
15
16using namespace recon;
17using namespace resip;
18using namespace std;
19
20#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
21
22// Url schemes
23static const Data toneScheme("tone");
24static const Data fileScheme("file");
25static const Data cacheScheme("cache");
26static const Data httpScheme("http");
27static const Data httpsScheme("https");
28static const Data recordScheme("record");
29static const Data recordMultiChannelScheme("record-mc");
30static const Data bufferScheme("buffer");
31
32static const resip::ExtensionParameter p_repeat("repeat");
33static const resip::ExtensionParameter p_prefetch("prefetch");
34static const resip::ExtensionParameter p_startOffset("startoffset");
35
37 ConversationManager& conversationManager,
38 const Uri& mediaUrl,
39 const std::shared_ptr<Data>& audioBuffer)
40: Participant(partHandle, ConversationManager::ParticipantType_MediaResource, conversationManager),
41 mMediaUrl(mediaUrl),
42 mAudioBuffer(audioBuffer),
43 mRepeat(false),
44 mPrefetch(false),
45 mDurationMs(0),
46 mStartOffsetMs(0),
47 mRunning(false),
48 mDestroying(false)
49{
50 InfoLog(<< "MediaResourceParticipant created, handle=" << mHandle << " url=" << mMediaUrl);
51 mResourceType = Invalid; // default
52 try
53 {
54 if(isEqualNoCase(mMediaUrl.scheme(), toneScheme))
55 {
56 mResourceType = Tone;
57 }
58 else if(isEqualNoCase(mMediaUrl.scheme(), fileScheme))
59 {
60 mResourceType = File;
61 }
62 else if(isEqualNoCase(mMediaUrl.scheme(), cacheScheme))
63 {
64 mResourceType = Cache;
65 }
66 else if(isEqualNoCase(mMediaUrl.scheme(), httpScheme))
67 {
68 mResourceType = Http;
69 }
70 else if(isEqualNoCase(mMediaUrl.scheme(), httpsScheme))
71 {
72 mResourceType = Https;
73 }
74 else if (isEqualNoCase(mMediaUrl.scheme(), recordScheme))
75 {
76 mResourceType = Record;
77 }
78 else if (isEqualNoCase(mMediaUrl.scheme(), recordMultiChannelScheme))
79 {
80 mResourceType = RecordMultiChannel;
81 }
82 else if (isEqualNoCase(mMediaUrl.scheme(), bufferScheme))
83 {
84 mResourceType = Buffer;
85 }
86 }
87 catch(BaseException &e)
88 {
89 WarningLog(<< "MediaResourceParticipant::MediaResourceParticipant exception for url=" << mMediaUrl << ": " << e);
90 }
91 catch(...)
92 {
93 WarningLog(<< "MediaResourceParticipant::MediaResourceParticipant unknown exception for url=" << mMediaUrl);
94 }
95}
96
98{
99 InfoLog(<< "MediaResourceParticipant destroyed, handle=" << mHandle << " url=" << mMediaUrl);
100}
101
102bool
104{
105 return mResourceType == Record ||
106 mResourceType == RecordMultiChannel;
107}
108
109bool
111{
112 return mResourceType == Tone ||
113 mResourceType == File ||
114 mResourceType == Cache ||
115 mResourceType == Http ||
116 mResourceType == Https ||
117 mResourceType == Buffer;
118}
119
120void
122{
123 resip_assert(!mRunning);
124 try
125 {
126 InfoLog(<< "MediaResourceParticipant::startResource, handle=" << mHandle << " url=" << mMediaUrl);
127
128 // Common processing
129 if(mMediaUrl.exists(p_duration))
130 {
131 mDurationMs = mMediaUrl.param(p_duration);
132 mMediaUrl.remove(p_duration);
133 }
134 if(mMediaUrl.exists(p_repeat))
135 {
136 mRepeat = true;
137 mMediaUrl.remove(p_repeat);
138 }
139 if(mMediaUrl.exists(p_prefetch))
140 {
141 mPrefetch = true;
142 mMediaUrl.remove(p_prefetch);
143 }
144 if (mMediaUrl.exists(p_startOffset))
145 {
146 mStartOffsetMs = mMediaUrl.param(p_startOffset).convertUnsignedLong();
147 mMediaUrl.remove(p_startOffset);
148 }
149
151 }
152 catch(BaseException &e)
153 {
154 WarningLog(<< "MediaResourceParticipant::startResource exception for url=" << mMediaUrl << ": " << e);
155 }
156 catch(...)
157 {
158 WarningLog(<< "MediaResourceParticipant::startResource unknown exception for url=" << mMediaUrl);
159 }
160
161 if(mRunning) // If play started successfully
162 {
163 if(mDurationMs > 0)
164 {
165 // Start timer to destroy media resource participant automatically
167 mConversationManager.post(destroyer, std::chrono::milliseconds(mDurationMs));
168 }
169 }
170 else
171 {
172 delete this;
173 }
174}
175
176void
178{
179 setRunning(false);
180 destroyParticipant(); // may destory this
181}
182
183void
185{
186 bool deleteNow = true;
187
188 if (isDestroying()) return;
189 setDestroying(true);
190
191 deleteNow = stopResource();
192
193 if (deleteNow) delete this;
194}
195
196
197
198/* ====================================================================
199
200 Copyright (c) 2021-2023, SIP Spectrum, Inc. http://www.sipspectrum.com
201 Copyright (c) 2021, Daniel Pocock https://danielpocock.com
202 Copyright (c) 2007-2008, Plantronics, Inc.
203 All rights reserved.
204
205 Redistribution and use in source and binary forms, with or without
206 modification, are permitted provided that the following conditions are
207 met:
208
209 1. Redistributions of source code must retain the above copyright
210 notice, this list of conditions and the following disclaimer.
211
212 2. Redistributions in binary form must reproduce the above copyright
213 notice, this list of conditions and the following disclaimer in the
214 documentation and/or other materials provided with the distribution.
215
216 3. Neither the name of Plantronics nor the names of its contributors
217 may be used to endorse or promote products derived from this
218 software without specific prior written permission.
219
220 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
221 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
222 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
223 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
224 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
227 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
228 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
229 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
230 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
231
232 ==================================================================== */
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
static const Data toneScheme("tone")
static const Data cacheScheme("cache")
static const Data recordMultiChannelScheme("record-mc")
static const Data fileScheme("file")
static const Data bufferScheme("buffer")
static const Data httpsScheme("https")
static const resip::ExtensionParameter p_startOffset("startoffset")
static const Data httpScheme("http")
static const Data recordScheme("record")
static const resip::ExtensionParameter p_prefetch("prefetch")
static const resip::ExtensionParameter p_repeat("repeat")
#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)
virtual void setDestroying(bool destroying)
virtual void startResourceImpl()=0
MediaResourceParticipant(ParticipantHandle partHandle, ConversationManager &conversationManager, const resip::Uri &mediaUrl, const std::shared_ptr< resip::Data > &audioBuffer)
This is the base class for a RemoteParticipant, LocalParticipant and a MediaResourceParticipant.
ParticipantHandle mHandle
ConversationManager & mConversationManager
The abstract base-class for all exceptions thrown by resip code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
unsigned long convertUnsignedLong() const
Definition Data.cxx:1724
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
Data & scheme()
Definition Uri.hxx:143
bool exists(const Param< Uri > &paramType) const
Definition Uri.cxx:1701
void remove(const Param< Uri > &paramType)
Definition Uri.cxx:1709
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
Definition Data.hxx:1116