Initial import of Widevine Common Encryption DRM engine
Builds libwvmdrmengine.so, which is loaded by the new MediaDrm APIs to support playback of Widevine/CENC protected content. Change-Id: I6f57dd37083dfd96c402cb9dd137c7d74edc8f1c
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
Rahul and Edwin fill this out
|
||||
Rahul and Edwin write tests
|
||||
19
libwvdrmengine/cdm/src/clock.cpp
Normal file
19
libwvdrmengine/cdm/src/clock.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Clock - implemented using the standard linux time library
|
||||
|
||||
#include "clock.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
int64_t GetCurrentTime() {
|
||||
struct timeval tv;
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace wvcdm
|
||||
56
libwvdrmengine/cdm/src/lock.cpp
Normal file
56
libwvdrmengine/cdm/src/lock.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2012 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Lock class - provides a simple android specific mutex implementation
|
||||
|
||||
#include "lock.h"
|
||||
#include "utils/Mutex.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class Lock::Impl {
|
||||
public:
|
||||
android::Mutex lock_;
|
||||
};
|
||||
|
||||
Lock::Lock() : impl_(new Lock::Impl()) {
|
||||
}
|
||||
|
||||
Lock::~Lock() {
|
||||
delete impl_;
|
||||
impl_ = NULL;
|
||||
}
|
||||
|
||||
void Lock::Acquire() {
|
||||
impl_->lock_.lock();
|
||||
}
|
||||
|
||||
void Lock::Release() {
|
||||
impl_->lock_.unlock();
|
||||
}
|
||||
|
||||
bool Lock::Try() {
|
||||
return (impl_->lock_.tryLock() == 0);
|
||||
}
|
||||
|
||||
class AutoLock::Impl {
|
||||
public:
|
||||
android::Mutex::Autolock *autolock_;
|
||||
};
|
||||
|
||||
AutoLock::AutoLock(Lock& lock) : impl_(new AutoLock::Impl()) {
|
||||
impl_->autolock_ = new android::Mutex::Autolock(lock.impl_->lock_);
|
||||
}
|
||||
|
||||
AutoLock::AutoLock(Lock* lock) : impl_(new AutoLock::Impl()) {
|
||||
impl_->autolock_ = new android::Mutex::Autolock(lock->impl_->lock_);
|
||||
}
|
||||
|
||||
AutoLock::~AutoLock() {
|
||||
delete impl_->autolock_;
|
||||
delete impl_;
|
||||
impl_ = NULL;
|
||||
}
|
||||
|
||||
}; // namespace wvcdm
|
||||
|
||||
|
||||
33
libwvdrmengine/cdm/src/log.cpp
Normal file
33
libwvdrmengine/cdm/src/log.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Log - implemented using the standard Android logging mechanism
|
||||
|
||||
#define LOG_TAG "WVCdm"
|
||||
#define LOG_BUF_SIZE 1024
|
||||
|
||||
#include "log.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void log_write(LogPriority level, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[LOG_BUF_SIZE];
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
android_LogPriority prio = ANDROID_LOG_VERBOSE;
|
||||
|
||||
switch(level) {
|
||||
case LOG_ERROR: prio = ANDROID_LOG_ERROR; break;
|
||||
case LOG_WARN: prio = ANDROID_LOG_WARN; break;
|
||||
case LOG_INFO: prio = ANDROID_LOG_INFO; break;
|
||||
case LOG_DEBUG: prio = ANDROID_LOG_DEBUG; break;
|
||||
case LOG_VERBOSE: prio = ANDROID_LOG_VERBOSE; break;
|
||||
}
|
||||
|
||||
__android_log_write(prio, LOG_TAG, buf);
|
||||
}
|
||||
|
||||
}; // namespace wvcdm
|
||||
57
libwvdrmengine/cdm/src/timer.cpp
Normal file
57
libwvdrmengine/cdm/src/timer.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Timer class - provides a simple Android specific timer implementation
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include "utils/Thread.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class Timer::Impl : public android::Thread {
|
||||
public:
|
||||
Impl() : Thread(false), handler_(NULL), period_(0) {}
|
||||
virtual ~Impl() {};
|
||||
|
||||
void Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
handler_ = handler;
|
||||
period_ = time_in_secs;
|
||||
run();
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool threadLoop() {
|
||||
sleep(period_);
|
||||
handler_->OnTimerEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
TimerHandler *handler_;
|
||||
uint32_t period_;
|
||||
};
|
||||
|
||||
Timer::Timer() : impl_(new Timer::Impl()) {
|
||||
}
|
||||
|
||||
Timer::~Timer() {
|
||||
if (IsRunning())
|
||||
Stop();
|
||||
|
||||
delete impl_;
|
||||
impl_ = NULL;
|
||||
}
|
||||
|
||||
void Timer::Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
impl_->Start(handler, time_in_secs);
|
||||
}
|
||||
|
||||
void Timer::Stop() {
|
||||
impl_->requestExitAndWait();
|
||||
}
|
||||
|
||||
bool Timer::IsRunning() {
|
||||
return impl_->getTid() < 0;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
112
libwvdrmengine/cdm/src/wv_content_decryption_module.cpp
Normal file
112
libwvdrmengine/cdm/src/wv_content_decryption_module.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "wv_content_decryption_module.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "cdm_engine.h"
|
||||
#include "log.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_event_listener.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
WvContentDecryptionModule::WvContentDecryptionModule() :
|
||||
cdm_engine_(new CdmEngine()) {
|
||||
}
|
||||
|
||||
WvContentDecryptionModule::~WvContentDecryptionModule() {
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::OpenSession(
|
||||
const CdmKeySystem& key_system,
|
||||
CdmSessionId* session_id) {
|
||||
return cdm_engine_->OpenSession(key_system, session_id);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::CloseSession(
|
||||
CdmSessionId& session_id) {
|
||||
return cdm_engine_->CloseSession(session_id);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::GenerateKeyRequest(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmInitData& init_data,
|
||||
const CdmLicenseType license_type,
|
||||
CdmNameValueMap& app_parameters,
|
||||
CdmKeyMessage* key_request) {
|
||||
CdmKeySystem key_system;
|
||||
return cdm_engine_->GenerateKeyRequest(session_id, false, key_system,
|
||||
init_data, license_type,
|
||||
app_parameters, key_request);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::AddKey(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data) {
|
||||
CdmKeySystem key_system;
|
||||
CdmInitData init_data;
|
||||
return cdm_engine_->AddKey(session_id, false, key_system,
|
||||
init_data, key_data);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::CancelKeyRequest(
|
||||
const CdmSessionId& session_id) {
|
||||
CdmKeySystem key_system;
|
||||
return cdm_engine_->CancelKeyRequest(session_id, false, key_system);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::QueryKeyStatus(
|
||||
const CdmSessionId& session_id,
|
||||
CdmNameValueMap* key_info) {
|
||||
return cdm_engine_->QueryKeyStatus(session_id, key_info);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::GetProvisioningRequest(
|
||||
CdmProvisioningRequest* request,
|
||||
std::string* default_url) {
|
||||
return cdm_engine_->GetProvisioningRequest(request, default_url);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::HandleProvisioningResponse(
|
||||
CdmProvisioningResponse& response) {
|
||||
return cdm_engine_->HandleProvisioningResponse(response);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::GetSecureStops(
|
||||
CdmSecureStops* secure_stops) {
|
||||
return cdm_engine_->GetSecureStops(secure_stops);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::ReleaseSecureStops(
|
||||
const CdmSecureStopReleaseMessage& message) {
|
||||
return cdm_engine_->ReleaseSecureStops(message);
|
||||
}
|
||||
|
||||
CdmResponseType WvContentDecryptionModule::Decrypt(
|
||||
const CdmSessionId& session_id,
|
||||
bool is_encrypted,
|
||||
const KeyId& key_id,
|
||||
const uint8_t* encrypted_buffer,
|
||||
size_t encrypted_size,
|
||||
const std::vector<uint8_t>& iv,
|
||||
size_t block_offset,
|
||||
void* decrypted_buffer) {
|
||||
return cdm_engine_->Decrypt(session_id, is_encrypted, key_id,
|
||||
encrypted_buffer, encrypted_size, iv,
|
||||
block_offset, decrypted_buffer);
|
||||
}
|
||||
|
||||
bool WvContentDecryptionModule::AttachEventListener(
|
||||
CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
return cdm_engine_->AttachEventListener(session_id, listener);
|
||||
}
|
||||
|
||||
bool WvContentDecryptionModule::DetachEventListener(
|
||||
CdmSessionId& session_id,
|
||||
WvCdmEventListener* listener) {
|
||||
return cdm_engine_->DetachEventListener(session_id, listener);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
Reference in New Issue
Block a user