Selaa lähdekoodia

Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3

Sebastien L 3 vuotta sitten
vanhempi
commit
e5516db60f

+ 2 - 1
components/_override/CMakeLists.txt

@@ -3,4 +3,5 @@ idf_component_register( SRCS ${srcs}
 						INCLUDE_DIRS ${IDF_PATH}/components/driver
 )
 
-message("overriding ${srcs} !! THIS MUST BE REQUIRED BY MAIN !!")
+# CMake is just a pile of crap
+message("overriding ${srcs} !! THIS MUST BE REQUIRED BY ONE COMPONENT BUT NO MAIN !!")

+ 14 - 5
components/_override/spi_master.c

@@ -125,6 +125,7 @@ We have two bits to control the interrupt:
 #include "esp_log.h"
 #include "freertos/task.h"
 #include "freertos/queue.h"
+#include "freertos/semphr.h"
 #include "soc/soc_memory_layout.h"
 #include "driver/gpio.h"
 #include "hal/spi_hal.h"
@@ -158,6 +159,10 @@ typedef struct {
 
 //debug information
     bool polling;   //in process of a polling, avoid of queue new transactions into ISR
+	
+//	PATCH
+	SemaphoreHandle_t mutex;
+	int count;	
 } spi_host_t;
 
 struct spi_device_t {
@@ -391,6 +396,12 @@ esp_err_t spi_bus_add_device(spi_host_device_t host_id, const spi_device_interfa
     if (dev_config->spics_io_num >= 0) {
         spicommon_cs_initialize(host_id, dev_config->spics_io_num, freecs, use_gpio);
     }
+	
+	// create a mutex if we have more than one client
+	if (host->count++) {
+		ESP_LOGI(SPI_TAG, "More than one device on SPI %d => creating mutex", host_id);
+		host->mutex = xSemaphoreCreateMutex();
+	}
 
     //save a pointer to device in spi_host_t
     host->device[freecs] = dev;
@@ -982,17 +993,15 @@ esp_err_t SPI_MASTER_ISR_ATTR spi_device_polling_end(spi_device_handle_t handle,
 esp_err_t SPI_MASTER_ISR_ATTR spi_device_polling_transmit(spi_device_handle_t handle, spi_transaction_t* trans_desc)
 {
     esp_err_t ret;
-	static SemaphoreHandle_t mutex;
-	if (!mutex) mutex = xSemaphoreCreateMutex();
-	xSemaphoreTake(mutex, portMAX_DELAY);
+if (handle->host->mutex) xSemaphoreTake(handle->host->mutex, portMAX_DELAY);
 
     ret = spi_device_polling_start(handle, trans_desc, portMAX_DELAY);
 	if (ret != ESP_OK) {
-		xSemaphoreGive(mutex);
+		if (handle->host->mutex) xSemaphoreGive(handle->host->mutex);
 		return ret;	
 	}	
 
 	ret = spi_device_polling_end(handle, portMAX_DELAY);
-	xSemaphoreGive(mutex);
+	if (handle->host->mutex) xSemaphoreGive(handle->host->mutex);
 	return ret;
 }

+ 1 - 1
components/services/CMakeLists.txt

@@ -1,5 +1,5 @@
 idf_component_register(SRC_DIRS .
-						INCLUDE_DIRS .  ${IDF_PATH}/components/driver
+						INCLUDE_DIRS .
 						REQUIRES json tools platform_config display wifi-manager
 						PRIV_REQUIRES soc esp32
 )

+ 1 - 2
components/spotify/cspot/bell/nanopb/extra/FindNanopb.cmake

@@ -262,8 +262,7 @@ function(NANOPB_GENERATE_CPP SRCS HDRS)
     execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version OUTPUT_VARIABLE PROTOC_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE)
     string(REGEX MATCH "[(0-9)].*.[(0-9)].*.[(0-9)].*$" PROTOC_VERSION "${PROTOC_VERSION_STRING}")
 
-    #if(PROTOC_VERSION VERSION_LESS "3.6.0")
-	if(0)
+    if(PROTOC_VERSION AND PROTOC_VERSION VERSION_LESS "3.6.0")
         #try to use the older way
         string(REGEX MATCH ":" HAS_COLON_IN_PATH ${NANOPB_PLUGIN_OPTIONS} ${NANOPB_OUT})
         if(HAS_COLON_IN_PATH)

+ 1 - 0
components/spotify/cspot/protobuf/metadata.options

@@ -13,5 +13,6 @@ Episode.gid type:FT_POINTER
 Episode.name type:FT_POINTER
 ImageGroup.image type:FT_POINTER
 Episode.audio type:FT_POINTER
+Episode.covers type:FT_POINTER
 Restriction.countries_allowed type:FT_POINTER
 Restriction.countries_forbidden type:FT_POINTER

+ 1 - 0
components/spotify/cspot/protobuf/metadata.proto

@@ -45,6 +45,7 @@ message Episode {
     optional string name = 2;
     optional sint32 duration = 7;
     repeated AudioFile audio = 12;
+    optional ImageGroup covers = 0x44;
 }
 
 enum AudioFormat {

+ 3 - 7
components/spotify/cspot/src/AudioChunkManager.cpp

@@ -3,7 +3,7 @@
 #include "Logger.h"
 
 AudioChunkManager::AudioChunkManager()
-    : bell::Task("AudioChunkManager", 4 * 1024, +0, 0) {
+    : bell::Task("AudioChunkManager", 4 * 1024, +1, 0) {
     this->chunks = std::vector<std::shared_ptr<AudioChunk>>();
     startTask();
 }
@@ -96,11 +96,7 @@ void AudioChunkManager::runTask() {
                             break;
 
                         default:
-                            // printf("ID: %d: Got data chunk!\n", seqId);
-                            // 2 first bytes are size so we skip it
-                            // printf("(_)--- Free memory %d\n",
-                            // esp_get_free_heap_size());
-                            if (chunk == nullptr) {
+                            if (chunk.get() == nullptr) {
                                 return;
                             }
                             auto actualData = std::vector<uint8_t>(
@@ -114,7 +110,7 @@ void AudioChunkManager::runTask() {
             } catch (...) {
             }
         } else {
-//            usleep(100*1000);
+            usleep(100);
         }
     }
 

+ 1 - 1
components/spotify/cspot/src/MercuryManager.cpp

@@ -30,7 +30,7 @@ MercuryManager::MercuryManager(std::unique_ptr<Session> session): bell::Task("me
 
 MercuryManager::~MercuryManager()
 {
-    pbFree(Header_fields, &tempMercuryHeader);
+    pb_release(Header_fields, tempMercuryHeader);
 }
 
 bool MercuryManager::timeoutHandler()

+ 1 - 1
components/spotify/cspot/src/MercuryResponse.cpp

@@ -9,7 +9,7 @@ MercuryResponse::MercuryResponse(std::vector<uint8_t> &data)
 }
 
 MercuryResponse::~MercuryResponse() {
-    pbFree(Header_fields, &mercuryHeader);
+    pb_release(Header_fields, mercuryHeader);
 }
 
 void MercuryResponse::parseResponse(std::vector<uint8_t> &data)

+ 2 - 2
components/spotify/cspot/src/PlayerState.cpp

@@ -53,8 +53,8 @@ PlayerState::PlayerState(std::shared_ptr<TimeProvider> timeProvider)
 }
 
 PlayerState::~PlayerState() {
-    pbFree(Frame_fields, &innerFrame);
-    pbFree(Frame_fields, &remoteFrame);
+    pb_release(Frame_fields, innerFrame);
+    pb_release(Frame_fields, remoteFrame);
 }
 
 void PlayerState::setPlaybackState(const PlaybackState state)

+ 4 - 4
components/spotify/cspot/src/Session.cpp

@@ -18,10 +18,10 @@ Session::Session()
 
 Session::~Session()
 {
-    pbFree(ClientHello_fields, &clientHello);
-    pbFree(APResponseMessage_fields, &apResponse);
-    pbFree(ClientResponseEncrypted_fields, &authRequest);
-    pbFree(ClientResponsePlaintext_fields, &clientResPlaintext);
+    pb_release(ClientHello_fields, clientHello);
+    pb_release(APResponseMessage_fields, apResponse);
+    pb_release(ClientResponseEncrypted_fields, authRequest);
+    pb_release(ClientResponsePlaintext_fields, clientResPlaintext);
 }
 
 void Session::connect(std::unique_ptr<PlainConnection> connection)

+ 17 - 2
components/spotify/cspot/src/SpotifyTrack.cpp

@@ -35,8 +35,8 @@ SpotifyTrack::~SpotifyTrack()
 {
     this->manager->unregisterMercuryCallback(this->reqSeqNum);
     this->manager->freeAudioKeyCallback();
-    pbFree(Track_fields, &this->trackInfo);
-    pbFree(Episode_fields, &this->episodeInfo);
+    pb_release(Track_fields, this->trackInfo);
+    pb_release(Episode_fields, this->episodeInfo);
 }
 
 bool SpotifyTrack::countryListContains(std::string countryList, std::string country)
@@ -142,6 +142,21 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr<MercuryResponse> r
         }
     }
 
+    if (trackInfoReceived != nullptr)
+    {
+        auto imageId = pbArrayToVector(episodeInfo.covers->image[0].file_id);
+        TrackInfo simpleTrackInfo = {
+            .name = std::string(episodeInfo.name),
+            .album = "",
+            .artist = "",
+            .imageUrl = "https://i.scdn.co/image/" + bytesToHexString(imageId),
+            .duration = trackInfo.duration,
+
+        };
+
+        trackInfoReceived(simpleTrackInfo);
+    }
+
     this->requestAudioKey(pbArrayToVector(episodeInfo.gid), this->fileId, episodeInfo.duration, position_ms, isPaused);
 }
 

+ 1 - 1
components/spotify/cspot/src/TrackReference.cpp

@@ -19,7 +19,7 @@ TrackReference::TrackReference(TrackRef *ref)
 
 TrackReference::~TrackReference()
 {
-    //pbFree(TrackRef_fields, &ref);
+	pb_release(TrackRef_fields, ref);
 }
 
 std::vector<uint8_t> TrackReference::base62Decode(std::string uri)

+ 2 - 2
components/tools/CMakeLists.txt

@@ -1,6 +1,6 @@
 idf_component_register( SRCS operator.cpp tools.c trace.c
-			REQUIRES esp_common pthread 
-                    	INCLUDE_DIRS .
+						REQUIRES _override esp_common pthread 
+						INCLUDE_DIRS .
 )
 
 #doing our own implementation of new operator for some pre-compiled binaries

+ 1 - 1
main/CMakeLists.txt

@@ -1,5 +1,5 @@
 idf_component_register(SRC_DIRS . 
-						PRIV_REQUIRES _override esp_common wifi-manager pthread squeezelite-ota platform_console telnet display
+						PRIV_REQUIRES esp_common wifi-manager pthread squeezelite-ota platform_console telnet display
                     	EMBED_FILES ../server_certs/github.pem
 						LDFRAGMENTS "linker.lf"
                     	)