mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
See CHANGELOG - release
This commit is contained in:
@@ -22482,9 +22482,13 @@ mg_init_library(unsigned features)
|
||||
file_mutex_init =
|
||||
pthread_mutex_init(&global_log_file_lock, &pthread_mutex_attr);
|
||||
if (file_mutex_init == 0) {
|
||||
#ifdef WINSOCK_START
|
||||
/* Start WinSock */
|
||||
WSADATA data;
|
||||
failed = wsa = WSAStartup(MAKEWORD(2, 2), &data);
|
||||
#else
|
||||
failed = wsa = 0;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
mutexattr_init = pthread_mutexattr_init(&pthread_mutex_attr);
|
||||
@@ -22498,7 +22502,9 @@ mg_init_library(unsigned features)
|
||||
if (failed) {
|
||||
#if defined(_WIN32)
|
||||
if (wsa == 0) {
|
||||
#ifdef WINSOCK_START
|
||||
(void)WSACleanup();
|
||||
#endif
|
||||
}
|
||||
if (file_mutex_init == 0) {
|
||||
(void)pthread_mutex_destroy(&global_log_file_lock);
|
||||
@@ -22598,7 +22604,9 @@ mg_exit_library(void)
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifdef WINSOCK_START
|
||||
(void)WSACleanup();
|
||||
#endif
|
||||
(void)pthread_mutex_destroy(&global_log_file_lock);
|
||||
#else
|
||||
(void)pthread_mutexattr_destroy(&pthread_mutex_attr);
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
using namespace bell;
|
||||
|
||||
std::mutex BellHTTPServer::initMutex;
|
||||
|
||||
class WebSocketHandler : public CivetWebSocketHandler {
|
||||
public:
|
||||
BellHTTPServer::WSDataHandler dataHandler;
|
||||
@@ -187,6 +189,7 @@ bool BellHTTPServer::handlePost(CivetServer* server,
|
||||
}
|
||||
|
||||
BellHTTPServer::BellHTTPServer(int serverPort) {
|
||||
std::lock_guard lock(initMutex);
|
||||
mg_init_library(0);
|
||||
BELL_LOG(info, "HttpServer", "Server listening on port %d", serverPort);
|
||||
this->serverPort = serverPort;
|
||||
@@ -197,6 +200,11 @@ BellHTTPServer::BellHTTPServer(int serverPort) {
|
||||
server = std::make_unique<CivetServer>(civetWebOptions);
|
||||
}
|
||||
|
||||
BellHTTPServer::~BellHTTPServer() {
|
||||
std::lock_guard lock(initMutex);
|
||||
mg_exit_library();
|
||||
}
|
||||
|
||||
std::unique_ptr<BellHTTPServer::HTTPResponse> BellHTTPServer::makeJsonResponse(
|
||||
const std::string& json, int status) {
|
||||
auto response = std::make_unique<BellHTTPServer::HTTPResponse>();
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace bell {
|
||||
class BellHTTPServer : public CivetHandler {
|
||||
public:
|
||||
BellHTTPServer(int serverPort);
|
||||
~BellHTTPServer();
|
||||
|
||||
enum class WSState { CONNECTED, READY, CLOSED };
|
||||
|
||||
@@ -100,6 +101,8 @@ class BellHTTPServer : public CivetHandler {
|
||||
std::mutex responseMutex;
|
||||
HTTPHandler notFoundHandler;
|
||||
|
||||
static std::mutex initMutex;
|
||||
|
||||
bool handleGet(CivetServer* server, struct mg_connection* conn);
|
||||
bool handlePost(CivetServer* server, struct mg_connection* conn);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
#if __has_include("avahi-client/client.h")
|
||||
#include <avahi-client/client.h>
|
||||
@@ -41,8 +42,9 @@ class implMDNSService : public MDNSService {
|
||||
#endif
|
||||
static struct mdnsd* mdnsServer;
|
||||
static in_addr_t host;
|
||||
static std::atomic<size_t> instances;
|
||||
|
||||
implMDNSService(struct mdns_service* service) : service(service){};
|
||||
implMDNSService(struct mdns_service* service) : service(service){ instances++; };
|
||||
#ifndef BELL_DISABLE_AVAHI
|
||||
implMDNSService(AvahiEntryGroup* avahiGroup) : avahiGroup(avahiGroup){};
|
||||
#endif
|
||||
@@ -51,6 +53,7 @@ class implMDNSService : public MDNSService {
|
||||
|
||||
struct mdnsd* implMDNSService::mdnsServer = NULL;
|
||||
in_addr_t implMDNSService::host = INADDR_ANY;
|
||||
std::atomic<size_t> implMDNSService::instances = 0;
|
||||
static std::mutex registerMutex;
|
||||
#ifndef BELL_DISABLE_AVAHI
|
||||
AvahiClient* implMDNSService::avahiClient = NULL;
|
||||
@@ -66,11 +69,21 @@ void implMDNSService::unregisterService() {
|
||||
#ifndef BELL_DISABLE_AVAHI
|
||||
if (avahiGroup) {
|
||||
avahi_entry_group_free(avahiGroup);
|
||||
if (!--instances && implMDNSService::avahiClient) {
|
||||
avahi_client_free(implMDNSService::avahiClient);
|
||||
avahi_simple_poll_free(implMDNSService::avahiPoll);
|
||||
implMDNSService::avahiClient = nullptr;
|
||||
implMDNSService::avahiPoll = nullptr;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
mdns_service_remove(implMDNSService::mdnsServer, service);
|
||||
}
|
||||
if (!--instances && implMDNSService::mdnsServer) {
|
||||
mdnsd_stop(implMDNSService::mdnsServer);
|
||||
implMDNSService::mdnsServer = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<MDNSService> MDNSService::registerService(
|
||||
@@ -180,19 +193,14 @@ std::unique_ptr<MDNSService> MDNSService::registerService(
|
||||
std::string type(serviceType + "." + serviceProto + ".local");
|
||||
|
||||
BELL_LOG(info, "MDNS", "using built-in mDNS for %s", serviceName.c_str());
|
||||
struct mdns_service* mdnsService =
|
||||
auto service =
|
||||
mdnsd_register_svc(implMDNSService::mdnsServer, serviceName.c_str(),
|
||||
type.c_str(), servicePort, NULL, txt.data());
|
||||
if (mdnsService) {
|
||||
auto service =
|
||||
mdnsd_register_svc(implMDNSService::mdnsServer, serviceName.c_str(),
|
||||
type.c_str(), servicePort, NULL, txt.data());
|
||||
|
||||
return std::make_unique<implMDNSService>(service);
|
||||
}
|
||||
if (service) return std::make_unique<implMDNSService>(service);
|
||||
}
|
||||
|
||||
BELL_LOG(error, "MDNS", "cannot start any mDNS listener for %s",
|
||||
serviceName.c_str());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,12 @@ using namespace bell;
|
||||
class implMDNSService : public MDNSService {
|
||||
private:
|
||||
struct mdns_service* service;
|
||||
void unregisterService(void) {
|
||||
mdns_service_remove(implMDNSService::mdnsServer, service);
|
||||
};
|
||||
void unregisterService(void);
|
||||
|
||||
public:
|
||||
static struct mdnsd* mdnsServer;
|
||||
implMDNSService(struct mdns_service* service) : service(service){};
|
||||
static std::atomic<size_t> instances;
|
||||
implMDNSService(struct mdns_service* service) : service(service) { instances++; };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -33,8 +32,18 @@ class implMDNSService : public MDNSService {
|
||||
**/
|
||||
|
||||
struct mdnsd* implMDNSService::mdnsServer = NULL;
|
||||
std::atomic<size_t> implMDNSService::instances = 0;
|
||||
|
||||
static std::mutex registerMutex;
|
||||
|
||||
void implMDNSService::unregisterService() {
|
||||
mdns_service_remove(implMDNSService::mdnsServer, service);
|
||||
if (!--instances && implMDNSService::mdnsServer) {
|
||||
mdnsd_stop(implMDNSService::mdnsServer);
|
||||
implMDNSService::mdnsServer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<MDNSService> MDNSService::registerService(
|
||||
const std::string& serviceName, const std::string& serviceType,
|
||||
const std::string& serviceProto, const std::string& serviceHost,
|
||||
@@ -94,5 +103,5 @@ std::unique_ptr<MDNSService> MDNSService::registerService(
|
||||
mdnsd_register_svc(implMDNSService::mdnsServer, serviceName.c_str(),
|
||||
type.c_str(), servicePort, NULL, txt.data());
|
||||
|
||||
return std::make_unique<implMDNSService>(service);
|
||||
return service ? std::make_unique<implMDNSService>(service) : nullptr;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,11 @@ class Task {
|
||||
(LPTHREAD_START_ROUTINE)taskEntryFunc, this, 0, NULL);
|
||||
return thread != NULL;
|
||||
#else
|
||||
return (pthread_create(&thread, NULL, taskEntryFunc, this) == 0);
|
||||
if (!pthread_create(&thread, NULL, taskEntryFunc, this)) {
|
||||
pthread_detach(thread);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -108,13 +112,7 @@ class Task {
|
||||
#endif
|
||||
|
||||
static void* taskEntryFunc(void* This) {
|
||||
Task* self = (Task*)This;
|
||||
self->runTask();
|
||||
#if _WIN32
|
||||
WaitForSingleObject(self->thread, INFINITE);
|
||||
#else
|
||||
pthread_join(self->thread, NULL);
|
||||
#endif
|
||||
((Task*)This)->runTask();
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ class CDNAudioFile;
|
||||
// Used in got track info event
|
||||
struct TrackInfo {
|
||||
std::string name, album, artist, imageUrl, trackId;
|
||||
uint32_t duration;
|
||||
uint32_t duration, number, discNumber;
|
||||
|
||||
void loadPbTrack(Track* pbTrack, const std::vector<uint8_t>& gid);
|
||||
void loadPbEpisode(Episode* pbEpisode, const std::vector<uint8_t>& gid);
|
||||
|
||||
@@ -32,6 +32,8 @@ message Artist {
|
||||
message Track {
|
||||
optional bytes gid = 1;
|
||||
optional string name = 2;
|
||||
optional sint32 number = 5;
|
||||
optional sint32 disc_number = 6;
|
||||
optional sint32 duration = 0x7;
|
||||
optional Album album = 0x3;
|
||||
repeated Artist artist = 0x4;
|
||||
@@ -44,6 +46,7 @@ message Episode {
|
||||
optional bytes gid = 1;
|
||||
optional string name = 2;
|
||||
optional sint32 duration = 7;
|
||||
optional sint32 number = 65;
|
||||
repeated AudioFile file = 12;
|
||||
repeated Restriction restriction = 0x4B;
|
||||
optional ImageGroup covers = 0x44;
|
||||
|
||||
@@ -97,6 +97,8 @@ void TrackInfo::loadPbTrack(Track* pbTrack, const std::vector<uint8_t>& gid) {
|
||||
}
|
||||
}
|
||||
|
||||
number = pbTrack->has_number ? pbTrack->number : 0;
|
||||
discNumber = pbTrack->has_disc_number ? pbTrack->disc_number : 0;
|
||||
duration = pbTrack->duration;
|
||||
}
|
||||
|
||||
@@ -113,6 +115,8 @@ void TrackInfo::loadPbEpisode(Episode* pbEpisode,
|
||||
imageUrl = "https://i.scdn.co/image/" + bytesToHexString(imageId);
|
||||
}
|
||||
|
||||
number = pbEpisode->has_number ? pbEpisode->number : 0;
|
||||
discNumber = 0;
|
||||
duration = pbEpisode->duration;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user