Skip to content

Commit

Permalink
feat: Update submodule/bell, improve memory management, and fix vario…
Browse files Browse the repository at this point in the history
…us issues

- **Submodule Update**:
  - Updated submodule/bell to latest commit.

- **Track Handling**:
  - Resolved play command issue when choosing a recently searched title.
  - Corrected track display issue in autoplay queue after playing tracks.
  - Fixed track processing issues and simplified shuffle logic.
  - Limited track processing to one track per call for better handling.

- **Memory Management**:
  - Fixed memory leak in CDNAudioFile.

- **DeviceStateHandler**:
  - Fixed double release issue during DeviceStateHandler destruction.

- **Error Handling**:
  - Added retry mechanism in TrackPlayer for handling read errors.
  - Fixed issue with incorrect string dereferencing.

- **Session Management**:
  - Addressed disconnect issue in MercurySession.
  - Ensured correct tracks are displayed for autoplay.

- **Performance Improvements**:
  - Reduced `loadedSemaphore->give()` to prevent overspawn.
  - Optimized TrackPlayer to prevent premature play attempts before track is processed.
  - Reduced `trackProcessing` to one track per call, giving the first track time to load completely.

- **Discovery & Login**:
  - Added new discovery mode option with stay-logged-in feature.

- **Miscellaneous**:
  - Minor bug fixes and improvements.
  • Loading branch information
