Work in progress

This commit is contained in:
Rene Zeldenthuis
2024-11-02 21:45:07 +01:00
parent 4b50b52ae0
commit 4dc36fb1e8
12 changed files with 202 additions and 198 deletions

View File

@@ -1,8 +1,9 @@
#pragma once
#include <micro_rtsp_source.h>
#include <esp_camera.h>
class micro_rtsp_camera
class micro_rtsp_camera : public micro_rtsp_source
{
public:
micro_rtsp_camera();
@@ -11,12 +12,12 @@ public:
esp_err_t initialize(camera_config_t *camera_config);
esp_err_t deinitialize();
void update_frame();
virtual void update_frame();
uint8_t *data() const { return fb_->buf; }
size_t width() const { return fb_->width; }
size_t height() const { return fb_->height; }
size_t size() const { return fb_->len; }
virtual uint8_t *data() const { return fb_->buf; }
virtual size_t width() const { return fb_->width; }
virtual size_t height() const { return fb_->height; }
virtual size_t size() const { return fb_->len; }
private:
esp_err_t init_result_;

View File

@@ -1,5 +1,6 @@
#pragma once
#include <map>
#include <string>
class micro_rtsp_requests
@@ -8,40 +9,41 @@ public:
std::string process_request(const std::string& request);
private:
enum rtsp_command
{
rtsp_command_unknown,
rtsp_command_option, // OPTIONS
rtsp_command_describe, // DESCRIBE
rtsp_command_setup, // SETUP
rtsp_command_play, // PLAY
rtsp_command_teardown // TEARDOWN
};
// enum rtsp_command
// {
// rtsp_command_unknown,
// rtsp_command_options, // OPTIONS
// rtsp_command_describe, // DESCRIBE
// rtsp_command_setup, // SETUP
// rtsp_command_play, // PLAY
// rtsp_command_teardown // TEARDOWN
// };
const char* available_stream_name_ = "mjpeg/1";
static const std::string available_stream_name_;
rtsp_command parse_command(const std::string &request);
//rtsp_command parse_command(const std::string &request);
//static bool parse_cseq(const std::string &line, unsigned long &cseq);
bool parse_client_port(const std::string &request);
bool parse_cseq(const std::string &request);
bool parse_stream_url(const std::string &request);
//bool parse_stream_url(const std::string &request);
std::string date_header();
std::string rtsp_error(unsigned short code, const std::string& message);
//static std::string date_header();
static std::string handle_rtsp_error(unsigned long cseq, unsigned short code, const std::string &message);
std::string handle_option(const std::string &request);
std::string handle_describe(const std::string &request);
std::string handle_setup(const std::string &request);
std::string handle_play(const std::string &request);
std::string handle_teardown(const std::string &request);
static std::string handle_options(unsigned long cseq);
static std::string handle_describe(unsigned long cseq, const std::string &request);
std::string handle_setup(unsigned long cseq, const std::map<std::string, std::string> &request);
std::string handle_play(unsigned long cseq);
std::string handle_teardown(unsigned long cseq);
unsigned long cseq_;
//unsigned long cseq_;
std::string host_url_;
unsigned short host_port_;
std::string stream_name_;
// std::string host_url_;
// unsigned short host_port_;
// std::string stream_name_;
bool tcp_transport_;
unsigned short client_port_;
unsigned short start_client_port_;
unsigned short end_client_port_;
unsigned short rtp_streamer_port_;
unsigned short rtcp_streamer_port_;

View File

@@ -13,18 +13,18 @@
class micro_rtsp_server : WiFiServer
{
public:
micro_rtsp_server(micro_rtsp_camera &source, unsigned frame_interval = 100);
micro_rtsp_server(micro_rtsp_source &source);
~micro_rtsp_server();
void begin(unsigned short port = 554);
void end();
unsigned get_frame_interval() { return frame_interval_; }
unsigned get_frame_interval() const { return frame_interval_; }
unsigned set_frame_interval(unsigned value) { return frame_interval_ = value; }
void loop();
size_t clients() { return clients_.size(); }
size_t clients() const { return clients_.size(); }
class rtsp_client : public WiFiClient, public micro_rtsp_requests
{
@@ -36,7 +36,7 @@ public:
};
private:
micro_rtsp_camera &source_;
micro_rtsp_source &source_;
unsigned frame_interval_;
unsigned long next_frame_update_;
unsigned long next_check_client_;

View File

@@ -0,0 +1,16 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
// Interface for a video source
class micro_rtsp_source
{
public:
virtual void update_frame() = 0;
virtual uint8_t *data() const = 0;
virtual size_t width() const = 0;
virtual size_t height() const = 0;
virtual size_t size() const = 0;
};

View File

@@ -1,7 +1,8 @@
#pragma once
#include <jpg_section.h>
#include <micro_rtp_structs.h>
#include <micro_rtsp_camera.h> // Add this line to include the definition of micro_rtsp_camera
#include <micro_rtsp_structs.h>
// https://en.wikipedia.org/wiki/Maximum_transmission_unit
constexpr size_t max_wifi_mtu = 2304;
@@ -32,11 +33,11 @@ typedef struct __attribute__((packed))
class micro_rtsp_streamer
{
public:
micro_rtsp_streamer(const uint16_t width, const uint16_t height);
micro_rtsp_streamer(const micro_rtsp_source& source);
rtp_over_tcp_hdr_t *create_jpg_packet(const uint8_t *jpg_scan, const uint8_t *jpg_scan_end, uint8_t **jpg_offset, const uint32_t timestamp, const uint8_t *quantization_table_luminance, const uint8_t *quantization_table_chrominance);
private:
uint16_t width_, height_;
const micro_rtsp_source& source_;
uint32_t ssrc_;
uint16_t sequence_number_;
};

View File

@@ -5,9 +5,9 @@
// https://www.ietf.org/rfc/rfc2326#section-10.12
typedef struct __attribute__((packed))
{
char magic='$'; // Magic encapsulation ASCII dollar sign (24 hexadecimal)
uint8_t channel; // Channel identifier
uint16_t length; // Network order
char magic = '$'; // Magic encapsulation ASCII dollar sign (24 hexadecimal)
uint8_t channel; // Channel identifier
uint16_t length; // Network order
} rtp_over_tcp_hdr_t;
// RTP data header - http://www.ietf.org/rfc/rfc3550.txt