Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Decrypters][cleanups] Const init data, session id as string #1695

Merged
merged 2 commits into from
Oct 15, 2024
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
16 changes: 8 additions & 8 deletions src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void SESSION::CSession::DisposeSampleDecrypter()
{
for (auto& cdmSession : m_cdmSessions)
{
cdmSession.m_cdmSessionStr = nullptr;
cdmSession.m_sessionId.clear();
cdmSession.m_cencSingleSampleDecrypter = nullptr;
}
}
Expand Down Expand Up @@ -293,8 +293,8 @@ bool SESSION::CSession::PreInitializeDRM(std::string& challengeB64,
m_decrypter->CreateSingleSampleDecrypter(initData, decKid, "", true,
CryptoMode::AES_CTR)) != nullptr)
{
session.m_cdmSessionStr = session.m_cencSingleSampleDecrypter->GetSessionId();
sessionId = session.m_cdmSessionStr;
session.m_sessionId = session.m_cencSingleSampleDecrypter->GetSessionId();
sessionId = session.m_sessionId;
challengeB64 = m_decrypter->GetChallengeB64Data(session.m_cencSingleSampleDecrypter);
}
else
Expand Down Expand Up @@ -466,7 +466,7 @@ bool SESSION::CSession::InitializeDRM(bool addDefaultKID /* = false */)
m_decrypter->GetCapabilities(session.m_cencSingleSampleDecrypter, defaultKid,
sessionPsshset.media_, session.m_decrypterCaps);

session.m_cdmSessionStr = session.m_cencSingleSampleDecrypter->GetSessionId();
session.m_sessionId = session.m_cencSingleSampleDecrypter->GetSessionId();

if (session.m_decrypterCaps.flags & DRM::DecrypterCapabilites::SSD_INVALID)
{
Expand Down Expand Up @@ -927,14 +927,14 @@ bool SESSION::CSession::IsCDMSessionSecurePath(size_t index)
DRM::DecrypterCapabilites::SSD_SECURE_PATH) != 0;
}

const char* SESSION::CSession::GetCDMSession(unsigned int index)
std::string SESSION::CSession::GetCDMSession(unsigned int index)
{
if (index >= m_cdmSessions.size())
{
LOG::LogF(LOGERROR, "No CDM session at index %u", index);
return nullptr;
return {};
}
return m_cdmSessions[index].m_cdmSessionStr;
return m_cdmSessions[index].m_sessionId;
}

uint64_t SESSION::CSession::PTSToElapsed(uint64_t pts)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> SESSION::CSession::GetSingle
for (std::vector<CCdmSession>::iterator b(m_cdmSessions.begin() + 1), e(m_cdmSessions.end());
b != e; ++b)
{
if (b->m_cdmSessionStr && sessionId == b->m_cdmSessionStr)
if (sessionId == b->m_sessionId)
return b->m_cencSingleSampleDecrypter;
}
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
* \param index The index (psshSet number) of the cdm session
* \return The session string
*/
const char* GetCDMSession(unsigned int index);
std::string GetCDMSession(unsigned int index);

/*! \brief Get the media type mask
* \return The media type mask
Expand Down Expand Up @@ -353,7 +353,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
{
DRM::DecrypterCapabilites m_decrypterCaps;
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> m_cencSingleSampleDecrypter;
const char* m_cdmSessionStr{nullptr};
std::string m_sessionId;
};
std::vector<CCdmSession> m_cdmSessions;

Expand Down
3 changes: 2 additions & 1 deletion src/common/AdaptiveDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "utils/CryptoUtils.h"

#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>

Expand Down Expand Up @@ -54,5 +55,5 @@ class Adaptive_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter

virtual AP4_UI32 AddPool() { return 0; }
virtual void RemovePool(AP4_UI32 poolId) {}
virtual const char* GetSessionId() { return nullptr; }
virtual std::string GetSessionId() { return {}; }
};
2 changes: 1 addition & 1 deletion src/decrypters/IDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class IDecrypter
* \return The single sample decrypter if successfully created
*/
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultKeyId,
std::string_view licenseUrl,
bool skipSessionMessage,
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/clearkey/ClearKeyDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool CClearKeyDecrypter::OpenDRMSystem(const DRM::Config& config)
}

std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CClearKeyDecrypter::CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultkeyid,
std::string_view licenseUrl,
bool skipSessionMessage,
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 @@ -19,7 +19,7 @@ class CClearKeyDecrypter : public IDecrypter
virtual std::vector<std::string_view> SelectKeySystems(std::string_view keySystem) override;
virtual bool OpenDRMSystem(const DRM::Config& config) override;
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultkeyid,
std::string_view licenseUrl,
bool skipSessionMessage,
Expand Down
6 changes: 3 additions & 3 deletions src/decrypters/widevine/WVCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void CWVCencSingleSampleDecrypter::SetSession(const std::string sessionId,

CWVCencSingleSampleDecrypter::CWVCencSingleSampleDecrypter(
IWVCdmAdapter<media::CdmAdapter>* cdmAdapter,
std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& defaultKeyId,
bool skipSessionMessage,
CryptoMode cryptoMode)
Expand Down Expand Up @@ -202,9 +202,9 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
}
}

const char* CWVCencSingleSampleDecrypter::GetSessionId()
std::string CWVCencSingleSampleDecrypter::GetSessionId()
{
return m_strSession.empty() ? nullptr : m_strSession.c_str();
return m_strSession;
}

