2
0
Philippe G 3 жил өмнө
parent
commit
8fa3906b52

+ 18 - 16
components/spotify/cspot/protobuf/metadata.options

@@ -1,16 +1,18 @@
-Track.name max_size: 512
-Track.gid max_size: 64
-Track.file max_count: 16
-Track.artist max_count: 8
-AudioFile.file_id max_size: 128
-Image.file_id max_size: 128
-Artist.gid max_size: 128
-Artist.name max_size: 512
-Album.name max_size: 512
-Episode.gid max_size: 64
-Episode.name max_size: 512
-ImageGroup.image max_count: 10
-Episode.audio max_count: 10
-Episode.covers max_count: 10
-Restriction.countries_allowed max_size: 32
-Restriction.countries_forbidden max_size: 32
+Track.name type: FT_POINTER
+Track.gid type: FT_POINTER
+Track.file type: FT_POINTER
+Track.restriction type: FT_POINTER
+Track.alternative type: FT_POINTER
+Track.artist type: FT_POINTER
+AudioFile.file_id type: FT_POINTER
+Image.file_id type: FT_POINTER
+Artist.gid type: FT_POINTER
+Artist.name type: FT_POINTER
+Album.name type: FT_POINTER
+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

+ 4 - 4
components/spotify/cspot/protobuf/metadata.pb.c

@@ -15,16 +15,16 @@ PB_BIND(Restriction, Restriction, AUTO)
 PB_BIND(Image, Image, AUTO)
 
 
-PB_BIND(ImageGroup, ImageGroup, 2)
+PB_BIND(ImageGroup, ImageGroup, AUTO)
 
 
-PB_BIND(Album, Album, 2)
+PB_BIND(Album, Album, AUTO)
 
 
-PB_BIND(Artist, Artist, 2)
+PB_BIND(Artist, Artist, AUTO)
 
 
-PB_BIND(Track, Track, 4)
+PB_BIND(Track, Track, AUTO)
 
 
 PB_BIND(Episode, Episode, 2)

+ 72 - 87
components/spotify/cspot/protobuf/metadata.pb.h

@@ -24,78 +24,63 @@ typedef enum _AudioFormat {
 } AudioFormat;
 
 /* Struct definitions */
-typedef PB_BYTES_ARRAY_T(128) Artist_gid_t;
 typedef struct _Artist { 
-    bool has_gid;
-    Artist_gid_t gid; 
-    bool has_name;
-    char name[512]; 
+    pb_bytes_array_t *gid; 
+    char *name; 
 } Artist;
 
-typedef PB_BYTES_ARRAY_T(128) AudioFile_file_id_t;
-typedef struct _AudioFile { 
-    bool has_file_id;
-    AudioFile_file_id_t file_id; 
-    bool has_format;
-    AudioFormat format; 
-} AudioFile;
-
-typedef PB_BYTES_ARRAY_T(128) Image_file_id_t;
 typedef struct _Image { 
-    bool has_file_id;
-    Image_file_id_t file_id; 
+    pb_bytes_array_t *file_id; 
 } Image;
 
-typedef struct _Restriction { 
-    bool has_countries_allowed;
-    char countries_allowed[32]; 
-    bool has_countries_forbidden;
-    char countries_forbidden[32]; 
-} Restriction;
-
 typedef struct _ImageGroup { 
     pb_size_t image_count;
-    Image image[10]; 
+    struct _Image *image; 
 } ImageGroup;
 
+typedef struct _Restriction { 
+    char *countries_allowed; 
+    char *countries_forbidden; 
+} Restriction;
+
 typedef struct _Album { 
     pb_callback_t gid; 
-    bool has_name;
-    char name[512]; 
+    char *name; 
     bool has_cover_group;
     ImageGroup cover_group; 
 } Album;
 
