Skip to content

Commit 952fb05

Browse files
authored
Merge pull request #1695 from CastagnaIT/next_cleanups
[Decrypters][cleanups] Const init data, session id as string
2 parents eb963b7 + 2d9d5ea commit 952fb05

15 files changed

+33
-33
lines changed

src/Session.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void SESSION::CSession::DisposeSampleDecrypter()
8282
{
8383
for (auto& cdmSession : m_cdmSessions)
8484
{
85-
cdmSession.m_cdmSessionStr = nullptr;
85+
cdmSession.m_sessionId.clear();
8686
cdmSession.m_cencSingleSampleDecrypter = nullptr;
8787
}
8888
}
@@ -293,8 +293,8 @@ bool SESSION::CSession::PreInitializeDRM(std::string& challengeB64,
293293
m_decrypter->CreateSingleSampleDecrypter(initData, decKid, "", true,
294294
CryptoMode::AES_CTR)) != nullptr)
295295
{
296-
session.m_cdmSessionStr = session.m_cencSingleSampleDecrypter->GetSessionId();
297-
sessionId = session.m_cdmSessionStr;
296+
session.m_sessionId = session.m_cencSingleSampleDecrypter->GetSessionId();
297+
sessionId = session.m_sessionId;
298298
challengeB64 = m_decrypter->GetChallengeB64Data(session.m_cencSingleSampleDecrypter);
299299
}
300300
else
@@ -466,7 +466,7 @@ bool SESSION::CSession::InitializeDRM(bool addDefaultKID /* = false */)
466466
m_decrypter->GetCapabilities(session.m_cencSingleSampleDecrypter, defaultKid,
467467
sessionPsshset.media_, session.m_decrypterCaps);
468468

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

471471
if (session.m_decrypterCaps.flags & DRM::DecrypterCapabilites::SSD_INVALID)
472472
{
@@ -927,14 +927,14 @@ bool SESSION::CSession::IsCDMSessionSecurePath(size_t index)
927927
DRM::DecrypterCapabilites::SSD_SECURE_PATH) != 0;
928928
}
929929

930-
const char* SESSION::CSession::GetCDMSession(unsigned int index)
930+
std::string SESSION::CSession::GetCDMSession(unsigned int index)
931931
{
932932
if (index >= m_cdmSessions.size())
933933
{
934934
LOG::LogF(LOGERROR, "No CDM session at index %u", index);
935-
return nullptr;
935+
return {};
936936
}
937-
return m_cdmSessions[index].m_cdmSessionStr;
937+
return m_cdmSessions[index].m_sessionId;
938938
}
939939

940940
uint64_t SESSION::CSession::PTSToElapsed(uint64_t pts)
@@ -1294,7 +1294,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> SESSION::CSession::GetSingle
12941294
for (std::vector<CCdmSession>::iterator b(m_cdmSessions.begin() + 1), e(m_cdmSessions.end());
12951295
b != e; ++b)
12961296
{
1297-
if (b->m_cdmSessionStr && sessionId == b->m_cdmSessionStr)
1297+
if (sessionId == b->m_sessionId)
12981298
return b->m_cencSingleSampleDecrypter;
12991299
}
13001300
return nullptr;

src/Session.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
125125
* \param index The index (psshSet number) of the cdm session
126126
* \return The session string
127127
*/
128-
const char* GetCDMSession(unsigned int index);
128+
std::string GetCDMSession(unsigned int index);
129129

130130
/*! \brief Get the media type mask
131131
* \return The media type mask
@@ -353,7 +353,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
353353
{
354354
DRM::DecrypterCapabilites m_decrypterCaps;
355355
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> m_cencSingleSampleDecrypter;
356-
const char* m_cdmSessionStr{nullptr};
356+
std::string m_sessionId;
357357
};
358358
std::vector<CCdmSession> m_cdmSessions;
359359

src/common/AdaptiveDecrypter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "utils/CryptoUtils.h"
1212

1313
#include <stdexcept>
14+
#include <string>
1415
#include <string_view>
1516
#include <vector>
1617

@@ -54,5 +55,5 @@ class Adaptive_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter
5455

5556
virtual AP4_UI32 AddPool() { return 0; }
5657
virtual void RemovePool(AP4_UI32 poolId) {}
57-
virtual const char* GetSessionId() { return nullptr; }
58+
virtual std::string GetSessionId() { return {}; }
5859
};

src/decrypters/IDecrypter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class IDecrypter
125125
* \return The single sample decrypter if successfully created
126126
*/
127127
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
128-
std::vector<uint8_t>& initData,
128+
const std::vector<uint8_t>& initData,
129129
const std::vector<uint8_t>& defaultKeyId,
130130
std::string_view licenseUrl,
131131
bool skipSessionMessage,

