Recently I discovered the Micro-RTSP-Audio Project from Thomas Pfitzinger which is based on Micro-RTSP from Kevin Hester.

The Real Time Streaming Protocol (RTSP) is an application-level network communication system that transfers real-time data from multimedia to an endpoint device by communicating directly with the server streaming the data.

I tried to adapt the library to make sure that it is also compiling in Arduino and converted the example to comply with the Arduino conventions. However when I started to test it, I was running into memory errors and I spent almost a full day looking at the source code trying to figure out what could be wrong and while doing this, I took the chance to perform some optimizations.

In the end it turned out that the issue was not in the library code but in the provided example: some objects where allocated on the stack and after the setup method, these objects were not valid any more!

My updated Micro-RTSP-Audio Library can be found on Github and the example is working now and I am providing an nice integration into my Audio Tools Library:

Arduino Sketch

#include "AudioTools.h"
#include "AudioLibs/MicroRTSPAudio.h"
#include "AudioStreamer.h"
#include "RTSPServer.h"

int port = 554;
int channels = 1;
int sample_rate = 16000;
int bits_per_sample = 16;
const char* wifi = "wifi";
const char* password = "password";

SineFromTable<int16_t> sineWave(32000);                // subclass of SoundGenerator 
GeneratedSoundStream<int16_t> sound(sineWave);             // Stream generated from sine wave
RTSPSourceAudioStream source(sound);                       // Stream sound via RTSP
AudioStreamer streamer = AudioStreamer(&source);
RTSPServer rtsp = RTSPServer(&streamer, port);


void setup() {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // Setup sine wave
  auto cfgS = sineWave.defaultConfig();
  cfgS.channels = channels;
  cfgS.sample_rate = sample_rate;
  cfgS.bits_per_sample = bits_per_sample;
  sineWave.begin(cfgS, N_B4);

  // Start Wifi & RTSP
  rtsp.begin(wifi, password);
}

void loop() { delay(1000); }

This example can be found on Github.

To listen to the generated sound you can use the VLC Media Player. Goto -> File -> Open Network and enter the URL rtsp://server-address

Caveat: Please note that currently only the sampling rate 16000 with 1 channel is supported!


4 Comments

Mira · 30. November 2022 at 0:02

hello,
my ArduinoIDE (1.8.19) write error:
“C:\Arduino ESP32\portable\sketchbook\libraries\arduino-audio-tools-main\src/AudioLibs/AudioKit.h:4:25: fatal error: AudioKitHAL.h: No such file or directory”
I have installed both linked libraries “updated Micro-RTSP-Audio Library” and “my Audio Tools Library”.

Where can i found “AudioKitHAL.h”, please?
Thank you

Han · 12. October 2022 at 9:43

Hello, i enjoyed reading it! thanks for sharing.
i have question might be ridiculous, if i stopped the stream, am i be able to view the previous streams?

    pschatzmann · 12. October 2022 at 11:14

    I don’t know. I guess this depends on the software that you use…

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *