Source release v2.1.3-2-789 + third_party libs

Change-Id: I8648756dab3fe1f53d6da18b83cd1294581d1abe
This commit is contained in:
Joey Parrish
2014-06-19 17:13:42 -07:00
parent 73445a920c
commit 84acd5a15e
32 changed files with 1340 additions and 1335 deletions

View File

@@ -6,7 +6,7 @@
namespace wvcdm {
IFileFactory* File::Impl::factory_ = NULL;
IFileFactory* File::Impl::factory_ = NULL;
// File::Impl() Section
// The file handler for cert.bin, aka DeviceCertificate is all we're
@@ -14,68 +14,60 @@ IFileFactory* File::Impl::factory_ = NULL;
bool File::Impl::Exists(const std::string& name) {
if (name == "cert.bin") {
std::vector<uint8_t> value;
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) {
return true;
}
std::string value;
host_->GetPlatformString("DeviceCertificate", &value);
return !value.empty();
}
return false;
}
bool File::Impl::Open(const std::string& name) {
if (name == "cert.bin") {
fname_= name;
fname_ = name;
return true;
}
return false;
}
bool File::Impl::Close() {
fname_ = "";
fname_.clear();
return true;
}
bool File::Impl::Remove(const std::string& name) {
if (Exists(name)) {
std::vector<uint8_t> value(0);
if (host_->SetPlatformByteArray("DeviceCertificate", value)) {
return true;
}
if (name == "cert.bin") {
host_->SetPlatformString("DeviceCertificate", "");
return true;
}
return false;
}
size_t File::Impl::Read(char* buffer, size_t bytes) {
if (fname_ == "cert.bin") {
std::vector<uint8_t> value;
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) {
memcpy(buffer, &value[0], bytes);
return bytes;
}
}
return 0;
}
size_t File::Impl::Write(const char* buffer, size_t bytes) {
ssize_t File::Impl::Read(char* buffer, size_t bytes) {
if (fname_ == "cert.bin") {
std::vector<uint8_t> value;
value.resize(bytes);
memcpy(&value[0], buffer, bytes);
if (host_->PersistPlatformByteArray("DeviceCertificate", value)) {
return bytes;
}
std::string value;
host_->GetPlatformString("DeviceCertificate", &value);
memcpy(buffer, value.data(), std::min(bytes, value.size()));
return value.size() ? value.size() : -1;
}
return 0;
return -1;
}
size_t File::Impl::FileSize(const std::string& name) {
if (name == "cert.bin") {
std::vector<uint8_t> value;
if (host_->GetPlatformByteArray("DeviceCertificate", &value)) {
return value.size();
}
ssize_t File::Impl::Write(const char* buffer, size_t bytes) {
if (fname_ == "cert.bin") {
std::string value(buffer, bytes);
host_->SetPlatformString("DeviceCertificate", value);
return bytes;
}
return 0;
return -1;
}
ssize_t File::Impl::FileSize(const std::string& name) {
if (name == "cert.bin") {
std::string value;
host_->GetPlatformString("DeviceCertificate", &value);
return value.size() ? value.size() : -1;
}
return -1;
}
File::File() : impl_(File::Impl::factory_->NewFileImpl()) {}
@@ -91,7 +83,6 @@ bool File::Open(const std::string& name, int flags) {
void File::Close() {
impl_->Close();
return;
}
ssize_t File::Read(char* buffer, size_t bytes) {
@@ -136,11 +127,7 @@ bool File::IsRegularFile(const std::string& path) {
}
ssize_t File::FileSize(const std::string& path) {
size_t size = impl_->FileSize(path);
if (size > 0) {
return size;
}
return -1;
return impl_->FileSize(path);
}
} // namespace wvcdm

View File

@@ -3,7 +3,6 @@
#include "properties.h"
#include <string>
#include <sys/utsname.h>
#include "log.h"

View File

@@ -1,76 +0,0 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Timer class - provides a simple timer implementation
//
#include "cdm_host_timer.h"
#include "scoped_ptr.h"
#include "timer.h"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
namespace wvcdm {
ITimerFactory* Timer::Impl::factory_ = NULL;
Timer::Impl::Impl(cdm::Host* const host)
: host_(host), handler_(NULL), delay_ms_(0),
state_(kIdle) {
}
void Timer::Impl::RegisterTimerFactory(ITimerFactory* factory) {
factory_ = factory;
}
void Timer::Impl::Start(TimerHandler* handler, uint32_t time_in_secs) {
handler_ = handler;
delay_ms_ = time_in_secs * 1000;
state_ = kRunning;
host_->SetTimer(delay_ms_, this);
}
void Timer::Impl::OnTimerEvent() {
if (kRunning == state_) {
handler_->OnTimerEvent();
host_->SetTimer(delay_ms_, this);
}
}
void Timer::Impl::Stop() {
state_ = kIdle;
}
Timer::Timer() : impl_(NULL) {}
Timer::~Timer() {
if (impl_)
delete impl_;
}
bool Timer::Start(TimerHandler* handler, uint32_t time_in_secs) {
if (!handler || 0 == time_in_secs)
return false;
if (!impl_ && Impl::factory_)
impl_ = Impl::factory_->NewTimerImpl();
if(!impl_)
return false;
impl_->Start(handler, time_in_secs);
return IsRunning();
}
void Timer::Stop() {
if (impl_)
impl_->Stop();
}
bool Timer::IsRunning() {
if (!impl_)
return false;
return impl_->IsRunning();
}
} // namespace wvcdm

View File

@@ -2,17 +2,14 @@
#include "wv_content_decryption_module.h"
#include <iostream>
#include <string.h>
#include "cdm_client_property_set.h"
#include "content_decryption_module.h"
#include "initialization_data.h"
#include <iostream>
#include "initialization_data.h"
#include "log.h"
#include "OEMCryptoCENC.h"
#include "properties.h"
#include "wv_cdm_constants.h"
#include "wv_cdm_types.h"
#include "wv_cdm_version.h"
@@ -38,10 +35,10 @@ void* CreateCdmInstance(int cdm_interface_version, const char* key_system,
int GetCdmVersion() { return cdm::kCdmInterfaceVersion; }
namespace {
static const std::string kWvCdmVersionString(WV_CDM_VERSION);
const int kCdmPolicyTimerDurationSeconds = 1;
const int kCdmPolicyTimerCancel = 0;
const int kCdmPolicyTimerDurationSeconds = 5;
// The iso spec only uses the lower 8 bytes of the iv as
// the counter.
@@ -69,6 +66,7 @@ bool Ctr128Add(size_t block_count, uint8_t* counter) {
}
return true;
}
} // namespace
namespace wvcdm {
@@ -80,6 +78,13 @@ bool IsBufferEncrypted(const cdm::InputBuffer& input_buffer) {
// cdm::ContentDecryptionModule implementation.
WvContentDecryptionModule::WvContentDecryptionModule(cdm::Host* host)
: host_(host),
host_event_listener_(host, &cdm_engine_),
timer_enabled_(false) {
HostClock::SetClockInterface(this);
}
WvContentDecryptionModule::~WvContentDecryptionModule() {
DisablePolicyTimer();
}
@@ -87,7 +92,7 @@ WvContentDecryptionModule::~WvContentDecryptionModule() {
cdm::Status WvContentDecryptionModule::GenerateKeyRequest(
const char* type, int type_size, const uint8_t* init_data,
int init_data_size) {
LOGI("Enter WvContentDecryptionModule::GenerateKeyRequest()");
LOGI("WvContentDecryptionModule::GenerateKeyRequest()");
CdmInitData init_data_internal(reinterpret_cast<const char*>(init_data),
init_data_size);
InitializationData initialization_data(ISO_BMFF_VIDEO_MIME_TYPE,
@@ -97,14 +102,14 @@ cdm::Status WvContentDecryptionModule::GenerateKeyRequest(
std::string security_level;
std::string privacy_mode;
VectorBytes service_certificate;
std::string service_certificate;
host_->GetPlatformString("SecurityLevel", &security_level);
host_->GetPlatformString("PrivacyOn", &privacy_mode);
host_->GetPlatformByteArray("ServiceCertificate", &service_certificate);
host_->GetPlatformString("ServiceCertificate", &service_certificate);
property_set_.set_security_level(security_level);
property_set_.set_use_privacy_mode(privacy_mode == "True" ? 1 : 0 );
property_set_.set_use_privacy_mode(privacy_mode == "True" ? 1 : 0);
property_set_.set_service_certificate(service_certificate);
CdmResponseType result =
@@ -146,7 +151,7 @@ cdm::Status WvContentDecryptionModule::AddKey(const char* session_id,
const uint8_t* key, int key_size,
const uint8_t* key_id,
int key_id_size) {
LOGI("Enter WvContentDecryptionModule::AddKey()\n");
LOGI("WvContentDecryptionModule::AddKey()");
CdmSessionId session_id_internal(session_id, session_id_size);
CdmKeyResponse key_data((const char*)key, key_size);
CdmKeySetId key_set_id;
@@ -160,12 +165,17 @@ cdm::Status WvContentDecryptionModule::AddKey(const char* session_id,
} else {
return cdm::kSessionError;
}
}
bool WvContentDecryptionModule::IsKeyValid(const uint8_t* key_id,
int key_id_size) {
KeyId key(reinterpret_cast<const char*>(key_id), key_id_size);
return cdm_engine_.IsKeyLoaded(key);
}
cdm::Status WvContentDecryptionModule::CancelKeyRequest(const char* session_id,
int session_id_size) {
LOGI("Enter WvContentDecryptionModule::CancelKeyRequest()\n");
LOGI("WvContentDecryptionModule::CancelKeyRequest()");
CdmSessionId session_id_internal(session_id, session_id_size);
return cdm_engine_.CancelKeyRequest(session_id_internal) == NO_ERROR
? cdm::kSuccess
@@ -173,18 +183,17 @@ cdm::Status WvContentDecryptionModule::CancelKeyRequest(const char* session_id,
}
void WvContentDecryptionModule::TimerExpired(void* context) {
LOGI("Timer expired, send cdm_engine OnTimerEvent");
if (this != context) {
LOGD("Context should have been set, Timer Expired Error\n");
return;
LOGI("WvContentDecryptionModule::TimerExpired()");
if (timer_enabled_) {
cdm_engine_.OnTimerEvent();
host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, NULL);
}
OnTimerEvent();
}
cdm::Status WvContentDecryptionModule::Decrypt(
const cdm::InputBuffer& encrypted_buffer,
cdm::DecryptedBlock* decrypted_block) {
LOGI("=>Enter WvContentDecryptionModule::Decrypt()\n");
LOGI("WvContentDecryptionModule::Decrypt()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError;
std::vector < uint8_t > iv(KEY_IV_SIZE);
@@ -210,47 +219,13 @@ cdm::Status WvContentDecryptionModule::Decrypt(
decrypted_block);
}
cdm::Status WvContentDecryptionModule::InitializeAudioDecoder(
const cdm::AudioDecoderConfig& audio_decoder_config) {
LOGI("WvContentDecryptionModule::InitializeAudioDecoder() Not implemented\n");
return cdm::kDecodeError;
}
cdm::Status WvContentDecryptionModule::InitializeVideoDecoder(
const cdm::VideoDecoderConfig& video_decoder_config) {
LOGI("WvContentDecryptionModule::InitializeVideoDecoder() Not implemented\n");
return cdm::kDecodeError;
}
void WvContentDecryptionModule::DeinitializeDecoder(
cdm::StreamType decoder_type) {
LOGI("WvContentDecryptionModule::DeInitializeDecoder() Not implemented\n");
}
void WvContentDecryptionModule::ResetDecoder(cdm::StreamType decoder_type) {
LOGI("WvContentDecryptionModule::ResetDecoder() Not implemented\n");
}
cdm::Status WvContentDecryptionModule::DecryptAndDecodeFrame(
const cdm::InputBuffer& encrypted_buffer, cdm::VideoFrame* video_frame) {
LOGI("WvContentDecryptionModule::DecryptAndDecodeFrame() Not implemented\n");
return cdm::kDecodeError;
}
cdm::Status WvContentDecryptionModule::DecryptAndDecodeSamples(
const cdm::InputBuffer& encrypted_buffer, cdm::AudioFrames* audio_frames) {
LOGI(
"WvContentDecryptionModule::DecryptAndDecodeSamples() Not implemented\n");
return cdm::kDecodeError;
}
// This is the Level 1 API. When the host application calls the CDM's
// DecryptDecodeAndRenderFrame(), rather than the CDM's Decrypt(),
// OEMCrypto_DecryptCTR() will be told to use direct rendering with no
// cleartext in the return.
cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderFrame(
const cdm::InputBuffer& encrypted_buffer) {
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderFrame()\n");
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderFrame()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError;
@@ -276,7 +251,7 @@ cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderFrame(
// in the return.
cdm::Status WvContentDecryptionModule::DecryptDecodeAndRenderSamples(
const cdm::InputBuffer& encrypted_buffer) {
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderSamples()\n");
LOGI("WvContentDecryptionModule::DecryptDecodeAndRenderSamples()");
if (static_cast<size_t>(encrypted_buffer.iv_size) != KEY_IV_SIZE)
return cdm::kDecryptError;
@@ -324,19 +299,16 @@ cdm::Status WvContentDecryptionModule::HandleProvisioningResponse(
}
void WvContentDecryptionModule::EnablePolicyTimer() {
LOGI("WvContentDecryptionModule::EnablePolicyTimer()\n");
host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, this);
LOGI("WvContentDecryptionModule::EnablePolicyTimer()");
if (!timer_enabled_) {
timer_enabled_ = true;
host_->SetTimer(kCdmPolicyTimerDurationSeconds * 1000, NULL);
}
}
void WvContentDecryptionModule::DisablePolicyTimer() {
LOGI("WvContentDecryptionModule::DisablePolicyTimer()\n");
host_->SetTimer(kCdmPolicyTimerCancel, NULL);
}
void WvContentDecryptionModule::OnTimerEvent() {
LOGI("WvContentDecryptionModule::OnTimerEvent()\n");
cdm_engine_.OnTimerEvent();
LOGI("WvContentDecryptionModule::DisablePolicyTimer()");
timer_enabled_ = false;
}
cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
@@ -385,7 +357,7 @@ cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
continue;
if (is_encrypted) {
uint32_t counter = encrypted_offset / kIvSize;
::Ctr128Add(counter - block_ctr, &iv[0]);
Ctr128Add(counter - block_ctr, &iv[0]);
block_ctr = counter;
}
@@ -413,16 +385,22 @@ cdm::Status WvContentDecryptionModule::DoSubsampleDecrypt(
switch (status) {
case wvcdm::NEED_KEY:
return cdm::kNoKey;
break;
case wvcdm::NO_ERROR:
break;
default:
return cdm::kDecryptError;
break;
}
}
}
return cdm::kSuccess;
}
int64_t WvContentDecryptionModule::GetCurrentTimeInSeconds() {
return host_->GetCurrentWallTimeInSeconds();
}
File::Impl* WvContentDecryptionModule::NewFileImpl() {
return new File::Impl(host_);
}
} // namespace wvcdm