src/decrypters/clearkey/ClearKeyDecrypter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool CClearKeyDecrypter::OpenDRMSystem(const DRM::Config& config)
3131
}
3232

3333
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CClearKeyDecrypter::CreateSingleSampleDecrypter(
34-
std::vector<uint8_t>& initData,
34+
const std::vector<uint8_t>& initData,
3535
const std::vector<uint8_t>& defaultkeyid,
3636
std::string_view licenseUrl,
3737
bool skipSessionMessage,

src/decrypters/clearkey/ClearKeyDecrypter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CClearKeyDecrypter : public IDecrypter
1919
virtual std::vector<std::string_view> SelectKeySystems(std::string_view keySystem) override;
2020
virtual bool OpenDRMSystem(const DRM::Config& config) override;
2121
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
22-
std::vector<uint8_t>& initData,
22+
const std::vector<uint8_t>& initData,
2323
const std::vector<uint8_t>& defaultkeyid,
2424
std::string_view licenseUrl,
2525
bool skipSessionMessage,

src/decrypters/widevine/WVCencSingleSampleDecrypter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CWVCencSingleSampleDecrypter::SetSession(const std::string sessionId,
4242

4343
CWVCencSingleSampleDecrypter::CWVCencSingleSampleDecrypter(
4444
IWVCdmAdapter<media::CdmAdapter>* cdmAdapter,
45-
std::vector<uint8_t>& pssh,
45+
const std::vector<uint8_t>& pssh,
4646
const std::vector<uint8_t>& defaultKeyId,
4747
bool skipSessionMessage,
4848
CryptoMode cryptoMode)
@@ -202,9 +202,9 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
202202
}
203203
}
204204

205-
const char* CWVCencSingleSampleDecrypter::GetSessionId()
205+
std::string CWVCencSingleSampleDecrypter::GetSessionId()
206206
{
207-
return m_strSession.empty() ? nullptr : m_strSession.c_str();
207+
return m_strSession;
208208
}
209209

210210
void CWVCencSingleSampleDecrypter::CloseSessionId()

src/decrypters/widevine/WVCencSingleSampleDecrypter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
3030
{
3131
public:
3232
CWVCencSingleSampleDecrypter(IWVCdmAdapter<media::CdmAdapter>* cdmAdapter,
33-
std::vector<uint8_t>& pssh,
33+
const std::vector<uint8_t>& pssh,
3434
const std::vector<uint8_t>& defaultKeyId,
3535
bool skipSessionMessage,
3636
CryptoMode cryptoMode);
@@ -39,7 +39,7 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
3939
void GetCapabilities(const std::vector<uint8_t>& keyId,
4040
uint32_t media,
4141
DecrypterCapabilites& caps);
42-
virtual const char* GetSessionId() override;
42+
virtual std::string GetSessionId() override;
4343
void CloseSessionId();
4444
AP4_DataBuffer GetChallengeData();
4545

src/decrypters/widevine/WVDecrypter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ bool CWVDecrypter::OpenDRMSystem(const DRM::Config& config)
9696
}
9797

