arduino-audio-tools
Loading...
Searching...
No Matches
RTSPOutput.h
1#pragma once
2
3#include "AudioTools/CoreAudio/AudioPlayer.h"
4#include "AudioTools/CoreAudio/AudioStreams.h"
5#include "RTSPAudioSource.h"
6#include "RTSPAudioStreamer.h"
7#include "RTSPFormat.h"
8
9namespace audio_tools {
10
25template <typename Platform>
26class RTSPOutput : public AudioOutput {
27 public:
36 RTSPOutput(RTSPFormat &format, AudioEncoder &encoder) {
37 setFormat(format);
38 rtsp_streamer.setAudioSource(&rtsp_source);
39 p_encoder = &encoder;
40 }
41
42 void setFormat(RTSPFormat &format) {
43 TRACEI();
44 p_format = &format;
45 rtsp_source.setFormat(format);
46 }
47
53 RTSPOutput() = default;
54
61
68 bool begin(AudioInfo info) {
69 cfg = info;
70 return begin();
71 }
72
79 bool begin() {
80 TRACEI();
81 if (p_encoder == nullptr) {
82 LOGE("encoder is null");
83 return false;
84 }
85 if (p_format == nullptr) {
86 LOGE("format is null");
87 return false;
88 }
89 // setup the RTSPAudioStreamer
90 cfg.logInfo();
91
94 p_encoder->begin();
95 // setup the RTSPSourceFromAudioStream
97 rtsp_source.setFormat(*p_format);
100
103
104 // Initialize format with audio info (PCM or codec-specific)
105 p_format->begin(cfg);
106
107 return true;
108 }
109
113 void end() {
115 memory_stream.end();
116 }
117
124 return rtsp_source.isStarted() ? memory_stream.availableForWrite() : 0;
125 }
126
134 size_t write(const uint8_t *data, size_t len) override {
135 TRACED();
136 size_t result = p_encoder->write(data, len);
137 return result;
138 }
139
145 operator bool() { return rtsp_source.isActive() && memory_stream.availableForWrite() > 0; }
146
147 protected:
148 // Core Components
153 &copy_encoder;
158};
159
160} // namespace audio_tools
Encoding of PCM data.
Definition AudioCodecsBase.h:97
void setAudioInfo(AudioInfo from) override
Defines the sample rate, number of channels and bits per sample.
Definition AudioCodecsBase.h:106
virtual void setOutput(Print &out_stream) override
Default output assignment (encoders may override to store Print reference)
Definition AudioCodecsBase.h:109
Abstract Audio Ouptut class.
Definition AudioOutput.h:25
Dummy Encoder which just copies the provided data to the output.
Definition CodecCopy.h:66
MemoryStream which is written and read using the internal RAM. For each write the data is allocated o...
Definition BaseStream.h:468
virtual bool begin() override
Intializes the processing.
Definition BaseStream.h:490
void setConsumeOnRead(bool consume)
Enable or disable consuming reads (remove records as they are read)
Definition BaseStream.h:506
Unified RTSP Audio Source - Works with both Stream and AudioStream.
Definition RTSPAudioSource.h:23
void start() override
Start the audio source.
Definition RTSPAudioSource.h:141
void setAudioInfo(AudioInfo info)
Set audio configuration manually.
Definition RTSPAudioSource.h:96
bool isStarted()
Returns true after start() has been called.
Definition RTSPAudioSource.h:203
bool isActive()
Check if source is actively being read (AudioStream only)
Definition RTSPAudioSource.h:194
void stop() override
Stop the audio source.
Definition RTSPAudioSource.h:164
void setInput(AudioStream &stream)
Set input from AudioStream (with auto-detection)
Definition RTSPAudioSource.h:63
RTSPAudioStreamer - Timer-driven RTP Audio Streaming Engine.
Definition RTSPAudioStreamer.h:650
Audio Format Definition - Base class for RTSP audio formats.
Definition RTSPFormat.h:40
Linear PCM Format for RTSP Streaming.
Definition RTSPFormat.h:113
RTSPOutput - Audio Output Stream for RTSP Streaming.
Definition RTSPOutput.h:26
RTSPAudioStreamer< Platform > rtsp_streamer
Handles RTP packet transmission.
Definition RTSPOutput.h:157
CopyEncoder copy_encoder
Pass-through encoder for PCM mode.
Definition RTSPOutput.h:149
RTSPAudioStreamer< Platform > & streamer()
Get access to the underlying RTSP streamer.
Definition RTSPOutput.h:60
bool begin()
Initialize RTSPOutput with current audio configuration.
Definition RTSPOutput.h:79
RTSPFormatPCM pcm
Default PCM format handler (merged class)
Definition RTSPOutput.h:154
RTSPOutput()=default
Construct RTSPOutput with default PCM format (no encoding)
size_t write(const uint8_t *data, size_t len) override
Write PCM audio data for encoding and streaming.
Definition RTSPOutput.h:134
int availableForWrite()
Get available space for writing audio data.
Definition RTSPOutput.h:123
DynamicMemoryStream memory_stream
Memory stream for internal buffer.
Definition RTSPOutput.h:151
void end()
Stop RTSP streaming and cleanup resources.
Definition RTSPOutput.h:113
RTSPOutput(RTSPFormat &format, AudioEncoder &encoder)
Construct RTSPOutput with specific encoder and format.
Definition RTSPOutput.h:36
AudioEncoder * p_encoder
Active encoder (PCM or codec-specific)
Definition RTSPOutput.h:152
RTSPFormat * p_format
Active format handler.
Definition RTSPOutput.h:155
RTSPAudioSource rtsp_source
Provides encoded audio to streamer.
Definition RTSPOutput.h:150
bool begin(AudioInfo info)
Initialize RTSPOutput with specific audio configuration.
Definition RTSPOutput.h:68
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:55