output/alsa: more assertions in class PeriodBuffer

This commit is contained in:
Max Kellermann 2019-06-27 21:34:12 +02:00
parent a92aa0bedc
commit 5b01373356

View File

@ -83,6 +83,8 @@ public:
* which may have been postponed by FillWithSilence(). * which may have been postponed by FillWithSilence().
*/ */
bool IsDrained() const noexcept { bool IsDrained() const noexcept {
assert(IsFull());
/* compare head with capacity, not with tail; this /* compare head with capacity, not with tail; this
method makes only sense if the period is full */ method makes only sense if the period is full */
return head >= capacity; return head >= capacity;
@ -95,6 +97,8 @@ public:
* commit the operation. * commit the operation.
*/ */
uint8_t *GetTail() noexcept { uint8_t *GetTail() noexcept {
assert(!IsFull());
return buffer + tail; return buffer + tail;
} }
@ -105,7 +109,7 @@ public:
* in bytes * in bytes
*/ */
size_t GetSpaceBytes() const noexcept { size_t GetSpaceBytes() const noexcept {
assert(tail <= capacity); assert(!IsFull());
return capacity - tail; return capacity - tail;
} }
@ -159,10 +163,14 @@ public:
* GetHead(). * GetHead().
*/ */
snd_pcm_uframes_t GetFrames(size_t frame_size) const noexcept { snd_pcm_uframes_t GetFrames(size_t frame_size) const noexcept {
assert(IsFull());
return (tail - head) / frame_size; return (tail - head) / frame_size;
} }
void ConsumeBytes(size_t n) noexcept { void ConsumeBytes(size_t n) noexcept {
assert(IsFull());
head += n; head += n;
assert(head <= capacity); assert(head <= capacity);
@ -177,6 +185,8 @@ public:
} }
void ConsumeFrames(snd_pcm_uframes_t n, size_t frame_size) noexcept { void ConsumeFrames(snd_pcm_uframes_t n, size_t frame_size) noexcept {
assert(IsFull());
ConsumeBytes(n * frame_size); ConsumeBytes(n * frame_size);
} }