arduino-audio-tools
Loading...
Searching...
No Matches
RTSPOutput.h
Go to the documentation of this file.
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
17namespace audio_tools {
18
33template <typename Platform>
34class RTSPOutput : public AudioOutput {
35 public:
44 RTSPOutput(RTSPFormat &format, AudioEncoder &encoder) {
45 setFormat(format);
46 rtsp_streamer.setAudioSource(&rtsp_source);
47 p_encoder = &encoder;
48 }
49
50 void setFormat(RTSPFormat &format) {
51 TRACEI();
52 p_format = &format;
53 rtsp_source.setFormat(format);
54 }
55
61 RTSPOutput() = default;
62
69
76 bool begin(AudioInfo info) {
77 cfg = info;
78 return begin();
79 }
80
87 bool begin() {
88 TRACEI();
89 if (p_encoder == nullptr) {
90 LOGE("encoder is null");
91 return false;
92 }
93 if (p_format == nullptr) {
94 LOGE("format is null");
95 return false;
96 }
97 // setup the RTSPAudioStreamer
98 cfg.logInfo();
99
102 p_encoder->begin();
103 // setup the RTSPSourceFromAudioStream
105 rtsp_source.setFormat(*p_format);
108
111
112 // Initialize format with audio info (PCM or codec-specific)
113 p_format->begin(cfg);
114
115 return true;
116 }
117
121 void end() {
123 memory_stream.end();
124 }
125
132 return rtsp_source.isStarted() ? memory_stream.availableForWrite() : 0;
133 }
134
142 size_t write(const uint8_t *data, size_t len) override {
143 TRACED();
144 size_t result = p_encoder->write(data, len);
145 return result;
146 }
147
153 operator bool() { return rtsp_source.isActive() && memory_stream.availableForWrite() > 0; }
154
155 protected:
156 // Core Components
161 &copy_encoder;
166};
167
168} // 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:22
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:30
void start() override
Start the audio source.
Definition RTSPAudioSource.h:148
void setAudioInfo(AudioInfo info)
Set audio configuration manually.
Definition RTSPAudioSource.h:103
bool isStarted()
Returns true after start() has been called.
Definition RTSPAudioSource.h:210
bool isActive()
Check if source is actively being read (AudioStream only)
Definition RTSPAudioSource.h:201
void stop() override
Stop the audio source.
Definition RTSPAudioSource.h:171
void setInput(AudioStream &stream)
Set input from AudioStream (with auto-detection)
Definition RTSPAudioSource.h:70
RTSPAudioStreamer - Timer-driven RTP Audio Streaming Engine.
Definition RTSPAudioStreamer.h:624
Audio Format Definition - Base class for RTSP audio formats.
Definition RTSPFormat.h:41
Linear PCM Format for RTSP Streaming.
Definition RTSPFormat.h:114
RTSPOutput - Audio Output Stream for RTSP Streaming.
Definition RTSPOutput.h:34
RTSPAudioStreamer< Platform > rtsp_streamer
Handles RTP packet transmission.
Definition RTSPOutput.h:165
CopyEncoder copy_encoder
Pass-through encoder for PCM mode.
Definition RTSPOutput.h:157
RTSPAudioStreamer< Platform > & streamer()
Get access to the underlying RTSP streamer.
Definition RTSPOutput.h:68
bool begin()
Initialize RTSPOutput with current audio configuration.
Definition RTSPOutput.h:87
RTSPFormatPCM pcm
Default PCM format handler (merged class)
Definition RTSPOutput.h:162
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:142
int availableForWrite()
Get available space for writing audio data.
Definition RTSPOutput.h:131
DynamicMemoryStream memory_stream
Memory stream for internal buffer.
Definition RTSPOutput.h:159
void end()
Stop RTSP streaming and cleanup resources.
Definition RTSPOutput.h:121
RTSPOutput(RTSPFormat &format, AudioEncoder &encoder)
Construct RTSPOutput with specific encoder and format.
Definition RTSPOutput.h:44
AudioEncoder * p_encoder
Active encoder (PCM or codec-specific)
Definition RTSPOutput.h:160
RTSPFormat * p_format
Active format handler.
Definition RTSPOutput.h:163
RTSPAudioSource rtsp_source
Provides encoded audio to streamer.
Definition RTSPOutput.h:158
bool begin(AudioInfo info)
Initialize RTSPOutput with specific audio configuration.
Definition RTSPOutput.h:76
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:53