From c104f055ee534980b4b309bf3f87de9fc649f12f Mon Sep 17 00:00:00 2001 From: John Varghese Date: Mon, 9 Jun 2025 21:59:01 +0530 Subject: [PATCH] . --- ESP32CAM-ONVIF/MyStreamer.cpp | 10 ++++++ ESP32CAM-ONVIF/MyStreamer.h | 13 ++++++++ ESP32CAM-ONVIF/rtsp_server.cpp | 56 +++++++++++++++++++++++++++++----- ESP32CAM-ONVIF/rtsp_server.h | 10 +++++- 4 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 ESP32CAM-ONVIF/MyStreamer.cpp create mode 100644 ESP32CAM-ONVIF/MyStreamer.h diff --git a/ESP32CAM-ONVIF/MyStreamer.cpp b/ESP32CAM-ONVIF/MyStreamer.cpp new file mode 100644 index 0000000..106024e --- /dev/null +++ b/ESP32CAM-ONVIF/MyStreamer.cpp @@ -0,0 +1,10 @@ +// MyStreamer.cpp +#include "MyStreamer.h" + +void MyStreamer::streamImage(uint32_t curMsec) { + uint8_t *image = m_cam.getfb(); + uint32_t size = m_cam.getSize(); + if (image && size) { + streamFrame(image, size, curMsec); + } +} diff --git a/ESP32CAM-ONVIF/MyStreamer.h b/ESP32CAM-ONVIF/MyStreamer.h new file mode 100644 index 0000000..a5ac09b --- /dev/null +++ b/ESP32CAM-ONVIF/MyStreamer.h @@ -0,0 +1,13 @@ +// MyStreamer.h +#pragma once +#include "OV2640.h" +#include "CStreamer.h" + +class MyStreamer : public CStreamer { +public: + MyStreamer(OV2640 &cam) : CStreamer(cam.getWidth(), cam.getHeight()), m_cam(cam) {} + virtual ~MyStreamer() {} + virtual void streamImage(uint32_t curMsec) override; +private: + OV2640 &m_cam; +}; diff --git a/ESP32CAM-ONVIF/rtsp_server.cpp b/ESP32CAM-ONVIF/rtsp_server.cpp index f1c9b72..40a75d0 100644 --- a/ESP32CAM-ONVIF/rtsp_server.cpp +++ b/ESP32CAM-ONVIF/rtsp_server.cpp @@ -1,28 +1,70 @@ #include "rtsp_server.h" -#include -#include "OV2640.h" -#include "CRtspSession.h" WiFiServer rtspServer(554); OV2640 cam; +MyStreamer *streamer = nullptr; String getRTSPUrl() { return "rtsp://" + WiFi.localIP().toString() + ":554/mjpeg/1"; } void rtsp_server_start() { + // Fill in your ESP32-CAM pin assignments + camera_config_t config; + config.pin_pwdn = -1; + config.pin_reset = -1; + config.pin_xclk = 4; + config.pin_sscb_sda = 18; + config.pin_sscb_scl = 23; + config.pin_d7 = 36; + config.pin_d6 = 37; + config.pin_d5 = 38; + config.pin_d4 = 39; + config.pin_d3 = 35; + config.pin_d2 = 14; + config.pin_d1 = 13; + config.pin_d0 = 34; + config.pin_vsync = 5; + config.pin_href = 27; + config.pin_pclk = 25; + config.xclk_freq_hz = 20000000; + config.ledc_timer = LEDC_TIMER_0; + config.ledc_channel = LEDC_CHANNEL_0; + config.pixel_format = PIXFORMAT_JPEG; + config.frame_size = FRAMESIZE_VGA; + config.jpeg_quality = 12; + config.fb_count = 1; + + cam.init(config); + streamer = new MyStreamer(cam); rtspServer.begin(); - cam.init(esp_camera_sensor_get()); Serial.println("[INFO] RTSP server started at " + getRTSPUrl()); } void rtsp_server_loop() { WiFiClient client = rtspServer.available(); if (client) { - CRtspSession session(client, cam); + // Micro-RTSP expects a SOCKET (int) and a CStreamer* + // On ESP32, WiFiClient.fd() is not available, so we use a hack: + // Pass the client object as a void* and cast it back in the library. + // This requires a custom build of Micro-RTSP or using the ESP32-compatible fork. + // For simplicity, this example assumes you have modified Micro-RTSP to accept WiFiClient*. + // If not, use the standard Micro-RTSP example and adapt as needed. + // For now, this is a placeholder: + // CRtspSession session(client, streamer); // Won't work out of the box! + // Instead, use the following workaround (requires library modification): + // CRtspSession session((void*)&client, streamer); + // Or use the standard Micro-RTSP example code. + + // IMPORTANT: The standard Micro-RTSP library does not support WiFiClient directly. + // You must either: + // 1. Use the standard Micro-RTSP example with a custom streamer, or + // 2. Modify the library to accept WiFiClient* (advanced). + + // For now, here is a placeholder. See notes below for a real solution. + Serial.println("Client connected, but RTSP session handling is not implemented."); while (client.connected()) { - session.handleRequests(0); - session.broadcastCurrentFrame(0); + // Handle client here if you modify the library delay(10); } client.stop(); diff --git a/ESP32CAM-ONVIF/rtsp_server.h b/ESP32CAM-ONVIF/rtsp_server.h index 553eccf..6f58d45 100644 --- a/ESP32CAM-ONVIF/rtsp_server.h +++ b/ESP32CAM-ONVIF/rtsp_server.h @@ -1,6 +1,14 @@ #pragma once #include +#include +#include "OV2640.h" +#include "CRtspSession.h" +#include "MyStreamer.h" +extern WiFiServer rtspServer; +extern OV2640 cam; +extern MyStreamer *streamer; + +String getRTSPUrl(); void rtsp_server_start(); void rtsp_server_loop(); -String getRTSPUrl();