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
12 changes: 6 additions & 6 deletions drm/DrmSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void DrmSessionManager::clearDrmSession(bool forceClearSession)
void DrmSessionManager::setVideoWindowSize(int width, int height)
{
auto localSession = mContentSecurityManagerSession; //Remove potential isSessionValid(), getSessionID() race by using a local copy
MW_LOG_WARN("In DrmSessionManager:: setting video window size w:%d x h:%d mMaxDRMSessions=%d sessionID=[%" PRId64 "]",width,height,mMaxDRMSessions,localSession.getSessionID());
MW_LOG_WARN("In DrmSessionManager:: setting video window size w:%d x h:%d mMaxDRMSessions=%d sessionID=[%s]",width,height,mMaxDRMSessions,localSession.getSessionID().c_str());
if(localSession.isSessionValid())
{
MW_LOG_WARN("In DrmSessionManager:: valid session ID. Calling setVideoWindowSize().");
Expand Down Expand Up @@ -274,7 +274,7 @@ void DrmSessionManager::setPlaybackSpeedState(bool live, double currentLatency,
{
bool isVideoOnMute=mIsVideoOnMute.load();
auto localSession = mContentSecurityManagerSession; //Remove potential isSessionValid(), getSessionID() race by using a local copy
MW_LOG_WARN("In DrmSessionManager::after calling setPlaybackSpeedState speed=%d position=%f sessionID=[%" PRId64 "], mute: %d",speed, positionMs, localSession.getSessionID(), isVideoOnMute);
MW_LOG_WARN("In DrmSessionManager::after calling setPlaybackSpeedState speed=%d position=%f sessionID=[%s], mute: %d",speed, positionMs, localSession.getSessionID().c_str(), isVideoOnMute);
mCurrentSpeed.store(speed);
if(firstFrameSeen)
{
Expand Down Expand Up @@ -312,7 +312,7 @@ void DrmSessionManager::setPlaybackSpeedState(bool live, double currentLatency,
{
bool firstFrameSeenCopy=mFirstFrameSeen.load();
isVideoOnMute=mIsVideoOnMute.load();
MW_LOG_INFO("Not calling ContentSecurityManager::setPlaybackSpeedState(), sessionID=[%" PRId64 "], mIsVideoOnMute=%d, firstFrameSeen=%d", localSession.getSessionID(), isVideoOnMute, firstFrameSeenCopy);
MW_LOG_INFO("Not calling ContentSecurityManager::setPlaybackSpeedState(), sessionID=[%s], mIsVideoOnMute=%d, firstFrameSeen=%d", localSession.getSessionID().c_str(), isVideoOnMute, firstFrameSeenCopy);
}
}

Expand Down Expand Up @@ -561,7 +561,7 @@ DrmSession* DrmSessionManager::createDrmSession(int &responseCode, int &err, std
const auto &localSession = mContentSecurityManagerSession; //Remove potential isSessionValid(), getSessionID() race by using a local copy
if (localSession.isSessionValid())
{
MW_LOG_WARN(" Setting sessionId[%" PRId64 "] to current drmSession", localSession.getSessionID());
MW_LOG_WARN(" Setting sessionId[%s] to current drmSession", localSession.getSessionID().c_str());
drmSessionContexts[selectedSlot].drmSession->setSecManagerSession(localSession);
}

Expand Down Expand Up @@ -851,7 +851,7 @@ KeyState DrmSessionManager::getDrmSession(int &err, std::shared_ptr<DrmHelper> d
// Set the drmSession's ID as mContentSecurityManagerSession so that this code will not be repeated for multiple calls for createDrmSession
mContentSecurityManagerSession = slotSession;
bool videoMuteState = mIsVideoOnMute.load();
MW_LOG_WARN("Activating re-used DRM, sessionId[%" PRId64 "], with video mute = %d", slotSession.getSessionID(), videoMuteState);
MW_LOG_WARN("Activating re-used DRM, sessionId[%s], with video mute = %d", slotSession.getSessionID().c_str(), videoMuteState);
ContentSecurityManager::GetInstance()->UpdateSessionState(slotSession.getSessionID(), true);
}
return KEY_READY;
Expand Down Expand Up @@ -972,7 +972,7 @@ void DrmSessionManager::notifyCleanup()
if(localSession.isSessionValid())
{
// Set current session to inactive
MW_LOG_WARN("De-activate DRM session [%" PRId64 "] and watermark", localSession.getSessionID() );
MW_LOG_WARN("De-activate DRM session [%s] and watermark", localSession.getSessionID().c_str());
ContentSecurityManager::GetInstance()->UpdateSessionState(localSession.getSessionID(), false);
// Reset the session ID, the session ID is preserved within DrmSession instances
mContentSecurityManagerSession.setSessionInvalid(); //note this doesn't necessarily close the session as the session ID is also saved in the slot
Expand Down
9 changes: 4 additions & 5 deletions externals/contentsecuritymanager/ContentSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bool ContentSecurityManager::AcquireLicense(std::string clientId, std::string ap
/**
* @brief To update session state to SecManager
*/
bool ContentSecurityManager::UpdateSessionState(int64_t sessionId, bool active)
bool ContentSecurityManager::UpdateSessionState(const std::string& sessionId, bool active)
{
bool success = false;
success = SetDrmSessionState(sessionId, active);
Expand All @@ -177,15 +177,15 @@ bool ContentSecurityManager::UpdateSessionState(int64_t sessionId, bool active)
/**
* @brief To notify SecManager to release a session
*/
void ContentSecurityManager::ReleaseSession(int64_t sessionId)
void ContentSecurityManager::ReleaseSession(const std::string& sessionId)
{
CloseDrmSession(sessionId);
}

/**
* @brief To update session state to SecManager
*/
bool ContentSecurityManager::setVideoWindowSize(int64_t sessionId, int64_t video_width, int64_t video_height)
bool ContentSecurityManager::setVideoWindowSize(const std::string& sessionId, int64_t video_width, int64_t video_height)
{
bool rpcResult = false;
rpcResult = setWindowSize(sessionId, video_width, video_height);
Expand All @@ -195,7 +195,7 @@ bool ContentSecurityManager::setVideoWindowSize(int64_t sessionId, int64_t video
/**
* @brief To set Playback Speed State to SecManager
*/
bool ContentSecurityManager::setPlaybackSpeedState(int64_t sessionId, int64_t playback_speed, int64_t playback_position)
bool ContentSecurityManager::setPlaybackSpeedState(const std::string& sessionId, int64_t playback_speed, int64_t playback_position)
{
bool rpcResult = false;
rpcResult = SetPlaybackPosition(sessionId, static_cast<float>(playback_speed), static_cast<int32_t>(playback_position));
Expand All @@ -218,4 +218,3 @@ std::function<void(uint32_t, uint32_t, const std::string&)>& ContentSecurityMana
{
return SendWatermarkSessionEvent_CB;
}

24 changes: 12 additions & 12 deletions externals/contentsecuritymanager/ContentSecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ContentSecurityManager : public PlayerScheduler
* @param[in] sessionId - session id
* @param[in] active - true if session is active, false otherwise
*/
virtual bool UpdateSessionState(int64_t sessionId, bool active);
virtual bool UpdateSessionState(const std::string& sessionId, bool active);

/**
* @fn setVideoWindowSize
Expand All @@ -115,22 +115,22 @@ class ContentSecurityManager : public PlayerScheduler
* @param[in] video_width - video width
* @param[in] video_height - video height
*/
virtual bool setVideoWindowSize(int64_t sessionId, int64_t video_width, int64_t video_height);
virtual bool setVideoWindowSize(const std::string& sessionId, int64_t video_width, int64_t video_height);
/**
* @fn setPlaybackSpeedState
*
* @param[in] sessionId - session id
* @param[in] playback_speed - playback speed
* @param[in] playback_position - playback position
*/
virtual bool setPlaybackSpeedState(int64_t sessionId, int64_t playback_speed, int64_t playback_position);
virtual bool setPlaybackSpeedState(const std::string& sessionId, int64_t playback_speed, int64_t playback_position);

/**
* @fn ReleaseSession - this should only be used by ContentSecurityManagerSession::SessionManager::~SessionManager();
*
* @param[in] sessionId - session id
*/
virtual void ReleaseSession(int64_t sessionId);
virtual void ReleaseSession(const std::string& sessionId);

/**
* @fn getSessionToken
Expand Down Expand Up @@ -185,29 +185,29 @@ class ContentSecurityManager : public PlayerScheduler
* @param active Whether the session should be marked active
* @return true on success, false otherwise
*/
virtual bool SetDrmSessionState(int64_t sessionId, bool active) { return false; }
virtual bool SetDrmSessionState(const std::string& sessionId, bool active) { return false; }
/**
* @brief Closes an existing DRM session
* @param sessionId DRM session ID
* @return true if closed successfully
*/
virtual void CloseDrmSession(int64_t sessionId) {}
virtual void CloseDrmSession(const std::string& sessionId) {}
/**
* @brief Sets playback state for watermark alignment
* @param sessionId Session ID
* @param speed Playback rate (1.0 = normal)
* @param position Current position in seconds
* @return true if command succeeded
*/
virtual bool SetPlaybackPosition(int64_t sessionId, float speed, int32_t position) { return false; }
virtual bool SetPlaybackPosition(const std::string& sessionId, float speed, int32_t position) { return false; }
/**
* @fn setWindowSize
*
* @param[in] sessionId - session id
* @param[in] video_width - video width
* @param[in] video_height - video height
*/
virtual bool setWindowSize(int64_t sessionId, int64_t video_width, int64_t video_height) { return false; };
virtual bool setWindowSize(const std::string& sessionId, int64_t video_width, int64_t video_height) { return false; };

/**
* @fn ContentSecurityManager
Expand Down Expand Up @@ -260,20 +260,20 @@ class FakeSecManager : public ContentSecurityManager
return false;
}

bool UpdateSessionState(int64_t sessionId, bool active) override
bool UpdateSessionState(const std::string& sessionId, bool active) override
{
return false;
}

bool setPlaybackSpeedState(int64_t sessionId, int64_t speed, int64_t position) override
bool setPlaybackSpeedState(const std::string& sessionId, int64_t speed, int64_t position) override
{
return false;
}
bool setVideoWindowSize(int64_t sessionId, int64_t video_width, int64_t video_height) override
bool setVideoWindowSize(const std::string& sessionId, int64_t video_width, int64_t video_height) override
{
return false;
}
void ReleaseSession(int64_t sessionId) override
void ReleaseSession(const std::string& sessionId) override
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@

#include "ContentSecurityManager.h"
#include "PlayerLogManager.h"
std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityManagerSession::SessionManager::getInstance(int64_t sessionID, std::size_t inputSummaryHash)
std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityManagerSession::SessionManager::getInstance(const std::string& sessionID, std::size_t inputSummaryHash)
{
std::shared_ptr<SessionManager> returnValue;

static std::mutex instancesMutex;
std::lock_guard<std::mutex> lock{instancesMutex};
static std::map<int64_t, std::weak_ptr<SessionManager>> instances;
static std::map<std::string, std::weak_ptr<SessionManager>> instances;

//Remove pointers to expired instances
{
std::vector<int64_t> keysToRemove;
std::vector<std::string> keysToRemove;
for (auto i : instances)
{
if(i.second.expired())
Expand All @@ -57,10 +57,8 @@ std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityMa
}
}

/* Only create or retrieve instances for valid sessionIDs.
* <0 is used as an invalid value e.g. CONTENT_SECURITY_MGR_INVALID_SESSION_ID
* 0 removes all sessions which is not the intended behaviour here*/
if(sessionID>0)
/* Only create or retrieve instances for non-empty session IDs. */
if(!sessionID.empty())
{
if(instances.count(sessionID)>0)
{
Expand All @@ -70,8 +68,8 @@ std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityMa
if(!returnValue)
{
//unexpected
MW_LOG_WARN("ContentSecurityManagerSession: session ID %" PRId64 " reused or session closed too early.",
sessionID);
MW_LOG_WARN("ContentSecurityManagerSession: session ID %s reused or session closed too early.",
sessionID.c_str());
}
}

Expand All @@ -80,7 +78,7 @@ std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityMa
if(returnValue->getInputSummaryHash()!=inputSummaryHash)
{
//this should only occur after a successful updatePlaybackSession
MW_LOG_MIL("ContentSecurityManagerSession: session ID %" PRId64 " input data changed.", sessionID);
MW_LOG_MIL("ContentSecurityManagerSession: session ID %s input data changed.", sessionID.c_str());
returnValue->setInputSummaryHash(inputSummaryHash);
}
}
Expand All @@ -90,22 +88,22 @@ std::shared_ptr<ContentSecurityManagerSession::SessionManager> ContentSecurityMa
* create a new instance & save a pointer to it for possible future reuse*/
returnValue.reset(new SessionManager{sessionID, inputSummaryHash});
instances[sessionID] = returnValue;
MW_LOG_WARN("ContentSecurityManagerSession: new instance created for ID:%" PRId64 ", %zu instances total.",
sessionID,
MW_LOG_WARN("ContentSecurityManagerSession: new instance created for ID:%s, %zu instances total.",
sessionID.c_str(),
instances.size());
}
}
else
{
MW_LOG_WARN("ContentSecurityManagerSession: invalid ID:%" PRId64 ".", sessionID);
MW_LOG_WARN("ContentSecurityManagerSession: invalid ID:%s.", sessionID.c_str());
}

return returnValue;
}

ContentSecurityManagerSession::SessionManager::~SessionManager()
{
if(mID>0)
if(!mID.empty())
{
ContentSecurityManager::GetInstance()->ReleaseSession(mID);
}
Expand All @@ -119,20 +117,20 @@ void ContentSecurityManagerSession::SessionManager::setInputSummaryHash(std::siz
}


ContentSecurityManagerSession::SessionManager::SessionManager(int64_t sessionID, std::size_t inputSummaryHash):
ContentSecurityManagerSession::SessionManager::SessionManager(const std::string& sessionID, std::size_t inputSummaryHash):
mID(sessionID),
mInputSummaryHash(inputSummaryHash)
{};

ContentSecurityManagerSession::ContentSecurityManagerSession(int64_t sessionID, std::size_t inputSummaryHash):
ContentSecurityManagerSession::ContentSecurityManagerSession(const std::string& sessionID, std::size_t inputSummaryHash):
mpSessionManager(ContentSecurityManagerSession::SessionManager::getInstance(sessionID, inputSummaryHash)),
sessionIdMutex()
{};

int64_t ContentSecurityManagerSession::getSessionID(void) const
std::string ContentSecurityManagerSession::getSessionID(void) const
{
std::lock_guard<std::mutex>lock(sessionIdMutex);
int64_t ID = CONTENT_SECURITY_MGR_INVALID_SESSION_ID;
std::string ID = CONTENT_SECURITY_MGR_INVALID_SESSION_ID;
if(mpSessionManager)
{
ID = mpSessionManager->getID();
Expand All @@ -152,4 +150,3 @@ std::size_t ContentSecurityManagerSession::getInputSummaryHash()

return hash;
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#include <atomic>
#include <memory>
#include <sstream>
#include <string>

#define CONTENT_SECURITY_MGR_INVALID_SESSION_ID (-1)
#define CONTENT_SECURITY_MGR_INVALID_SESSION_ID ""

class ContentSecurityManager;

Expand All @@ -52,19 +53,19 @@ class ContentSecurityManagerSession
class SessionManager
{
private:
int64_t mID; //set once undermutex in constructor
std::string mID; //set once under mutex in constructor
std::atomic<std::size_t> mInputSummaryHash; //can be changed by setInputSummaryHash
SessionManager(int64_t sessionID, std::size_t inputSummaryHash);
SessionManager(const std::string& sessionID, std::size_t inputSummaryHash);

public:
/**
* @fn getInstance
* @brief
* Get a shared pointer to an object corresponding to the sessionID, creating a new one if required
*/
static std::shared_ptr<ContentSecurityManagerSession::SessionManager> getInstance(int64_t sessionID, std::size_t inputSummaryHash);
static std::shared_ptr<ContentSecurityManagerSession::SessionManager> getInstance(const std::string& sessionID, std::size_t inputSummaryHash);

int64_t getID(){return mID;}
const std::string& getID(){return mID;}
std::size_t getInputSummaryHash(){return mInputSummaryHash.load();}
void setInputSummaryHash(std::size_t inputSummaryHash);

Expand All @@ -83,7 +84,7 @@ class ContentSecurityManagerSession
* this is only intended to be used in ContentSecurityManager::acquireLicence()
* it is the responsibility of ContentSecurityManager::acquireLicence() to ensure sessionID is valid
*/
ContentSecurityManagerSession(int64_t sessionID, std::size_t inputSummaryHash);
ContentSecurityManagerSession(const std::string& sessionID, std::size_t inputSummaryHash);

/**
* @brief constructor for an invalid object*/
Expand Down Expand Up @@ -116,7 +117,7 @@ class ContentSecurityManagerSession
* the ContentSecurityManagerSession on which this method is called
* otherwise the session may be closed before the ID can be used
*/
int64_t getSessionID(void) const;
std::string getSessionID(void) const;
std::size_t getInputSummaryHash();

bool isSessionValid(void) const
Expand Down
Loading
Loading