3 #include "AudioTools/CoreAudio/AudioOutput.h"
4 #include "AudioTools/CoreAudio/AudioStreams.h"
24 LOGE(
"Output already defined");
29 if (p_stream ==
nullptr) {
30 LOGE(
"Input not defined");
36 if (p_ai_source !=
nullptr) {
41 components.push_back(&io);
48 auto& last_c =
last();
50 last_c.addNotifyAudioChange(io);
52 components.push_back(&io);
60 LOGE(
"Output already defined");
65 LOGE(
"Input not supported");
70 cleanup.push_back(io);
95 LOGE(
"Output already defined");
118 LOGE(
"Defined as output");
123 LOGE(
"Input already defined");
133 int availableForWrite()
override {
134 if (!is_active)
return 0;
136 if (p_print !=
nullptr)
return p_print->availableForWrite();
139 return components[0]->availableForWrite();
142 size_t write(
const uint8_t* data,
size_t len)
override {
143 if (!is_active)
return 0;
145 if (p_print !=
nullptr)
return p_print->write(data, len);
148 LOGD(
"write: %u", (
unsigned)len);
149 return components[0]->write(data, len);
152 int available()
override {
153 if (!is_active)
return 0;
155 if (in ==
nullptr)
return 0;
156 return in->available();
159 size_t readBytes(uint8_t* data,
size_t len)
override {
160 if (!is_active)
return 0;
162 if (in ==
nullptr)
return 0;
163 return in->readBytes(data, len);
185 for (
auto c : components) {
186 ok = ok && c->begin();
189 if (p_out_stream !=
nullptr) {
190 ok = ok && p_out_stream->begin();
191 }
else if (p_out_print !=
nullptr) {
192 ok = ok && p_out_print->begin();
195 if (p_ai_input !=
nullptr) {
196 ok = ok && p_ai_input->begin();
207 for (
auto c : components) {
211 for (
auto& c : cleanup) {
218 p_out_print =
nullptr;
219 p_out_stream =
nullptr;
222 p_ai_source =
nullptr;
223 p_ai_input =
nullptr;
230 this->info = newInfo;
231 if (has_input && p_ai_input !=
nullptr) {
233 }
else if (has_output) {
234 components[0]->setAudioInfo(info);
251 int size() {
return components.size(); }
266 is_notify_active = flag;
267 for (
auto c : components) {
268 c->setNotifyActive(flag);
288 operator bool() {
return is_ok && is_active; }
292 Vector<ModifyingStream*> cleanup{0};
293 bool has_output =
false;
294 bool has_input =
false;
296 bool is_active =
true;
298 Stream* p_stream =
nullptr;
299 AudioInfoSource* p_ai_source =
nullptr;
300 AudioStream* p_ai_input =
nullptr;
302 AudioOutput* p_out_print =
nullptr;
303 AudioStream* p_out_stream =
nullptr;
304 Print* p_print =
nullptr;
316 size_t write(
const uint8_t* data,
size_t len)
override {
317 return p_out->write(data, len);
320 bool begin()
override {
return p_out->begin(); }
322 void end()
override { p_out->end(); }