Bug 1221587: patch 11 - Block attempts to open two mics at once until supported in full-duplex r=jib
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -40,16 +40,17 @@ GetUserMediaLog()
#endif
#undef LOG
#define LOG(args) MOZ_LOG(GetUserMediaLog(), mozilla::LogLevel::Debug, args)
namespace mozilla {
cubeb_device_collection* AudioInputCubeb::mDevices = nullptr;
+bool AudioInputCubeb::mAnyInUse = false;
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
: mMutex("mozilla::MediaEngineWebRTC"),
mVoiceEngine(nullptr),
mAudioInput(nullptr),
mAudioEngineInit(false)
{
#ifndef MOZ_B2G_CAMERA
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -154,17 +154,17 @@ protected:
webrtc::VoiceEngine* mVoiceEngine;
};
class AudioInputCubeb : public AudioInput
{
public:
AudioInputCubeb(webrtc::VoiceEngine* aVoiceEngine) :
- AudioInput(aVoiceEngine), mSelectedDevice(0)
+ AudioInput(aVoiceEngine), mSelectedDevice(0), mInUse(false)
{
// Force calculation of the indexes. We could keep them global
// too... cleanup would be annoying
int devices;
GetNumOfRecordingDevices(devices);
}
static void CleanupGlobalData()
@@ -237,40 +237,50 @@ public:
MOZ_ASSERT(mDevices);
ScopedCustomReleasePtr<webrtc::VoEExternalMedia> ptrVoERender;
ptrVoERender = webrtc::VoEExternalMedia::GetInterface(mVoiceEngine);
if (ptrVoERender) {
ptrVoERender->SetExternalRecordingStatus(true);
}
aGraph->OpenAudioInput(mDevices->device[mSelectedDevice]->devid, aListener);
+ mInUse = true;
+ mAnyInUse = true;
}
virtual void StopRecording(MediaStreamGraph *aGraph, AudioDataListener *aListener)
{
aGraph->CloseAudioInput(aListener);
+ mInUse = false;
+ mAnyInUse = false;
}
virtual int SetRecordingDevice(int aIndex)
{
int32_t devindex = DeviceIndex(aIndex);
- if (!mDevices || devindex < 0) {
+ // Bug 1238038: block attempts to capture from more than one mic at a time
+ // until we can handle that in full-duplex
+ if (!mDevices || devindex < 0 || mInUse) {
return 1;
}
mSelectedDevice = devindex;
return 0;
}
protected:
- virtual ~AudioInputCubeb() {}
+ virtual ~AudioInputCubeb() {
+ MOZ_RELEASE_ASSERT(!mInUse);
+ }
private:
nsTArray<int> mDeviceIndexes;
int mSelectedDevice;
static cubeb_device_collection *mDevices;
+ bool mInUse; // for assertions about listener lifetime
+ static bool mAnyInUse;
};
class AudioInputWebRTC : public AudioInput
{
public:
AudioInputWebRTC(webrtc::VoiceEngine* aVoiceEngine) : AudioInput(aVoiceEngine) {}
virtual int GetNumOfRecordingDevices(int& aDevices)