Bug 1397793 - Use a ControlMessage to switch between passthrough and processing mode for microphone input. r=pehsrons

MozReview-Commit-ID: EIvQKZf7oGq

--HG--
extra : rebase_source : 7e7e0cedb7069639cd6dc3d1612c4d75ce71faa3
extra : source : 771c95f2963b64f52f32c9d2770136748bbf943a
This commit is contained in:
Paul Adenot 2017-11-08 14:10:45 +01:00
Родитель dce032329a
Коммит 30d795740b
3 изменённых файлов: 42 добавлений и 12 удалений

Просмотреть файл

@ -494,12 +494,6 @@ private:
// These allocate/configure and release the channel
bool AllocChannel();
void FreeChannel();
// This is true when all processing is disabled, we can skip
// packetization, resampling and other processing passes.
bool PassThrough() {
return mSkipProcessing;
}
template<typename T>
void InsertInGraph(const T* aBuffer,
size_t aFrames,
@ -511,6 +505,16 @@ private:
TrackRate aRate,
uint32_t aChannels);
// This is true when all processing is disabled, we can skip
// packetization, resampling and other processing passes.
bool PassThrough() {
return mSkipProcessing;
}
void SetPassThrough(bool aPassThrough) {
mSkipProcessing = aPassThrough;
}
RefPtr<mozilla::AudioInput> mAudioInput;
RefPtr<WebRTCAudioDataListener> mListener;
@ -548,7 +552,8 @@ private:
// mSkipProcessing is true if none of the processing passes are enabled,
// because of prefs or constraints. This allows simply copying the audio into
// the MSG, skipping resampling and the whole webrtc.org code.
std::atomic_bool mSkipProcessing;
// This is read and written to only on the MSG thread.
bool mSkipProcessing;
// To only update microphone when needed, we keep track of previous settings.
MediaEnginePrefs mLastPrefs;

Просмотреть файл

@ -10,6 +10,7 @@
#include "mtransport/runnable_utils.h"
#include "nsAutoPtr.h"
#include "AudioConverter.h"
#include "MediaStreamGraphImpl.h"
// scoped_ptr.h uses FF
#ifdef FF
@ -522,8 +523,7 @@ MediaEngineWebRTCMicrophoneSource::UpdateSingleSource(
#undef HANDLE_APM_ERROR
void
MediaEngineWebRTCMicrophoneSource::SetLastPrefs(
const MediaEnginePrefs& aPrefs)
MediaEngineWebRTCMicrophoneSource::SetLastPrefs(const MediaEnginePrefs& aPrefs)
{
mLastPrefs = aPrefs;
@ -534,11 +534,35 @@ MediaEngineWebRTCMicrophoneSource::SetLastPrefs(
that->mSettings->mAutoGainControl.Value() = aPrefs.mAgcOn;
that->mSettings->mNoiseSuppression.Value() = aPrefs.mNoiseOn;
that->mSettings->mChannelCount.Value() = aPrefs.mChannels;
class Message : public ControlMessage {
public:
Message(MediaEngineWebRTCMicrophoneSource* aSource,
bool aPassThrough)
: ControlMessage(nullptr)
, mMicrophoneSource(aSource)
, mPassThrough(aPassThrough)
{}
void Run() override
{
mMicrophoneSource->SetPassThrough(mPassThrough);
}
protected:
RefPtr<MediaEngineWebRTCMicrophoneSource> mMicrophoneSource;
bool mPassThrough;
};
bool passThrough = !(aPrefs.mAecOn || aPrefs.mAgcOn || aPrefs.mNoiseOn);
if (!that->mSources.IsEmpty()) {
that->mSources[0]->GraphImpl()->AppendMessage(MakeUnique<Message>(that, passThrough));
}
return NS_OK;
}));
}
nsresult
MediaEngineWebRTCMicrophoneSource::Deallocate(AllocationHandle* aHandle)
{
@ -675,7 +699,7 @@ MediaEngineWebRTCMicrophoneSource::NotifyOutputData(MediaStreamGraph* aGraph,
{
if (!PassThrough()) {
mAudioOutputObserver->InsertFarEnd(aBuffer, aFrames, false,
aRate, aChannels);
aRate, aChannels);
}
}

Просмотреть файл

@ -39,11 +39,12 @@ if CONFIG['MOZ_WEBRTC']:
'MediaEngineWebRTC.cpp',
]
LOCAL_INCLUDES += [
'..',
'/dom/base',
'/media/libyuv/libyuv/include',
'/media/webrtc/signaling/src/common',
'/media/webrtc/signaling/src/common/browser_logging',
'/media/webrtc/trunk',
'/media/webrtc/trunk'
]
XPIDL_SOURCES += [