Implement ALSASink::drop()

Signed-off-by: mio <stigma@disroot.org>
issue/4/reduce-alsa-delay
mio 2 weeks ago
parent b52b99781a
commit 433470e252

@ -18,7 +18,9 @@
Boston, MA 02110-1301, USA.
*/
#include <iostream>
// #define DEBUG
#include "akode_debug.h"
#include <alsa/asoundlib.h>
#include <alsa/pcm.h>
@ -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

@ -43,6 +43,8 @@ public:
void pause();
void resume();
void drop() override;
struct private_data;
private:
template<class T> bool _writeFrame(AudioFrame *frame);

Loading…
Cancel
Save