ESPHome 2025.9.1
Loading...
Searching...
No Matches
encoder.h
Go to the documentation of this file.
1#pragma once
2
3#include "buffer.h"
4#include "camera.h"
5
6namespace esphome::camera {
7
15
17inline const char *to_string(EncoderError error) {
18 switch (error) {
20 return "ENCODER_ERROR_SUCCESS";
22 return "ENCODER_ERROR_SKIP_FRAME";
24 return "ENCODER_ERROR_RETRY_FRAME";
26 return "ENCODER_ERROR_CONFIGURATION";
27 }
28 return "ENCODER_ERROR_INVALID";
29}
30
33 public:
37 virtual bool set_buffer_size(size_t size) = 0;
38
40 virtual uint8_t *get_data() const = 0;
41
43 virtual size_t get_size() const = 0;
44
46 virtual size_t get_max_size() const = 0;
47
48 virtual ~EncoderBuffer() = default;
49};
50
52class Encoder {
53 public:
58 virtual EncoderError encode_pixels(CameraImageSpec *spec, Buffer *pixels) = 0;
59
63
65 virtual void dump_config() = 0;
66 virtual ~Encoder() = default;
67};
68
69} // namespace esphome::camera
Interface for a generic buffer that stores image data.
Definition buffer.h:9
Interface for an encoder buffer supporting resizing and variable-length data.
Definition encoder.h:32
virtual size_t get_size() const =0
Returns number of bytes currently used.
virtual size_t get_max_size() const =0
Returns total allocated buffer size.
virtual uint8_t * get_data() const =0
Returns a pointer to the buffer data.
virtual bool set_buffer_size(size_t size)=0
Sets logical buffer size, reallocates if needed.
virtual ~EncoderBuffer()=default
Interface for image encoders used in a camera pipeline.
Definition encoder.h:52
virtual ~Encoder()=default
virtual void dump_config()=0
Prints the encoder's configuration to the log.
virtual EncoderBuffer * get_output_buffer()=0
Returns the encoder's output buffer.
virtual EncoderError encode_pixels(CameraImageSpec *spec, Buffer *pixels)=0
Encodes pixel data from a previous camera pipeline stage.
EncoderError
Result codes from the encoder used to control camera pipeline flow.
Definition encoder.h:9
@ ENCODER_ERROR_RETRY_FRAME
Retry current frame, after buffer growth or for incremental encoding.
Definition encoder.h:12
@ ENCODER_ERROR_SUCCESS
Encoding succeeded, continue pipeline normally.
Definition encoder.h:10
@ ENCODER_ERROR_CONFIGURATION
Fatal config error, shut down pipeline.
Definition encoder.h:13
@ ENCODER_ERROR_SKIP_FRAME
Skip current frame, try again on next frame.
Definition encoder.h:11
const char * to_string(PixelFormat format)
Returns string name for a given PixelFormat.
Definition camera.h:26
Specification of a caputured camera image.
Definition camera.h:69