Commit ddabe1a6 authored by Max Kellermann's avatar Max Kellermann

output/alsa: add "noexcept"

parent e7b47ce3
...@@ -165,7 +165,7 @@ class AlsaOutput final ...@@ -165,7 +165,7 @@ class AlsaOutput final
PeriodBuffer(const PeriodBuffer &) = delete; PeriodBuffer(const PeriodBuffer &) = delete;
PeriodBuffer &operator=(const PeriodBuffer &) = delete; PeriodBuffer &operator=(const PeriodBuffer &) = delete;
void Allocate(size_t n_frames, size_t frame_size) { void Allocate(size_t n_frames, size_t frame_size) noexcept {
capacity = n_frames * frame_size; capacity = n_frames * frame_size;
/* reserve space for one more (partial) frame, /* reserve space for one more (partial) frame,
...@@ -176,29 +176,29 @@ class AlsaOutput final ...@@ -176,29 +176,29 @@ class AlsaOutput final
head = tail = 0; head = tail = 0;
} }
void Free() { void Free() noexcept {
delete[] buffer; delete[] buffer;
} }
bool IsEmpty() const { bool IsEmpty() const noexcept {
return head == tail; return head == tail;
} }
bool IsFull() const { bool IsFull() const noexcept {
return tail >= capacity; return tail >= capacity;
} }
uint8_t *GetTail() { uint8_t *GetTail() noexcept {
return buffer + tail; return buffer + tail;
} }
size_t GetSpaceBytes() const { size_t GetSpaceBytes() const noexcept {
assert(tail <= capacity); assert(tail <= capacity);
return capacity - tail; return capacity - tail;
} }
void AppendBytes(size_t n) { void AppendBytes(size_t n) noexcept {
assert(n <= capacity); assert(n <= capacity);
assert(tail <= capacity - n); assert(tail <= capacity - n);
...@@ -206,7 +206,7 @@ class AlsaOutput final ...@@ -206,7 +206,7 @@ class AlsaOutput final
} }
void FillWithSilence(const uint8_t *_silence, void FillWithSilence(const uint8_t *_silence,
const size_t frame_size) { const size_t frame_size) noexcept {
size_t partial_frame = tail % frame_size; size_t partial_frame = tail % frame_size;
auto *dest = GetTail() - partial_frame; auto *dest = GetTail() - partial_frame;
...@@ -219,15 +219,15 @@ class AlsaOutput final ...@@ -219,15 +219,15 @@ class AlsaOutput final
tail = capacity + partial_frame; tail = capacity + partial_frame;
} }
const uint8_t *GetHead() const { const uint8_t *GetHead() const noexcept {
return buffer + head; return buffer + head;
} }
snd_pcm_uframes_t GetFrames(size_t frame_size) const { snd_pcm_uframes_t GetFrames(size_t frame_size) const noexcept {
return (tail - head) / frame_size; return (tail - head) / frame_size;
} }
void ConsumeBytes(size_t n) { void ConsumeBytes(size_t n) noexcept {
head += n; head += n;
assert(head <= capacity); assert(head <= capacity);
...@@ -241,19 +241,19 @@ class AlsaOutput final ...@@ -241,19 +241,19 @@ class AlsaOutput final
} }
} }
void ConsumeFrames(snd_pcm_uframes_t n, size_t frame_size) { void ConsumeFrames(snd_pcm_uframes_t n, size_t frame_size) noexcept {
ConsumeBytes(n * frame_size); ConsumeBytes(n * frame_size);
} }
snd_pcm_uframes_t GetPeriodPosition(size_t frame_size) const { snd_pcm_uframes_t GetPeriodPosition(size_t frame_size) const noexcept {
return head / frame_size; return head / frame_size;
} }
void Rewind() { void Rewind() noexcept {
head = 0; head = 0;
} }
void Clear() { void Clear() noexcept {
head = tail = 0; head = tail = 0;
} }
}; };
...@@ -277,7 +277,7 @@ class AlsaOutput final ...@@ -277,7 +277,7 @@ class AlsaOutput final
public: public:
AlsaOutput(EventLoop &loop, const ConfigBlock &block); AlsaOutput(EventLoop &loop, const ConfigBlock &block);
~AlsaOutput() { ~AlsaOutput() noexcept {
/* free libasound's config cache */ /* free libasound's config cache */
snd_config_update_free_global(); snd_config_update_free_global();
} }
...@@ -324,7 +324,7 @@ private: ...@@ -324,7 +324,7 @@ private:
* has no effect; nothing will be played, and no code will be * has no effect; nothing will be played, and no code will be
* run on #EventLoop's thread. * run on #EventLoop's thread.
*/ */
void Activate() { void Activate() noexcept {
if (active) if (active)
return; return;
...@@ -336,7 +336,7 @@ private: ...@@ -336,7 +336,7 @@ private:
* Wrapper for Activate() which unlocks our mutex. Call this * Wrapper for Activate() which unlocks our mutex. Call this
* if you're holding the mutex. * if you're holding the mutex.
*/ */
void UnlockActivate() { void UnlockActivate() noexcept {
if (active) if (active)
return; return;
...@@ -344,12 +344,12 @@ private: ...@@ -344,12 +344,12 @@ private:
Activate(); Activate();
} }
void ClearRingBuffer() { void ClearRingBuffer() noexcept {
std::array<uint8_t, 1024> buffer; std::array<uint8_t, 1024> buffer;
while (ring_buffer->pop(&buffer.front(), buffer.size())) {} while (ring_buffer->pop(&buffer.front(), buffer.size())) {}
} }
int Recover(int err); int Recover(int err) noexcept;
/** /**
* Drain all buffers. To be run in #EventLoop's thread. * Drain all buffers. To be run in #EventLoop's thread.
...@@ -357,15 +357,15 @@ private: ...@@ -357,15 +357,15 @@ private:
* @return true if draining is complete, false if this method * @return true if draining is complete, false if this method
* needs to be called again later * needs to be called again later
*/ */
bool DrainInternal(); bool DrainInternal() noexcept;
/** /**
* Stop playback immediately, dropping all buffers. To be run * Stop playback immediately, dropping all buffers. To be run
* in #EventLoop's thread. * in #EventLoop's thread.
*/ */
void CancelInternal(); void CancelInternal() noexcept;
void CopyRingToPeriodBuffer() { void CopyRingToPeriodBuffer() noexcept {
if (period_buffer.IsFull()) if (period_buffer.IsFull())
return; return;
...@@ -382,7 +382,7 @@ private: ...@@ -382,7 +382,7 @@ private:
cond.signal(); cond.signal();
} }
snd_pcm_sframes_t WriteFromPeriodBuffer() { snd_pcm_sframes_t WriteFromPeriodBuffer() noexcept {
assert(!period_buffer.IsEmpty()); assert(!period_buffer.IsEmpty());
auto frames_written = snd_pcm_writei(pcm, period_buffer.GetHead(), auto frames_written = snd_pcm_writei(pcm, period_buffer.GetHead(),
...@@ -394,7 +394,7 @@ private: ...@@ -394,7 +394,7 @@ private:
return frames_written; return frames_written;
} }
bool LockHasError() const { bool LockHasError() const noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard<Mutex> lock(mutex);
return !!error; return !!error;
} }
...@@ -1066,7 +1066,7 @@ AlsaOutput::Open(AudioFormat &audio_format) ...@@ -1066,7 +1066,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
} }
inline int inline int
AlsaOutput::Recover(int err) AlsaOutput::Recover(int err) noexcept
{ {
if (err == -EPIPE) { if (err == -EPIPE) {
FormatDebug(alsa_output_domain, FormatDebug(alsa_output_domain,
...@@ -1110,7 +1110,7 @@ AlsaOutput::Recover(int err) ...@@ -1110,7 +1110,7 @@ AlsaOutput::Recover(int err)
} }
inline bool inline bool
AlsaOutput::DrainInternal() AlsaOutput::DrainInternal() noexcept
{ {
if (snd_pcm_state(pcm) != SND_PCM_STATE_RUNNING) { if (snd_pcm_state(pcm) != SND_PCM_STATE_RUNNING) {
CancelInternal(); CancelInternal();
...@@ -1167,7 +1167,7 @@ AlsaOutput::Drain() ...@@ -1167,7 +1167,7 @@ AlsaOutput::Drain()
} }
inline void inline void
AlsaOutput::CancelInternal() AlsaOutput::CancelInternal() noexcept
{ {
must_prepare = true; must_prepare = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment