3#include "AudioTools/CoreAudio/AudioIO.h"
4#include "AudioTools/CoreAudio/AudioOutput.h"
5#include "AudioTools/CoreAudio/AudioStreams.h"
26 LOGE(
"Output already defined");
31 if (p_stream ==
nullptr) {
32 LOGE(
"Input not defined");
38 if (p_ai_source !=
nullptr) {
43 components.push_back(&io);
50 auto& last_c =
last();
52 last_c.addNotifyAudioChange(io);
54 components.push_back(&io);
62 LOGE(
"Output already defined");
67 LOGE(
"Input not supported");
72 cleanup.push_back(io);
97 LOGE(
"Output already defined");
120 LOGE(
"Defined as output");
125 LOGE(
"Input already defined");
135 int availableForWrite()
override {
136 if (!is_active)
return 0;
138 if (p_print !=
nullptr)
return p_print->availableForWrite();
141 return components[0]->availableForWrite();
144 size_t write(
const uint8_t* data,
size_t len)
override {
145 if (!is_active)
return 0;
147 if (p_print !=
nullptr)
return p_print->write(data, len);
150 LOGD(
"write: %u", (
unsigned)len);
151 return components[0]->write(data, len);
154 int available()
override {
155 if (!is_active)
return 0;
157 if (in ==
nullptr)
return 0;
158 return in->available();
161 size_t readBytes(uint8_t* data,
size_t len)
override {
162 if (!is_active)
return 0;
164 if (in ==
nullptr)
return 0;
165 return in->readBytes(data, len);
187 for (
auto c : components) {
188 ok = ok && c->begin();
191 if (p_out_stream !=
nullptr) {
192 ok = ok && p_out_stream->begin();
193 }
else if (p_out_print !=
nullptr) {
194 ok = ok && p_out_print->begin();
197 if (p_ai_input !=
nullptr) {
198 ok = ok && p_ai_input->begin();
209 for (
auto c : components) {
213 for (
auto& c : cleanup) {
220 p_out_print =
nullptr;
221 p_out_stream =
nullptr;
224 p_ai_source =
nullptr;
225 p_ai_input =
nullptr;
232 this->info = newInfo;
233 if (has_input && p_ai_input !=
nullptr) {
235 }
else if (has_output) {
236 components[0]->setAudioInfo(info);
253 int size() {
return components.size(); }
268 is_notify_active = flag;
269 for (
auto c : components) {
270 c->setNotifyActive(flag);
284 operator bool()
override {
return is_ok && is_active; }
288 Vector<ModifyingStream*> cleanup{0};
289 bool has_output =
false;
290 bool has_input =
false;
292 bool is_active =
true;
294 Stream* p_stream =
nullptr;
295 AudioInfoSource* p_ai_source =
nullptr;
296 AudioStream* p_ai_input =
nullptr;
298 AudioOutput* p_out_print =
nullptr;
299 AudioStream* p_out_stream =
nullptr;
300 Print* p_print =
nullptr;
312 size_t write(
const uint8_t* data,
size_t len)
override {
313 return p_out->write(data, len);
316 bool begin()
override {
return p_out->begin(); }
318 void end()
override { p_out->end(); }