-typedef PB_BYTES_ARRAY_T(64) Episode_gid_t;
+typedef struct _AudioFile { 
+    pb_bytes_array_t *file_id; 
+    bool has_format;
+    AudioFormat format; 
+} AudioFile;
+
 typedef struct _Episode { 
-    bool has_gid;
-    Episode_gid_t gid; 
-    bool has_name;
-    char name[512]; 
+    pb_bytes_array_t *gid; 
+    char *name; 
     bool has_duration;
     int32_t duration; 
     pb_size_t audio_count;
-    AudioFile audio[10]; 
-    bool has_covers;
-    ImageGroup covers; 
+    struct _AudioFile *audio; 
+    struct _ImageGroup *covers; 
 } Episode;
 
-typedef PB_BYTES_ARRAY_T(64) Track_gid_t;
 typedef struct _Track { 
-    bool has_gid;
-    Track_gid_t gid; 
-    bool has_name;
-    char name[512]; 
+    pb_bytes_array_t *gid; 
+    char *name; 
     bool has_album;
     Album album; 
     pb_size_t artist_count;
-    Artist artist[8]; 
+    struct _Artist *artist; 
     bool has_duration;
     int32_t duration; 
-    pb_callback_t restriction; 
+    pb_size_t restriction_count;
+    struct _Restriction *restriction; 
     pb_size_t file_count;
-    AudioFile file[16]; 
-    pb_callback_t alternative; 
+    struct _AudioFile *file; 
+    pb_size_t alternative_count;
+    struct _Track *alternative; 
 } Track;
 
 
