diff --git a/CODEOWNERS b/CODEOWNERS index 53300d6740..df6ba28cd6 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -85,6 +85,7 @@ esphome/components/bmp581/* @kahrendt esphome/components/bp1658cj/* @Cossid esphome/components/bp5758d/* @Cossid esphome/components/button/* @esphome/core +esphome/components/camera/* @DT-art1 esphome/components/canbus/* @danielschramm @mvturnho esphome/components/cap1188/* @mreditor97 esphome/components/captive_portal/* @OttoWinter diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 6d26af714e..06147c20f0 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -42,7 +42,8 @@ APIConnection::APIConnection(std::unique_ptr sock, APIServer *pa #ifdef USE_CAMERA if (camera::Camera::global_camera != nullptr) - this->image_reader_ = std::unique_ptr{camera::Camera::global_camera->create_image_reader()}; + this->image_reader_ = + std::unique_ptr{camera::Camera::global_camera->create_image_reader()}; #endif } void APIConnection::start() { @@ -1074,8 +1075,7 @@ void APIConnection::send_camera_state(std::shared_ptr image return; if (this->image_reader_->available()) return; - if (image->was_requested_by(esphome::camera::API_REQUESTER) || - image->was_requested_by(esphome::camera::IDLE)) + if (image->was_requested_by(esphome::camera::API_REQUESTER) || image->was_requested_by(esphome::camera::IDLE)) this->image_reader_->set_image(std::move(image)); } bool APIConnection::send_camera_info(camera::Camera *camera) { @@ -1099,9 +1099,8 @@ void APIConnection::camera_image(const CameraImageRequest &msg) { if (msg.stream) { camera::Camera::global_camera->start_stream(esphome::camera::API_REQUESTER); - App.scheduler.set_timeout(this->parent_, "api_esp32_camera_stop_stream", ESP32_CAMERA_STOP_STREAM, []() { - camera::Camera::global_camera->stop_stream(esphome::camera::API_REQUESTER); - }); + App.scheduler.set_timeout(this->parent_, "api_esp32_camera_stop_stream", ESP32_CAMERA_STOP_STREAM, + []() { camera::Camera::global_camera->stop_stream(esphome::camera::API_REQUESTER); }); } } #endif diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index b353143e42..309473bbaa 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -82,13 +82,12 @@ void APIServer::setup() { #ifdef USE_CAMERA if (camera::Camera::global_camera != nullptr && !camera::Camera::global_camera->is_internal()) { - camera::Camera::global_camera->add_image_callback( - [this](const std::shared_ptr &image) { - for (auto &c : this->clients_) { - if (!c->remove_) - c->send_camera_state(image); - } - }); + camera::Camera::global_camera->add_image_callback([this](const std::shared_ptr &image) { + for (auto &c : this->clients_) { + if (!c->remove_) + c->send_camera_state(image); + } + }); } #endif } diff --git a/esphome/components/api/list_entities.cpp b/esphome/components/api/list_entities.cpp index 0be0b84745..37aecf517a 100644 --- a/esphome/components/api/list_entities.cpp +++ b/esphome/components/api/list_entities.cpp @@ -51,9 +51,7 @@ bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) { } #ifdef USE_CAMERA -bool ListEntitiesIterator::on_camera(camera::Camera *camera) { - return this->client_->send_camera_info(camera); -} +bool ListEntitiesIterator::on_camera(camera::Camera *camera) { return this->client_->send_camera_info(camera); } #endif #ifdef USE_CLIMATE diff --git a/esphome/components/camera/camera.cpp b/esphome/components/camera/camera.cpp index 680f786d3a..becf3fee2e 100644 --- a/esphome/components/camera/camera.cpp +++ b/esphome/components/camera/camera.cpp @@ -5,9 +5,7 @@ namespace camera { Camera *Camera::global_camera = nullptr; -Camera::Camera() { - global_camera = this; -} +Camera::Camera() { global_camera = this; } } // namespace camera } // namespace esphome diff --git a/esphome/components/camera/camera.h b/esphome/components/camera/camera.h index 4113d456ef..0515b7396a 100644 --- a/esphome/components/camera/camera.h +++ b/esphome/components/camera/camera.h @@ -60,7 +60,7 @@ class Camera : public EntityBase { // Camera implementation invokes callback to publish a new image. virtual void add_image_callback(std::function)> &&callback) = 0; /// Returns a new camera image reader that keeps track of the JPEG data in the camera image. - virtual CameraImageReader* create_image_reader() = 0; + virtual CameraImageReader *create_image_reader() = 0; // Connection, camera or web server requests one new JPEG image. virtual void request_image(CameraRequester requester) = 0; // Connection, camera or web server requests a stream of images. diff --git a/esphome/components/esp32_camera/esp32_camera.cpp b/esphome/components/esp32_camera/esp32_camera.cpp index a9b8c9f261..5e44ea95eb 100644 --- a/esphome/components/esp32_camera/esp32_camera.cpp +++ b/esphome/components/esp32_camera/esp32_camera.cpp @@ -34,7 +34,7 @@ void ESP32Camera::setup() { xTaskCreatePinnedToCore(&ESP32Camera::framebuffer_task, "framebuffer_task", // name 1024, // stack size - this, // task pv params + this, // task pv params 1, // priority nullptr, // handle 1 // core @@ -348,9 +348,7 @@ void ESP32Camera::add_stream_start_callback(std::function &&callback) { void ESP32Camera::add_stream_stop_callback(std::function &&callback) { this->stream_stop_callback_.add(std::move(callback)); } -camera::CameraImageReader* ESP32Camera::create_image_reader() { - return new ESP32CameraImageReader; -} +camera::CameraImageReader *ESP32Camera::create_image_reader() { return new ESP32CameraImageReader; } void ESP32Camera::start_stream(camera::CameraRequester requester) { this->stream_start_callback_.call(); this->stream_requesters_ |= (1U << requester); @@ -388,7 +386,7 @@ void ESP32Camera::update_camera_parameters() { bool ESP32Camera::has_requested_image_() const { return this->single_requesters_ || this->stream_requesters_; } bool ESP32Camera::can_return_image_() const { return this->current_image_.use_count() == 1; } void ESP32Camera::framebuffer_task(void *pv) { - ESP32Camera *that = (ESP32Camera *)pv; + ESP32Camera *that = (ESP32Camera *) pv; while (true) { camera_fb_t *framebuffer = esp_camera_fb_get(); xQueueSend(that->framebuffer_get_queue_, &framebuffer, portMAX_DELAY); @@ -414,7 +412,8 @@ void ESP32CameraImageReader::consume_data(size_t consumed) { this->offset_ += co uint8_t *ESP32CameraImageReader::peek_data_buffer() { return this->image_->get_data_buffer() + this->offset_; } /* ---------------- CameraImage class ---------------- */ -ESP32CameraImage::ESP32CameraImage(camera_fb_t *buffer, uint8_t requesters) : buffer_(buffer), requesters_(requesters) {} +ESP32CameraImage::ESP32CameraImage(camera_fb_t *buffer, uint8_t requesters) + : buffer_(buffer), requesters_(requesters) {} camera_fb_t *ESP32CameraImage::get_raw_buffer() { return this->buffer_; } uint8_t *ESP32CameraImage::get_data_buffer() { return this->buffer_->buf; } diff --git a/esphome/components/esp32_camera/esp32_camera.h b/esphome/components/esp32_camera/esp32_camera.h index d8f0486ea5..076866c4e9 100644 --- a/esphome/components/esp32_camera/esp32_camera.h +++ b/esphome/components/esp32_camera/esp32_camera.h @@ -160,7 +160,8 @@ class ESP32Camera : public Component, public camera::Camera { void add_image_callback(std::function)> &&callback); void add_stream_start_callback(std::function &&callback); void add_stream_stop_callback(std::function &&callback); - camera::CameraImageReader* create_image_reader() override; + camera::CameraImageReader *create_image_reader() override; + protected: /* internal methods */ bool has_requested_image_() const;