arduino-audio-tools
Loading...
Searching...
No Matches
CameraFrameSourceTinyCamera.h
Go to the documentation of this file.
1#pragma once
3#include "TinyCamera.h"
4
5namespace audio_tools {
6
27 public:
29
33 bool begin(const camera_config_t &config, float fps) {
34 info.fps = fps;
35 if (!camera_.begin(config)) return false;
36 tiny_camera::TinyCameraFrame probe = camera_.captureFrame();
37 if (!probe) {
38 LOGE("CameraFrameSourceTinyCamera: probe capture failed");
39 return false;
40 }
41 info.width = probe.width();
42 info.height = probe.height();
43 info.format = toVideoFormat(probe.format());
44 info.frame_size = videoFrameSizeBytes(info.format, info.width, info.height);
45 LOGI("CameraFrameSourceTinyCamera: %dx%d, format %d", (int)info.width,
46 (int)info.height, (int)info.format);
47 return true;
48 }
49
51 void end() {
52 frame_.release();
53 camera_.end();
54 }
55
58 const uint8_t *nextFrame(size_t &len) override {
59 frame_.release();
60 frame_ = camera_.captureFrame();
61 if (!frame_) {
62 len = 0;
63 return nullptr;
64 }
65 len = frame_.size();
66 return frame_.data();
67 }
68
70 VideoInfo videoInfo() override { return info; }
71
73 tiny_camera::TinyCamera &camera() { return camera_; }
74
75 protected:
76 tiny_camera::TinyCamera camera_;
77 tiny_camera::TinyCameraFrame frame_;
79
80 static VideoFormat toVideoFormat(pixformat_t format) {
81 switch (format) {
82 case PIXFORMAT_RGB565:
84 case PIXFORMAT_YUV422:
86 case PIXFORMAT_JPEG:
87 return VideoFormat::MJPEG;
88#if defined(TINY_CAMERA_ESP_VIDEO)
89 case PIXFORMAT_RGB888:
91#endif
92 default:
94 }
95 }
96};
97
98} // namespace audio_tools
#define LOGI(...)
#define LOGE(...)
static VideoFormat toVideoFormat(pixformat_t format)
Definition CameraFrameSourceTinyCamera.h:80
VideoInfo videoInfo() override
Width/height/format determined by begin(), and the fps given to it.
Definition CameraFrameSourceTinyCamera.h:70
bool begin(const camera_config_t &config, float fps)
Definition CameraFrameSourceTinyCamera.h:33
tiny_camera::TinyCameraFrame frame_
Definition CameraFrameSourceTinyCamera.h:77
const uint8_t * nextFrame(size_t &len) override
Definition CameraFrameSourceTinyCamera.h:58
tiny_camera::TinyCamera camera_
Definition CameraFrameSourceTinyCamera.h:76
VideoInfo info
Definition CameraFrameSourceTinyCamera.h:78
tiny_camera::TinyCamera & camera()
Access to the camera, e.g. for sensor tuning (camera().sensor()).
Definition CameraFrameSourceTinyCamera.h:73
void end()
Returns the last captured frame (if any) and releases the camera.
Definition CameraFrameSourceTinyCamera.h:51
Pull-based provider of one already-encoded video/image frame at a time - e.g. wraps a camera capture ...
Definition Video.h:92
VideoFormat
Video codec/pixel-format identifier, shared by two unrelated uses: the (single) video stream of a con...
Definition VideoOutput.h:29
size_t videoFrameSizeBytes(VideoFormat format, uint16_t width, uint16_t height)
Fixed per-frame size (bytes) for a raw/uncompressed VideoFormat at the given resolution - 0 for compr...
Definition Video.h:27
@ MJPEG
Definition VideoOutput.h:31
@ RGB888
Definition VideoOutput.h:37
@ RGB565
Definition VideoOutput.h:35
@ UNKNOWN
Definition VideoOutput.h:40
@ YUV422
Definition VideoOutput.h:34
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
Basic video information (width/height/codec/frame size), analogous to AudioInfo - common to both Demu...
Definition VideoOutput.h:49