output/pipewire: replace usleep() with with pw_thread_loop_wait()
This commit is contained in:
@@ -44,7 +44,7 @@
|
|||||||
class PipeWireOutput final : AudioOutput {
|
class PipeWireOutput final : AudioOutput {
|
||||||
const char *const name;
|
const char *const name;
|
||||||
|
|
||||||
struct pw_thread_loop *thread_loop;
|
struct pw_thread_loop *thread_loop = nullptr;
|
||||||
struct pw_stream *stream;
|
struct pw_stream *stream;
|
||||||
|
|
||||||
std::byte buffer[1024];
|
std::byte buffer[1024];
|
||||||
@@ -56,7 +56,7 @@ class PipeWireOutput final : AudioOutput {
|
|||||||
|
|
||||||
const uint32_t target_id;
|
const uint32_t target_id;
|
||||||
|
|
||||||
volatile bool interrupted;
|
bool interrupted;
|
||||||
|
|
||||||
explicit PipeWireOutput(const ConfigBlock &block);
|
explicit PipeWireOutput(const ConfigBlock &block);
|
||||||
|
|
||||||
@@ -91,7 +91,12 @@ private:
|
|||||||
void Close() noexcept override;
|
void Close() noexcept override;
|
||||||
|
|
||||||
void Interrupt() noexcept override {
|
void Interrupt() noexcept override {
|
||||||
|
if (thread_loop == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const PipeWire::ThreadLoopLock lock(thread_loop);
|
||||||
interrupted = true;
|
interrupted = true;
|
||||||
|
pw_thread_loop_signal(thread_loop, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Play(const void *chunk, size_t size) override;
|
size_t Play(const void *chunk, size_t size) override;
|
||||||
@@ -125,6 +130,7 @@ void
|
|||||||
PipeWireOutput::Disable() noexcept
|
PipeWireOutput::Disable() noexcept
|
||||||
{
|
{
|
||||||
pw_thread_loop_destroy(thread_loop);
|
pw_thread_loop_destroy(thread_loop);
|
||||||
|
thread_loop = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr enum spa_audio_format
|
static constexpr enum spa_audio_format
|
||||||
@@ -261,11 +267,15 @@ PipeWireOutput::Process() noexcept
|
|||||||
buf->datas[0].chunk->size = nbytes;
|
buf->datas[0].chunk->size = nbytes;
|
||||||
|
|
||||||
pw_stream_queue_buffer(stream, b);
|
pw_stream_queue_buffer(stream, b);
|
||||||
|
|
||||||
|
pw_thread_loop_signal(thread_loop, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
PipeWireOutput::Play(const void *chunk, size_t size)
|
PipeWireOutput::Play(const void *chunk, size_t size)
|
||||||
{
|
{
|
||||||
|
const PipeWire::ThreadLoopLock lock(thread_loop);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std::size_t bytes_written =
|
std::size_t bytes_written =
|
||||||
ring_buffer->push((const std::byte *)chunk, size);
|
ring_buffer->push((const std::byte *)chunk, size);
|
||||||
@@ -275,7 +285,7 @@ PipeWireOutput::Play(const void *chunk, size_t size)
|
|||||||
if (interrupted)
|
if (interrupted)
|
||||||
throw AudioOutputInterrupted{};
|
throw AudioOutputInterrupted{};
|
||||||
|
|
||||||
usleep(1000); // TODO
|
pw_thread_loop_wait(thread_loop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user