5#ifdef USE_ESP32_VARIANT_ESP32P4
10#include <freertos/FreeRTOS.h>
11#include <freertos/queue.h>
12#include <freertos/task.h>
14#include <esp_cam_sensor_types.h>
45 return (this->
requesters_ & (1U << requester)) != 0;
57 void set_image(std::shared_ptr<camera::CameraImage> image)
override;
64 std::shared_ptr<camera::CameraImage>
image_;
74 uint8_t bytes_per_pixel, jpeg_enc_input_format_t jpeg_input, jpeg_down_sampling_type_t sub_sample,
75 uint8_t jpeg_quality, uint8_t frame_buffer_count, uint8_t framerate,
uint32_t idle_update_interval,
76 esp_cam_sensor_output_format_t sensor_format)
82 encoder_(jpeg_input, sub_sample, jpeg_quality),
101 void setup()
override;
102 void loop()
override;
113#ifdef USE_MIPI_CSI_IMAGE_CALLBACK
119#ifdef USE_MIPI_CSI_STREAM_CALLBACK
143 void fail_(
const LogString *reason);
153 bool is_better_sensor_format_(
const esp_cam_sensor_format_t &candidate,
const esp_cam_sensor_format_t ¤t)
const;
181#ifdef USE_MIPI_CSI_IMAGE_CALLBACK
184#ifdef USE_MIPI_CSI_STREAM_CALLBACK
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
Abstract camera base class.
Abstract camera image base class.
Abstract image reader base class.
Listener interface for camera events.
ESP32-P4 hardware JPEG encoder with one output buffer: one encoded frame at a time.
MIPI-CSI camera on the ESP32-P4: V4L2 capture through esp_video, JPEG by the hardware encoder.
const char * sensor_name_
MipiCsiCamera(const char *sensor_name, i2c::InternalI2CBus *i2c_bus, uint32_t sccb_frequency, uint32_t fourcc, uint8_t bytes_per_pixel, jpeg_enc_input_format_t jpeg_input, jpeg_down_sampling_type_t sub_sample, uint8_t jpeg_quality, uint8_t frame_buffer_count, uint8_t framerate, uint32_t idle_update_interval, esp_cam_sensor_output_format_t sensor_format)
std::shared_ptr< MipiCsiImage > current_image_
i2c::InternalI2CBus * i2c_bus_
void fail_(const LogString *reason)
Releases everything setup() acquired and marks the component failed.
void set_external_clock(int8_t pin, uint32_t frequency)
CallbackManager< void(bool)> stream_callback_
uint32_t last_idle_request_
void request_image(camera::CameraRequester requester) override
FixedVector< FrameBuffer > buffers_
static constexpr uint8_t FLIP_VERTICAL_ON
std::atomic< uint8_t > single_requesters_
CallbackManager< void(CameraImageData)> image_callback_
std::shared_ptr< MipiCsiImage > reusable_image_
void add_on_stream_callback(F &&callback)
on_stream_start (true) / on_stream_stop (false)
void add_on_image_callback(F &&callback)
on_image: the frame is valid only during the call
camera::CameraListener ** listeners_
std::atomic< bool > frame_wanted_
Set by the main loop to ask the capture task for one frame, cleared by the task when done.
static constexpr uint8_t FLIP_HORIZONTAL_SET
void start_stream(camera::CameraRequester requester) override
std::atomic< uint8_t > stream_requesters_
void for_each_sensor_format_(F &&fn)
Calls fn with every MIPI-CSI format the sensor offers.
camera::CameraImageReader * create_image_reader() override
uint8_t pending_requesters_
Requesters recorded when the frame currently being captured was asked for.
bool has_requested_image_() const
float get_setup_priority() const override
void set_reset_pin(GPIOPin *pin)
bool start_streaming_(size_t frame_size)
QueueHandle_t result_queue_
size_t configure_device_()
Returns the size of one raw frame, or 0 on failure.
bool is_better_sensor_format_(const esp_cam_sensor_format_t &candidate, const esp_cam_sensor_format_t ¤t) const
Ranks two sensor formats of the same resolution against each other.
void set_flip_flags(uint8_t flags)
Bits as in FLIP_*: whether each flip is configured, and its value.
void add_listener(camera::CameraListener *listener) override
static void capture_task(void *param)
void stop_stream(camera::CameraRequester requester) override
bool read_back_format_()
Reads back the format the driver settled on, which the JPEG encoder has to match exactly.
bool select_sensor_format_()
void set_power_pin(GPIOPin *pin)
uint8_t resolve_framerate_(uint8_t sensor_fps) const
Reduces the configured frame rate to one the driver can actually produce.
bool start_external_clock_()
uint8_t reachable_framerate_(uint8_t sensor_fps) const
void apply_control_(uint32_t id, int32_t value, const LogString *name)
Applies a V4L2 user control, logging a warning if the sensor does not support it.
uint8_t sensor_format_
The sensor output that needs no conversion for the configured pixel format.
void dump_config() override
uint32_t idle_update_interval_
static constexpr uint8_t FLIP_HORIZONTAL_ON
uint8_t frame_buffer_count_
static constexpr uint8_t FLIP_VERTICAL_SET
void set_resolution(uint16_t width, uint16_t height)
A JPEG frame in the encoder's buffer; the camera reuses it once every shared_ptr is released.
uint8_t * get_data_buffer() override
bool was_requested_by(camera::CameraRequester requester) const override
void set_frame(uint8_t *data, size_t length, uint8_t requesters)
size_t get_data_length() override
Tracks how far a consumer has read into an image.
size_t available() const override
void return_image() override
void set_image(std::shared_ptr< camera::CameraImage > image) override
void consume_data(size_t consumed) override
std::shared_ptr< camera::CameraImage > image_
uint8_t * peek_data_buffer() override
CameraRequester
Different sources for filtering.
constexpr float LATE
For components that should be initialized at the very end of the setup process.
void * callback_manager_grow(void *data, uint16_t size, uint16_t &capacity, size_t elem_size)
Grow a CallbackManager's backing array to exactly size+1. Defined in helpers.cpp.
uint16_t uint16_t & capacity
Payload handed to the on_image automation.
One V4L2 capture buffer mapped into our address space.