3 #include "AudioConfig.h"
4 #include "AudioTools/CoreAudio/AudioOutput.h"
5 #include "AudioTools/AudioCodecs/CodecWAV.h"
6 #include "AudioTools/CoreAudio/AudioBasic/StrView.h"
7 #include "HttpServer.h"
8 #include "HttpExtensions.h"
19 const char* mime =
nullptr;
20 const char* ssid =
nullptr;
21 const char* password =
nullptr;
22 const char* path =
"/";
54 virtual bool begin(AudioServerExConfig cfg) {
59 virtual bool begin(Stream &in,
const char* contentType) {
61 info.mime = contentType;
65 virtual bool begin() {
68 if (info.input==
nullptr){
69 p_stream =
new ExtensionStream(info.path,tinyhttp::T_GET, info.mime );
71 p_stream =
new ExtensionStream(info.path, info.mime, *info.input);
73 p_stream->setReplyHeader(*getReplyHeader());
74 p_server =
new tinyhttp::HttpServer(wifi);
77 p_server->addExtension(*p_stream);
78 return p_server->begin(info.port, info.ssid, info.password);
82 if (p_stream!=
nullptr) {
86 if (p_server!=
nullptr) {
93 size_t write(
const uint8_t* data,
size_t len)
override {
94 if (p_stream==
nullptr)
return 0;
95 return p_stream->write((uint8_t*)data, len);
98 int availableForWrite()
override {
99 if (p_stream==
nullptr)
return 0;
100 return p_stream->availableForWrite();
105 if (p_server!=
nullptr){
113 HttpServer *p_server;
114 ExtensionStream *p_stream=
nullptr;
116 virtual tinyhttp::StrView* getReplyHeader() {
141 cfg.mime =
"audio/wav";
146 bool begin(
Stream &in,
int sample_rate,
int channels,
int bits_per_sample=16) {
150 info. bits_per_sample = bits_per_sample;
151 info.mime =
"audio/wav";
152 return AudioServerEx::begin();
156 return AudioServerEx::begin(cfg);
161 tinyhttp::Str header;
164 virtual tinyhttp::StrView* getReplyHeader() {
166 MemoryOutput mp{(uint8_t*)header.c_str(), 44};
169 wi.format = AudioFormat::PCM;
173 enc.setAudioInfo(wi);
175 enc.writeHeader(&mp);
177 assert(header.length() == 44);