tobiasguyer committed Dec 17, 2024
1 parent 8d2d5ec commit 66941c9
Show file tree
Hide file tree
Showing 23 changed files with 978 additions and 717 deletions.
15 changes: 13 additions & 2 deletions cspot/include/CDNAudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class CDNAudioFile {
* @brief Opens connection to the provided cdn url, and fetches track metadata.
*/
void openStream();

/**
* @brief Read and decrypt part of the cdn stream
*
* @param dst buffer where to read received data to
* @param amount of bytes to read
*
* @returns amount of bytes read
*/
size_t readBytes(uint8_t* dst, size_t bytes);
#else
/**
* @brief Opens connection to the provided cdn url, and fetches track header.
Expand All @@ -34,8 +44,8 @@ class CDNAudioFile {
*
* @returns char* where to read data from
*/
uint8_t* openStream(size_t&);
#endif
uint8_t* openStream(ssize_t&);

/**
* @brief Read and decrypt part of the cdn stream
*
Expand All @@ -46,6 +56,7 @@ class CDNAudioFile {
*/
long readBytes(uint8_t* dst, size_t bytes);

#endif
/**
* @brief Returns current position in CDN stream
*/
Expand Down
12 changes: 7 additions & 5 deletions cspot/include/DeviceStateHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class DeviceStateHandler {
};

typedef std::function<void(Command)> StateCallback;
std::function<void()> onClose;

DeviceStateHandler(std::shared_ptr<cspot::Context>);
DeviceStateHandler(std::shared_ptr<cspot::Context>, std::function<void()>);
~DeviceStateHandler();

void disconnect();
Expand Down Expand Up @@ -101,10 +102,11 @@ class DeviceStateHandler {
void parseCommand(std::vector<uint8_t>& data);
void skip(CommandType dir, bool notify);

void unreference(char* string) {
if (string != NULL)
free(string);
string = NULL;
void unreference(char** string) {
if (*string != NULL) {
free(*string);
*string = NULL;
}
}

static void reloadTrackList(void*);
Expand Down
9 changes: 3 additions & 6 deletions cspot/include/TrackPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TrackPlayer : bell::Task {
TrackPlayer(std::shared_ptr<cspot::Context> ctx,
std::shared_ptr<cspot::TrackQueue> trackQueue,
TrackEndedCallback onTrackEnd,
TrackChangedCallback onTrackChanged);
TrackChangedCallback onTrackChanged, bool* track_repeat);
~TrackPlayer();

void loadTrackFromRef(TrackReference& ref, size_t playbackMs,
Expand All @@ -54,7 +54,7 @@ class TrackPlayer : bell::Task {
SeekableCallback spaces_available = nullptr);

// CDNTrackStream::TrackInfo getCurrentTrackInfo();
void seekMs(size_t ms);
void seekMs(size_t ms, bool loading = true);
void resetState(bool paused = false);

#ifndef CONFIG_BELL_NOCODEC
Expand Down Expand Up @@ -85,6 +85,7 @@ class TrackPlayer : bell::Task {

// Playback control
std::atomic<bool> currentSongPlaying;
bool* repeating_track_;
std::mutex playbackMutex;
std::mutex dataOutMutex;

Expand All @@ -95,11 +96,7 @@ class TrackPlayer : bell::Task {
int currentSection;
#endif

#ifndef CONFIG_BELL_NOCODEC
std::vector<uint8_t> pcmBuffer = std::vector<uint8_t>(1024);
#else
std::vector<uint8_t> pcmBuffer = std::vector<uint8_t>(1024);
#endif

bool autoStart = false;

Expand Down
8 changes: 4 additions & 4 deletions cspot/include/TrackQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class QueuedTrack {
std::string identifier;
uint32_t playingTrackIndex;
uint32_t requestedPosition;
AudioFormat audioFormat;
bool loading = false;
uint8_t retries = 0;

// PB data
Track pbTrack = Track_init_zero;
Expand All @@ -84,8 +86,6 @@ class QueuedTrack {

void stepLoadCDNUrl(const std::string& accessKey);

void expire();

private:
std::shared_ptr<cspot::Context> ctx;
std::shared_ptr<bell::WrappedSemaphore> playableSemaphore;
Expand Down Expand Up @@ -126,10 +126,10 @@ class TrackQueue : public bell::Task {
std::shared_ptr<cspot::Context> ctx;
std::shared_ptr<bell::WrappedSemaphore> processSemaphore;

bool isRunning = false;
std::atomic<bool> isRunning = false;

std::string accessKey;

void processTrack(std::shared_ptr<QueuedTrack> track);
bool processTrack(std::shared_ptr<QueuedTrack> track);
};
} // namespace cspot
170 changes: 95 additions & 75 deletions cspot/protobuf/connect.options
Original file line number Diff line number Diff line change
@@ -1,79 +1,99 @@
DeviceInfo.name type:FT_POINTER
DeviceInfo.device_id type:FT_POINTER
DeviceInfo.client_id type:FT_POINTER
DeviceInfo.spirc_version type:FT_POINTER
//DeviceInfo.supported_types type:FT_POINTER
DeviceInfo.device_software_version type:FT_POINTER
DeviceInfo.capabilities max_count:27, fixed_count:false
DeviceInfo.model type:FT_POINTER
DeviceInfo.brand type:FT_POINTER
PutStateRequest.callback_url type:FT_POINTER
PutStateRequest.last_command_sent_by_device_id type:FT_POINTER
Capabilities.stringValue max_count:50, max_size: 50
Capabilities.intValue max_count:50
Capabilities.supported_types type:FT_POINTER
Capabilities.Supported_typesEntry type:FT_POINTER
Cluster.device max_count:10 fixed_count:false
Cluster.DeviceEntry.key type:FT_POINTER
Cluster.active_device_id type:FT_POINTER
ProvidedTrack.uri type:FT_POINTER
ProvidedTrack.uid type:FT_POINTER
ProvidedTrack.metadata max_count:30, fixed_count:false
ProvidedTrack.MetadataEntry type:FT_POINTER
ProvidedTrack.removed type:FT_POINTER
ProvidedTrack.blocked type:FT_POINTER
ProvidedTrack.provider type:FT_POINTER
ProvidedTrack.album_uri type:FT_POINTER
ProvidedTrack.disallow_reasons type:FT_POINTER
ProvidedTrack.artist_uri type:FT_POINTER
ProvidedTrack.disallow_undecided type:FT_POINTER
PlayOrigin.feature_identifier type:FT_POINTER
PlayOrigin.feature_version type:FT_POINTER
PlayOrigin.view_uri type:FT_POINTER
PlayOrigin.external_referrer type:FT_POINTER
PlayOrigin.referrer_identifier type:FT_POINTER
PlayOrigin.device_identifier type:FT_POINTER
PlayOrigin.feature_classes type:FT_POINTER
PlayerState.playback_id type:FT_POINTER
DeviceInfo.name type
: FT_POINTER DeviceInfo.device_id type
: FT_POINTER DeviceInfo.client_id type : FT_POINTER DeviceInfo
.spirc_version type
: FT_POINTER
//DeviceInfo.supported_types type:FT_POINTER
DeviceInfo.device_software_version type
: FT_POINTER DeviceInfo.model type
: FT_POINTER DeviceInfo.brand type
: FT_POINTER PutStateRequest.callback_url type
: FT_POINTER PutStateRequest.last_command_sent_by_device_id type
: FT_POINTER Capabilities.supported_types type
: FT_POINTER Capabilities.supported_typesEntry type
: FT_POINTER Cluster.device max_count : 10 fixed_count
: false Cluster.DeviceEntry.key type
: FT_POINTER Cluster.active_device_id type
: FT_POINTER ProvidedTrack.uri type
: FT_POINTER ProvidedTrack.uid type
: FT_POINTER ProvidedTrack.metadata max_count : 30,
fixed_count
: false ProvidedTrack.MetadataEntry type
: FT_POINTER ProvidedTrack.removed type
: FT_POINTER ProvidedTrack.blocked type
: FT_POINTER ProvidedTrack.provider type
: FT_POINTER ProvidedTrack.album_uri type
: FT_POINTER ProvidedTrack.disallow_reasons type
: FT_POINTER ProvidedTrack.artist_uri type
: FT_POINTER ProvidedTrack.disallow_undecided type
: FT_POINTER PlayOrigin.feature_identifier type
: FT_POINTER PlayOrigin.feature_version type
: FT_POINTER PlayOrigin.view_uri type
: FT_POINTER PlayOrigin.external_referrer type
: FT_POINTER PlayOrigin.referrer_identifier type
: FT_POINTER PlayOrigin.device_identifier type
: FT_POINTER PlayOrigin.feature_classes type : FT_POINTER PlayerState
.playback_id type
: FT_POINTER

ContextPlayerOptions.context_enhancement max_count:2, fixed_count:false
ContextPlayerOptions.ContextEnhancementEntry type:FT_POINTER
ContextPlayerOptions.context_enhancement max_count : 2,
fixed_count : false ContextPlayerOptions
.ContextEnhancementEntry type : FT_POINTER

Restrictions type:FT_POINTER
Restrictions type
: FT_POINTER

PlayerState.context_uri type:FT_POINTER
PlayerState.context_url type:FT_POINTER
PlayerState.context_metadata type:FT_POINTER
PlayerState.ContextMetadataEntry type:FT_POINTER
PlayerState.page_metadata type:FT_POINTER
PlayerState.PageMetadataEntry type:FT_POINTER
PlayerState.session_id type:FT_POINTER
PlayerState.queue_revision type:FT_POINTER
PlayerState.entity_uri type:FT_POINTER
PlayerState.playback_provider type:FT_POINTER
PlayerState.random_message type:FT_POINTER
PlayerState.context_uri type
: FT_POINTER PlayerState.context_url type
: FT_POINTER PlayerState.context_metadata type
: FT_POINTER PlayerState.ContextMetadataEntry type
: FT_POINTER PlayerState.page_metadata type
: FT_POINTER PlayerState.PageMetadataEntry type
: FT_POINTER PlayerState.session_id type
: FT_POINTER PlayerState.queue_revision type
: FT_POINTER PlayerState.entity_uri type
: FT_POINTER PlayerState.playback_provider type : FT_POINTER PlayerState
.random_message type
: FT_POINTER

Restrictions.disallow_pausing_reasons type:FT_POINTER
Restrictions.disallow_resuming_reasons type:FT_POINTER
Restrictions.disallow_seeking_reasons type:FT_POINTER
Restrictions.disallow_peeking_prev_reasons type:FT_POINTER
Restrictions.disallow_peeking_next_reasons type:FT_POINTER
Restrictions.disallow_skipping_prev_reasons type:FT_POINTER
Restrictions.disallow_skipping_next_reasons type:FT_POINTER
Restrictions.disallow_toggling_repeat_context_reasons type:FT_POINTER
Restrictions.disallow_toggling_repeat_track_reasons type:FT_POINTER
Restrictions.disallow_toggling_shuffle_reasons type:FT_POINTER
Restrictions.disallow_set_queue_reasons type:FT_POINTER
Restrictions.disallow_interrupting_playback_reasons type:FT_POINTER
Restrictions.disallow_transferring_playback_reasons type:FT_POINTER
Restrictions.disallow_remote_control_reasons type:FT_POINTER
Restrictions.disallow_inserting_into_next_tracks_reasons type:FT_POINTER
Restrictions.disallow_inserting_into_context_tracks_reasons type:FT_POINTER
Restrictions.disallow_reordering_in_next_tracks_reasons type:FT_POINTER
Restrictions.disallow_reordering_in_context_tracks_reasons type:FT_POINTER
Restrictions.disallow_removing_from_next_tracks_reasons type:FT_POINTER
Restrictions.disallow_removing_from_context_tracks_reasons type:FT_POINTER
Restrictions.disallow_updating_context_reasons type:FT_POINTER
Restrictions.disallow_playing_reasons type:FT_POINTER
Restrictions.disallow_stopping_reasons type:FT_POINTER
Restrictions.disallow_loading_context_reasons type:FT_POINTER
Restrictions.disallow_pausing_reasons type : FT_POINTER Restrictions
.disallow_resuming_reasons type : FT_POINTER Restrictions
.disallow_seeking_reasons type : FT_POINTER Restrictions
.disallow_peeking_prev_reasons type
: FT_POINTER Restrictions
.disallow_peeking_next_reasons type
: FT_POINTER Restrictions
.disallow_skipping_prev_reasons type
: FT_POINTER Restrictions
.disallow_skipping_next_reasons type
: FT_POINTER Restrictions
.disallow_toggling_repeat_context_reasons type
: FT_POINTER Restrictions
.disallow_toggling_repeat_track_reasons type
: FT_POINTER Restrictions
.disallow_toggling_shuffle_reasons type
: FT_POINTER Restrictions
.disallow_set_queue_reasons type : FT_POINTER Restrictions
.disallow_interrupting_playback_reasons type
: FT_POINTER Restrictions
.disallow_transferring_playback_reasons type
: FT_POINTER Restrictions
.disallow_remote_control_reasons type
: FT_POINTER Restrictions
.disallow_inserting_into_next_tracks_reasons type
: FT_POINTER Restrictions
.disallow_inserting_into_context_tracks_reasons type
: FT_POINTER Restrictions
.disallow_reordering_in_next_tracks_reasons type
: FT_POINTER Restrictions
.disallow_reordering_in_context_tracks_reasons type
: FT_POINTER Restrictions
.disallow_removing_from_next_tracks_reasons type
: FT_POINTER Restrictions
.disallow_removing_from_context_tracks_reasons type
: FT_POINTER Restrictions
.disallow_updating_context_reasons type
: FT_POINTER Restrictions
.disallow_playing_reasons type : FT_POINTER Restrictions
.disallow_stopping_reasons type
: FT_POINTER Restrictions.disallow_loading_context_reasons type : FT_POINTER
Loading

0 comments on commit 66941c9

Please sign in to comment.