24
24
#include " utils/Utils.h"
25
25
#include " utils/log.h"
26
26
27
- #include < array>
28
-
29
- #include < kodi/addon-instance/Inputstream.h>
30
-
31
- using namespace kodi ::tools;
32
27
using namespace adaptive ;
33
28
using namespace PLAYLIST ;
34
29
using namespace SESSION ;
35
30
using namespace UTILS ;
36
31
37
- CSession::~CSession ()
32
+ SESSION:: CSession::~CSession ()
38
33
{
39
34
LOG::Log (LOGDEBUG, " CSession::~CSession()" );
40
35
DeleteStreams ();
@@ -57,7 +52,7 @@ void SESSION::CSession::DeleteStreams()
57
52
m_streams.clear ();
58
53
}
59
54
60
- void CSession::SetSupportedDecrypterURN (std::vector<std::string_view>& keySystems)
55
+ void SESSION:: CSession::SetSupportedDecrypterURN (std::vector<std::string_view>& keySystems)
61
56
{
62
57
std::string decrypterPath = CSrvBroker::GetSettings ().GetDecrypterPath ();
63
58
if (decrypterPath.empty ())
@@ -81,7 +76,7 @@ void CSession::SetSupportedDecrypterURN(std::vector<std::string_view>& keySystem
81
76
m_decrypter->SetLibraryPath (decrypterPath);
82
77
}
83
78
84
- void CSession::DisposeSampleDecrypter ()
79
+ void SESSION:: CSession::DisposeSampleDecrypter ()
85
80
{
86
81
if (m_decrypter)
87
82
{
@@ -93,7 +88,7 @@ void CSession::DisposeSampleDecrypter()
93
88
}
94
89
}
95
90
96
- void CSession::DisposeDecrypter ()
91
+ void SESSION:: CSession::DisposeDecrypter ()
97
92
{
98
93
DisposeSampleDecrypter ();
99
94
m_decrypter = nullptr ;
@@ -103,7 +98,7 @@ void CSession::DisposeDecrypter()
103
98
| initialize
104
99
+---------------------------------------------------------------------*/
105
100
106
- bool CSession::Initialize (std::string manifestUrl)
101
+ bool SESSION:: CSession::Initialize (std::string manifestUrl)
107
102
{
108
103
m_reprChooser = CHOOSER::CreateRepresentationChooser ();
109
104
@@ -196,7 +191,7 @@ bool CSession::Initialize(std::string manifestUrl)
196
191
return InitializePeriod (isSessionOpened);
197
192
}
198
193
199
- void CSession::CheckHDCP ()
194
+ void SESSION:: CSession::CheckHDCP ()
200
195
{
201
196
// ! @todo: is needed to implement an appropriate CP check to
202
197
// ! remove HDCPOVERRIDE setting workaround
@@ -238,9 +233,9 @@ void CSession::CheckHDCP()
238
233
}
239
234
}
240
235
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)
244
239
{
245
240
auto & drmPropCfg = CSrvBroker::GetKodiProps ().GetDrmConfig ();
246
241
@@ -318,7 +313,7 @@ bool CSession::PreInitializeDRM(std::string& challengeB64,
318
313
return true ;
319
314
}
320
315
321
- bool CSession::InitializeDRM (bool addDefaultKID /* = false */ )
316
+ bool SESSION:: CSession::InitializeDRM (bool addDefaultKID /* = false */ )
322
317
{
323
318
bool isSecureVideoSession{false };
324
319
m_cdmSessions.resize (m_adaptiveTree->m_currentPeriod ->GetPSSHSets ().size ());
@@ -519,7 +514,7 @@ bool CSession::InitializeDRM(bool addDefaultKID /* = false */)
519
514
return true ;
520
515
}
521
516
522
- bool CSession::InitializePeriod (bool isSessionOpened /* = false */ )
517
+ bool SESSION:: CSession::InitializePeriod (bool isSessionOpened /* = false */ )
523
518
{
524
519
bool isPsshChanged{true };
525
520
bool isReusePssh{true };
@@ -625,11 +620,11 @@ bool CSession::InitializePeriod(bool isSessionOpened /* = false */)
625
620
return true ;
626
621
}
627
622
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)
633
628
{
634
629
m_streams.push_back (std::make_unique<CStream>(m_adaptiveTree, adp, initialRepr));
635
630
@@ -687,7 +682,7 @@ void CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
687
682
UpdateStream (stream);
688
683
}
689
684
690
- void CSession::UpdateStream (CStream& stream)
685
+ void SESSION:: CSession::UpdateStream (CStream& stream)
691
686
{
692
687
// On this method we set stream info provided by manifest parsing, but these info could be
693
688
// changed by sample readers just before the start of playback by using GetInformation() methods
@@ -877,7 +872,7 @@ void CSession::UpdateStream(CStream& stream)
877
872
stream.m_info .SetCodecInternalName (codecStr);
878
873
}
879
874
880
- void CSession::PrepareStream (CStream* stream)
875
+ void SESSION:: CSession::PrepareStream (CStream* stream)
881
876
{
882
877
if (!m_adaptiveTree->IsReqPrepareStream ())
883
878
return ;
@@ -942,7 +937,7 @@ const char* SESSION::CSession::GetCDMSession(unsigned int index)
942
937
return m_cdmSessions[index ].m_cdmSessionStr ;
943
938
}
944
939
945
- uint64_t CSession::PTSToElapsed (uint64_t pts)
940
+ uint64_t SESSION:: CSession::PTSToElapsed (uint64_t pts)
946
941
{
947
942
if (m_timingStream)
948
943
{
@@ -968,7 +963,7 @@ uint64_t CSession::PTSToElapsed(uint64_t pts)
968
963
return pts;
969
964
}
970
965
971
- uint64_t CSession::GetTimeshiftBufferStart ()
966
+ uint64_t SESSION:: CSession::GetTimeshiftBufferStart ()
972
967
{
973
968
if (m_timingStream)
974
969
{
@@ -985,7 +980,7 @@ uint64_t CSession::GetTimeshiftBufferStart()
985
980
}
986
981
987
982
// TODO: clean this up along with seektime
988
- void CSession::StartReader (
983
+ void SESSION:: CSession::StartReader (
989
984
CStream* stream, uint64_t seekTime, int64_t ptsDiff, bool preceeding, bool timing)
990
985
{
991
986
ISampleReader* streamReader = stream->GetReader ();
@@ -1013,12 +1008,12 @@ void CSession::StartReader(
1013
1008
m_changed = true ;
1014
1009
}
1015
1010
1016
- void CSession::OnScreenResChange ()
1011
+ void SESSION:: CSession::OnScreenResChange ()
1017
1012
{
1018
1013
m_reprChooser->OnUpdateScreenRes ();
1019
1014
};
1020
1015
1021
- bool CSession::GetNextSample (ISampleReader*& sampleReader)
1016
+ bool SESSION:: CSession::GetNextSample (ISampleReader*& sampleReader)
1022
1017
{
1023
1018
CStream* res{nullptr };
1024
1019
CStream* waiting{nullptr };
@@ -1083,7 +1078,7 @@ bool CSession::GetNextSample(ISampleReader*& sampleReader)
1083
1078
return false ;
1084
1079
}
1085
1080
1086
- bool CSession::SeekTime (double seekTime, unsigned int streamId, bool preceeding)
1081
+ bool SESSION:: CSession::SeekTime (double seekTime, unsigned int streamId, bool preceeding)
1087
1082
{
1088
1083
bool ret{false };
1089
1084
@@ -1220,7 +1215,7 @@ bool CSession::SeekTime(double seekTime, unsigned int streamId, bool preceeding)
1220
1215
return ret;
1221
1216
}
1222
1217
1223
- void CSession::OnDemuxRead ()
1218
+ void SESSION:: CSession::OnDemuxRead ()
1224
1219
{
1225
1220
if (m_adaptiveTree->IsChangingPeriod () && m_adaptiveTree->IsChangingPeriodDone ())
1226
1221
{
@@ -1234,7 +1229,7 @@ void CSession::OnDemuxRead()
1234
1229
}
1235
1230
}
1236
1231
1237
- void CSession::OnSegmentChanged (adaptive::AdaptiveStream* adStream)
1232
+ void SESSION:: CSession::OnSegmentChanged (adaptive::AdaptiveStream* adStream)
1238
1233
{
1239
1234
for (auto & stream : m_streams)
1240
1235
{
@@ -1251,7 +1246,7 @@ void CSession::OnSegmentChanged(adaptive::AdaptiveStream* adStream)
1251
1246
}
1252
1247
}
1253
1248
1254
- void CSession::OnStreamChange (adaptive::AdaptiveStream* adStream)
1249
+ void SESSION:: CSession::OnStreamChange (adaptive::AdaptiveStream* adStream)
1255
1250
{
1256
1251
for (auto & stream : m_streams)
1257
1252
{
@@ -1263,7 +1258,38 @@ void CSession::OnStreamChange(adaptive::AdaptiveStream* adStream)
1263
1258
}
1264
1259
}
1265
1260
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)
1267
1293
{
1268
1294
for (std::vector<CCdmSession>::iterator b (m_cdmSessions.begin () + 1 ), e (m_cdmSessions.end ());
1269
1295
b != e; ++b)
@@ -1274,7 +1300,7 @@ std::shared_ptr<Adaptive_CencSingleSampleDecrypter> CSession::GetSingleSampleDec
1274
1300
return nullptr ;
1275
1301
}
1276
1302
1277
- uint32_t CSession::GetIncludedStreamMask () const
1303
+ uint32_t SESSION:: CSession::GetIncludedStreamMask () const
1278
1304
{
1279
1305
// ! @todo: this conversion must be reworked can easily be broken and cause hidden problems
1280
1306
const INPUTSTREAM_TYPE adp2ips[] = {INPUTSTREAM_TYPE_NONE, INPUTSTREAM_TYPE_VIDEO,
@@ -1288,7 +1314,7 @@ uint32_t CSession::GetIncludedStreamMask() const
1288
1314
return res;
1289
1315
}
1290
1316
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
1292
1318
{
1293
1319
if (keySystem == DRM::KS_WIDEVINE)
1294
1320
return STREAM_CRYPTO_KEY_SYSTEM_WIDEVINE;
@@ -1318,15 +1344,15 @@ int CSession::GetChapter() const
1318
1344
return -1 ;
1319
1345
}
1320
1346
1321
- int CSession::GetChapterCount () const
1347
+ int SESSION:: CSession::GetChapterCount () const
1322
1348
{
1323
1349
if (m_adaptiveTree && m_adaptiveTree->m_periods .size () > 1 )
1324
1350
return static_cast <int >(m_adaptiveTree->m_periods .size ());
1325
1351
1326
1352
return 0 ;
1327
1353
}
1328
1354
1329
- std::string CSession::GetChapterName (int ch) const
1355
+ std::string SESSION:: CSession::GetChapterName (int ch) const
1330
1356
{
1331
1357
if (m_adaptiveTree)
1332
1358
{
@@ -1338,7 +1364,7 @@ std::string CSession::GetChapterName(int ch) const
1338
1364
return " [Unknown]" ;
1339
1365
}
1340
1366
1341
- int64_t CSession::GetChapterPos (int ch) const
1367
+ int64_t SESSION:: CSession::GetChapterPos (int ch) const
1342
1368
{
1343
1369
int64_t sum{0 };
1344
1370
--ch;
@@ -1352,7 +1378,7 @@ int64_t CSession::GetChapterPos(int ch) const
1352
1378
return sum / STREAM_TIME_BASE;
1353
1379
}
1354
1380
1355
- uint64_t CSession::GetChapterStartTime () const
1381
+ uint64_t SESSION:: CSession::GetChapterStartTime () const
1356
1382
{
1357
1383
uint64_t start_time = 0 ;
1358
1384
for (std::unique_ptr<CPeriod>& p : m_adaptiveTree->m_periods )
@@ -1365,7 +1391,7 @@ uint64_t CSession::GetChapterStartTime() const
1365
1391
return start_time;
1366
1392
}
1367
1393
1368
- int CSession::GetPeriodId () const
1394
+ int SESSION:: CSession::GetPeriodId () const
1369
1395
{
1370
1396
if (m_adaptiveTree)
1371
1397
{
@@ -1384,7 +1410,7 @@ int CSession::GetPeriodId() const
1384
1410
return -1 ;
1385
1411
}
1386
1412
1387
- bool CSession::SeekChapter (int ch)
1413
+ bool SESSION:: CSession::SeekChapter (int ch)
1388
1414
{
1389
1415
if (m_adaptiveTree->IsChangingPeriod ())
1390
1416
return true ;
@@ -1412,10 +1438,10 @@ bool CSession::SeekChapter(int ch)
1412
1438
return false ;
1413
1439
}
1414
1440
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)
1419
1445
{
1420
1446
auto initialRepr = m_reprChooser->GetRepresentation (psshSet.adaptation_set_ );
1421
1447
0 commit comments