-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrtspVC.cpp
56 lines (46 loc) · 1.66 KB
/
rtspVC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Provide RTSP Server to output audio stream that can be received on device
// with RTSP client - eg VLC
//
// s60sc 2025
#include "appGlobals.h"
bool RTSPAudio = false;
int16_t* RTSPAudioBuffer = NULL;
size_t RTSPAudioBytes = 0;
#if INCLUDE_RTSP
#include <ESP32-RTSPServer.h> // https://github.com/rjsachse/ESP32-RTSPServer.git
RTSPServer rtspServer;
static const int rtspPort = 554;
static const uint16_t rtpAudioPort = 5432;
static uint8_t rtpTTL = 1;
IPAddress rtpIp = IPAddress(239, 255, 0, 1);
static void sendRTSPAudio(void* p) {
// send audio chunks via RTSP
// chunk > 1024 causes panic abort in rtsp lib due to buffer overrun
RTSPAudioBytes = 0;
while (true) {
if (RTSPAudioBytes && rtspServer.readyToSendAudio()) {
rtspServer.sendRTSPAudio(RTSPAudioBuffer, RTSPAudioBytes);
RTSPAudioBytes = 0;
}
delay(20);
}
vTaskDelete(NULL);
}
void prepRTSP() {
// Initialize the RTSP server for audio
rtspServer.transport = RTSPServer::AUDIO_ONLY;
rtspServer.sampleRate = SAMPLE_RATE;
rtspServer.rtspPort = rtspPort;
rtspServer.rtpAudioPort = rtpAudioPort;
rtspServer.rtpIp = rtpIp;
rtspServer.rtpTTL = rtpTTL;
if (rtspServer.init()) {
LOG_INF("RTSP server started successfully with transport: AUDIO only @ %uHz", SAMPLE_RATE);
if (RTSPAudioBuffer == NULL) RTSPAudioBuffer = (int16_t*)malloc(sampleBytes);
LOG_INF("Connect to: rtsp://%s:%d", WiFi.localIP().toString().c_str(), rtspServer.rtspPort);
xTaskCreate(sendRTSPAudio, "sendRTSPAudio", 1024 * 4, NULL, 5, NULL);
RTSPAudio = true;
} else LOG_ERR("Failed to start RTSP server");
}
#endif