2020-05-03 17:37:12 +01:00
|
|
|
/*
|
2021-01-27 09:38:45 +00:00
|
|
|
xdrv_81_esp32_webcam.ino - ESP32 webcam support for Tasmota
|
2020-05-03 17:37:12 +01:00
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Gerhard Mutz and Theo Arends
|
2020-05-03 17:37:12 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
#ifdef USE_WEBCAM
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* ESP32 webcam based on example in Arduino-ESP32 library
|
|
|
|
*
|
|
|
|
* Template as used on ESP32-CAM WiFi + bluetooth Camera Module Development Board ESP32 With Camera Module OV2640 Geekcreit for Arduino
|
2021-03-26 17:30:03 +00:00
|
|
|
* {"NAME":"AITHINKER CAM","GPIO":[4992,1,672,1,416,5088,1,1,1,6720,736,704,1,1,5089,5090,0,5091,5184,5152,0,5120,5024,5056,0,0,0,0,4928,1,5094,5095,5092,0,0,5093],"FLAG":0,"BASE":2}
|
2020-05-03 17:37:12 +01:00
|
|
|
*
|
2020-05-12 13:30:07 +01:00
|
|
|
* Supported commands:
|
2021-12-17 17:01:27 +00:00
|
|
|
* WcInterrupt = Control streaming, 0 = stop, 1 = start
|
2020-05-12 13:30:07 +01:00
|
|
|
* WcResolution = Set resolution
|
2021-02-18 19:37:35 +00:00
|
|
|
0 = FRAMESIZE_96X96, // 96x96
|
|
|
|
1 = FRAMESIZE_QQVGA, // 160x120
|
|
|
|
2 = FRAMESIZE_QCIF, // 176x144
|
|
|
|
3 = FRAMESIZE_HQVGA, // 240x176
|
|
|
|
4 = FRAMESIZE_240X240, // 240x240
|
|
|
|
5 = FRAMESIZE_QVGA, // 320x240
|
|
|
|
6 = FRAMESIZE_CIF, // 400x296
|
|
|
|
7 = FRAMESIZE_HVGA, // 480x320
|
|
|
|
8 = FRAMESIZE_VGA, // 640x480
|
|
|
|
9 = FRAMESIZE_SVGA, // 800x600
|
|
|
|
10 = FRAMESIZE_XGA, // 1024x768
|
|
|
|
11 = FRAMESIZE_HD, // 1280x720
|
|
|
|
12 = FRAMESIZE_SXGA, // 1280x1024
|
|
|
|
13 = FRAMESIZE_UXGA, // 1600x1200
|
|
|
|
// 3MP Sensors above this no yet supported with this driver
|
|
|
|
14 = FRAMESIZE_FHD, // 1920x1080
|
|
|
|
15 = FRAMESIZE_P_HD, // 720x1280
|
|
|
|
16 = FRAMESIZE_P_3MP, // 864x1536
|
|
|
|
17 = FRAMESIZE_QXGA, // 2048x1536
|
|
|
|
// 5MP Sensors
|
|
|
|
18 = FRAMESIZE_QHD, // 2560x1440
|
|
|
|
19 = FRAMESIZE_WQXGA, // 2560x1600
|
|
|
|
20 = FRAMESIZE_P_FHD, // 1080x1920
|
|
|
|
21 = FRAMESIZE_QSXGA, // 2560x1920
|
|
|
|
22 = FRAMESIZE_INVALID
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
* WcMirror = Mirror picture, 0 = no, 1 = yes
|
|
|
|
* WcFlip = Flip picture, 0 = no, 1 = yes
|
|
|
|
* WcSaturation = Set picture Saturation -2 ... +2
|
|
|
|
* WcBrightness = Set picture Brightness -2 ... +2
|
|
|
|
* WcContrast = Set picture Contrast -2 ... +2
|
2022-05-03 23:23:26 +01:00
|
|
|
* WcSpecialEffekt = Set Special Picture Effect: 0 = off, 1 = , 2 = , 3 = , 4 = , 5 = , 6 =
|
2022-04-27 21:37:32 +01:00
|
|
|
* WcAWB = Auto White Balance, 0 = no, 1 = yes
|
|
|
|
* WcWBMode = White Balance Mode, 0 = auto, 1 =
|
|
|
|
* WcAWBGain = Auto White Balance Gain, 0 = no, 1 = yes
|
|
|
|
* WcAEC = Auto exposure control (Sensor), 0 = no, 1 = yes
|
|
|
|
* WcAECDSP = Auto exposure control (DSP), 0 = no, 1 = yes
|
|
|
|
* WcAECValue = Auto exposure control value, 0 ... 1024
|
|
|
|
* WcAECLevel = Auto exposure control level, -2 ... +2
|
|
|
|
* WcAGC = Auto gain control, 0 = no, 1 = yes
|
|
|
|
* WcAGCGain = Auto gain control gain, 0 .. 30
|
|
|
|
* WcGainCeiling = Gain ceiling, 0 .. 6 (0 = x2, 1 = x4, 2 = x8, 3 = x16, 4 = x32, 5 = x64, 6 = x128)
|
|
|
|
* WcGammaCorrect = Auto Gamma Correct, 0 = no, 1 = yes
|
|
|
|
* WcLensCorrect = Auto Lens Correct, 0 = no, 1 = yes
|
|
|
|
* WcWPC = White Pixel Correct, 0 = no, 1 = yes
|
|
|
|
* WcDCW = Downscale, 0 = no, 1 = yes
|
|
|
|
* WcBPC = Black Pixel Correct, 0 = no, 1 = yes
|
|
|
|
* WcColorbar = Show Colorbar, 0 = no, 1 = yes
|
|
|
|
* WcFeature = Set extended Feature, 0 = off, 1 = reduce FPS, 2 = Nightmode
|
|
|
|
* WcStats = Show Statistics
|
|
|
|
* WcInit = Init Camera Interface
|
|
|
|
* WcRtsp = Control RTSP Server, 0=disable, 1=enable (forces restart) (if defined ENABLE_RTSPSERVER)
|
2020-05-04 11:48:42 +01:00
|
|
|
*
|
2022-05-03 23:23:26 +01:00
|
|
|
* WcFeature Explanation
|
|
|
|
* See https://hobbylad.files.wordpress.com/2020/02/ov2640-camera-module-software-application-notes.pdf
|
|
|
|
* for more Information
|
|
|
|
* 0: Normal Operation
|
|
|
|
* 1: Reduced FPS: Set XCLK Divisor to 2. Reduces Framerate and also increases exposure time. This causes
|
|
|
|
* better low light performance. See above document, page 6
|
|
|
|
* 2: Night Mode: Further increase exposure time and lower the Framerate depending on available light.
|
|
|
|
* See above Document, Page 8
|
|
|
|
*
|
2022-05-05 16:30:46 +01:00
|
|
|
* Only boards with PSRAM should be used.
|
|
|
|
* To speed up cam processing cpu frequency should be better set to 240Mhz
|
2022-09-10 11:54:28 +01:00
|
|
|
*
|
2020-05-12 07:14:58 +01:00
|
|
|
* remarks for AI-THINKER
|
|
|
|
* GPIO0 zero must be disconnected from any wire after programming because this pin drives the cam clock and does
|
|
|
|
* not tolerate any capictive load
|
|
|
|
* flash led = gpio 4
|
|
|
|
* red led = gpio 33
|
2021-01-20 07:42:44 +00:00
|
|
|
* optional rtsp url: rtsp://xxx.xxx.xxx.xxx:8554/mjpeg/1
|
2020-05-12 07:14:58 +01:00
|
|
|
*/
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-12 07:14:58 +01:00
|
|
|
/*********************************************************************************************/
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-12 07:14:58 +01:00
|
|
|
#define XDRV_81 81
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2021-12-17 17:01:27 +00:00
|
|
|
#include "cam_hal.h"
|
2020-05-12 13:30:07 +01:00
|
|
|
#include "esp_camera.h"
|
|
|
|
#include "sensor.h"
|
2020-05-05 08:36:43 +01:00
|
|
|
#include "fb_gfx.h"
|
2022-09-10 11:54:28 +01:00
|
|
|
#include "camera_pins.h"
|
2021-11-02 16:00:22 +00:00
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
bool HttpCheckPriviledgedAccess(bool);
|
|
|
|
extern ESP8266WebServer *Webserver;
|
|
|
|
|
|
|
|
#define BOUNDARY "e8b8c539-047d-4777-a985-fbba6edff11e"
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifndef MAX_PICSTORE
|
|
|
|
#define MAX_PICSTORE 4
|
|
|
|
#endif
|
|
|
|
struct PICSTORE {
|
|
|
|
uint8_t *buff;
|
|
|
|
uint32_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
#include <OV2640.h>
|
|
|
|
#include <SimStreamer.h>
|
|
|
|
#include <OV2640Streamer.h>
|
|
|
|
#include <CRtspSession.h>
|
|
|
|
#ifndef RTSP_FRAME_TIME
|
|
|
|
#define RTSP_FRAME_TIME 100
|
|
|
|
#endif // RTSP_FRAME_TIME
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
struct {
|
|
|
|
uint8_t up;
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
uint8_t stream_active;
|
2021-01-20 07:42:44 +00:00
|
|
|
WiFiClient client;
|
|
|
|
ESP8266WebServer *CamServer;
|
|
|
|
struct PICSTORE picstore[MAX_PICSTORE];
|
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
WiFiServer *rtspp;
|
|
|
|
CStreamer *rtsp_streamer;
|
|
|
|
CRtspSession *rtsp_session;
|
|
|
|
WiFiClient rtsp_client;
|
|
|
|
uint8_t rtsp_start;
|
|
|
|
OV2640 cam;
|
|
|
|
uint32_t rtsp_lastframe_time;
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
2020-05-25 16:25:47 +01:00
|
|
|
} Wc;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2022-04-26 23:25:26 +01:00
|
|
|
struct {
|
|
|
|
uint32_t camcnt = 0;
|
|
|
|
uint32_t camfps = 0;
|
|
|
|
uint32_t camfail = 0;
|
|
|
|
uint32_t jpegfail = 0;
|
|
|
|
uint32_t clientfail = 0;
|
|
|
|
char name[7] = "Webcam";
|
|
|
|
} WcStats;
|
|
|
|
|
2021-12-17 17:01:27 +00:00
|
|
|
/*********************************************************************************************/
|
2021-01-20 07:42:44 +00:00
|
|
|
|
2021-12-17 17:01:27 +00:00
|
|
|
void WcInterrupt(uint32_t state) {
|
|
|
|
// Stop camera ISR if active to fix TG1WDT_SYS_RESET
|
|
|
|
if (!Wc.up) { return; }
|
2020-10-19 06:26:42 +01:00
|
|
|
|
2021-12-17 17:01:27 +00:00
|
|
|
if (state) {
|
|
|
|
// Re-enable interrupts
|
|
|
|
cam_start();
|
|
|
|
} else {
|
|
|
|
// Stop interrupts
|
|
|
|
cam_stop();
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 13:30:07 +01:00
|
|
|
|
2020-05-05 17:36:12 +01:00
|
|
|
bool WcPinUsed(void) {
|
|
|
|
bool pin_used = true;
|
|
|
|
for (uint32_t i = 0; i < MAX_WEBCAM_DATA; i++) {
|
|
|
|
if (!PinUsed(GPIO_WEBCAM_DATA, i)) {
|
|
|
|
pin_used = false;
|
|
|
|
}
|
|
|
|
// if (i < MAX_WEBCAM_HSD) {
|
|
|
|
// if (!PinUsed(GPIO_WEBCAM_HSD, i)) {
|
|
|
|
// pin_used = false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
if (!PinUsed(GPIO_WEBCAM_XCLK) || !PinUsed(GPIO_WEBCAM_PCLK) ||
|
|
|
|
!PinUsed(GPIO_WEBCAM_VSYNC) || !PinUsed(GPIO_WEBCAM_HREF) ||
|
2022-10-29 19:13:00 +01:00
|
|
|
((!PinUsed(GPIO_WEBCAM_SIOD) || !PinUsed(GPIO_WEBCAM_SIOC)) && !TasmotaGlobal.i2c_enabled_2) // preferred option is to reuse and share I2Cbus 2
|
|
|
|
) {
|
|
|
|
pin_used = false;
|
2020-05-05 17:36:12 +01:00
|
|
|
}
|
|
|
|
return pin_used;
|
|
|
|
}
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
void WcFeature(int32_t value) {
|
|
|
|
sensor_t * wc_s = esp_camera_sensor_get();
|
2022-04-26 23:25:26 +01:00
|
|
|
if (!wc_s) { return; }
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
if (value != 1) {
|
|
|
|
// CLKRC: Set Clock Divider to 0 = fullspeed
|
|
|
|
wc_s->set_reg(wc_s, 0x111, 0x3f, 0x00);
|
|
|
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
|
|
|
}
|
|
|
|
if (value != 2) {
|
|
|
|
// Stop Nightmode
|
|
|
|
wc_s->set_reg(wc_s, 0x103, 0xff, 0x0a); // COM1: Reset dummy frames
|
|
|
|
wc_s->set_reg(wc_s, 0x10f, 0xff, 0x43); // Reserved Reg
|
|
|
|
wc_s->set_reg(wc_s, 0x10f, 0xff, 0x4b); // Reserved Reg
|
|
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
|
|
wc_s->set_reg(wc_s, 0x10f, 0xff, 0x43); // Reserved Reg
|
2022-04-26 23:25:26 +01:00
|
|
|
}
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
switch(value) {
|
|
|
|
case 1:
|
|
|
|
// Reduce FPS
|
|
|
|
// CLKRC: Set Clock Divider to 2
|
|
|
|
wc_s->set_reg(wc_s, 0x111, 0x3f, 0x02);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// Start Nightmode
|
|
|
|
wc_s->set_reg(wc_s, 0x10f, 0xff, 0x4b); // Reserved Reg
|
|
|
|
wc_s->set_reg(wc_s, 0x103, 0xff, 0xcf); // COM1: Allow 7 dummy frames
|
|
|
|
break;
|
2022-04-26 23:25:26 +01:00
|
|
|
}
|
2022-04-27 21:37:32 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Feature: %d"), value);
|
2022-04-26 23:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WcApplySettings() {
|
|
|
|
sensor_t * wc_s = esp_camera_sensor_get();
|
|
|
|
if (!wc_s) { return; }
|
|
|
|
|
|
|
|
wc_s->set_vflip(wc_s, Settings->webcam_config.flip);
|
|
|
|
wc_s->set_hmirror(wc_s, Settings->webcam_config.mirror);
|
|
|
|
|
|
|
|
wc_s->set_brightness(wc_s, Settings->webcam_config.brightness - 2);
|
|
|
|
wc_s->set_saturation(wc_s, Settings->webcam_config.saturation - 2);
|
|
|
|
wc_s->set_contrast(wc_s, Settings->webcam_config.contrast - 2);
|
|
|
|
|
|
|
|
wc_s->set_special_effect(wc_s, Settings->webcam_config2.special_effect);
|
|
|
|
|
|
|
|
wc_s->set_whitebal(wc_s, Settings->webcam_config.awb);
|
|
|
|
wc_s->set_wb_mode(wc_s, Settings->webcam_config2.wb_mode);
|
|
|
|
wc_s->set_awb_gain(wc_s, Settings->webcam_config.awb_gain);
|
|
|
|
|
|
|
|
wc_s->set_exposure_ctrl(wc_s, Settings->webcam_config.aec);
|
|
|
|
wc_s->set_aec_value(wc_s, Settings->webcam_config2.aec_value - 2);
|
|
|
|
wc_s->set_ae_level(wc_s, Settings->webcam_config2.ae_level);
|
|
|
|
wc_s->set_aec2(wc_s, Settings->webcam_config.aec2);
|
|
|
|
|
|
|
|
wc_s->set_gain_ctrl(wc_s, Settings->webcam_config.agc);
|
|
|
|
wc_s->set_agc_gain(wc_s, Settings->webcam_config2.agc_gain);
|
|
|
|
wc_s->set_gainceiling(wc_s, (gainceiling_t)Settings->webcam_config2.gainceiling);
|
|
|
|
|
|
|
|
wc_s->set_raw_gma(wc_s, Settings->webcam_config.raw_gma);
|
|
|
|
wc_s->set_lenc(wc_s, Settings->webcam_config.lenc);
|
|
|
|
wc_s->set_wpc(wc_s, Settings->webcam_config.wpc);
|
|
|
|
wc_s->set_dcw(wc_s, Settings->webcam_config.dcw);
|
|
|
|
wc_s->set_bpc(wc_s, Settings->webcam_config.bpc);
|
2022-04-27 21:37:32 +01:00
|
|
|
|
2022-05-05 15:26:29 +01:00
|
|
|
WcFeature(Settings->webcam_config.feature);
|
2022-04-26 23:25:26 +01:00
|
|
|
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Settings updated"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WcSetDefaults(uint32_t upgrade) {
|
|
|
|
if (!upgrade) {
|
|
|
|
Settings->webcam_config.flip = 0;
|
|
|
|
Settings->webcam_config.mirror = 0;
|
|
|
|
|
|
|
|
Settings->webcam_config.saturation = 2; // = 0
|
|
|
|
Settings->webcam_config.brightness = 2; // = 0
|
|
|
|
Settings->webcam_config.contrast = 2; // = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->webcam_config2.special_effect = 0;
|
|
|
|
Settings->webcam_config.colorbar = 0;
|
|
|
|
|
|
|
|
Settings->webcam_config.awb = 1; // white balance
|
|
|
|
Settings->webcam_config2.wb_mode = 0; // white balance mode
|
|
|
|
Settings->webcam_config.awb_gain = 1; // white blance gain
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
Settings->webcam_config.aec = 1; // autoexposure (sensor)
|
|
|
|
Settings->webcam_config.aec2 = 1; // autoexposure (dsp)
|
|
|
|
Settings->webcam_config2.ae_level = 2; // autoexposure level (-2 - +2, default 0)
|
|
|
|
Settings->webcam_config2.aec_value = 204; // manual exposure value
|
2022-04-26 23:25:26 +01:00
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
Settings->webcam_config.agc = 1; // auto gain control
|
|
|
|
Settings->webcam_config2.agc_gain = 5; // manual gain control
|
|
|
|
Settings->webcam_config2.gainceiling = 0; // auto gain ceiling
|
2022-04-26 23:25:26 +01:00
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
Settings->webcam_config.raw_gma = 1; // gamma correct
|
|
|
|
Settings->webcam_config.lenc = 1; // lens correction
|
|
|
|
Settings->webcam_config.wpc = 1; // white pixel correct
|
|
|
|
Settings->webcam_config.dcw = 1; // downsize en
|
|
|
|
Settings->webcam_config.bpc = 0; // black pixel correct?
|
2022-04-26 23:25:26 +01:00
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
Settings->webcam_config.feature = 0;
|
2022-04-26 23:25:26 +01:00
|
|
|
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Defaults set"));
|
|
|
|
|
|
|
|
if (Wc.up) { WcApplySettings(); }
|
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcSetup(int32_t fsiz) {
|
2021-02-18 19:37:35 +00:00
|
|
|
if (fsiz >= FRAMESIZE_FHD) { fsiz = FRAMESIZE_FHD - 1; }
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
if (fsiz < 0) {
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_deinit();
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.up = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
if (Wc.up) {
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_deinit();
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Deinit"));
|
2020-05-25 16:25:47 +01:00
|
|
|
//return Wc.up;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2020-05-25 16:52:31 +01:00
|
|
|
Wc.up = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
//esp_log_level_set("*", ESP_LOG_VERBOSE);
|
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
camera_config_t config;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-05 17:36:12 +01:00
|
|
|
if (WcPinUsed()) {
|
|
|
|
config.pin_d0 = Pin(GPIO_WEBCAM_DATA); // Y2_GPIO_NUM;
|
|
|
|
config.pin_d1 = Pin(GPIO_WEBCAM_DATA, 1); // Y3_GPIO_NUM;
|
|
|
|
config.pin_d2 = Pin(GPIO_WEBCAM_DATA, 2); // Y4_GPIO_NUM;
|
|
|
|
config.pin_d3 = Pin(GPIO_WEBCAM_DATA, 3); // Y5_GPIO_NUM;
|
|
|
|
config.pin_d4 = Pin(GPIO_WEBCAM_DATA, 4); // Y6_GPIO_NUM;
|
|
|
|
config.pin_d5 = Pin(GPIO_WEBCAM_DATA, 5); // Y7_GPIO_NUM;
|
|
|
|
config.pin_d6 = Pin(GPIO_WEBCAM_DATA, 6); // Y8_GPIO_NUM;
|
|
|
|
config.pin_d7 = Pin(GPIO_WEBCAM_DATA, 7); // Y9_GPIO_NUM;
|
|
|
|
config.pin_xclk = Pin(GPIO_WEBCAM_XCLK); // XCLK_GPIO_NUM;
|
|
|
|
config.pin_pclk = Pin(GPIO_WEBCAM_PCLK); // PCLK_GPIO_NUM;
|
|
|
|
config.pin_vsync = Pin(GPIO_WEBCAM_VSYNC); // VSYNC_GPIO_NUM;
|
|
|
|
config.pin_href = Pin(GPIO_WEBCAM_HREF); // HREF_GPIO_NUM;
|
2022-10-29 19:13:00 +01:00
|
|
|
config.pin_sccb_sda = Pin(GPIO_WEBCAM_SIOD); // SIOD_GPIO_NUM; - unset to use shared I2C bus 2
|
|
|
|
config.pin_sccb_scl = Pin(GPIO_WEBCAM_SIOC); // SIOC_GPIO_NUM;
|
|
|
|
if(TasmotaGlobal.i2c_enabled_2){ // configure SIOD and SIOC as SDA,2 and SCL,2
|
|
|
|
config.sccb_i2c_port = 1; // reuse initialized bus 2, can be shared now
|
|
|
|
if(config.pin_sccb_sda < 0){ // GPIO_WEBCAM_SIOD must not be set to really make it happen
|
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: use I2C bus 2"));
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 12:06:19 +00:00
|
|
|
config.pin_pwdn = Pin(GPIO_WEBCAM_PWDN); // PWDN_GPIO_NUM;
|
|
|
|
config.pin_reset = Pin(GPIO_WEBCAM_RESET); // RESET_GPIO_NUM;
|
2022-10-13 10:54:27 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Template pin config"));
|
|
|
|
} else if (Y2_GPIO_NUM != -1) {
|
|
|
|
// Modell is set in camera_pins.h
|
2020-05-03 17:37:12 +01:00
|
|
|
config.pin_d0 = Y2_GPIO_NUM;
|
|
|
|
config.pin_d1 = Y3_GPIO_NUM;
|
|
|
|
config.pin_d2 = Y4_GPIO_NUM;
|
|
|
|
config.pin_d3 = Y5_GPIO_NUM;
|
|
|
|
config.pin_d4 = Y6_GPIO_NUM;
|
|
|
|
config.pin_d5 = Y7_GPIO_NUM;
|
|
|
|
config.pin_d6 = Y8_GPIO_NUM;
|
|
|
|
config.pin_d7 = Y9_GPIO_NUM;
|
|
|
|
config.pin_xclk = XCLK_GPIO_NUM;
|
|
|
|
config.pin_pclk = PCLK_GPIO_NUM;
|
|
|
|
config.pin_vsync = VSYNC_GPIO_NUM;
|
|
|
|
config.pin_href = HREF_GPIO_NUM;
|
|
|
|
config.pin_sscb_sda = SIOD_GPIO_NUM;
|
|
|
|
config.pin_sscb_scl = SIOC_GPIO_NUM;
|
|
|
|
config.pin_pwdn = PWDN_GPIO_NUM;
|
|
|
|
config.pin_reset = RESET_GPIO_NUM;
|
2022-10-13 10:54:27 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Compile flag pin config"));
|
|
|
|
} else {
|
|
|
|
// no valid config found -> abort
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: No pin config"));
|
|
|
|
return 0;
|
|
|
|
}
|
2022-05-05 15:26:29 +01:00
|
|
|
|
2022-01-27 20:30:05 +00:00
|
|
|
int32_t ledc_channel = analogAttach(config.pin_xclk);
|
|
|
|
if (ledc_channel < 0) {
|
2022-10-13 10:54:27 +01:00
|
|
|
AddLog(LOG_LEVEL_ERROR, "CAM: cannot allocated ledc channel, remove a PWM GPIO");
|
2022-01-27 20:30:05 +00:00
|
|
|
}
|
|
|
|
config.ledc_channel = (ledc_channel_t) ledc_channel;
|
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, "CAM: XCLK on GPIO %i using ledc channel %i", config.pin_xclk, config.ledc_channel);
|
|
|
|
config.ledc_timer = LEDC_TIMER_0;
|
2022-10-13 16:58:16 +01:00
|
|
|
// config.xclk_freq_hz = 20000000;
|
|
|
|
config.xclk_freq_hz = Settings->webcam_clk * 1000000;
|
2022-01-27 20:30:05 +00:00
|
|
|
config.pixel_format = PIXFORMAT_JPEG;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
//esp_log_level_set("*", ESP_LOG_INFO);
|
|
|
|
|
|
|
|
// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
|
|
|
|
// for larger pre-allocated frame buffer.
|
|
|
|
|
2021-07-18 18:43:33 +01:00
|
|
|
bool psram = UsePSRAM();
|
2020-05-02 07:10:23 +01:00
|
|
|
if (psram) {
|
|
|
|
config.frame_size = FRAMESIZE_UXGA;
|
|
|
|
config.jpeg_quality = 10;
|
|
|
|
config.fb_count = 2;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: PSRAM found"));
|
2020-05-02 07:10:23 +01:00
|
|
|
} else {
|
|
|
|
config.frame_size = FRAMESIZE_VGA;
|
|
|
|
config.jpeg_quality = 12;
|
|
|
|
config.fb_count = 1;
|
2022-02-01 14:57:41 +00:00
|
|
|
config.fb_location = CAMERA_FB_IN_DRAM;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: PSRAM not found"));
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t err = esp_camera_init(&config);
|
|
|
|
|
|
|
|
if (err != ESP_OK) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: Init failed with error 0x%x"), err);
|
2020-05-02 07:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
// AddLog(LOG_LEVEL_INFO, PSTR("CAM: heap check 2: %d"),ESP_getFreeHeap());
|
2020-10-19 06:26:42 +01:00
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
sensor_t * wc_s = esp_camera_sensor_get();
|
|
|
|
// drop down frame size for higher initial frame rate
|
|
|
|
wc_s->set_framesize(wc_s, (framesize_t)fsiz);
|
|
|
|
|
|
|
|
camera_fb_t *wc_fb = esp_camera_fb_get();
|
2020-05-25 16:25:47 +01:00
|
|
|
if (!wc_fb) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: Init failed to get the frame on time"));
|
2020-05-25 16:25:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Wc.width = wc_fb->width;
|
|
|
|
Wc.height = wc_fb->height;
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_fb_return(wc_fb);
|
|
|
|
|
2022-04-26 23:25:26 +01:00
|
|
|
WcApplySettings();
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: Initialized"));
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.up = 1;
|
2020-05-25 16:52:31 +01:00
|
|
|
if (psram) { Wc.up = 2; }
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
return Wc.up;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
/*********************************************************************************************/
|
|
|
|
|
|
|
|
int32_t WcSetOptions(uint32_t sel, int32_t value) {
|
2020-05-03 17:37:12 +01:00
|
|
|
int32_t res = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
sensor_t *s = esp_camera_sensor_get();
|
2020-05-03 17:37:12 +01:00
|
|
|
if (!s) { return -99; }
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
switch (sel) {
|
|
|
|
case 0:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= 0) { s->set_framesize(s, (framesize_t)value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.framesize;
|
2022-04-27 21:50:47 +01:00
|
|
|
|
|
|
|
// WcFeature is lost on resolution change
|
|
|
|
WcApplySettings();
|
2020-05-02 07:10:23 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= 0) { s->set_special_effect(s, value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.special_effect;
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= 0) { s->set_vflip(s, value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.vflip;
|
|
|
|
break;
|
|
|
|
case 3:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= 0) { s->set_hmirror(s, value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.hmirror;
|
|
|
|
break;
|
|
|
|
case 4:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= -4) { s->set_contrast(s, value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.contrast;
|
|
|
|
break;
|
|
|
|
case 5:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= -4) { s->set_brightness(s, value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.brightness;
|
|
|
|
break;
|
|
|
|
case 6:
|
2020-05-03 17:37:12 +01:00
|
|
|
if (value >= -4) { s->set_saturation(s,value); }
|
2020-05-02 07:10:23 +01:00
|
|
|
res = s->status.saturation;
|
|
|
|
break;
|
2022-04-26 23:25:26 +01:00
|
|
|
case 7:
|
|
|
|
if (value >= 0) { s->set_whitebal(s, value); }
|
|
|
|
res = s->status.awb;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (value >= 0) { s->set_wb_mode(s, value); }
|
|
|
|
res = s->status.wb_mode;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
if (value >= 0) { s->set_awb_gain(s, value); }
|
|
|
|
res = s->status.awb_gain;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
if (value >= 0) { s->set_exposure_ctrl(s, value); }
|
|
|
|
res = s->status.aec;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
if (value >= 0) { s->set_aec_value(s, value); }
|
|
|
|
res = s->status.aec_value;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (value >= 0) { s->set_ae_level(s, value); }
|
|
|
|
res = s->status.ae_level;
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
if (value >= 0) { s->set_aec2(s, value); }
|
|
|
|
res = s->status.aec2;
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
if (value >= 0) { s->set_gain_ctrl(s, value); }
|
|
|
|
res = s->status.agc;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
if (value >= 0) { s->set_agc_gain(s, value); }
|
|
|
|
res = s->status.agc_gain;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
if (value >= 0) { s->set_gainceiling(s, (gainceiling_t)value); }
|
|
|
|
res = s->status.gainceiling;
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
if (value >= 0) { s->set_raw_gma(s, value); }
|
|
|
|
res = s->status.raw_gma;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
if (value >= 0) { s->set_lenc(s, value); }
|
|
|
|
res = s->status.lenc;
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
if (value >= 0) { s->set_wpc(s, value); }
|
|
|
|
res = s->status.wpc;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
if (value >= 0) { s->set_dcw(s, value); }
|
|
|
|
res = s->status.dcw;
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
// blackpixelcontrol
|
|
|
|
if (value >= 0) { s->set_bpc(s, value); }
|
|
|
|
res = s->status.bpc;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (value >= 0) { s->set_colorbar(s, value); }
|
|
|
|
res = s->status.colorbar;
|
|
|
|
break;
|
|
|
|
case 23:
|
2022-04-27 21:37:32 +01:00
|
|
|
if (value >= 0) { WcFeature(value); }
|
2022-04-26 23:25:26 +01:00
|
|
|
break;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcGetWidth(void) {
|
2020-05-02 07:10:23 +01:00
|
|
|
camera_fb_t *wc_fb = esp_camera_fb_get();
|
2020-05-03 17:37:12 +01:00
|
|
|
if (!wc_fb) { return 0; }
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.width = wc_fb->width;
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_fb_return(wc_fb);
|
2020-05-25 16:25:47 +01:00
|
|
|
return Wc.width;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcGetHeight(void) {
|
2020-05-02 07:10:23 +01:00
|
|
|
camera_fb_t *wc_fb = esp_camera_fb_get();
|
2020-05-03 17:37:12 +01:00
|
|
|
if (!wc_fb) { return 0; }
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.height = wc_fb->height;
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_fb_return(wc_fb);
|
2020-05-25 16:25:47 +01:00
|
|
|
return Wc.height;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
/*********************************************************************************************/
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
struct WC_Motion {
|
2020-05-12 13:30:07 +01:00
|
|
|
uint16_t motion_detect;
|
|
|
|
uint32_t motion_ltime;
|
|
|
|
uint32_t motion_trigger;
|
|
|
|
uint32_t motion_brightness;
|
|
|
|
uint8_t *last_motion_buffer;
|
2021-01-20 07:42:44 +00:00
|
|
|
} wc_motion;
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
|
|
|
|
uint32_t WcSetMotionDetect(int32_t value) {
|
2021-01-20 07:42:44 +00:00
|
|
|
if (value >= 0) { wc_motion.motion_detect = value; }
|
2020-05-12 13:30:07 +01:00
|
|
|
if (-1 == value) {
|
2021-01-20 07:42:44 +00:00
|
|
|
return wc_motion.motion_trigger;
|
2020-05-12 13:30:07 +01:00
|
|
|
} else {
|
2021-01-20 07:42:44 +00:00
|
|
|
return wc_motion.motion_brightness;
|
2020-05-12 13:30:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// optional motion detector
|
|
|
|
void WcDetectMotion(void) {
|
|
|
|
camera_fb_t *wc_fb;
|
|
|
|
uint8_t *out_buf = 0;
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
if ((millis()-wc_motion.motion_ltime) > wc_motion.motion_detect) {
|
|
|
|
wc_motion.motion_ltime = millis();
|
2020-05-12 13:30:07 +01:00
|
|
|
wc_fb = esp_camera_fb_get();
|
|
|
|
if (!wc_fb) { return; }
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!wc_motion.last_motion_buffer) {
|
|
|
|
wc_motion.last_motion_buffer = (uint8_t *)heap_caps_malloc((wc_fb->width*wc_fb->height) + 4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
2020-05-12 13:30:07 +01:00
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
if (wc_motion.last_motion_buffer) {
|
2020-05-12 13:30:07 +01:00
|
|
|
if (PIXFORMAT_JPEG == wc_fb->format) {
|
|
|
|
out_buf = (uint8_t *)heap_caps_malloc((wc_fb->width*wc_fb->height*3)+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
|
|
if (out_buf) {
|
|
|
|
fmt2rgb888(wc_fb->buf, wc_fb->len, wc_fb->format, out_buf);
|
|
|
|
uint32_t x, y;
|
|
|
|
uint8_t *pxi = out_buf;
|
2021-01-20 07:42:44 +00:00
|
|
|
uint8_t *pxr = wc_motion.last_motion_buffer;
|
2020-05-12 13:30:07 +01:00
|
|
|
// convert to bw
|
|
|
|
uint64_t accu = 0;
|
|
|
|
uint64_t bright = 0;
|
|
|
|
for (y = 0; y < wc_fb->height; y++) {
|
|
|
|
for (x = 0; x < wc_fb->width; x++) {
|
|
|
|
int32_t gray = (pxi[0] + pxi[1] + pxi[2]) / 3;
|
|
|
|
int32_t lgray = pxr[0];
|
|
|
|
pxr[0] = gray;
|
|
|
|
pxi += 3;
|
|
|
|
pxr++;
|
|
|
|
accu += abs(gray - lgray);
|
|
|
|
bright += gray;
|
|
|
|
}
|
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
wc_motion.motion_trigger = accu / ((wc_fb->height * wc_fb->width) / 100);
|
|
|
|
wc_motion.motion_brightness = bright / ((wc_fb->height * wc_fb->width) / 100);
|
2020-05-12 13:30:07 +01:00
|
|
|
free(out_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
esp_camera_fb_return(wc_fb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
#ifdef COPYFRAME
|
|
|
|
struct PICSTORE tmp_picstore;
|
|
|
|
#endif
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcGetPicstore(int32_t num, uint8_t **buff) {
|
2020-05-03 17:37:12 +01:00
|
|
|
if (num<0) { return MAX_PICSTORE; }
|
2021-01-20 07:42:44 +00:00
|
|
|
*buff = Wc.picstore[num].buff;
|
|
|
|
return Wc.picstore[num].len;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcGetFrame(int32_t bnum) {
|
2020-05-02 07:10:23 +01:00
|
|
|
size_t _jpg_buf_len = 0;
|
|
|
|
uint8_t * _jpg_buf = NULL;
|
2020-05-03 17:37:12 +01:00
|
|
|
camera_fb_t *wc_fb = 0;
|
|
|
|
bool jpeg_converted = false;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
if (bnum < 0) {
|
|
|
|
if (bnum < -MAX_PICSTORE) { bnum=-1; }
|
|
|
|
bnum = -bnum;
|
2020-05-02 07:10:23 +01:00
|
|
|
bnum--;
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.picstore[bnum].buff) { free(Wc.picstore[bnum].buff); }
|
|
|
|
Wc.picstore[bnum].len = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COPYFRAME
|
2020-05-03 17:37:12 +01:00
|
|
|
if (bnum & 0x10) {
|
|
|
|
bnum &= 0xf;
|
|
|
|
_jpg_buf = tmp_picstore.buff;
|
|
|
|
_jpg_buf_len = tmp_picstore.len;
|
|
|
|
if (!_jpg_buf_len) { return 0; }
|
2020-05-02 07:10:23 +01:00
|
|
|
goto pcopy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wc_fb = esp_camera_fb_get();
|
|
|
|
if (!wc_fb) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Can't get frame"));
|
2020-05-02 07:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!bnum) {
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.width = wc_fb->width;
|
|
|
|
Wc.height = wc_fb->height;
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_fb_return(wc_fb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
if (wc_fb->format != PIXFORMAT_JPEG) {
|
2020-05-02 07:10:23 +01:00
|
|
|
jpeg_converted = frame2jpg(wc_fb, 80, &_jpg_buf, &_jpg_buf_len);
|
|
|
|
if (!jpeg_converted){
|
2020-05-03 17:37:12 +01:00
|
|
|
//Serial.println("JPEG compression failed");
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcopy:
|
2020-05-03 17:37:12 +01:00
|
|
|
if ((bnum < 1) || (bnum > MAX_PICSTORE)) { bnum = 1; }
|
2020-05-02 07:10:23 +01:00
|
|
|
bnum--;
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.picstore[bnum].buff) { free(Wc.picstore[bnum].buff); }
|
|
|
|
Wc.picstore[bnum].buff = (uint8_t *)heap_caps_malloc(_jpg_buf_len+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
|
|
if (Wc.picstore[bnum].buff) {
|
|
|
|
memcpy(Wc.picstore[bnum].buff, _jpg_buf, _jpg_buf_len);
|
|
|
|
Wc.picstore[bnum].len = _jpg_buf_len;
|
2020-05-02 07:10:23 +01:00
|
|
|
} else {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Can't allocate picstore"));
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.picstore[bnum].len = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2020-05-03 17:37:12 +01:00
|
|
|
if (wc_fb) { esp_camera_fb_return(wc_fb); }
|
|
|
|
if (jpeg_converted) { free(_jpg_buf); }
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.picstore[bnum].buff) { return 0; }
|
2020-05-03 17:37:12 +01:00
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
return _jpg_buf_len;
|
|
|
|
}
|
|
|
|
|
2022-05-24 22:06:41 +01:00
|
|
|
//////////////// Handle authentication /////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool WebcamAuthenticate(void)
|
|
|
|
{
|
|
|
|
if (strlen(SettingsText(SET_WEBPWD)) && (HTTP_MANAGER_RESET_ONLY != Web.state)) {
|
|
|
|
return Wc.CamServer->authenticate(WEB_USERNAME, SettingsText(SET_WEBPWD));
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebcamCheckPriviledgedAccess(bool autorequestauth = true)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(Settings->webcam_config2.auth == 0){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autorequestauth && !WebcamAuthenticate()) {
|
|
|
|
Wc.CamServer->requestAuthentication();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
void HandleImage(void) {
|
2020-05-12 13:30:07 +01:00
|
|
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
uint32_t bnum = Webserver->arg(F("p")).toInt();
|
2020-05-03 17:37:12 +01:00
|
|
|
if ((bnum < 0) || (bnum > MAX_PICSTORE)) { bnum= 1; }
|
2020-05-02 07:10:23 +01:00
|
|
|
WiFiClient client = Webserver->client();
|
|
|
|
String response = "HTTP/1.1 200 OK\r\n";
|
|
|
|
response += "Content-disposition: inline; filename=cap.jpg\r\n";
|
|
|
|
response += "Content-type: image/jpeg\r\n\r\n";
|
|
|
|
Webserver->sendContent(response);
|
|
|
|
|
|
|
|
if (!bnum) {
|
2020-05-12 07:14:58 +01:00
|
|
|
size_t _jpg_buf_len = 0;
|
|
|
|
uint8_t * _jpg_buf = NULL;
|
|
|
|
camera_fb_t *wc_fb = 0;
|
|
|
|
wc_fb = esp_camera_fb_get();
|
|
|
|
if (!wc_fb) { return; }
|
|
|
|
if (wc_fb->format != PIXFORMAT_JPEG) {
|
|
|
|
bool jpeg_converted = frame2jpg(wc_fb, 80, &_jpg_buf, &_jpg_buf_len);
|
|
|
|
if (!jpeg_converted) {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
if (_jpg_buf_len) {
|
|
|
|
client.write((char *)_jpg_buf, _jpg_buf_len);
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2020-05-12 07:14:58 +01:00
|
|
|
if (wc_fb) { esp_camera_fb_return(wc_fb); }
|
2020-05-02 07:10:23 +01:00
|
|
|
} else {
|
|
|
|
bnum--;
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.picstore[bnum].len) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: No image #: %d"), bnum);
|
2020-05-02 07:10:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
client.write((char *)Wc.picstore[bnum].buff, Wc.picstore[bnum].len);
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2020-05-12 07:14:58 +01:00
|
|
|
client.stop();
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("CAM: Sending image #: %d"), bnum+1);
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void HandleImageBasic(void) {
|
|
|
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
2020-05-10 16:52:28 +01:00
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP "Capture image"));
|
2020-05-10 16:52:28 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->webcam_config.stream) {
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.CamServer) {
|
2021-12-17 17:01:27 +00:00
|
|
|
WcInterruptControl();
|
2020-05-10 16:52:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
camera_fb_t *wc_fb;
|
|
|
|
wc_fb = esp_camera_fb_get(); // Acquire frame
|
|
|
|
if (!wc_fb) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Frame buffer could not be acquired"));
|
2020-05-10 16:52:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t _jpg_buf_len = 0;
|
|
|
|
uint8_t * _jpg_buf = NULL;
|
|
|
|
if (wc_fb->format != PIXFORMAT_JPEG) {
|
|
|
|
bool jpeg_converted = frame2jpg(wc_fb, 80, &_jpg_buf, &_jpg_buf_len);
|
|
|
|
if (!jpeg_converted) {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_jpg_buf_len) {
|
|
|
|
Webserver->client().flush();
|
|
|
|
WSHeaderSend();
|
2020-05-12 13:30:07 +01:00
|
|
|
Webserver->sendHeader(F("Content-disposition"), F("inline; filename=snapshot.jpg"));
|
2020-05-10 16:52:28 +01:00
|
|
|
Webserver->send_P(200, "image/jpeg", (char *)_jpg_buf, _jpg_buf_len);
|
|
|
|
Webserver->client().stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_camera_fb_return(wc_fb); // Free frame buffer
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("CAM: Image sent"));
|
2020-05-05 08:36:43 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void HandleWebcamMjpeg(void) {
|
2022-05-24 22:06:41 +01:00
|
|
|
if(!WebcamCheckPriviledgedAccess()){
|
|
|
|
Wc.CamServer->send(403,"","");
|
|
|
|
return;
|
|
|
|
}
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Handle camserver"));
|
2020-05-25 16:25:47 +01:00
|
|
|
// if (!Wc.stream_active) {
|
2020-05-12 13:30:07 +01:00
|
|
|
// always restart stream
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 1;
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.client = Wc.CamServer->client();
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Create client"));
|
2020-05-12 13:30:07 +01:00
|
|
|
// }
|
2020-05-05 08:36:43 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void HandleWebcamMjpegTask(void) {
|
2020-05-02 07:10:23 +01:00
|
|
|
camera_fb_t *wc_fb;
|
|
|
|
size_t _jpg_buf_len = 0;
|
|
|
|
uint8_t * _jpg_buf = NULL;
|
|
|
|
|
|
|
|
//WiFiClient client = CamServer->client();
|
|
|
|
uint32_t tlen;
|
2020-05-03 17:37:12 +01:00
|
|
|
bool jpeg_converted = false;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.client.connected()) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Client fail"));
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 0;
|
2022-04-26 23:25:26 +01:00
|
|
|
WcStats.clientfail++;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2020-05-25 16:25:47 +01:00
|
|
|
if (1 == Wc.stream_active) {
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.client.flush();
|
|
|
|
Wc.client.setTimeout(3);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Start stream"));
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.client.print("HTTP/1.1 200 OK\r\n"
|
2020-05-03 17:37:12 +01:00
|
|
|
"Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY "\r\n"
|
|
|
|
"\r\n");
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 2;
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2020-05-25 16:25:47 +01:00
|
|
|
if (2 == Wc.stream_active) {
|
2020-05-02 07:10:23 +01:00
|
|
|
wc_fb = esp_camera_fb_get();
|
|
|
|
if (!wc_fb) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Frame fail"));
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 0;
|
2022-04-26 23:25:26 +01:00
|
|
|
WcStats.camfail++;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
2022-04-26 23:25:26 +01:00
|
|
|
WcStats.camcnt++;
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2020-05-25 16:25:47 +01:00
|
|
|
if (2 == Wc.stream_active) {
|
2020-05-03 17:37:12 +01:00
|
|
|
if (wc_fb->format != PIXFORMAT_JPEG) {
|
2020-05-02 07:10:23 +01:00
|
|
|
jpeg_converted = frame2jpg(wc_fb, 80, &_jpg_buf, &_jpg_buf_len);
|
|
|
|
if (!jpeg_converted){
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: JPEG compression failed"));
|
2020-05-02 07:10:23 +01:00
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
2022-04-26 23:25:26 +01:00
|
|
|
WcStats.jpegfail++;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_jpg_buf_len = wc_fb->len;
|
|
|
|
_jpg_buf = wc_fb->buf;
|
|
|
|
}
|
|
|
|
|
2021-06-19 15:40:32 +01:00
|
|
|
Wc.client.print("--" BOUNDARY "\r\n");
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.client.printf("Content-Type: image/jpeg\r\n"
|
2020-05-02 07:10:23 +01:00
|
|
|
"Content-Length: %d\r\n"
|
2020-05-03 17:37:12 +01:00
|
|
|
"\r\n", static_cast<int>(_jpg_buf_len));
|
2021-01-20 07:42:44 +00:00
|
|
|
tlen = Wc.client.write(_jpg_buf, _jpg_buf_len);
|
2020-05-02 07:10:23 +01:00
|
|
|
/*
|
|
|
|
if (tlen!=_jpg_buf_len) {
|
|
|
|
esp_camera_fb_return(wc_fb);
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active=0;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Send fail"));
|
2020-05-02 07:10:23 +01:00
|
|
|
}*/
|
2021-06-19 15:40:32 +01:00
|
|
|
// Wc.client.print("\r\n--" BOUNDARY "\r\n");
|
|
|
|
Wc.client.print("\r\n");
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
#ifdef COPYFRAME
|
2020-05-03 17:37:12 +01:00
|
|
|
if (tmp_picstore.buff) { free(tmp_picstore.buff); }
|
|
|
|
tmp_picstore.buff = (uint8_t *)heap_caps_malloc(_jpg_buf_len+4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
2020-05-02 07:10:23 +01:00
|
|
|
if (tmp_picstore.buff) {
|
2020-05-03 17:37:12 +01:00
|
|
|
memcpy(tmp_picstore.buff, _jpg_buf, _jpg_buf_len);
|
|
|
|
tmp_picstore.len = _jpg_buf_len;
|
2020-05-02 07:10:23 +01:00
|
|
|
} else {
|
2020-05-03 17:37:12 +01:00
|
|
|
tmp_picstore.len = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
if (jpeg_converted) { free(_jpg_buf); }
|
2020-05-02 07:10:23 +01:00
|
|
|
esp_camera_fb_return(wc_fb);
|
2021-01-23 16:10:06 +00:00
|
|
|
//AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: send frame"));
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2020-05-25 16:25:47 +01:00
|
|
|
if (0 == Wc.stream_active) {
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Stream exit"));
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.client.flush();
|
|
|
|
Wc.client.stop();
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void HandleWebcamRoot(void) {
|
2022-05-24 22:06:41 +01:00
|
|
|
if(!WebcamCheckPriviledgedAccess()){
|
|
|
|
Wc.CamServer->send(403,"","");
|
|
|
|
return;
|
|
|
|
}
|
2020-05-02 07:10:23 +01:00
|
|
|
//CamServer->redirect("http://" + String(ip) + ":81/cam.mjpeg");
|
2022-05-20 13:42:32 +01:00
|
|
|
Wc.CamServer->sendHeader("Location", "/cam.mjpeg");
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.CamServer->send(302, "", "");
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Root called"));
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
/*********************************************************************************************/
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
uint32_t WcSetStreamserver(uint32_t flag) {
|
2020-10-30 11:29:48 +00:00
|
|
|
if (TasmotaGlobal.global_state.network_down) { return 0; }
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-25 16:25:47 +01:00
|
|
|
Wc.stream_active = 0;
|
2020-05-02 07:10:23 +01:00
|
|
|
|
|
|
|
if (flag) {
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.CamServer) {
|
|
|
|
Wc.CamServer = new ESP8266WebServer(81);
|
|
|
|
Wc.CamServer->on("/", HandleWebcamRoot);
|
|
|
|
Wc.CamServer->on("/cam.mjpeg", HandleWebcamMjpeg);
|
|
|
|
Wc.CamServer->on("/cam.jpg", HandleWebcamMjpeg);
|
|
|
|
Wc.CamServer->on("/stream", HandleWebcamMjpeg);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Stream init"));
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.CamServer->begin();
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.CamServer) {
|
|
|
|
Wc.CamServer->stop();
|
|
|
|
delete Wc.CamServer;
|
|
|
|
Wc.CamServer = NULL;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Stream exit"));
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-17 17:01:27 +00:00
|
|
|
void WcInterruptControl() {
|
2021-06-11 17:14:12 +01:00
|
|
|
WcSetStreamserver(Settings->webcam_config.stream);
|
|
|
|
WcSetup(Settings->webcam_config.resolution);
|
2020-05-04 16:13:14 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
/*********************************************************************************************/
|
2021-01-20 07:42:44 +00:00
|
|
|
|
2020-05-08 16:17:09 +01:00
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void WcLoop(void) {
|
2021-12-17 17:01:27 +00:00
|
|
|
if (4 == Wc.stream_active) { return; }
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.CamServer) {
|
|
|
|
Wc.CamServer->handleClient();
|
2020-05-25 16:25:47 +01:00
|
|
|
if (Wc.stream_active) { HandleWebcamMjpegTask(); }
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
if (wc_motion.motion_detect) { WcDetectMotion(); }
|
2020-10-19 06:26:42 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_RTSPSERVER
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->webcam_config.rtsp && !TasmotaGlobal.global_state.wifi_down && Wc.up) {
|
2021-01-20 07:42:44 +00:00
|
|
|
if (!Wc.rtsp_start) {
|
|
|
|
Wc.rtspp = new WiFiServer(8554);
|
|
|
|
Wc.rtspp->begin();
|
|
|
|
Wc.rtsp_start = 1;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: RTSP init"));
|
2021-01-20 07:42:44 +00:00
|
|
|
Wc.rtsp_lastframe_time = millis();
|
|
|
|
}
|
2020-10-19 06:26:42 +01:00
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
// If we have an active client connection, just service that until gone
|
|
|
|
if (Wc.rtsp_session) {
|
|
|
|
Wc.rtsp_session->handleRequests(0); // we don't use a timeout here,
|
2020-10-19 06:26:42 +01:00
|
|
|
// instead we send only if we have new enough frames
|
|
|
|
|
|
|
|
uint32_t now = millis();
|
2021-01-20 07:42:44 +00:00
|
|
|
if ((now-Wc.rtsp_lastframe_time) > RTSP_FRAME_TIME) {
|
|
|
|
Wc.rtsp_session->broadcastCurrentFrame(now);
|
|
|
|
Wc.rtsp_lastframe_time = now;
|
2021-01-23 16:10:06 +00:00
|
|
|
// AddLog(LOG_LEVEL_INFO, PSTR("CAM: RTSP session frame"));
|
2020-10-19 06:26:42 +01:00
|
|
|
}
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.rtsp_session->m_stopped) {
|
|
|
|
delete Wc.rtsp_session;
|
|
|
|
delete Wc.rtsp_streamer;
|
|
|
|
Wc.rtsp_session = NULL;
|
|
|
|
Wc.rtsp_streamer = NULL;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: RTSP stopped"));
|
2020-10-19 06:26:42 +01:00
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Wc.rtsp_client = Wc.rtspp->accept();
|
|
|
|
if (Wc.rtsp_client) {
|
|
|
|
Wc.rtsp_streamer = new OV2640Streamer(&Wc.rtsp_client, Wc.cam); // our streamer for UDP/TCP based RTP transport
|
|
|
|
Wc.rtsp_session = new CRtspSession(&Wc.rtsp_client, Wc.rtsp_streamer); // our threads RTSP session and state
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("CAM: RTSP stream created"));
|
2020-10-19 06:26:42 +01:00
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
}
|
2020-10-19 06:26:42 +01:00
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
#endif // ENABLE_RTSPSERVER
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void WcPicSetup(void) {
|
2020-10-20 17:56:18 +01:00
|
|
|
WebServer_on(PSTR("/wc.jpg"), HandleImage);
|
|
|
|
WebServer_on(PSTR("/wc.mjpeg"), HandleImage);
|
|
|
|
WebServer_on(PSTR("/snapshot.jpg"), HandleImage);
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:30:07 +01:00
|
|
|
void WcShowStream(void) {
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->webcam_config.stream) {
|
2021-01-20 07:42:44 +00:00
|
|
|
// if (!Wc.CamServer || !Wc.up) {
|
|
|
|
if (!Wc.CamServer) {
|
2021-12-17 17:01:27 +00:00
|
|
|
WcInterruptControl();
|
2020-05-12 13:30:07 +01:00
|
|
|
delay(50); // Give the webcam webserver some time to prepare the stream
|
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
if (Wc.CamServer && Wc.up) {
|
2021-01-27 11:14:33 +00:00
|
|
|
WSContentSend_P(PSTR("<p></p><center><img src='http://%_I:81/stream' alt='Webcam stream' style='width:99%%;'></center><p></p>"),
|
|
|
|
(uint32_t)WiFi.localIP());
|
2020-05-12 13:30:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2020-05-04 16:13:14 +01:00
|
|
|
void WcInit(void) {
|
2021-06-11 17:14:12 +01:00
|
|
|
if (!Settings->webcam_config.data) {
|
|
|
|
Settings->webcam_config.stream = 1;
|
|
|
|
Settings->webcam_config.resolution = FRAMESIZE_QVGA;
|
2022-04-26 23:25:26 +01:00
|
|
|
WcSetDefaults(0);
|
|
|
|
}
|
|
|
|
// previous webcam driver had only a small subset of possible config vars
|
|
|
|
// in this case we have to only set the new variables to default values
|
|
|
|
if(!Settings->webcam_config2.upgraded) {
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("CAM: Upgrade settings"));
|
|
|
|
WcSetDefaults(1);
|
|
|
|
Settings->webcam_config2.upgraded = 1;
|
2020-05-04 16:13:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
/*********************************************************************************************\
|
2020-05-03 17:37:12 +01:00
|
|
|
* Commands
|
2020-05-02 07:10:23 +01:00
|
|
|
\*********************************************************************************************/
|
2020-05-03 17:37:12 +01:00
|
|
|
|
2020-05-08 16:17:09 +01:00
|
|
|
#define D_PRFX_WEBCAM "WC"
|
|
|
|
#define D_CMND_WC_STREAM "Stream"
|
|
|
|
#define D_CMND_WC_RESOLUTION "Resolution"
|
|
|
|
#define D_CMND_WC_MIRROR "Mirror"
|
|
|
|
#define D_CMND_WC_FLIP "Flip"
|
|
|
|
#define D_CMND_WC_SATURATION "Saturation"
|
|
|
|
#define D_CMND_WC_BRIGHTNESS "Brightness"
|
|
|
|
#define D_CMND_WC_CONTRAST "Contrast"
|
2022-04-26 23:25:26 +01:00
|
|
|
#define D_CMND_WC_SPECIALEFFECT "SpecialEffect"
|
|
|
|
|
|
|
|
#define D_CMND_WC_AWB "AWB"
|
|
|
|
#define D_CMND_WC_WB_MODE "WBMode"
|
|
|
|
#define D_CMND_WC_AWB_GAIN "AWBGain"
|
|
|
|
|
|
|
|
#define D_CMND_WC_AEC "AEC"
|
|
|
|
#define D_CMND_WC_AEC_VALUE "AECValue"
|
|
|
|
#define D_CMND_WC_AE_LEVEL "AELevel"
|
|
|
|
#define D_CMND_WC_AEC2 "AECDSP"
|
|
|
|
|
|
|
|
#define D_CMND_WC_AGC "AGC"
|
|
|
|
#define D_CMND_WC_AGC_GAIN "AGCGain"
|
|
|
|
#define D_CMND_WC_GAINCEILING "GainCeiling"
|
|
|
|
|
|
|
|
#define D_CMND_WC_RAW_GMA "GammaCorrect"
|
|
|
|
#define D_CMND_WC_LENC "LensCorrect"
|
|
|
|
|
|
|
|
#define D_CMND_WC_WPC "WPC"
|
|
|
|
#define D_CMND_WC_DCW "DCW"
|
|
|
|
#define D_CMND_WC_BPC "BPC"
|
|
|
|
|
|
|
|
#define D_CMND_WC_COLORBAR "Colorbar"
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
#define D_CMND_WC_FEATURE "Feature"
|
2022-04-26 23:25:26 +01:00
|
|
|
#define D_CMND_WC_SETDEFAULTS "SetDefaults"
|
|
|
|
#define D_CMND_WC_STATS "Stats"
|
|
|
|
|
2020-10-19 06:26:42 +01:00
|
|
|
#define D_CMND_WC_INIT "Init"
|
2021-01-20 07:42:44 +00:00
|
|
|
#define D_CMND_RTSP "Rtsp"
|
2020-05-08 16:17:09 +01:00
|
|
|
|
2022-05-20 11:30:12 +01:00
|
|
|
#define D_CMND_WC_AUTH "Auth"
|
2022-10-13 16:58:16 +01:00
|
|
|
#define D_CMND_WC_CLK "Clock"
|
2022-05-20 11:30:12 +01:00
|
|
|
|
2020-05-08 16:17:09 +01:00
|
|
|
const char kWCCommands[] PROGMEM = D_PRFX_WEBCAM "|" // Prefix
|
|
|
|
"|" D_CMND_WC_STREAM "|" D_CMND_WC_RESOLUTION "|" D_CMND_WC_MIRROR "|" D_CMND_WC_FLIP "|"
|
2022-04-26 23:25:26 +01:00
|
|
|
D_CMND_WC_SATURATION "|" D_CMND_WC_BRIGHTNESS "|" D_CMND_WC_CONTRAST "|" D_CMND_WC_SPECIALEFFECT "|"
|
|
|
|
D_CMND_WC_AWB "|" D_CMND_WC_WB_MODE "|" D_CMND_WC_AWB_GAIN "|" D_CMND_WC_AEC "|"
|
|
|
|
D_CMND_WC_AEC_VALUE "|" D_CMND_WC_AE_LEVEL "|" D_CMND_WC_AEC2 "|" D_CMND_WC_AGC "|"
|
|
|
|
D_CMND_WC_AGC_GAIN "|" D_CMND_WC_GAINCEILING "|" D_CMND_WC_RAW_GMA "|" D_CMND_WC_LENC "|"
|
2022-05-05 15:26:29 +01:00
|
|
|
D_CMND_WC_WPC "|" D_CMND_WC_DCW "|" D_CMND_WC_BPC "|" D_CMND_WC_COLORBAR "|" D_CMND_WC_FEATURE "|"
|
2022-10-13 16:58:16 +01:00
|
|
|
D_CMND_WC_SETDEFAULTS "|" D_CMND_WC_STATS "|" D_CMND_WC_INIT "|" D_CMND_WC_AUTH "|" D_CMND_WC_CLK
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
"|" D_CMND_RTSP
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
2020-05-02 15:44:44 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
void (* const WCCommand[])(void) PROGMEM = {
|
2020-05-08 16:17:09 +01:00
|
|
|
&CmndWebcam, &CmndWebcamStream, &CmndWebcamResolution, &CmndWebcamMirror, &CmndWebcamFlip,
|
2022-04-26 23:25:26 +01:00
|
|
|
&CmndWebcamSaturation, &CmndWebcamBrightness, &CmndWebcamContrast, &CmndWebcamSpecialEffect,
|
|
|
|
&CmndWebcamAWB, &CmndWebcamWBMode, &CmndWebcamAWBGain, &CmndWebcamAEC, &CmndWebcamAECValue,
|
|
|
|
&CmndWebcamAELevel, &CmndWebcamAEC2, &CmndWebcamAGC, &CmndWebcamAGCGain, &CmndWebcamGainCeiling,
|
|
|
|
&CmndWebcamGammaCorrect, &CmndWebcamLensCorrect, &CmndWebcamWPC, &CmndWebcamDCW, &CmndWebcamBPC,
|
2022-05-05 15:26:29 +01:00
|
|
|
&CmndWebcamColorbar, &CmndWebcamFeature, &CmndWebcamSetDefaults,
|
2022-10-13 16:58:16 +01:00
|
|
|
&CmndWebcamStats, &CmndWebcamInit, &CmndWebcamAuth, &CmndWebcamClock
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
, &CmndWebRtsp
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
2020-05-02 15:44:44 +01:00
|
|
|
};
|
|
|
|
|
2020-05-04 16:13:14 +01:00
|
|
|
void CmndWebcam(void) {
|
2020-05-08 16:17:09 +01:00
|
|
|
Response_P(PSTR("{\"" D_PRFX_WEBCAM "\":{\"" D_CMND_WC_STREAM "\":%d,\"" D_CMND_WC_RESOLUTION "\":%d,\"" D_CMND_WC_MIRROR "\":%d,\""
|
|
|
|
D_CMND_WC_FLIP "\":%d,\""
|
2022-04-26 23:25:26 +01:00
|
|
|
D_CMND_WC_SATURATION "\":%d,\"" D_CMND_WC_BRIGHTNESS "\":%d,\"" D_CMND_WC_CONTRAST "\":%d,\""
|
|
|
|
D_CMND_WC_SPECIALEFFECT "\":%d,\"" D_CMND_WC_AWB "\":%d,\"" D_CMND_WC_WB_MODE "\":%d,\""
|
|
|
|
D_CMND_WC_AWB_GAIN "\":%d,\"" D_CMND_WC_AEC "\":%d,\"" D_CMND_WC_AEC_VALUE "\":%d,\""
|
|
|
|
D_CMND_WC_AE_LEVEL "\":%d,\"" D_CMND_WC_AEC2 "\":%d,\"" D_CMND_WC_AGC "\":%d,\""
|
|
|
|
D_CMND_WC_AGC_GAIN "\":%d,\"" D_CMND_WC_GAINCEILING "\":%d,\"" D_CMND_WC_RAW_GMA "\":%d,\""
|
|
|
|
D_CMND_WC_LENC "\":%d,\"" D_CMND_WC_WPC "\":%d,\"" D_CMND_WC_DCW "\":%d,\"" D_CMND_WC_BPC "\":%d,\""
|
2022-05-20 11:30:12 +01:00
|
|
|
D_CMND_WC_COLORBAR "\":%d,\"" D_CMND_WC_FEATURE "\":%d,\"" D_CMND_WC_AUTH "\":%d"
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
",\"" D_CMND_RTSP "\":%d"
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
|
|
|
"}}"),
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.stream, Settings->webcam_config.resolution, Settings->webcam_config.mirror,
|
|
|
|
Settings->webcam_config.flip,
|
2022-04-26 23:25:26 +01:00
|
|
|
Settings->webcam_config.saturation -2, Settings->webcam_config.brightness -2, Settings->webcam_config.contrast -2,
|
|
|
|
Settings->webcam_config2.special_effect, Settings->webcam_config.awb, Settings->webcam_config2.wb_mode,
|
|
|
|
Settings->webcam_config.awb_gain, Settings->webcam_config.aec, Settings->webcam_config2.aec_value,
|
|
|
|
Settings->webcam_config2.ae_level -2, Settings->webcam_config.aec2, Settings->webcam_config.agc,
|
|
|
|
Settings->webcam_config2.agc_gain, Settings->webcam_config2.gainceiling, Settings->webcam_config.raw_gma,
|
|
|
|
Settings->webcam_config.lenc, Settings->webcam_config.wpc, Settings->webcam_config.dcw, Settings->webcam_config.bpc,
|
2022-05-20 11:30:12 +01:00
|
|
|
Settings->webcam_config.colorbar, Settings->webcam_config.feature, Settings->webcam_config2.auth
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifdef ENABLE_RTSPSERVER
|
2021-06-11 17:14:12 +01:00
|
|
|
, Settings->webcam_config.rtsp
|
2021-01-20 07:42:44 +00:00
|
|
|
#endif // ENABLE_RTSPSERVER
|
|
|
|
);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamStream(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.stream = XdrvMailbox.payload;
|
2021-12-17 17:01:27 +00:00
|
|
|
if (!Settings->webcam_config.stream) { WcInterruptControl(); } // Stop stream
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndStateText(Settings->webcam_config.stream);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamResolution(void) {
|
2021-02-18 19:37:35 +00:00
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < FRAMESIZE_FHD)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.resolution = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(0, Settings->webcam_config.resolution);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->webcam_config.resolution);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamMirror(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.mirror = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(3, Settings->webcam_config.mirror);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndStateText(Settings->webcam_config.mirror);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamFlip(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.flip = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(2, Settings->webcam_config.flip);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndStateText(Settings->webcam_config.flip);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamSaturation(void) {
|
|
|
|
if ((XdrvMailbox.payload >= -2) && (XdrvMailbox.payload <= 2)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.saturation = XdrvMailbox.payload +2;
|
|
|
|
WcSetOptions(6, Settings->webcam_config.saturation -2);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->webcam_config.saturation -2);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamBrightness(void) {
|
|
|
|
if ((XdrvMailbox.payload >= -2) && (XdrvMailbox.payload <= 2)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.brightness = XdrvMailbox.payload +2;
|
|
|
|
WcSetOptions(5, Settings->webcam_config.brightness -2);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->webcam_config.brightness -2);
|
2020-05-08 16:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamContrast(void) {
|
|
|
|
if ((XdrvMailbox.payload >= -2) && (XdrvMailbox.payload <= 2)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.contrast = XdrvMailbox.payload +2;
|
|
|
|
WcSetOptions(4, Settings->webcam_config.contrast -2);
|
2020-05-02 15:44:44 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->webcam_config.contrast -2);
|
2020-05-02 15:44:44 +01:00
|
|
|
}
|
|
|
|
|
2022-04-26 23:25:26 +01:00
|
|
|
void CmndWebcamSpecialEffect(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 6)) {
|
|
|
|
Settings->webcam_config2.special_effect = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(1, Settings->webcam_config2.special_effect);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.special_effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAWB(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.awb = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(7, Settings->webcam_config.awb);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.awb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamWBMode(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 4)) {
|
|
|
|
Settings->webcam_config2.wb_mode = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(8, Settings->webcam_config2.wb_mode);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.wb_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAWBGain(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.awb_gain = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(9, Settings->webcam_config.awb_gain);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.awb_gain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAEC(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.aec = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(10, Settings->webcam_config.aec);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.aec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAECValue(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1200)) {
|
|
|
|
Settings->webcam_config2.aec_value = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(11, Settings->webcam_config2.aec_value);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.aec_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAELevel(void) {
|
|
|
|
if ((XdrvMailbox.payload >= -2) && (XdrvMailbox.payload <= 2)) {
|
|
|
|
Settings->webcam_config2.ae_level = XdrvMailbox.payload + 2;
|
|
|
|
WcSetOptions(12, Settings->webcam_config2.ae_level - 2);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.ae_level - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAEC2(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.aec2 = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(13, Settings->webcam_config.aec2);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.aec2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAGC(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.agc = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(14, Settings->webcam_config.agc);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.agc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamAGCGain(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 30)) {
|
|
|
|
Settings->webcam_config2.agc_gain = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(15, Settings->webcam_config2.agc_gain);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.agc_gain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamGainCeiling(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 6)) {
|
|
|
|
Settings->webcam_config2.gainceiling = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(16, Settings->webcam_config2.gainceiling);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.gainceiling);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamGammaCorrect(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.raw_gma = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(17, Settings->webcam_config.raw_gma);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.raw_gma);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamLensCorrect(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.lenc = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(18, Settings->webcam_config.lenc);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.lenc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamWPC(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.wpc = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(19, Settings->webcam_config.wpc);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.wpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamDCW(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.dcw = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(20, Settings->webcam_config.dcw);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.dcw);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamBPC(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.bpc = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(21, Settings->webcam_config.bpc);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.bpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWebcamColorbar(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
|
|
|
Settings->webcam_config.colorbar = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(22, Settings->webcam_config.colorbar);
|
|
|
|
}
|
|
|
|
ResponseCmndStateText(Settings->webcam_config.colorbar);
|
|
|
|
}
|
|
|
|
|
2022-04-27 21:37:32 +01:00
|
|
|
void CmndWebcamFeature(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) {
|
|
|
|
Settings->webcam_config.feature = XdrvMailbox.payload;
|
|
|
|
WcSetOptions(23, Settings->webcam_config.feature);
|
2022-04-26 23:25:26 +01:00
|
|
|
}
|
2022-04-27 21:37:32 +01:00
|
|
|
ResponseCmndNumber(Settings->webcam_config.feature);
|
2022-04-26 23:25:26 +01:00
|
|
|
}
|
|
|
|
|
2022-05-20 11:30:12 +01:00
|
|
|
void CmndWebcamAuth(void){
|
|
|
|
if((XdrvMailbox.payload >=0) && (XdrvMailbox.payload <= 1)){
|
|
|
|
Settings->webcam_config2.auth = XdrvMailbox.payload;
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_config2.auth);
|
|
|
|
}
|
|
|
|
|
2022-10-13 16:58:16 +01:00
|
|
|
void CmndWebcamClock(void){
|
|
|
|
if((XdrvMailbox.payload >= 10) && (XdrvMailbox.payload <= 200)){
|
|
|
|
Settings->webcam_clk = XdrvMailbox.payload;
|
2022-10-14 12:54:37 +01:00
|
|
|
WcInterruptControl();
|
2022-10-13 16:58:16 +01:00
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->webcam_clk);
|
|
|
|
}
|
|
|
|
|
2020-10-19 06:26:42 +01:00
|
|
|
void CmndWebcamInit(void) {
|
2021-12-17 17:01:27 +00:00
|
|
|
WcInterruptControl();
|
2020-10-19 06:26:42 +01:00
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
2022-04-26 23:25:26 +01:00
|
|
|
void CmndWebcamSetDefaults(void) {
|
|
|
|
WcSetDefaults(0);
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define D_WEBCAM_STATS_FPS "FPS"
|
|
|
|
#define D_WEBCAM_STATS_CAMFAIL "CamFail"
|
|
|
|
#define D_WEBCAM_STATS_JPEGFAIL "JpegFail"
|
|
|
|
#define D_WEBCAM_STATS_CLIENTFAIL "ClientFail"
|
|
|
|
|
|
|
|
void CmndWebcamStats(void) {
|
|
|
|
Response_P(PSTR("{\"" D_PRFX_WEBCAM D_CMND_WC_STATS "\":{\"" D_WEBCAM_STATS_FPS "\":%d,\""
|
|
|
|
D_WEBCAM_STATS_CAMFAIL "\":%d,\"" D_WEBCAM_STATS_JPEGFAIL "\":%d,\"" D_WEBCAM_STATS_CLIENTFAIL "\":%d"
|
|
|
|
"}}"),
|
|
|
|
WcStats.camfps, WcStats.camfail, WcStats.jpegfail, WcStats.clientfail
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-20 07:42:44 +00:00
|
|
|
#ifdef ENABLE_RTSPSERVER
|
|
|
|
void CmndWebRtsp(void) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->webcam_config.rtsp = XdrvMailbox.payload;
|
2021-01-20 07:42:44 +00:00
|
|
|
TasmotaGlobal.restart_flag = 2;
|
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndStateText(Settings->webcam_config.rtsp);
|
2021-01-20 07:42:44 +00:00
|
|
|
}
|
|
|
|
#endif // ENABLE_RTSPSERVER
|
|
|
|
|
2022-04-26 23:25:26 +01:00
|
|
|
void WcUpdateStats(void) {
|
|
|
|
WcStats.camfps = WcStats.camcnt;
|
|
|
|
WcStats.camcnt = 0;
|
|
|
|
}
|
|
|
|
|
2022-05-05 15:26:29 +01:00
|
|
|
const char HTTP_WEBCAM_FPS[] PROGMEM = "{s}%s " D_FRAME_RATE "{m}%d " D_UNIT_FPS "{e}";
|
2022-04-26 23:25:26 +01:00
|
|
|
|
|
|
|
void WcStatsShow(void) {
|
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
WSContentSend_PD(HTTP_WEBCAM_FPS, WcStats.name, WcStats.camfps);
|
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
2021-01-20 07:42:44 +00:00
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
2020-05-02 07:10:23 +01:00
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
bool Xdrv81(uint32_t function) {
|
2020-05-02 07:10:23 +01:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
switch (function) {
|
|
|
|
case FUNC_LOOP:
|
2020-05-12 13:30:07 +01:00
|
|
|
WcLoop();
|
2020-05-02 07:10:23 +01:00
|
|
|
break;
|
|
|
|
case FUNC_WEB_ADD_HANDLER:
|
2020-05-12 13:30:07 +01:00
|
|
|
WcPicSetup();
|
2020-05-02 07:10:23 +01:00
|
|
|
break;
|
2020-05-02 15:44:44 +01:00
|
|
|
case FUNC_WEB_ADD_MAIN_BUTTON:
|
2020-05-08 16:17:09 +01:00
|
|
|
WcShowStream();
|
2020-05-05 08:36:43 +01:00
|
|
|
break;
|
2022-04-26 23:25:26 +01:00
|
|
|
case FUNC_EVERY_SECOND:
|
|
|
|
WcUpdateStats();
|
|
|
|
case FUNC_WEB_SENSOR:
|
|
|
|
WcStatsShow();
|
|
|
|
break;
|
2020-05-02 15:44:44 +01:00
|
|
|
case FUNC_COMMAND:
|
|
|
|
result = DecodeCommand(kWCCommands, WCCommand);
|
|
|
|
break;
|
2020-05-04 16:13:14 +01:00
|
|
|
case FUNC_PRE_INIT:
|
|
|
|
WcInit();
|
|
|
|
break;
|
2020-05-05 08:36:43 +01:00
|
|
|
|
2020-05-02 07:10:23 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-03 17:37:12 +01:00
|
|
|
#endif // USE_WEBCAM
|
|
|
|
#endif // ESP32
|