Commit 3991a6e0 authored by Tristan Matthews's avatar Tristan Matthews

* #30347: audiortp: remove ScopedLock

parent a4568618
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "logger.h" #include "logger.h"
#include "sip/sipcall.h" #include "sip/sipcall.h"
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "scoped_lock.h"
#include "manager.h" #include "manager.h"
namespace sfl { namespace sfl {
...@@ -115,12 +114,7 @@ AudioRtpRecord::AudioRtpRecord() : ...@@ -115,12 +114,7 @@ AudioRtpRecord::AudioRtpRecord() :
, dtmfPayloadType_(101) // same as Asterisk , dtmfPayloadType_(101) // same as Asterisk
, dead_(false) , dead_(false)
, currentCodecIndex_(0) , currentCodecIndex_(0)
{ {}
pthread_mutex_init(&audioCodecMutex_, NULL);
#if HAVE_SPEEXDSP
pthread_mutex_init(&audioProcessMutex_, NULL);
#endif
}
// Call from processData* // Call from processData*
bool AudioRtpRecord::isDead() bool AudioRtpRecord::isDead()
...@@ -182,22 +176,17 @@ AudioRtpRecord::~AudioRtpRecord() ...@@ -182,22 +176,17 @@ AudioRtpRecord::~AudioRtpRecord()
delete converterDecode_; delete converterDecode_;
converterDecode_ = 0; converterDecode_ = 0;
{ {
ScopedLock lock(audioCodecMutex_); std::lock_guard<std::mutex> lock(audioCodecMutex_);
deleteCodecs(); deleteCodecs();
} }
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
{ {
ScopedLock lock(audioProcessMutex_); std::lock_guard<std::mutex> lock(audioProcessMutex_);
delete noiseSuppressDecode_; delete noiseSuppressDecode_;
noiseSuppressDecode_ = 0; noiseSuppressDecode_ = 0;
delete noiseSuppressEncode_; delete noiseSuppressEncode_;
noiseSuppressEncode_ = 0; noiseSuppressEncode_ = 0;
} }
#endif
pthread_mutex_destroy(&audioCodecMutex_);
#if HAVE_SPEEXDSP
pthread_mutex_destroy(&audioProcessMutex_);
#endif #endif
} }
...@@ -217,7 +206,7 @@ std::string ...@@ -217,7 +206,7 @@ std::string
AudioRtpRecordHandler::getCurrentAudioCodecNames() AudioRtpRecordHandler::getCurrentAudioCodecNames()
{ {
std::string result; std::string result;
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
{ {
std::string sep = ""; std::string sep = "";
...@@ -234,7 +223,7 @@ AudioRtpRecordHandler::getCurrentAudioCodecNames() ...@@ -234,7 +223,7 @@ AudioRtpRecordHandler::getCurrentAudioCodecNames()
void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs) void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs)
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
audioRtpRecord_.deleteCodecs(); audioRtpRecord_.deleteCodecs();
// Set various codec info to reduce indirection // Set various codec info to reduce indirection
...@@ -268,7 +257,7 @@ void AudioRtpRecordHandler::initBuffers() ...@@ -268,7 +257,7 @@ void AudioRtpRecordHandler::initBuffers()
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
void AudioRtpRecordHandler::initNoiseSuppress() void AudioRtpRecordHandler::initNoiseSuppress()
{ {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
delete audioRtpRecord_.noiseSuppressEncode_; delete audioRtpRecord_.noiseSuppressEncode_;
audioRtpRecord_.noiseSuppressEncode_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate()); audioRtpRecord_.noiseSuppressEncode_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate());
delete audioRtpRecord_.noiseSuppressDecode_; delete audioRtpRecord_.noiseSuppressDecode_;
...@@ -334,7 +323,7 @@ int AudioRtpRecordHandler::processDataEncode() ...@@ -334,7 +323,7 @@ int AudioRtpRecordHandler::processDataEncode()
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
if (Manager::instance().audioPreference.getNoiseReduce()) { if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressEncode_, 0, "Noise suppressor already destroyed"); RETURN_IF_NULL(audioRtpRecord_.noiseSuppressEncode_, 0, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize()); audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize());
} }
...@@ -346,7 +335,7 @@ int AudioRtpRecordHandler::processDataEncode() ...@@ -346,7 +335,7 @@ int AudioRtpRecordHandler::processDataEncode()
#endif #endif
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed"); RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed");
unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data(); unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data();
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize()); return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize());
...@@ -378,7 +367,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si ...@@ -378,7 +367,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
size = std::min(size, audioRtpRecord_.decData_.frames()); size = std::min(size, audioRtpRecord_.decData_.frames());
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed"); RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed");
// Return the size of data in samples // Return the size of data in samples
audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size); audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size);
...@@ -392,7 +381,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si ...@@ -392,7 +381,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
if (Manager::instance().audioPreference.getNoiseReduce()) { if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressDecode_, "Noise suppressor already destroyed"); RETURN_IF_NULL(audioRtpRecord_.noiseSuppressDecode_, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize()); audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize());
} }
......
...@@ -42,7 +42,7 @@ using std::ptrdiff_t; ...@@ -42,7 +42,7 @@ using std::ptrdiff_t;
#include <ccrtp/rtp.h> #include <ccrtp/rtp.h>
#include <tr1/array> #include <tr1/array>
#include <list> #include <list>
#include <pthread.h> #include <mutex>
#include "noncopyable.h" #include "noncopyable.h"
#include "audio/codecs/audiocodec.h" #include "audio/codecs/audiocodec.h"
...@@ -89,7 +89,7 @@ class AudioRtpRecord { ...@@ -89,7 +89,7 @@ class AudioRtpRecord {
private: private:
std::vector<AudioCodec*> audioCodecs_; std::vector<AudioCodec*> audioCodecs_;
pthread_mutex_t audioCodecMutex_; std::mutex audioCodecMutex_;
// these will have the same value unless we are sending // these will have the same value unless we are sending
// a different codec than we are receiving (asymmetric RTP) // a different codec than we are receiving (asymmetric RTP)
int encoderPayloadType_; int encoderPayloadType_;
...@@ -107,7 +107,7 @@ class AudioRtpRecord { ...@@ -107,7 +107,7 @@ class AudioRtpRecord {
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
NoiseSuppress *noiseSuppressEncode_; NoiseSuppress *noiseSuppressEncode_;
NoiseSuppress *noiseSuppressDecode_; NoiseSuppress *noiseSuppressDecode_;
pthread_mutex_t audioProcessMutex_; std::mutex audioProcessMutex_;
#endif #endif
unsigned int dtmfPayloadType_; unsigned int dtmfPayloadType_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment