Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Nov 2, 2024
1 parent 4b50b52 commit 4dc36fb
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 204 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ There are a lot of boards available that are all called ESP32-CAM.
However, there are differences in CPU (type/speed/cores), how the camera is connected, presence of PSRAM or not...
To select the right board use the table below and use the configuration that is listed below for your board:

| Board | Image | CPU | SRAM | Flash | PSRAM | Camera | | Site |
| Board | Image | CPU | SRAM | Flash | PSRAM | Camera | Extras | Manufacturer site |
|--- |--- |--- |--- |--- | --- |--- |--- |--- |
| Espressif ESP32-Wrover CAM | ![img](assets/boards/esp32-wrover-cam.jpg) | ESP32 | 520KB | 4Mb | 4MB | OV2640 | | |
| AI-Thinker ESP32-CAM | ![img](assets/boards/ai-thinker-esp32-cam-ipex.jpg) ![img](assets/boards/ai-thinker-esp32-cam.jpg) | ESP32-S | 520KB | 4Mb | 4MB | OV2640 | | [https://docs.ai-thinker.com/esp32-cam](https://docs.ai-thinker.com/esp32-cam) |
Expand Down
1 change: 1 addition & 0 deletions dotnet_riscv
Submodule dotnet_riscv added at 70e3cb
13 changes: 7 additions & 6 deletions lib/micro-rtsp-server/include/micro_rtsp_camera.h
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -11,12 +12,12 @@ class micro_rtsp_camera
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_;
Expand Down
56 changes: 29 additions & 27 deletions lib/micro-rtsp-server/include/micro_rtsp_requests.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <map>
#include <string>

class micro_rtsp_requests
Expand All @@ -8,40 +9,41 @@ class micro_rtsp_requests
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
};

const char* available_stream_name_ = "mjpeg/1";

rtsp_command parse_command(const std::string &request);
// 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
// };

static const std::string available_stream_name_;

//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_;
Expand Down
8 changes: 4 additions & 4 deletions lib/micro-rtsp-server/include/micro_rtsp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -36,7 +36,7 @@ class micro_rtsp_server : WiFiServer
};

private:
micro_rtsp_camera &source_;
micro_rtsp_source &source_;
unsigned frame_interval_;
unsigned long next_frame_update_;
unsigned long next_check_client_;
Expand Down
16 changes: 16 additions & 0 deletions lib/micro-rtsp-server/include/micro_rtsp_source.h
Original file line number Diff line number Diff line change
@@ -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;
};
7 changes: 4 additions & 3 deletions lib/micro-rtsp-server/include/micro_rtsp_streamer.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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_;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4dc36fb

Please sign in to comment.