Backed out a previous attempt to fix multiple streams trying to cache

the same file simultaenously. This was later fixed in a more robust way
in LruCache using Player instanceIds, but the code removed in this
commit was left around to rot and cause issues.
This commit is contained in:
Casey Langen 2020-10-24 12:07:48 -07:00
parent a50c2467dc
commit a302837f1a
8 changed files with 33 additions and 55 deletions

View File

@ -79,11 +79,6 @@ void CrossfadeTransport::PrepareNextTrack(const std::string& uri, Gain gain) {
this->next.Reset(uri, this, gain, false);
}
bool CrossfadeTransport::HasNextTrack() {
Lock lock(this->stateMutex);
return !!this->next.player;
}
void CrossfadeTransport::Start(const std::string& uri, Gain gain, StartMode mode) {
{
Lock lock(this->stateMutex);

View File

@ -62,7 +62,6 @@ namespace musik { namespace core { namespace audio {
virtual void Start(const std::string& uri, Gain gain, StartMode mode);
virtual void PrepareNextTrack(const std::string& uri, Gain gain);
virtual bool HasNextTrack();
virtual std::string Uri();

View File

@ -45,22 +45,6 @@ using namespace musik::core::sdk;
static std::string TAG = "GaplessTransport";
#define RESET_NEXT_PLAYER(instance) \
if (instance->nextPlayer) { \
instance->nextPlayer->Detach(instance); \
instance->nextPlayer->Destroy(); \
this->RaiseStreamEvent(StreamDestroyed, instance->nextPlayer); \
instance->nextPlayer = nullptr; \
}
#define RESET_ACTIVE_PLAYER(instance) \
if (instance->activePlayer) { \
instance->activePlayer->Detach(instance); \
instance->activePlayer->Destroy(); \
this->RaiseStreamEvent(StreamDestroyed, instance->activePlayer); \
instance->activePlayer = nullptr; \
}
GaplessTransport::GaplessTransport()
: volume(1.0)
, playbackState(PlaybackStopped)
@ -73,8 +57,8 @@ GaplessTransport::GaplessTransport()
GaplessTransport::~GaplessTransport() {
LockT lock(this->stateMutex);
RESET_NEXT_PLAYER(this);
RESET_ACTIVE_PLAYER(this);
this->ResetNextPlayer();
this->ResetActivePlayer();
}
PlaybackState GaplessTransport::GetPlaybackState() {
@ -92,7 +76,7 @@ void GaplessTransport::PrepareNextTrack(const std::string& uri, Gain gain) {
{
LockT lock(this->stateMutex);
RESET_NEXT_PLAYER(this);
this->ResetNextPlayer();
if (uri.size()) {
this->nextPlayer = Player::Create(uri, this->output, Player::NoDrain, this, gain);
@ -105,10 +89,6 @@ void GaplessTransport::PrepareNextTrack(const std::string& uri, Gain gain) {
}
}
bool GaplessTransport::HasNextTrack() {
return !!this->nextPlayer;
}
void GaplessTransport::Start(const std::string& uri, Gain gain, StartMode mode) {
musik::debug::info(TAG, "starting track at " + uri);
Player* newPlayer = Player::Create(uri, this->output, Player::NoDrain, this, gain);
@ -124,10 +104,10 @@ void GaplessTransport::StartWithPlayer(Player* newPlayer, StartMode mode) {
playingNext = (newPlayer == nextPlayer);
if (newPlayer != nextPlayer) {
RESET_NEXT_PLAYER(this);
this->ResetNextPlayer();
}
RESET_ACTIVE_PLAYER(this);
this->ResetActivePlayer();
this->nextPlayer = nullptr;
this->activePlayer = newPlayer;
@ -182,9 +162,9 @@ void GaplessTransport::StopInternal(
{
LockT lock(this->stateMutex);
RESET_NEXT_PLAYER(this);
this->ResetNextPlayer();
if (this->activePlayer != exclude) {
RESET_ACTIVE_PLAYER(this);
this->ResetActivePlayer();
}
}
@ -366,12 +346,12 @@ void GaplessTransport::OnPlayerOpenFailed(Player* player) {
{
LockT lock(this->stateMutex);
if (player == this->activePlayer) {
RESET_ACTIVE_PLAYER(this);
RESET_NEXT_PLAYER(this);
this->ResetActivePlayer();
this->ResetNextPlayer();
raiseEvents = true;
}
else if (player == this->nextPlayer) {
RESET_NEXT_PLAYER(this);
this->ResetNextPlayer();
}
}
if (raiseEvents) {
@ -384,7 +364,7 @@ void GaplessTransport::OnPlayerDestroying(Player *player) {
LockT lock(this->stateMutex);
if (player == this->activePlayer) {
RESET_ACTIVE_PLAYER(this);
this->ResetActivePlayer();
return;
}
}
@ -417,3 +397,21 @@ void GaplessTransport::RaiseStreamEvent(int type, Player* player) {
this->StreamEvent(type, player->GetUrl());
}
}
void GaplessTransport::ResetNextPlayer() {
if (this->nextPlayer) {
this->nextPlayer->Detach(this);
this->nextPlayer->Destroy();
this->RaiseStreamEvent(StreamDestroyed, this->nextPlayer);
this->nextPlayer = nullptr;
}
}
void GaplessTransport::ResetActivePlayer() {
if (this->activePlayer) {
this->activePlayer->Detach(this);
this->activePlayer->Destroy();
this->RaiseStreamEvent(StreamDestroyed, this->activePlayer);
this->activePlayer = nullptr;
}
}

View File

@ -55,7 +55,6 @@ namespace musik { namespace core { namespace audio {
virtual void Start(const std::string& uri, Gain gain, StartMode mode);
virtual void PrepareNextTrack(const std::string& uri, Gain gain);
virtual bool HasNextTrack();
virtual std::string Uri();
@ -101,6 +100,9 @@ namespace musik { namespace core { namespace audio {
virtual void OnPlayerOpenFailed(Player* player);
virtual void OnPlayerDestroying(Player* player);
void ResetActivePlayer();
void ResetNextPlayer();
musik::core::sdk::PlaybackState playbackState;
musik::core::sdk::StreamState activePlayerState;
std::recursive_mutex stateMutex;

View File

@ -58,7 +58,6 @@ namespace musik { namespace core { namespace audio {
virtual void Start(const std::string& uri, Gain gain, StartMode mode) = 0;
virtual void PrepareNextTrack(const std::string& uri, Gain gain) = 0;
virtual bool HasNextTrack() = 0;
virtual std::string Uri() = 0;

View File

@ -107,10 +107,6 @@ void MasterTransport::PrepareNextTrack(const std::string& uri, Gain gain) {
this->transport->PrepareNextTrack(uri, gain);
}
bool MasterTransport::HasNextTrack() {
return this->transport->HasNextTrack();
}
void MasterTransport::Start(const std::string& uri, Gain gain, StartMode type) {
this->transport->Start(uri, gain, type);
}

View File

@ -51,7 +51,6 @@ namespace musik { namespace core { namespace audio {
virtual void Start(const std::string& uri, Gain gain, StartMode mode);
virtual void PrepareNextTrack(const std::string& uri, Gain gain);
virtual bool HasNextTrack();
virtual std::string Uri();

View File

@ -308,17 +308,7 @@ void PlaybackService::ProcessMessage(IMessage &message) {
StreamMessage* streamMessage = static_cast<StreamMessage*>(&message);
StreamState eventType = (StreamState) streamMessage->GetEventType();
if (eventType == StreamDestroyed) {
/* it's possible that we tried to precache a track that was already being
buffered. in this case, it's possible that operation failed. if that's the
case, let's just load the next track now. */
if (!this->transport->HasNextTrack()) {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
this->nextIndex = NO_POSITION;
this->PrepareNextTrack();
}
}
else if (eventType == StreamBuffering || eventType == StreamBuffered || eventType == StreamPlaying) {
if (eventType == StreamBuffering || eventType == StreamBuffered || eventType == StreamPlaying) {
TrackPtr track;
{