Skip to content

Commit

Permalink
TIDAL: Allow specifying the default sound quality as a ctr parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
projectgoav committed Dec 12, 2023
1 parent 3e5823f commit 7d33a1d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
5 changes: 3 additions & 2 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 aOdpPort, TUint aWebUiPort,
const TChar* aStoreFile, TUint aDefaultTidalAudioQuality, TUint aOdpPort, TUint aWebUiPort,
TUint aMinWebUiResourceThreads, TUint aMaxWebUiTabs, TUint aUiSendQueueSize,
TUint aUiMsgBufCount, TUint aUiMsgBufBytes)
: iPullableClock(nullptr)
Expand All @@ -184,6 +184,7 @@ TestMediaPlayer::TestMediaPlayer(Net::DvStack& aDvStack, Net::CpStack& aCpStack,
, iUiSendQueueSize(aUiSendQueueSize)
, iUiMsgBufCount(aUiMsgBufCount)
, iUiMsgBufBytes(aUiMsgBufBytes)
, iDefaultTidalAudioQuality(aDefaultTidalAudioQuality)
{
Log::Print("Shell running on port %u\n", aDvStack.Env().Shell()->Port());
iInfoLogger = new Media::AllocatorInfoLogger();
Expand Down Expand Up @@ -498,7 +499,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, *iMediaPlayer));
iMediaPlayer->Add(ProtocolFactory::NewTidal(aEnv, ssl, clientId, clientSecret, apps, iDefaultTidalAudioQuality, *iMediaPlayer));
}
// ...likewise, only add Qobuz if we have ids for login
if (iQobuzIdSecret.Bytes() > 0) {
Expand Down
6 changes: 5 additions & 1 deletion OpenHome/Av/Tests/TestMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ 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 kDefaultTidalAudioQuality = 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 aOdpPort=0, TUint aWebUiPort=0,
const TChar* aStoreFile, TUint aDefaultTidalAudioQuality = kDefaultTidalAudioQuality, 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 @@ -216,6 +217,7 @@ class TestMediaPlayer : private Net::IResourceManager, public IPowerHandler/*, p
TUint iUiSendQueueSize;
TUint iUiMsgBufCount;
TUint iUiMsgBufBytes;
const TUint iDefaultTidalAudioQuality;
};

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

// Not very nice, but only to allow reusable test functions.
Expand Down
10 changes: 10 additions & 0 deletions OpenHome/Av/Tests/TestMediaPlayerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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 @@ -23,6 +27,7 @@ TestMediaPlayerOptions::TestMediaPlayerOptions()
, iOptionOdp("", "--odp", 0, "Port for ODP server")
, iOptionWebUi("", "--webui", 0, "Port for Web UI server")
, iOptionShell("", "--shell", 0, "Port for shell")
, iOptionTidalDefaultAudioQuality("", "--tidalDefaultAudioQuality", kDefaultTidalMaxAudioQuality, "Default audio quality for TIDAL streaming. 0 = LOSSY ... 3 = HI_RES")
{
iParser.AddOption(&iOptionRoom);
iParser.AddOption(&iOptionName);
Expand Down Expand Up @@ -125,3 +130,8 @@ const OptionUint& TestMediaPlayerOptions::Shell() const
{
return iOptionShell;
}

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

return new ProtocolTidal(aEnv, aSsl, config, aMediaPlayer.ConfigInitialiser(), aMediaPlayer.Device(),
Expand Down
5 changes: 4 additions & 1 deletion OpenHome/Av/Tidal/Tidal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ Tidal::Tidal(Environment& aEnv,

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;
const TUint defaultOption = std::min(iMaxSoundQuality, aTidalConfig.defaultSoundQualityOption);

iConfigQuality = new ConfigChoice(aConfigInitialiser, kConfigKeySoundQuality, qualities, defaultOption);
iSubscriberIdQuality = iConfigQuality->Subscribe(MakeFunctorConfigChoice(*this, &Tidal::QualityChanged));

iPollHandle = aThreadPool.CreateHandle(MakeFunctor(*this, &Tidal::DoPollForToken), "Tidal-POLL", ThreadPoolPriority::Low);
Expand Down
3 changes: 2 additions & 1 deletion OpenHome/Av/Tidal/Tidal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ 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 defaultSoundQualityOption; // Used to set the default 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, Av::IMediaPlayer& aMediaPlayer);
static Protocol* NewTidal(Environment& aEnv, SslContext& aSsl, const Brx& aClientId, const Brx& aClientSecret, std::vector<OAuthAppDetails>& aAppDetails, TUint aDefaultAudioQuality, 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 7d33a1d

Please sign in to comment.