arduino-audio-tools
Loading...
Searching...
No Matches
RTSPMediaStreamer.h
Go to the documentation of this file.
1/*
2 * Author: Phil Schatzmann
3 *
4 * Based on Micro-RTSP library:
5 * https://github.com/Tomp0801/Micro-RTSP-Audio
6 * https://github.com/geeksville/Micro-RTSP
7 *
8 */
9
10#pragma once
11
12#include <stdio.h>
13
14#ifdef __linux__
16#else
18#endif
21#include "IMediaSource.h"
22#include "RTSPPlatform.h"
23
24namespace audio_tools {
25
49template <typename Platform>
51 public:
64 LOGD("Creating RTSP Audio streamer base");
67
69 m_Timestamp = 0;
70 m_SendIdx = 0;
71
72 m_RtpSocket = Platform::NULL_UDP_SOCKET;
73 m_RtcpSocket = Platform::NULL_UDP_SOCKET;
74
75 m_prevMsec = 0;
76
77 m_udpRefCount = 0;
78
79 m_useTcpInterleaved = false;
80 m_RtspTcpSocket = Platform::NULL_TCP_SOCKET;
83
85 }
86
104
114 // mRtpBuf is automatically managed by Vector
115 }
116
130 virtual void setMediaSource(IMediaSource *source) {
131 m_audioSource = source;
133 LOGI("RTSP Audio streamer created. Fragment size: %i bytes",
135 }
136
151 LOGI("initAudioSource");
152 if (getMediaSource() == nullptr) {
153 LOGE("audio_source is null");
154 return false;
155 }
160 LOGI("m_fragmentSize (bytes): %d", m_fragmentSize);
161 return true;
162 }
163
182 bool initUdpTransport(IPAddress aClientIP, uint16_t aClientPort) {
183 m_ClientIP = aClientIP;
184 m_ClientPort = aClientPort;
185
186 m_SequenceNumber = random(65536);
187
188 if (m_udpRefCount != 0) {
190 return true;
191 }
192
193 for (u_short P = 6970; P < 0xFFFE; P += 2) {
194 m_RtpSocket = Platform::createUdpSocket(P);
195 if (m_RtpSocket) { // Rtp socket was bound successfully. Lets try to bind
196 // the consecutive Rtsp socket
197 m_RtcpSocket = Platform::createUdpSocket(P + 1);
198 if (m_RtcpSocket) {
199 m_RtpServerPort = P;
200 m_RtcpServerPort = P + 1;
201 break;
202 } else {
203 Platform::closeUdpSocket(m_RtpSocket);
204 Platform::closeUdpSocket(m_RtcpSocket);
205 };
206 }
207 };
209
210 LOGI("RTP Streamer set up with client IP %s and client Port %i",
211 m_ClientIP.toString().c_str(), m_ClientPort);
212
213 // If client IP is unknown (0.0.0.0), try to learn it from an inbound UDP packet
215
216 return true;
217 }
218
230 void initTcpInterleavedTransport(typename Platform::TcpClientType *tcpSock,
231 int rtpChannel, int rtcpChannel) {
232 m_RtspTcpSocket = tcpSock;
233 m_TcpRtpChannel = rtpChannel;
234 m_TcpRtcpChannel = rtcpChannel;
235 m_useTcpInterleaved = true;
236 m_SequenceNumber = random(65536);
237 LOGI("Using RTP over RTSP TCP interleaved: ch=%d/%d", rtpChannel,
238 rtcpChannel);
239 }
240
254 if (m_udpRefCount == 0) {
255 m_RtpServerPort = 0;
257 Platform::closeUdpSocket(m_RtpSocket);
258 Platform::closeUdpSocket(m_RtcpSocket);
259
260 m_RtpSocket = Platform::NULL_UDP_SOCKET;
261 m_RtcpSocket = Platform::NULL_UDP_SOCKET;
262 }
263 }
264
286 // check buffer
287 if (mRtpBuf.size() == 0) {
288 LOGE("mRtpBuf is empty");
289 return -1;
290 }
291
292 // append data to header
293 if (m_audioSource == nullptr) {
294 LOGE("No audio source provided");
295 return -1;
296 }
297
298 int firstPacketSize = m_audioSource->packetSize();
299 if (firstPacketSize != -1) {
300 return sendPacketizedFrame(firstPacketSize);
301 }
302
303 // unsigned char * dataBuf = &mRtpBuf[m_fragmentSize];
305 LOGE(
306 "STREAMIN_BUFFER_SIZE too small for the sampling rate: increase to "
307 "%d",
309 return -1;
310 }
311
312 // Generic path (PCM, G711, etc.)
313 memset(mRtpBuf.data(), 0, STREAMING_BUFFER_SIZE);
315
316 unsigned char *dataBuf = &mRtpBuf[HEADER_SIZE];
317 int header_len = m_audioSource->getFormat().readHeader(dataBuf);
318 int maxPayload = STREAMING_BUFFER_SIZE - HEADER_SIZE - header_len;
319 dataBuf += header_len;
320
321 int toRead = m_fragmentSize;
322 if (toRead > maxPayload) {
323 LOGW("Fragment exceeds payload capacity (%d > %d); clamping", toRead, maxPayload);
324 toRead = maxPayload;
325 }
326 int bytesRead = m_audioSource->readBytes((void *)dataBuf, toRead);
327 LOGI("Read %d bytes from audio source", bytesRead);
328 int bytesNet = m_audioSource->getFormat().convert(dataBuf, bytesRead);
329
330 // Compute samples sent for timestamp increment
333 sendOut(HEADER_SIZE + bytesNet + header_len);
334 return bytesNet;
335 }
336
357 int sendPacketizedFrame(int firstPacketSize) {
358 int totalBytes = 0;
359 int maxPayload = STREAMING_BUFFER_SIZE - HEADER_SIZE;
360 int size = firstPacketSize;
361
362 while (size > 0) {
363 int toRead = size > maxPayload ? maxPayload : size;
364
365 unsigned char *dataBuf = &mRtpBuf[HEADER_SIZE];
366 int len = m_audioSource->readBytes(dataBuf, toRead);
367 if (len <= 0) break;
368 totalBytes += len;
369
370 // Peek: 0 (or -1, defensively) means nothing left, so this fragment
371 // was the last one of the current frame.
372 size = m_audioSource->packetSize();
373 bool isLast = (size <= 0);
374 buildRtpHeader(isLast);
376 sendOut(HEADER_SIZE + len);
377
378 if (isLast) break;
379 }
380
381 if (totalBytes > 0) {
383 }
384 return totalBytes;
385 }
386
399 virtual void start() {
400 LOGI("Starting audio source (base)");
401
402 if (mRtpBuf.size() == 0) {
404 }
405
406 if (m_audioSource != nullptr) {
409 LOGI("Audio source started - ready for manual streaming");
410 } else {
411 LOGE("No streaming source");
412 }
413 }
414
427 virtual void stop() {
428 LOGI("Stopping audio source (base)");
429
430 if (m_audioSource != nullptr) {
432 }
433
434 LOGI("Audio source stopped");
435 }
436
442 u_short getRtpServerPort() { return m_RtpServerPort; }
443
450
457
463 uint32_t getTimerPeriodUs() const { return m_timer_period_us; }
464
470 uint32_t getTimerPeriodMs() const { return m_timer_period_us / 1000; }
471
476 uint16_t currentSeq() const { return m_SequenceNumber; }
477
482 uint32_t currentRtpTimestamp() const { return m_Timestamp; }
483
487 uint32_t currentSsrc() const { return m_Ssrc; }
488
501 if (m_audioSource == nullptr) {
502 return false;
503 }
504
505 uint32_t newPeriod = m_audioSource->getFormat().timerPeriodUs();
506 if (newPeriod != m_timer_period_us && newPeriod > 0) {
507 LOGI("Timer period changed from %u us to %u us",
508 (unsigned)m_timer_period_us, (unsigned)newPeriod);
509 m_timer_period_us = newPeriod;
510 return true;
511 }
512 return false;
513 }
514
532 static void timerCallback(void *audioStreamerObj) {
533 LOGD("timerCallback");
534 if (audioStreamerObj == nullptr) {
535 LOGE("audioStreamerObj is null");
536 return;
537 };
539 (RTSPMediaStreamerBase<Platform> *)audioStreamerObj;
540 unsigned long start, stop;
541
542 start = micros();
543
544 int bytes = streamer->sendRtpPacketDirect();
545
546 if (bytes < 0) {
547 LOGW("Direct sending of RTP stream failed");
548 } else if (bytes > 0) {
549 uint32_t inc = streamer->computeTimestampIncrement(bytes);
550 streamer->m_Timestamp += inc;
551 LOGD("%i samples (ts inc) sent; timestamp: %u", inc,
552 (unsigned)streamer->m_Timestamp);
553 }
554
555 stop = micros();
556 if (stop - start > streamer->m_timer_period_us) {
557 LOGW("RTP Stream can't keep up (took %lu us, %d is max)!", stop - start,
558 streamer->m_timer_period_us);
559 }
560 }
561
562 protected:
563 const int STREAMING_BUFFER_SIZE = 1024 * 3;
565
567 int m_fragmentSize = 0; // changed from samples to bytes !
568 int m_timer_period_us = 20000;
569 const int HEADER_SIZE = 12; // size of the RTP header
571 false; // Flag for dynamic timer restart
572
573 typename Platform::UdpSocketType
574 *m_RtpSocket; // RTP socket for streaming RTP packets to client
575 typename Platform::UdpSocketType
576 *m_RtcpSocket; // RTCP socket for sending/receiving RTCP packages
577
578 uint16_t m_RtpServerPort; // RTP sender port on server
579 uint16_t m_RtcpServerPort; // RTCP sender port on server
580
582 uint32_t m_Timestamp;
584
586 uint16_t m_ClientPort;
587 uint32_t m_prevMsec;
588
590
591 // TCP interleaved transport
593 typename Platform::TcpClientType *m_RtspTcpSocket;
596
599 uint32_t m_Ssrc = 0x13F97E67; // default fixed SSRC
600 // MP3 packetization carry buffer to ensure whole-frame packets
603
616 inline uint32_t computeTimestampIncrement(int bytesSent) {
617 // Prefer exact samples sent (set by sender) if available
618 int samples = 0;
619 if (m_lastSamplesSent > 0) {
620 samples = m_lastSamplesSent;
621 } else if (m_audioSource) {
623 } else {
624 samples = bytesSent / 2; // crude fallback
625 }
626 return (uint32_t)samples;
627 }
628
629 inline void buildRtpHeader(bool markerBit = false) {
630 mRtpBuf[0] = 0x80; // V=2
631 mRtpBuf[1] = (uint8_t)(m_payloadType & 0x7F);
632 if (m_payloadType == 14) {
633 // Set Marker bit on each complete MP3 frame packet
634 mRtpBuf[1] |= 0x80;
635 } else if (markerBit) {
636 // Set by the caller: e.g. the last fragment of a JPEG frame
637 mRtpBuf[1] |= 0x80;
638 }
639 mRtpBuf[2] = (uint8_t)((m_SequenceNumber >> 8) & 0xFF);
640 mRtpBuf[3] = (uint8_t)(m_SequenceNumber & 0xFF);
641 mRtpBuf[4] = (uint8_t)((m_Timestamp >> 24) & 0xFF);
642 mRtpBuf[5] = (uint8_t)((m_Timestamp >> 16) & 0xFF);
643 mRtpBuf[6] = (uint8_t)((m_Timestamp >> 8) & 0xFF);
644 mRtpBuf[7] = (uint8_t)(m_Timestamp & 0xFF);
645 // SSRC
646 mRtpBuf[8] = (uint8_t)((m_Ssrc >> 24) & 0xFF);
647 mRtpBuf[9] = (uint8_t)((m_Ssrc >> 16) & 0xFF);
648 mRtpBuf[10] = (uint8_t)((m_Ssrc >> 8) & 0xFF);
649 mRtpBuf[11] = (uint8_t)(m_Ssrc & 0xFF);
650 }
651
652 inline void sendOut(uint16_t totalLen) {
653 if (m_useTcpInterleaved && m_RtspTcpSocket != Platform::NULL_TCP_SOCKET) {
654 LOGD("Sending TCP: %d", totalLen);
655 uint8_t hdr[4];
656 hdr[0] = 0x24; // '$'
657 hdr[1] = (uint8_t)m_TcpRtpChannel;
658 hdr[2] = (uint8_t)((totalLen >> 8) & 0xFF);
659 hdr[3] = (uint8_t)(totalLen & 0xFF);
660 Platform::sendSocket(m_RtspTcpSocket, hdr, sizeof(hdr));
661 Platform::sendSocket(m_RtspTcpSocket, mRtpBuf.data(), totalLen);
662 } else {
663 // If client IP is still unknown, attempt to learn it just-in-time
665 LOGI("Sending UDP: %d bytes (to %s:%d)", totalLen,
666 m_ClientIP.toString().c_str(), m_ClientPort);
667 Platform::sendUdpSocket(m_RtpSocket, mRtpBuf.data(), totalLen, m_ClientIP,
669 }
670 }
671
672 inline void tryLearnClientFromUdp(bool warnIfNone) {
673 if (m_ClientIP == IPAddress(0, 0, 0, 0) && m_RtpSocket) {
674 int avail = m_RtpSocket->parsePacket();
675 if (avail > 0) {
676 IPAddress learnedIp = m_RtpSocket->remoteIP();
677 uint16_t learnedPort = m_RtpSocket->remotePort();
678 if (learnedIp != IPAddress(0, 0, 0, 0)) {
679 m_ClientIP = learnedIp;
680 if (m_ClientPort == 0) m_ClientPort = learnedPort;
681 LOGI("RTP learned client via UDP: %s:%u",
682 m_ClientIP.toString().c_str(), (unsigned)m_ClientPort);
683 }
684 } else if (warnIfNone) {
685 LOGW("Client IP unknown (0.0.0.0) and no inbound UDP yet");
686 }
687 }
688 }
689};
690
707template <typename Platform>
708class RTSPMediaStreamer : public RTSPMediaStreamerBase<Platform> {
709 public:
720 LOGD("Creating RTSP Audio streamer with timer");
721
722 // Setup timer callback for RTP streaming
724
725 // CRITICAL FIX: Force timer to run in task context, not ISR context
726 // ISR context (ESP_TIMER_ISR) has severe limitations that cause
727 // LoadProhibited crashes Task context (ESP_TIMER_TASK) allows full object
728 // access and FreeRTOS calls
730 true); // true = use TimerCallbackInThread (ESP_TIMER_TASK)
731 LOGI("RTSPMediaStreamer: Timer set to safe task mode (ESP_TIMER_TASK)");
732 }
733
745 this->setMediaSource(&source);
746 }
747
761 void start() override {
762 LOGI("Starting RTP Stream with timer");
763
764 // Call base class start to initialize audio source and buffer
766
767 if (this->m_audioSource != nullptr) {
768 // Start timer with period in microseconds using specialized callback
771 LOGE("Could not start timer");
772 }
773 LOGI("timer: %u us", (unsigned)this->m_timer_period_us);
774#ifdef ESP32
775 LOGI("Free heap size: %i KB", esp_get_free_heap_size() / 1000);
776#endif
777 }
778 }
779
788 void updateTimer() {
789 if (this->checkTimerPeriodChange()) {
790 LOGI("Updating timer period to %u us", (unsigned)this->m_timer_period_us);
791 rtpTimer.begin(this->m_timer_period_us, audio_tools::US);
792 }
793 }
794
807 void stop() override {
808 LOGI("Stopping RTP Stream with timer");
809
810 // Stop timer first to prevent callbacks during cleanup
811 rtpTimer.end();
812
813 // Add small delay to ensure any running callbacks complete
814 delay(50);
815
816 // Call base class stop to stop audio source
818
819 LOGI("RTP Stream stopped - ready for restart");
820 }
821
822 protected:
824};
825
826
834template <typename Platform>
836 public:
837 RTSPMediaStreamerTaskless(bool throttled = true)
838 : RTSPMediaStreamerBase<Platform>(), m_throttled(throttled) {
839 m_lastSendUs = 0;
840 m_fixed_delay_ms = 1;
841 m_throttle_interval = 50;
842 m_send_counter = 0;
843 m_last_throttle_us = 0;
844 }
845 RTSPMediaStreamerTaskless(IMediaSource &source, bool throttled = true)
846 : RTSPMediaStreamerBase<Platform>(source), m_throttled(throttled) {
847 m_lastSendUs = 0;
848 m_fixed_delay_ms = 1;
849 m_throttle_interval = 50;
850 m_send_counter = 0;
851 m_last_throttle_us = 0;
852 }
853
854 void setThrottled(bool isThrottled) { m_throttled = isThrottled; }
855 void setFixedDelayMs(uint32_t delayMs) { m_fixed_delay_ms = delayMs; m_throttled = false; }
856 void setThrottleInterval(uint32_t interval) { m_throttle_interval = interval; }
857
858 void start() override {
860 m_lastSendUs = micros();
861 m_send_counter = 0;
862 m_last_throttle_us = micros();
863 }
864
865 void stop() override {
867 }
868
872 void doLoop() {
873 unsigned long nowUs = micros();
874 if (nowUs - m_lastSendUs >= this->getTimerPeriodUs()) {
876 m_lastSendUs = nowUs;
877 applyThrottling(nowUs);
878 }
879 }
880
881 private:
882 void applyThrottling(unsigned long iterationStartUs) {
883 ++m_send_counter;
884 delay(m_fixed_delay_ms);
885 if (m_throttled && m_throttle_interval > 0) {
886 if (this->checkTimerPeriodChange()) {
887 m_send_counter = 0;
888 m_last_throttle_us = iterationStartUs;
889 return;
890 }
891 if (m_send_counter >= m_throttle_interval) {
892 uint64_t expectedUs = (uint64_t)m_throttle_interval * (uint64_t)this->getTimerPeriodUs();
893 unsigned long nowUs = micros();
894 uint64_t actualUs = (uint64_t)(nowUs - m_last_throttle_us);
895 if (actualUs < expectedUs) {
896 uint32_t remainingUs = (uint32_t)(expectedUs - actualUs);
897 if (remainingUs >= 1000) delay(remainingUs / 1000);
898 uint32_t remUs = remainingUs % 1000;
899 if (remUs > 0) delayMicroseconds(remUs);
900 }
901 m_send_counter = 0;
902 m_last_throttle_us = micros();
903 }
904 }
905 }
906
907 unsigned long m_lastSendUs;
908 bool m_throttled;
909 uint16_t m_fixed_delay_ms;
910 uint32_t m_throttle_interval;
911 uint32_t m_send_counter;
912 unsigned long m_last_throttle_us;
913};
914
915
916} // namespace audio_tools
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
Common Interface definition for AudioTimer.
Definition AudioTimer.h:30
void setIsSave(bool is_save)
Definition AudioTimer.h:67
void setCallbackParameter(void *obj)
Definition AudioTimer.h:57
bool begin(repeating_timer_callback_t callback_f, uint32_t time, TimeUnit unit=MS)
Definition AudioTimer.h:44
bool end()
Definition AudioTimer.h:52
Media Source Interface - Contract for Media Data Providers.
Definition IMediaSource.h:19
virtual RTSPFormat & getFormat()=0
Get the media format configuration.
virtual void start()
Initialize media source for streaming.
Definition IMediaSource.h:65
virtual int packetSize()
Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready,...
Definition IMediaSource.h:99
virtual int readBytes(void *dest, int maxSamples)=0
Read media data into provided buffer.
virtual void stop()
Cleanup media source after streaming.
Definition IMediaSource.h:78
Arduino-compatible IPAddress class implemented in pure C++.
Definition IPAddress.h:28
std::string toString() const
Returns dotted-decimal string e.g. "192.168.1.1".
Definition IPAddress.h:112
Audio Format Definition - Base class for RTSP audio formats.
Definition RTSPFormat.h:57
virtual int timerPeriodUs()
Timer period in microseconds.
Definition RTSPFormat.h:115
virtual int readHeader(uint8_t *data)
Optional header: e.g. rfc2250.
Definition RTSPFormat.h:126
virtual int convert(void *data, int sampleCount)
Definition RTSPFormat.h:64
virtual int timestampIncrement()
Fragment size in samples (for audio) or timestamp increment (for video)
Definition RTSPFormat.h:101
virtual int fragmentSize()
Fragment (=write) size in bytes.
Definition RTSPFormat.h:98
virtual int rtpPayloadType()
default dynamic
Definition RTSPFormat.h:123
RTSPMediaStreamerBase - Core RTP Media Streaming Engine.
Definition RTSPMediaStreamer.h:50
volatile bool m_timer_restart_needed
Definition RTSPMediaStreamer.h:570
bool initUdpTransport(IPAddress aClientIP, uint16_t aClientPort)
Initialize UDP transport for RTP streaming.
Definition RTSPMediaStreamer.h:182
RTSPMediaStreamerBase(IMediaSource &source)
Constructor with audio source.
Definition RTSPMediaStreamer.h:101
uint32_t m_prevMsec
Definition RTSPMediaStreamer.h:587
audio_tools::Vector< uint8_t > mMp3Carry
Definition RTSPMediaStreamer.h:601
virtual void setMediaSource(IMediaSource *source)
Configure the audio source for streaming.
Definition RTSPMediaStreamer.h:130
IMediaSource * m_audioSource
Definition RTSPMediaStreamer.h:566
int m_SendIdx
Definition RTSPMediaStreamer.h:583
Platform::UdpSocketType * m_RtcpSocket
Definition RTSPMediaStreamer.h:576
Platform::TcpClientType * m_RtspTcpSocket
Definition RTSPMediaStreamer.h:593
RTSPMediaStreamerBase()
Default constructor for RTSPMediaStreamerBase.
Definition RTSPMediaStreamer.h:63
const int HEADER_SIZE
Definition RTSPMediaStreamer.h:569
int m_fragmentSize
Definition RTSPMediaStreamer.h:567
void tryLearnClientFromUdp(bool warnIfNone)
Definition RTSPMediaStreamer.h:672
Platform::UdpSocketType * m_RtpSocket
Definition RTSPMediaStreamer.h:574
int m_timer_period_us
Definition RTSPMediaStreamer.h:568
virtual void start()
Start audio source (base implementation)
Definition RTSPMediaStreamer.h:399
uint32_t currentRtpTimestamp() const
Get current RTP timestamp value that will be used in the next packet.
Definition RTSPMediaStreamer.h:482
uint32_t computeTimestampIncrement(int bytesSent)
Compute RTP timestamp increment based on samples sent.
Definition RTSPMediaStreamer.h:616
uint16_t m_RtpServerPort
Definition RTSPMediaStreamer.h:578
int m_TcpRtpChannel
Definition RTSPMediaStreamer.h:594
static void timerCallback(void *audioStreamerObj)
Static timer callback function for periodic RTP streaming.
Definition RTSPMediaStreamer.h:532
int m_lastSamplesSent
Definition RTSPMediaStreamer.h:598
uint32_t m_Timestamp
Definition RTSPMediaStreamer.h:582
uint32_t currentSsrc() const
Get current SSRC used in RTP header.
Definition RTSPMediaStreamer.h:487
uint32_t getTimerPeriodMs() const
Get the timer period in milliseconds.
Definition RTSPMediaStreamer.h:470
uint16_t currentSeq() const
Get current RTP sequence number that will be used in the next packet.
Definition RTSPMediaStreamer.h:476
int mMp3CarryLen
Definition RTSPMediaStreamer.h:602
void buildRtpHeader(bool markerBit=false)
Definition RTSPMediaStreamer.h:629
u_short getRtcpServerPort()
Get the RTCP server port number.
Definition RTSPMediaStreamer.h:449
const int STREAMING_BUFFER_SIZE
Definition RTSPMediaStreamer.h:563
IMediaSource * getMediaSource()
Get the configured audio source.
Definition RTSPMediaStreamer.h:456
void sendOut(uint16_t totalLen)
Definition RTSPMediaStreamer.h:652
IPAddress m_ClientIP
Definition RTSPMediaStreamer.h:585
u_short m_SequenceNumber
Definition RTSPMediaStreamer.h:581
int m_udpRefCount
Definition RTSPMediaStreamer.h:589
uint16_t m_RtcpServerPort
Definition RTSPMediaStreamer.h:579
int sendPacketizedFrame(int firstPacketSize)
Send every already-fragmented RTP payload belonging to the next queued video frame (packetized source...
Definition RTSPMediaStreamer.h:357
int m_TcpRtcpChannel
Definition RTSPMediaStreamer.h:595
bool m_useTcpInterleaved
Definition RTSPMediaStreamer.h:592
u_short getRtpServerPort()
Get the RTP server port number.
Definition RTSPMediaStreamer.h:442
int sendRtpPacketDirect()
Send a single RTP packet with audio data.
Definition RTSPMediaStreamer.h:285
int m_payloadType
Definition RTSPMediaStreamer.h:597
audio_tools::Vector< uint8_t > mRtpBuf
Definition RTSPMediaStreamer.h:564
void initTcpInterleavedTransport(typename Platform::TcpClientType *tcpSock, int rtpChannel, int rtcpChannel)
Initialize TCP interleaved transport for RTP over RTSP.
Definition RTSPMediaStreamer.h:230
uint32_t getTimerPeriodUs() const
Get the timer period in microseconds.
Definition RTSPMediaStreamer.h:463
virtual void stop()
Stop audio source (base implementation)
Definition RTSPMediaStreamer.h:427
void releaseUdpTransport(void)
Release UDP transport resources.
Definition RTSPMediaStreamer.h:252
bool checkTimerPeriodChange()
Check if timer period has changed and update if necessary.
Definition RTSPMediaStreamer.h:500
uint32_t m_Ssrc
Definition RTSPMediaStreamer.h:599
uint16_t m_ClientPort
Definition RTSPMediaStreamer.h:586
virtual ~RTSPMediaStreamerBase()
Destructor.
Definition RTSPMediaStreamer.h:113
bool initMediaSource()
Initialize audio source configuration.
Definition RTSPMediaStreamer.h:150
RTSPMediaStreamer - Timer-driven RTP Media Streaming Engine.
Definition RTSPMediaStreamer.h:708
void updateTimer()
Update timer period if audio format has changed.
Definition RTSPMediaStreamer.h:788
RTSPMediaStreamer()
Default constructor for RTSPMediaStreamer.
Definition RTSPMediaStreamer.h:719
void start() override
Start timer-driven RTP streaming.
Definition RTSPMediaStreamer.h:761
audio_tools::AudioTimer rtpTimer
Definition RTSPMediaStreamer.h:823
void stop() override
Stop timer-driven RTP streaming.
Definition RTSPMediaStreamer.h:807
RTSPMediaStreamer(IMediaSource &source)
Constructor with audio source.
Definition RTSPMediaStreamer.h:744
RTSPMediaStreamerTaskless - Manual RTP Audio Streaming Engine (no Task)
Definition RTSPMediaStreamer.h:835
void setFixedDelayMs(uint32_t delayMs)
Definition RTSPMediaStreamer.h:855
void setThrottled(bool isThrottled)
Definition RTSPMediaStreamer.h:854
void doLoop()
Call this in your Arduino loop() to send RTP packets at the correct rate.
Definition RTSPMediaStreamer.h:872
RTSPMediaStreamerTaskless(IMediaSource &source, bool throttled=true)
Definition RTSPMediaStreamer.h:845
void start() override
Start audio source (base implementation)
Definition RTSPMediaStreamer.h:858
RTSPMediaStreamerTaskless(bool throttled=true)
Definition RTSPMediaStreamer.h:837
void setThrottleInterval(uint32_t interval)
Definition RTSPMediaStreamer.h:856
void stop() override
Stop audio source (base implementation)
Definition RTSPMediaStreamer.h:865
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
bool resize(size_t newSize, T value)
Definition Vector.h:266
T * data()
Definition Vector.h:316
int size()
Definition Vector.h:178
@ US
Definition AudioTypes.h:49
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
void delay(uint32_t ms)
Definition Arduino.h:259
uint64_t micros()
Definition Arduino.h:265
void delayMicroseconds(uint32_t us)
Definition Arduino.h:261