Bug 1367646 - Update WebRTC with cubeb_device_collection changes. r+jesup
MozReview-Commit-ID: 3llJO2vWPJh
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -33,31 +33,31 @@ static mozilla::LazyLogModule sGetUserMe
#define LOG(args) MOZ_LOG(sGetUserMediaLog, mozilla::LogLevel::Debug, args)
namespace mozilla {
// statics from AudioInputCubeb
nsTArray<int>* AudioInputCubeb::mDeviceIndexes;
int AudioInputCubeb::mDefaultDevice = -1;
nsTArray<nsCString>* AudioInputCubeb::mDeviceNames;
-cubeb_device_collection* AudioInputCubeb::mDevices = nullptr;
+cubeb_device_collection AudioInputCubeb::mDevices = { nullptr, 0 };
bool AudioInputCubeb::mAnyInUse = false;
StaticMutex AudioInputCubeb::sMutex;
// AudioDeviceID is an annoying opaque value that's really a string
// pointer, and is freed when the cubeb_device_collection is destroyed
void AudioInputCubeb::UpdateDeviceList()
{
cubeb* cubebContext = CubebUtils::GetCubebContext();
if (!cubebContext) {
return;
}
- cubeb_device_collection *devices = nullptr;
+ cubeb_device_collection devices = { nullptr, 0 };
if (CUBEB_OK != cubeb_enumerate_devices(cubebContext,
CUBEB_DEVICE_TYPE_INPUT,
&devices)) {
return;
}
for (auto& device_index : (*mDeviceIndexes)) {
@@ -66,49 +66,47 @@ void AudioInputCubeb::UpdateDeviceList()
// We keep all the device names, but wipe the mappings and rebuild them
// Calculate translation from existing mDevices to new devices. Note we
// never end up with less devices than before, since people have
// stashed indexes.
// For some reason the "fake" device for automation is marked as DISABLED,
// so white-list it.
mDefaultDevice = -1;
- for (uint32_t i = 0; i < devices->count; i++) {
+ for (uint32_t i = 0; i < devices.count; i++) {
LOG(("Cubeb device %u: type 0x%x, state 0x%x, name %s, id %p",
- i, devices->device[i]->type, devices->device[i]->state,
- devices->device[i]->friendly_name, devices->device[i]->device_id));
- if (devices->device[i]->type == CUBEB_DEVICE_TYPE_INPUT && // paranoia
- (devices->device[i]->state == CUBEB_DEVICE_STATE_ENABLED ||
- (devices->device[i]->state == CUBEB_DEVICE_STATE_DISABLED &&
- devices->device[i]->friendly_name &&
- strcmp(devices->device[i]->friendly_name, "Sine source at 440 Hz") == 0)))
+ i, devices.device[i].type, devices.device[i].state,
+ devices.device[i].friendly_name, devices.device[i].device_id));
+ if (devices.device[i].type == CUBEB_DEVICE_TYPE_INPUT && // paranoia
+ (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED ||
+ (devices.device[i].state == CUBEB_DEVICE_STATE_DISABLED &&
+ devices.device[i].friendly_name &&
+ strcmp(devices.device[i].friendly_name, "Sine source at 440 Hz") == 0)))
{
- auto j = mDeviceNames->IndexOf(devices->device[i]->device_id);
+ auto j = mDeviceNames->IndexOf(devices.device[i].device_id);
if (j != nsTArray<nsCString>::NoIndex) {
// match! update the mapping
(*mDeviceIndexes)[j] = i;
} else {
// new device, add to the array
mDeviceIndexes->AppendElement(i);
- mDeviceNames->AppendElement(devices->device[i]->device_id);
+ mDeviceNames->AppendElement(devices.device[i].device_id);
j = mDeviceIndexes->Length()-1;
}
- if (devices->device[i]->preferred & CUBEB_DEVICE_PREF_VOICE) {
+ if (devices.device[i].preferred & CUBEB_DEVICE_PREF_VOICE) {
// There can be only one... we hope
NS_ASSERTION(mDefaultDevice == -1, "multiple default cubeb input devices!");
mDefaultDevice = j;
}
}
}
LOG(("Cubeb default input device %d", mDefaultDevice));
StaticMutexAutoLock lock(sMutex);
// swap state
- if (mDevices) {
- cubeb_device_collection_destroy(cubebContext, mDevices);
- }
+ cubeb_device_collection_destroy(cubebContext, &mDevices);
mDevices = devices;
}
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
: mMutex("mozilla::MediaEngineWebRTC"),
mVoiceEngine(nullptr),
mAudioInput(nullptr),
mFullDuplex(aPrefs.mFullDuplex),
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -174,21 +174,17 @@ public:
mDeviceIndexes = new nsTArray<int>;
mDeviceNames = new nsTArray<nsCString>;
mDefaultDevice = -1;
}
}
static void CleanupGlobalData()
{
- if (mDevices) {
- // This doesn't require anything more than support for free()
- cubeb_device_collection_destroy(CubebUtils::GetCubebContext(), mDevices);
- mDevices = nullptr;
- }
+ cubeb_device_collection_destroy(CubebUtils::GetCubebContext(), &mDevices);
delete mDeviceIndexes;
mDeviceIndexes = nullptr;
delete mDeviceNames;
mDeviceNames = nullptr;
}
int GetNumOfRecordingDevices(int& aDevices)
{
@@ -229,36 +225,36 @@ public:
// Assert sMutex is held
sMutex.AssertCurrentThreadOwns();
#ifdef MOZ_WIDGET_ANDROID
aID = nullptr;
return true;
#else
int dev_index = DeviceIndex(aDeviceIndex);
if (dev_index != -1) {
- aID = mDevices->device[dev_index]->devid;
+ aID = mDevices.device[dev_index].devid;
return true;
}
return false;
#endif
}
int GetRecordingDeviceName(int aIndex, char (&aStrNameUTF8)[128],
char aStrGuidUTF8[128])
{
#ifdef MOZ_WIDGET_ANDROID
aStrNameUTF8[0] = '\0';
aStrGuidUTF8[0] = '\0';
#else
int32_t devindex = DeviceIndex(aIndex);
- if (!mDevices || devindex < 0) {
+ if (mDevices.count == 0 || devindex < 0) {
return 1;
}
SprintfLiteral(aStrNameUTF8, "%s%s", aIndex == -1 ? "default: " : "",
- mDevices->device[devindex]->friendly_name);
+ mDevices.device[devindex].friendly_name);
aStrGuidUTF8[0] = '\0';
#endif
return 0;
}
int GetRecordingDeviceStatus(bool& aIsAvailable)
{
// With cubeb, we only expose devices of type CUBEB_DEVICE_TYPE_INPUT,
@@ -266,19 +262,19 @@ public:
aIsAvailable = true;
return 0;
}
void StartRecording(SourceMediaStream *aStream, AudioDataListener *aListener)
{
#ifdef MOZ_WIDGET_ANDROID
// OpenSL ES does not support enumerating devices.
- MOZ_ASSERT(!mDevices);
+ MOZ_ASSERT(mDevices.count == 0);
#else
- MOZ_ASSERT(mDevices);
+ MOZ_ASSERT(mDevices.count > 0);
#endif
if (mInUseCount == 0) {
ScopedCustomReleasePtr<webrtc::VoEExternalMedia> ptrVoEXMedia;
ptrVoEXMedia = webrtc::VoEExternalMedia::GetInterface(mVoiceEngine);
if (ptrVoEXMedia) {
ptrVoEXMedia->SetExternalRecordingStatus(true);
}
@@ -320,17 +316,17 @@ private:
// updated on each re-enumeration.
int mSelectedDevice;
uint32_t mInUseCount;
// pointers to avoid static constructors
static nsTArray<int>* mDeviceIndexes;
static int mDefaultDevice; // -1 == not set
static nsTArray<nsCString>* mDeviceNames;
- static cubeb_device_collection *mDevices;
+ static cubeb_device_collection mDevices;
static bool mAnyInUse;
static StaticMutex sMutex;
};
class AudioInputWebRTC final : public AudioInput
{
public:
explicit AudioInputWebRTC(webrtc::VoiceEngine* aVoiceEngine) : AudioInput(aVoiceEngine) {}