Skip to content

Commit eb963b7

Browse files
authored
Merge pull request #1694 from CastagnaIT/next_changes
Fix old prop parsing, and new session OnGetStream method
2 parents 54a146b + 00c906c commit eb963b7

File tree

4 files changed

+85
-76
lines changed

4 files changed

+85
-76
lines changed

src/CompKodiProps.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void ADP::KODI_PROPS::CCompKodiProps::ParseDrmOldProps(
376376
{
377377
// Translate data from old ISA properties to the new DRM config
378378

379-
if (!STRING::KeyExists(props, PROP_LICENSE_TYPE) && !STRING::KeyExists(props, PROP_LICENSE_KEY))
379+
if (!STRING::KeyExists(props, PROP_LICENSE_TYPE))
380380
return;
381381
/*
382382
*! @todo: TO UNCOMMENT WHEN DRM AUTO-SELECTION WILL BE FULL IMPLEMENTED

src/Session.cpp

+71-45
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@
2424
#include "utils/Utils.h"
2525
#include "utils/log.h"
2626

27-
#include <array>
28-
29-
#include <kodi/addon-instance/Inputstream.h>
30-
31-
using namespace kodi::tools;
3227
using namespace adaptive;
3328
using namespace PLAYLIST;
3429
using namespace SESSION;
3530
using namespace UTILS;
3631

37-
CSession::~CSession()
32+
SESSION::CSession::~CSession()
3833
{
3934
LOG::Log(LOGDEBUG, "CSession::~CSession()");
4035
DeleteStreams();
@@ -57,7 +52,7 @@ void SESSION::CSession::DeleteStreams()
5752
m_streams.clear();
5853
}
5954

60-
void CSession::SetSupportedDecrypterURN(std::vector<std::string_view>& keySystems)
55+
void SESSION::CSession::SetSupportedDecrypterURN(std::vector<std::string_view>& keySystems)
6156
{
6257
std::string decrypterPath = CSrvBroker::GetSettings().GetDecrypterPath();
6358
if (decrypterPath.empty())
@@ -81,7 +76,7 @@ void CSession::SetSupportedDecrypterURN(std::vector<std::string_view>& keySystem
8176
m_decrypter->SetLibraryPath(decrypterPath);
8277
}
8378

84-
void CSession::DisposeSampleDecrypter()
79+
void SESSION::CSession::DisposeSampleDecrypter()
8580
{
8681
if (m_decrypter)
8782
{
@@ -93,7 +88,7 @@ void CSession::DisposeSampleDecrypter()
9388
}
9489
}
9590

96-
void CSession::DisposeDecrypter()
91+
void SESSION::CSession::DisposeDecrypter()
9792
{
9893
DisposeSampleDecrypter();
9994
m_decrypter = nullptr;
@@ -103,7 +98,7 @@ void CSession::DisposeDecrypter()
10398
| initialize
10499
+---------------------------------------------------------------------*/
105100

106-
bool CSession::Initialize(std::string manifestUrl)
101+
bool SESSION::CSession::Initialize(std::string manifestUrl)
107102
{
108103
m_reprChooser = CHOOSER::CreateRepresentationChooser();
109104

@@ -196,7 +191,7 @@ bool CSession::Initialize(std::string manifestUrl)
196191
return InitializePeriod(isSessionOpened);
197192
}
198193

199-
void CSession::CheckHDCP()
194+
void SESSION::CSession::CheckHDCP()
200195
{
201196
//! @todo: is needed to implement an appropriate CP check to
202197
//! remove HDCPOVERRIDE setting workaround
@@ -238,9 +233,9 @@ void CSession::CheckHDCP()
238233
}
239234
}
240235

241-
bool CSession::PreInitializeDRM(std::string& challengeB64,
242-
std::string& sessionId,
243-
bool& isSessionOpened)
236+
bool SESSION::CSession::PreInitializeDRM(std::string& challengeB64,
237+
std::string& sessionId,
238+
bool& isSessionOpened)
244239
{
245240
auto& drmPropCfg = CSrvBroker::GetKodiProps().GetDrmConfig();
246241

@@ -318,7 +313,7 @@ bool CSession::PreInitializeDRM(std::string& challengeB64,
318313
return true;
319314
}
320315

321-
bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
316+
bool SESSION::CSession::InitializeDRM(bool addDefaultKID /* = false */)
322317
{
323318
bool isSecureVideoSession{false};
324319
m_cdmSessions.resize(m_adaptiveTree->m_currentPeriod->GetPSSHSets().size());
@@ -519,7 +514,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
519514
return true;
520515
}
521516

522-
bool CSession::InitializePeriod(bool isSessionOpened /* = false */)
517+
bool SESSION::CSession::InitializePeriod(bool isSessionOpened /* = false */)
523518
{
524519
bool isPsshChanged{true};
525520
bool isReusePssh{true};
@@ -625,11 +620,11 @@ bool CSession::InitializePeriod(bool isSessionOpened /* = false */)
625620
return true;
626621
}
627622

628-
void CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
629-
PLAYLIST::CRepresentation* initialRepr,
630-
bool isDefaultRepr,
631-
uint32_t uniqueId,
632-
std::string_view audioLanguageOrig)
623+
void SESSION::CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
624+
PLAYLIST::CRepresentation* initialRepr,
625+
bool isDefaultRepr,
626+
uint32_t uniqueId,
627+
std::string_view audioLanguageOrig)
633628
{
634629
m_streams.push_back(std::make_unique<CStream>(m_adaptiveTree, adp, initialRepr));
635630

@@ -687,7 +682,7 @@ void CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
687682
UpdateStream(stream);
688683
}
689684

