enable micro-rtsp

This commit is contained in:
dreamer 2020-09-09 13:37:04 +02:00
parent 7ec31edf21
commit fd145903db

View File

@ -29,6 +29,12 @@
#include <SPIFFS.h>
#include <EEPROM.h>
#include "OV2640.h"
#include "SimStreamer.h"
#include "OV2640Streamer.h"
#include "CRtspSession.h"
#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3003000)
#warning "Requires FastLED 3.3 or later; check github for latest code."
#endif
@ -88,6 +94,11 @@ CRGB leds[NUM_LEDS];
#include "wifi.h"
#include "web.h"
#define CAMERA_MODEL_AI_THINKER
OV2640 cam;
WiFiServer rtspServer(8554);
CStreamer *streamer;
// wifi ssid and password should be added to a file in the sketch named secrets.h
// the secrets.h file should be added to the .gitignore file and never committed or
// pushed to public source control (GitHub).
@ -125,6 +136,16 @@ void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
}
}
void setupCam() {
esp32cam_aithinker_config.frame_size = FRAMESIZE_VGA;
// esp32cam_aithinker_config.frame_size = FRAMESIZE_QVGA;
esp32cam_aithinker_config.jpeg_quality = 16;
cam.init(esp32cam_aithinker_config);
rtspServer.begin();
streamer = new OV2640Streamer(cam); // our streamer for UDP/TCP based RTP transport
}
void setup() {
pinMode(led, OUTPUT);
digitalWrite(led, 1);
@ -139,7 +160,7 @@ void setup() {
setupWifi();
setupWeb();
setupCam();
// Parallel output: 13, 12, 15, 14,
FastLED.addLeds<LED_TYPE, 13, COLOR_ORDER>(leds, 0, NUM_LEDS_PER_STRIP).setCorrection(TypicalLEDStrip);
@ -188,8 +209,42 @@ void loop()
FastLED.show();
// insert a delay to keep the framerate modest
// FastLED.delay(1000 / FRAMES_PER_SECOND);
delay(1000 / FRAMES_PER_SECOND);
FastLED.delay(1000 / FRAMES_PER_SECOND);
// delay(1000 / FRAMES_PER_SECOND);
//
// micro-rtsp server section
//
uint32_t msecPerFrame = 100;
static uint32_t lastimage = millis();
// If we have an active client connection, just service that until gone
streamer->handleRequests(0); // we don't use a timeout here,
// instead we send only if we have new enough frames
uint32_t now = millis();
if(streamer->anySessions()) {
if(now > lastimage + msecPerFrame || now < lastimage) { // handle clock rollover
streamer->streamImage(now);
lastimage = now;
// check if we are overrunning our max frame rate
now = millis();
if(now > lastimage + msecPerFrame) {
printf("warning exceeding max frame rate of %d ms\n", now - lastimage);
}
}
}
WiFiClient rtspClient = rtspServer.accept();
if(rtspClient) {
Serial.print("client: ");
Serial.print(rtspClient.remoteIP());
Serial.println();
streamer->addSession(rtspClient);
}
}
void nextPattern()