diff options
Diffstat (limited to 'Audio/soundin.cpp')
| -rw-r--r-- | Audio/soundin.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/Audio/soundin.cpp b/Audio/soundin.cpp index 89d86782..24844864 100644 --- a/Audio/soundin.cpp +++ b/Audio/soundin.cpp @@ -21,10 +21,12 @@ bool SoundInput::checkStream () switch (m_stream->error ()) { case QAudio::OpenError: + if (!m_destroying) clearStreamDescriptor (); Q_EMIT error (tr ("An error opening the audio input device has occurred.")); break; case QAudio::IOError: + if (!m_destroying) clearStreamDescriptor (); Q_EMIT error (tr ("An error occurred during read from the audio input device.")); break; @@ -33,6 +35,7 @@ bool SoundInput::checkStream () // break; case QAudio::FatalError: + if (!m_destroying) clearStreamDescriptor (); Q_EMIT error (tr ("Non-recoverable error, audio input device not usable at this time.")); break; @@ -46,6 +49,29 @@ bool SoundInput::checkStream () return result; } +void SoundInput::publishStreamDescriptor () +{ + if (!m_stream) + { + return; + } + + auto descriptor = audioStreamDescriptorFromQAudioFormat (m_stream->format ()); + if (descriptor.isValid ()) + { + descriptor.clock_domain = + AudioStreamDescriptor::ClockDomain::DeviceClock; + descriptor.timing_evidence = + AudioStreamDescriptor::TimingEvidence::PositionCountable; + descriptor.can_report_discontinuities = false; + setStreamDescriptor (descriptor); + } + else + { + LOG_WARN ("Opened input audio stream has an unrecognized format"); + } +} + void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, AudioDevice * sink , unsigned downSampleFactor, AudioDevice::Channel channel) { @@ -53,6 +79,11 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi stop (); + if (device.isNull ()) + { + return; + } + m_sink = sink; QAudioFormat format (device.preferredFormat()); @@ -95,8 +126,12 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi if (m_sink->initialize (QIODevice::WriteOnly, channel)) { m_stream->start (sink); - checkStream (); + auto const stream_ok = checkStream (); cummulative_lost_usec_ = -1; + if (stream_ok) + { + publishStreamDescriptor (); + } // LOG_DEBUG ("Selected buffer size (bytes): " << m_stream->bufferSize () << " period size: " << m_stream->periodSize ()); } else @@ -127,7 +162,10 @@ void SoundInput::resume () { // m_stream->resume (); m_stream->start (m_sink); // better stop and restart audio (fixes issues on Linux and macOS) - checkStream (); + if (checkStream ()) + { + publishStreamDescriptor (); + } } } @@ -208,9 +246,11 @@ void SoundInput::stop() m_stream->stop (); } m_stream.reset (); + if (!m_destroying) clearStreamDescriptor (); } SoundInput::~SoundInput () { + m_destroying = true; stop (); } |