690-
void CSession::UpdateStream(CStream& stream)
685+
void SESSION::CSession::UpdateStream(CStream& stream)
691686
{
692687
// On this method we set stream info provided by manifest parsing, but these info could be
693688
// changed by sample readers just before the start of playback by using GetInformation() methods
@@ -877,7 +872,7 @@ void CSession::UpdateStream(CStream& stream)
877872
stream.m_info.SetCodecInternalName(codecStr);
878873
}
879874

880-
void CSession::PrepareStream(CStream* stream)
875+
void SESSION::CSession::PrepareStream(CStream* stream)
881876
{
882877
if (!m_adaptiveTree->IsReqPrepareStream())
883878
return;
@@ -942,7 +937,7 @@ const char* SESSION::CSession::GetCDMSession(unsigned int index)
942937
return m_cdmSessions[index].m_cdmSessionStr;
943938
}
944939

945-
uint64_t CSession::PTSToElapsed(uint64_t pts)
940+
uint64_t SESSION::CSession::PTSToElapsed(uint64_t pts)
946941
{
947942
if (m_timingStream)
948943
{
@@ -968,7 +963,7 @@ uint64_t CSession::PTSToElapsed(uint64_t pts)
968963
return pts;
969964
}
970965

971-
uint64_t CSession::GetTimeshiftBufferStart()
966+
uint64_t SESSION::CSession::GetTimeshiftBufferStart()
972967
{
973968
if (m_timingStream)
974969
{
@@ -985,7 +980,7 @@ uint64_t CSession::GetTimeshiftBufferStart()
985980
}
986981

987982
// TODO: clean this up along with seektime
988-
void CSession::StartReader(
983+
void SESSION::CSession::StartReader(
989984
CStream* stream, uint64_t seekTime, int64_t ptsDiff, bool preceeding, bool timing)
990985
{
991986
ISampleReader* streamReader = stream->GetReader();
@@ -1013,12 +1008,12 @@ void CSession::StartReader(
10131008
m_changed = true;
10141009
}
10151010

1016-
void CSession::OnScreenResChange()
1011+
void SESSION::CSession::OnScreenResChange()
10171012
{
10181013
m_reprChooser->OnUpdateScreenRes();
10191014
};
10201015

1021-
bool CSession::GetNextSample(ISampleReader*& sampleReader)
1016+
bool SESSION::CSession::GetNextSample(ISampleReader*& sampleReader)
10221017
{
10231018
CStream* res{nullptr};
10241019
CStream* waiting{nullptr};
@@ -1083,7 +1078,7 @@ bool CSession::GetNextSample(ISampleReader*& sampleReader)
10831078
return false;
10841079
}
10851080

1086-
bool CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding)
1081+
bool SESSION::CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding)
10871082
{
10881083
bool ret{false};
10891084

@@ -1220,7 +1215,7 @@ bool CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding)
12201215
return ret;
12211216
}
12221217

1223-
void CSession::OnDemuxRead()
1218+
void SESSION::CSession::OnDemuxRead()
12241219
{
12251220
if (m_adaptiveTree->IsChangingPeriod() && m_adaptiveTree->IsChangingPeriodDone())
12261221
{
@@ -1234,7 +1229,7 @@ void CSession::OnDemuxRead()
12341229
}
12351230
}
12361231

1237-
void CSession::OnSegmentChanged(adaptive::AdaptiveStream* adStream)
1232+
void SESSION::CSession::OnSegmentChanged(adaptive::AdaptiveStream* adStream)
12381233
{
12391234
for (auto& stream : m_streams)
12401235
{
@@ -1251,7 +1246,7 @@ void CSession::OnSegmentChanged(adaptive::AdaptiveStream* adStream)
12511246
}
12521247
}
12531248

1254-
void CSession::OnStreamChange(adaptive::AdaptiveStream* adStream)
1249+
void SESSION::CSession::OnStreamChange(adaptive::AdaptiveStream* adStream)
12551250
{
12561251
for (auto& stream : m_streams)
12571252
{
@@ -1263,7 +1258,38 @@ void CSession::OnStreamChange(adaptive::AdaptiveStream* adStream)
12631258
}
12641259
}
12651260

1266-
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CSession::GetSingleSampleDecrypter(std::string sessionId)
1261+
bool SESSION::CSession::OnGetStream(int streamid, kodi::addon::InputstreamInfo& info)
1262+
{
1263+
CStream* stream(GetStream(streamid - GetPeriodId() * 1000));
1264+
1265+
if (stream)
1266+
{
1267+
const uint16_t psshSetPos = stream->m_adStream.getRepresentation()->m_psshSetPos;
1268+
if (psshSetPos != PSSHSET_POS_DEFAULT ||
1269+
stream->m_adStream.getPeriod()->GetEncryptionState() == EncryptionState::NOT_SUPPORTED)
1270+
{
1271+
if (!GetSingleSampleDecryptor(psshSetPos))
1272+
{
1273+
// If the stream is protected with a unsupported DRM, we have to stop the playback,
1274+
// since there are no ways to stop playback when Kodi request streams
1275+
// we are forced to delete all CStream's here, so that when demux reader will starts
1276+
// will have no data to process, and so stop the playback
1277+
// (other streams may have been requested/opened before this one)
1278+
LOG::Log(LOGERROR, "GetStream(%d): Decrypter for the stream not found");
1279+
DeleteStreams();
1280+
return false;
1281+
}
1282+
}
1283+
1284+
info = stream->m_info;
1285+
return true;
1286+
}
1287+
1288+
return false;
1289+
}
1290+
1291+
std::shared_ptr<Adaptive_CencSingleSampleDecrypter> SESSION::CSession::GetSingleSampleDecrypter(
1292+
std::string sessionId)
12671293
{
12681294
for (std::vector<CCdmSession>::iterator b(m_cdmSessions.begin() + 1), e(m_cdmSessions.end());
12691295
b != e; ++b)
@@ -1274,7 +1300,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CSession::GetSingleSampleDec
12741300
return nullptr;
12751301
}
12761302

1277-
uint32_t CSession::GetIncludedStreamMask() const
1303+
uint32_t SESSION::CSession::GetIncludedStreamMask() const
12781304
{
12791305
//! @todo: this conversion must be reworked can easily be broken and cause hidden problems
12801306
const INPUTSTREAM_TYPE adp2ips[] = {INPUTSTREAM_TYPE_NONE, INPUTSTREAM_TYPE_VIDEO,
@@ -1288,7 +1314,7 @@ uint32_t CSession::GetIncludedStreamMask() const
12881314
return res;
12891315
}
12901316

1291-
STREAM_CRYPTO_KEY_SYSTEM CSession::GetCryptoKeySystem(std::string_view keySystem) const
1317+
STREAM_CRYPTO_KEY_SYSTEM SESSION::CSession::GetCryptoKeySystem(std::string_view keySystem) const
12921318
{
12931319
if (keySystem == DRM::KS_WIDEVINE)
12941320
return STREAM_CRYPTO_KEY_SYSTEM_WIDEVINE;
@@ -1318,15 +1344,15 @@ int CSession::GetChapter() const
13181344
return -1;
13191345
}
13201346

1321-
int CSession::GetChapterCount() const
1347+
int SESSION::CSession::GetChapterCount() const
13221348
{
13231349
if (m_adaptiveTree && m_adaptiveTree->m_periods.size() > 1)
13241350
return static_cast<int>(m_adaptiveTree->m_periods.size());
13251351

13261352
return 0;
13271353
}
13281354

1329-
std::string CSession::GetChapterName(int ch) const
1355+
std::string SESSION::CSession::GetChapterName(int ch) const
13301356
{
13311357
if (m_adaptiveTree)
13321358
{
@@ -1338,7 +1364,7 @@ std::string CSession::GetChapterName(int ch) const
13381364
return "[Unknown]";
13391365
}
13401366

1341-
int64_t CSession::GetChapterPos(int ch) const
1367+
int64_t SESSION::CSession::GetChapterPos(int ch) const
13421368
{
13431369
int64_t sum{0};
13441370
--ch;
@@ -1352,7 +1378,7 @@ int64_t CSession::GetChapterPos(int ch) const
13521378
return sum / STREAM_TIME_BASE;
13531379
}
13541380

1355-
uint64_t CSession::GetChapterStartTime() const
1381+
uint64_t SESSION::CSession::GetChapterStartTime() const
13561382
{
13571383
uint64_t start_time = 0;
13581384
for (std::unique_ptr<CPeriod>& p : m_adaptiveTree->m_periods)
@@ -1365,7 +1391,7 @@ uint64_t CSession::GetChapterStartTime() const
13651391
return start_time;
13661392
}
13671393

1368-
int CSession::GetPeriodId() const
1394+
int SESSION::CSession::GetPeriodId() const
13691395
{
13701396
if (m_adaptiveTree)
13711397
{
@@ -1384,7 +1410,7 @@ int CSession::GetPeriodId() const
13841410
return -1;
13851411
}
13861412

1387-
bool CSession::SeekChapter(int ch)
1413+
bool SESSION::CSession::SeekChapter(int ch)
13881414
{
13891415
if (m_adaptiveTree->IsChangingPeriod())
13901416
return true;
@@ -1412,10 +1438,10 @@ bool CSession::SeekChapter(int ch)
14121438
return false;
14131439
}
14141440

1415-
void CSession::ExtractStreamProtectionData(const PLAYLIST::CPeriod::PSSHSet& psshSet,
1416-
std::string& defaultKid,
1417-
std::vector<uint8_t>& initData,
1418-
const std::vector<std::string_view>& keySystems)
1441+
void SESSION::CSession::ExtractStreamProtectionData(const PLAYLIST::CPeriod::PSSHSet& psshSet,
1442+
std::string& defaultKid,
1443+
std::vector<uint8_t>& initData,
1444+
const std::vector<std::string_view>& keySystems)
14191445
{
14201446
auto initialRepr = m_reprChooser->GetRepresentation(psshSet.adaptation_set_);
14211447

src/Session.h

+8
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
318318
*/
319319
void OnStreamChange(adaptive::AdaptiveStream* adStream) override;
320320

321+
/*!
322+
* \brief Callback from CInputStreamAdaptive::GetStream.
323+
* \param streamid The requested stream id
324+
* \param info The stream info object (can be updated)
325+
* \return True to allow Kodi core to load the stream, otherwise false
326+
*/
327+
bool OnGetStream(int streamid, kodi::addon::InputstreamInfo& info);
328+
321329
protected:
322330
/*! \brief Check for and load decrypter module matching the supplied key system
323331
* \param key_system [OUT] Will be assigned to if a decrypter is found matching

0 commit comments

Comments
 (0)