mirror of
https://github.com/esphome/esphome.git
synced 2026-05-09 21:28:40 +08:00
Force construction through the `create` method
This commit is contained in:
@@ -212,7 +212,8 @@ std::unique_ptr<RingBufferAudioSource> RingBufferAudioSource::create(
|
||||
if (ring_buffer == nullptr || max_fill_bytes == 0 || alignment_bytes == 0 || alignment_bytes > MAX_ALIGNMENT_BYTES) {
|
||||
return nullptr;
|
||||
}
|
||||
return make_unique<RingBufferAudioSource>(std::move(ring_buffer), max_fill_bytes, alignment_bytes);
|
||||
return std::unique_ptr<RingBufferAudioSource>(
|
||||
new RingBufferAudioSource(std::move(ring_buffer), max_fill_bytes, alignment_bytes));
|
||||
}
|
||||
|
||||
RingBufferAudioSource::~RingBufferAudioSource() {
|
||||
|
||||
@@ -235,10 +235,6 @@ class RingBufferAudioSource : public AudioReadableBuffer {
|
||||
static std::unique_ptr<RingBufferAudioSource> create(std::shared_ptr<ring_buffer::RingBuffer> ring_buffer,
|
||||
size_t max_fill_bytes, uint8_t alignment_bytes = 1);
|
||||
|
||||
explicit RingBufferAudioSource(std::shared_ptr<ring_buffer::RingBuffer> ring_buffer, size_t max_fill_bytes,
|
||||
uint8_t alignment_bytes)
|
||||
: ring_buffer_(std::move(ring_buffer)), max_fill_bytes_(max_fill_bytes), alignment_bytes_(alignment_bytes) {}
|
||||
|
||||
~RingBufferAudioSource() override;
|
||||
|
||||
// AudioReadableBuffer interface
|
||||
@@ -257,6 +253,12 @@ class RingBufferAudioSource : public AudioReadableBuffer {
|
||||
uint8_t *mutable_data() { return this->current_data_; }
|
||||
|
||||
protected:
|
||||
/// @brief Constructs a new ring-buffer-backed audio source. Use create() instead, which validates
|
||||
/// arguments before construction.
|
||||
explicit RingBufferAudioSource(std::shared_ptr<ring_buffer::RingBuffer> ring_buffer, size_t max_fill_bytes,
|
||||
uint8_t alignment_bytes)
|
||||
: ring_buffer_(std::move(ring_buffer)), max_fill_bytes_(max_fill_bytes), alignment_bytes_(alignment_bytes) {}
|
||||
|
||||
/// @brief Releases the currently held ring buffer item, first copying any trailing sub-frame bytes
|
||||
/// into the splice buffer so they can be stitched with the next chunk.
|
||||
void release_item_();
|
||||
|
||||
Reference in New Issue
Block a user