@@ -110,35 +95,35 @@ extern "C" {
 #endif
 
 /* Initializer values for message structs */
-#define AudioFile_init_default                   {false, {0, {0}}, false, _AudioFormat_MIN}
-#define Restriction_init_default                 {false, "", false, ""}
-#define Image_init_default                       {false, {0, {0}}}
-#define ImageGroup_init_default                  {0, {Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default, Image_init_default}}
-#define Album_init_default                       {{{NULL}, NULL}, false, "", false, ImageGroup_init_default}
-#define Artist_init_default                      {false, {0, {0}}, false, ""}
-#define Track_init_default                       {false, {0, {0}}, false, "", false, Album_init_default, 0, {Artist_init_default, Artist_init_default, Artist_init_default, Artist_init_default, Artist_init_default, Artist_init_default, Artist_init_default, Artist_init_default}, false, 0, {{NULL}, NULL}, 0, {AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default}, {{NULL}, NULL}}
-#define Episode_init_default                     {false, {0, {0}}, false, "", false, 0, 0, {AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default, AudioFile_init_default}, false, ImageGroup_init_default}
-#define AudioFile_init_zero                      {false, {0, {0}}, false, _AudioFormat_MIN}
-#define Restriction_init_zero                    {false, "", false, ""}
-#define Image_init_zero                          {false, {0, {0}}}
-#define ImageGroup_init_zero                     {0, {Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero, Image_init_zero}}
-#define Album_init_zero                          {{{NULL}, NULL}, false, "", false, ImageGroup_init_zero}
-#define Artist_init_zero                         {false, {0, {0}}, false, ""}
-#define Track_init_zero                          {false, {0, {0}}, false, "", false, Album_init_zero, 0, {Artist_init_zero, Artist_init_zero, Artist_init_zero, Artist_init_zero, Artist_init_zero, Artist_init_zero, Artist_init_zero, Artist_init_zero}, false, 0, {{NULL}, NULL}, 0, {AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero}, {{NULL}, NULL}}
-#define Episode_init_zero                        {false, {0, {0}}, false, "", false, 0, 0, {AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero, AudioFile_init_zero}, false, ImageGroup_init_zero}
+#define AudioFile_init_default                   {NULL, false, _AudioFormat_MIN}
+#define Restriction_init_default                 {NULL, NULL}
+#define Image_init_default                       {NULL}
+#define ImageGroup_init_default                  {0, NULL}
+#define Album_init_default                       {{{NULL}, NULL}, NULL, false, ImageGroup_init_default}
+#define Artist_init_default                      {NULL, NULL}
+#define Track_init_default                       {NULL, NULL, false, Album_init_default, 0, NULL, false, 0, 0, NULL, 0, NULL, 0, NULL}
+#define Episode_init_default                     {NULL, NULL, false, 0, 0, NULL, NULL}
+#define AudioFile_init_zero                      {NULL, false, _AudioFormat_MIN}
+#define Restriction_init_zero                    {NULL, NULL}
+#define Image_init_zero                          {NULL}
+#define ImageGroup_init_zero                     {0, NULL}
+#define Album_init_zero                          {{{NULL}, NULL}, NULL, false, ImageGroup_init_zero}
+#define Artist_init_zero                         {NULL, NULL}
+#define Track_init_zero                          {NULL, NULL, false, Album_init_zero, 0, NULL, false, 0, 0, NULL, 0, NULL, 0, NULL}
+#define Episode_init_zero                        {NULL, NULL, false, 0, 0, NULL, NULL}
 
 /* Field tags (for use in manual encoding/decoding) */
 #define Artist_gid_tag                           1
 #define Artist_name_tag                          2
-#define AudioFile_file_id_tag                    1
-#define AudioFile_format_tag                     2
 #define Image_file_id_tag                        1
+#define ImageGroup_image_tag                     1
 #define Restriction_countries_allowed_tag        2
 #define Restriction_countries_forbidden_tag      3
-#define ImageGroup_image_tag                     1
 #define Album_gid_tag                            1
 #define Album_name_tag                           2
 #define Album_cover_group_tag                    17
+#define AudioFile_file_id_tag                    1
+#define AudioFile_format_tag                     2
 #define Episode_gid_tag                          1
 #define Episode_name_tag                         2
 #define Episode_duration_tag                     7
@@ -155,52 +140,52 @@ extern "C" {
 
 /* Struct field encoding specification for nanopb */
 #define AudioFile_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, BYTES,    file_id,           1) \
+X(a, POINTER,  OPTIONAL, BYTES,    file_id,           1) \
 X(a, STATIC,   OPTIONAL, UENUM,    format,            2)
 #define AudioFile_CALLBACK NULL
 #define AudioFile_DEFAULT NULL
 
 #define Restriction_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, STRING,   countries_allowed,   2) \
-X(a, STATIC,   OPTIONAL, STRING,   countries_forbidden,   3)
+X(a, POINTER,  OPTIONAL, STRING,   countries_allowed,   2) \
+X(a, POINTER,  OPTIONAL, STRING,   countries_forbidden,   3)
 #define Restriction_CALLBACK NULL
 #define Restriction_DEFAULT NULL
 
 #define Image_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, BYTES,    file_id,           1)
+X(a, POINTER,  OPTIONAL, BYTES,    file_id,           1)
 #define Image_CALLBACK NULL
 #define Image_DEFAULT NULL
 
 #define ImageGroup_FIELDLIST(X, a) \
-X(a, STATIC,   REPEATED, MESSAGE,  image,             1)
+X(a, POINTER,  REPEATED, MESSAGE,  image,             1)
 #define ImageGroup_CALLBACK NULL
 #define ImageGroup_DEFAULT NULL
 #define ImageGroup_image_MSGTYPE Image
 
 #define Album_FIELDLIST(X, a) \
 X(a, CALLBACK, OPTIONAL, BYTES,    gid,               1) \
-X(a, STATIC,   OPTIONAL, STRING,   name,              2) \
+X(a, POINTER,  OPTIONAL, STRING,   name,              2) \
 X(a, STATIC,   OPTIONAL, MESSAGE,  cover_group,      17)
 #define Album_CALLBACK pb_default_field_callback
 #define Album_DEFAULT NULL
 #define Album_cover_group_MSGTYPE ImageGroup
 
 #define Artist_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, BYTES,    gid,               1) \
-X(a, STATIC,   OPTIONAL, STRING,   name,              2)
+X(a, POINTER,  OPTIONAL, BYTES,    gid,               1) \
+X(a, POINTER,  OPTIONAL, STRING,   name,              2)
 #define Artist_CALLBACK NULL
 #define Artist_DEFAULT NULL
 
 #define Track_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, BYTES,    gid,               1) \
-X(a, STATIC,   OPTIONAL, STRING,   name,              2) \
+X(a, POINTER,  OPTIONAL, BYTES,    gid,               1) \
+X(a, POINTER,  OPTIONAL, STRING,   name,              2) \
 X(a, STATIC,   OPTIONAL, MESSAGE,  album,             3) \
-X(a, STATIC,   REPEATED, MESSAGE,  artist,            4) \
+X(a, POINTER,  REPEATED, MESSAGE,  artist,            4) \
 X(a, STATIC,   OPTIONAL, SINT32,   duration,          7) \
-X(a, CALLBACK, REPEATED, MESSAGE,  restriction,      11) \
-X(a, STATIC,   REPEATED, MESSAGE,  file,             12) \
-X(a, CALLBACK, REPEATED, MESSAGE,  alternative,      13)
-#define Track_CALLBACK pb_default_field_callback
+X(a, POINTER,  REPEATED, MESSAGE,  restriction,      11) \
+X(a, POINTER,  REPEATED, MESSAGE,  file,             12) \
+X(a, POINTER,  REPEATED, MESSAGE,  alternative,      13)
+#define Track_CALLBACK NULL
 #define Track_DEFAULT NULL
 #define Track_album_MSGTYPE Album
 #define Track_artist_MSGTYPE Artist
@@ -209,11 +194,11 @@ X(a, CALLBACK, REPEATED, MESSAGE,  alternative,      13)
 #define Track_alternative_MSGTYPE Track
 
 #define Episode_FIELDLIST(X, a) \
-X(a, STATIC,   OPTIONAL, BYTES,    gid,               1) \
-X(a, STATIC,   OPTIONAL, STRING,   name,              2) \
+X(a, POINTER,  OPTIONAL, BYTES,    gid,               1) \
+X(a, POINTER,  OPTIONAL, STRING,   name,              2) \
 X(a, STATIC,   OPTIONAL, SINT32,   duration,          7) \
-X(a, STATIC,   REPEATED, MESSAGE,  audio,            12) \
-X(a, STATIC,   OPTIONAL, MESSAGE,  covers,           68)
+X(a, POINTER,  REPEATED, MESSAGE,  audio,            12) \
+X(a, POINTER,  OPTIONAL, MESSAGE,  covers,           68)
 #define Episode_CALLBACK NULL
 #define Episode_DEFAULT NULL
 #define Episode_audio_MSGTYPE AudioFile
@@ -239,14 +224,14 @@ extern const pb_msgdesc_t Episode_msg;
 #define Episode_fields &Episode_msg
 
 /* Maximum encoded size of messages (where known) */
+/* AudioFile_size depends on runtime parameters */
+/* Restriction_size depends on runtime parameters */
+/* Image_size depends on runtime parameters */
+/* ImageGroup_size depends on runtime parameters */
 /* Album_size depends on runtime parameters */
+/* Artist_size depends on runtime parameters */
 /* Track_size depends on runtime parameters */
-#define Artist_size                              645
-#define AudioFile_size                           133
-#define Episode_size                             3290
-#define ImageGroup_size                          1340
-#define Image_size                               131
-#define Restriction_size                         66
+/* Episode_size depends on runtime parameters */
 
 #ifdef __cplusplus
 } /* extern "C" */

+ 10 - 9
components/spotify/cspot/protobuf/spirc.options

@@ -1,12 +1,13 @@
-Frame.ident max_size: 64, fixed_length:false
-Frame.protocol_version max_size: 64, fixed_length:false
-Frame.recipient max_count: 64, max_size: 64
+Frame.ident type:FT_POINTER
+Frame.protocol_version type:FT_POINTER
+Frame.recipient type:FT_POINTER
 Capability.stringValue max_count:50, max_size: 50
 Capability.intValue max_count:50
-DeviceState.sw_version max_size: 64, fixed_length:false
-DeviceState.name max_size: 64, fixed_length:false
+DeviceState.sw_version type:FT_POINTER
+DeviceState.name type:FT_POINTER
 DeviceState.capabilities max_count:17, fixed_count:false
-State.context_uri max_size: 256, fixed_length:false
-State.track max_count:100, fixed_count:false
-TrackRef.gid max_size: 128, fixed_length:false
-TrackRef.uri max_size: 256 fixed_length:false
+State.context_uri type:FT_POINTER
+State.track type:FT_POINTER
+TrackRef.gid type:FT_POINTER
+TrackRef.uri type:FT_POINTER
+TrackRef.context type:FT_POINTER

+ 2 - 2
components/spotify/cspot/protobuf/spirc.pb.c

@@ -6,10 +6,10 @@
 #error Regenerate this file with the current version of nanopb generator.
 #endif
 
-PB_BIND(TrackRef, TrackRef, 2)
+PB_BIND(TrackRef, TrackRef, AUTO)
 
 
-PB_BIND(State, State, 4)
+PB_BIND(State, State, AUTO)
 
 
 PB_BIND(Capability, Capability, 2)

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 29 - 38
components/spotify/cspot/protobuf/spirc.pb.h


+ 33 - 44
components/spotify/cspot/src/PlayerState.cpp

@@ -24,20 +24,18 @@ PlayerState::PlayerState(std::shared_ptr<TimeProvider> timeProvider)
     innerFrame.state.repeat = false;
     innerFrame.state.has_repeat = true;
 
-    innerFrame.device_state.has_sw_version = true;
-    pbPutCharArray(swVersion, innerFrame.device_state.sw_version);
+    innerFrame.device_state.sw_version = strdup(swVersion);
 
     innerFrame.device_state.is_active = false;
     innerFrame.device_state.has_is_active = true;
-    
+
     innerFrame.device_state.can_play = true;
     innerFrame.device_state.has_can_play = true;
 
     innerFrame.device_state.volume = configMan->volume;
     innerFrame.device_state.has_volume = true;
 
-    innerFrame.device_state.has_name = true;
-    pbPutString(configMan->deviceName, innerFrame.device_state.name);
+    innerFrame.device_state.name = strdup(configMan->deviceName.c_str());
 
     // Prepare player's capabilities
     addCapability(CapabilityType_kCanBePlayer, 1);
@@ -55,33 +53,32 @@ PlayerState::PlayerState(std::shared_ptr<TimeProvider> timeProvider)
 }
 
 PlayerState::~PlayerState() {
+    pb_release(Frame_fields, &innerFrame);
     pb_release(Frame_fields, &remoteFrame);
-    // do not destruct inner frame as it is never allocated
-//    pb_release(Frame_fields, &innerFrame);
 }
 
 void PlayerState::setPlaybackState(const PlaybackState state)
 {
     switch (state)
     {
-    case PlaybackState::Loading:
-        // Prepare the playback at position 0
-        innerFrame.state.status = PlayStatus_kPlayStatusPause;
-        innerFrame.state.position_ms = 0;
-        innerFrame.state.position_measured_at = timeProvider->getSyncedTimestamp();
-        break;
-    case PlaybackState::Playing:
-        innerFrame.state.status = PlayStatus_kPlayStatusPlay;
-        innerFrame.state.position_measured_at = timeProvider->getSyncedTimestamp();
-        break;
-    case PlaybackState::Stopped:
-        break;
-    case PlaybackState::Paused:
-        // Update state and recalculate current song position
-        innerFrame.state.status = PlayStatus_kPlayStatusPause;
-        uint32_t diff = timeProvider->getSyncedTimestamp() - innerFrame.state.position_measured_at;
-        this->updatePositionMs(innerFrame.state.position_ms + diff);
-        break;
+        case PlaybackState::Loading:
+            // Prepare the playback at position 0
+            innerFrame.state.status = PlayStatus_kPlayStatusPause;
+            innerFrame.state.position_ms = 0;
+            innerFrame.state.position_measured_at = timeProvider->getSyncedTimestamp();
+            break;
+        case PlaybackState::Playing:
+            innerFrame.state.status = PlayStatus_kPlayStatusPlay;
+            innerFrame.state.position_measured_at = timeProvider->getSyncedTimestamp();
+            break;
+        case PlaybackState::Stopped:
+            break;
+        case PlaybackState::Paused:
+            // Update state and recalculate current song position
+            innerFrame.state.status = PlayStatus_kPlayStatusPause;
+            uint32_t diff = timeProvider->getSyncedTimestamp() - innerFrame.state.position_measured_at;
+            this->updatePositionMs(innerFrame.state.position_ms + diff);
+            break;
     }
 }
 
