Migration from jb-mr2 to master for Widevine CDM
Android development of the widevine CDM has been done on the jb-mr2 branch of the cdm code base. This CL contains a merge of that jb-mr2 work to CDM master, and also reflects the evolution of the common Modular DRM code base since jb-mr2 branched. Change-Id: I1d7e1a12d092c00044a4298261146cb97808d4ef
This commit is contained in:
@@ -14,31 +14,31 @@
|
||||
#include "log.h"
|
||||
|
||||
namespace {
|
||||
const char* kCurrentDirectory = ".";
|
||||
const char* kParentDirectory = "..";
|
||||
}
|
||||
const char* kCurrentDirectory = ".";
|
||||
const char* kParentDirectory = "..";
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class File::Impl {
|
||||
public:
|
||||
Impl() : file_(NULL) {}
|
||||
Impl(const std::string& file_path) : file_(NULL), file_path_(file_path) {}
|
||||
virtual ~Impl() {}
|
||||
|
||||
FILE* file_;
|
||||
std::string file_path_;
|
||||
};
|
||||
|
||||
File::File() : impl_(new File::Impl()) {}
|
||||
|
||||
File::File(const std::string& file_path, int flags) :
|
||||
impl_(new File::Impl()) {
|
||||
Open(file_path, flags);
|
||||
}
|
||||
|
||||
File::~File() {
|
||||
Close();
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
bool File::Open(const std::string& name, int flags) {
|
||||
std::string openFlags = "";
|
||||
std::string open_flags;
|
||||
|
||||
if (((flags & File::kTruncate) && Exists(name)) ||
|
||||
((flags & File::kCreate) && !Exists(name))) {
|
||||
@@ -49,39 +49,29 @@ bool File::Open(const std::string& name, int flags) {
|
||||
}
|
||||
|
||||
if (flags & File::kBinary) {
|
||||
openFlags = (flags & File::kReadOnly)? "rb" : "rb+";
|
||||
open_flags = (flags & File::kReadOnly)? "rb" : "rb+";
|
||||
} else {
|
||||
openFlags = (flags & File::kReadOnly)? "r" : "r+";
|
||||
open_flags = (flags & File::kReadOnly)? "r" : "r+";
|
||||
}
|
||||
|
||||
impl_->file_ = fopen(name.c_str(), openFlags.c_str());
|
||||
impl_->file_ = fopen(name.c_str(), open_flags.c_str());
|
||||
if (!impl_->file_) {
|
||||
LOGW("File::Open: fopen failed: %d", errno);
|
||||
}
|
||||
return IsOpen();
|
||||
impl_->file_path_ = name;
|
||||
return impl_->file_ != NULL;
|
||||
}
|
||||
|
||||
void File::Close() {
|
||||
if (impl_->file_) {
|
||||
fclose(impl_->file_);
|
||||
impl_->file_ = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool File::IsOpen() {
|
||||
return impl_->file_ != NULL;
|
||||
}
|
||||
|
||||
bool File::IsBad() {
|
||||
if (impl_->file_)
|
||||
return ferror(impl_->file_) != 0;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
ssize_t File::Read(void* buffer, size_t bytes) {
|
||||
ssize_t File::Read(char* buffer, size_t bytes) {
|
||||
if (impl_->file_) {
|
||||
size_t len = fread(buffer, 1, bytes, impl_->file_);
|
||||
size_t len = fread(buffer, sizeof(char), bytes, impl_->file_);
|
||||
if (len == 0) {
|
||||
LOGW("File::Read: fread failed: %d", errno);
|
||||
}
|
||||
@@ -91,9 +81,9 @@ ssize_t File::Read(void* buffer, size_t bytes) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t File::Write(const void* buffer, size_t bytes) {
|
||||
ssize_t File::Write(const char* buffer, size_t bytes) {
|
||||
if (impl_->file_) {
|
||||
size_t len = fwrite(buffer, 1, bytes, impl_->file_);
|
||||
size_t len = fwrite(buffer, sizeof(char), bytes, impl_->file_);
|
||||
if (len == 0) {
|
||||
LOGW("File::Write: fwrite failed: %d", errno);
|
||||
}
|
||||
@@ -103,27 +93,27 @@ ssize_t File::Write(const void* buffer, size_t bytes) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool File::Exists(const std::string& file) {
|
||||
bool File::Exists(const std::string& path) {
|
||||
struct stat buf;
|
||||
int res = stat(file.c_str(), &buf) == 0;
|
||||
int res = stat(path.c_str(), &buf) == 0;
|
||||
if (!res) {
|
||||
LOGV("File::Exists: stat failed: %d", errno);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool File::Remove(const std::string& file_path) {
|
||||
if (IsDirectory(file_path)) {
|
||||
bool File::Remove(const std::string& path) {
|
||||
if (IsDirectory(path)) {
|
||||
DIR* dir;
|
||||
if ((dir = opendir(file_path.c_str())) != NULL) {
|
||||
if ((dir = opendir(path.c_str())) != NULL) {
|
||||
// first remove files and dir within it
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp(entry->d_name, kCurrentDirectory) &&
|
||||
(strcmp(entry->d_name, kParentDirectory))) {
|
||||
std::string file_path_to_remove = file_path + '/';
|
||||
file_path_to_remove += entry->d_name;
|
||||
if (!Remove(file_path_to_remove)) {
|
||||
std::string path_to_remove = path + '/';
|
||||
path_to_remove += entry->d_name;
|
||||
if (!Remove(path_to_remove)) {
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
@@ -131,13 +121,13 @@ bool File::Remove(const std::string& file_path) {
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
if (rmdir(file_path.c_str())) {
|
||||
if (rmdir(path.c_str())) {
|
||||
LOGW("File::Remove: rmdir failed: %d", errno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (unlink(file_path.c_str())) {
|
||||
if (unlink(path.c_str()) && (errno != ENOENT)) {
|
||||
LOGW("File::Remove: unlink failed: %d", errno);
|
||||
return false;
|
||||
}
|
||||
@@ -195,9 +185,9 @@ bool File::IsRegularFile(const std::string& path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t File::FileSize(const std::string& file_path) {
|
||||
ssize_t File::FileSize(const std::string& path) {
|
||||
struct stat buf;
|
||||
if (stat(file_path.c_str(), &buf) == 0)
|
||||
if (stat(path.c_str(), &buf) == 0)
|
||||
return buf.st_size;
|
||||
else
|
||||
return -1;
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void log_write(LogPriority level, const char *fmt, ...) {
|
||||
void InitLogging(int argc, const char* const* argv) {}
|
||||
|
||||
void Log(const char* file, int line, LogPriority level, const char* fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[LOG_BUF_SIZE];
|
||||
va_start(ap, fmt);
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cutils/properties.h"
|
||||
#include "properties.h"
|
||||
|
||||
namespace {
|
||||
bool GetAndroidProperty(const char* key, std::string& value) {
|
||||
char val[PROPERTY_VALUE_MAX];
|
||||
|
||||
if (property_get(key, val, "Unknown") <= 0)
|
||||
return false;
|
||||
|
||||
value = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
bool Properties::GetCompanyName(std::string& company_name) {
|
||||
return GetAndroidProperty("ro.product.manufacturer", company_name);
|
||||
}
|
||||
|
||||
bool Properties::GetModelName(std::string& model_name) {
|
||||
return GetAndroidProperty("ro.product.model", model_name);
|
||||
}
|
||||
|
||||
bool Properties::GetArchitectureName(std::string& arch_name) {
|
||||
return GetAndroidProperty("ro.product.cpu.abi", arch_name);
|
||||
}
|
||||
|
||||
bool Properties::GetDeviceName(std::string& device_name) {
|
||||
return GetAndroidProperty("ro.product.device", device_name);
|
||||
}
|
||||
|
||||
bool Properties::GetProductName(std::string& product_name) {
|
||||
return GetAndroidProperty("ro.product.name", product_name);
|
||||
}
|
||||
|
||||
bool Properties::GetBuildInfo(std::string& build_info) {
|
||||
return GetAndroidProperty("ro.build.fingerprint", build_info);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
95
libwvdrmengine/cdm/src/properties_android.cpp
Normal file
95
libwvdrmengine/cdm/src/properties_android.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "properties.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cutils/properties.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool GetAndroidProperty(const char* key, std::string* value) {
|
||||
char val[PROPERTY_VALUE_MAX];
|
||||
if (!key) {
|
||||
LOGW("GetAndroidProperty: Invalid property key parameter");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
LOGW("GetAndroidProperty: Invalid property value parameter");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (property_get(key, val, "Unknown") <= 0) return false;
|
||||
|
||||
*value = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
bool Properties::GetCompanyName(std::string* company_name) {
|
||||
if (!company_name) {
|
||||
LOGW("Properties::GetCompanyName: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.product.manufacturer", company_name);
|
||||
}
|
||||
|
||||
bool Properties::GetModelName(std::string* model_name) {
|
||||
if (!model_name) {
|
||||
LOGW("Properties::GetModelName: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.product.model", model_name);
|
||||
}
|
||||
|
||||
bool Properties::GetArchitectureName(std::string* arch_name) {
|
||||
if (!arch_name) {
|
||||
LOGW("Properties::GetArchitectureName: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.product.cpu.abi", arch_name);
|
||||
}
|
||||
|
||||
bool Properties::GetDeviceName(std::string* device_name) {
|
||||
if (!device_name) {
|
||||
LOGW("Properties::GetDeviceName: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.product.device", device_name);
|
||||
}
|
||||
|
||||
bool Properties::GetProductName(std::string* product_name) {
|
||||
if (!product_name) {
|
||||
LOGW("Properties::GetProductName: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.product.name", product_name);
|
||||
}
|
||||
|
||||
bool Properties::GetBuildInfo(std::string* build_info) {
|
||||
if (!build_info) {
|
||||
LOGW("Properties::GetBuildInfo: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
return GetAndroidProperty("ro.build.fingerprint", build_info);
|
||||
}
|
||||
|
||||
bool Properties::GetDeviceFilesBasePath(std::string* base_path) {
|
||||
if (!base_path) {
|
||||
LOGW("Properties::GetDeviceFilesBasePath: Invalid parameter");
|
||||
return false;
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << "/data/mediadrm/IDM" << getuid() << "/";
|
||||
*base_path = ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
@@ -26,7 +26,10 @@ class Timer::Impl : virtual public android::RefBase {
|
||||
|
||||
private:
|
||||
virtual bool threadLoop() {
|
||||
sleep(period_);
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = period_;
|
||||
timeout.tv_usec = 0;
|
||||
TEMP_FAILURE_RETRY(select(0, NULL, NULL, NULL, &timeout));
|
||||
handler_->OnTimerEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ CdmResponseType WvContentDecryptionModule::GenerateKeyRequest(
|
||||
app_parameters, key_request,
|
||||
server_url);
|
||||
|
||||
if ((license_type == kLicenseTypeRelease) && (sts != KEY_MESSAGE)) {
|
||||
if (license_type == kLicenseTypeRelease && sts != KEY_MESSAGE) {
|
||||
cdm_engine_->CloseKeySetSession(key_set_id);
|
||||
}
|
||||
return sts;
|
||||
@@ -57,10 +57,10 @@ CdmResponseType WvContentDecryptionModule::GenerateKeyRequest(
|
||||
CdmResponseType WvContentDecryptionModule::AddKey(
|
||||
const CdmSessionId& session_id,
|
||||
const CdmKeyResponse& key_data,
|
||||
CdmKeySetId& key_set_id) {
|
||||
CdmKeySetId* key_set_id) {
|
||||
CdmResponseType sts = cdm_engine_->AddKey(session_id, key_data, key_set_id);
|
||||
if ((sts == KEY_ADDED) && session_id.empty()) // license type release
|
||||
cdm_engine_->CloseKeySetSession(key_set_id);
|
||||
if (sts == KEY_ADDED && session_id.empty()) // license type release
|
||||
cdm_engine_->CloseKeySetSession(*key_set_id);
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user