9898
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypter::CreateSingleSampleDecrypter(
99-
std::vector<uint8_t>& initData,
99+
const std::vector<uint8_t>& initData,
100100
const std::vector<uint8_t>& defaultKeyId,
101101
std::string_view licenseUrl,
102102
bool skipSessionMessage,
103103
CryptoMode cryptoMode)
104104
{
105105
auto decrypter = std::make_shared<CWVCencSingleSampleDecrypter>(
106106
m_WVCdmAdapter.get(), initData, defaultKeyId, skipSessionMessage, cryptoMode);
107-
if (!decrypter->GetSessionId())
107+
if (decrypter->GetSessionId().empty())
108108
{
109109
return nullptr;
110110
}

src/decrypters/widevine/WVDecrypter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ATTR_DLL_LOCAL CWVDecrypter : public DRM::IDecrypter
2222
virtual std::vector<std::string_view> SelectKeySystems(std::string_view keySystem) override;
2323
virtual bool OpenDRMSystem(const DRM::Config& config) override;
2424
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
25-
std::vector<uint8_t>& initData,
25+
const std::vector<uint8_t>& initData,
2626
const std::vector<uint8_t>& defaultKeyId,
2727
std::string_view licenseUrl,
2828
bool skipSessionMessage,

src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace UTILS;
2828

2929
CWVCencSingleSampleDecrypterA::CWVCencSingleSampleDecrypterA(
3030
IWVCdmAdapter<jni::CJNIMediaDrm>* cdmAdapter,
31-
std::vector<uint8_t>& pssh,
31+
const std::vector<uint8_t>& pssh,
3232
const std::vector<uint8_t>& defaultKeyId)
3333
: m_cdmAdapter(cdmAdapter),
3434
m_pssh(pssh),
@@ -159,9 +159,9 @@ CWVCencSingleSampleDecrypterA::~CWVCencSingleSampleDecrypterA()
159159
m_cdmAdapter->DetachObserver(this);
160160
}
161161

162-
const char* CWVCencSingleSampleDecrypterA::GetSessionId()
162+
std::string CWVCencSingleSampleDecrypterA::GetSessionId()
163163
{
164-
return m_sessionId.c_str();
164+
return m_sessionId;
165165
}
166166

167167
std::vector<uint8_t> CWVCencSingleSampleDecrypterA::GetChallengeData()

src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypterA : public Adaptive_CencSingleS
2525
{
2626
public:
2727
CWVCencSingleSampleDecrypterA(IWVCdmAdapter<jni::CJNIMediaDrm>* cdmAdapter,
28-
std::vector<uint8_t>& pssh,
28+
const std::vector<uint8_t>& pssh,
2929
const std::vector<uint8_t>& defaultKeyId);
3030
virtual ~CWVCencSingleSampleDecrypterA();
3131

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

34-
virtual const char* GetSessionId() override;
34+
virtual std::string GetSessionId() override;
3535
std::vector<uint8_t> GetChallengeData();
3636
virtual bool HasLicenseKey(const std::vector<uint8_t>& keyId);
3737

src/decrypters/widevineandroid/WVDecrypter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool CWVDecrypterA::OpenDRMSystem(const DRM::Config& config)
9090
}
9191

9292
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypterA::CreateSingleSampleDecrypter(
93-
std::vector<uint8_t>& initData,
93+
const std::vector<uint8_t>& initData,
9494
const std::vector<uint8_t>& defaultKeyId,
9595
std::string_view licenseUrl,
9696
bool skipSessionMessage,
@@ -99,7 +99,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CWVDecrypterA::CreateSingleS
9999
std::shared_ptr<CWVCencSingleSampleDecrypterA> decrypter =
100100
std::make_shared<CWVCencSingleSampleDecrypterA>(m_WVCdmAdapter.get(), initData, defaultKeyId);
101101

102-
if (!(*decrypter->GetSessionId() && decrypter->StartSession(skipSessionMessage)))
102+
if (!(!decrypter->GetSessionId().empty() && decrypter->StartSession(skipSessionMessage)))
103103
{
104104
return nullptr;
105105
}

src/decrypters/widevineandroid/WVDecrypter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ATTR_DLL_LOCAL CWVDecrypterA : public DRM::IDecrypter
4949
virtual bool OpenDRMSystem(const DRM::Config& config) override;
5050

5151
virtual std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CreateSingleSampleDecrypter(
52-
std::vector<uint8_t>& initData,
52+
const std::vector<uint8_t>& initData,
5353
const std::vector<uint8_t>& defaultKeyId,
5454
std::string_view licenseUrl,
5555
bool skipSessionMessage,

src/main.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ bool CInputStreamAdaptive::OpenStream(int streamid)
306306
const std::string keySystem = CSrvBroker::GetKodiProps().GetDrmKeySystem();
307307
cryptoSession.SetKeySystem(m_session->GetCryptoKeySystem(keySystem));
308308

309-
const char* sessionId(m_session->GetCDMSession(cdmSessionIndex));
310-
cryptoSession.SetSessionId(sessionId);
309+
cryptoSession.SetSessionId(m_session->GetCDMSession(cdmSessionIndex));
311310

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

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

587586
return m_session->GetDecrypter()->OpenVideoDecoder(

0 commit comments

Comments
 (0)