update CSpot + clear audio buffer when changing track

This commit is contained in:
philippe44
2022-08-23 17:06:59 -07:00
parent 36f18fc069
commit 0222dbd6de
22 changed files with 383 additions and 93 deletions

View File

@@ -67,6 +67,6 @@ long long bell::BinaryReader::readLong() {
long low = readInt();
return static_cast<long long>(
(high << 32) | low );
((long long) high << 32) | low );
}

View File

@@ -127,6 +127,7 @@ void CryptoOpenSSL::aesECBdecrypt(const std::vector<uint8_t>& key, std::vector<u
int len = 0;
EVP_DecryptInit_ex(ctx, EVP_aes_192_ecb(), NULL, key.data(), NULL);
EVP_CIPHER_CTX_set_padding(ctx, 0); // disable padding
EVP_DecryptUpdate(ctx, data.data(), &len, data.data(), data.size());
EVP_DecryptFinal_ex(ctx, data.data() + len, &len);

View File

@@ -1,4 +1,5 @@
#include "HTTPServer.h"
#include <cstring>
bell::HTTPServer::HTTPServer(int serverPort) { this->serverPort = serverPort; }
@@ -65,8 +66,7 @@ void bell::HTTPServer::registerHandler(RequestType requestType,
}
void bell::HTTPServer::listen() {
BELL_LOG(info, "http", "Starting server at port %d",
this->serverPort);
BELL_LOG(info, "http", "Starting server at port %d", this->serverPort);
// setup address
struct addrinfo hints, *server;
@@ -82,9 +82,20 @@ void bell::HTTPServer::listen() {
socklen_t incomingSockSize;
int i;
int yes = true;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
bind(sockfd, server->ai_addr, server->ai_addrlen);
::listen(sockfd, 10);
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
throw std::runtime_error("setsockopt failed: " +
std::string(strerror(errno)));
}
if (bind(sockfd, server->ai_addr, server->ai_addrlen) < 0) {
throw std::runtime_error("bind failed on port " +
std::to_string(this->serverPort) + ": " +
std::string(strerror(errno)));
}
if (::listen(sockfd, 5) < 0) {
throw std::runtime_error("listen failed on port " +
std::to_string(this->serverPort) + ": " +
std::string(strerror(errno)));
}
FD_ZERO(&activeFdSet);
FD_SET(sockfd, &activeFdSet);
@@ -172,7 +183,8 @@ void bell::HTTPServer::readFromClient(int clientFd) {
std::stoi(line.substr(16, line.size() - 1));
}
// detect hostname for captive portal
if (line.find("Host: connectivitycheck.gstatic.com") != std::string::npos) {
if (line.find("Host: connectivitycheck.gstatic.com") !=
std::string::npos) {
conn.isCaptivePortal = true;
BELL_LOG(info, "http", "Captive portal request detected");
}
@@ -182,11 +194,11 @@ void bell::HTTPServer::readFromClient(int clientFd) {
goto READBODY;
} else {
if (!conn.isCaptivePortal) {
findAndHandleRoute(conn.httpMethod, conn.currentLine, clientFd);
findAndHandleRoute(conn.httpMethod,
conn.currentLine, clientFd);
} else {
this->redirectCaptivePortal(clientFd);
}
}
}
}
@@ -299,7 +311,7 @@ void bell::HTTPServer::redirectCaptivePortal(int connectionFd) {
this->closeConnection(connectionFd);
}
void bell::HTTPServer::redirectTo(const std::string & url, int connectionFd) {
void bell::HTTPServer::redirectTo(const std::string &url, int connectionFd) {
std::lock_guard lock(this->responseMutex);
std::stringstream stream;
stream << "HTTP/1.1 301 Moved Permanently\r\n";

View File

@@ -85,7 +85,11 @@ bool SPDIFAudioSink::setParams(uint32_t sampleRate, uint8_t channelCount, uint8_
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = (uint32_t)sample_rate,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.sample_rate = (uint32_t) sample_rate,
#else
.sample_rate = (int) sample_rate,
#endif
.bits_per_sample = (i2s_bits_per_sample_t)(bitDepth * 2),
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,