more CSpot catchup

This commit is contained in:
Philippe G
2022-01-07 19:16:55 -08:00
parent 052600a45a
commit e9da432bfc
5 changed files with 12 additions and 10 deletions

View File

@@ -37,6 +37,7 @@ class SpircController {
private: private:
std::shared_ptr<MercuryManager> manager; std::shared_ptr<MercuryManager> manager;
std::string username; std::string username;
bool firstFrame = true;
std::unique_ptr<Player> player; std::unique_ptr<Player> player;
std::unique_ptr<PlayerState> state; std::unique_ptr<PlayerState> state;
std::shared_ptr<AudioSink> audioSink; std::shared_ptr<AudioSink> audioSink;

View File

@@ -156,7 +156,6 @@ void ChunkedAudioStream::startPlaybackLoop()
void ChunkedAudioStream::seek(size_t dpos, Whence whence) void ChunkedAudioStream::seek(size_t dpos, Whence whence)
{ {
BELL_LOG(info, "cspot", "%d", dpos);
auto seekPos = 0; auto seekPos = 0;
switch (whence) switch (whence)
{ {

View File

@@ -31,6 +31,7 @@ void ChunkedByteStream::fetchFileInformation() {
endChunk->keepInMemory = true; endChunk->keepInMemory = true;
chunks.push_back(endChunk); chunks.push_back(endChunk);
requestChunk(0);
} }
std::shared_ptr<AudioChunk> ChunkedByteStream::getChunkForPosition(size_t position) { std::shared_ptr<AudioChunk> ChunkedByteStream::getChunkForPosition(size_t position) {
@@ -57,6 +58,8 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
std::scoped_lock lock(this->readMutex); std::scoped_lock lock(this->readMutex);
auto chunk = getChunkForPosition(pos); auto chunk = getChunkForPosition(pos);
uint16_t chunkIndex = this->pos / AUDIO_CHUNK_SIZE; uint16_t chunkIndex = this->pos / AUDIO_CHUNK_SIZE;
if (loadAheadEnabled) {
for (auto it = chunks.begin(); it != chunks.end();) { for (auto it = chunks.begin(); it != chunks.end();) {
if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) { if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
it = chunks.erase(it); it = chunks.erase(it);
@@ -64,6 +67,7 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
it++; it++;
} }
} }
}
// Request chunk if does not exist // Request chunk if does not exist
if (chunk == nullptr) { if (chunk == nullptr) {
@@ -85,7 +89,7 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
pos += read; pos += read;
auto nextChunkPos = ((chunkIndex + 1) * AUDIO_CHUNK_SIZE) + 1; auto nextChunkPos = ((chunkIndex + 1) * AUDIO_CHUNK_SIZE) + 1;
if (loadAheadEnabled && nextChunkPos + AUDIO_CHUNK_SIZE < fileSize) { if (loadAheadEnabled && nextChunkPos < fileSize) {
auto nextChunk = getChunkForPosition(nextChunkPos); auto nextChunk = getChunkForPosition(nextChunkPos);
if (nextChunk == nullptr) { if (nextChunk == nullptr) {
@@ -117,7 +121,6 @@ size_t ChunkedByteStream::attemptRead(uint8_t *buffer, size_t bytes, std::shared
void ChunkedByteStream::seek(size_t nbytes) { void ChunkedByteStream::seek(size_t nbytes) {
std::scoped_lock lock(this->readMutex); std::scoped_lock lock(this->readMutex);
BELL_LOG(info, "cspot", "seeking to %d", nbytes);
pos = nbytes; pos = nbytes;

View File

@@ -137,7 +137,7 @@ void PlayerState::updatePositionMs(uint32_t position)
void PlayerState::updateTracks() void PlayerState::updateTracks()
{ {
CSPOT_LOG(info, "---- Track count %d", remoteFrame.state.track_count); CSPOT_LOG(info, "---- Track count %d", remoteFrame.state.track_count);
//innerFrame.state.context_uri = remoteFrame.state.context_uri == nullptr ? nullptr : strdup(remoteFrame.state.context_uri); innerFrame.state.context_uri = remoteFrame.state.context_uri == nullptr ? nullptr : strdup(remoteFrame.state.context_uri);
std::copy(std::begin(remoteFrame.state.track), std::end(remoteFrame.state.track), std::begin(innerFrame.state.track)); std::copy(std::begin(remoteFrame.state.track), std::end(remoteFrame.state.track), std::begin(innerFrame.state.track));
innerFrame.state.track_count = remoteFrame.state.track_count; innerFrame.state.track_count = remoteFrame.state.track_count;
innerFrame.state.has_playing_track_index = true; innerFrame.state.has_playing_track_index = true;

View File

@@ -103,7 +103,6 @@ void SpircController::prevSong() {
} }
void SpircController::handleFrame(std::vector<uint8_t> &data) { void SpircController::handleFrame(std::vector<uint8_t> &data) {
//pb_release(Frame_fields, &state->remoteFrame);
pbDecode(state->remoteFrame, Frame_fields, data); pbDecode(state->remoteFrame, Frame_fields, data);
switch (state->remoteFrame.typ) { switch (state->remoteFrame.typ) {