diff options
Diffstat (limited to 'src/mumble/PulseAudio.cpp')
-rw-r--r-- | src/mumble/PulseAudio.cpp | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/mumble/PulseAudio.cpp b/src/mumble/PulseAudio.cpp index 1527ca444..5bb0baf79 100644 --- a/src/mumble/PulseAudio.cpp +++ b/src/mumble/PulseAudio.cpp @@ -8,9 +8,6 @@ #include "MainWindow.h" #include "Timer.h" #include "User.h" - -// We define a global macro called 'g'. This can lead to issues when included code uses 'g' as a type or parameter name -// (like protobuf 3.7 does). As such, for now, we have to make this our last include. #include "Global.h" #ifdef Q_CC_GNU @@ -148,7 +145,7 @@ PulseAudioSystem::~PulseAudioSystem() { } QString PulseAudioSystem::outputDevice() const { - QString odev = g.s.qsPulseAudioOutput; + QString odev = Global::get().s.qsPulseAudioOutput; if (odev.isEmpty()) { odev = qsDefaultOutput; } @@ -159,7 +156,7 @@ QString PulseAudioSystem::outputDevice() const { } QString PulseAudioSystem::inputDevice() const { - QString idev = g.s.qsPulseAudioInput; + QString idev = Global::get().s.qsPulseAudioInput; if (idev.isEmpty()) { idev = qsDefaultInput; } @@ -192,8 +189,8 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { if (!bSourceDone || !bSinkDone || !bServerDone) return; - AudioInputPtr ai = g.ai; - AudioOutputPtr ao = g.ao; + AudioInputPtr ai = Global::get().ai; + AudioOutputPtr ao = Global::get().ao; AudioInput *raw_ai = ai.get(); AudioOutput *raw_ao = ao.get(); PulseAudioInput *pai = dynamic_cast< PulseAudioInput * >(raw_ai); @@ -231,7 +228,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { do_start = true; break; case PA_STREAM_READY: { - if (g.s.iOutputDelay != iDelayCache) { + if (Global::get().s.iOutputDelay != iDelayCache) { do_stop = true; } else if (odev != qsOutputCache) { do_stop = true; @@ -252,13 +249,13 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { const pa_sample_spec *pss = m_pulseAudio.stream_get_sample_spec(pasOutput); const size_t sampleSize = (pss->format == PA_SAMPLE_FLOAT32NE) ? sizeof(float) : sizeof(short); const unsigned int iBlockLen = pao->iFrameSize * pss->channels * static_cast< unsigned int >(sampleSize); - buff.tlength = iBlockLen * (g.s.iOutputDelay + 1); + buff.tlength = iBlockLen * (Global::get().s.iOutputDelay + 1); buff.minreq = iBlockLen; buff.maxlength = -1; buff.prebuf = -1; buff.fragsize = iBlockLen; - iDelayCache = g.s.iOutputDelay; + iDelayCache = Global::get().s.iOutputDelay; qsOutputCache = odev; m_pulseAudio.stream_connect_playback(pasOutput, qPrintable(odev), &buff, PA_STREAM_ADJUST_LATENCY, nullptr, @@ -334,9 +331,9 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { bool do_stop = false; bool do_start = false; - if ((!pai || g.s.echoOption == EchoCancelOptionID::DISABLED) && (est == PA_STREAM_READY)) { + if ((!pai || Global::get().s.echoOption == EchoCancelOptionID::DISABLED) && (est == PA_STREAM_READY)) { do_stop = true; - } else if (pai && g.s.echoOption != EchoCancelOptionID::DISABLED) { + } else if (pai && Global::get().s.echoOption != EchoCancelOptionID::DISABLED) { switch (est) { case PA_STREAM_TERMINATED: { if (pasSpeaker) @@ -347,7 +344,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { if ((pss.format != PA_SAMPLE_FLOAT32NE) && (pss.format != PA_SAMPLE_S16NE)) pss.format = PA_SAMPLE_FLOAT32NE; pss.rate = SAMPLE_RATE; - if ((pss.channels == 0) || (g.s.echoOption != EchoCancelOptionID::SPEEX_MULTICHANNEL)) + if ((pss.channels == 0) || (Global::get().s.echoOption != EchoCancelOptionID::SPEEX_MULTICHANNEL)) pss.channels = 1; pasSpeaker = @@ -360,7 +357,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { do_start = true; break; case PA_STREAM_READY: { - if ((g.s.echoOption == EchoCancelOptionID::SPEEX_MULTICHANNEL) != bEchoMultiCache) { + if ((Global::get().s.echoOption == EchoCancelOptionID::SPEEX_MULTICHANNEL) != bEchoMultiCache) { do_stop = true; } else if (edev != qsEchoCache) { do_stop = true; @@ -386,7 +383,7 @@ void PulseAudioSystem::eventCallback(pa_mainloop_api *api, pa_defer_event *) { buff.prebuf = -1; buff.fragsize = iBlockLen; - bEchoMultiCache = (g.s.echoOption == EchoCancelOptionID::SPEEX_MULTICHANNEL); + bEchoMultiCache = (Global::get().s.echoOption == EchoCancelOptionID::SPEEX_MULTICHANNEL); qsEchoCache = edev; m_pulseAudio.stream_connect_record(pasSpeaker, qPrintable(edev), &buff, PA_STREAM_ADJUST_LATENCY); @@ -483,7 +480,7 @@ void PulseAudioSystem::write_stream_callback(pa_stream *s, void *userdata) { } const pa_buffer_attr *bufferAttr; if ((bufferAttr = pa.stream_get_buffer_attr(s))) { - g.ao->setBufferSize(bufferAttr->maxlength); + Global::get().ao->setBufferSize(bufferAttr->maxlength); } pas->wakeup(); } @@ -518,7 +515,7 @@ void PulseAudioSystem::read_callback(pa_stream *s, size_t bytes, void *userdata) return; } - AudioInputPtr ai = g.ai; + AudioInputPtr ai = Global::get().ai; PulseAudioInput *pai = dynamic_cast< PulseAudioInput * >(ai.get()); if (!pai) { if (length > 0) { @@ -569,7 +566,7 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata PulseAudioSystem *pas = reinterpret_cast< PulseAudioSystem * >(userdata); Q_ASSERT(s == pas->pasOutput); - AudioOutputPtr ao = g.ao; + AudioOutputPtr ao = Global::get().ao; PulseAudioOutput *pao = dynamic_cast< PulseAudioOutput * >(ao.get()); if (!pao) { @@ -643,13 +640,13 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata // do we have some mixed output? if (pao->mix(buffer, samples)) { // attenuate if instructed to or it's in settings - pas->bAttenuating = (g.bAttenuateOthers || g.s.bAttenuateOthers); + pas->bAttenuating = (Global::get().bAttenuateOthers || Global::get().s.bAttenuateOthers); } else { memset(buffer, 0, bytes); // attenuate if intructed to (self-activated) - pas->bAttenuating = g.bAttenuateOthers; + pas->bAttenuating = Global::get().bAttenuateOthers; } // if the attenuation state has changed @@ -668,16 +665,16 @@ void PulseAudioSystem::volume_sink_input_list_callback(pa_context *c, const pa_s if (eol == 0) { // If we're using the default of "enable attenuation on all ouputs" and output from an application is // loopbacked, both the loopback and the application will be attenuated leading to double attenuation. - if (!g.s.bOnlyAttenuateSameOutput && pas->iSinkId > -1 && !strcmp(i->driver, "module-loopback.c")) { + if (!Global::get().s.bOnlyAttenuateSameOutput && pas->iSinkId > -1 && !strcmp(i->driver, "module-loopback.c")) { return; } // If we're not attenuating different sinks and the input is not on this sink, don't attenuate. Or, // if the input is a loopback module and connected to Mumble's sink, also ignore it (loopbacks are used to // connect sinks). An attenuated loopback means an indirect application attenuation. - if (g.s.bOnlyAttenuateSameOutput && pas->iSinkId > -1) { + if (Global::get().s.bOnlyAttenuateSameOutput && pas->iSinkId > -1) { if (int(i->sink) != pas->iSinkId || (int(i->sink) == pas->iSinkId && !strcmp(i->driver, "module-loopback.c") - && !g.s.bAttenuateLoopbacks)) { + && !Global::get().s.bAttenuateLoopbacks)) { return; } } @@ -691,7 +688,7 @@ void PulseAudioSystem::volume_sink_input_list_callback(pa_context *c, const pa_s patt.normal_volume = i->volume; // calculate the attenuated volume - pa_volume_t adj = static_cast< pa_volume_t >(PA_VOLUME_NORM * g.s.fOtherVolume); + pa_volume_t adj = static_cast< pa_volume_t >(PA_VOLUME_NORM * Global::get().s.fOtherVolume); pa.sw_cvolume_multiply_scalar(&patt.attenuated_volume, &i->volume, adj); // set it on the sink input @@ -908,9 +905,9 @@ const QList< audioDevice > PulseAudioInputRegistrar::getDeviceChoices() { QStringList qlInputDevs = pasys->qhInput.keys(); std::sort(qlInputDevs.begin(), qlInputDevs.end()); - if (qlInputDevs.contains(g.s.qsPulseAudioInput)) { - qlInputDevs.removeAll(g.s.qsPulseAudioInput); - qlInputDevs.prepend(g.s.qsPulseAudioInput); + if (qlInputDevs.contains(Global::get().s.qsPulseAudioInput)) { + qlInputDevs.removeAll(Global::get().s.qsPulseAudioInput); + qlInputDevs.prepend(Global::get().s.qsPulseAudioInput); } foreach (const QString &dev, qlInputDevs) { qlReturn << audioDevice(pasys->qhInput.value(dev), dev); } @@ -940,9 +937,9 @@ const QList< audioDevice > PulseAudioOutputRegistrar::getDeviceChoices() { QStringList qlOutputDevs = pasys->qhOutput.keys(); std::sort(qlOutputDevs.begin(), qlOutputDevs.end()); - if (qlOutputDevs.contains(g.s.qsPulseAudioOutput)) { - qlOutputDevs.removeAll(g.s.qsPulseAudioOutput); - qlOutputDevs.prepend(g.s.qsPulseAudioOutput); + if (qlOutputDevs.contains(Global::get().s.qsPulseAudioOutput)) { + qlOutputDevs.removeAll(Global::get().s.qsPulseAudioOutput); + qlOutputDevs.prepend(Global::get().s.qsPulseAudioOutput); } foreach (const QString &dev, qlOutputDevs) { qlReturn << audioDevice(pasys->qhOutput.value(dev), dev); } |