49template <
typename Platform>
64 LOGD(
"Creating RTSP Audio streamer base");
133 LOGI(
"RTSP Audio streamer created. Fragment size: %i bytes",
151 LOGI(
"initAudioSource");
153 LOGE(
"audio_source is null");
193 for (u_short P = 6970; P < 0xFFFE; P += 2) {
210 LOGI(
"RTP Streamer set up with client IP %s and client Port %i",
231 int rtpChannel,
int rtcpChannel) {
237 LOGI(
"Using RTP over RTSP TCP interleaved: ch=%d/%d", rtpChannel,
288 LOGE(
"mRtpBuf is empty");
294 LOGE(
"No audio source provided");
299 if (firstPacketSize != -1) {
306 "STREAMIN_BUFFER_SIZE too small for the sampling rate: increase to "
319 dataBuf += header_len;
322 if (toRead > maxPayload) {
323 LOGW(
"Fragment exceeds payload capacity (%d > %d); clamping", toRead, maxPayload);
327 LOGI(
"Read %d bytes from audio source", bytesRead);
360 int size = firstPacketSize;
363 int toRead = size > maxPayload ? maxPayload : size;
373 bool isLast = (size <= 0);
381 if (totalBytes > 0) {
400 LOGI(
"Starting audio source (base)");
409 LOGI(
"Audio source started - ready for manual streaming");
411 LOGE(
"No streaming source");
428 LOGI(
"Stopping audio source (base)");
434 LOGI(
"Audio source stopped");
507 LOGI(
"Timer period changed from %u us to %u us",
533 LOGD(
"timerCallback");
534 if (audioStreamerObj ==
nullptr) {
535 LOGE(
"audioStreamerObj is null");
547 LOGW(
"Direct sending of RTP stream failed");
548 }
else if (bytes > 0) {
551 LOGD(
"%i samples (ts inc) sent; timestamp: %u", inc,
557 LOGW(
"RTP Stream can't keep up (took %lu us, %d is max)!",
stop -
start,
573 typename Platform::UdpSocketType
575 typename Platform::UdpSocketType
624 samples = bytesSent / 2;
626 return (uint32_t)samples;
635 }
else if (markerBit) {
654 LOGD(
"Sending TCP: %d", totalLen);
658 hdr[2] = (uint8_t)((totalLen >> 8) & 0xFF);
659 hdr[3] = (uint8_t)(totalLen & 0xFF);
665 LOGI(
"Sending UDP: %d bytes (to %s:%d)", totalLen,
678 if (learnedIp !=
IPAddress(0, 0, 0, 0)) {
681 LOGI(
"RTP learned client via UDP: %s:%u",
684 }
else if (warnIfNone) {
685 LOGW(
"Client IP unknown (0.0.0.0) and no inbound UDP yet");
707template <
typename Platform>
720 LOGD(
"Creating RTSP Audio streamer with timer");
731 LOGI(
"RTSPMediaStreamer: Timer set to safe task mode (ESP_TIMER_TASK)");
762 LOGI(
"Starting RTP Stream with timer");
771 LOGE(
"Could not start timer");
775 LOGI(
"Free heap size: %i KB", esp_get_free_heap_size() / 1000);
808 LOGI(
"Stopping RTP Stream with timer");
819 LOGI(
"RTP Stream stopped - ready for restart");
834template <
typename Platform>
840 m_fixed_delay_ms = 1;
841 m_throttle_interval = 50;
843 m_last_throttle_us = 0;
848 m_fixed_delay_ms = 1;
849 m_throttle_interval = 50;
851 m_last_throttle_us = 0;
855 void setFixedDelayMs(uint32_t delayMs) { m_fixed_delay_ms = delayMs; m_throttled =
false; }
862 m_last_throttle_us =
micros();
873 unsigned long nowUs =
micros();
876 m_lastSendUs = nowUs;
877 applyThrottling(nowUs);
882 void applyThrottling(
unsigned long iterationStartUs) {
884 delay(m_fixed_delay_ms);
885 if (m_throttled && m_throttle_interval > 0) {
888 m_last_throttle_us = iterationStartUs;
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;
902 m_last_throttle_us =
micros();
907 unsigned long m_lastSendUs;
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;
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
@ US
Definition AudioTypes.h:49