forked from xbmc/inputstream.adaptive
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
654 lines (552 loc) · 22.5 KB
/
main.cpp
File metadata and controls
654 lines (552 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/*
* Copyright (C) 2016 peak3d (http://www.peak3d.de)
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "main.h"
#include "CompResources.h"
#include "CompKodiProps.h"
#include "SrvBroker.h"
#include "Stream.h"
#include "utils/GUIUtils.h"
#include "utils/ThreadPool.h"
#include "utils/log.h"
using namespace PLAYLIST;
using namespace SESSION;
CInputStreamAdaptive::CInputStreamAdaptive(const kodi::addon::IInstanceInfo& instance)
: CInstanceInputStream(instance)
{
CSrvBroker::GetInstance()->Initialize();
}
ADDON_STATUS CInputStreamAdaptive::CreateInstance(const kodi::addon::IInstanceInfo& instance,
KODI_ADDON_INSTANCE_HDL& hdl)
{
if (instance.IsType(ADDON_INSTANCE_VIDEOCODEC))
{
hdl = new CVideoCodecAdaptive(instance, this);
return ADDON_STATUS_OK;
}
return ADDON_STATUS_NOT_IMPLEMENTED;
}
bool CInputStreamAdaptive::Open(const kodi::addon::InputstreamProperty& props)
{
LOG::Log(LOGDEBUG, "Open()");
CSrvBroker::GetInstance()->InitStage1(props.GetProperties());
m_session = std::make_shared<CSession>();
SResult ret = m_session->Initialize(props.GetURL());
if (ret.IsFailed())
{
LOG::Log(LOGERROR, ret.Message().c_str());
UTILS::GUI::ErrorDialog(ret.Message());
m_session = nullptr;
return false;
}
return true;
}
void CInputStreamAdaptive::Close(void)
{
LOG::Log(LOGDEBUG, "Close()");
m_session = nullptr;
UTILS::THREAD::GlobalThreadPool.Reset();
CSrvBroker::GetInstance()->Deinitialize();
}
bool CInputStreamAdaptive::GetStreamIds(std::vector<unsigned int>& ids)
{
LOG::Log(LOGDEBUG, "GetStreamIds()");
if (!m_session)
return false;
const unsigned int streamCount = m_session->GetStreamCount();
if (streamCount > INPUTSTREAM_MAX_STREAM_COUNT)
{
LOG::LogF(
LOGWARNING,
"Exceeded the maximum limit of %i streams. %u streams have been excluded from playback",
INPUTSTREAM_MAX_STREAM_COUNT, streamCount - INPUTSTREAM_MAX_STREAM_COUNT);
}
for (unsigned int i(0); i < INPUTSTREAM_MAX_STREAM_COUNT && i < streamCount; ++i)
{
auto stream = m_session->GetStream(i);
if (!stream)
{
LOG::LogF(LOGERROR, "Cannot get the stream from sid %u", i);
continue;
}
if (stream->m_isValid &&
(m_session->GetMediaTypeMask() &
static_cast<uint8_t>(1) << static_cast<int>(stream->m_adStream.GetStreamType())))
{
if (m_session->GetMediaTypeMask() != 0xFF)
{
const CRepresentation* rep = stream->m_adStream.getRepresentation();
if (rep->IsIncludedStream())
continue;
}
ids.emplace_back(m_session->GetStreamIdFromIndex(i));
}
}
return !ids.empty();
}
void CInputStreamAdaptive::GetCapabilities(kodi::addon::InputstreamCapabilities& caps)
{
LOG::Log(LOGDEBUG, "GetCapabilities()");
uint32_t mask = INPUTSTREAM_SUPPORTS_IDEMUX | INPUTSTREAM_SUPPORTS_IDISPLAYTIME |
INPUTSTREAM_SUPPORTS_IPOSTIME | INPUTSTREAM_SUPPORTS_SEEK |
INPUTSTREAM_SUPPORTS_PAUSE;
#if INPUTSTREAM_VERSION_LEVEL > 1
mask |= INPUTSTREAM_SUPPORTS_ICHAPTER;
#endif
caps.SetMask(mask);
}
bool CInputStreamAdaptive::GetStream(int streamid, kodi::addon::InputstreamInfo& info)
{
// GetStream is called by Kodi twice times, before and after OpenStream.
LOG::Log(LOGDEBUG, "GetStream(%d)", streamid);
// Return false prevents this stream from loading, but does not stop playback,
// Kodi core will continue to request another stream of same type (a/v)
// as long as one is successful
return m_session->OnGetStream(streamid, info);
//! @todo: Kodi VideoPlayer stream fallback bug / problem:
//! if a video stream for some reason does not start (OpenStream/GetStream fails) VideoPlayer has no logic to open the next video stream based of stream ID
//! this is a big problem (can be reproduced using "Stream selection type" to "Manual OSD" and hack a bit the code)
//! because VP seem to always take the first stream ID (1001) in index order, instead to continue with the next stream ID.
//! For example if you are playing stream ID 1022 and fails, VP try to play always 1001 instead of 1023.
//! This causes the following problems:
//! - impossibility to keep a consistent video codec to be used
//! - impossibility to have a stable video quality fallback in a decreasing manner. We could sort the list of streams decreasingly by resolution and bandwidth
//! but dont solve in full the problem in case of multicodec's because VP will mix all.
//! I'm talking about "decreasing manner" quality also because with DRM if 4k / FULLHD doesn't work you need a fallback to lower quality.
//! this needs to be fixed in the Kodi core VP
}
void CInputStreamAdaptive::EnableStream(int streamid, bool enable)
{
LOG::Log(LOGDEBUG, "EnableStream(%d: %s)", streamid, enable ? "true" : "false");
if (!m_session)
return;
auto stream = m_session->GetStream(m_session->GetStreamIndexFromId(streamid));
if (!enable && stream && stream->IsEnabled())
{
stream->UnlinkStream();
m_session->EnableStream(stream, false);
}
}
// OpenStream method notes:
// - This method is called:
// - At playback start
// - At chapter/period change (DEMUX_SPECIALID_STREAMCHANGE)
// - At stream quality change (DEMUX_SPECIALID_STREAMCHANGE) by "adaptive" streaming or from Kodi OSD
// - Due to CDVDDemuxClient::ParsePacket (Kodi core) while in playback, see "Kodi core is attempting to reopen the stream" below
// - The "streamid" requested can be influenced from preferences set in Kodi settings (e.g. language).
// - If the requested "streamid" fails to open on the Kodi core side (after OpenStream callback, e.g. for missing extradata)
// Kodi core will try to (fallback) open another video "streamid", this will happen recursively until success.
// - The OpenStream method not only opens the stream, but also implicitly enables it
// so don't exists a EnableStream callback to explicitly enable the stream after the opening,
// EnableStream method is used by VP only to disable the stream
// which can happen immediately after opening (e.g. subtitles disabled on playback startup).
// - If a stream info property has been changed, you need to return "true" on OpenStream
// to allow Kodi core to update its internal properties with our changes.
bool CInputStreamAdaptive::OpenStream(int streamid)
{
LOG::Log(LOGDEBUG, "OpenStream(%d)", streamid);
if (!m_session)
return false;
auto stream = m_session->GetStream(m_session->GetStreamIndexFromId(streamid));
if (!stream)
return false;
const bool isStreamChanged{stream->m_adStream.StreamChanged()};
if (stream->IsEnabled())
{
// Stream quality changed (by "adaptive" streaming, not OSD)
if (isStreamChanged)
{
stream->Reset();
stream->m_adStream.Reset();
}
else // Kodi core is attempting to reopen the stream
{
// If a stream was already opened means that Kodi core is attempting to reopen
// ALL streams just for his internal purposes and this callback must be avoided.
//! @todo: This issue appears to have been introduced with PR https://github.com/xbmc/xbmc/pull/10097
//! when "changes" var differs from the stored value, it force to reopen all streams,
//! where in the past was reopening only the associated stream.
//!
//! The request to reopen a stream is unclear,
//! there is no reason to open a stream already opened, because the EnableStream(false) callback was never sent
//! so the state of the addon is still unchanged.
//!
//! Looks like that the "changes" var is modified by CDVDDemuxClient::ParsePacket while in playback
//! https://github.com/xbmc/xbmc/blob/d1a1d48c3cb3722d39264ffdd8132f755ffecd27/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp#L119
//! maybe this is required for some other CDVDInputStream interface(?) but not for CInputStreamAddon, this should be at least optional
//! since can easily leads to playback problems such as stuttering because reopening all streams can be an heavy task to do while playback
//! moreover for subtitles case this is even more messed up, since they can be disabled... (EnableStream callback)
// NOTE: you cannot rely on stream->IsEnabled() for all stream types because a playback can start with subtitles disabled
// so this leads to a mess between OpenStream and EnableStream callbacks causing abnormal behaviors in the addon components.
// As workaround we detect the first stream opened twice times (OpenStream for subtitles type is always last),
// then we set m_checkCoreReopen to true in order to skip all the following callbacks to OpenStream,
// and when we receive the first DemuxRead callback means that Kodi core has finished all openings,
// then we reset m_checkCoreReopen for the next round of OpenStream callbacks
m_checkCoreReopen = true;
}
}
if (m_checkCoreReopen && !isStreamChanged)
{
LOG::Log(LOGDEBUG, "OpenStream(%d): The stream has already been opened", streamid);
return false;
}
CRepresentation* rep = stream->m_adStream.getRepresentation();
// "included" streams are audio streams embedded into a video stream (multiplexed).
// How works:
// The manifest parser create a "dummy" (AdaptationSet + Representation) for the audio track,
// this dummy stream will be shared between all video representations
// so needs to be linked to the video stream currently in use,
// and if the video quality changes, must be re-linked with the current video.
// The behavior of how works the "dummy" stream changes depending on the type of demuxer used,
// in general way in this case the CStream dont use the AdaptiveStream class
// but could have a SampleReader that somewhat read the data from the video package.
//! @todo: HLS TS with multiple "included" audio streams, not implemented, more likely
//! its needed implement a way to get PIDs of each stream from segment, and map them to the manifest variants
if (rep->IsIncludedStream())
{
auto videoStream = m_session->GetCurrentVideoStream();
if (!videoStream)
{
LOG::LogF(LOGERROR, "Cannot get video stream to link the included stream id: %i",
streamid);
return false;
}
stream->LinkStream(videoStream, streamid);
m_session->EnableStream(stream, true);
return true;
}
if (!m_session->PrepareStream(*stream, m_lastPts))
{
return false;
}
if (stream->GetReader()->GetType() == ISampleReader::Type::WebM &&
!stream->m_info.GetCryptoSession().GetSessionId().empty())
{
//! @todo: it should be implemented on the WebM demuxer side and verify if appropriate changes are required on CDM
LOG::LogF(LOGERROR, "WebM container with DRM encrypted stream is not supported");
return false;
}
stream->GetReader()->SetStreamId(stream->m_info.GetStreamType(), streamid);
// In case of video quality change (OSD)
// re-link "included" streams to current opened stream
// is assumed that "included" streams are still readable from the new selected stream
if (stream->m_info.GetStreamType() == INPUTSTREAM_TYPE_VIDEO)
{
for (unsigned int i{0}; i < m_session->GetStreamCount(); ++i)
{
auto sesStream = m_session->GetStream(i);
if (!sesStream || !sesStream->IsEnabled())
continue;
if (sesStream->IsLinkedToStreamType(INPUTSTREAM_TYPE_VIDEO))
{
sesStream->UnlinkStream();
sesStream->LinkStream(stream, m_session->GetStreamIdFromIndex(i));
}
}
}
m_session->EnableStream(stream, true);
// If stream use DRM always update stream info
const bool isInfoChanged = stream->GetReader()->GetInformation(stream->m_info) ||
!stream->m_info.GetCryptoSession().GetSessionId().empty();
return isInfoChanged;
}
DEMUX_PACKET* CInputStreamAdaptive::DemuxRead(void)
{
if (!m_session)
return NULL;
m_session->OnDemuxRead();
// On Kodi core CDVDDemuxClient::ParsePacket occurs after the DemuxRead callback
// since it can cause to reopen all streams, reset the check just before
m_checkCoreReopen = false;
ISampleReader* sr{nullptr};
if (m_session->GetNextSample(sr))
{
DEMUX_PACKET* p{nullptr};
if (m_session->CheckChange())
{
// Adaptive stream has switched stream (representation) quality
m_lastPts = PLAYLIST::NO_PTS_VALUE;
p = AllocateDemuxPacket(0);
p->iStreamId = DEMUX_SPECIALID_STREAMCHANGE;
LOG::Log(LOGDEBUG, "DEMUX_SPECIALID_STREAMCHANGE (stream quality changed)");
return p;
}
if (sr)
{
AP4_Size iSize(sr->GetSampleDataSize());
const AP4_UI08* pData(sr->GetSampleData());
bool srHaveData{iSize > 0 && pData};
if (sr->IsEncrypted() && srHaveData)
{
const unsigned int numSubSamples(*(reinterpret_cast<const unsigned int*>(pData)));
pData += sizeof(numSubSamples);
p = AllocateEncryptedDemuxPacket(iSize, numSubSamples);
std::memcpy(p->cryptoInfo->clearBytes, pData, numSubSamples * sizeof(uint16_t));
pData += (numSubSamples * sizeof(uint16_t));
std::memcpy(p->cryptoInfo->cipherBytes, pData, numSubSamples * sizeof(uint32_t));
pData += (numSubSamples * sizeof(uint32_t));
std::memcpy(p->cryptoInfo->iv, pData, 16);
pData += 16;
std::memcpy(p->cryptoInfo->kid, pData, 16);
pData += 16;
iSize -= static_cast<AP4_Size>(pData - sr->GetSampleData());
CryptoInfo cryptoInfo = sr->GetReaderCryptoInfo();
p->cryptoInfo->numSubSamples = numSubSamples;
p->cryptoInfo->cryptBlocks = cryptoInfo.m_cryptBlocks;
p->cryptoInfo->skipBlocks = cryptoInfo.m_skipBlocks;
p->cryptoInfo->mode = static_cast<uint16_t>(cryptoInfo.m_mode);
p->cryptoInfo->flags = 0;
}
else
p = AllocateDemuxPacket(iSize);
if (srHaveData)
{
m_lastPts = sr->DTSorPTSManifest();
p->dts = static_cast<double>(sr->DTS());
p->pts = static_cast<double>(sr->PTS());
p->duration = static_cast<double>(sr->GetDuration());
p->iStreamId = sr->GetStreamId();
p->iGroupId = 0;
p->iSize = iSize;
std::memcpy(p->pData, pData, iSize);
}
//LOG::Log(LOGDEBUG, "DTS: %0.4f, PTS:%0.4f, ID: %u SZ: %d", p->dts, p->pts, p->iStreamId, p->iSize);
// Start reading the next sample
sr->ReadSampleAsync();
}
else // We are waiting for the data, so return an empty packet
{
p = AllocateDemuxPacket(0);
}
return p;
}
// Ends here when GetNextSample fails due to sample reader in EOS state or stream disabled
// that could means, in case of multi-periods streams, that segments are ended
// in the current period and its needed to switch to the next period
if (m_session->SeekChapter(m_session->GetChapter() + 1))
{
// Switched to new period / chapter
m_lastPts = PLAYLIST::NO_PTS_VALUE;
// Disable streams from the old period (kodi core never close/disable streams...)
for (unsigned int i(0); i < INPUTSTREAM_MAX_STREAM_COUNT && i < m_session->GetStreamCount();
++i)
{
EnableStream(m_session->GetStreamIdFromIndex(i), false);
}
// Initialize the new period
m_session->InitializePeriod();
DEMUX_PACKET* p = AllocateDemuxPacket(0);
p->iStreamId = DEMUX_SPECIALID_STREAMCHANGE;
LOG::Log(LOGDEBUG, "DEMUX_SPECIALID_STREAMCHANGE (chapter changed)");
return p;
}
return NULL;
}
// Accurate search (PTS based)
bool CInputStreamAdaptive::DemuxSeekTime(double time, bool backwards, double& startpts)
{
return true;
}
void CInputStreamAdaptive::SetVideoResolution(unsigned int width,
unsigned int height,
unsigned int maxWidth,
unsigned int maxHeight)
{
CSrvBroker::GetResources().SetScreenInfo({static_cast<int>(width), static_cast<int>(height),
static_cast<int>(maxWidth),
static_cast<int>(maxHeight)});
// SetVideoResolution method is initially called before CInputStreamAdaptive::Open so there is no session yet
// After that, other callbacks may be made during playback (e.g. for window resize)
if (m_session)
m_session->OnScreenResChange();
}
bool CInputStreamAdaptive::PosTime(int ms)
{
// Note: VP may require a seek (ms) even beyond the total duration of the media.
// Note: When you return false VP will continue to request packets with DemuxRead callbacks
// VP should expect to continue playback from the last PTS fed (as if the seek had not occurred)
// or you can stop playback by forcibly stop the packet feed from DemuxRead callbacks.
if (!m_session)
return false;
LOG::Log(LOGINFO, "PosTime (%d)", ms);
const uint64_t currentTimeMs = m_session->GetElapsedTimeMs();
bool isError{false};
if (m_session->SeekTime(static_cast<double>(ms) * 0.001f, isError))
return true;
if (!isError)
{
// If for some reason the seek operation fails without errors
// try to restore the streams/readers to previous (current) position
LOG::Log(LOGWARNING, "PosTime - Seek failed. Attempt to restore previous %llu ms position",
currentTimeMs);
if (m_session->SeekTime(static_cast<double>(currentTimeMs) * 0.001f, isError))
return false; // returns false because the initially requested seek was unsuccessful
}
// A problem has occurred or EOS, force stop playback
LOG::Log(LOGDEBUG, "PosTime - Cannot seek at %d ms position.", ms);
m_session->DeleteStreams();
return false;
}
int CInputStreamAdaptive::GetTotalTime()
{
if (!m_session)
return 0;
return static_cast<int>(m_session->GetTotalTimeMs());
}
int CInputStreamAdaptive::GetTime()
{
if (!m_session)
return 0;
int timeMs = static_cast<int>(m_session->GetElapsedTimeMs());
return timeMs;
}
bool CInputStreamAdaptive::IsRealTimeStream()
{
return m_session && m_session->IsLive();
}
#if INPUTSTREAM_VERSION_LEVEL > 1
int CInputStreamAdaptive::GetChapter()
{
// Provide the current chapter number
// chapter numbering starts from 1, specify 0 for no chapter
return m_session ? m_session->GetChapter() : 0;
}
int CInputStreamAdaptive::GetChapterCount()
{
if (m_session)
{
const int count = m_session->GetChapterCount();
if (count > 1)
return count;
}
// Return 0 to prevent Kodi core from handling chapters
return 0;
}
const char* CInputStreamAdaptive::GetChapterName(int ch)
{
if (!m_session)
return nullptr;
return m_session->GetChapterName(ch);
}
int64_t CInputStreamAdaptive::GetChapterPos(int ch)
{
return m_session ? m_session->GetChapterPos(ch) : 0;
}
bool CInputStreamAdaptive::SeekChapter(int ch)
{
return m_session ? m_session->SeekChapter(ch) : false;
}
#endif
/*****************************************************************************************************/
CVideoCodecAdaptive::CVideoCodecAdaptive(const kodi::addon::IInstanceInfo& instance)
: CInstanceVideoCodec(instance), m_name("inputstream.adaptive.decoder")
{
}
CVideoCodecAdaptive::CVideoCodecAdaptive(const kodi::addon::IInstanceInfo& instance,
CInputStreamAdaptive* parent)
: CInstanceVideoCodec(instance), m_session(parent->GetSession())
{
}
CVideoCodecAdaptive::~CVideoCodecAdaptive()
{
// When the addon is about to be terminated
// CVideoCodecAdaptive instance will be destroyed before of CInputStreamAdaptive::Close() call
LOG::Log(LOGDEBUG, "CVideoCodecAdaptive::~CVideoCodecAdaptive");
m_drmDecoder->DisposeDecoder();
m_drmDecoder = nullptr;
}
bool CVideoCodecAdaptive::Open(const kodi::addon::VideoCodecInitdata& initData)
{
if (!m_session)
return false;
if ((initData.GetCodecType() == VIDEOCODEC_H264 || initData.GetCodecType() == VIDEOCODEC_AV1) &&
initData.GetExtraDataSize() == 0 && !m_waitExtraData)
{
LOG::Log(LOGINFO, "VideoCodec::Open: Wait ExtraData");
m_waitExtraData = true;
return true;
}
m_waitExtraData = false;
LOG::Log(LOGINFO, "VideoCodec::Open");
m_name = "inputstream.adaptive";
switch (initData.GetCodecType())
{
case VIDEOCODEC_VP8:
m_name += ".vp8";
break;
case VIDEOCODEC_H264:
m_name += ".h264";
break;
case VIDEOCODEC_VP9:
m_name += ".vp9";
break;
case VIDEOCODEC_AV1:
m_name += ".av1";
break;
default:
break;
}
m_name += ".decoder";
const std::string sessionId = initData.GetCryptoSession().GetSessionId();
auto drmSession = m_session->GetDRMEngine().GetSession(sessionId);
if (!drmSession)
{
LOG::LogF(LOGERROR, "Cannot get DRM session id: %s", sessionId.c_str());
return false;
}
m_drmDecoder = drmSession->drm;
return m_drmDecoder->OpenVideoDecoder(drmSession->decrypter, initData.GetCStructure());
}
bool CVideoCodecAdaptive::Reconfigure(const kodi::addon::VideoCodecInitdata& initData)
{
return false;
}
bool CVideoCodecAdaptive::AddData(const DEMUX_PACKET& packet)
{
if (!m_drmDecoder)
return false;
return m_drmDecoder->DecryptAndDecodeVideo(dynamic_cast<kodi::addon::CInstanceVideoCodec*>(this),
&packet) != VC_ERROR;
}
VIDEOCODEC_RETVAL CVideoCodecAdaptive::GetPicture(VIDEOCODEC_PICTURE& picture)
{
if (!m_drmDecoder)
return VIDEOCODEC_RETVAL::VC_ERROR;
static VIDEOCODEC_RETVAL vrvm[] = {VIDEOCODEC_RETVAL::VC_NONE, VIDEOCODEC_RETVAL::VC_ERROR,
VIDEOCODEC_RETVAL::VC_BUFFER, VIDEOCODEC_RETVAL::VC_PICTURE,
VIDEOCODEC_RETVAL::VC_EOF};
return vrvm[m_drmDecoder->VideoFrameDataToPicture(dynamic_cast<kodi::addon::CInstanceVideoCodec*>(this),
&picture)];
}
void CVideoCodecAdaptive::Reset()
{
if (!m_drmDecoder)
return;
m_drmDecoder->ResetVideo();
}
/*****************************************************************************************************/
class ATTR_DLL_LOCAL CMyAddon : public kodi::addon::CAddonBase
{
public:
CMyAddon();
ADDON_STATUS CreateInstance(const kodi::addon::IInstanceInfo& instance,
KODI_ADDON_INSTANCE_HDL& hdl) override;
};
CMyAddon::CMyAddon()
{
}
ADDON_STATUS CMyAddon::CreateInstance(const kodi::addon::IInstanceInfo& instance,
KODI_ADDON_INSTANCE_HDL& hdl)
{
if (instance.IsType(ADDON_INSTANCE_INPUTSTREAM))
{
hdl = new CInputStreamAdaptive(instance);
return ADDON_STATUS_OK;
}
return ADDON_STATUS_NOT_IMPLEMENTED;
}
ADDONCREATOR(CMyAddon);