forked from external-repos/ESP32-CAM-ONVIF
.
This commit is contained in:
10
ESP32CAM-ONVIF/MyStreamer.cpp
Normal file
10
ESP32CAM-ONVIF/MyStreamer.cpp
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
13
ESP32CAM-ONVIF/MyStreamer.h
Normal file
13
ESP32CAM-ONVIF/MyStreamer.h
Normal file
@@ -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;
|
||||
};
|
||||
@@ -1,28 +1,70 @@
|
||||
#include "rtsp_server.h"
|
||||
#include <WiFi.h>
|
||||
#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();
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#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();
|
||||
|
||||
Reference in New Issue
Block a user