• Stars
    star
    744
  • Rank 60,513 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A RTSP video server intended for very small CPUs (ESP32 etc)

Micro-RTSP

This is a small library which can be used to serve up RTSP streams from resource constrained MCUs. It lets you trivially make a $10 open source RTSP video stream camera.

Usage

This library works for ESP32/arduino targets but also for most any posixish platform.

Example arduino/ESP32 usage

This library will work standalone, but it is super easy to use if your app is platform.io based. Just "pio lib install Micro-RTSP" to pull the latest version from their library server. If you want to use the OV2640 camera support you'll need to be targeting the espressif32 platform in your project.

See the example platform.io app. It should build and run on virtually any of the $10 ESP32-CAM boards (such as M5CAM). The relevant bit of the code is included below. In short:

  1. Listen for a TCP connection on the RTSP port with accept()
  2. When a connection comes in, create a CRtspSession and OV2640Streamer camera streamer objects.
  3. While the connection remains, call session->handleRequests(0) to handle any incoming client requests.
  4. Every 100ms or so call session->broadcastCurrentFrame() to send new frames to any clients.
void loop()
{
    uint32_t msecPerFrame = 100;
    static uint32_t lastimage = millis();

    // If we have an active client connection, just service that until gone
    // (FIXME - support multiple simultaneous clients)
    if(session) {
        session->handleRequests(0); // we don't use a timeout here,
        // instead we send only if we have new enough frames

        uint32_t now = millis();
        if(now > lastimage + msecPerFrame || now < lastimage) { // handle clock rollover
            session->broadcastCurrentFrame(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);
        }

        if(session->m_stopped) {
            delete session;
            delete streamer;
            session = NULL;
            streamer = NULL;
        }
    }
    else {
        client = rtspServer.accept();

        if(client) {
            //streamer = new SimStreamer(&client, true);             // our streamer for UDP/TCP based RTP transport
            streamer = new OV2640Streamer(&client, cam);             // our streamer for UDP/TCP based RTP transport

            session = new CRtspSession(&client, streamer); // our threads RTSP session and state
        }
    }
}

Example posix/linux usage

There is a small standalone example here. You can build it by following these directions. The usage of the two key classes (CRtspSession and SimStreamer) are very similar to to the ESP32 usage.

Supporting new camera devices

Supporting new camera devices is quite simple. See OV2640Streamer for an example and implement streamImage() by reading a frame from your camera.

Structure and design notes

Issues and sending pull requests

Please report issues and send pull requests. I'll happily reply. ;-)

Credits

The server code was initially based on a great 2013 tutorial by Medialan.

License

Copyright 2018 S. Kevin Hester-Chow, [email protected] (MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

TenDollarWebcam

A small example app for ESP32 + Micro-RTSP
C++
388
star
2

arduleader

An android ground controller (and other things) for Mavlink/Arduplane
Scala
141
star
3

steamback

A Decky plugin to add versioned save-game snapshots to Steam-cloud enabled games.
Python
57
star
4

framework-portduino

An Arduino API that sits on top of Linux and other operating systems. This lets you run Arduino code on Raspberry PI, desktops, etc... All as a standard user-space application.
C++
42
star
5

AutoWifi

Making ESP32 wifi setup trivial with Android/iOS helper apps. 5 lines of code and no more hardcoded keys.
C++
38
star
6

Gaggle

An Android application for glider pilots
Java
34
star
7

nrf51-extractor

A tool for code readout of 'protected' NRF51 devices - using a ST-LINK/jtag.
Python
14
star
8

ezdevice-esp32

Client side software for ezdevices (ESP32 version)
C++
8
star
9

usb-serial-for-android

An unofficial fork of http://code.google.com/p/usb-serial-for-android/
Java
7
star
10

reddit-bots

The old source code to /u/All-American-Bot
Python
6
star
11

SW102_LCD_Bluetooth

C
3
star
12

ParticleWebLog

A publish based web logger for particle.io
C++
3
star
13

ESP32-AutoUpdate

Making secure software updates from the cloud for your ESP32 project/product
C++
3
star
14

AndroidShared

Code that is used as a submodule by a number of Geeksville modules
Java
2
star
15

ezdevice-python

Python tool & library for using ESP32 based Ezdevice.net projects
Python
2
star
16

API

drone API experiments
Python
1
star
17

particle-humidity

A cloudified humidity sensor based on particle.io
C++
1
star
18

hummingbot

A google AIY-Vision machine vision based hummingbird tweeting bot
Python
1
star
19

SW102_LCD_Bluetooth-bootloader

C
1
star
20

3scale-akka

A small async akka wrapper for the 3scale.com API
Scala
1
star
21

ardupilot

C
1
star
22

primus-python

A python client for sending/receiving real time events with Primus compatible servers.
Python
1
star