Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions drm/helper/WidevineDrmHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,50 @@ void WidevineDrmHelper::setDrmMetaData(const std::string& metaData)

void WidevineDrmHelper::setDefaultKeyID(const std::string& cencData)
{
mDefaultKeySlot = -1;
std::vector<uint8_t> defaultKeyID(cencData.begin(), cencData.end());
// Also convert UUID string (e.g. "f3dff538-b8c9-58e4-e8cd-96cf811d32dc") to 16-byte binary
// for comparison against binary keyIDs parsed from PSSH
std::vector<uint8_t> defaultKeyIDBinary;
std::string uuidHex;
uuidHex.reserve(cencData.size());
for (char c : cencData)
{
if (c != '-')
{
uuidHex += c;
}
}
Comment thread
Copilot marked this conversation as resolved.
if (uuidHex.size() == 32)
{
defaultKeyIDBinary.reserve(16);
for (size_t i = 0; i < uuidHex.size(); i += 2)
{
char hexPair[3] = {uuidHex[i], uuidHex[i + 1], '\0'};
char* end = nullptr;
unsigned long v = strtoul(hexPair, &end, 16);
if (*end != '\0' || v > 0xFF) { defaultKeyIDBinary.clear(); break; }
defaultKeyIDBinary.push_back(static_cast<uint8_t>(v));
Comment thread
Copilot marked this conversation as resolved.
Comment thread
Copilot marked this conversation as resolved.
}
}
Comment thread
Copilot marked this conversation as resolved.

if(!mKeyIDs.empty())
{
for(auto& it : mKeyIDs)
{
if(defaultKeyID == it.second)
if(defaultKeyID == it.second || defaultKeyIDBinary == it.second)
{
mDefaultKeySlot = it.first;
MW_LOG_WARN("setDefaultKeyID : %s slot : %d", PlayerLogManager::getHexDebugStr(defaultKeyID).c_str(), mDefaultKeySlot);
MW_LOG_WARN("setDefaultKeyID : %s slot : %d", PlayerLogManager::getHexDebugStr(it.second).c_str(), mDefaultKeySlot);
break;
}
}
}
if (mDefaultKeySlot < 0 && !mKeyIDs.empty())
{
MW_LOG_WARN("setDefaultKeyID: no match found for cencData, defaulting to slot 0");
mDefaultKeySlot = 0;
}
}


Expand All @@ -217,17 +249,18 @@ void WidevineDrmHelper::getKey(std::vector<uint8_t>& keyID) const
std::string keyStr = PlayerLogManager::getHexDebugStr(keyPair.second);
MW_LOG_DEBUG("Key ID [%d]: %s", keyPair.first, keyStr.c_str());
}
if ((mDefaultKeySlot >= 0) && (mDefaultKeySlot < mKeyIDs.size()))
if ((mDefaultKeySlot >= 0) && ((size_t)mDefaultKeySlot < mKeyIDs.size()))
{
keyID = this->mKeyIDs.at(mDefaultKeySlot);
}
else if (mKeyIDs.size() > 0)
Comment thread
ALSAMEEMA marked this conversation as resolved.
{
MW_LOG_WARN("mDefaultKeySlot(%d) invalid, falling back to slot 0", mDefaultKeySlot);
keyID = this->mKeyIDs.at(0);
}
else
{
MW_LOG_ERR("No key");
MW_LOG_ERR("No key available - mKeyIDs is empty");
}
}

Expand Down
Loading
Loading