Skip to content

Commit fe7479c

Browse files
committed
Add dvcc parsing and store in inputstream
1 parent e725415 commit fe7479c

10 files changed

Lines changed: 87 additions & 32 deletions

File tree

lib/cdm/cdm/media/base/cdm_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ namespace media {
1515
// |requestMediaKeySystemAccess|. This is in some sense the Chromium-side
1616
// counterpart of Blink's WebMediaKeySystemConfiguration.
1717
struct CdmConfig {
18-
CdmConfig(bool distinctive_identifier=false, bool persistent_state=false)
18+
CdmConfig(bool distinctive_identifier=false, bool persistent_state=false, bool hw_secure_codecs=false)
1919
:allow_distinctive_identifier(distinctive_identifier)
2020
, allow_persistent_state(persistent_state)
21-
, use_hw_secure_codecs(false){};
21+
, use_hw_secure_codecs(hw_secure_codecs){};
2222

2323
// Allow access to a distinctive identifier.
2424
bool allow_distinctive_identifier;

lib/cdm/cdm/media/cdm/cdm_adapter.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include "../../debug.h"
1212
#include "../base/limits.h"
13-
#include "SrvBroker.h"
14-
#include "CompSettings.h"
1513

1614
#include <chrono>
1715
#include <cstring>
@@ -252,27 +250,20 @@ bool CdmAdapter::Initialize()
252250

253251
if (cdm12_ || cdm11_ || cdm10_)
254252
{
255-
bool use_hw_secure_codecs = false;
256-
257-
#ifdef TARGET_WEBOS
258-
if(CSrvBroker::GetSettings().IsSecurePathOverride())
259-
use_hw_secure_codecs = true;
260-
#endif
261-
262253
if (cdm12_)
263254
{
264255
cdm12_->Initialize(cdm_config_.allow_distinctive_identifier,
265-
cdm_config_.allow_persistent_state, use_hw_secure_codecs);
256+
cdm_config_.allow_persistent_state, cdm_config_.use_hw_secure_codecs);
266257
}
267258
else if (cdm11_)
268259
{
269260
cdm11_->Initialize(cdm_config_.allow_distinctive_identifier,
270-
cdm_config_.allow_persistent_state, use_hw_secure_codecs);
261+
cdm_config_.allow_persistent_state, cdm_config_.use_hw_secure_codecs);
271262
}
272263
else if (cdm10_)
273264
{
274265
cdm10_->Initialize(cdm_config_.allow_distinctive_identifier,
275-
cdm_config_.allow_persistent_state, use_hw_secure_codecs);
266+
cdm_config_.allow_persistent_state, cdm_config_.use_hw_secure_codecs);
276267
}
277268

278269
// Wait for the CDM to be initialized

src/CompSettings.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ bool ADP::SETTINGS::CCompSettings::IsDebugVerbose() const
140140
return kodi::addon::GetSettingBoolean("debug.verbose");
141141
}
142142

143-
#ifdef TARGET_WEBOS
144143
bool ADP::SETTINGS::CCompSettings::IsSecurePathOverride() const
145144
{
146145
return kodi::addon::GetSettingBoolean("secure.path.override");
147146
}
148-
#endif

src/CompSettings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ class ATTR_DLL_LOCAL CCompSettings
7575
bool IsDebugManifest() const;
7676
bool IsDebugVerbose() const;
7777

78-
#ifdef TARGET_WEBOS
7978
bool IsSecurePathOverride() const;
80-
#endif
8179
};
8280

8381
} // namespace SETTINGS

src/common/AdaptiveCencSampleDecrypter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88

99
#include "AdaptiveDecrypter.h"
10+
<<<<<<< HEAD
11+
=======
12+
13+
>>>>>>> 380146c9 (Add dvcc parsing and store in inputstream)
1014
#include "decrypters/DrmEngineDefines.h"
1115

1216
#include <memory>

src/decrypters/widevine/WVCdmAdapter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ SResult CWVCdmAdapter::Initialize(const DRM::Config& config, CWVDecrypter* host)
8888
return SResultCode::ERROR;
8989
}
9090
std::string cdmPath;
91+
bool use_hw_secure_codecs = false;
92+
9193
#ifdef TARGET_WEBOS
94+
use_hw_secure_codecs = true;
9295
auto it = std::ranges::find_if(candidatePaths, [](std::string_view sv)
9396
{ return std::filesystem::exists(std::filesystem::path{sv}); });
9497

@@ -120,7 +123,7 @@ SResult CWVCdmAdapter::Initialize(const DRM::Config& config, CWVDecrypter* host)
120123

121124
auto cdmAdapter =
122125
std::make_shared<media::CdmAdapter>("com.widevine.alpha", cdmPath, basePath,
123-
media::CdmConfig(false, m_config.isPersistentStorage),
126+
media::CdmConfig(false, m_config.isPersistentStorage, use_hw_secure_codecs),
124127
dynamic_cast<media::CdmAdapterClient*>(this));
125128

126129
if (!cdmAdapter->LoadCDM())

src/decrypters/widevine/WVCencSingleSampleDecrypter.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ CWVCencSingleSampleDecrypter::CWVCencSingleSampleDecrypter(
7676
// prepare the promise before calling into CDM
7777
std::future<std::string> fut = m_cdmAdapter->PrepareSessionFuture(pid);
7878

79-
LOG::LogF(LOGDEBUG, "Creating widevine session with promise ID: %u", pid);
8079
m_cdmAdapter->GetCDM()->CreateSessionAndGenerateRequest(
8180
pid, cdm::SessionType::kTemporary, cdm::InitDataType::kCenc,
8281
m_pssh.data(), static_cast<uint32_t>(m_pssh.size()));
@@ -141,8 +140,7 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
141140
if (!caps.hdcpLimit)
142141
caps.hdcpLimit = m_resolutionLimit;
143142

144-
#ifdef TARGET_WEBOS
145-
// optional override for webOS required for L1
143+
// optional override for webOS required for L1
146144
if(CSrvBroker::GetSettings().IsSecurePathOverride()) {
147145
LOG::LogF(LOGDEBUG,
148146
"Overriding settings to: SSD_SECURE PATH | SSD_ANNEXB_REQUIRED | SSD_SECURE_DECODER");
@@ -152,7 +150,6 @@ void CWVCencSingleSampleDecrypter::GetCapabilities(const std::vector<uint8_t>& k
152150
caps.hdcpVersion = DRM::HDCP_V_MAX;
153151
return;
154152
}
155-
#endif
156153

157154
if ((caps.flags & DecrypterCapabilites::SSD_SUPPORTS_DECODING) != 0)
158155
{
@@ -477,7 +474,7 @@ void CWVCencSingleSampleDecrypter::RepackSubsampleData(AP4_DataBuffer& dataIn,
477474
{
478475
#ifdef TARGET_WEBOS
479476
// with kStreamTypeVideo we need to handle the SVP header so it is not lost
480-
if(streamType == cdm::StreamType::kStreamTypeVideo) {
477+
if(streamType == DRM::DRMMediaType::VIDEO) {
481478
const size_t encryptedBytes = bytesOfEncryptedData[subsamplePos];
482479
const size_t clearBytes = bytesOfCleartextData[subsamplePos];
483480

@@ -590,7 +587,7 @@ AP4_Result CWVCencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 poolId,
590587
dataIn, payload, subsampleCount, fragInfo, iv,
591588
bytesOfCleartextData, bytesOfEncryptedData, convertAnnexB, rebuiltSubs);
592589
if (res != AP4_SUCCESS) {
593-
LOG::LogF(LOGERROR, "[DecryptSampleData] ConvertToAnnexB failed: %d", res);
590+
LOG::LogF(LOGERROR, "ConvertToAnnexBandInject failed: %d", res);
594591
return res;
595592
}
596593
}
@@ -641,8 +638,6 @@ AP4_Result CWVCencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 poolId,
641638
// Prepare CDM input using rebuiltSubs
642639
cdm::InputBuffer_2 cdmIn;
643640
SetInput(cdmIn, payload, static_cast<uint32_t>(rebuiltSubs.size()), iv, fragInfo, rebuiltSubs);
644-
LOG::LogF(LOGDEBUG, "[DecryptSampleData] CDM input prepared [V=%d] subSampleCount=%u",
645-
streamType, static_cast<unsigned>(rebuiltSubs.size()));
646641

647642
const size_t header_cushion = 64;
648643
m_decryptOut.Reserve(payload.GetDataSize() + dataOut.GetDataSize() + header_cushion);
@@ -654,16 +649,14 @@ AP4_Result CWVCencSingleSampleDecrypter::DecryptSampleData(AP4_UI32 poolId,
654649

655650
CheckLicenseRenewal();
656651

657-
cdm::Status ret = m_cdmAdapter->GetCDM()->Decrypt(cdmIn, &cdmOut, streamType);
652+
cdm::Status ret = m_cdmAdapter->GetCDM()->Decrypt(cdmIn, &cdmOut, ToCdmStreamType(streamType));
658653
if (ret != cdm::kSuccess) {
659654
LOG::LogF(LOGERROR, "[DecryptSampleData] CDM->Decrypt failed, status=%d", static_cast<int>(ret));
660655
return AP4_ERROR_INVALID_FORMAT;
661656
}
662657

663658
// Prefix (if any) + SVP-wrapped payload
664659
dataOut.AppendData(m_decryptOut.GetData(), m_decryptOut.GetDataSize());
665-
LOG::LogF(LOGDEBUG, "[DecryptSampleData] Secure-path success, forwarding CDM output size=%zu",
666-
dataOut.GetDataSize());
667660
#else
668661
// Prefix (if IV) + raw payload
669662
dataOut.AppendData(payload.GetData(), payload.GetDataSize());
@@ -858,7 +851,6 @@ CWVCencSingleSampleDecrypter::ConvertToAnnexBandInject(
858851
packetIn[2] == 0x00 &&
859852
packetIn[3] == 0x01))
860853
{
861-
LOG::LogF(LOGDEBUG, "Injecting annex b header");
862854
dataOut.AppendData(annexbStartCode, 4);
863855
}
864856

src/decrypters/widevine/WVCencSingleSampleDecrypter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypter : public Adaptive_CencSingleSa
151151
bool convertAnnexB,
152152
std::vector<cdm::SubsampleEntry>& rebuiltSubs);
153153

154+
cdm::StreamType ToCdmStreamType(DRM::DRMMediaType stream_type);
155+
154156
uint32_t m_promiseId;
155157
bool m_isDrained;
156158

src/samplereader/FragmentedSampleReader.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ AP4_Result CFragmentedSampleReader::ReadSample()
135135
if (m_track->GetType() == AP4_Track::Type::TYPE_AUDIO)
136136
streamType = DRM::DRMMediaType::AUDIO;
137137

138+
#ifdef TARGET_WEBOS
139+
// if we are not in secure path mode, adding SVP header/meta data is not needed
140+
if(m_track->GetType() == AP4_Track::Type::TYPE_VIDEO &&
141+
(!CSrvBroker::GetSettings().IsSecurePathOverride()))
142+
{
143+
LOG::LogF(LOGDEBUG, "Overriding VIDEO as non-secure path to: kStreamTypeAudio");
144+
streamType = DRM::DRMMediaType::AUDIO;
145+
}
146+
#endif
147+
138148
AP4_Result result;
139149
if (!m_codecHandler->ReadNextSample(m_sample, m_sampleData))
140150
{
@@ -268,6 +278,11 @@ bool CFragmentedSampleReader::GetInformation(kodi::addon::InputstreamInfo& info)
268278

269279
isChanged |= m_codecHandler->GetInformation(info);
270280

281+
// store dvcc metadata
282+
if (auto dvcc = ParseDvcc()) {
283+
PopulateDvccMetadata(info, dvcc);
284+
}
285+
271286
m_bSampleDescChanged = false;
272287

273288
return isChanged;
@@ -511,7 +526,7 @@ void CFragmentedSampleReader::UpdateSampleDescription()
511526

512527
LOG::LogF(LOGDEBUG, "Codec fourcc: %s (%u)", CODEC::FourCCToString(desc->GetFormat()).c_str(),
513528
desc->GetFormat());
514-
529+
515530
if (AP4_DYNAMIC_CAST(AP4_AudioSampleDescription, desc))
516531
{
517532
// Audio sample of any format
@@ -590,3 +605,53 @@ void CFragmentedSampleReader::ParseTrafTfrf(AP4_UuidAtom* uuidAtom)
590605
m_observer->OnTFRFatom(time, duration, m_track->GetMediaTimeScale());
591606
}
592607
}
608+
609+
AP4_DvccAtom* CFragmentedSampleReader::ParseDvcc()
610+
{
611+
if (AP4_TrakAtom* trak = m_track->UseTrakAtom()) {
612+
if (auto mdia = AP4_DYNAMIC_CAST(AP4_ContainerAtom,
613+
trak->GetChild(AP4_ATOM_TYPE_MDIA, 0))) {
614+
if (auto minf = AP4_DYNAMIC_CAST(AP4_ContainerAtom,
615+
mdia->GetChild(AP4_ATOM_TYPE_MINF, 0))) {
616+
if (auto stbl = AP4_DYNAMIC_CAST(AP4_ContainerAtom,
617+
minf->GetChild(AP4_ATOM_TYPE_STBL, 0))) {
618+
if (auto stsd = AP4_DYNAMIC_CAST(AP4_ContainerAtom,
619+
stbl->GetChild(AP4_ATOM_TYPE_STSD, 0))) {
620+
for (auto* eitem = stsd->GetChildren().FirstItem(); eitem; eitem = eitem->GetNext()) {
621+
auto entry_ctn = AP4_DYNAMIC_CAST(AP4_ContainerAtom, eitem->GetData());
622+
623+
if (!entry_ctn) continue;
624+
AP4_Atom* dv_atom = entry_ctn->GetChild(AP4_ATOM_TYPE_DVCC, 0);
625+
if (!dv_atom) dv_atom = entry_ctn->GetChild(AP4_ATOM_TYPE_DVVC, 0);
626+
if (!dv_atom) continue;
627+
628+
if (auto dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, dv_atom)) {
629+
return dvcc;
630+
}
631+
}
632+
}
633+
}
634+
}
635+
}
636+
}
637+
638+
return nullptr;
639+
}
640+
641+
void CFragmentedSampleReader::PopulateDvccMetadata(kodi::addon::InputstreamInfo& info, AP4_DvccAtom* dvcc)
642+
{
643+
if (!dvcc)
644+
return;
645+
646+
auto* meta = new INPUTSTREAM_DVCC_METADATA();
647+
meta->m_dvVersionMajor = dvcc->GetDvVersionMajor();
648+
meta->m_dvVersionMinor = dvcc->GetDvVersionMinor();
649+
meta->m_dvProfile = dvcc->GetDvProfile();
650+
meta->m_dvLevel = dvcc->GetDvLevel();
651+
meta->m_rpuPresentFlag = dvcc->GetRpuPresentFlag();
652+
meta->m_elPresentFlag = dvcc->GetElPresentFlag();
653+
meta->m_blPresentFlag = dvcc->GetBlPresentFlag();
654+
meta->m_dvBlSignalCompatibilityId = dvcc->GetDvBlSignalCompatibilityID();
655+
656+
info.SetDvccMetadata(meta);
657+
}

src/samplereader/FragmentedSampleReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class ATTR_DLL_LOCAL CFragmentedSampleReader : public ISampleReader, public AP4_
5454
private:
5555
void UpdateSampleDescription();
5656
void ParseTrafTfrf(AP4_UuidAtom* uuidAtom);
57+
AP4_DvccAtom* ParseDvcc();
58+
void PopulateDvccMetadata(kodi::addon::InputstreamInfo& info, AP4_DvccAtom* dvcc);
5759

5860
AP4_Track* m_track;
5961
AP4_UI32 m_poolId{0};

0 commit comments

Comments
 (0)