output/wasapi: add field paused
Fixes bogus Delay() results at the start of playback, because Delay() thinks the output is paused.
This commit is contained in:
@@ -239,6 +239,11 @@ class WasapiOutput final : public AudioOutput {
|
|||||||
*/
|
*/
|
||||||
bool is_started;
|
bool is_started;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only valid if the output is open.
|
||||||
|
*/
|
||||||
|
bool paused;
|
||||||
|
|
||||||
std::atomic_flag not_interrupted = true;
|
std::atomic_flag not_interrupted = true;
|
||||||
|
|
||||||
const std::string device_config;
|
const std::string device_config;
|
||||||
@@ -276,6 +281,7 @@ public:
|
|||||||
}
|
}
|
||||||
void Open(AudioFormat &audio_format) override {
|
void Open(AudioFormat &audio_format) override {
|
||||||
com_worker->Async([&]() { DoOpen(audio_format); }).get();
|
com_worker->Async([&]() { DoOpen(audio_format); }).get();
|
||||||
|
paused = false;
|
||||||
}
|
}
|
||||||
void Close() noexcept override;
|
void Close() noexcept override;
|
||||||
std::chrono::steady_clock::duration Delay() const noexcept override;
|
std::chrono::steady_clock::duration Delay() const noexcept override;
|
||||||
@@ -589,6 +595,7 @@ WasapiOutput::DoOpen(AudioFormat &audio_format)
|
|||||||
buffer_size_in_frames, is_exclusive);
|
buffer_size_in_frames, is_exclusive);
|
||||||
|
|
||||||
is_started = false;
|
is_started = false;
|
||||||
|
paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -613,7 +620,7 @@ WasapiOutput::Close() noexcept
|
|||||||
std::chrono::steady_clock::duration
|
std::chrono::steady_clock::duration
|
||||||
WasapiOutput::Delay() const noexcept
|
WasapiOutput::Delay() const noexcept
|
||||||
{
|
{
|
||||||
if (!is_started) {
|
if (paused) {
|
||||||
// idle while paused
|
// idle while paused
|
||||||
return std::chrono::seconds(1);
|
return std::chrono::seconds(1);
|
||||||
}
|
}
|
||||||
@@ -626,6 +633,8 @@ WasapiOutput::Play(const void *chunk, size_t size)
|
|||||||
{
|
{
|
||||||
assert(thread);
|
assert(thread);
|
||||||
|
|
||||||
|
paused = false;
|
||||||
|
|
||||||
not_interrupted.test_and_set();
|
not_interrupted.test_and_set();
|
||||||
|
|
||||||
ConstBuffer<void> input(chunk, size);
|
ConstBuffer<void> input(chunk, size);
|
||||||
@@ -665,6 +674,7 @@ WasapiOutput::Play(const void *chunk, size_t size)
|
|||||||
bool
|
bool
|
||||||
WasapiOutput::Pause()
|
WasapiOutput::Pause()
|
||||||
{
|
{
|
||||||
|
paused = true;
|
||||||
if (is_started) {
|
if (is_started) {
|
||||||
thread->Pause();
|
thread->Pause();
|
||||||
is_started = false;
|
is_started = false;
|
||||||
|
Reference in New Issue
Block a user