Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions device/observer_rtsp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
32 changes: 32 additions & 0 deletions device/observer_rtsp/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = esp-wrover-kit

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = arduino
monitor_speed = 115200
board_build.f_flash = 80000000L
board_build.flash_mode = qio
build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
lib_deps =
geeksville/Micro-RTSP@^0.1.6

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
lib_deps =
espressif/esp32-camera@^2.0.4
geeksville/Micro-RTSP@^0.1.6
84 changes: 84 additions & 0 deletions device/observer_rtsp/src/camera/cam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <Arduino.h> // needed to include otherwise got 'Serial' not in scope errors
#include "esp_camera.h"
#include "camera/cam.h"
#include "camera/cam_pins.h"

CamManager::CamManager()
: _cam_config{
// --- pins
.pin_pwdn = PWDN_GPIO_NUM,
.pin_reset = RESET_GPIO_NUM,
.pin_xclk = XCLK_GPIO_NUM,
.pin_sscb_sda = SIOD_GPIO_NUM,
.pin_sscb_scl = SIOC_GPIO_NUM,
.pin_d7 = Y9_GPIO_NUM,
.pin_d6 = Y8_GPIO_NUM,
.pin_d5 = Y7_GPIO_NUM,
.pin_d4 = Y6_GPIO_NUM,
.pin_d3 = Y5_GPIO_NUM,
.pin_d2 = Y4_GPIO_NUM,
.pin_d1 = Y3_GPIO_NUM,
.pin_d0 = Y2_GPIO_NUM,
.pin_vsync = VSYNC_GPIO_NUM,
.pin_href = HREF_GPIO_NUM,
.pin_pclk = PCLK_GPIO_NUM,
// --- timers/clocks
.xclk_freq_hz = 20000000, // XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
.ledc_timer = LEDC_TIMER_0,
.ledc_channel = LEDC_CHANNEL_0,
// --- qualtiy settings
.pixel_format = PIXFORMAT_JPEG, // for streaming
.frame_size = FRAMESIZE_SXGA, // sizes: https://randomnerdtutorials.com/esp32-cam-ov2640-camera-settings/
.jpeg_quality = 45, // 1 - 63 (lower numbers higher quality)
// --- buffer refrences
.fb_count = 1, // When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
.fb_location = CAMERA_FB_IN_PSRAM, // trying to fix an init issue (https://github.com/espressif/esp32-camera/issues/571#issuecomment-1726196189)
.grab_mode = CAMERA_GRAB_WHEN_EMPTY,
}
{
}

esp_err_t CamManager::initialize()
{
Serial.println("[CamManager::initialize] esp_camera_init");
// --- init
esp_err_t camera_init_result = esp_camera_init(&_cam_config);
if (camera_init_result != ESP_OK)
{
Serial.println("[CamManager::initialize] esp_camera_init FAILED");
Serial.println(camera_init_result);
}
Serial.println("[CamManager::initialize] initial frame clearing");
// --- clear first buffer: HACK: capture and throw away first frame. common issue with camera initialization/startup. the esp_camera_fb_return'ed a black frame or prior frame in loop below (did in setup, but after a crash doesn't seem to work): https://github.com/espressif/esp32-camera/issues/545#issuecomment-1600335819
esp_camera_fb_return(esp_camera_fb_get());
// --- return esp err/res
return camera_init_result;
}

void CamManager::updateSettings()
{
Serial.println("[CamManager::updateSettings] setting");
sensor_t *s = esp_camera_sensor_get();
s->set_brightness(s, 1);
s->set_saturation(s, 1);
}

camera_fb_t *CamManager::capture()
{
// --- capture
camera_fb_t *fb = esp_camera_fb_get();
if (!fb)
Serial.println("[CamManager::capture] capture FAILED");
else
Serial.println("[CamManager::capture] capture");
// --- return
return fb;
}

void CamManager::release(camera_fb_t *fb)
{
if (fb)
esp_camera_fb_return(fb);
else
Serial.println("[CamManager::release] no frame buffer to release");
}
24 changes: 24 additions & 0 deletions device/observer_rtsp/src/camera/cam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// camera.h
#ifndef __cam_h__
#define __cam_h__

#include "esp_camera.h"

class CamManager
{
public:
// --- constructor
CamManager();
// --- setup/config
esp_err_t initialize();
void updateSettings();
// --- actions
camera_fb_t *capture();
void release(camera_fb_t *fb);

private:
camera_config_t _cam_config;
camera_model_t _cam_model = CAMERA_OV5640;
};

#endif // __cam_h__
Loading