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;
|
||||
|
||||
Reference in New Issue
Block a user