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
25 changes: 24 additions & 1 deletion drm/aes/Aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,34 @@ DrmReturn AesDec::SetDecryptInfo(const struct DrmInfo *drmInfo, int acquireKeyWa
void AesDec::WaitForKeyAcquireCompleteUnlocked(int timeInMs, DrmReturn &err, std::unique_lock<std::mutex>& lock )
{
MW_LOG_INFO( "waiting for key acquisition to complete,wait time:%d",timeInMs );
if( std::cv_status::timeout == mCond.wait_for(lock, std::chrono::milliseconds(timeInMs)) ) // block until drm ready
// Initialize err to default error state
err = eDRM_ERROR;

// Wait with predicate - returns false if timeout, true if condition met
bool acquiredBeforeTimeout = mCond.wait_for(lock, std::chrono::milliseconds(timeInMs),
[this]() { return mDrmState != eDRM_ACQUIRING_KEY; });

if (!acquiredBeforeTimeout)
{
MW_LOG_WARN("AesDec:: wait for key acquisition timed out");
err = eDRM_KEY_ACQUISITION_TIMEOUT;
}
else if (mDrmState == eDRM_KEY_ACQUIRED)
{
err = eDRM_SUCCESS;
}
else if (mDrmState == eDRM_KEY_FAILED)
{
err = eDRM_ERROR;
}
Comment thread
trupthi1403 marked this conversation as resolved.
else if (mDrmState == eDRM_KEY_FLUSH)
{
err = eDRM_ERROR;
}
else
{
err = eDRM_ERROR;
}
}

/**
Expand Down
12 changes: 7 additions & 5 deletions drm/ocdm/opencdmsessionadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,22 @@ class Event {

inline bool wait(const uint32_t waitTime)
{
bool ret = true;
std::unique_lock<std::mutex> _lock(lock);
if (!signalled) {
if (waitTime == 0) {
condition.wait(_lock);
condition.wait(_lock, [this]() { return signalled; });
} else {
if( std::cv_status::timeout == condition.wait_for(_lock,std::chrono::milliseconds(waitTime)) )
// Use predicate version - returns false if timeout, true if condition met
if (!condition.wait_for(_lock, std::chrono::milliseconds(waitTime),
[this]() { return signalled; }))
{
ret = false;
signalled = false;
return false; // Timeout occurred
}
}
}
signalled = false;
return ret;
return true;
}

inline void signal()
Expand Down
29 changes: 23 additions & 6 deletions test/utests/tests/DrmAes/DrmTestsAes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <stdio.h>
#include "Aes.h"

#define private public
#include "Aes.h"
#undef private
Comment on lines 34 to +40

class DrmAesDecTests : public ::testing::Test
{
Expand Down Expand Up @@ -1359,9 +1361,20 @@ TEST(DrmAesDecTests, WaitForKeyAcquireCompleteUnlocked_SuccessfulKeyAcquisition)

AesDec aesDec;

std::mutex mtx;

std::unique_lock<std::mutex> lock(mtx);
std::unique_lock<std::mutex> lock(aesDec.mMutex);

aesDec.mDrmState = eDRM_ACQUIRING_KEY;

// Spawn thread to simulate key acquisition success
std::thread keyAcquiredThread([&aesDec]() {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Simulate key fetch delay
{
std::lock_guard<std::mutex> lg(aesDec.mMutex);
aesDec.mDrmState = eDRM_KEY_ACQUIRED;
}
aesDec.mCond.notify_all(); // Signal waiting thread that key is ready
});

int timeInMs = 1000;
DrmReturn return_value;
Expand All @@ -1372,7 +1385,10 @@ TEST(DrmAesDecTests, WaitForKeyAcquireCompleteUnlocked_SuccessfulKeyAcquisition)

std::cout << "Method returned err with value " << return_value << std::endl;

EXPECT_EQ(return_value, eDRM_KEY_ACQUIRED);
// - Returns correct success code for acquired key
EXPECT_EQ(return_value, eDRM_SUCCESS);

keyAcquiredThread.join();

std::cout << "Exiting WaitForKeyAcquireCompleteUnlocked_SuccessfulKeyAcquisition test" << std::endl;
}
Expand Down Expand Up @@ -1404,9 +1420,9 @@ TEST(DrmAesDecTests, WaitForKeyAcquireCompleteUnlocked_ZeroWaitTimeImmediateTime

AesDec aesDec;

std::mutex mtx;
std::unique_lock<std::mutex> lock(aesDec.mMutex);

std::unique_lock<std::mutex> lock(mtx);
aesDec.mDrmState = eDRM_ACQUIRING_KEY;

int timeInMs = 0;
DrmReturn return_value;
Expand All @@ -1417,6 +1433,7 @@ TEST(DrmAesDecTests, WaitForKeyAcquireCompleteUnlocked_ZeroWaitTimeImmediateTime

std::cout << "Method returned err with value " << return_value << std::endl;

// - Returns correct timeout error code
EXPECT_EQ(return_value, eDRM_KEY_ACQUISITION_TIMEOUT);

std::cout << "Exiting WaitForKeyAcquireCompleteUnlocked_ZeroWaitTimeImmediateTimeout test" << std::endl;
Expand Down
Loading