Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions media/server/main/include/MediaKeySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class MediaKeySession : public IMediaKeySession, public firebolt::rialto::wrappe
*/
std::vector<uint8_t> m_selectedKeyId;

/**
* @brief Whether initData contains amazon string
*/
bool m_isAmazonApp;

/**
* @brief Whether a Ocdm call is currently ongoing.
*/
Expand All @@ -187,6 +192,11 @@ class MediaKeySession : public IMediaKeySession, public firebolt::rialto::wrappe
*/
std::mutex m_ocdmErrorMutex;

/**
* @brief Drm header to be set once the session is constructed
*/
std::vector<uint8_t> m_queuedDrmHeader;

/**
* @brief Posts a getChallenge task onto the main thread.
*
Expand All @@ -207,6 +217,15 @@ class MediaKeySession : public IMediaKeySession, public firebolt::rialto::wrappe
* @retval True if an error was received.
*/
bool checkForOcdmErrors(const char *operationStr);

/**
* @brief Checks if data contains amazon string in UTF-8 or UTF-16 encoding.
*
* @param[in] data : The data to check.
*
* @retval True if amazon string is found.
*/
bool isAmazonApp(const std::vector<uint8_t> &data);
};
} // namespace firebolt::rialto::server

Expand Down
48 changes: 44 additions & 4 deletions media/server/main/source/MediaKeySession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MediaKeySession::MediaKeySession(const std::string &keySystem, int32_t keySessio
const std::shared_ptr<IMainThreadFactory> &mainThreadFactory)
: m_kKeySystem(keySystem), m_kKeySessionId(keySessionId), m_kSessionType(sessionType), m_mediaKeysClient(client),
m_kIsLDL(isLDL), m_isSessionConstructed(false), m_isSessionClosed(false), m_licenseRequested(false),
m_ongoingOcdmOperation(false), m_ocdmError(false)
m_isAmazonApp(false), m_ongoingOcdmOperation(false), m_ocdmError(false)
{
RIALTO_SERVER_LOG_DEBUG("entry:");

Expand Down Expand Up @@ -109,6 +109,10 @@ MediaKeySession::~MediaKeySession()
MediaKeyErrorStatus MediaKeySession::generateRequest(InitDataType initDataType, const std::vector<uint8_t> &initData)
{
RIALTO_SERVER_LOG_DEBUG("entry:");

// Check if initData contains amazon string
m_isAmazonApp = isAmazonApp(initData);

// Set the request flag for the onLicenseRequest callback
m_licenseRequested = true;

Expand All @@ -127,7 +131,15 @@ MediaKeyErrorStatus MediaKeySession::generateRequest(InitDataType initDataType,
else
{
m_isSessionConstructed = true;
if (isNetflixPlayreadyKeySystem())

if (!m_queuedDrmHeader.empty())
{
RIALTO_SERVER_LOG_DEBUG("Setting queued drm header after session construction");
setDrmHeader(m_queuedDrmHeader);
m_queuedDrmHeader.clear();
}

if (isNetflixPlayreadyKeySystem() || m_isAmazonApp)
{
// Ocdm-playready does not notify onProcessChallenge when complete.
// Fetch the challenge manually.
Expand Down Expand Up @@ -195,7 +207,7 @@ MediaKeyErrorStatus MediaKeySession::updateSession(const std::vector<uint8_t> &r
initOcdmErrorChecking();

MediaKeyErrorStatus status;
if (isNetflixPlayreadyKeySystem())
if (isNetflixPlayreadyKeySystem() || m_isAmazonApp)
{
status = m_ocdmSession->storeLicenseData(&responseData[0], responseData.size());
if (MediaKeyErrorStatus::OK != status)
Expand Down Expand Up @@ -243,7 +255,7 @@ MediaKeyErrorStatus MediaKeySession::closeKeySession()
initOcdmErrorChecking();

MediaKeyErrorStatus status;
if (isNetflixPlayreadyKeySystem())
if (isNetflixPlayreadyKeySystem() || m_isAmazonApp)
{
if (MediaKeyErrorStatus::OK != m_ocdmSession->cancelChallengeData())
{
Expand Down Expand Up @@ -322,6 +334,13 @@ MediaKeyErrorStatus MediaKeySession::setDrmHeader(const std::vector<uint8_t> &re
{
initOcdmErrorChecking();

if (!m_isSessionConstructed)
{
RIALTO_SERVER_LOG_INFO("Session not yet constructed, queueing drm header to be set after construction");
m_queuedDrmHeader = requestData;
return MediaKeyErrorStatus::OK;
}

MediaKeyErrorStatus status = m_ocdmSession->setDrmHeader(requestData.data(), requestData.size());
if (MediaKeyErrorStatus::OK != status)
{
Expand Down Expand Up @@ -472,4 +491,25 @@ bool MediaKeySession::checkForOcdmErrors(const char *operationStr)
return error;
}

bool MediaKeySession::isAmazonApp(const std::vector<uint8_t> &data)
{
// Check for UTF-8 encoding
std::string dataUtf8(data.begin(), data.end());
if (dataUtf8.find("amazon") != std::string::npos)
{
return true;
}

// Check for UTF-16 LE encoding
if (data.size() > 4)
{
std::string dataUtf16(data.begin(), data.end());
if (dataUtf16.find("a\0m\0a\0z\0o\0n", 0, 12) != std::string::npos)
{
return true;
}
}

return false;
}
}; // namespace firebolt::rialto::server
Loading