3 #include "AudioConfig.h"
4 #include "AudioTools/AudioOutput.h"
5 #include "AudioCodecs/CodecWAV.h"
6 #include "HttpServer.h"
7 #include "HttpExtensions.h"
18 const char* mime =
nullptr;
19 const char* ssid =
nullptr;
20 const char* password =
nullptr;
21 const char* path =
"/";
53 virtual bool begin(AudioServerExConfig cfg) {
58 virtual bool begin(Stream &in,
const char* contentType) {
60 info.mime = contentType;
64 virtual bool begin() {
67 if (info.input==
nullptr){
68 p_stream =
new ExtensionStream(info.path,tinyhttp::T_GET, info.mime );
70 p_stream =
new ExtensionStream(info.path, info.mime, *info.input);
72 p_stream->setReplyHeader(*getReplyHeader());
73 p_server =
new tinyhttp::HttpServer(wifi);
76 p_server->addExtension(*p_stream);
77 return p_server->begin(info.port, info.ssid, info.password);
81 if (p_stream!=
nullptr) {
85 if (p_server!=
nullptr) {
92 size_t write(
const uint8_t* data,
size_t len)
override {
93 if (p_stream==
nullptr)
return 0;
94 return p_stream->write((uint8_t*)data, len);
97 int availableForWrite()
override {
98 if (p_stream==
nullptr)
return 0;
99 return p_stream->availableForWrite();
104 if (p_server!=
nullptr){
112 HttpServer *p_server;
113 ExtensionStream *p_stream=
nullptr;
115 virtual tinyhttp::Str* getReplyHeader() {
140 cfg.mime =
"audio/wav";
145 bool begin(
Stream &in,
int sample_rate,
int channels,
int bits_per_sample=16) {
149 info. bits_per_sample = bits_per_sample;
150 info.mime =
"audio/wav";
151 return AudioServerEx::begin();
155 return AudioServerEx::begin(cfg);
160 tinyhttp::StrExt header;
163 virtual tinyhttp::Str* getReplyHeader() {
165 MemoryOutput mp{(uint8_t*)header.c_str(), 44};
168 wi.format = AudioFormat::PCM;
172 enc.setAudioInfo(wi);
174 enc.writeHeader(&mp);
176 assert(header.length() == 44);