Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
7d3a53ff
Commit
7d3a53ff
authored
12 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #18668: manager: use pthread_mutex_t
parent
b19b940d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
daemon/src/managerimpl.cpp
+59
-45
59 additions, 45 deletions
daemon/src/managerimpl.cpp
daemon/src/managerimpl.h
+7
-6
7 additions, 6 deletions
daemon/src/managerimpl.h
with
66 additions
and
51 deletions
daemon/src/managerimpl.cpp
+
59
−
45
View file @
7d3a53ff
...
...
@@ -70,6 +70,7 @@
#endif
#include
"conference.h"
#include
"scoped_lock.h"
#include
<cerrno>
#include
<algorithm>
...
...
@@ -93,10 +94,23 @@ ManagerImpl::ManagerImpl() :
callAccountMap_
(),
callAccountMapMutex_
(),
IPToIPMap_
(),
mainBuffer_
(),
conferenceMap_
(),
history_
(),
finished_
(
false
)
{
pthread_mutex_init
(
&
currentCallMutex_
,
NULL
);
pthread_mutex_init
(
&
toneMutex_
,
NULL
);
pthread_mutex_init
(
&
audioLayerMutex_
,
NULL
);
pthread_mutex_init
(
&
waitingCallMutex_
,
NULL
);
// initialize random generator for call id
srand
(
time
(
NULL
));
}
ManagerImpl
::~
ManagerImpl
()
{
// destroy in reverse order of initialization
pthread_mutex_destroy
(
&
waitingCallMutex_
);
pthread_mutex_destroy
(
&
audioLayerMutex_
);
pthread_mutex_destroy
(
&
toneMutex_
);
pthread_mutex_destroy
(
&
currentCallMutex_
);
}
void
ManagerImpl
::
init
(
const
std
::
string
&
config_file
)
{
path_
=
config_file
.
empty
()
?
createConfigFile
()
:
config_file
;
...
...
@@ -123,10 +137,10 @@ void ManagerImpl::init(const std::string &config_file)
initAudioDriver
();
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
)
{
{
ost
::
Mutex
Lock
toneLock
(
toneMutex_
);
sfl
::
Scoped
Lock
toneLock
(
toneMutex_
);
telephoneTone_
.
reset
(
new
TelephoneTone
(
preferences
.
getZoneToneChoice
(),
audiodriver_
->
getSampleRate
()));
}
dtmfKey_
.
reset
(
new
DTMF
(
getMainBuffer
().
getInternalSamplingRate
()));
...
...
@@ -171,7 +185,7 @@ void ManagerImpl::finish()
#endif
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
delete
audiodriver_
;
audiodriver_
=
NULL
;
...
...
@@ -203,7 +217,7 @@ void ManagerImpl::unsetCurrentCall()
void
ManagerImpl
::
switchCall
(
const
std
::
string
&
id
)
{
ost
::
Mutex
Lock
m
(
currentCallMutex_
);
sfl
::
Scoped
Lock
m
(
currentCallMutex_
);
DEBUG
(
"----- Switch current call id to %s -----"
,
id
.
c_str
());
currentCallId_
=
id
;
}
...
...
@@ -596,7 +610,7 @@ void ManagerImpl::refuseCall(const std::string& id)
stopTone
();
if
(
getCallList
().
size
()
<=
1
)
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
stopStream
();
}
...
...
@@ -849,7 +863,7 @@ void ManagerImpl::addMainParticipant(const std::string& conference_id)
}
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
ConferenceMap
::
const_iterator
iter
=
conferenceMap_
.
find
(
conference_id
);
...
...
@@ -987,7 +1001,7 @@ void ManagerImpl::joinParticipant(const std::string& callId1, const std::string&
// set recording sampling rate
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
)
conf
->
setRecordingSmplRate
(
audiodriver_
->
getSampleRate
());
}
...
...
@@ -1038,7 +1052,7 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string >
dbus_
.
getCallManager
()
->
conferenceCreated
(
conf
->
getConfID
());
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
)
conf
->
setRecordingSmplRate
(
audiodriver_
->
getSampleRate
());
...
...
@@ -1243,7 +1257,7 @@ void ManagerImpl::addStream(const std::string& call_id)
// bind to main
getMainBuffer
().
bindCallID
(
call_id
,
MainBuffer
::
DEFAULT_ID
);
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
flushUrgent
();
audiodriver_
->
flushMain
();
}
...
...
@@ -1321,7 +1335,7 @@ void ManagerImpl::playDtmf(char code)
return
;
}
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
// numbers of int = length in milliseconds / 1000 (number of seconds)
// = number of seconds * SAMPLING_RATE by SECONDS
...
...
@@ -1366,14 +1380,14 @@ bool ManagerImpl::incomingCallWaiting() const
void
ManagerImpl
::
addWaitingCall
(
const
std
::
string
&
id
)
{
ost
::
Mutex
Lock
m
(
waitingCallMutex_
);
sfl
::
Scoped
Lock
m
(
waitingCallMutex_
);
waitingCall_
.
insert
(
id
);
nbIncomingWaitingCall_
++
;
}
void
ManagerImpl
::
removeWaitingCall
(
const
std
::
string
&
id
)
{
ost
::
Mutex
Lock
m
(
waitingCallMutex_
);
sfl
::
Scoped
Lock
m
(
waitingCallMutex_
);
if
(
waitingCall_
.
erase
(
id
))
nbIncomingWaitingCall_
--
;
...
...
@@ -1546,7 +1560,7 @@ void ManagerImpl::peerAnsweredCall(const std::string& id)
addStream
(
id
);
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
flushMain
();
audiodriver_
->
flushUrgent
();
}
...
...
@@ -1608,7 +1622,7 @@ void ManagerImpl::peerHungupCall(const std::string& call_id)
if
(
getCallList
().
empty
())
{
DEBUG
(
"Stop audio stream, there are no calls remaining"
);
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
stopStream
();
}
}
...
...
@@ -1664,7 +1678,7 @@ void ManagerImpl::playATone(Tone::TONEID toneId)
return
;
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
==
NULL
)
{
ERROR
(
"Audio layer not initialized"
);
...
...
@@ -1676,7 +1690,7 @@ void ManagerImpl::playATone(Tone::TONEID toneId)
}
{
ost
::
Mutex
Lock
lock
(
toneMutex_
);
sfl
::
Scoped
Lock
lock
(
toneMutex_
);
if
(
telephoneTone_
.
get
()
!=
0
)
telephoneTone_
->
setCurrentTone
(
toneId
);
}
...
...
@@ -1690,7 +1704,7 @@ void ManagerImpl::stopTone()
if
(
not
voipPreferences
.
getPlayTones
())
return
;
ost
::
Mutex
Lock
lock
(
toneMutex_
);
sfl
::
Scoped
Lock
lock
(
toneMutex_
);
if
(
telephoneTone_
.
get
()
!=
NULL
)
telephoneTone_
->
setCurrentTone
(
Tone
::
TONE_NULL
);
...
...
@@ -1761,7 +1775,7 @@ void ManagerImpl::ringtone(const std::string& accountID)
int
audioLayerSmplr
=
8000
;
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
!
audiodriver_
)
{
ERROR
(
"no audio layer in ringtone"
);
...
...
@@ -1772,7 +1786,7 @@ void ManagerImpl::ringtone(const std::string& accountID)
}
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
if
(
audiofile_
.
get
())
{
dbus_
.
getCallManager
()
->
recordPlaybackStopped
(
audiofile_
->
getFilePath
());
...
...
@@ -1796,14 +1810,14 @@ void ManagerImpl::ringtone(const std::string& accountID)
}
}
// leave mutex
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
// start audio if not started AND flush all buffers (main and urgent)
audiodriver_
->
startStream
();
}
AudioLoop
*
ManagerImpl
::
getTelephoneTone
()
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
if
(
telephoneTone_
.
get
())
return
telephoneTone_
->
getCurrentTone
();
else
...
...
@@ -1813,7 +1827,7 @@ AudioLoop* ManagerImpl::getTelephoneTone()
AudioLoop
*
ManagerImpl
::
getTelephoneFile
()
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
return
audiofile_
.
get
();
}
...
...
@@ -1898,7 +1912,7 @@ ManagerImpl::getCurrentVideoCodecName(const std::string& ID)
*/
void
ManagerImpl
::
setAudioPlugin
(
const
std
::
string
&
audioPlugin
)
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audioPreference
.
setAlsaPlugin
(
audioPlugin
);
...
...
@@ -1917,7 +1931,7 @@ void ManagerImpl::setAudioPlugin(const std::string& audioPlugin)
*/
void
ManagerImpl
::
setAudioDevice
(
int
index
,
AudioLayer
::
PCMType
type
)
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
!
audiodriver_
)
{
ERROR
(
"Audio driver not initialized"
);
...
...
@@ -1940,7 +1954,7 @@ void ManagerImpl::setAudioDevice(int index, AudioLayer::PCMType type)
*/
std
::
vector
<
std
::
string
>
ManagerImpl
::
getAudioOutputDeviceList
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
return
audiodriver_
->
getPlaybackDeviceList
();
}
...
...
@@ -1950,7 +1964,7 @@ std::vector<std::string> ManagerImpl::getAudioOutputDeviceList()
*/
std
::
vector
<
std
::
string
>
ManagerImpl
::
getAudioInputDeviceList
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
return
audiodriver_
->
getCaptureDeviceList
();
}
...
...
@@ -1959,7 +1973,7 @@ std::vector<std::string> ManagerImpl::getAudioInputDeviceList()
*/
std
::
vector
<
std
::
string
>
ManagerImpl
::
getCurrentAudioDevicesIndex
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
std
::
vector
<
std
::
string
>
v
;
...
...
@@ -2051,7 +2065,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
int
sampleRate
;
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
!
audiodriver_
)
{
ERROR
(
"No audio layer in start recorded file playback"
);
...
...
@@ -2062,7 +2076,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
}
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
if
(
audiofile_
.
get
())
{
dbus_
.
getCallManager
()
->
recordPlaybackStopped
(
audiofile_
->
getFilePath
());
...
...
@@ -2077,7 +2091,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
}
}
// release toneMutex
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
startStream
();
return
true
;
...
...
@@ -2085,7 +2099,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath)
void
ManagerImpl
::
recordingPlaybackSeek
(
const
double
value
)
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
if
(
audiofile_
.
get
())
audiofile_
.
get
()
->
seek
(
value
);
}
...
...
@@ -2096,12 +2110,12 @@ void ManagerImpl::stopRecordedFilePlayback(const std::string& filepath)
DEBUG
(
"Stop recorded file playback %s"
,
filepath
.
c_str
());
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
stopStream
();
}
{
ost
::
Mutex
Lock
m
(
toneMutex_
);
sfl
::
Scoped
Lock
m
(
toneMutex_
);
audiofile_
.
reset
();
}
}
...
...
@@ -2121,7 +2135,7 @@ int ManagerImpl::getHistoryLimit() const
void
ManagerImpl
::
setAudioManager
(
const
std
::
string
&
api
)
{
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
!
audiodriver_
)
return
;
...
...
@@ -2147,7 +2161,7 @@ int ManagerImpl::getAudioDeviceIndex(const std::string &name)
{
int
soundCardIndex
=
0
;
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
==
NULL
)
{
ERROR
(
"Audio layer not initialized"
);
...
...
@@ -2208,13 +2222,13 @@ void ManagerImpl::setEchoCancelDelay(int delay)
*/
void
ManagerImpl
::
initAudioDriver
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
=
audioPreference
.
createAudioLayer
();
}
void
ManagerImpl
::
switchAudioManager
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
bool
wasStarted
=
audiodriver_
->
isStarted
();
delete
audiodriver_
;
...
...
@@ -2226,7 +2240,7 @@ void ManagerImpl::switchAudioManager()
void
ManagerImpl
::
audioSamplingRateChanged
(
int
samplerate
)
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
!
audiodriver_
)
{
DEBUG
(
"No Audio driver initialized"
);
...
...
@@ -2252,7 +2266,7 @@ void ManagerImpl::audioSamplingRateChanged(int samplerate)
unsigned
int
sampleRate
=
audiodriver_
->
getSampleRate
();
{
ost
::
Mutex
Lock
toneLock
(
toneMutex_
);
sfl
::
Scoped
Lock
toneLock
(
toneMutex_
);
telephoneTone_
.
reset
(
new
TelephoneTone
(
preferences
.
getZoneToneChoice
(),
sampleRate
));
}
dtmfKey_
.
reset
(
new
DTMF
(
sampleRate
));
...
...
@@ -2478,14 +2492,14 @@ void ManagerImpl::removeAccount(const std::string& accountID)
void
ManagerImpl
::
associateCallToAccount
(
const
std
::
string
&
callID
,
const
std
::
string
&
accountID
)
{
ost
::
Mutex
Lock
m
(
callAccountMapMutex_
);
sfl
::
Scoped
Lock
m
(
callAccountMapMutex_
);
callAccountMap_
[
callID
]
=
accountID
;
DEBUG
(
"Associate Call %s with Account %s"
,
callID
.
data
(),
accountID
.
data
());
}
std
::
string
ManagerImpl
::
getAccountFromCall
(
const
std
::
string
&
callID
)
{
ost
::
Mutex
Lock
m
(
callAccountMapMutex_
);
sfl
::
Scoped
Lock
m
(
callAccountMapMutex_
);
CallAccountMap
::
iterator
iter
=
callAccountMap_
.
find
(
callID
);
return
(
iter
==
callAccountMap_
.
end
())
?
""
:
iter
->
second
;
...
...
@@ -2493,12 +2507,12 @@ std::string ManagerImpl::getAccountFromCall(const std::string& callID)
void
ManagerImpl
::
removeCallAccount
(
const
std
::
string
&
callID
)
{
ost
::
Mutex
Lock
m
(
callAccountMapMutex_
);
sfl
::
Scoped
Lock
m
(
callAccountMapMutex_
);
callAccountMap_
.
erase
(
callID
);
// Stop audio layer if there is no call anymore
if
(
callAccountMap_
.
empty
())
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
if
(
audiodriver_
)
audiodriver_
->
stopStream
();
...
...
@@ -2508,7 +2522,7 @@ void ManagerImpl::removeCallAccount(const std::string& callID)
bool
ManagerImpl
::
isValidCall
(
const
std
::
string
&
callID
)
{
ost
::
Mutex
Lock
m
(
callAccountMapMutex_
);
sfl
::
Scoped
Lock
m
(
callAccountMapMutex_
);
return
callAccountMap_
.
find
(
callID
)
!=
callAccountMap_
.
end
();
}
...
...
@@ -2877,6 +2891,6 @@ void ManagerImpl::clearHistory()
void
ManagerImpl
::
startAudioDriverStream
()
{
ost
::
Mutex
Lock
lock
(
audioLayerMutex_
);
sfl
::
Scoped
Lock
lock
(
audioLayerMutex_
);
audiodriver_
->
startStream
();
}
This diff is collapsed.
Click to expand it.
daemon/src/managerimpl.h
+
7
−
6
View file @
7d3a53ff
...
...
@@ -45,7 +45,7 @@
#include
<map>
#include
<tr1/memory>
#include
"cc_
thread.h
"
#include
<p
thread.h
>
#include
"dbus/dbusmanager.h"
#include
"config/sfl_config.h"
...
...
@@ -100,6 +100,7 @@ static const char * const default_conf = "conf";
class
ManagerImpl
{
public:
ManagerImpl
();
~
ManagerImpl
();
/**
* General preferences configuration
...
...
@@ -863,7 +864,7 @@ class ManagerImpl {
std
::
string
currentCallId_
;
/** Protected current call access */
ost
::
M
utex
currentCallMutex_
;
pthread_m
utex
_t
currentCallMutex_
;
/** Audio layer */
AudioLayer
*
audiodriver_
;
...
...
@@ -874,7 +875,7 @@ class ManagerImpl {
/////////////////////
// Protected by Mutex
/////////////////////
ost
::
M
utex
toneMutex_
;
pthread_m
utex
_t
toneMutex_
;
std
::
tr1
::
shared_ptr
<
TelephoneTone
>
telephoneTone_
;
std
::
tr1
::
shared_ptr
<
AudioFile
>
audiofile_
;
...
...
@@ -886,7 +887,7 @@ class ManagerImpl {
/**
* Mutex used to protect audio layer
*/
ost
::
M
utex
audioLayerMutex_
;
pthread_m
utex
_t
audioLayerMutex_
;
/**
* Waiting Call Vectors
...
...
@@ -896,7 +897,7 @@ class ManagerImpl {
/**
* Protect waiting call list, access by many voip/audio threads
*/
ost
::
M
utex
waitingCallMutex_
;
pthread_m
utex
_t
waitingCallMutex_
;
/**
* Number of waiting call, synchronize with waitingcall callidvector
...
...
@@ -936,7 +937,7 @@ class ManagerImpl {
CallAccountMap
callAccountMap_
;
/** Mutex to lock the call account map (main thread + voiplink thread) */
ost
::
M
utex
callAccountMapMutex_
;
pthread_m
utex
_t
callAccountMapMutex_
;
std
::
map
<
std
::
string
,
bool
>
IPToIPMap_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment