Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ bool SESSION::CSession::PrepareStream(CStream& stream)
if (!drmSession)
return false;

isDrmSecure = drmSession->capabilities.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH;
isDrmSecure = drmSession->capabilities.HasFlag(DRM::Capabilities::SECURE_PATH);

reader->SetDecrypter(drmSession);
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/AdaptiveDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Adaptive_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
DRM::Capabilities caps,
CryptoInfo cryptoInfo) = 0;

virtual AP4_Result DecryptSampleData(AP4_UI32 poolId,
Expand Down
18 changes: 9 additions & 9 deletions src/decrypters/DrmEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ bool GetCapabilities(const std::optional<bool> isForceSecureDecoder,
auto& caps = session.capabilities;
session.drm->GetCapabilities(session.decrypter, defaultKid, caps, session.mediaType);

if (caps.flags & DRM::DecrypterCapabilites::SSD_INVALID)
if (caps.flags & DRM::Capabilities::INVALID_STATUS)
{
return false;
}
else if (caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH)
else if (caps.flags & DRM::Capabilities::SECURE_PATH)
{
// Allow to disable the secure decoder
bool disableSecureDecoder = CSrvBroker::GetSettings().IsDisableSecureDecoder();
Expand All @@ -99,7 +99,7 @@ bool GetCapabilities(const std::optional<bool> isForceSecureDecoder,
if (disableSecureDecoder)
{
LOG::Log(LOGDEBUG, "DRM configured with secure decoder disabled");
caps.flags &= ~DRM::DecrypterCapabilites::SSD_SECURE_DECODER;
caps.flags &= ~DRM::Capabilities::SECURE_DECODER;
}
}

Expand Down Expand Up @@ -632,7 +632,7 @@ const std::shared_ptr<DRMSession> DRM::CDRMEngine::InitializeSession(
//! since audio streams that require Secure path decoder cannot be played
//! we have no way to distinguish which ones they are other than to do a KID test with the DRM
if (!session->drm->IsSecureDecoderAudioSupported() && session->mediaType == DRMMediaType::AUDIO &&
caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH)
caps.flags & DRM::Capabilities::SECURE_PATH)
{
LOG::Log(LOGWARNING, "Secure decoder on audio stream is not supported");
m_status = EngineStatus::NOT_SUPPORTED;
Expand All @@ -644,11 +644,11 @@ const std::shared_ptr<DRMSession> DRM::CDRMEngine::InitializeSession(

cryptoSession.SetSessionId(session->id);
// Set the key system will enable the crypto session to kodi decoders (e.g. ffmpeg)
if (caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH)
if (caps.flags & DRM::Capabilities::SECURE_PATH)
cryptoSession.SetKeySystem(KSToCryptoKeySystem(m_keySystem));

if (caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH &&
caps.flags & DRM::DecrypterCapabilites::SSD_SUPPORTS_DECODING)
if (caps.flags & DRM::Capabilities::SECURE_PATH &&
caps.flags & DRM::Capabilities::SUPPORTS_DECODING)
{
LOG::Log(LOGDEBUG, "Secure crypto session enabled to DRM session (ID: %s)",
session->id.c_str());
Expand All @@ -657,8 +657,8 @@ const std::shared_ptr<DRMSession> DRM::CDRMEngine::InitializeSession(
else
streamInfo.SetFeatures(INPUTSTREAM_FEATURE_NONE);

if (caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_PATH &&
caps.flags & DRM::DecrypterCapabilites::SSD_SECURE_DECODER)
if (caps.flags & DRM::Capabilities::SECURE_PATH &&
caps.flags & DRM::Capabilities::SECURE_DECODER)
{
// Enable the ISA VideoCodecAdaptive decoder
LOG::Log(LOGDEBUG, "Secure crypto decoder enabled to DRM session (ID: %s)",
Expand Down
20 changes: 11 additions & 9 deletions src/decrypters/DrmEngineDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ namespace DRM
constexpr uint16_t HDCP_V_NONE = 0;
constexpr uint16_t HDCP_V_MAX = 9999;

struct DecrypterCapabilites
// \brief Decrypter capabilities
struct Capabilities
{
static const uint32_t SSD_SUPPORTS_DECODING = 1;
static const uint32_t SSD_SECURE_PATH = 2;
static const uint32_t SSD_ANNEXB_REQUIRED = 4;
static const uint32_t SSD_HDCP_RESTRICTED = 8;
static const uint32_t SSD_SINGLE_DECRYPT = 16;
static const uint32_t SSD_SECURE_DECODER = 32;
static const uint32_t SSD_INVALID = 64;
static const uint32_t SUPPORTS_DECODING = 1;
static const uint32_t SECURE_PATH = 2;
static const uint32_t ANNEXB_REQUIRED = 4;
static const uint32_t HDCP_RESTRICTED = 8;
static const uint32_t SINGLE_DECRYPT = 16;
static const uint32_t SECURE_DECODER = 32;
static const uint32_t INVALID_STATUS = 64;

uint16_t flags{0};
bool HasFlag(uint32_t cap) const { return (flags & cap) != 0; }

/* The following 2 fields are set as followed:
- If licenseresponse return hdcp information, hdcpversion is 0 and
Expand Down Expand Up @@ -145,7 +147,7 @@ struct DRMSession
std::string id; // DRM session ID
std::shared_ptr<DRM::IDecrypter> drm; // DRM instance
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter; // DRM Decrypter instance
DRM::DecrypterCapabilites capabilities;
DRM::Capabilities capabilities;
std::string kid;
std::string challenge; // Key request (Challenge) as base64
DRMMediaType mediaType{DRMMediaType::UNKNOWN};
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/IDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class IDecrypter : public IDecrypterDecoder
*/
virtual void GetCapabilities(std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter,
const std::vector<uint8_t>& keyId,
DecrypterCapabilites& caps,
Capabilities& caps,
DRMMediaType mediaType) = 0;

/*
Expand Down
13 changes: 7 additions & 6 deletions src/decrypters/clearkey/ClearKeyCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ void CClearKeyCencSingleSampleDecrypter::RemovePool(AP4_UI32 poolId)
m_pool.erase(poolId);
}

AP4_Result CClearKeyCencSingleSampleDecrypter::SetFragmentInfo(AP4_UI32 poolId,
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
CryptoInfo cryptoInfo)
AP4_Result CClearKeyCencSingleSampleDecrypter::SetFragmentInfo(
AP4_UI32 poolId,
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
DRM::Capabilities flags,
CryptoInfo cryptoInfo)
{
if (!STRING::KeyExists(m_pool, poolId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CClearKeyCencSingleSampleDecrypter : public Adaptive_CencSingleSampleDecry
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
DRM::Capabilities flags,
CryptoInfo cryptoInfo) override;
virtual AP4_Result DecryptSampleData(AP4_UI32 poolId,
AP4_DataBuffer& dataIn,
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/clearkey/ClearKeyDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CClearKeyDecrypter : public IDecrypter

virtual void GetCapabilities(std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter,
const std::vector<uint8_t>& keyid,
DRM::DecrypterCapabilites& caps,
DRM::Capabilities& caps,
DRMMediaType mediaType) override
{
}
Expand Down
38 changes: 16 additions & 22 deletions src/decrypters/widevine/WVCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,41 +149,39 @@ SResult CWVCencSingleSampleDecrypter::CreateSession(const std::vector<uint8_t>&
}

void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& keyId,
DecrypterCapabilites& caps,
Capabilities& caps,
DRMMediaType mediaType)
{
caps = {0, m_hdcpVersion, m_hdcpLimit};

if (m_strSession.empty())
{
LOG::LogF(LOGDEBUG, "Session empty");
caps.flags = DecrypterCapabilites::SSD_INVALID;
caps.flags = Capabilities::INVALID_STATUS;
return;
}

caps.flags = DecrypterCapabilites::SSD_SUPPORTS_DECODING;
caps.flags = Capabilities::SUPPORTS_DECODING;

if (m_keys.empty())
{
LOG::LogF(LOGDEBUG, "Keys empty");
caps.flags = DecrypterCapabilites::SSD_INVALID;
caps.flags = Capabilities::INVALID_STATUS;
return;
}

if (!caps.hdcpLimit)
caps.hdcpLimit = m_resolutionLimit;

#ifdef TARGET_WEBOS
LOG::LogF(LOGDEBUG,
"Overriding settings to: SSD_SECURE PATH | SSD_ANNEXB_REQUIRED | SSD_SECURE_DECODER");
caps = {DRM::DecrypterCapabilites::SSD_SECURE_PATH |
DRM::DecrypterCapabilites::SSD_ANNEXB_REQUIRED,
DRM::DecrypterCapabilites::SSD_SECURE_DECODER};
LOG::LogF(LOGDEBUG, "Overriding settings to: SECURE_PATH | ANNEXB_REQUIRED | SECURE_DECODER");
caps = {DRM::Capabilities::SECURE_PATH | DRM::Capabilities::ANNEXB_REQUIRED,
DRM::Capabilities::SECURE_DECODER};
caps.hdcpVersion = DRM::HDCP_V_MAX;
return;
#endif

if ((caps.flags & DecrypterCapabilites::SSD_SUPPORTS_DECODING) != 0)
if (caps.HasFlag(Capabilities::SUPPORTS_DECODING))
{
AP4_UI32 poolId(AddPool());
m_fragmentPool[poolId].m_key = keyId.empty() ? m_keys.front().kid : keyId;
Expand Down Expand Up @@ -211,13 +209,12 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
AP4_SUCCESS)
{
LOG::LogF(LOGDEBUG, "Single decrypt failed, secure path only");
caps.flags |=
(DecrypterCapabilites::SSD_SECURE_PATH | DecrypterCapabilites::SSD_ANNEXB_REQUIRED);
caps.flags |= (Capabilities::SECURE_PATH | Capabilities::ANNEXB_REQUIRED);
}
else
{
LOG::LogF(LOGDEBUG, "Single decrypt possible");
caps.flags |= DecrypterCapabilites::SSD_SINGLE_DECRYPT;
caps.flags |= Capabilities::SINGLE_DECRYPT;
caps.hdcpVersion = DRM::HDCP_V_MAX;
caps.hdcpLimit = m_resolutionLimit;
}
Expand All @@ -227,15 +224,14 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
catch (const std::exception& e)
{
LOG::LogF(LOGDEBUG, "Decrypt error, assuming secure path: %s", e.what());
caps.flags |= (DecrypterCapabilites::SSD_SECURE_PATH |
DecrypterCapabilites::SSD_ANNEXB_REQUIRED);
caps.flags |= (Capabilities::SECURE_PATH | Capabilities::ANNEXB_REQUIRED);
}
RemovePool(poolId);
}
else
{
LOG::LogF(LOGDEBUG, "Decoding not supported");
caps.flags = DecrypterCapabilites::SSD_INVALID;
caps.flags = Capabilities::INVALID_STATUS;
}
}

Expand Down Expand Up @@ -458,7 +454,7 @@ AP4_Result CWVCencSingleSampleDecrypter::SetFragmentInfo(AP4_UI32 poolId,
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
DRM::Capabilities caps,
CryptoInfo cryptoInfo)
{
if (poolId >= m_fragmentPool.size())
Expand All @@ -467,7 +463,7 @@ AP4_Result CWVCencSingleSampleDecrypter::SetFragmentInfo(AP4_UI32 poolId,
m_fragmentPool[poolId].m_key = keyId;
m_fragmentPool[poolId].m_nalLengthSize = nalLengthSize;
m_fragmentPool[poolId].m_annexbSpsPps = annexbSpsPps;
m_fragmentPool[poolId].m_decrypterFlags = flags;
m_fragmentPool[poolId].capabilities = caps;
m_fragmentPool[poolId].m_cryptoInfo = cryptoInfo;

return AP4_SUCCESS;
Expand Down Expand Up @@ -581,8 +577,7 @@ AP4_Result CWVCencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 poolId,

FINFO& fragInfo(m_fragmentPool[poolId]);

if (fragInfo.m_decrypterFlags &
DecrypterCapabilites::SSD_SECURE_PATH) //we can not decrypt only
if (fragInfo.capabilities.HasFlag(Capabilities::SECURE_PATH)) //we can not decrypt only
{
if (fragInfo.m_nalLengthSize > 4)
{
Expand All @@ -592,8 +587,7 @@ AP4_Result CWVCencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 poolId,

AP4_DataBuffer payload;
std::vector<cdm::SubsampleEntry> rebuiltSubs;
bool convertAnnexB =
(fragInfo.m_decrypterFlags & DecrypterCapabilites::SSD_ANNEXB_REQUIRED) != 0;
const bool convertAnnexB = fragInfo.capabilities.HasFlag(Capabilities::ANNEXB_REQUIRED);

// Convert only when safe to look at clear_bytes[0]
if (fragInfo.m_nalLengthSize && (!iv || (subsampleCount > 0 && bytesOfCleartextData[0] > 0)))
Expand Down
6 changes: 3 additions & 3 deletions src/decrypters/widevine/WVCencSingleSampleDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
bool skipSessionMessage) override;

void GetCapabilities(const std::vector<uint8_t>& keyId,
DecrypterCapabilites& caps,
Capabilities& caps,
DRMMediaType mediaType);
virtual std::string GetSessionId() override;
void CloseSessionId();
Expand All @@ -53,7 +53,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
DRM::Capabilities caps,
CryptoInfo cryptoInfo) override;
virtual AP4_UI32 AddPool() override;
virtual void RemovePool(AP4_UI32 poolId) override;
Expand Down Expand Up @@ -113,7 +113,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
{
std::vector<uint8_t> m_key;
AP4_UI08 m_nalLengthSize;
AP4_UI16 m_decrypterFlags;
DRM::Capabilities capabilities;
std::vector<uint8_t> m_annexbSpsPps;
CryptoInfo m_cryptoInfo;
};
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/widevine/WVDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypter::CreateSingleSa

void CWVDecrypter::GetCapabilities(std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter,
const std::vector<uint8_t>& keyId,
DRM::DecrypterCapabilites& caps,
DRM::Capabilities& caps,
DRMMediaType mediaType)
{
if (!decrypter)
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/widevine/WVDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ATTR_DLL_LOCAL CWVDecrypter : public DRM::IDecrypter

virtual void GetCapabilities(std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter,
const std::vector<uint8_t>& keyId,
DRM::DecrypterCapabilites& caps,
DRM::Capabilities& caps,
DRM::DRMMediaType mediaType) override;
virtual std::optional<bool> HasLicenseKey(
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> decrypter,
Expand Down
15 changes: 7 additions & 8 deletions src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ bool CWVCencSingleSampleDecrypterA::HasKeyId(const std::vector<uint8_t>& keyid)
}

void CWVCencSingleSampleDecrypterA::GetCapabilities(const std::vector<uint8_t>& keyId,
DRM::DecrypterCapabilites& caps)
DRM::Capabilities& caps)
{
caps = {DRM::DecrypterCapabilites::SSD_SECURE_PATH |
DRM::DecrypterCapabilites::SSD_ANNEXB_REQUIRED,
m_hdcpVersion, m_hdcpLimit};
caps = {DRM::Capabilities::SECURE_PATH | DRM::Capabilities::ANNEXB_REQUIRED, m_hdcpVersion,
m_hdcpLimit};

if (caps.hdcpLimit == 0)
caps.hdcpLimit = m_resolutionLimit;
Expand All @@ -217,7 +216,7 @@ void CWVCencSingleSampleDecrypterA::GetCapabilities(const std::vector<uint8_t>&
if (m_cdmAdapter->GetCDM()->getPropertyString("securityLevel") == "L1")
{
caps.hdcpLimit = m_resolutionLimit; //No restriction
caps.flags |= DRM::DecrypterCapabilites::SSD_SECURE_DECODER;
caps.flags |= DRM::Capabilities::SECURE_DECODER;
}
LOG::LogF(LOGDEBUG, "hdcpLimit: %i", caps.hdcpLimit);
}
Expand Down Expand Up @@ -526,7 +525,7 @@ AP4_Result CWVCencSingleSampleDecrypterA::SetFragmentInfo(AP4_UI32 poolId,
const std::vector<uint8_t>& keyId,
const AP4_UI08 nalLengthSize,
const std::vector<uint8_t>& annexbSpsPps,
AP4_UI32 flags,
DRM::Capabilities caps,
CryptoInfo cryptoInfo)
{
if (poolId >= m_fragmentPool.size())
Expand All @@ -535,7 +534,7 @@ AP4_Result CWVCencSingleSampleDecrypterA::SetFragmentInfo(AP4_UI32 poolId,
m_fragmentPool[poolId].m_key = keyId;
m_fragmentPool[poolId].m_nalLengthSize = nalLengthSize;
m_fragmentPool[poolId].m_annexbSpsPps = annexbSpsPps;
m_fragmentPool[poolId].m_decrypterFlags = flags;
m_fragmentPool[poolId].capabilities = caps;

if (m_isKeyUpdateRequested)
KeyUpdateRequest(false, false);
Expand Down Expand Up @@ -585,7 +584,7 @@ AP4_Result CWVCencSingleSampleDecrypterA::DecryptSampleData(AP4_UI32 poolId,

AP4_DataBuffer payload;
std::vector<SubsampleEntry> rebuiltSubs;
bool convertAnnexB = (fragInfo.m_decrypterFlags & DRM::DecrypterCapabilites::SSD_ANNEXB_REQUIRED) != 0;
const bool convertAnnexB = fragInfo.capabilities.HasFlag(DRM::Capabilities::ANNEXB_REQUIRED);

// Convert only when safe to look at clear_bytes[0]
if (fragInfo.m_nalLengthSize && (!iv || (subsampleCount > 0 && bytesOfCleartextData[0] > 0)))
Expand Down
Loading
Loading