mirror of
https://github.com/esphome/esphome.git
synced 2026-02-15 05:57:35 -07:00
Compare commits
1 Commits
camera-rem
...
online-ima
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6273ad6bf8 |
@@ -3,22 +3,18 @@
|
||||
namespace esphome::camera {
|
||||
|
||||
BufferImpl::BufferImpl(size_t size) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
this->data_ = allocator.allocate(size);
|
||||
this->data_ = this->allocator_.allocate(size);
|
||||
this->size_ = size;
|
||||
}
|
||||
|
||||
BufferImpl::BufferImpl(CameraImageSpec *spec) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
this->data_ = allocator.allocate(spec->bytes_per_image());
|
||||
this->data_ = this->allocator_.allocate(spec->bytes_per_image());
|
||||
this->size_ = spec->bytes_per_image();
|
||||
}
|
||||
|
||||
BufferImpl::~BufferImpl() {
|
||||
if (this->data_ != nullptr) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
allocator.deallocate(this->data_, this->size_);
|
||||
}
|
||||
if (this->data_ != nullptr)
|
||||
this->allocator_.deallocate(this->data_, this->size_);
|
||||
}
|
||||
|
||||
} // namespace esphome::camera
|
||||
|
||||
@@ -18,6 +18,7 @@ class BufferImpl : public Buffer {
|
||||
~BufferImpl() override;
|
||||
|
||||
protected:
|
||||
RAMAllocator<uint8_t> allocator_;
|
||||
size_t size_{};
|
||||
uint8_t *data_{};
|
||||
};
|
||||
|
||||
@@ -4,8 +4,7 @@ namespace esphome::camera_encoder {
|
||||
|
||||
bool EncoderBufferImpl::set_buffer_size(size_t size) {
|
||||
if (size > this->capacity_) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
uint8_t *p = allocator.reallocate(this->data_, size);
|
||||
uint8_t *p = this->allocator_.reallocate(this->data_, size);
|
||||
if (p == nullptr)
|
||||
return false;
|
||||
|
||||
@@ -17,10 +16,8 @@ bool EncoderBufferImpl::set_buffer_size(size_t size) {
|
||||
}
|
||||
|
||||
EncoderBufferImpl::~EncoderBufferImpl() {
|
||||
if (this->data_ != nullptr) {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
allocator.deallocate(this->data_, this->capacity_);
|
||||
}
|
||||
if (this->data_ != nullptr)
|
||||
this->allocator_.deallocate(this->data_, this->capacity_);
|
||||
}
|
||||
|
||||
} // namespace esphome::camera_encoder
|
||||
|
||||
@@ -16,6 +16,7 @@ class EncoderBufferImpl : public camera::EncoderBuffer {
|
||||
~EncoderBufferImpl() override;
|
||||
|
||||
protected:
|
||||
RAMAllocator<uint8_t> allocator_;
|
||||
size_t capacity_{};
|
||||
size_t size_{};
|
||||
uint8_t *data_{};
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace esphome::online_image {
|
||||
static const char *const TAG = "online_image.download_buffer";
|
||||
|
||||
DownloadBuffer::DownloadBuffer(size_t size) : size_(size) {
|
||||
this->buffer_ = this->allocator_.allocate(size);
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
this->buffer_ = allocator.allocate(size);
|
||||
this->reset();
|
||||
if (!this->buffer_) {
|
||||
ESP_LOGE(TAG, "Initial allocation of download buffer failed!");
|
||||
@@ -38,15 +39,16 @@ size_t DownloadBuffer::resize(size_t size) {
|
||||
// Avoid useless reallocations; if the buffer is big enough, don't reallocate.
|
||||
return this->size_;
|
||||
}
|
||||
this->allocator_.deallocate(this->buffer_, this->size_);
|
||||
this->buffer_ = this->allocator_.allocate(size);
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
allocator.deallocate(this->buffer_, this->size_);
|
||||
this->buffer_ = allocator.allocate(size);
|
||||
this->reset();
|
||||
if (this->buffer_) {
|
||||
this->size_ = size;
|
||||
return size;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "allocation of %zu bytes failed. Biggest block in heap: %zu Bytes", size,
|
||||
this->allocator_.get_max_free_block_size());
|
||||
allocator.get_max_free_block_size());
|
||||
this->size_ = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@ namespace esphome::online_image {
|
||||
class DownloadBuffer {
|
||||
public:
|
||||
DownloadBuffer(size_t size);
|
||||
~DownloadBuffer() { this->allocator_.deallocate(this->buffer_, this->size_); }
|
||||
~DownloadBuffer() {
|
||||
RAMAllocator<uint8_t> allocator;
|
||||
allocator.deallocate(this->buffer_, this->size_);
|
||||
}
|
||||
|
||||
uint8_t *data(size_t offset = 0);
|
||||
uint8_t *append() { return this->data(this->unread_); }
|
||||
@@ -34,7 +37,6 @@ class DownloadBuffer {
|
||||
size_t resize(size_t size);
|
||||
|
||||
protected:
|
||||
RAMAllocator<uint8_t> allocator_{};
|
||||
uint8_t *buffer_;
|
||||
size_t size_;
|
||||
/** Total number of downloaded bytes not yet read. */
|
||||
|
||||
Reference in New Issue
Block a user