Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Nov 11, 2024
1 parent a1a28e0 commit 9992a4c
Show file tree
Hide file tree
Showing 26 changed files with 1,106 additions and 881 deletions.
619 changes: 104 additions & 515 deletions src/Session.cpp

Large diffs are not rendered by default.

81 changes: 6 additions & 75 deletions src/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Stream.h"
#include "common/AdaptiveStream.h"
#include "common/AdaptiveTree.h"
#include "decrypters/DrmEngine.h"
#include "decrypters/IDecrypter.h"

#if defined(ANDROID)
Expand Down Expand Up @@ -40,21 +41,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
/*
* \brief Check HDCP parameters to remove unplayable representations
*/
void CheckHDCP();

/*! \brief Pre-Initialize the DRM
* \param challengeB64 [OUT] Provide the challenge data as base64
* \param sessionId [OUT] Provide the session ID
* \param isSessionOpened [OUT] Will be true if the DRM session has been opened
* \return True if has success, false otherwise
*/
bool PreInitializeDRM(std::string& challengeB64, std::string& sessionId, bool& isSessionOpened);

/*! \brief Initialize the DRM
* \param addDefaultKID Set True to add the default KID to the first session
* \return True if has success, false otherwise
*/
bool InitializeDRM(bool addDefaultKID = false);
//void CheckHDCP();

/*! \brief Initialize adaptive tree period
* \param isSessionOpened Set True to kept and re-use the DRM session opened,
Expand Down Expand Up @@ -93,7 +80,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
* \brief Update stream's InputstreamInfo
* \param stream The stream to prepare
*/
void PrepareStream(CStream* stream);
bool PrepareStream(CStream* stream, uint64_t startPts);

/*! \brief Get a stream by index (starting at 1)
* \param sid The one-indexed stream id
Expand All @@ -115,50 +102,11 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
*/
unsigned int GetStreamCount() const { return static_cast<unsigned int>(m_streams.size()); }

/*!
* \brief Determines if the CDM session at specified index require Secure Path (TEE).
* \return True if Secure Path is required, otherwise false.
*/
bool IsCDMSessionSecurePath(size_t index);

/*! \brief Get a session string (session id) by index from the cdm sessions
* \param index The index (psshSet number) of the cdm session
* \return The session string
*/
std::string GetCDMSession(unsigned int index);

/*! \brief Get the media type mask
* \return The media type mask
*/
uint8_t GetMediaTypeMask() const { return m_mediaTypeMask; }

/*! \brief Get a single sample decrypter by index from the cdm sessions
* \param index The index (psshSet number) of the cdm session
* \return The single sample decrypter
*/
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> GetSingleSampleDecryptor(
unsigned int index) const;

/*! \brief Get the decrypter (DRM lib)
* \return The decrypter
*/
DRM::IDecrypter* GetDecrypter() { return m_decrypter.get(); }

/*! \brief Get a single sample decrypter matching the session id provided
* \param sessionId The session id string to match
* \return The single sample decrypter
*/
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> GetSingleSampleDecrypter(std::string sessionId);

/*! \brief Get decrypter capabilities for a single sample decrypter
* \param index The index (psshSet number) of the cdm session
* \return The single sample decrypter capabilities
*/
const DRM::DecrypterCapabilites& GetDecrypterCaps(unsigned int index) const
{
return m_cdmSessions[index].m_decrypterCaps;
};

/*! \brief Get the total time in ms of the stream
* \return The total time in ms of the stream
*/
Expand Down Expand Up @@ -324,13 +272,9 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
*/
bool OnGetStream(int streamid, kodi::addon::InputstreamInfo& info);

protected:
/*! \brief Check for and load decrypter module matching the supplied key system
* \param key_system [OUT] Will be assigned to if a decrypter is found matching
* the set license type
*/
void SetSupportedDecrypterURN(std::vector<std::string_view>& keySystems);
const DRM::CDRMEngine& GetDRMEngine() const { return m_drmEngine; }

protected:
/*! \brief Destroy all CencSingleSampleDecrypter instances
*/
void DisposeSampleDecrypter();
Expand All @@ -339,21 +283,8 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
*/
void DisposeDecrypter();

void ExtractStreamProtectionData(const PLAYLIST::CPeriod::PSSHSet& psshSet,
std::string& defaultKid,
std::vector<uint8_t>& initData,
const std::vector<std::string_view>& keySystems);

private:
std::shared_ptr<DRM::IDecrypter> m_decrypter;

struct CCdmSession
{
DRM::DecrypterCapabilites m_decrypterCaps;
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> m_cencSingleSampleDecrypter;
std::string m_sessionId;
};
std::vector<CCdmSession> m_cdmSessions;
DRM::CDRMEngine m_drmEngine;

adaptive::AdaptiveTree* m_adaptiveTree{nullptr};
CHOOSER::IRepresentationChooser* m_reprChooser{nullptr};
Expand Down
1 change: 0 additions & 1 deletion src/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void CStream::Disable()
Reset();

