Bug 1266285: Don't include UNPLUGGED cubeb devices in getUserMedia list, and use correct default r=kinetik

MozReview-Commit-ID: 1hBNLCAu2rW
This commit is contained in:
Randell Jesup 2016-04-21 01:42:50 -04:00
Родитель 72f7003eb5
Коммит 7d950772fc
2 изменённых файлов: 16 добавлений и 3 удалений

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

@ -46,6 +46,7 @@ namespace mozilla {
// statics from AudioInputCubeb
nsTArray<int>* AudioInputCubeb::mDeviceIndexes;
int AudioInputCubeb::mDefaultDevice = -1;
nsTArray<nsCString>* AudioInputCubeb::mDeviceNames;
cubeb_device_collection* AudioInputCubeb::mDevices = nullptr;
bool AudioInputCubeb::mAnyInUse = false;
@ -74,10 +75,10 @@ void AudioInputCubeb::UpdateDeviceList()
// 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++) {
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_UNPLUGGED ||
(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)))
@ -91,6 +92,11 @@ void AudioInputCubeb::UpdateDeviceList()
mDeviceIndexes->AppendElement(i);
mDeviceNames->AppendElement(devices->device[i]->device_id);
}
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 = i;
}
}
}
StaticMutexAutoLock lock(sMutex);

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

@ -167,6 +167,7 @@ public:
if (!mDeviceIndexes) {
mDeviceIndexes = new nsTArray<int>;
mDeviceNames = new nsTArray<nsCString>;
mDefaultDevice = -1;
}
}
@ -192,10 +193,15 @@ public:
static int32_t DeviceIndex(int aIndex)
{
// -1 = system default if any
if (aIndex == -1) {
aIndex = 0; // -1 = system default
if (mDefaultDevice == -1) {
aIndex = 0;
} else {
aIndex = mDefaultDevice;
}
if (aIndex >= (int) mDeviceIndexes->Length()) {
}
if (aIndex < 0 || aIndex >= (int) mDeviceIndexes->Length()) {
return -1;
}
// Note: if the device is gone, this will be -1
@ -291,6 +297,7 @@ private:
// 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 bool mAnyInUse;