Signal buffer event on audio in/out system stop, and force remove all registered audio buffers
This commit is contained in:
parent
9ff891ce71
commit
6a56f42f5d
|
@ -91,9 +91,10 @@ public:
|
||||||
* @param core_timing - The CoreTiming instance
|
* @param core_timing - The CoreTiming instance
|
||||||
* @param session - The device session
|
* @param session - The device session
|
||||||
*
|
*
|
||||||
* @return Is the buffer was released.
|
* @return If any buffer was released.
|
||||||
*/
|
*/
|
||||||
bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session) {
|
bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session,
|
||||||
|
bool force) {
|
||||||
std::scoped_lock l{lock};
|
std::scoped_lock l{lock};
|
||||||
bool buffer_released{false};
|
bool buffer_released{false};
|
||||||
while (registered_count > 0) {
|
while (registered_count > 0) {
|
||||||
|
@ -103,7 +104,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check with the backend if this buffer can be released yet.
|
// Check with the backend if this buffer can be released yet.
|
||||||
if (!session.IsBufferConsumed(buffers[index])) {
|
// If we're shutting down, we don't care if it's been played or not.
|
||||||
|
if (!force && !session.IsBufferConsumed(buffers[index])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,12 @@ void DeviceSession::Stop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceSession::ClearBuffers() {
|
||||||
|
if (stream) {
|
||||||
|
stream->ClearQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
|
void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
|
||||||
for (const auto& buffer : buffers) {
|
for (const auto& buffer : buffers) {
|
||||||
Sink::SinkBuffer new_buffer{
|
Sink::SinkBuffer new_buffer{
|
||||||
|
|
|
@ -90,6 +90,11 @@ public:
|
||||||
*/
|
*/
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear out the underlying audio buffers in the backend stream.
|
||||||
|
*/
|
||||||
|
void ClearBuffers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this device session's volume.
|
* Set this device session's volume.
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,7 +23,6 @@ System::~System() {
|
||||||
void System::Finalize() {
|
void System::Finalize() {
|
||||||
Stop();
|
Stop();
|
||||||
session->Finalize();
|
session->Finalize();
|
||||||
buffer_event->Signal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::StartSession() {
|
void System::StartSession() {
|
||||||
|
@ -102,6 +101,10 @@ Result System::Stop() {
|
||||||
if (state == State::Started) {
|
if (state == State::Started) {
|
||||||
session->Stop();
|
session->Stop();
|
||||||
session->SetVolume(0.0f);
|
session->SetVolume(0.0f);
|
||||||
|
session->ClearBuffers();
|
||||||
|
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||||
|
buffer_event->Signal();
|
||||||
|
}
|
||||||
state = State::Stopped;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +141,7 @@ void System::RegisterBuffers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::ReleaseBuffers() {
|
void System::ReleaseBuffers() {
|
||||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
|
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||||
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
// Signal if any buffer was released, or if none are registered, we need more.
|
// Signal if any buffer was released, or if none are registered, we need more.
|
||||||
|
|
|
@ -24,7 +24,6 @@ System::~System() {
|
||||||
void System::Finalize() {
|
void System::Finalize() {
|
||||||
Stop();
|
Stop();
|
||||||
session->Finalize();
|
session->Finalize();
|
||||||
buffer_event->Signal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view System::GetDefaultOutputDeviceName() const {
|
std::string_view System::GetDefaultOutputDeviceName() const {
|
||||||
|
@ -102,6 +101,10 @@ Result System::Stop() {
|
||||||
if (state == State::Started) {
|
if (state == State::Started) {
|
||||||
session->Stop();
|
session->Stop();
|
||||||
session->SetVolume(0.0f);
|
session->SetVolume(0.0f);
|
||||||
|
session->ClearBuffers();
|
||||||
|
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||||
|
buffer_event->Signal();
|
||||||
|
}
|
||||||
state = State::Stopped;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +141,7 @@ void System::RegisterBuffers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::ReleaseBuffers() {
|
void System::ReleaseBuffers() {
|
||||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
|
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||||
if (signal) {
|
if (signal) {
|
||||||
// Signal if any buffer was released, or if none are registered, we need more.
|
// Signal if any buffer was released, or if none are registered, we need more.
|
||||||
buffer_event->Signal();
|
buffer_event->Signal();
|
||||||
|
|
Loading…
Reference in a new issue