diff --git a/akode/plugins/alsa_sink/alsa_sink.cpp b/akode/plugins/alsa_sink/alsa_sink.cpp index 2abad2e..501b8ca 100644 --- a/akode/plugins/alsa_sink/alsa_sink.cpp +++ b/akode/plugins/alsa_sink/alsa_sink.cpp @@ -18,7 +18,9 @@ Boston, MA 02110-1301, USA. */ -#include +// #define DEBUG + +#include "akode_debug.h" #include #include @@ -308,4 +310,33 @@ void ALSASink::resume() snd_pcm_pause(m_data->pcm_playback, 0); } +void ALSASink::drop() +{ + if (m_data->error) + { + AKODE_WARN("cannot drop frames because error with sink"); + return; + } + + int err = snd_pcm_drop(m_data->pcm_playback); + if (err < 0) + { + AKODE_WARN("unable to drop frames: " << snd_strerror(err)); + return; + } + + delete[] m_data->buffer; + m_data->buffer = new char[m_data->fragmentSize]; + m_data->filled = 0; + + err = snd_pcm_prepare(m_data->pcm_playback); + if (err < 0) + { + // No need to set error since calling writeFrame() or + // setAudioConfiguration() again. + AKODE_WARN("unable to prepare sink: " << snd_strerror(err)); + return; + } +} + } // namespace diff --git a/akode/plugins/alsa_sink/alsa_sink.h b/akode/plugins/alsa_sink/alsa_sink.h index cd8da4e..845fbcc 100644 --- a/akode/plugins/alsa_sink/alsa_sink.h +++ b/akode/plugins/alsa_sink/alsa_sink.h @@ -43,6 +43,8 @@ public: void pause(); void resume(); + void drop() override; + struct private_data; private: template bool _writeFrame(AudioFrame *frame);