void CWVCencSingleSampleDecrypter::CloseSessionId()
Expand Down
4 changes: 2 additions & 2 deletions src/decrypters/widevine/WVCencSingleSampleDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
{
public:
CWVCencSingleSampleDecrypter(IWVCdmAdapter<media::CdmAdapter>* cdmAdapter,
std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& defaultKeyId,
bool skipSessionMessage,
CryptoMode cryptoMode);
Expand All @@ -39,7 +39,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
void GetCapabilities(const std::vector<uint8_t>& keyId,
uint32_t media,
DecrypterCapabilites& caps);
virtual const char* GetSessionId() override;
virtual std::string GetSessionId() override;
void CloseSessionId();
AP4_DataBuffer GetChallengeData();

Expand Down
4 changes: 2 additions & 2 deletions src/decrypters/widevine/WVDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ bool CWVDecrypter::OpenDRMSystem(const DRM::Config& config)
}

std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypter::CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultKeyId,
std::string_view licenseUrl,
bool skipSessionMessage,
CryptoMode cryptoMode)
{
auto decrypter = std::make_shared<CWVCencSingleSampleDecrypter>(
m_WVCdmAdapter.get(), initData, defaultKeyId, skipSessionMessage, cryptoMode);
if (!decrypter->GetSessionId())
if (decrypter->GetSessionId().empty())
{
return nullptr;
}
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 @@ -22,7 +22,7 @@ class ATTR_DLL_LOCAL CWVDecrypter : public DRM::IDecrypter
virtual std::vector<std::string_view> SelectKeySystems(std::string_view keySystem) override;
virtual bool OpenDRMSystem(const DRM::Config& config) override;
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultKeyId,
std::string_view licenseUrl,
bool skipSessionMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace UTILS;

CWVCencSingleSampleDecrypterA::CWVCencSingleSampleDecrypterA(
IWVCdmAdapter<jni::CJNIMediaDrm>* cdmAdapter,
std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& defaultKeyId)
: m_cdmAdapter(cdmAdapter),
m_pssh(pssh),
Expand Down Expand Up @@ -159,9 +159,9 @@ CWVCencSingleSampleDecrypterA::~CWVCencSingleSampleDecrypterA()
m_cdmAdapter->DetachObserver(this);
}

const char* CWVCencSingleSampleDecrypterA::GetSessionId()
std::string CWVCencSingleSampleDecrypterA::GetSessionId()
{
return m_sessionId.c_str();
return m_sessionId;
}

std::vector<uint8_t> CWVCencSingleSampleDecrypterA::GetChallengeData()
Expand Down
4 changes: 2 additions & 2 deletions src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypterA : public Adaptive_CencSingleS
{
public:
CWVCencSingleSampleDecrypterA(IWVCdmAdapter<jni::CJNIMediaDrm>* cdmAdapter,
std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& pssh,
const std::vector<uint8_t>& defaultKeyId);
virtual ~CWVCencSingleSampleDecrypterA();

bool StartSession(bool skipSessionMessage) { return KeyUpdateRequest(true, skipSessionMessage); };

virtual const char* GetSessionId() override;
virtual std::string GetSessionId() override;
std::vector<uint8_t> GetChallengeData();
virtual bool HasLicenseKey(const std::vector<uint8_t>& keyId);

Expand Down
4 changes: 2 additions & 2 deletions src/decrypters/widevineandroid/WVDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool CWVDecrypterA::OpenDRMSystem(const DRM::Config& config)
}

std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypterA::CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultKeyId,
std::string_view licenseUrl,
bool skipSessionMessage,
Expand All @@ -99,7 +99,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypterA::CreateSingleS
std::shared_ptr<CWVCencSingleSampleDecrypterA> decrypter =
std::make_shared<CWVCencSingleSampleDecrypterA>(m_WVCdmAdapter.get(), initData, defaultKeyId);

if (!(*decrypter->GetSessionId() && decrypter->StartSession(skipSessionMessage)))
if (!(!decrypter->GetSessionId().empty() && decrypter->StartSession(skipSessionMessage)))
{
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decrypters/widevineandroid/WVDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ATTR_DLL_LOCAL CWVDecrypterA : public DRM::IDecrypter
virtual bool OpenDRMSystem(const DRM::Config& config) override;

virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
std::vector<uint8_t>& initData,
const std::vector<uint8_t>& initData,
const std::vector<uint8_t>& defaultKeyId,
std::string_view licenseUrl,
bool skipSessionMessage,
Expand Down
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ bool CInputStreamAdaptive::OpenStream(int streamid)
const std::string keySystem = CSrvBroker::GetKodiProps().GetDrmKeySystem();
cryptoSession.SetKeySystem(m_session->GetCryptoKeySystem(keySystem));

const char* sessionId(m_session->GetCDMSession(cdmSessionIndex));
cryptoSession.SetSessionId(sessionId);
cryptoSession.SetSessionId(m_session->GetCDMSession(cdmSessionIndex));

if (m_session->GetDecrypterCaps(cdmSessionIndex).flags &
DRM::DecrypterCapabilites::SSD_SUPPORTS_DECODING)
Expand Down Expand Up @@ -581,7 +580,7 @@ bool CVideoCodecAdaptive::Open(const kodi::addon::VideoCodecInitdata& initData)
}
m_name += ".decoder";

std::string sessionId(initData.GetCryptoSession().GetSessionId());
std::string sessionId = initData.GetCryptoSession().GetSessionId();
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> ssd(m_session->GetSingleSampleDecrypter(sessionId));

return m_session->GetDecrypter()->OpenVideoDecoder(
Expand Down