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:
std::shared_ptr<MercuryManager> manager;
std::string username;
bool firstFrame = true;
std::unique_ptr<Player> player;
std::unique_ptr<PlayerState> state;
std::shared_ptr<AudioSink> audioSink;

View File

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

View File

@@ -31,6 +31,7 @@ void ChunkedByteStream::fetchFileInformation() {
endChunk->keepInMemory = true;
chunks.push_back(endChunk);
requestChunk(0);
}
std::shared_ptr<AudioChunk> ChunkedByteStream::getChunkForPosition(size_t position) {
@@ -57,11 +58,14 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
std::scoped_lock lock(this->readMutex);
auto chunk = getChunkForPosition(pos);
uint16_t chunkIndex = this->pos / AUDIO_CHUNK_SIZE;
for (auto it = chunks.begin(); it != chunks.end();) {
if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
it = chunks.erase(it);
} else {
it++;
if (loadAheadEnabled) {
for (auto it = chunks.begin(); it != chunks.end();) {
if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
it = chunks.erase(it);
} else {
it++;
}
}
}
@@ -85,7 +89,7 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) {
pos += read;
auto nextChunkPos = ((chunkIndex + 1) * AUDIO_CHUNK_SIZE) + 1;
if (loadAheadEnabled && nextChunkPos + AUDIO_CHUNK_SIZE < fileSize) {
if (loadAheadEnabled && nextChunkPos < fileSize) {
auto nextChunk = getChunkForPosition(nextChunkPos);
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) {
std::scoped_lock lock(this->readMutex);
BELL_LOG(info, "cspot", "seeking to %d", nbytes);
pos = nbytes;

View File

@@ -137,7 +137,7 @@ void PlayerState::updatePositionMs(uint32_t position)
void PlayerState::updateTracks()
{
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));
innerFrame.state.track_count = remoteFrame.state.track_count;
innerFrame.state.has_playing_track_index = true;

View File

@@ -103,7 +103,6 @@ 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) {