From 719b289659567b323af6cef777fbdb9601f95657 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Mon, 2 Oct 2023 19:06:59 -0700 Subject: [PATCH] update cspot --- CHANGELOG | 3 + .../bell/main/audio-codec/AACDecoder.cpp | 2 +- .../main/audio-codec/include/DecoderGlobals.h | 2 +- .../main/audio-containers/MP3Container.cpp | 4 +- .../spotify/cspot/bell/main/io/BellTar.cpp | 2 +- .../cspot/bell/main/io/MGStreamAdapter.cpp | 93 ++++++++++--------- .../spotify/cspot/bell/main/io/X509Bundle.cpp | 14 +-- .../bell/main/io/include/MGStreamAdapter.h | 29 +++--- .../cspot/bell/main/utilities/Crypto.cpp | 10 +- .../spotify/cspot/include/CSpotContext.h | 36 +++---- .../spotify/cspot/include/MercurySession.h | 4 +- .../spotify/cspot/include/SpircHandler.h | 2 +- .../spotify/cspot/include/TrackPlayer.h | 3 +- components/spotify/cspot/include/TrackQueue.h | 3 +- .../spotify/cspot/include/TrackReference.h | 2 +- components/spotify/cspot/src/ApResolve.cpp | 2 +- components/spotify/cspot/src/CDNAudioFile.cpp | 10 +- components/spotify/cspot/src/LoginBlob.cpp | 11 ++- .../spotify/cspot/src/MercurySession.cpp | 2 +- .../spotify/cspot/src/PlainConnection.cpp | 24 ++--- components/spotify/cspot/src/Session.cpp | 9 +- components/spotify/cspot/src/SpircHandler.cpp | 4 +- components/spotify/cspot/src/TimeProvider.cpp | 6 +- components/spotify/cspot/src/TrackPlayer.cpp | 11 ++- .../spotify/cspot/src/TrackReference.cpp | 4 +- components/spotify/cspot/src/Utils.cpp | 4 +- 26 files changed, 153 insertions(+), 143 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8154fc5e9..e4a3a8c52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2023-10-02 + - update cspot + 2023-09-29 - sleep mechanism - spotify can store credentials so that zeroconf is optional and players are always registered diff --git a/components/spotify/cspot/bell/main/audio-codec/AACDecoder.cpp b/components/spotify/cspot/bell/main/audio-codec/AACDecoder.cpp index 53197c12c..aa4f61fac 100644 --- a/components/spotify/cspot/bell/main/audio-codec/AACDecoder.cpp +++ b/components/spotify/cspot/bell/main/audio-codec/AACDecoder.cpp @@ -1,8 +1,8 @@ #include "AACDecoder.h" +#include #include // for free, malloc #include -#include #include "e_tmp4audioobjecttype.h" #include "pvmp4audiodecoder_api.h" diff --git a/components/spotify/cspot/bell/main/audio-codec/include/DecoderGlobals.h b/components/spotify/cspot/bell/main/audio-codec/include/DecoderGlobals.h index e2a202575..c6682512f 100644 --- a/components/spotify/cspot/bell/main/audio-codec/include/DecoderGlobals.h +++ b/components/spotify/cspot/bell/main/audio-codec/include/DecoderGlobals.h @@ -24,7 +24,7 @@ class DecodersInstance { void ensureAAC() { // if (aacDecoder == NULL) { - // aacDecoder = AACInitDecoder(); + // aacDecoder = AACInitDecoder(); // } } diff --git a/components/spotify/cspot/bell/main/audio-containers/MP3Container.cpp b/components/spotify/cspot/bell/main/audio-containers/MP3Container.cpp index 6b602ec94..da8cf9282 100644 --- a/components/spotify/cspot/bell/main/audio-containers/MP3Container.cpp +++ b/components/spotify/cspot/bell/main/audio-containers/MP3Container.cpp @@ -7,7 +7,8 @@ using namespace bell; -MP3Container::MP3Container(std::istream& istr, const std::byte* headingBytes) : bell::AudioContainer(istr) { +MP3Container::MP3Container(std::istream& istr, const std::byte* headingBytes) + : bell::AudioContainer(istr) { if (headingBytes != nullptr) { memcpy(buffer.data(), headingBytes, 7); bytesInBuffer = 7; @@ -38,7 +39,6 @@ std::byte* MP3Container::readSample(uint32_t& len) { bytesInBuffer -= toConsume; } - if (!this->fillBuffer()) { len = 0; return nullptr; diff --git a/components/spotify/cspot/bell/main/io/BellTar.cpp b/components/spotify/cspot/bell/main/io/BellTar.cpp index 61b410390..aa52bf9dc 100644 --- a/components/spotify/cspot/bell/main/io/BellTar.cpp +++ b/components/spotify/cspot/bell/main/io/BellTar.cpp @@ -292,7 +292,7 @@ void reader::extract_all_files(std::string dest_directory) { if (fileType == '0' && !fileName.starts_with("._")) { #else if (fileType == '0' && fileName.find("._") != 0) { -#endif +#endif std::string path = dest_directory + "/" + fileName; size_t pos = 0; diff --git a/components/spotify/cspot/bell/main/io/MGStreamAdapter.cpp b/components/spotify/cspot/bell/main/io/MGStreamAdapter.cpp index 71660eadc..b086abbe6 100644 --- a/components/spotify/cspot/bell/main/io/MGStreamAdapter.cpp +++ b/components/spotify/cspot/bell/main/io/MGStreamAdapter.cpp @@ -2,76 +2,77 @@ #include "MGStreamAdapter.h" mg_buf::mg_buf(struct mg_connection* _conn) : conn(_conn) { - setp(buffer, buffer + BUF_SIZE - 1); // -1 to leave space for overflow '\0' + setp(buffer, buffer + BUF_SIZE - 1); // -1 to leave space for overflow '\0' } mg_buf::int_type mg_buf::overflow(int_type c) { - if (c != EOF) { - *pptr() = c; - pbump(1); - } + if (c != EOF) { + *pptr() = c; + pbump(1); + } - if (flush_buffer() == EOF) { - return EOF; - } + if (flush_buffer() == EOF) { + return EOF; + } - return c; + return c; } int mg_buf::flush_buffer() { - int len = int(pptr() - pbase()); - if (mg_write(conn, buffer, len) != len) { - return EOF; - } - pbump(-len); // reset put pointer accordingly - return len; + int len = int(pptr() - pbase()); + if (mg_write(conn, buffer, len) != len) { + return EOF; + } + pbump(-len); // reset put pointer accordingly + return len; } int mg_buf::sync() { - if (flush_buffer() == EOF) { - return -1; // return -1 on error - } - return 0; + if (flush_buffer() == EOF) { + return -1; // return -1 on error + } + return 0; } -MGStreamAdapter::MGStreamAdapter(struct mg_connection* _conn) : std::ostream(&buf), buf(_conn) { - rdbuf(&buf); // set the custom streambuf +MGStreamAdapter::MGStreamAdapter(struct mg_connection* _conn) + : std::ostream(&buf), buf(_conn) { + rdbuf(&buf); // set the custom streambuf } - mg_read_buf::mg_read_buf(struct mg_connection* _conn) : conn(_conn) { - setg(buffer + BUF_SIZE, // beginning of putback area - buffer + BUF_SIZE, // read position - buffer + BUF_SIZE); // end position + setg(buffer + BUF_SIZE, // beginning of putback area + buffer + BUF_SIZE, // read position + buffer + BUF_SIZE); // end position } mg_read_buf::int_type mg_read_buf::underflow() { - if (gptr() < egptr()) { // buffer not exhausted - return traits_type::to_int_type(*gptr()); - } + if (gptr() < egptr()) { // buffer not exhausted + return traits_type::to_int_type(*gptr()); + } - char* base = buffer; - char* start = base; + char* base = buffer; + char* start = base; - if (eback() == base) { // true when this isn't the first fill - // Make arrangements for putback characters - std::memmove(base, egptr() - 2, 2); - start += 2; - } + if (eback() == base) { // true when this isn't the first fill + // Make arrangements for putback characters + std::memmove(base, egptr() - 2, 2); + start += 2; + } - // Read new characters - int n = mg_read(conn, start, buffer + BUF_SIZE - start); - if (n == 0) { - return traits_type::eof(); - } + // Read new characters + int n = mg_read(conn, start, buffer + BUF_SIZE - start); + if (n == 0) { + return traits_type::eof(); + } - // Set buffer pointers - setg(base, start, start + n); + // Set buffer pointers + setg(base, start, start + n); - // Return next character - return traits_type::to_int_type(*gptr()); + // Return next character + return traits_type::to_int_type(*gptr()); } -MGInputStreamAdapter::MGInputStreamAdapter(struct mg_connection* _conn) : std::istream(&buf), buf(_conn) { - rdbuf(&buf); // set the custom streambuf +MGInputStreamAdapter::MGInputStreamAdapter(struct mg_connection* _conn) + : std::istream(&buf), buf(_conn) { + rdbuf(&buf); // set the custom streambuf } diff --git a/components/spotify/cspot/bell/main/io/X509Bundle.cpp b/components/spotify/cspot/bell/main/io/X509Bundle.cpp index 351a63172..7d07ad4de 100644 --- a/components/spotify/cspot/bell/main/io/X509Bundle.cpp +++ b/components/spotify/cspot/bell/main/io/X509Bundle.cpp @@ -1,12 +1,12 @@ #include "X509Bundle.h" -#include // for mbedtls_md, mbedtls_md_get_size -#include // for mbedtls_pk_can_do, mbedtls_pk_pa... -#include // for mbedtls_ssl_conf_ca_chain, mbedt... -#include // for mbedtls_x509_buf, MBEDTLS_ERR_X5... -#include // for free, calloc -#include // for memcmp, memcpy -#include // for runtime_error +#include // for mbedtls_md, mbedtls_md_get_size +#include // for mbedtls_pk_can_do, mbedtls_pk_pa... +#include // for mbedtls_ssl_conf_ca_chain, mbedt... +#include // for mbedtls_x509_buf, MBEDTLS_ERR_X5... +#include // for free, calloc +#include // for memcmp, memcpy +#include // for runtime_error #include "BellLogger.h" // for AbstractLogger, BELL_LOG diff --git a/components/spotify/cspot/bell/main/io/include/MGStreamAdapter.h b/components/spotify/cspot/bell/main/io/include/MGStreamAdapter.h index 4c6086d44..5f150522b 100644 --- a/components/spotify/cspot/bell/main/io/include/MGStreamAdapter.h +++ b/components/spotify/cspot/bell/main/io/include/MGStreamAdapter.h @@ -1,8 +1,8 @@ #pragma once +#include #include #include -#include #include "civetweb.h" const size_t BUF_SIZE = 1024; @@ -36,25 +36,24 @@ class MGStreamAdapter : public std::ostream { // Custom streambuf class mg_read_buf : public std::streambuf { -private: - struct mg_connection* conn; - char buffer[BUF_SIZE]; - -public: - mg_read_buf(struct mg_connection* _conn); - -protected: - virtual int_type underflow(); + private: + struct mg_connection* conn; + char buffer[BUF_SIZE]; + + public: + mg_read_buf(struct mg_connection* _conn); + + protected: + virtual int_type underflow(); }; /** * @brief Adapts istream to mg_read */ class MGInputStreamAdapter : public std::istream { -private: - mg_read_buf buf; + private: + mg_read_buf buf; -public: - MGInputStreamAdapter(struct mg_connection* _conn); + public: + MGInputStreamAdapter(struct mg_connection* _conn); }; - diff --git a/components/spotify/cspot/bell/main/utilities/Crypto.cpp b/components/spotify/cspot/bell/main/utilities/Crypto.cpp index 70d71e29f..1072426ae 100644 --- a/components/spotify/cspot/bell/main/utilities/Crypto.cpp +++ b/components/spotify/cspot/bell/main/utilities/Crypto.cpp @@ -141,14 +141,14 @@ std::vector CryptoMbedTLS::pbkdf2HmacSha1( mbedtls_pkcs5_pbkdf2_hmac(&sha1Context, password.data(), password.size(), salt.data(), salt.size(), iterations, digestSize, digest.data()); - + // Free sha context mbedtls_md_free(&sha1Context); #else - mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, password.data(), password.size(), - salt.data(), salt.size(), iterations, digestSize, - digest.data()); -#endif + mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, password.data(), + password.size(), salt.data(), salt.size(), + iterations, digestSize, digest.data()); +#endif return digest; } diff --git a/components/spotify/cspot/include/CSpotContext.h b/components/spotify/cspot/include/CSpotContext.h index 2f274ce68..d4fdde844 100644 --- a/components/spotify/cspot/include/CSpotContext.h +++ b/components/spotify/cspot/include/CSpotContext.h @@ -3,12 +3,12 @@ #include #include +#include "Crypto.h" #include "LoginBlob.h" #include "MercurySession.h" #include "TimeProvider.h" -#include "Crypto.h" +#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE... #include "protobuf/metadata.pb.h" -#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE... #ifdef BELL_ONLY_CJSON #include "cJSON.h" #else @@ -37,24 +37,28 @@ struct Context { std::shared_ptr session; std::string getCredentialsJson() { #ifdef BELL_ONLY_CJSON - cJSON* json_obj = cJSON_CreateObject(); - cJSON_AddStringToObject(json_obj, "authData", Crypto::base64Encode(config.authData).c_str()); - cJSON_AddNumberToObject(json_obj, "authType", AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS); - cJSON_AddStringToObject(json_obj, "username", config.username.c_str()); + cJSON* json_obj = cJSON_CreateObject(); + cJSON_AddStringToObject(json_obj, "authData", + Crypto::base64Encode(config.authData).c_str()); + cJSON_AddNumberToObject( + json_obj, "authType", + AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS); + cJSON_AddStringToObject(json_obj, "username", config.username.c_str()); - char* str = cJSON_PrintUnformatted(json_obj); - cJSON_Delete(json_obj); - std::string json_objStr(str); - free(str); + char* str = cJSON_PrintUnformatted(json_obj); + cJSON_Delete(json_obj); + std::string json_objStr(str); + free(str); - return json_objStr; + return json_objStr; #else - nlohmann::json obj; - obj["authData"] = Crypto::base64Encode(config.authData); - obj["authType"] = AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS; - obj["username"] = config.username; + nlohmann::json obj; + obj["authData"] = Crypto::base64Encode(config.authData); + obj["authType"] = + AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS; + obj["username"] = config.username; - return obj.dump(); + return obj.dump(); #endif } diff --git a/components/spotify/cspot/include/MercurySession.h b/components/spotify/cspot/include/MercurySession.h index 07496cc27..91f05f589 100644 --- a/components/spotify/cspot/include/MercurySession.h +++ b/components/spotify/cspot/include/MercurySession.h @@ -88,8 +88,8 @@ class MercurySession : public bell::Task, public cspot::Session { void unregisterAudioKey(uint32_t sequenceId); uint32_t requestAudioKey(const std::vector& trackId, - const std::vector& fileId, - AudioKeyCallback audioCallback); + const std::vector& fileId, + AudioKeyCallback audioCallback); std::string getCountryCode(); diff --git a/components/spotify/cspot/include/SpircHandler.h b/components/spotify/cspot/include/SpircHandler.h index ecb21082b..7a4545364 100644 --- a/components/spotify/cspot/include/SpircHandler.h +++ b/components/spotify/cspot/include/SpircHandler.h @@ -7,7 +7,7 @@ #include // for variant #include // for vector -#include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track... +#include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track... #include "TrackQueue.h" #include "protobuf/spirc.pb.h" // for MessageType diff --git a/components/spotify/cspot/include/TrackPlayer.h b/components/spotify/cspot/include/TrackPlayer.h index 74735ab45..9ec100a17 100644 --- a/components/spotify/cspot/include/TrackPlayer.h +++ b/components/spotify/cspot/include/TrackPlayer.h @@ -33,7 +33,8 @@ class TrackPlayer : bell::Task { public: // Callback types typedef std::function)> TrackLoadedCallback; - typedef std::function DataCallback; + typedef std::function + DataCallback; typedef std::function EOFCallback; typedef std::function isAiringCallback; diff --git a/components/spotify/cspot/include/TrackQueue.h b/components/spotify/cspot/include/TrackQueue.h index 7ff097e36..174d51af1 100644 --- a/components/spotify/cspot/include/TrackQueue.h +++ b/components/spotify/cspot/include/TrackQueue.h @@ -3,8 +3,8 @@ #include // for size_t #include #include -#include #include +#include #include "BellTask.h" #include "PlaybackState.h" @@ -94,7 +94,6 @@ class TrackQueue : public bell::Task { std::shared_ptr playableSemaphore; std::atomic notifyPending = false; - void runTask() override; void stopTask(); diff --git a/components/spotify/cspot/include/TrackReference.h b/components/spotify/cspot/include/TrackReference.h index a1ede7bec..8b9863498 100644 --- a/components/spotify/cspot/include/TrackReference.h +++ b/components/spotify/cspot/include/TrackReference.h @@ -1,9 +1,9 @@ #pragma once #include +#include #include #include -#include #include "NanoPBHelper.h" #include "pb_decode.h" #include "protobuf/spirc.pb.h" diff --git a/components/spotify/cspot/src/ApResolve.cpp b/components/spotify/cspot/src/ApResolve.cpp index ba455e9db..6d7fd6b22 100644 --- a/components/spotify/cspot/src/ApResolve.cpp +++ b/components/spotify/cspot/src/ApResolve.cpp @@ -6,7 +6,7 @@ #include // for string_view #include // for vector -#include "HTTPClient.h" // for HTTPClient, HTTPClient::Response +#include "HTTPClient.h" // for HTTPClient, HTTPClient::Response #ifdef BELL_ONLY_CJSON #include "cJSON.h" #else diff --git a/components/spotify/cspot/src/CDNAudioFile.cpp b/components/spotify/cspot/src/CDNAudioFile.cpp index 2fbd0742d..f58ea07d9 100644 --- a/components/spotify/cspot/src/CDNAudioFile.cpp +++ b/components/spotify/cspot/src/CDNAudioFile.cpp @@ -10,11 +10,11 @@ #include "AccessKeyFetcher.h" // for AccessKeyFetcher #include "BellLogger.h" // for AbstractLogger #include "Crypto.h" -#include "Logger.h" // for CSPOT_LOG -#include "Packet.h" // for cspot -#include "SocketStream.h" // for SocketStream -#include "Utils.h" // for bigNumAdd, bytesToHexString, string... -#include "WrappedSemaphore.h" // for WrappedSemaphore +#include "Logger.h" // for CSPOT_LOG +#include "Packet.h" // for cspot +#include "SocketStream.h" // for SocketStream +#include "Utils.h" // for bigNumAdd, bytesToHexString, string... +#include "WrappedSemaphore.h" // for WrappedSemaphore #ifdef BELL_ONLY_CJSON #include "cJSON.h" #else diff --git a/components/spotify/cspot/src/LoginBlob.cpp b/components/spotify/cspot/src/LoginBlob.cpp index 8790071df..62c9df140 100644 --- a/components/spotify/cspot/src/LoginBlob.cpp +++ b/components/spotify/cspot/src/LoginBlob.cpp @@ -3,10 +3,10 @@ #include // for sprintf #include // for initializer_list -#include "BellLogger.h" // for AbstractLogger -#include "ConstantParameters.h" // for brandName, cspot, protoc... -#include "Logger.h" // for CSPOT_LOG -#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE... +#include "BellLogger.h" // for AbstractLogger +#include "ConstantParameters.h" // for brandName, cspot, protoc... +#include "Logger.h" // for CSPOT_LOG +#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE... #ifdef BELL_ONLY_CJSON #include "cJSON.h" #else @@ -142,7 +142,8 @@ void LoginBlob::loadJson(const std::string& json) { cJSON* root = cJSON_Parse(json.c_str()); this->authType = cJSON_GetObjectItem(root, "authType")->valueint; this->username = cJSON_GetObjectItem(root, "username")->valuestring; - std::string authDataObject = cJSON_GetObjectItem(root, "authData")->valuestring; + std::string authDataObject = + cJSON_GetObjectItem(root, "authData")->valuestring; this->authData = crypto->base64Decode(authDataObject); cJSON_Delete(root); #else diff --git a/components/spotify/cspot/src/MercurySession.cpp b/components/spotify/cspot/src/MercurySession.cpp index 605ac924f..7aafbb760 100644 --- a/components/spotify/cspot/src/MercurySession.cpp +++ b/components/spotify/cspot/src/MercurySession.cpp @@ -7,7 +7,7 @@ #include // for remove_extent_t, __underlying_type_impl<>:... #include // for pair #ifndef _WIN32 -#include // for htons, ntohs, htonl, ntohl +#include // for htons, ntohs, htonl, ntohl #endif #include "BellLogger.h" // for AbstractLogger #include "BellTask.h" // for Task diff --git a/components/spotify/cspot/src/PlainConnection.cpp b/components/spotify/cspot/src/PlainConnection.cpp index 7337f691a..1bff6cf99 100644 --- a/components/spotify/cspot/src/PlainConnection.cpp +++ b/components/spotify/cspot/src/PlainConnection.cpp @@ -1,22 +1,22 @@ #include "PlainConnection.h" #ifndef _WIN32 -#include // for addrinfo, freeaddrinfo, getaddrinfo -#include // for IPPROTO_IP, IPPROTO_TCP -#include // for EAGAIN, EINTR, ETIMEDOUT, errno -#include // for setsockopt, connect, recv, send, shutdown -#include // for timeval -#include // for memset -#include // for runtime_error -#include // for TCP_NODELAY +#include // for addrinfo, freeaddrinfo, getaddrinfo #include +#include // for IPPROTO_IP, IPPROTO_TCP +#include // for TCP_NODELAY +#include // for EAGAIN, EINTR, ETIMEDOUT, errno +#include // for setsockopt, connect, recv, send, shutdown +#include // for timeval +#include // for memset +#include // for runtime_error #else #include #endif -#include "BellLogger.h" // for AbstractLogger -#include "Logger.h" // for CSPOT_LOG -#include "Packet.h" // for cspot -#include "Utils.h" // for extract, pack +#include "BellLogger.h" // for AbstractLogger +#include "Logger.h" // for CSPOT_LOG +#include "Packet.h" // for cspot +#include "Utils.h" // for extract, pack using namespace cspot; diff --git a/components/spotify/cspot/src/Session.cpp b/components/spotify/cspot/src/Session.cpp index 7d76b86a9..74bd06331 100644 --- a/components/spotify/cspot/src/Session.cpp +++ b/components/spotify/cspot/src/Session.cpp @@ -17,8 +17,8 @@ #include "PlainConnection.h" // for PlainConnection, timeoutCallback #include "ShannonConnection.h" // for ShannonConnection -#include "pb_decode.h" #include "NanoPBHelper.h" // for pbPutString, pbEncode, pbDecode +#include "pb_decode.h" #include "protobuf/authentication.pb.h" using random_bytes_engine = @@ -86,10 +86,9 @@ std::vector Session::authenticate(std::shared_ptr blob) { APWelcome welcome; CSPOT_LOG(debug, "Authorization successful"); pbDecode(welcome, APWelcome_fields, packet.data); - return std::vector( - welcome.reusable_auth_credentials.bytes, - welcome.reusable_auth_credentials.bytes + welcome.reusable_auth_credentials.size - ); + return std::vector(welcome.reusable_auth_credentials.bytes, + welcome.reusable_auth_credentials.bytes + + welcome.reusable_auth_credentials.size); break; } case AUTH_DECLINED_COMMAND: { diff --git a/components/spotify/cspot/src/SpircHandler.cpp b/components/spotify/cspot/src/SpircHandler.cpp index 0346b25f3..52032aedb 100644 --- a/components/spotify/cspot/src/SpircHandler.cpp +++ b/components/spotify/cspot/src/SpircHandler.cpp @@ -38,7 +38,7 @@ SpircHandler::SpircHandler(std::shared_ptr ctx) { this->notify(); // Send playback start event, unpause - sendEvent(EventType::PLAYBACK_START, (int) track->requestedPosition); + sendEvent(EventType::PLAYBACK_START, (int)track->requestedPosition); sendEvent(EventType::PLAY_PAUSE, false); }; @@ -111,7 +111,7 @@ void SpircHandler::updatePositionMs(uint32_t position) { void SpircHandler::disconnect() { this->trackQueue->stopTask(); - this->trackPlayer->resetState(); + this->trackPlayer->stop(); this->ctx->session->disconnect(); } diff --git a/components/spotify/cspot/src/TimeProvider.cpp b/components/spotify/cspot/src/TimeProvider.cpp index 8617ef13b..69c2f3041 100644 --- a/components/spotify/cspot/src/TimeProvider.cpp +++ b/components/spotify/cspot/src/TimeProvider.cpp @@ -1,8 +1,8 @@ #include "TimeProvider.h" -#include "BellLogger.h" // for AbstractLogger -#include "Logger.h" // for CSPOT_LOG -#include "Utils.h" // for extract, getCurrentTimestamp +#include "BellLogger.h" // for AbstractLogger +#include "Logger.h" // for CSPOT_LOG +#include "Utils.h" // for extract, getCurrentTimestamp #ifndef _WIN32 #include #endif diff --git a/components/spotify/cspot/src/TrackPlayer.cpp b/components/spotify/cspot/src/TrackPlayer.cpp index eb897b206..d310caa5d 100644 --- a/components/spotify/cspot/src/TrackPlayer.cpp +++ b/components/spotify/cspot/src/TrackPlayer.cpp @@ -13,8 +13,10 @@ #include "WrappedSemaphore.h" // for WrappedSemaphore #ifdef BELL_VORBIS_FLOAT -#define VORBIS_SEEK(file, position) (ov_time_seek(file, (double)position / 1000)) -#define VORBIS_READ(file, buffer, bufferSize, section) (ov_read(file, buffer, bufferSize, 0, 2, 1, section)) +#define VORBIS_SEEK(file, position) \ + (ov_time_seek(file, (double)position / 1000)) +#define VORBIS_READ(file, buffer, bufferSize, section) \ + (ov_read(file, buffer, bufferSize, 0, 2, 1, section)) #else #define VORBIS_SEEK(file, position) (ov_time_seek(file, position)) #define VORBIS_READ(file, buffer, bufferSize, section) \ @@ -68,6 +70,7 @@ TrackPlayer::TrackPlayer(std::shared_ptr ctx, TrackPlayer::~TrackPlayer() { isRunning = false; + resetState(); std::scoped_lock lock(runningMutex); } @@ -233,8 +236,8 @@ void TrackPlayer::runTask() { if (!currentSongPlaying || pendingReset) break; - written = - dataCallback(pcmBuffer.data() + (ret - toWrite), toWrite, track->identifier); + written = dataCallback(pcmBuffer.data() + (ret - toWrite), + toWrite, track->identifier); } if (written == 0) { BELL_SLEEP_MS(50); diff --git a/components/spotify/cspot/src/TrackReference.cpp b/components/spotify/cspot/src/TrackReference.cpp index 4c399dbaa..2a5f6bfe1 100644 --- a/components/spotify/cspot/src/TrackReference.cpp +++ b/components/spotify/cspot/src/TrackReference.cpp @@ -27,8 +27,8 @@ void TrackReference::decodeURI() { #if __cplusplus >= 202002L if (uri.starts_with("episode")) { #else - if (uri.find("episode") == 0) { -#endif + if (uri.find("episode") == 0) { +#endif type = Type::EPISODE; } } diff --git a/components/spotify/cspot/src/Utils.cpp b/components/spotify/cspot/src/Utils.cpp index 6983e3ae8..fa5a3d95e 100644 --- a/components/spotify/cspot/src/Utils.cpp +++ b/components/spotify/cspot/src/Utils.cpp @@ -1,12 +1,12 @@ #include "Utils.h" -#include // for strtol +#include // for strtol +#include #include // for operator<<, setfill, setw #include // for basic_ostream, hex #include // for stringstream #include // for string #include // for enable_if<>::type -#include #ifndef _WIN32 #include #endif