m_isEnabled = false;
m_isEncrypted = false;
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ class ATTR_DLL_LOCAL CStream
CStream(adaptive::AdaptiveTree* tree,
PLAYLIST::CAdaptationSet* adp,
PLAYLIST::CRepresentation* initialRepr)
: m_isEnabled{false},
m_isEncrypted{false},
m_mainId{0},
m_adStream{tree, adp, initialRepr},
m_isValid{true} {};

: m_isEnabled{false}, m_mainId{0}, m_adStream{tree, adp, initialRepr}, m_isValid{true}
{
}

~CStream() { Disable(); };
~CStream() { Disable(); }

/*!
* \brief Stop/disable the AdaptiveStream and reset
Expand Down Expand Up @@ -82,7 +79,6 @@ class ATTR_DLL_LOCAL CStream
}

bool m_isEnabled;
bool m_isEncrypted;
uint16_t m_mainId;
adaptive::AdaptiveStream m_adStream;
kodi::addon::InputstreamInfo m_info;
Expand Down
2 changes: 1 addition & 1 deletion src/common/AdaptiveDecrypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ class Adaptive_CencSingleSampleDecrypter : public AP4_CencSingleSampleDecrypter

virtual AP4_UI32 AddPool() { return 0; }
virtual void RemovePool(AP4_UI32 poolId) {}
virtual std::string GetSessionId() { return {}; }
virtual std::string GetSessionId() = 0;
};
3 changes: 0 additions & 3 deletions src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace adaptive
m_manifestParams = left.m_manifestParams;
m_manifestHeaders = left.m_manifestHeaders;
m_settings = left.m_settings;
m_supportedKeySystems = left.m_supportedKeySystems;
m_pathSaveManifest = left.m_pathSaveManifest;
stream_start_ = left.stream_start_;

Expand All @@ -49,11 +48,9 @@ namespace adaptive
}

void AdaptiveTree::Configure(CHOOSER::IRepresentationChooser* reprChooser,
std::vector<std::string_view> supportedKeySystems,
std::string_view manifestUpdParams)
{
m_reprChooser = reprChooser;
m_supportedKeySystems = supportedKeySystems;

auto srvBroker = CSrvBroker::GetInstance();

Expand Down
5 changes: 2 additions & 3 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ATTR_DLL_LOCAL AdaptiveTree
uint64_t available_time_{0}; // in ms
uint64_t m_liveDelay{0}; // Apply a delay in seconds from the live edge

std::vector<std::string_view> m_supportedKeySystems;
std::vector<std::string_view> m_supportedKeySystems; // REMOVE ME
std::string location_;

CryptoMode m_cryptoMode{CryptoMode::NONE};
Expand All @@ -86,11 +86,10 @@ class ATTR_DLL_LOCAL AdaptiveTree

/*!
* \brief Configure the adaptive tree.
* \param kodiProps The Kodi properties
* \param reprChooser The representation chooser
* \param manifestUpdParams Parameters to be add to manifest request url, depends on manifest implementation
*/
virtual void Configure(CHOOSER::IRepresentationChooser* reprChooser,
std::vector<std::string_view> supportedKeySystems,
std::string_view manifestUpdParams);

/*
Expand Down
5 changes: 5 additions & 0 deletions src/common/Representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "SegmentBase.h"
#include "SegTemplate.h"
#include "SegmentList.h"
#include "decrypters/DrmEngineDefines.h"

#ifdef INPUTSTREAM_TEST_BUILD
#include "test/KodiStubs.h"
Expand Down Expand Up @@ -158,6 +159,9 @@ class ATTR_DLL_LOCAL CRepresentation : public CCommonSegAttribs, public CCommonA
bool IsIncludedStream() const { return m_isIncludedStream; }
void SetIsIncludedStream(bool isIncludedStream) { m_isIncludedStream = isIncludedStream; }

std::vector<DRM::DRMInfo>& DrmInfos() { return m_drmInfo; }
void AddDrmInfo(DRM::DRMInfo drmInfo) { m_drmInfo.emplace_back(drmInfo); }

void CopyHLSData(const CRepresentation* other);

static bool CompareBandwidth(std::unique_ptr<CRepresentation>& left,
Expand Down Expand Up @@ -239,6 +243,7 @@ class ATTR_DLL_LOCAL CRepresentation : public CCommonSegAttribs, public CCommonA
bool m_isWaitForSegment{false};

bool m_isIncludedStream{false};
std::vector<DRM::DRMInfo> m_drmInfo;
};

} // namespace PLAYLIST
3 changes: 3 additions & 0 deletions src/decrypters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
set(SOURCES
DrmEngine.cpp
DrmFactory.cpp
Helpers.cpp
HelperPr.cpp
HelperWv.cpp
)

set(HEADERS
DrmEngine.h
DrmEngineDefines.h
DrmFactory.h
Helpers.h
HelperPr.h
Expand Down
Loading

0 comments on commit 9992a4c

Please sign in to comment.