Rename EncryptorSource to EncryptionKeySource
Change-Id: I0a3d0e205922bbb4015955e04d51b7a9a4fa86e1
This commit is contained in:
parent
f059d926d7
commit
9076411044
|
@ -19,7 +19,7 @@
|
||||||
#include "media/base/muxer_options.h"
|
#include "media/base/muxer_options.h"
|
||||||
#include "media/base/request_signer.h"
|
#include "media/base/request_signer.h"
|
||||||
#include "media/base/stream_info.h"
|
#include "media/base/stream_info.h"
|
||||||
#include "media/base/widevine_encryptor_source.h"
|
#include "media/base/widevine_encryption_key_source.h"
|
||||||
#include "media/event/vod_media_info_dump_muxer_listener.h"
|
#include "media/event/vod_media_info_dump_muxer_listener.h"
|
||||||
#include "media/file/file.h"
|
#include "media/file/file.h"
|
||||||
#include "media/file/file_closer.h"
|
#include "media/file/file_closer.h"
|
||||||
|
@ -41,8 +41,8 @@ void DumpStreamInfo(const std::vector<MediaStream*>& streams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and initialize encryptor source.
|
// Create and initialize encryptor source.
|
||||||
scoped_ptr<EncryptorSource> CreateEncryptorSource() {
|
scoped_ptr<EncryptionKeySource> CreateEncryptionKeySource() {
|
||||||
scoped_ptr<EncryptorSource> encryptor_source;
|
scoped_ptr<EncryptionKeySource> encryption_key_source;
|
||||||
if (FLAGS_enable_widevine_encryption) {
|
if (FLAGS_enable_widevine_encryption) {
|
||||||
scoped_ptr<RequestSigner> signer;
|
scoped_ptr<RequestSigner> signer;
|
||||||
DCHECK(!FLAGS_aes_signing_key.empty() ||
|
DCHECK(!FLAGS_aes_signing_key.empty() ||
|
||||||
|
@ -55,7 +55,7 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
|
||||||
LOG(ERROR) << "Cannot create an AES signer object from '"
|
LOG(ERROR) << "Cannot create an AES signer object from '"
|
||||||
<< FLAGS_aes_signing_key << "':'" << FLAGS_aes_signing_iv
|
<< FLAGS_aes_signing_key << "':'" << FLAGS_aes_signing_iv
|
||||||
<< "'.";
|
<< "'.";
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
} else if (!FLAGS_rsa_signing_key_path.empty()) {
|
} else if (!FLAGS_rsa_signing_key_path.empty()) {
|
||||||
std::string rsa_private_key;
|
std::string rsa_private_key;
|
||||||
|
@ -63,7 +63,7 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
|
||||||
&rsa_private_key)) {
|
&rsa_private_key)) {
|
||||||
LOG(ERROR) << "Failed to read from '" << FLAGS_rsa_signing_key_path
|
LOG(ERROR) << "Failed to read from '" << FLAGS_rsa_signing_key_path
|
||||||
<< "'.";
|
<< "'.";
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
|
|
||||||
signer.reset(
|
signer.reset(
|
||||||
|
@ -71,17 +71,17 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
|
||||||
if (!signer) {
|
if (!signer) {
|
||||||
LOG(ERROR) << "Cannot create a RSA signer object from '"
|
LOG(ERROR) << "Cannot create a RSA signer object from '"
|
||||||
<< FLAGS_rsa_signing_key_path << "'.";
|
<< FLAGS_rsa_signing_key_path << "'.";
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptor_source.reset(new WidevineEncryptorSource(
|
encryption_key_source.reset(new WidevineEncryptionKeySource(
|
||||||
FLAGS_server_url, FLAGS_content_id, signer.Pass()));
|
FLAGS_server_url, FLAGS_content_id, signer.Pass()));
|
||||||
} else if (FLAGS_enable_fixed_key_encryption) {
|
} else if (FLAGS_enable_fixed_key_encryption) {
|
||||||
encryptor_source = EncryptorSource::CreateFromHexStrings(
|
encryption_key_source = EncryptionKeySource::CreateFromHexStrings(
|
||||||
FLAGS_key_id, FLAGS_key, FLAGS_pssh, "");
|
FLAGS_key_id, FLAGS_key, FLAGS_pssh, "");
|
||||||
}
|
}
|
||||||
return encryptor_source.Pass();
|
return encryption_key_source.Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetMuxerOptions(MuxerOptions* muxer_options) {
|
bool GetMuxerOptions(MuxerOptions* muxer_options) {
|
||||||
|
@ -206,21 +206,21 @@ bool RunPackager(const std::string& input) {
|
||||||
if (!AddStreamToMuxer(demuxer.streams(), muxer.get()))
|
if (!AddStreamToMuxer(demuxer.streams(), muxer.get()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
scoped_ptr<EncryptorSource> encryptor_source;
|
scoped_ptr<EncryptionKeySource> encryption_key_source;
|
||||||
if (FLAGS_enable_widevine_encryption || FLAGS_enable_fixed_key_encryption) {
|
if (FLAGS_enable_widevine_encryption || FLAGS_enable_fixed_key_encryption) {
|
||||||
encryptor_source = CreateEncryptorSource();
|
encryption_key_source = CreateEncryptionKeySource();
|
||||||
if (!encryptor_source)
|
if (!encryption_key_source)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EncryptorSource::TrackType track_type =
|
EncryptionKeySource::TrackType track_type =
|
||||||
EncryptorSource::GetTrackTypeFromString(FLAGS_track_type);
|
EncryptionKeySource::GetTrackTypeFromString(FLAGS_track_type);
|
||||||
if (track_type != EncryptorSource::TRACK_TYPE_SD &&
|
if (track_type != EncryptionKeySource::TRACK_TYPE_SD &&
|
||||||
track_type != EncryptorSource::TRACK_TYPE_HD) {
|
track_type != EncryptionKeySource::TRACK_TYPE_HD) {
|
||||||
LOG(ERROR) << "FLAGS_track_type should be either 'SD' or 'HD'";
|
LOG(ERROR) << "FLAGS_track_type should be either 'SD' or 'HD'";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
muxer->SetEncryptorSource(
|
muxer->SetEncryptionKeySource(
|
||||||
encryptor_source.get(), track_type, FLAGS_clear_lead);
|
encryption_key_source.get(), track_type, FLAGS_clear_lead);
|
||||||
|
|
||||||
// Start remuxing process.
|
// Start remuxing process.
|
||||||
status = demuxer.Run();
|
status = demuxer.Run();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// license that can be found in the LICENSE file or at
|
// license that can be found in the LICENSE file or at
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
// https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
|
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
#include "media/base/aes_encryptor.h"
|
#include "media/base/aes_encryptor.h"
|
||||||
|
@ -21,16 +21,16 @@ namespace media {
|
||||||
EncryptionKey::EncryptionKey() {}
|
EncryptionKey::EncryptionKey() {}
|
||||||
EncryptionKey::~EncryptionKey() {}
|
EncryptionKey::~EncryptionKey() {}
|
||||||
|
|
||||||
EncryptorSource::~EncryptorSource() {}
|
EncryptionKeySource::~EncryptionKeySource() {}
|
||||||
|
|
||||||
Status EncryptorSource::GetKey(TrackType track_type, EncryptionKey* key) {
|
Status EncryptionKeySource::GetKey(TrackType track_type, EncryptionKey* key) {
|
||||||
DCHECK(key);
|
DCHECK(key);
|
||||||
DCHECK(encryption_key_);
|
DCHECK(encryption_key_);
|
||||||
*key = *encryption_key_;
|
*key = *encryption_key_;
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_ptr<EncryptorSource> EncryptorSource::CreateFromHexStrings(
|
scoped_ptr<EncryptionKeySource> EncryptionKeySource::CreateFromHexStrings(
|
||||||
const std::string& key_id_hex,
|
const std::string& key_id_hex,
|
||||||
const std::string& key_hex,
|
const std::string& key_hex,
|
||||||
const std::string& pssh_data_hex,
|
const std::string& pssh_data_hex,
|
||||||
|
@ -39,33 +39,33 @@ scoped_ptr<EncryptorSource> EncryptorSource::CreateFromHexStrings(
|
||||||
|
|
||||||
if (!base::HexStringToBytes(key_id_hex, &encryption_key->key_id)) {
|
if (!base::HexStringToBytes(key_id_hex, &encryption_key->key_id)) {
|
||||||
LOG(ERROR) << "Cannot parse key_id_hex " << key_id_hex;
|
LOG(ERROR) << "Cannot parse key_id_hex " << key_id_hex;
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!base::HexStringToBytes(key_hex, &encryption_key->key)) {
|
if (!base::HexStringToBytes(key_hex, &encryption_key->key)) {
|
||||||
LOG(ERROR) << "Cannot parse key_hex " << key_hex;
|
LOG(ERROR) << "Cannot parse key_hex " << key_hex;
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8> pssh_data;
|
std::vector<uint8> pssh_data;
|
||||||
if (!base::HexStringToBytes(pssh_data_hex, &pssh_data)) {
|
if (!base::HexStringToBytes(pssh_data_hex, &pssh_data)) {
|
||||||
LOG(ERROR) << "Cannot parse pssh_hex " << pssh_data_hex;
|
LOG(ERROR) << "Cannot parse pssh_hex " << pssh_data_hex;
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iv_hex.empty()) {
|
if (!iv_hex.empty()) {
|
||||||
if (!base::HexStringToBytes(iv_hex, &encryption_key->iv)) {
|
if (!base::HexStringToBytes(iv_hex, &encryption_key->iv)) {
|
||||||
LOG(ERROR) << "Cannot parse iv_hex " << iv_hex;
|
LOG(ERROR) << "Cannot parse iv_hex " << iv_hex;
|
||||||
return scoped_ptr<EncryptorSource>();
|
return scoped_ptr<EncryptionKeySource>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);
|
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);
|
||||||
return scoped_ptr<EncryptorSource>(
|
return scoped_ptr<EncryptionKeySource>(
|
||||||
new EncryptorSource(encryption_key.Pass()));
|
new EncryptionKeySource(encryption_key.Pass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptorSource::TrackType EncryptorSource::GetTrackTypeFromString(
|
EncryptionKeySource::TrackType EncryptionKeySource::GetTrackTypeFromString(
|
||||||
const std::string& track_type_string) {
|
const std::string& track_type_string) {
|
||||||
if (track_type_string == "SD")
|
if (track_type_string == "SD")
|
||||||
return TRACK_TYPE_SD;
|
return TRACK_TYPE_SD;
|
||||||
|
@ -77,7 +77,7 @@ EncryptorSource::TrackType EncryptorSource::GetTrackTypeFromString(
|
||||||
return TRACK_TYPE_UNKNOWN;
|
return TRACK_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EncryptorSource::TrackTypeToString(TrackType track_type) {
|
std::string EncryptionKeySource::TrackTypeToString(TrackType track_type) {
|
||||||
switch (track_type) {
|
switch (track_type) {
|
||||||
case TRACK_TYPE_SD:
|
case TRACK_TYPE_SD:
|
||||||
return "SD";
|
return "SD";
|
||||||
|
@ -91,7 +91,7 @@ std::string EncryptorSource::TrackTypeToString(TrackType track_type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8> EncryptorSource::PsshBoxFromPsshData(
|
std::vector<uint8> EncryptionKeySource::PsshBoxFromPsshData(
|
||||||
const std::vector<uint8>& pssh_data) {
|
const std::vector<uint8>& pssh_data) {
|
||||||
const uint8 kPsshFourCC[] = {'p', 's', 's', 'h'};
|
const uint8 kPsshFourCC[] = {'p', 's', 's', 'h'};
|
||||||
const uint32 kVersionAndFlags = 0;
|
const uint32 kVersionAndFlags = 0;
|
||||||
|
@ -111,8 +111,9 @@ std::vector<uint8> EncryptorSource::PsshBoxFromPsshData(
|
||||||
return std::vector<uint8>(writer.Buffer(), writer.Buffer() + writer.Size());
|
return std::vector<uint8>(writer.Buffer(), writer.Buffer() + writer.Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptorSource::EncryptorSource() {}
|
EncryptionKeySource::EncryptionKeySource() {}
|
||||||
EncryptorSource::EncryptorSource(scoped_ptr<EncryptionKey> encryption_key)
|
EncryptionKeySource::EncryptionKeySource(
|
||||||
|
scoped_ptr<EncryptionKey> encryption_key)
|
||||||
: encryption_key_(encryption_key.Pass()) {
|
: encryption_key_(encryption_key.Pass()) {
|
||||||
DCHECK(encryption_key_);
|
DCHECK(encryption_key_);
|
||||||
}
|
}
|
|
@ -4,8 +4,8 @@
|
||||||
// license that can be found in the LICENSE file or at
|
// license that can be found in the LICENSE file or at
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
// https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
#ifndef MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|
#ifndef MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|
||||||
#define MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|
#define MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ struct EncryptionKey {
|
||||||
std::vector<uint8> iv;
|
std::vector<uint8> iv;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// EncryptorSource is responsible for encryption key acquisition.
|
/// EncryptionKeySource is responsible for encryption key acquisition.
|
||||||
class EncryptorSource {
|
class EncryptionKeySource {
|
||||||
public:
|
public:
|
||||||
enum TrackType {
|
enum TrackType {
|
||||||
TRACK_TYPE_UNKNOWN = 0,
|
TRACK_TYPE_UNKNOWN = 0,
|
||||||
|
@ -35,13 +35,13 @@ class EncryptorSource {
|
||||||
NUM_VALID_TRACK_TYPES = 3
|
NUM_VALID_TRACK_TYPES = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~EncryptorSource();
|
virtual ~EncryptionKeySource();
|
||||||
|
|
||||||
/// Get encryption key of the specified track type.
|
/// Get encryption key of the specified track type.
|
||||||
/// @return OK on success, an error status otherwise.
|
/// @return OK on success, an error status otherwise.
|
||||||
virtual Status GetKey(TrackType track_type, EncryptionKey* key);
|
virtual Status GetKey(TrackType track_type, EncryptionKey* key);
|
||||||
|
|
||||||
/// Create EncryptorSource object from hex strings.
|
/// Create EncryptionKeySource object from hex strings.
|
||||||
/// @param key_id_hex is the key id in hex string.
|
/// @param key_id_hex is the key id in hex string.
|
||||||
/// @param key_hex is the key in hex string.
|
/// @param key_hex is the key in hex string.
|
||||||
/// @param pssh_data_hex is the pssh_data in hex string.
|
/// @param pssh_data_hex is the pssh_data in hex string.
|
||||||
|
@ -49,7 +49,7 @@ class EncryptorSource {
|
||||||
/// generated IV with the default length will be used.
|
/// generated IV with the default length will be used.
|
||||||
/// Note: GetKey on the created key source will always return the same key
|
/// Note: GetKey on the created key source will always return the same key
|
||||||
/// for all track types.
|
/// for all track types.
|
||||||
static scoped_ptr<EncryptorSource> CreateFromHexStrings(
|
static scoped_ptr<EncryptionKeySource> CreateFromHexStrings(
|
||||||
const std::string& key_id_hex,
|
const std::string& key_id_hex,
|
||||||
const std::string& key_hex,
|
const std::string& key_hex,
|
||||||
const std::string& pssh_data_hex,
|
const std::string& pssh_data_hex,
|
||||||
|
@ -62,7 +62,7 @@ class EncryptorSource {
|
||||||
static std::string TrackTypeToString(TrackType track_type);
|
static std::string TrackTypeToString(TrackType track_type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EncryptorSource();
|
EncryptionKeySource();
|
||||||
|
|
||||||
/// @return the raw bytes of the pssh box with system ID and box header
|
/// @return the raw bytes of the pssh box with system ID and box header
|
||||||
/// included.
|
/// included.
|
||||||
|
@ -70,13 +70,13 @@ class EncryptorSource {
|
||||||
const std::vector<uint8>& pssh_data);
|
const std::vector<uint8>& pssh_data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit EncryptorSource(scoped_ptr<EncryptionKey> encryption_key);
|
explicit EncryptionKeySource(scoped_ptr<EncryptionKey> encryption_key);
|
||||||
|
|
||||||
scoped_ptr<EncryptionKey> encryption_key_;
|
scoped_ptr<EncryptionKey> encryption_key_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(EncryptorSource);
|
DISALLOW_COPY_AND_ASSIGN(EncryptionKeySource);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
|
|
||||||
#endif // MEDIA_BASE_ENCRYPTOR_SOURCE_H_
|
#endif // MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|
|
@ -1,46 +0,0 @@
|
||||||
// Copyright 2014 Google Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
|
||||||
|
|
||||||
#include "media/base/fixed_encryptor_source.h"
|
|
||||||
|
|
||||||
#include "base/logging.h"
|
|
||||||
#include "base/strings/string_number_conversions.h"
|
|
||||||
|
|
||||||
namespace media {
|
|
||||||
|
|
||||||
FixedEncryptorSource::FixedEncryptorSource(const std::string& key_id_hex,
|
|
||||||
const std::string& key_hex,
|
|
||||||
const std::string& pssh_hex)
|
|
||||||
: key_id_hex_(key_id_hex), key_hex_(key_hex), pssh_hex_(pssh_hex) {}
|
|
||||||
|
|
||||||
FixedEncryptorSource::~FixedEncryptorSource() {}
|
|
||||||
|
|
||||||
Status FixedEncryptorSource::Initialize() {
|
|
||||||
std::vector<uint8> key_id;
|
|
||||||
if (!base::HexStringToBytes(key_id_hex_, &key_id)) {
|
|
||||||
LOG(ERROR) << "Cannot parse key_id_hex " << key_id_hex_;
|
|
||||||
return Status(error::INVALID_ARGUMENT, "Cannot parse input key_id_hex.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8> key;
|
|
||||||
if (!base::HexStringToBytes(key_hex_, &key)) {
|
|
||||||
LOG(ERROR) << "Cannot parse key_hex " << key_hex_;
|
|
||||||
return Status(error::INVALID_ARGUMENT, "Cannot parse input key_hex.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8> pssh;
|
|
||||||
if (!base::HexStringToBytes(pssh_hex_, &pssh)) {
|
|
||||||
LOG(ERROR) << "Cannot parse pssh_hex " << pssh_hex_;
|
|
||||||
return Status(error::INVALID_ARGUMENT, "Cannot parse input pssh_hex.");
|
|
||||||
}
|
|
||||||
|
|
||||||
set_key_id(key_id);
|
|
||||||
set_key(key);
|
|
||||||
set_pssh(pssh);
|
|
||||||
return Status::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace media
|
|
|
@ -1,35 +0,0 @@
|
||||||
// Copyright 2014 Google Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file or at
|
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
|
||||||
|
|
||||||
#ifndef MEDIA_BASE_FIXED_ENCRYPTOR_SOURCE_H_
|
|
||||||
#define MEDIA_BASE_FIXED_ENCRYPTOR_SOURCE_H_
|
|
||||||
|
|
||||||
#include "media/base/encryptor_source.h"
|
|
||||||
|
|
||||||
namespace media {
|
|
||||||
|
|
||||||
/// Defines a fixed encryptor source with keys provided by the user.
|
|
||||||
class FixedEncryptorSource : public EncryptorSource {
|
|
||||||
public:
|
|
||||||
FixedEncryptorSource(const std::string& key_id_hex,
|
|
||||||
const std::string& key_hex,
|
|
||||||
const std::string& pssh_hex);
|
|
||||||
virtual ~FixedEncryptorSource();
|
|
||||||
|
|
||||||
/// EncryptorSource implementation override.
|
|
||||||
virtual Status Initialize() OVERRIDE;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string key_id_hex_;
|
|
||||||
std::string key_hex_;
|
|
||||||
std::string pssh_hex_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(FixedEncryptorSource);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace media
|
|
||||||
|
|
||||||
#endif // MEDIA_BASE_FIXED_ENCRYPTOR_SOURCE_H_
|
|
|
@ -74,8 +74,8 @@
|
||||||
'decrypt_config.cc',
|
'decrypt_config.cc',
|
||||||
'decrypt_config.h',
|
'decrypt_config.h',
|
||||||
'decryptor_source.h',
|
'decryptor_source.h',
|
||||||
'encryptor_source.cc',
|
'encryption_key_source.cc',
|
||||||
'encryptor_source.h',
|
'encryption_key_source.h',
|
||||||
'limits.h',
|
'limits.h',
|
||||||
'media_parser.h',
|
'media_parser.h',
|
||||||
'media_sample.cc',
|
'media_sample.cc',
|
||||||
|
@ -99,8 +99,8 @@
|
||||||
'timestamp.h',
|
'timestamp.h',
|
||||||
'video_stream_info.cc',
|
'video_stream_info.cc',
|
||||||
'video_stream_info.h',
|
'video_stream_info.h',
|
||||||
'widevine_encryptor_source.cc',
|
'widevine_encryption_key_source.cc',
|
||||||
'widevine_encryptor_source.h',
|
'widevine_encryption_key_source.h',
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'../../base/base.gyp:base',
|
'../../base/base.gyp:base',
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
'status_test_util.h',
|
'status_test_util.h',
|
||||||
'status_test_util_unittest.cc',
|
'status_test_util_unittest.cc',
|
||||||
'status_unittest.cc',
|
'status_unittest.cc',
|
||||||
'widevine_encryptor_source_unittest.cc',
|
'widevine_encryption_key_source_unittest.cc',
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'../../testing/gtest.gyp:gtest',
|
'../../testing/gtest.gyp:gtest',
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "media/base/muxer.h"
|
#include "media/base/muxer.h"
|
||||||
|
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/media_sample.h"
|
#include "media/base/media_sample.h"
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
|
|
||||||
|
@ -14,19 +14,19 @@ namespace media {
|
||||||
|
|
||||||
Muxer::Muxer(const MuxerOptions& options)
|
Muxer::Muxer(const MuxerOptions& options)
|
||||||
: options_(options),
|
: options_(options),
|
||||||
encryptor_source_(NULL),
|
encryption_key_source_(NULL),
|
||||||
initialized_(false),
|
initialized_(false),
|
||||||
track_type_(EncryptorSource::TRACK_TYPE_SD),
|
track_type_(EncryptionKeySource::TRACK_TYPE_SD),
|
||||||
clear_lead_in_seconds_(0),
|
clear_lead_in_seconds_(0),
|
||||||
muxer_listener_(NULL),
|
muxer_listener_(NULL),
|
||||||
clock_(NULL) {}
|
clock_(NULL) {}
|
||||||
|
|
||||||
Muxer::~Muxer() {}
|
Muxer::~Muxer() {}
|
||||||
|
|
||||||
void Muxer::SetEncryptorSource(EncryptorSource* encryptor_source,
|
void Muxer::SetEncryptionKeySource(EncryptionKeySource* encryption_key_source,
|
||||||
EncryptorSource::TrackType track_type,
|
EncryptionKeySource::TrackType track_type,
|
||||||
double clear_lead_in_seconds) {
|
double clear_lead_in_seconds) {
|
||||||
encryptor_source_ = encryptor_source;
|
encryption_key_source_ = encryption_key_source;
|
||||||
track_type_ = track_type;
|
track_type_ = track_type;
|
||||||
clear_lead_in_seconds_ = clear_lead_in_seconds;
|
clear_lead_in_seconds_ = clear_lead_in_seconds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "base/memory/ref_counted.h"
|
#include "base/memory/ref_counted.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/muxer_options.h"
|
#include "media/base/muxer_options.h"
|
||||||
#include "media/base/status.h"
|
#include "media/base/status.h"
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Clock;
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
class EncryptorSource;
|
class EncryptionKeySource;
|
||||||
class MediaSample;
|
class MediaSample;
|
||||||
class MediaStream;
|
class MediaStream;
|
||||||
|
|
||||||
|
@ -32,22 +32,22 @@ class MuxerListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Muxer is responsible for taking elementary stream samples and producing
|
/// Muxer is responsible for taking elementary stream samples and producing
|
||||||
/// media containers. An optional EncryptorSource can be provided to Muxer to
|
/// media containers. An optional EncryptionKeySource can be provided to Muxer
|
||||||
/// generate encrypted outputs.
|
/// to generate encrypted outputs.
|
||||||
class Muxer {
|
class Muxer {
|
||||||
public:
|
public:
|
||||||
explicit Muxer(const MuxerOptions& options);
|
explicit Muxer(const MuxerOptions& options);
|
||||||
virtual ~Muxer();
|
virtual ~Muxer();
|
||||||
|
|
||||||
/// Set encryptor source.
|
/// Set encryption key source.
|
||||||
/// @param encryptor_source points to the encryptor source to be injected.
|
/// @param encryption_key_source points to the encryption key source to be
|
||||||
/// Should not be NULL.
|
/// injected. Should not be NULL.
|
||||||
/// @param track_type should be either SD or HD. It affects whether SD key or
|
/// @param track_type should be either SD or HD. It affects whether SD key or
|
||||||
/// HD key is used to encrypt the video content.
|
/// HD key is used to encrypt the video content.
|
||||||
/// @param clear_lead_in_seconds specifies clear lead duration in seconds.
|
/// @param clear_lead_in_seconds specifies clear lead duration in seconds.
|
||||||
void SetEncryptorSource(EncryptorSource* encryptor_source,
|
void SetEncryptionKeySource(EncryptionKeySource* encryption_key_source,
|
||||||
EncryptorSource::TrackType track_type,
|
EncryptionKeySource::TrackType track_type,
|
||||||
double clear_lead_in_seconds);
|
double clear_lead_in_seconds);
|
||||||
|
|
||||||
/// Add video/audio stream.
|
/// Add video/audio stream.
|
||||||
void AddStream(MediaStream* stream);
|
void AddStream(MediaStream* stream);
|
||||||
|
@ -73,8 +73,10 @@ class Muxer {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const MuxerOptions& options() const { return options_; }
|
const MuxerOptions& options() const { return options_; }
|
||||||
EncryptorSource* encryptor_source() { return encryptor_source_; }
|
EncryptionKeySource* encryption_key_source() {
|
||||||
EncryptorSource::TrackType track_type() const { return track_type_; }
|
return encryption_key_source_;
|
||||||
|
}
|
||||||
|
EncryptionKeySource::TrackType track_type() const { return track_type_; }
|
||||||
double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
|
double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
|
||||||
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
||||||
base::Clock* clock() { return clock_; }
|
base::Clock* clock() { return clock_; }
|
||||||
|
@ -98,9 +100,9 @@ class Muxer {
|
||||||
|
|
||||||
MuxerOptions options_;
|
MuxerOptions options_;
|
||||||
std::vector<MediaStream*> streams_;
|
std::vector<MediaStream*> streams_;
|
||||||
EncryptorSource* encryptor_source_;
|
EncryptionKeySource* encryption_key_source_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
EncryptorSource::TrackType track_type_;
|
EncryptionKeySource::TrackType track_type_;
|
||||||
double clear_lead_in_seconds_;
|
double clear_lead_in_seconds_;
|
||||||
|
|
||||||
event::MuxerListener* muxer_listener_;
|
event::MuxerListener* muxer_listener_;
|
||||||
|
|
|
@ -4,14 +4,12 @@
|
||||||
// license that can be found in the LICENSE file or at
|
// license that can be found in the LICENSE file or at
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
// https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
#include "media/base/widevine_encryptor_source.h"
|
#include "media/base/widevine_encryption_key_source.h"
|
||||||
|
|
||||||
#include "base/base64.h"
|
#include "base/base64.h"
|
||||||
#include "base/json/json_reader.h"
|
#include "base/json/json_reader.h"
|
||||||
#include "base/json/json_writer.h"
|
#include "base/json/json_writer.h"
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
#include "base/time/time.h"
|
|
||||||
#include "base/threading/platform_thread.h"
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "media/base/http_fetcher.h"
|
#include "media/base/http_fetcher.h"
|
||||||
#include "media/base/request_signer.h"
|
#include "media/base/request_signer.h"
|
||||||
|
@ -95,7 +93,7 @@ bool GetPsshData(const base::DictionaryValue& track_dict,
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
WidevineEncryptorSource::WidevineEncryptorSource(
|
WidevineEncryptionKeySource::WidevineEncryptionKeySource(
|
||||||
const std::string& server_url,
|
const std::string& server_url,
|
||||||
const std::string& content_id,
|
const std::string& content_id,
|
||||||
scoped_ptr<RequestSigner> signer)
|
scoped_ptr<RequestSigner> signer)
|
||||||
|
@ -106,12 +104,12 @@ WidevineEncryptorSource::WidevineEncryptorSource(
|
||||||
key_fetched_(false) {
|
key_fetched_(false) {
|
||||||
DCHECK(signer_);
|
DCHECK(signer_);
|
||||||
}
|
}
|
||||||
WidevineEncryptorSource::~WidevineEncryptorSource() {
|
WidevineEncryptionKeySource::~WidevineEncryptionKeySource() {
|
||||||
STLDeleteValues(&encryption_key_map_);
|
STLDeleteValues(&encryption_key_map_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status WidevineEncryptorSource::GetKey(TrackType track_type,
|
Status WidevineEncryptionKeySource::GetKey(TrackType track_type,
|
||||||
EncryptionKey* key) {
|
EncryptionKey* key) {
|
||||||
DCHECK(track_type == TRACK_TYPE_SD || track_type == TRACK_TYPE_HD ||
|
DCHECK(track_type == TRACK_TYPE_SD || track_type == TRACK_TYPE_HD ||
|
||||||
track_type == TRACK_TYPE_AUDIO);
|
track_type == TRACK_TYPE_AUDIO);
|
||||||
Status status;
|
Status status;
|
||||||
|
@ -133,12 +131,12 @@ Status WidevineEncryptorSource::GetKey(TrackType track_type,
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidevineEncryptorSource::set_http_fetcher(
|
void WidevineEncryptionKeySource::set_http_fetcher(
|
||||||
scoped_ptr<HttpFetcher> http_fetcher) {
|
scoped_ptr<HttpFetcher> http_fetcher) {
|
||||||
http_fetcher_ = http_fetcher.Pass();
|
http_fetcher_ = http_fetcher.Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status WidevineEncryptorSource::FetchKeys() {
|
Status WidevineEncryptionKeySource::FetchKeys() {
|
||||||
std::string request;
|
std::string request;
|
||||||
FillRequest(content_id_, &request);
|
FillRequest(content_id_, &request);
|
||||||
|
|
||||||
|
@ -186,8 +184,8 @@ Status WidevineEncryptorSource::FetchKeys() {
|
||||||
"Failed to recover from server internal error.");
|
"Failed to recover from server internal error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidevineEncryptorSource::FillRequest(const std::string& content_id,
|
void WidevineEncryptionKeySource::FillRequest(const std::string& content_id,
|
||||||
std::string* request) {
|
std::string* request) {
|
||||||
DCHECK(request);
|
DCHECK(request);
|
||||||
|
|
||||||
std::string content_id_base64_string;
|
std::string content_id_base64_string;
|
||||||
|
@ -220,8 +218,8 @@ void WidevineEncryptorSource::FillRequest(const std::string& content_id,
|
||||||
base::JSONWriter::Write(&request_dict, request);
|
base::JSONWriter::Write(&request_dict, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status WidevineEncryptorSource::SignRequest(const std::string& request,
|
Status WidevineEncryptionKeySource::SignRequest(const std::string& request,
|
||||||
std::string* signed_request) {
|
std::string* signed_request) {
|
||||||
DCHECK(signed_request);
|
DCHECK(signed_request);
|
||||||
|
|
||||||
// Sign the request.
|
// Sign the request.
|
||||||
|
@ -245,8 +243,9 @@ Status WidevineEncryptorSource::SignRequest(const std::string& request,
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WidevineEncryptorSource::DecodeResponse(const std::string& raw_response,
|
bool WidevineEncryptionKeySource::DecodeResponse(
|
||||||
std::string* response) {
|
const std::string& raw_response,
|
||||||
|
std::string* response) {
|
||||||
DCHECK(response);
|
DCHECK(response);
|
||||||
|
|
||||||
// Extract base64 formatted response from JSON formatted raw response.
|
// Extract base64 formatted response from JSON formatted raw response.
|
||||||
|
@ -264,8 +263,9 @@ bool WidevineEncryptorSource::DecodeResponse(const std::string& raw_response,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WidevineEncryptorSource::ExtractEncryptionKey(const std::string& response,
|
bool WidevineEncryptionKeySource::ExtractEncryptionKey(
|
||||||
bool* transient_error) {
|
const std::string& response,
|
||||||
|
bool* transient_error) {
|
||||||
DCHECK(transient_error);
|
DCHECK(transient_error);
|
||||||
*transient_error = false;
|
*transient_error = false;
|
||||||
|
|
||||||
|
@ -302,8 +302,8 @@ bool WidevineEncryptorSource::ExtractEncryptionKey(const std::string& response,
|
||||||
|
|
||||||
scoped_ptr<EncryptionKey> encryption_key(new EncryptionKey());
|
scoped_ptr<EncryptionKey> encryption_key(new EncryptionKey());
|
||||||
std::vector<uint8> pssh_data;
|
std::vector<uint8> pssh_data;
|
||||||
if (!GetKeyAndKeyId(*track_dict, &encryption_key->key,
|
if (!GetKeyAndKeyId(
|
||||||
&encryption_key->key_id) ||
|
*track_dict, &encryption_key->key, &encryption_key->key_id) ||
|
||||||
!GetPsshData(*track_dict, &pssh_data))
|
!GetPsshData(*track_dict, &pssh_data))
|
||||||
return false;
|
return false;
|
||||||
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);
|
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);
|
|
@ -4,33 +4,34 @@
|
||||||
// license that can be found in the LICENSE file or at
|
// license that can be found in the LICENSE file or at
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
// https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
#ifndef MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|
#ifndef MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_
|
||||||
#define MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|
#define MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/synchronization/lock.h"
|
#include "base/synchronization/lock.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
class HttpFetcher;
|
class HttpFetcher;
|
||||||
class RequestSigner;
|
class RequestSigner;
|
||||||
|
|
||||||
/// Encryptor source which talks to the Widevine encryption service.
|
/// WidevineEncryptionKeySource talks to the Widevine encryption service to
|
||||||
class WidevineEncryptorSource : public EncryptorSource {
|
/// acquire the encryption keys.
|
||||||
|
class WidevineEncryptionKeySource : public EncryptionKeySource {
|
||||||
public:
|
public:
|
||||||
/// @param server_url is the Widevine common encryption server url.
|
/// @param server_url is the Widevine common encryption server url.
|
||||||
/// @param content_id the unique id identify the content to be encrypted.
|
/// @param content_id the unique id identify the content to be encrypted.
|
||||||
/// @param signer must not be NULL.
|
/// @param signer must not be NULL.
|
||||||
WidevineEncryptorSource(const std::string& server_url,
|
WidevineEncryptionKeySource(const std::string& server_url,
|
||||||
const std::string& content_id,
|
const std::string& content_id,
|
||||||
scoped_ptr<RequestSigner> signer);
|
scoped_ptr<RequestSigner> signer);
|
||||||
virtual ~WidevineEncryptorSource();
|
virtual ~WidevineEncryptionKeySource();
|
||||||
|
|
||||||
/// EncryptorSource implementation override.
|
/// EncryptionKeySource implementation override.
|
||||||
virtual Status GetKey(TrackType track_type, EncryptionKey* key) OVERRIDE;
|
virtual Status GetKey(TrackType track_type, EncryptionKey* key) OVERRIDE;
|
||||||
|
|
||||||
/// Inject an @b HttpFetcher object, mainly used for testing.
|
/// Inject an @b HttpFetcher object, mainly used for testing.
|
||||||
|
@ -54,8 +55,7 @@ class WidevineEncryptorSource : public EncryptorSource {
|
||||||
// formatted. |transient_error| will be set to true if it fails and the
|
// formatted. |transient_error| will be set to true if it fails and the
|
||||||
// failure is because of a transient error from the server. |transient_error|
|
// failure is because of a transient error from the server. |transient_error|
|
||||||
// should not be NULL.
|
// should not be NULL.
|
||||||
bool ExtractEncryptionKey(const std::string& response,
|
bool ExtractEncryptionKey(const std::string& response, bool* transient_error);
|
||||||
bool* transient_error);
|
|
||||||
|
|
||||||
// The fetcher object used to fetch HTTP response from server.
|
// The fetcher object used to fetch HTTP response from server.
|
||||||
// It is initialized to a default fetcher on class initialization.
|
// It is initialized to a default fetcher on class initialization.
|
||||||
|
@ -69,9 +69,9 @@ class WidevineEncryptorSource : public EncryptorSource {
|
||||||
bool key_fetched_; // Protected by lock_;
|
bool key_fetched_; // Protected by lock_;
|
||||||
std::map<TrackType, EncryptionKey*> encryption_key_map_;
|
std::map<TrackType, EncryptionKey*> encryption_key_map_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptorSource);
|
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptionKeySource);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
||||||
|
|
||||||
#endif // MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
|
#endif // MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_
|
|
@ -4,7 +4,7 @@
|
||||||
// license that can be found in the LICENSE file or at
|
// license that can be found in the LICENSE file or at
|
||||||
// https://developers.google.com/open-source/licenses/bsd
|
// https://developers.google.com/open-source/licenses/bsd
|
||||||
|
|
||||||
#include "media/base/widevine_encryptor_source.h"
|
#include "media/base/widevine_encryption_key_source.h"
|
||||||
|
|
||||||
#include "base/base64.h"
|
#include "base/base64.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
|
@ -23,9 +23,10 @@ const char kMockSignature[] = "MockSignature";
|
||||||
|
|
||||||
// The license service may return an error indicating a transient error has
|
// The license service may return an error indicating a transient error has
|
||||||
// just happened in the server, or other types of errors.
|
// just happened in the server, or other types of errors.
|
||||||
// WidevineEncryptorSource will perform a number of retries on transient errors;
|
// WidevineEncryptionKeySource will perform a number of retries on transient
|
||||||
// WidevineEncryptorSource does not know about other errors and retries are not
|
// errors;
|
||||||
// performed.
|
// WidevineEncryptionKeySource does not know about other errors and retries are
|
||||||
|
// not performed.
|
||||||
const char kLicenseStatusTransientError[] = "INTERNAL_ERROR";
|
const char kLicenseStatusTransientError[] = "INTERNAL_ERROR";
|
||||||
const char kLicenseStatusUnknownError[] = "UNKNOWN_ERROR";
|
const char kLicenseStatusUnknownError[] = "UNKNOWN_ERROR";
|
||||||
|
|
||||||
|
@ -37,8 +38,7 @@ const char kExpectedSignedMessageFormat[] =
|
||||||
const char kTrackFormat[] =
|
const char kTrackFormat[] =
|
||||||
"{\"type\":\"%s\",\"key_id\":\"%s\",\"key\":"
|
"{\"type\":\"%s\",\"key_id\":\"%s\",\"key\":"
|
||||||
"\"%s\",\"pssh\":[{\"drm_type\":\"WIDEVINE\",\"data\":\"%s\"}]}";
|
"\"%s\",\"pssh\":[{\"drm_type\":\"WIDEVINE\",\"data\":\"%s\"}]}";
|
||||||
const char kLicenseResponseFormat[] =
|
const char kLicenseResponseFormat[] = "{\"status\":\"%s\",\"tracks\":[%s]}";
|
||||||
"{\"status\":\"%s\",\"tracks\":[%s]}";
|
|
||||||
const char kHttpResponseFormat[] = "{\"response\":\"%s\"}";
|
const char kHttpResponseFormat[] = "{\"response\":\"%s\"}";
|
||||||
|
|
||||||
std::string Base64Encode(const std::string& input) {
|
std::string Base64Encode(const std::string& input) {
|
||||||
|
@ -122,55 +122,53 @@ class MockHttpFetcher : public HttpFetcher {
|
||||||
DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher);
|
DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WidevineEncryptorSourceTest : public ::testing::Test {
|
class WidevineEncryptionKeySourceTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
WidevineEncryptorSourceTest()
|
WidevineEncryptionKeySourceTest()
|
||||||
: mock_request_signer_(new MockRequestSigner(kSignerName)),
|
: mock_request_signer_(new MockRequestSigner(kSignerName)),
|
||||||
mock_http_fetcher_(new MockHttpFetcher()) {}
|
mock_http_fetcher_(new MockHttpFetcher()) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void CreateWidevineEncryptorSource() {
|
void CreateWidevineEncryptionKeySource() {
|
||||||
widevine_encryptor_source_.reset(new WidevineEncryptorSource(
|
widevine_encryption_key_source_.reset(new WidevineEncryptionKeySource(
|
||||||
kServerUrl,
|
kServerUrl, kContentId, mock_request_signer_.PassAs<RequestSigner>()));
|
||||||
kContentId,
|
widevine_encryption_key_source_->set_http_fetcher(
|
||||||
mock_request_signer_.PassAs<RequestSigner>()));
|
|
||||||
widevine_encryptor_source_->set_http_fetcher(
|
|
||||||
mock_http_fetcher_.PassAs<HttpFetcher>());
|
mock_http_fetcher_.PassAs<HttpFetcher>());
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_ptr<MockRequestSigner> mock_request_signer_;
|
scoped_ptr<MockRequestSigner> mock_request_signer_;
|
||||||
scoped_ptr<MockHttpFetcher> mock_http_fetcher_;
|
scoped_ptr<MockHttpFetcher> mock_http_fetcher_;
|
||||||
scoped_ptr<WidevineEncryptorSource> widevine_encryptor_source_;
|
scoped_ptr<WidevineEncryptionKeySource> widevine_encryption_key_source_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptorSourceTest);
|
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptionKeySourceTest);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WidevineEncryptorSourceTest, GetTrackTypeFromString) {
|
TEST_F(WidevineEncryptionKeySourceTest, GetTrackTypeFromString) {
|
||||||
EXPECT_EQ(EncryptorSource::TRACK_TYPE_SD,
|
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_SD,
|
||||||
EncryptorSource::GetTrackTypeFromString("SD"));
|
EncryptionKeySource::GetTrackTypeFromString("SD"));
|
||||||
EXPECT_EQ(EncryptorSource::TRACK_TYPE_HD,
|
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_HD,
|
||||||
EncryptorSource::GetTrackTypeFromString("HD"));
|
EncryptionKeySource::GetTrackTypeFromString("HD"));
|
||||||
EXPECT_EQ(EncryptorSource::TRACK_TYPE_AUDIO,
|
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_AUDIO,
|
||||||
EncryptorSource::GetTrackTypeFromString("AUDIO"));
|
EncryptionKeySource::GetTrackTypeFromString("AUDIO"));
|
||||||
EXPECT_EQ(EncryptorSource::TRACK_TYPE_UNKNOWN,
|
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_UNKNOWN,
|
||||||
EncryptorSource::GetTrackTypeFromString("FOO"));
|
EncryptionKeySource::GetTrackTypeFromString("FOO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WidevineEncryptorSourceTest, GeneratureSignatureFailure) {
|
TEST_F(WidevineEncryptionKeySourceTest, GeneratureSignatureFailure) {
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
|
|
||||||
CreateWidevineEncryptorSource();
|
CreateWidevineEncryptionKeySource();
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
ASSERT_EQ(Status(error::INTERNAL_ERROR, "Signature generation failed."),
|
ASSERT_EQ(Status(error::INTERNAL_ERROR, "Signature generation failed."),
|
||||||
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
|
widevine_encryption_key_source_->GetKey(
|
||||||
&encryption_key));
|
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether expected request message and post data was generated and
|
// Check whether expected request message and post data was generated and
|
||||||
// verify the correct behavior on http failure.
|
// verify the correct behavior on http failure.
|
||||||
TEST_F(WidevineEncryptorSourceTest, HttpPostFailure) {
|
TEST_F(WidevineEncryptionKeySourceTest, HttpPostFailure) {
|
||||||
std::string expected_message = base::StringPrintf(
|
std::string expected_message = base::StringPrintf(
|
||||||
kExpectedRequestMessageFormat, Base64Encode(kContentId).c_str());
|
kExpectedRequestMessageFormat, Base64Encode(kContentId).c_str());
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(expected_message, _))
|
||||||
|
@ -185,14 +183,14 @@ TEST_F(WidevineEncryptorSourceTest, HttpPostFailure) {
|
||||||
EXPECT_CALL(*mock_http_fetcher_, Post(kServerUrl, expected_post_data, _))
|
EXPECT_CALL(*mock_http_fetcher_, Post(kServerUrl, expected_post_data, _))
|
||||||
.WillOnce(Return(kMockStatus));
|
.WillOnce(Return(kMockStatus));
|
||||||
|
|
||||||
CreateWidevineEncryptorSource();
|
CreateWidevineEncryptionKeySource();
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
ASSERT_EQ(kMockStatus,
|
ASSERT_EQ(kMockStatus,
|
||||||
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
|
widevine_encryption_key_source_->GetKey(
|
||||||
&encryption_key));
|
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WidevineEncryptorSourceTest, LicenseStatusOK) {
|
TEST_F(WidevineEncryptionKeySourceTest, LicenseStatusOK) {
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
|
@ -202,13 +200,13 @@ TEST_F(WidevineEncryptorSourceTest, LicenseStatusOK) {
|
||||||
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
|
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
|
||||||
.WillOnce(DoAll(SetArgPointee<2>(expected_response), Return(Status::OK)));
|
.WillOnce(DoAll(SetArgPointee<2>(expected_response), Return(Status::OK)));
|
||||||
|
|
||||||
CreateWidevineEncryptorSource();
|
CreateWidevineEncryptionKeySource();
|
||||||
|
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
const std::string kTrackTypes[] = {"SD", "HD", "AUDIO"};
|
const std::string kTrackTypes[] = {"SD", "HD", "AUDIO"};
|
||||||
for (size_t i = 0; i < 3; ++i) {
|
for (size_t i = 0; i < 3; ++i) {
|
||||||
ASSERT_OK(widevine_encryptor_source_->GetKey(
|
ASSERT_OK(widevine_encryption_key_source_->GetKey(
|
||||||
EncryptorSource::GetTrackTypeFromString(kTrackTypes[i]),
|
EncryptionKeySource::GetTrackTypeFromString(kTrackTypes[i]),
|
||||||
&encryption_key));
|
&encryption_key));
|
||||||
EXPECT_EQ(GetMockKeyId(kTrackTypes[i]), ToString(encryption_key.key_id));
|
EXPECT_EQ(GetMockKeyId(kTrackTypes[i]), ToString(encryption_key.key_id));
|
||||||
EXPECT_EQ(GetMockKey(kTrackTypes[i]), ToString(encryption_key.key));
|
EXPECT_EQ(GetMockKey(kTrackTypes[i]), ToString(encryption_key.key));
|
||||||
|
@ -217,7 +215,7 @@ TEST_F(WidevineEncryptorSourceTest, LicenseStatusOK) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WidevineEncryptorSourceTest, RetryOnTransientError) {
|
TEST_F(WidevineEncryptionKeySourceTest, RetryOnTransientError) {
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
|
@ -235,17 +233,17 @@ TEST_F(WidevineEncryptorSourceTest, RetryOnTransientError) {
|
||||||
.WillOnce(DoAll(SetArgPointee<2>(expected_retried_response),
|
.WillOnce(DoAll(SetArgPointee<2>(expected_retried_response),
|
||||||
Return(Status::OK)));
|
Return(Status::OK)));
|
||||||
|
|
||||||
CreateWidevineEncryptorSource();
|
CreateWidevineEncryptionKeySource();
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
ASSERT_OK(widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
|
ASSERT_OK(widevine_encryption_key_source_->GetKey(
|
||||||
&encryption_key));
|
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
|
||||||
EXPECT_EQ(GetMockKeyId("SD"), ToString(encryption_key.key_id));
|
EXPECT_EQ(GetMockKeyId("SD"), ToString(encryption_key.key_id));
|
||||||
EXPECT_EQ(GetMockKey("SD"), ToString(encryption_key.key));
|
EXPECT_EQ(GetMockKey("SD"), ToString(encryption_key.key));
|
||||||
EXPECT_EQ(GetMockPsshData("SD"),
|
EXPECT_EQ(GetMockPsshData("SD"),
|
||||||
GetPsshDataFromPsshBox(ToString(encryption_key.pssh)));
|
GetPsshDataFromPsshBox(ToString(encryption_key.pssh)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WidevineEncryptorSourceTest, NoRetryOnUnknownError) {
|
TEST_F(WidevineEncryptionKeySourceTest, NoRetryOnUnknownError) {
|
||||||
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
|
@ -257,11 +255,13 @@ TEST_F(WidevineEncryptorSourceTest, NoRetryOnUnknownError) {
|
||||||
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
|
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
|
||||||
.WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK)));
|
.WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK)));
|
||||||
|
|
||||||
CreateWidevineEncryptorSource();
|
CreateWidevineEncryptionKeySource();
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
ASSERT_EQ(error::SERVER_ERROR,
|
ASSERT_EQ(
|
||||||
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
|
error::SERVER_ERROR,
|
||||||
&encryption_key).error_code());
|
widevine_encryption_key_source_->GetKey(
|
||||||
|
EncryptionKeySource::TRACK_TYPE_SD,
|
||||||
|
&encryption_key).error_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace media
|
} // namespace media
|
|
@ -10,7 +10,7 @@
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
#include "media/base/aes_encryptor.h"
|
#include "media/base/aes_encryptor.h"
|
||||||
#include "media/base/audio_stream_info.h"
|
#include "media/base/audio_stream_info.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/media_sample.h"
|
#include "media/base/media_sample.h"
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
#include "media/base/video_stream_info.h"
|
#include "media/base/video_stream_info.h"
|
||||||
|
@ -98,8 +98,11 @@ Status MP4Muxer::Initialize() {
|
||||||
new MultiSegmentSegmenter(options(), ftyp.Pass(), moov.Pass()));
|
new MultiSegmentSegmenter(options(), ftyp.Pass(), moov.Pass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Status segmenter_initialized = segmenter_->Initialize(
|
Status segmenter_initialized =
|
||||||
streams(), encryptor_source(), track_type(), clear_lead_in_seconds());
|
segmenter_->Initialize(streams(),
|
||||||
|
encryption_key_source(),
|
||||||
|
track_type(),
|
||||||
|
clear_lead_in_seconds());
|
||||||
|
|
||||||
if (!segmenter_initialized.ok())
|
if (!segmenter_initialized.ok())
|
||||||
return segmenter_initialized;
|
return segmenter_initialized;
|
||||||
|
@ -274,7 +277,7 @@ void MP4Muxer::FireOnMediaEndEvent() {
|
||||||
index_range_end,
|
index_range_end,
|
||||||
duration_seconds,
|
duration_seconds,
|
||||||
file_size,
|
file_size,
|
||||||
encryptor_source());
|
encryption_key_source());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 MP4Muxer::IsoTimeNow() {
|
uint64 MP4Muxer::IsoTimeNow() {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
#include "media/base/aes_encryptor.h"
|
#include "media/base/aes_encryptor.h"
|
||||||
#include "media/base/buffer_writer.h"
|
#include "media/base/buffer_writer.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/media_sample.h"
|
#include "media/base/media_sample.h"
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
#include "media/base/muxer_options.h"
|
#include "media/base/muxer_options.h"
|
||||||
|
@ -108,8 +108,8 @@ Segmenter::Segmenter(const MuxerOptions& options,
|
||||||
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
|
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
|
||||||
|
|
||||||
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
||||||
EncryptorSource* encryptor_source,
|
EncryptionKeySource* encryption_key_source,
|
||||||
EncryptorSource::TrackType track_type,
|
EncryptionKeySource::TrackType track_type,
|
||||||
double clear_lead_in_seconds) {
|
double clear_lead_in_seconds) {
|
||||||
DCHECK_LT(0u, streams.size());
|
DCHECK_LT(0u, streams.size());
|
||||||
moof_->header.sequence_number = 0;
|
moof_->header.sequence_number = 0;
|
||||||
|
@ -130,16 +130,16 @@ Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
|
||||||
sidx_->reference_id = i + 1;
|
sidx_->reference_id = i + 1;
|
||||||
}
|
}
|
||||||
scoped_ptr<AesCtrEncryptor> encryptor;
|
scoped_ptr<AesCtrEncryptor> encryptor;
|
||||||
if (encryptor_source) {
|
if (encryption_key_source) {
|
||||||
SampleDescription& description =
|
SampleDescription& description =
|
||||||
moov_->tracks[i].media.information.sample_table.description;
|
moov_->tracks[i].media.information.sample_table.description;
|
||||||
|
|
||||||
DCHECK(track_type == EncryptorSource::TRACK_TYPE_SD ||
|
DCHECK(track_type == EncryptionKeySource::TRACK_TYPE_SD ||
|
||||||
track_type == EncryptorSource::TRACK_TYPE_HD);
|
track_type == EncryptionKeySource::TRACK_TYPE_HD);
|
||||||
|
|
||||||
EncryptionKey encryption_key;
|
EncryptionKey encryption_key;
|
||||||
Status status = encryptor_source->GetKey(
|
Status status = encryption_key_source->GetKey(
|
||||||
description.type == kAudio ? EncryptorSource::TRACK_TYPE_AUDIO
|
description.type == kAudio ? EncryptionKeySource::TRACK_TYPE_AUDIO
|
||||||
: track_type,
|
: track_type,
|
||||||
&encryption_key);
|
&encryption_key);
|
||||||
if (!status.ok())
|
if (!status.ok())
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "base/memory/ref_counted.h"
|
#include "base/memory/ref_counted.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/status.h"
|
#include "media/base/status.h"
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
@ -20,7 +20,7 @@ namespace media {
|
||||||
struct MuxerOptions;
|
struct MuxerOptions;
|
||||||
|
|
||||||
class BufferWriter;
|
class BufferWriter;
|
||||||
class EncryptorSource;
|
class EncryptionKeySource;
|
||||||
class MediaSample;
|
class MediaSample;
|
||||||
class MediaStream;
|
class MediaStream;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class Segmenter {
|
||||||
/// Initialize the segmenter.
|
/// Initialize the segmenter.
|
||||||
/// Calling other public methods of this class without this method returning
|
/// Calling other public methods of this class without this method returning
|
||||||
/// Status::OK results in an undefined behavior.
|
/// Status::OK results in an undefined behavior.
|
||||||
/// @param encryptor_source points to the key source which contains
|
/// @param encryption_key_source points to the key source which contains
|
||||||
/// the encryption keys. It can be NULL to indicate that no encryption
|
/// the encryption keys. It can be NULL to indicate that no encryption
|
||||||
/// is required.
|
/// is required.
|
||||||
/// @param track_type indicates whether SD key or HD key should be used to
|
/// @param track_type indicates whether SD key or HD key should be used to
|
||||||
|
@ -57,8 +57,8 @@ class Segmenter {
|
||||||
/// @param clear_time specifies clear lead duration in seconds.
|
/// @param clear_time specifies clear lead duration in seconds.
|
||||||
/// @return OK on success, an error status otherwise.
|
/// @return OK on success, an error status otherwise.
|
||||||
Status Initialize(const std::vector<MediaStream*>& streams,
|
Status Initialize(const std::vector<MediaStream*>& streams,
|
||||||
EncryptorSource* encryptor_source,
|
EncryptionKeySource* encryption_key_source,
|
||||||
EncryptorSource::TrackType track_type,
|
EncryptionKeySource::TrackType track_type,
|
||||||
double clear_lead_in_seconds);
|
double clear_lead_in_seconds);
|
||||||
|
|
||||||
/// Finalize the segmenter.
|
/// Finalize the segmenter.
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/time/clock.h"
|
#include "base/time/clock.h"
|
||||||
#include "media/base/demuxer.h"
|
#include "media/base/demuxer.h"
|
||||||
#include "media/base/encryptor_source.h"
|
#include "media/base/encryption_key_source.h"
|
||||||
#include "media/base/media_stream.h"
|
#include "media/base/media_stream.h"
|
||||||
#include "media/base/muxer.h"
|
#include "media/base/muxer.h"
|
||||||
#include "media/base/status_test_util.h"
|
#include "media/base/status_test_util.h"
|
||||||
|
@ -148,9 +148,10 @@ void PackagerTestBasic::Remux(const std::string& input,
|
||||||
Demuxer demuxer(GetFullPath(input), decryptor_source_);
|
Demuxer demuxer(GetFullPath(input), decryptor_source_);
|
||||||
ASSERT_OK(demuxer.Initialize());
|
ASSERT_OK(demuxer.Initialize());
|
||||||
|
|
||||||
scoped_ptr<EncryptorSource> encryptor_source(
|
scoped_ptr<EncryptionKeySource> encryption_key_source(
|
||||||
EncryptorSource::CreateFromHexStrings(kKeyIdHex, kKeyHex, kPsshHex, ""));
|
EncryptionKeySource::CreateFromHexStrings(
|
||||||
DCHECK(encryptor_source);
|
kKeyIdHex, kKeyHex, kPsshHex, ""));
|
||||||
|
DCHECK(encryption_key_source);
|
||||||
|
|
||||||
scoped_ptr<Muxer> muxer_video;
|
scoped_ptr<Muxer> muxer_video;
|
||||||
if (!video_output.empty()) {
|
if (!video_output.empty()) {
|
||||||
|
@ -161,9 +162,9 @@ void PackagerTestBasic::Remux(const std::string& input,
|
||||||
muxer_video->AddStream(FindFirstVideoStream(demuxer.streams()));
|
muxer_video->AddStream(FindFirstVideoStream(demuxer.streams()));
|
||||||
|
|
||||||
if (enable_encryption) {
|
if (enable_encryption) {
|
||||||
muxer_video->SetEncryptorSource(encryptor_source.get(),
|
muxer_video->SetEncryptionKeySource(encryption_key_source.get(),
|
||||||
EncryptorSource::TRACK_TYPE_SD,
|
EncryptionKeySource::TRACK_TYPE_SD,
|
||||||
kClearLeadInSeconds);
|
kClearLeadInSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,9 +177,9 @@ void PackagerTestBasic::Remux(const std::string& input,
|
||||||
muxer_audio->AddStream(FindFirstAudioStream(demuxer.streams()));
|
muxer_audio->AddStream(FindFirstAudioStream(demuxer.streams()));
|
||||||
|
|
||||||
if (enable_encryption) {
|
if (enable_encryption) {
|
||||||
muxer_audio->SetEncryptorSource(encryptor_source.get(),
|
muxer_audio->SetEncryptionKeySource(encryption_key_source.get(),
|
||||||
EncryptorSource::TRACK_TYPE_SD,
|
EncryptionKeySource::TRACK_TYPE_SD,
|
||||||
kClearLeadInSeconds);
|
kClearLeadInSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue