Skip to content
Merged

Rtsp #2174

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e48ff87
CopyEncoder: prevent NPE
pschatzmann Sep 12, 2025
0c676b0
AudioInfo: bool() check for range
pschatzmann Sep 12, 2025
c88929a
EncodedAudioStream: invalid AudioInfo
pschatzmann Sep 12, 2025
a3aeab1
rtsp corrections
pschatzmann Sep 12, 2025
0fb40ed
RTSP: integrate server
pschatzmann Sep 13, 2025
fca1799
RTSP namespace
pschatzmann Sep 13, 2025
b039d86
clean up platform
pschatzmann Sep 13, 2025
647b2cd
RTSP use template class fro platform
pschatzmann Sep 13, 2025
6b7499d
delete DefaultRTSPPlatform
pschatzmann Sep 13, 2025
2d27984
Remove WiFiClient
pschatzmann Sep 13, 2025
7b1e6c9
AudioTimerESP32
pschatzmann Sep 14, 2025
7443ea3
Cleanup
pschatzmann Sep 14, 2025
da4ceac
RTSPAudioStreamer: cleanup
pschatzmann Sep 14, 2025
bb74798
RTSP: closing and restart fix
pschatzmann Sep 14, 2025
faff41a
RtspSession: cleanup
pschatzmann Sep 14, 2025
17e14ef
FrameDurationSource: new class
pschatzmann Sep 14, 2025
ffe4ee6
RTSP dynamic timer update
pschatzmann Sep 14, 2025
1989da1
MP3ParserDecoder, MP3ParserEncoder
pschatzmann Sep 14, 2025
7a1d70c
RTSPFormatAudioTools audioInfo()
pschatzmann Sep 15, 2025
3d17a32
OpusAudioEncoder: trace on setAudioInfo()
pschatzmann Sep 15, 2025
c7ce88e
USE_LEGACY_I2S;: ifndef
pschatzmann Sep 15, 2025
c58fe23
USE_LEGACY_I2S: make it idf version dependent
pschatzmann Sep 15, 2025
33e5748
OpusAudioEncoder: rollback setAudioInfo trace
pschatzmann Sep 15, 2025
0f4c3ef
RTSPOutput: use of DynamicMemoryStream
pschatzmann Sep 15, 2025
9a70f48
RTSP compile errors
pschatzmann Sep 15, 2025
1e2f5ee
RTSP compile errors
pschatzmann Sep 16, 2025
d98ab6e
RTSP cleanup
pschatzmann Sep 17, 2025
85ff75b
AudioTimerLinux
pschatzmann Sep 17, 2025
1c59c42
fix cmake build errors
pschatzmann Sep 17, 2025
98c64c1
cmake SD build errors
pschatzmann Sep 17, 2025
54940cc
VSF documentation
pschatzmann Sep 17, 2025
7eb49e2
MetaDataFilterEncoder
pschatzmann Sep 17, 2025
97ab7e7
RTSP: compile errors
pschatzmann Sep 18, 2025
38b062e
RTSP
pschatzmann Sep 18, 2025
f557a74
RTSP: user WiFiServer
pschatzmann Sep 18, 2025
dea800a
Task: Desktop support
pschatzmann Sep 18, 2025
785455a
rtsp
pschatzmann Sep 18, 2025
cfeec40
RTSPServer compile error Ethernet.h
pschatzmann Sep 19, 2025
d077732
RTSPAudioStreamerUsingTask: throttle interval
pschatzmann Sep 19, 2025
e77f7aa
RTSPAudioStreamerUsingTask: throttling true by default
pschatzmann Sep 19, 2025
d25051f
test: mp3-parser
pschatzmann Sep 20, 2025
9c68f76
HeaderParserMP3: corrections
pschatzmann Sep 20, 2025
92181f1
rtsp
pschatzmann Sep 20, 2025
db5e179
RTSP: mp3 corrections
pschatzmann Sep 20, 2025
0221617
RTSP: test
pschatzmann Sep 20, 2025
4ffa30a
Task: prevent deadlock
pschatzmann Sep 20, 2025
d840b87
RTSP: corrections for ffplay
pschatzmann Sep 21, 2025
b3c8f47
RTSP: automitic rfc2250 header
pschatzmann Sep 21, 2025
5675602
RTPSession: cleanup
pschatzmann Sep 21, 2025
46222a0
Merge branch 'main' into rtsp
pschatzmann Sep 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build/
.vscode/
_deps/
.ipynb_checkpoints/
.DS_Store
.DS_Store
miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioLibs/RTSP.h"
#include "AudioStreamer.h"
#include "RTSPServer.h"
#include "AudioTools/Communication/RTSP.h"

int port = 554;
AudioBoardStream kit(AudioKitEs8388V1); // Audio source
RTSPSourceFromAudioStream source(kit); // IAudioSource for RTSP
AudioStreamer streamer = AudioStreamer(&source); // Stream audio via RTSP
RTSPServer rtsp = RTSPServer(&streamer, port);
RTSPAudioSource source(kit); // IAudioSource for RTSP
RTSPAudioStreamer<RTSPPlatformWiFi> streamer(source); // Stream audio via RTSP
RTSPServer<RTSPPlatformWiFi> rtsp(streamer, port);

const char* wifi = "wifi";
const char* password = "password";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioLibs/RTSP.h" // https://github.com/pschatzmann/Micro-RTSP-Audio
#include "AudioTools/AudioCodecs/CodecG7xx.h" // https://github.com/pschatzmann/arduino-libg7xx.git
#include "RTSPServer.h"
#include "AudioTools/Communication/RTSP.h"

int port = 554;
AudioInfo info(8000, 1, 16);
Expand All @@ -24,10 +23,10 @@ GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wa
// rtsp
RTSPFormatG711 format;
G711_ULAWEncoder encoder;
RTSPOutput rtsp_stream(format, encoder);
RTSPOutput<RTSPPlatformWiFi> rtsp_stream(format, encoder);
StreamCopy copier(rtsp_stream, sound); // rtsp to sine
// Server
RTSPServer rtsp(rtsp_stream.streamer(), port);
RTSPServer<RTSPPlatformWiFi> rtsp(*rtsp_stream.streamer(), port);


void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
*/

#include "AudioTools.h"
#include "AudioTools/AudioLibs/RTSP.h"
#include "AudioStreamer.h"
#include "RTSPServer.h"
#include "AudioTools/Communication/RTSP.h"

int port = 554;
int channels = 1;
int sample_rate = 16000;
int bits_per_sample = 16;
AudioInfo info(16000,1,16); // AudioInfo for RTSP
const char* wifi = "ssid";
const char* password = "password";

SineFromTable<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
RTSPSourceFromAudioStream source(sound); // Stream sound via RTSP
AudioStreamer streamer = AudioStreamer(&source);
RTSPServer rtsp = RTSPServer(&streamer, port);
RTSPAudioSource source(sound, info); // Stream sound via RTSP
RTSPAudioStreamer<RTSPPlatformWiFi> streamer(source);
RTSPServer<RTSPPlatformWiFi> rtsp(streamer, port);


void setup() {
Expand All @@ -34,9 +30,7 @@ void setup() {

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

// Start Wifi & rtsp server
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#pragma once

#include <stdint.h>

#include "AudioTools/Communication/RTSP.h"

class AudioTestSource : public IAudioSource {

public:
AudioTestSource(){};

int readBytes(void* dest, int maxBytes) override {
// Ensure we only read complete 16-bit samples
int bytesToRead = (maxBytes / 2) * 2;
int16_t* destSamples = static_cast<int16_t*>(dest);
int samplesToRead = bytesToRead / 2;

for (int i = 0; i < samplesToRead; i++) {
destSamples[i] = testData[index];
index = (index + 1) % testDataSamples; // Safer modulo operation
}
return bytesToRead;
}

void start() {
log_i("AudioTestSource start");
index = 0; // Reset to beginning for clean start
}

void stop() {
log_i("AudioTestSource stop");
}

protected:
int index = 0;
static const int testDataSamples = 1024;

const int16_t testData[testDataSamples] = {
0, 6398, 12551, 18220, 23188, 27263, 30288, 32146, 32767,
32127, 30249, 27207, 23117, 18136, 12458, 6300, -100, -6497,
-12644, -18304, -23259, -27318, -30326, -32166, -32767, -32107, -30210,
-27150, -23045, -18052, -12365, -6201, 201, 6596, 12737, 18387,
23330, 27374, 30364, 32185, 32767, 32087, 30171, 27094, 22973,
17968, 12271, 6102, -301, -6694, -12829, -18470, -23400, -27429,
-30402, -32204, -32766, -32066, -30132, -27037, -22902, -17884, -12178,
-6003, 402, 6793, 12922, 18553, 23470, 27484, 30439, 32222,
32764, 32045, 30092, 26980, 22830, 17800, 12085, 5904, -503,
-6891, -13014, -18636, -23541, -27538, -30476, -32240, -32763, -32024,
-30052, -26923, -22757, -17715, -11991, -5805, 603, 6989, 13106,
18719, 23610, 27593, 30513, 32258, 32761, 32003, 30012, 26866,
22685, 17630, 11897, 5706, -704, -7088, -13199, -18801, -23680,
-27647, -30549, -32275, -32759, -31981, -29971, -26808, -22612, -17546,
-11804, -5607, 804, 7186, 13291, 18884, 23750, 27701, 30586,
32293, 32756, 31959, 29930, 26750, 22539, 17461, 11710, 5508,
-905, -7284, -13383, -18966, -23819, -27755, -30622, -32310, -32754,
-31936, -29889, -26692, -22466, -17375, -11616, -5409, 1006, 7382,
13474, 19048, 23888, 27808, 30657, 32326, 32750, 31914, 29848,
26633, 22393, 17290, 11521, 5309, -1106, -7480, -13566, -19130,
-23956, -27861, -30693, -32343, -32747, -31891, -29806, -26574, -22319,
-17204, -11427, -5210, 1207, 7578, 13658, 19211, 24025, 27914,
30728, 32359, 32743, 31867, 29764, 26515, 22245, 17119, 11333,
5111, -1307, -7676, -13749, -19293, -24093, -27966, -30763, -32374,
-32739, -31844, -29722, -26456, -22171, -17033, -11238, -5011, 1408,
7774, 13840, 19374, 24161, 28019, 30797, 32390, 32735, 31820,
29680, 26397, 22097, 16947, 11144, 4912, -1508, -7871, -13931,
-19455, -24229, -28071, -30831, -32405, -32730, -31796, -29637, -26337,
-22023, -16860, -11049, -4812, 1609, 7969, 14022, 19536, 24297,
28123, 30865, 32419, 32725, 31771, 29594, 26277, 21948, 16774,
10954, 4713, -1709, -8067, -14113, -19616, -24364, -28174, -30899,
-32434, -32720, -31747, -29550, -26217, -21873, -16688, -10859, -4613,
1810, 8164, 14204, 19697, 24432, 28225, 30932, 32448, 32715,
31721, 29507, 26156, 21798, 16601, 10764, 4513, -1910, -8262,
-14295, -19777, -24498, -28276, -30965, -32462, -32709, -31696, -29463,
-26095, -21723, -16514, -10669, -4414, 2011, 8359, 14385, 19857,
24565, 28327, 30998, 32476, 32703, 31670, 29419, 26034, 21647,
16427, 10574, 4314, -2111, -8456, -14475, -19937, -24632, -28377,
-31031, -32489, -32696, -31644, -29374, -25973, -21572, -16340, -10479,
-4214, 2212, 8553, 14566, 20017, 24698, 28428, 31063, 32502,
32689, 31618, 29330, 25912, 21496, 16253, 10383, 4114, -2312,
-8650, -14656, -20097, -24764, -28478, -31095, -32514, -32682, -31592,
-29285, -25850, -21420, -16165, -10288, -4015, 2412, 8747, 14746,
20176, 24830, 28527, 31126, 32527, 32675, 31565, 29239, 25788,
21344, 16078, 10192, 3915, -2513, -8844, -14835, -20255, -24895,
-28577, -31157, -32539, -32667, -31538, -29194, -25726, -21267, -15990,
-10097, -3815, 2613, 8941, 14925, 20334, 24961, 28626, 31189,
32550, 32659, 31510, 29148, 25663, 21191, 15902, 10001, 3715,
-2713, -9038, -15015, -20413, -25026, -28674, -31219, -32562, -32651,
-31482, -29102, -25601, -21114, -15814, -9905, -3615, 2814, 9135,
15104, 20492, 25090, 28723, 31250, 32573, 32642, 31454, 29055,
25538, 21037, 15726, 9809, 3515, -2914, -9231, -15193, -20570,
-25155, -28771, -31280, -32584, -32633, -31426, -29009, -25475, -20959,
-15637, -9713, -3415, 3014, 9328, 15282, 20648, 25219, 28819,
31310, 32594, 32624, 31397, 28962, 25411, 20882, 15549, 9617,
3315, -3114, -9424, -15371, -20726, -25284, -28867, -31339, -32604,
-32614, -31368, -28915, -25347, -20804, -15460, -9521, -3214, 3214,
9521, 15460, 20804, 25347, 28915, 31368, 32614, 32604, 31339,
28867, 25284, 20726, 15371, 9424, 3114, -3315, -9617, -15549,
-20882, -25411, -28962, -31397, -32624, -32594, -31310, -28819, -25219,
-20648, -15282, -9328, -3014, 3415, 9713, 15637, 20959, 25475,
29009, 31426, 32633, 32584, 31280, 28771, 25155, 20570, 15193,
9231, 2914, -3515, -9809, -15726, -21037, -25538, -29055, -31454,
-32642, -32573, -31250, -28723, -25090, -20492, -15104, -9135, -2814,
3615, 9905, 15814, 21114, 25601, 29102, 31482, 32651, 32562,
31219, 28674, 25026, 20413, 15015, 9038, 2713, -3715, -10001,
-15902, -21191, -25663, -29148, -31510, -32659, -32550, -31189, -28626,
-24961, -20334, -14925, -8941, -2613, 3815, 10097, 15990, 21267,
25726, 29194, 31538, 32667, 32539, 31157, 28577, 24895, 20255,
14835, 8844, 2513, -3915, -10192, -16078, -21344, -25788, -29239,
-31565, -32675, -32527, -31126, -28527, -24830, -20176, -14746, -8747,
-2412, 4015, 10288, 16165, 21420, 25850, 29285, 31592, 32682,
32514, 31095, 28478, 24764, 20097, 14656, 8650, 2312, -4114,
-10383, -16253, -21496, -25912, -29330, -31618, -32689, -32502, -31063,
-28428, -24698, -20017, -14566, -8553, -2212, 4214, 10479, 16340,
21572, 25973, 29374, 31644, 32696, 32489, 31031, 28377, 24632,
19937, 14475, 8456, 2111, -4314, -10574, -16427, -21647, -26034,
-29419, -31670, -32703, -32476, -30998, -28327, -24565, -19857, -14385,
-8359, -2011, 4414, 10669, 16514, 21723, 26095, 29463, 31696,
32709, 32462, 30965, 28276, 24498, 19777, 14295, 8262, 1910,
-4513, -10764, -16601, -21798, -26156, -29507, -31721, -32715, -32448,
-30932, -28225, -24432, -19697, -14204, -8164, -1810, 4613, 10859,
16688, 21873, 26217, 29550, 31747, 32720, 32434, 30899, 28174,
24364, 19616, 14113, 8067, 1709, -4713, -10954, -16774, -21948,
-26277, -29594, -31771, -32725, -32419, -30865, -28123, -24297, -19536,
-14022, -7969, -1609, 4812, 11049, 16860, 22023, 26337, 29637,
31796, 32730, 32405, 30831, 28071, 24229, 19455, 13931, 7871,
1508, -4912, -11144, -16947, -22097, -26397, -29680, -31820, -32735,
-32390, -30797, -28019, -24161, -19374, -13840, -7774, -1408, 5011,
11238, 17033, 22171, 26456, 29722, 31844, 32739, 32374, 30763,
27966, 24093, 19293, 13749, 7676, 1307, -5111, -11333, -17119,
-22245, -26515, -29764, -31867, -32743, -32359, -30728, -27914, -24025,
-19211, -13658, -7578, -1207, 5210, 11427, 17204, 22319, 26574,
29806, 31891, 32747, 32343, 30693, 27861, 23956, 19130, 13566,
7480, 1106, -5309, -11521, -17290, -22393, -26633, -29848, -31914,
-32750, -32326, -30657, -27808, -23888, -19048, -13474, -7382, -1006,
5409, 11616, 17375, 22466, 26692, 29889, 31936, 32754, 32310,
30622, 27755, 23819, 18966, 13383, 7284, 905, -5508, -11710,
-17461, -22539, -26750, -29930, -31959, -32756, -32293, -30586, -27701,
-23750, -18884, -13291, -7186, -804, 5607, 11804, 17546, 22612,
26808, 29971, 31981, 32759, 32275, 30549, 27647, 23680, 18801,
13199, 7088, 704, -5706, -11897, -17630, -22685, -26866, -30012,
-32003, -32761, -32258, -30513, -27593, -23610, -18719, -13106, -6989,
-603, 5805, 11991, 17715, 22757, 26923, 30052, 32024, 32763,
32240, 30476, 27538, 23541, 18636, 13014, 6891, 503, -5904,
-12085, -17800, -22830, -26980, -30092, -32045, -32764, -32222, -30439,
-27484, -23470, -18553, -12922, -6793, -402, 6003, 12178, 17884,
22902, 27037, 30132, 32066, 32766, 32204, 30402, 27429, 23400,
18470, 12829, 6694, 301, -6102, -12271, -17968, -22973, -27094,
-30171, -32087, -32767, -32185, -30364, -27374, -23330, -18387, -12737,
-6596, -201, 6201, 12365, 18052, 23045, 27150, 30210, 32107,
32767, 32166, 30326, 27318, 23259, 18304, 12644, 6497, 100,
-6300, -12458, -18136, -23117, -27207, -30249, -32127, -32767, -32146,
-30288, -27263, -23188, -18220, -12551, -6398, 0,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// a minimal RTSP server example
#include "AudioTools.h"
#include "AudioTools/Communication/RTSP.h"
#include "AudioTestSource.h"

const char* ssid = "ssid";
const char* password = "password";

int port = 554;
AudioTestSource testSource;
DefaultRTSPAudioStreamer<RTSPPlatformWiFi> streamer(testSource);
DefaultRTSPServer<RTSPPlatformWiFi> rtsp(streamer, port);

void setup() {
Serial.begin(114200);
rtsp.begin(ssid, password);
}

void loop() { delay(1000); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

// Use the AudioPlayer to publish mp3 data as-is

#include "AudioTools.h"
#include "AudioTools/Disk/AudioSourceSDMMC.h"
#include "AudioTools/Communication/RTSP.h"
#include "AudioTools/AudioCodecs/MP3Parser.h"

int port = 554;
const char* wifi = "SSID";
const char* password = "password";

// rtsp
RTSPFormatMP3 mp3format; // RTSP mp3
MP3ParserEncoder enc; // mp3 packaging
MetaDataFilterEncoder filter(enc);
RTSPOutput<RTSPPlatformWiFi> rtsp_out(mp3format, filter);
AudioSourceSDMMC source("/", ".mp3");
CopyDecoder dec; // no decoding, just copy
AudioPlayer player(source, rtsp_out, dec);
RTSPServer<RTSPPlatformWiFi> rtsp(rtsp_out.streamer(), port);


void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);

// no delay between mp3 files
source.setTimeoutAutoNext(0);

// start the player
player.begin();

// Start Output Stream
rtsp_out.begin();

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

}

void loop() {
if (rtsp_out) {
player.copy();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

// Use the AudioPlayer to decode mp3 and publish as adpcm data

#include "AudioTools.h"
#include "AudioTools/Disk/AudioSourceSDMMC.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioCodecs/CodecADPCM.h"
#include "AudioTools/Communication/RTSP.h"

int port = 554;
const char* wifi = "SSID";
const char* password = "password";

// mp3 data
AudioSourceSDMMC source("/", ".mp3");
MP3DecoderHelix mp3; // no decoding, just copy
// rtsp
ADPCMEncoder adpcm(AV_CODEC_ID_ADPCM_IMA_WAV, 512); // ima adpcm encoder
RTSPFormatADPCM<ADPCMEncoder> adpcm_format(adpcm); // RTSP adpcm: provide info from encoder
RTSPOutput<RTSPPlatformWiFi> rtsp_out(adpcm_format, adpcm);
FormatConverterStream convert(rtsp_out);
RTSPServer<RTSPPlatformWiFi> rtsp(rtsp_out.streamer(), port);
// player
AudioPlayer player(source, convert, mp3);


void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);

// no delay between mp3 files
source.setTimeoutAutoNext(0);

// start the player
player.begin();

// Start Output Stream
rtsp_out.begin();

// convert the data format
convert.begin(mp3.audioInfo(), rtsp_out.audioInfo());

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

}

void loop() {
if (rtsp_out) {
player.copy();
}
}
7 changes: 7 additions & 0 deletions src/AudioTools/AudioCodecs/AudioCodecsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ContainerDecoder : public AudioDecoder {
bool isResultPCM() override { return true; }
};


/**
* @brief Encoding of PCM data
* @ingroup codecs
Expand All @@ -104,6 +105,12 @@ class AudioEncoder : public AudioWriter {
/// Defines the sample rate, number of channels and bits per sample
void setAudioInfo(AudioInfo from) override { info = from; }
AudioInfo audioInfo() override { return info; }
/// Default output assignment (encoders may override to store Print reference)
virtual void setOutput(Print &out_stream) override { (void)out_stream; }
/// Optioinal rtsp function: provide the frame duration in microseconds
virtual uint32_t frameDurationUs() { return 0;};
/// Optioinal rtsp function: provide samples per the frame
virtual uint16_t samplesPerFrame() { return 0;};

protected:
AudioInfo info;
Expand Down
Loading