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");
301 "STREAMIN_BUFFER_SIZE too small for the sampling rate: increase to "
314 dataBuf += header_len;
317 if (toRead > maxPayload) {
318 LOGW(
"Fragment exceeds payload capacity (%d > %d); clamping", toRead, maxPayload);
322 LOGI(
"Read %d bytes from audio source", bytesRead);
345 LOGI(
"Starting audio source (base)");
354 LOGI(
"Audio source started - ready for manual streaming");
356 LOGE(
"No streaming source");
373 LOGI(
"Stopping audio source (base)");
379 LOGI(
"Audio source stopped");
452 LOGI(
"Timer period changed from %u us to %u us",
478 LOGD(
"timerCallback");
479 if (audioStreamerObj ==
nullptr) {
480 LOGE(
"audioStreamerObj is null");
492 LOGW(
"Direct sending of RTP stream failed");
493 }
else if (bytes > 0) {
496 LOGD(
"%i samples (ts inc) sent; timestamp: %u", inc,
502 LOGW(
"RTP Stream can't keep up (took %lu us, %d is max)!",
stop -
start,
518 typename Platform::UdpSocketType
520 typename Platform::UdpSocketType
569 samples = bytesSent / 2;
571 return (uint32_t)samples;
596 LOGD(
"Sending TCP: %d", totalLen);
600 hdr[2] = (uint8_t)((totalLen >> 8) & 0xFF);
601 hdr[3] = (uint8_t)(totalLen & 0xFF);
607 LOGI(
"Sending UDP: %d bytes (to %s:%d)", totalLen,
620 if (learnedIp !=
IPAddress(0, 0, 0, 0)) {
623 LOGI(
"RTP learned client via UDP: %s:%u",
626 }
else if (warnIfNone) {
627 LOGW(
"Client IP unknown (0.0.0.0) and no inbound UDP yet");
649template <
typename Platform>
662 LOGD(
"Creating RTSP Audio streamer with timer");
673 LOGI(
"RTSPAudioStreamer: Timer set to safe task mode (ESP_TIMER_TASK)");
704 LOGI(
"Starting RTP Stream with timer");
713 LOGE(
"Could not start timer");
717 LOGI(
"Free heap size: %i KB", esp_get_free_heap_size() / 1000);
750 LOGI(
"Stopping RTP Stream with timer");
761 LOGI(
"RTP Stream stopped - ready for restart");
776template <
typename Platform>
782 m_fixed_delay_ms = 1;
783 m_throttle_interval = 50;
785 m_last_throttle_us = 0;
790 m_fixed_delay_ms = 1;
791 m_throttle_interval = 50;
793 m_last_throttle_us = 0;
797 void setFixedDelayMs(uint32_t delayMs) { m_fixed_delay_ms = delayMs; m_throttled =
false; }
804 m_last_throttle_us =
micros();
815 unsigned long nowUs =
micros();
818 m_lastSendUs = nowUs;
819 applyThrottling(nowUs);
824 void applyThrottling(
unsigned long iterationStartUs) {
826 delay(m_fixed_delay_ms);
827 if (m_throttled && m_throttle_interval > 0) {
830 m_last_throttle_us = iterationStartUs;
833 if (m_send_counter >= m_throttle_interval) {
834 uint64_t expectedUs = (uint64_t)m_throttle_interval * (uint64_t)this->
getTimerPeriodUs();
835 unsigned long nowUs =
micros();
836 uint64_t actualUs = (uint64_t)(nowUs - m_last_throttle_us);
837 if (actualUs < expectedUs) {
838 uint32_t remainingUs = (uint32_t)(expectedUs - actualUs);
839 if (remainingUs >= 1000)
delay(remainingUs / 1000);
840 uint32_t remUs = remainingUs % 1000;
844 m_last_throttle_us =
micros();
849 unsigned long m_lastSendUs;
851 uint16_t m_fixed_delay_ms;
852 uint32_t m_throttle_interval;
853 uint32_t m_send_counter;
854 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:44