Skip to content

Commit

Permalink
TIDAL: Revert changes to restrict available sound quality options
Browse files Browse the repository at this point in the history
Now all products will offer a Hi-Res option. Actual sound quality is
controlled by any restrictions placed on the provided OAuth token used
to stream with.
  • Loading branch information
projectgoav committed Jan 17, 2024
1 parent ee2e05f commit 1b87ddc
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 37 deletions.
5 changes: 2 additions & 3 deletions OpenHome/Av/Tests/TestMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const TUint TestMediaPlayer::kDsdPadBytesPerChunk;

TestMediaPlayer::TestMediaPlayer(Net::DvStack& aDvStack, Net::CpStack& aCpStack, const Brx& aUdn, const TChar* aRoom, const TChar* aProductName,
const Brx& aTuneInPartnerId, const Brx& aTidalId, const Brx& aQobuzIdSecret, const Brx& aUserAgent,
const TChar* aStoreFile, TUint aMaxTidalAudioQuality, TUint aOdpPort, TUint aWebUiPort,
const TChar* aStoreFile, TUint aOdpPort, TUint aWebUiPort,
TUint aMinWebUiResourceThreads, TUint aMaxWebUiTabs, TUint aUiSendQueueSize,
TUint aUiMsgBufCount, TUint aUiMsgBufBytes)
: iPullableClock(nullptr)
Expand All @@ -184,7 +184,6 @@ TestMediaPlayer::TestMediaPlayer(Net::DvStack& aDvStack, Net::CpStack& aCpStack,
, iUiSendQueueSize(aUiSendQueueSize)
, iUiMsgBufCount(aUiMsgBufCount)
, iUiMsgBufBytes(aUiMsgBufBytes)
, iMaxTidalAudioQuality(aMaxTidalAudioQuality)
{
Log::Print("Shell running on port %u\n", aDvStack.Env().Shell()->Port());
iInfoLogger = new Media::AllocatorInfoLogger();
Expand Down Expand Up @@ -499,7 +498,7 @@ void TestMediaPlayer::RegisterPlugins(Environment& aEnv)
Log::Print(" App: ID: %.*s - ClientId = %.*s, Secret = %.*s\n", PBUF(v.AppId()), PBUF(v.ClientId()), PBUF(v.ClientSecret()));
}

iMediaPlayer->Add(ProtocolFactory::NewTidal(aEnv, ssl, clientId, clientSecret, apps, iMaxTidalAudioQuality, *iMediaPlayer));
iMediaPlayer->Add(ProtocolFactory::NewTidal(aEnv, ssl, clientId, clientSecret, apps, *iMediaPlayer));
}
// ...likewise, only add Qobuz if we have ids for login
if (iQobuzIdSecret.Bytes() > 0) {
Expand Down
6 changes: 1 addition & 5 deletions OpenHome/Av/Tests/TestMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ class TestMediaPlayer : private Net::IResourceManager, public IPowerHandler/*, p
static const TUint kDsdMaxSampleRate = 11289600; // DSD256
static const TUint kDsdSampleBlockWords = 6; // Specifies if the test player outputs DSD as 16xL, 16xR [32 bits = 1 word] or 4 x (24xL, 24xR) [192 bits = 6]
static const TUint kDsdPadBytesPerChunk = 2;
static const TUint kDefaultMaxTidalAudioQuality = 13034431; // Suitably large so we're clamped to the highest. Revisit if TIDAL ever offer more than this number of qualities
public:
TestMediaPlayer(Net::DvStack& aDvStack, Net::CpStack& aCpStack, const Brx& aUdn, const TChar* aRoom, const TChar* aProductName,
const Brx& aTuneInPartnerId, const Brx& aTidalId, const Brx& aQobuzIdSecret, const Brx& aUserAgent,
const TChar* aStoreFile, TUint aMaxTidalAudioQuality = kDefaultMaxTidalAudioQuality, TUint aOdpPort=0, TUint aWebUiPort=0,
const TChar* aStoreFile, TUint aOdpPort=0, TUint aWebUiPort=0,
TUint aMinWebUiResourceThreads=kMinWebUiResourceThreads, TUint aMaxWebUiTabs=kMaxWebUiTabs, TUint aUiSendQueueSize=kUiSendQueueSize, TUint aUiMsgBufCount=kUiMsgBufCount, TUint aUiMsgBufBytes=kUiMsgBufBytes);
virtual ~TestMediaPlayer();
void SetPullableClock(Media::IPullableClock& aPullableClock);
Expand Down Expand Up @@ -217,7 +216,6 @@ class TestMediaPlayer : private Net::IResourceManager, public IPowerHandler/*, p
TUint iUiSendQueueSize;
TUint iUiMsgBufCount;
TUint iUiMsgBufBytes;
const TUint iMaxTidalAudioQuality;
};

class TestMediaPlayerOptions
Expand All @@ -241,7 +239,6 @@ class TestMediaPlayerOptions
const TestFramework::OptionUint& OptionOdp() const;
const TestFramework::OptionUint& OptionWebUi() const;
const TestFramework::OptionUint& Shell() const;
const TestFramework::OptionUint& TidalMaxAudioQuality() const;
private:
TestFramework::OptionParser iParser;
TestFramework::OptionString iOptionRoom;
Expand All @@ -259,7 +256,6 @@ class TestMediaPlayerOptions
TestFramework::OptionUint iOptionOdp;
TestFramework::OptionUint iOptionWebUi;
TestFramework::OptionUint iOptionShell;
TestFramework::OptionUint iOptionTidalMaxAudioQuality;
};

// Not very nice, but only to allow reusable test functions.
Expand Down
2 changes: 1 addition & 1 deletion OpenHome/Av/Tests/TestMediaPlayerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void TestMediaPlayerThread::RunInThread()
// Create TestMediaPlayer.
TestMediaPlayer* tmp = new TestMediaPlayer(*dvStack, *cpStack, udn, iOptions.Room().CString(), iOptions.Name().CString(),
iOptions.TuneIn().Value(), iOptions.Tidal().Value(), iOptions.Qobuz().Value(),
iOptions.UserAgent().Value(), iOptions.StoreFile().CString(), iOptions.TidalMaxAudioQuality().Value(), iOptions.OptionOdp().Value(), iOptions.OptionWebUi().Value());
iOptions.UserAgent().Value(), iOptions.StoreFile().CString(), iOptions.OptionOdp().Value(), iOptions.OptionWebUi().Value());
Media::AnimatorBasic* animator = new Media::AnimatorBasic(
dvStack->Env(),
tmp->Pipeline(),
Expand Down
11 changes: 0 additions & 11 deletions OpenHome/Av/Tests/TestMediaPlayerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ using namespace OpenHome;
using namespace OpenHome::TestFramework;
using namespace OpenHome::Av::Test;

// NOTE: We set this to a suitably high number as default so that internally TIDAL clamp to the highest available, unless otherwise specified
// It's really unlikely that TIDAL will offer that many qualities in the future, but we can revisit this in the future if it does
static const TUint kDefaultTidalMaxAudioQuality = 13043431;

TestMediaPlayerOptions::TestMediaPlayerOptions()
: iOptionRoom("-r", "--room", Brn(""), "room the Product service will report")
, iOptionName("-n", "--name", Brn("SoftPlayer"), "Product name")
Expand All @@ -27,7 +23,6 @@ TestMediaPlayerOptions::TestMediaPlayerOptions()
, iOptionOdp("", "--odp", 0, "Port for ODP server")
, iOptionWebUi("", "--webui", 0, "Port for Web UI server")
, iOptionShell("", "--shell", 0, "Port for shell")
, iOptionTidalMaxAudioQuality("", "--tidalMaxAudioQuality", kDefaultTidalMaxAudioQuality, "Default audio quality for TIDAL streaming. 0 = LOSSY ... 3 = HI_RES")
{
iParser.AddOption(&iOptionRoom);
iParser.AddOption(&iOptionName);
Expand All @@ -44,7 +39,6 @@ TestMediaPlayerOptions::TestMediaPlayerOptions()
iParser.AddOption(&iOptionOdp);
iParser.AddOption(&iOptionWebUi);
iParser.AddOption(&iOptionShell);
iParser.AddOption(&iOptionTidalMaxAudioQuality);
}

void TestMediaPlayerOptions::AddOption(Option* aOption)
Expand Down Expand Up @@ -131,8 +125,3 @@ const OptionUint& TestMediaPlayerOptions::Shell() const
{
return iOptionShell;
}

const OptionUint& TestMediaPlayerOptions::TidalMaxAudioQuality() const
{
return iOptionTidalMaxAudioQuality;
}
4 changes: 1 addition & 3 deletions OpenHome/Av/Tidal/ProtocolTidal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ Protocol* ProtocolFactory::NewTidal(Environment& aEnv,
const Brx& aClientId,
const Brx& aClientSecret,
std::vector<OAuthAppDetails>& aAppDetails,
TUint aMaxAudioQuality,
Av::IMediaPlayer& aMediaPlayer)
{ // static;
const TBool hasOAuthDeets = aClientId.Bytes() > 0; //NOTE - secret is optional, depending on the OAuth flow used.
Expand All @@ -109,8 +108,7 @@ Protocol* ProtocolFactory::NewTidal(Environment& aEnv,
{
aClientId,
aClientSecret,
aAppDetails,
aMaxAudioQuality,
aAppDetails
};

return new ProtocolTidal(aEnv, aSsl, config, aMediaPlayer.ConfigInitialiser(), aMediaPlayer.Device(),
Expand Down
17 changes: 6 additions & 11 deletions OpenHome/Av/Tidal/Tidal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ using namespace OpenHome::Av;
using namespace OpenHome::Configuration;

static const TChar* kSoundQualities[4] = {"LOW", "HIGH", "LOSSLESS", "HI_RES"};
static const TUint kNumSoundQualities = sizeof(kSoundQualities) / sizeof(kSoundQualities[0]);


// Staging = XXXX.stage.tidal.com
const Brn Tidal::kHost("api.tidal.com");
Expand Down Expand Up @@ -137,17 +139,10 @@ Tidal::Tidal(Environment& aEnv,
choices.push_back(ENABLED_YES);
iConfigEnable = new ConfigChoice(aConfigInitialiser, kConfigKeyEnabled, choices, ENABLED_YES);

iMaxSoundQuality = std::min(static_cast<TUint>(3), aTidalConfig.maxSoundQualityOption);
Log::Print("TIDAL: MaxSoundQuality limited to: %u\n", iMaxSoundQuality);

std::vector<TUint> qualities;
qualities.reserve(4);
for(TUint i = 0; i <= iMaxSoundQuality; ++i) {
qualities.emplace_back(i);
}

const TUint defaultOption = qualities.back();
iConfigQuality = new ConfigChoice(aConfigInitialiser, kConfigKeySoundQuality, qualities, defaultOption);
const int arr[] = {0, 1, 2, 3};
std::vector<TUint> qualities(arr, arr + sizeof(arr)/sizeof(arr[0]));
iConfigQuality = new ConfigChoice(aConfigInitialiser, kConfigKeySoundQuality, qualities, 3);
iMaxSoundQuality = kNumSoundQualities - 1;
iSubscriberIdQuality = iConfigQuality->Subscribe(MakeFunctorConfigChoice(*this, &Tidal::QualityChanged));

iPollHandle = aThreadPool.CreateHandle(MakeFunctor(*this, &Tidal::DoPollForToken), "Tidal-POLL", ThreadPoolPriority::Low);
Expand Down
3 changes: 1 addition & 2 deletions OpenHome/Av/Tidal/Tidal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class Tidal : public IOAuthAuthenticator

struct ConfigurationValues
{
const Brx& clientId; // Used for OAuth authentication, directly by the DS
const Brx& clientId; //Used for OAuth authentication, directly by the DS
const Brx& clientSecret;
const std::vector<OAuthAppDetails> appDetails; // All other supported CPs
const TUint maxSoundQualityOption; // Used to set the max sound quality. See Tidal.cpp for details
};


Expand Down
2 changes: 1 addition & 1 deletion OpenHome/Media/Protocol/ProtocolFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ProtocolFactory
static Protocol* NewFile(Environment& aEnv);
static Protocol* NewTone(Environment& aEnv);
static Protocol* NewRtsp(Environment& aEnv, const Brx& aGuid);
static Protocol* NewTidal(Environment& aEnv, SslContext& aSsl, const Brx& aClientId, const Brx& aClientSecret, std::vector<OAuthAppDetails>& aAppDetails, TUint aMaxAudioQuality, Av::IMediaPlayer& aMediaPlayer);
static Protocol* NewTidal(Environment& aEnv, SslContext& aSsl, const Brx& aClientId, const Brx& aClientSecret, std::vector<OAuthAppDetails>& aAppDetails, Av::IMediaPlayer& aMediaPlayer);
static Protocol* NewQobuz(const Brx& aAppId, const Brx& aAppSecret, Av::IMediaPlayer& aMediaPlayer, const Brx& aUserAgent); // UA is optional so can be empty
static Protocol* NewCalmRadio(Environment& aEnv, SslContext& aSsl, const Brx& aUserAgent, Av::IMediaPlayer& aMediaPlayer); // UA is optional so can be empty
};
Expand Down

0 comments on commit 1b87ddc

Please sign in to comment.