Skip to content

Commit

Permalink
Force delete streams, when decrypter is not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 21, 2024
1 parent e845dc5 commit f7dae9f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CSession::CSession(const std::string& manifestUrl) : m_manifestUrl(manifestUrl)
CSession::~CSession()
{
LOG::Log(LOGDEBUG, "CSession::~CSession()");
m_streams.clear();
DeleteStreams();
DisposeDecrypter();

if (m_adaptiveTree)
Expand All @@ -79,6 +79,12 @@ CSession::~CSession()
m_reprChooser = nullptr;
}

void SESSION::CSession::DeleteStreams()
{
LOG::Log(LOGDEBUG, "CSession::DeleteStreams()");
m_streams.clear();
}

void CSession::SetSupportedDecrypterURN(std::vector<std::string_view>& keySystems)
{
std::string decrypterPath = CSrvBroker::GetSettings().GetDecrypterPath();
Expand Down
2 changes: 2 additions & 0 deletions src/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
CSession(const std::string& manifestUrl);
virtual ~CSession();

void DeleteStreams();

/*! \brief Initialize the session
* \return True if has success, false otherwise
*/
Expand Down
20 changes: 20 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ bool CInputStreamAdaptive::GetStream(int streamid, kodi::addon::InputstreamInfo&

if (stream)
{
// If the stream is encrypted, verify if the decrypter has been initialized
// this is important for HLS because the DRM it is initialized at later time
// so on the OpenStream, instead of CSession::Initialize->InitializePeriod->InitializeDRM
// Since kodi initialize one single stream at time, can happens that or another stream
// has been opened before this one, or another stream will be opened after this one (e.g. unencrypted)
// so if you dont delete all streams, the kodi demux reader still starts
// and a corrupted playback will starts.
// NOTE: GetStream is called by Kodi twice times, before and after OpenStream, on HLS
// the first time all streams are unencrypted because child manifest has not been downloaded
const uint16_t psshSetPos = stream->m_adStream.getRepresentation()->m_psshSetPos;
if (psshSetPos != PSSHSET_POS_DEFAULT)
{
if (!m_session->GetSingleSampleDecryptor(psshSetPos))
{
LOG::Log(LOGERROR, "GetStream(%d): Decrypter for the stream not found");
m_session->DeleteStreams();
return false;
}
}

info = stream->m_info;
return true;
}
Expand Down

0 comments on commit f7dae9f

Please sign in to comment.