Merge pull request #8878 from Kelebek1/remove_pause

Remove pause callbacks from coretiming
This commit is contained in:
bunnei 2022-09-15 13:50:13 -07:00 committed by GitHub
commit e85bda5f31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 29 additions and 144 deletions

View file

@ -129,20 +129,13 @@ public:
* Default false.
*/
void Start(bool resume = false) override {
if (!ctx) {
if (!ctx || !paused) {
return;
}
if (resume && was_playing) {
if (cubeb_stream_start(stream_backend) != CUBEB_OK) {
LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream");
}
paused = false;
} else if (!resume) {
if (cubeb_stream_start(stream_backend) != CUBEB_OK) {
LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream");
}
paused = false;
paused = false;
if (cubeb_stream_start(stream_backend) != CUBEB_OK) {
LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream");
}
}
@ -151,16 +144,15 @@ public:
*/
void Stop() override {
Unstall();
if (!ctx) {
if (!ctx || paused) {
return;
}
paused = true;
if (cubeb_stream_stop(stream_backend) != CUBEB_OK) {
LOG_CRITICAL(Audio_Sink, "Error stopping cubeb stream");
}
was_playing.store(!paused);
paused = true;
}
private:
@ -286,18 +278,6 @@ void CubebSink::CloseStreams() {
sink_streams.clear();
}
void CubebSink::PauseStreams() {
for (auto& stream : sink_streams) {
stream->Stop();
}
}
void CubebSink::UnpauseStreams() {
for (auto& stream : sink_streams) {
stream->Start(true);
}
}
f32 CubebSink::GetDeviceVolume() const {
if (sink_streams.empty()) {
return 1.0f;

View file

@ -52,16 +52,6 @@ public:
*/
void CloseStreams() override;
/**
* Pause all streams.
*/
void PauseStreams() override;
/**
* Unpause all streams.
*/
void UnpauseStreams() override;
/**
* Get the device volume. Set from calls to the IAudioDevice service.
*

View file

@ -44,8 +44,6 @@ public:
void CloseStream(SinkStream*) override {}
void CloseStreams() override {}
void PauseStreams() override {}
void UnpauseStreams() override {}
f32 GetDeviceVolume() const override {
return 1.0f;
}

View file

@ -108,17 +108,12 @@ public:
* Default false.
*/
void Start(bool resume = false) override {
if (device == 0) {
if (device == 0 || !paused) {
return;
}
if (resume && was_playing) {
SDL_PauseAudioDevice(device, 0);
paused = false;
} else if (!resume) {
SDL_PauseAudioDevice(device, 0);
paused = false;
}
paused = false;
SDL_PauseAudioDevice(device, 0);
}
/**
@ -126,11 +121,11 @@ public:
*/
void Stop() override {
Unstall();
if (device == 0) {
if (device == 0 || paused) {
return;
}
SDL_PauseAudioDevice(device, 1);
paused = true;
SDL_PauseAudioDevice(device, 1);
}
private:
@ -207,18 +202,6 @@ void SDLSink::CloseStreams() {
sink_streams.clear();
}
void SDLSink::PauseStreams() {
for (auto& stream : sink_streams) {
stream->Stop();
}
}
void SDLSink::UnpauseStreams() {
for (auto& stream : sink_streams) {
stream->Start();
}
}
f32 SDLSink::GetDeviceVolume() const {
if (sink_streams.empty()) {
return 1.0f;

View file

@ -50,16 +50,6 @@ public:
*/
void CloseStreams() override;
/**
* Pause all streams.
*/
void PauseStreams() override;
/**
* Unpause all streams.
*/
void UnpauseStreams() override;
/**
* Get the device volume. Set from calls to the IAudioDevice service.
*

View file

@ -39,16 +39,6 @@ public:
*/
virtual void CloseStreams() = 0;
/**
* Pause all streams.
*/
virtual void PauseStreams() = 0;
/**
* Unpause all streams.
*/
virtual void UnpauseStreams() = 0;
/**
* Create a new sink stream, kept within this sink, with a pointer returned for use.
* Do not free the returned pointer. When done with the stream, call CloseStream on the sink.

View file

@ -143,6 +143,12 @@ void SinkStream::ProcessAudioIn(std::span<const s16> input_buffer, std::size_t n
const std::size_t frame_size_bytes = frame_size * sizeof(s16);
size_t frames_written{0};
// If we're paused or going to shut down, we don't want to consume buffers as coretiming is
// paused and we'll desync, so just return.
if (system.IsPaused() || system.IsShuttingDown()) {
return;
}
if (queued_buffers > max_queue_size) {
Stall();
}
@ -193,6 +199,16 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
const std::size_t frame_size_bytes = frame_size * sizeof(s16);
size_t frames_written{0};
// If we're paused or going to shut down, we don't want to consume buffers as coretiming is
// paused and we'll desync, so just play silence.
if (system.IsPaused() || system.IsShuttingDown()) {
constexpr std::array<s16, 6> silence{};
for (size_t i = frames_written; i < num_frames; i++) {
std::memcpy(&output_buffer[i * frame_size], &silence[0], frame_size_bytes);
}
return;
}
// Due to many frames being queued up with nvdec (5 frames or so?), a lot of buffers also get
// queued up (30+) but not all at once, which causes constant stalling here, so just let the
// video play out without attempting to stall.

View file

@ -220,8 +220,6 @@ protected:
u32 device_channels{2};
/// Is this stream currently paused?
std::atomic<bool> paused{true};
/// Was this stream previously playing?
std::atomic<bool> was_playing{false};
/// Name of this stream
std::string name{};