mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Speaker return bytes written and do not wait for queue (#5182)
This commit is contained in:
parent
581cb642ff
commit
ce8091c14e
3 changed files with 9 additions and 9 deletions
|
@ -185,7 +185,7 @@ void I2SAudioSpeaker::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
bool I2SAudioSpeaker::play(const uint8_t *data, size_t length) {
|
||||
size_t I2SAudioSpeaker::play(const uint8_t *data, size_t length) {
|
||||
if (this->state_ != speaker::STATE_RUNNING && this->state_ != speaker::STATE_STARTING) {
|
||||
this->start();
|
||||
}
|
||||
|
@ -197,13 +197,13 @@ bool I2SAudioSpeaker::play(const uint8_t *data, size_t length) {
|
|||
size_t to_send_length = std::min(remaining, BUFFER_SIZE);
|
||||
event.len = to_send_length;
|
||||
memcpy(event.data, data + index, to_send_length);
|
||||
if (xQueueSend(this->buffer_queue_, &event, 100 / portTICK_PERIOD_MS) == pdTRUE) {
|
||||
if (xQueueSend(this->buffer_queue_, &event, 0) != pdTRUE) {
|
||||
return index;
|
||||
}
|
||||
remaining -= to_send_length;
|
||||
index += to_send_length;
|
||||
}
|
||||
App.feed_wdt();
|
||||
}
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
|
||||
} // namespace i2s_audio
|
||||
|
|
|
@ -54,7 +54,7 @@ class I2SAudioSpeaker : public Component, public speaker::Speaker, public I2SAud
|
|||
void start();
|
||||
void stop() override;
|
||||
|
||||
bool play(const uint8_t *data, size_t length) override;
|
||||
size_t play(const uint8_t *data, size_t length) override;
|
||||
|
||||
protected:
|
||||
void start_();
|
||||
|
|
|
@ -12,8 +12,8 @@ enum State : uint8_t {
|
|||
|
||||
class Speaker {
|
||||
public:
|
||||
virtual bool play(const uint8_t *data, size_t length) = 0;
|
||||
virtual bool play(const std::vector<uint8_t> &data) { return this->play(data.data(), data.size()); }
|
||||
virtual size_t play(const uint8_t *data, size_t length) = 0;
|
||||
virtual size_t play(const std::vector<uint8_t> &data) { return this->play(data.data(), data.size()); }
|
||||
|
||||
virtual void stop() = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue