mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 13:37:03 +03:00
more CSpot catchup
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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,11 +58,14 @@ 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;
|
||||||
for (auto it = chunks.begin(); it != chunks.end();) {
|
|
||||||
if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
|
if (loadAheadEnabled) {
|
||||||
it = chunks.erase(it);
|
for (auto it = chunks.begin(); it != chunks.end();) {
|
||||||
} else {
|
if (((*it)->endPosition<pos || (*it)->startPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) {
|
||||||
it++;
|
it = chunks.erase(it);
|
||||||
|
} else {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user