@@ -139,9 +136,8 @@ void PlayerState::updatePositionMs(uint32_t position)
 void PlayerState::updateTracks()
 {
     CSPOT_LOG(info, "---- Track count %d", remoteFrame.state.track_count);
-    strcpy(innerFrame.state.context_uri, remoteFrame.state.context_uri);
-
-    std::copy(std::begin(remoteFrame.state.track), std::end(remoteFrame.state.track), std::begin(innerFrame.state.track));
+    std::swap(innerFrame.state.context_uri, remoteFrame.state.context_uri);
+    std::swap(innerFrame.state.track, remoteFrame.state.track);
     innerFrame.state.track_count = remoteFrame.state.track_count;
     innerFrame.state.has_playing_track_index = true;
     innerFrame.state.playing_track_index = remoteFrame.state.playing_track_index;
@@ -170,17 +166,13 @@ void PlayerState::setShuffle(bool shuffle)
     if (shuffle)
     {
         // Put current song at the begining
-        auto tmp = innerFrame.state.track[0];
-        innerFrame.state.track[0] = innerFrame.state.track[innerFrame.state.playing_track_index];
-        innerFrame.state.track[innerFrame.state.playing_track_index] = tmp;
+        std::swap(innerFrame.state.track[0], innerFrame.state.track[innerFrame.state.playing_track_index]);
 
         // Shuffle current tracks
         for (int x = 1; x < innerFrame.state.track_count - 1; x++)
         {
             auto j = x + (std::rand() % (innerFrame.state.track_count - x));
-            tmp = innerFrame.state.track[j];
-            innerFrame.state.track[j] = innerFrame.state.track[x];
-            innerFrame.state.track[x] = tmp;
+            std::swap(innerFrame.state.track[j], innerFrame.state.track[x]);
         }
         innerFrame.state.playing_track_index = 0;
     }
@@ -199,16 +191,14 @@ std::shared_ptr<TrackReference> PlayerState::getCurrentTrack()
 
 std::vector<uint8_t> PlayerState::encodeCurrentFrame(MessageType typ)
 {
+    free(innerFrame.ident);
+    free(innerFrame.protocol_version);
+
     // Prepare current frame info
     innerFrame.version = 1;
-
-    pbPutCharArray(deviceId, innerFrame.ident);
-    innerFrame.has_ident = true;
-
+    innerFrame.ident = strdup(deviceId);
     innerFrame.seq_nr = this->seqNum;
-    pbPutCharArray(protocolVersion, innerFrame.protocol_version);
-    innerFrame.has_protocol_version = true;
-
+    innerFrame.protocol_version = strdup(protocolVersion);
     innerFrame.typ = typ;
     innerFrame.state_update_id = timeProvider->getSyncedTimestamp();
     innerFrame.has_version = true;
@@ -241,10 +231,9 @@ void PlayerState::addCapability(CapabilityType typ, int intValue, std::vector<st
 
     for (int x = 0; x < stringValue.size(); x++)
     {
-        stringValue[x].copy(this->innerFrame.device_state.capabilities[capabilityIndex].stringValue[x], stringValue[x].size());
-        this->innerFrame.device_state.capabilities[capabilityIndex].stringValue[x][stringValue[x].size()] = '\0';
+        pbPutString(stringValue[x], this->innerFrame.device_state.capabilities[capabilityIndex].stringValue[x]);
     }
 
     this->innerFrame.device_state.capabilities[capabilityIndex].stringValue_count = stringValue.size();
     this->capabilityIndex += 1;
-}
+}

+ 2 - 1
components/spotify/cspot/src/SpircController.cpp

@@ -56,7 +56,7 @@ void SpircController::disconnect(void) {
     state->setActive(false);
     notify();
     // Send the event at the end at it might be a last gasp
-    sendEvent(CSpotEventType::DISC);    
+    sendEvent(CSpotEventType::DISC);
 }
 
 void SpircController::playToggle() {
@@ -103,6 +103,7 @@ void SpircController::prevSong() {
 }
 
 void SpircController::handleFrame(std::vector<uint8_t> &data) {
+    pb_release(Frame_fields, &state->remoteFrame);
     pbDecode(state->remoteFrame, Frame_fields, data);
 
     switch (state->remoteFrame.typ) {

+ 34 - 37
components/spotify/cspot/src/SpotifyTrack.cpp

@@ -53,18 +53,18 @@ bool SpotifyTrack::countryListContains(std::string countryList, std::string coun
 
 bool SpotifyTrack::canPlayTrack()
 {
-//    for (int x = 0; x < trackInfo.restriction_count; x++)
-//    {
-//        if (strlen(trackInfo.restriction[x].countries_allowed) > 0)
-//        {
-//            return countryListContains(std::string(trackInfo.restriction[x].countries_allowed), manager->countryCode);
-//        }
-//
-//        if (strlen(trackInfo.restriction[x].countries_forbidden) > 0)
-//        {
-//            return !countryListContains(std::string(trackInfo.restriction[x].countries_forbidden), manager->countryCode);
-//        }
-//    }
+    for (int x = 0; x < trackInfo.restriction_count; x++)
+    {
+        if (trackInfo.restriction[x].countries_allowed != nullptr)
+        {
+            return countryListContains(std::string(trackInfo.restriction[x].countries_allowed), manager->countryCode);
+        }
+
+        if (trackInfo.restriction[x].countries_forbidden != nullptr)
+        {
+            return !countryListContains(std::string(trackInfo.restriction[x].countries_forbidden), manager->countryCode);
+        }
+    }
 
     return true;
 }
@@ -77,39 +77,37 @@ void SpotifyTrack::trackInformationCallback(std::unique_ptr<MercuryResponse> res
 
     pb_release(Track_fields, &trackInfo);
     pbDecode(trackInfo, Track_fields, response->parts[0]);
-//
-//    CSPOT_LOG(info, "Track name: %s", trackInfo.name);
-//    CSPOT_LOG(info, "Track duration: %d", trackInfo.duration);
-//    CSPOT_LOG(debug, "trackInfo.restriction.size() = %d", trackInfo.restriction_count);
-//    int altIndex = 0;
-//    while (!canPlayTrack())
-//    {
-//        auto src = trackInfo.alternative[altIndex].restriction;
-////        std::copy(std::begin(src), std::end(src), std::begin(trackInfo.restriction));
-////        trackInfo.restriction_count = trackInfo.alternative[altIndex].restriction_count;
-////
-////        free(trackInfo.gid);
-//        trackInfo.gid = trackInfo.alternative[altIndex].gid;
-//        altIndex++;
-//        CSPOT_LOG(info, "Trying alternative %d", altIndex);
-//    }
-
-    auto trackId = std::vector(trackInfo.gid.bytes, trackInfo.gid.bytes + trackInfo.gid.size);
+
+    CSPOT_LOG(info, "Track name: %s", trackInfo.name);
+    CSPOT_LOG(info, "Track duration: %d", trackInfo.duration);
+    CSPOT_LOG(debug, "trackInfo.restriction.size() = %d", trackInfo.restriction_count);
+    int altIndex = 0;
+    while (!canPlayTrack())
+    {
+        std::swap(trackInfo.restriction, trackInfo.alternative[altIndex].restriction);
+        std::swap(trackInfo.restriction_count, trackInfo.alternative[altIndex].restriction_count);
+        std::swap(trackInfo.file, trackInfo.alternative[altIndex].file);
+        std::swap(trackInfo.file_count, trackInfo.alternative[altIndex].file_count);
+        std::swap(trackInfo.gid, trackInfo.alternative[altIndex].gid);
+
+        CSPOT_LOG(info, "Trying alternative %d", altIndex);
+    }
+
+    auto trackId = pbArrayToVector(trackInfo.gid);
     this->fileId = std::vector<uint8_t>();
 
     for (int x = 0; x < trackInfo.file_count; x++)
     {
         if (trackInfo.file[x].format == configMan->format)
         {
-            this->fileId = std::vector(trackInfo.file[x].file_id.bytes, trackInfo.file[x].file_id.bytes + trackInfo.file[x].file_id.size);
+            this->fileId = pbArrayToVector(trackInfo.file[x].file_id);
             break; // If file found stop searching
         }
     }
 
     if (trackInfoReceived != nullptr)
     {
-        auto imageIdBytes = trackInfo.album.cover_group.image[0].file_id;
-        auto imageId = std::vector(imageIdBytes.bytes, imageIdBytes.bytes + imageIdBytes.size);
+        auto imageId = pbArrayToVector(trackInfo.album.cover_group.image[0].file_id);
         TrackInfo simpleTrackInfo = {
             .name = std::string(trackInfo.name),
             .album = std::string(trackInfo.album.name),
@@ -143,15 +141,14 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr<MercuryResponse> r
     {
         if (episodeInfo.audio[x].format == AudioFormat_OGG_VORBIS_96)
         {
-            this->fileId = std::vector(episodeInfo.audio[x].file_id.bytes, episodeInfo.audio[x].file_id.bytes + episodeInfo.audio[x].file_id.size);
+            this->fileId = pbArrayToVector(episodeInfo.audio[x].file_id);
             break; // If file found stop searching
         }
     }
 
     if (trackInfoReceived != nullptr)
     {
-        auto imageFileId = episodeInfo.covers.image[0].file_id;
-        auto imageId = std::vector(imageFileId.bytes, imageFileId.bytes + imageFileId.size);
+        auto imageId = pbArrayToVector(episodeInfo.covers->image[0].file_id);
         TrackInfo simpleTrackInfo = {
             .name = std::string(episodeInfo.name),
             .album = "",
@@ -164,7 +161,7 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr<MercuryResponse> r
         trackInfoReceived(simpleTrackInfo);
     }
 
-    this->requestAudioKey(std::vector(episodeInfo.gid.bytes, episodeInfo.gid.bytes + episodeInfo.gid.size), this->fileId, episodeInfo.duration, position_ms, isPaused);
+    this->requestAudioKey(pbArrayToVector(episodeInfo.gid), this->fileId, episodeInfo.duration, position_ms, isPaused);
 }
 
 void SpotifyTrack::requestAudioKey(std::vector<uint8_t> fileId, std::vector<uint8_t> trackId, int32_t trackDuration, uint32_t position_ms, bool isPaused)

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

@@ -3,11 +3,11 @@
 
 TrackReference::TrackReference(TrackRef *ref)
 {
-    if (ref->gid.size > 0)
+    if (ref->gid != nullptr)
     {
-        gid = std::vector(ref->gid.bytes, ref->gid.bytes + ref->gid.size);
+        gid = pbArrayToVector(ref->gid);
     }
-    else if (strlen(ref->uri) > 0)
+    else if (ref->uri != nullptr)
     {
         auto uri = std::string(ref->uri);
         auto idString = uri.substr(uri.find_last_of(":") + 1, uri.size());

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно