Rename EncryptorSource to EncryptionKeySource

Change-Id: I0a3d0e205922bbb4015955e04d51b7a9a4fa86e1
This commit is contained in:
Kongqun Yang 2014-04-15 18:09:32 -07:00
parent f059d926d7
commit 9076411044
15 changed files with 183 additions and 257 deletions

View File

@ -19,7 +19,7 @@
#include "media/base/muxer_options.h"
#include "media/base/request_signer.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/file/file.h"
#include "media/file/file_closer.h"
@ -41,8 +41,8 @@ void DumpStreamInfo(const std::vector<MediaStream*>& streams) {
}
// Create and initialize encryptor source.
scoped_ptr<EncryptorSource> CreateEncryptorSource() {
scoped_ptr<EncryptorSource> encryptor_source;
scoped_ptr<EncryptionKeySource> CreateEncryptionKeySource() {
scoped_ptr<EncryptionKeySource> encryption_key_source;
if (FLAGS_enable_widevine_encryption) {
scoped_ptr<RequestSigner> signer;
DCHECK(!FLAGS_aes_signing_key.empty() ||
@ -55,7 +55,7 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
LOG(ERROR) << "Cannot create an AES signer object from '"
<< FLAGS_aes_signing_key << "':'" << FLAGS_aes_signing_iv
<< "'.";
return scoped_ptr<EncryptorSource>();
return scoped_ptr<EncryptionKeySource>();
}
} else if (!FLAGS_rsa_signing_key_path.empty()) {
std::string rsa_private_key;
@ -63,7 +63,7 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
&rsa_private_key)) {
LOG(ERROR) << "Failed to read from '" << FLAGS_rsa_signing_key_path
<< "'.";
return scoped_ptr<EncryptorSource>();
return scoped_ptr<EncryptionKeySource>();
}
signer.reset(
@ -71,17 +71,17 @@ scoped_ptr<EncryptorSource> CreateEncryptorSource() {
if (!signer) {
LOG(ERROR) << "Cannot create a RSA signer object from '"
<< 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()));
} else if (FLAGS_enable_fixed_key_encryption) {
encryptor_source = EncryptorSource::CreateFromHexStrings(
encryption_key_source = EncryptionKeySource::CreateFromHexStrings(
FLAGS_key_id, FLAGS_key, FLAGS_pssh, "");
}
return encryptor_source.Pass();
return encryption_key_source.Pass();
}
bool GetMuxerOptions(MuxerOptions* muxer_options) {
@ -206,21 +206,21 @@ bool RunPackager(const std::string& input) {
if (!AddStreamToMuxer(demuxer.streams(), muxer.get()))
return false;
scoped_ptr<EncryptorSource> encryptor_source;
scoped_ptr<EncryptionKeySource> encryption_key_source;
if (FLAGS_enable_widevine_encryption || FLAGS_enable_fixed_key_encryption) {
encryptor_source = CreateEncryptorSource();
if (!encryptor_source)
encryption_key_source = CreateEncryptionKeySource();
if (!encryption_key_source)
return false;
}
EncryptorSource::TrackType track_type =
EncryptorSource::GetTrackTypeFromString(FLAGS_track_type);
if (track_type != EncryptorSource::TRACK_TYPE_SD &&
track_type != EncryptorSource::TRACK_TYPE_HD) {
EncryptionKeySource::TrackType track_type =
EncryptionKeySource::GetTrackTypeFromString(FLAGS_track_type);
if (track_type != EncryptionKeySource::TRACK_TYPE_SD &&
track_type != EncryptionKeySource::TRACK_TYPE_HD) {
LOG(ERROR) << "FLAGS_track_type should be either 'SD' or 'HD'";
return false;
}
muxer->SetEncryptorSource(
encryptor_source.get(), track_type, FLAGS_clear_lead);
muxer->SetEncryptionKeySource(
encryption_key_source.get(), track_type, FLAGS_clear_lead);
// Start remuxing process.
status = demuxer.Run();

View File

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file or at
// 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 "media/base/aes_encryptor.h"
@ -21,16 +21,16 @@ namespace media {
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(encryption_key_);
*key = *encryption_key_;
return Status::OK;
}
scoped_ptr<EncryptorSource> EncryptorSource::CreateFromHexStrings(
scoped_ptr<EncryptionKeySource> EncryptionKeySource::CreateFromHexStrings(
const std::string& key_id_hex,
const std::string& key_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)) {
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)) {
LOG(ERROR) << "Cannot parse key_hex " << key_hex;
return scoped_ptr<EncryptorSource>();
return scoped_ptr<EncryptionKeySource>();
}
std::vector<uint8> pssh_data;
if (!base::HexStringToBytes(pssh_data_hex, &pssh_data)) {
LOG(ERROR) << "Cannot parse pssh_hex " << pssh_data_hex;
return scoped_ptr<EncryptorSource>();
return scoped_ptr<EncryptionKeySource>();
}
if (!iv_hex.empty()) {
if (!base::HexStringToBytes(iv_hex, &encryption_key->iv)) {
LOG(ERROR) << "Cannot parse iv_hex " << iv_hex;
return scoped_ptr<EncryptorSource>();
return scoped_ptr<EncryptionKeySource>();
}
}
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);
return scoped_ptr<EncryptorSource>(
new EncryptorSource(encryption_key.Pass()));
return scoped_ptr<EncryptionKeySource>(
new EncryptionKeySource(encryption_key.Pass()));
}
EncryptorSource::TrackType EncryptorSource::GetTrackTypeFromString(
EncryptionKeySource::TrackType EncryptionKeySource::GetTrackTypeFromString(
const std::string& track_type_string) {
if (track_type_string == "SD")
return TRACK_TYPE_SD;
@ -77,7 +77,7 @@ EncryptorSource::TrackType EncryptorSource::GetTrackTypeFromString(
return TRACK_TYPE_UNKNOWN;
}
std::string EncryptorSource::TrackTypeToString(TrackType track_type) {
std::string EncryptionKeySource::TrackTypeToString(TrackType track_type) {
switch (track_type) {
case TRACK_TYPE_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 uint8 kPsshFourCC[] = {'p', 's', 's', 'h'};
const uint32 kVersionAndFlags = 0;
@ -111,8 +111,9 @@ std::vector<uint8> EncryptorSource::PsshBoxFromPsshData(
return std::vector<uint8>(writer.Buffer(), writer.Buffer() + writer.Size());
}
EncryptorSource::EncryptorSource() {}
EncryptorSource::EncryptorSource(scoped_ptr<EncryptionKey> encryption_key)
EncryptionKeySource::EncryptionKeySource() {}
EncryptionKeySource::EncryptionKeySource(
scoped_ptr<EncryptionKey> encryption_key)
: encryption_key_(encryption_key.Pass()) {
DCHECK(encryption_key_);
}

View File

@ -4,8 +4,8 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef MEDIA_BASE_ENCRYPTOR_SOURCE_H_
#define MEDIA_BASE_ENCRYPTOR_SOURCE_H_
#ifndef MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
#define MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
#include <vector>
@ -24,8 +24,8 @@ struct EncryptionKey {
std::vector<uint8> iv;
};
/// EncryptorSource is responsible for encryption key acquisition.
class EncryptorSource {
/// EncryptionKeySource is responsible for encryption key acquisition.
class EncryptionKeySource {
public:
enum TrackType {
TRACK_TYPE_UNKNOWN = 0,
@ -35,13 +35,13 @@ class EncryptorSource {
NUM_VALID_TRACK_TYPES = 3
};
virtual ~EncryptorSource();
virtual ~EncryptionKeySource();
/// Get encryption key of the specified track type.
/// @return OK on success, an error status otherwise.
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_hex is the key 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.
/// Note: GetKey on the created key source will always return the same key
/// for all track types.
static scoped_ptr<EncryptorSource> CreateFromHexStrings(
static scoped_ptr<EncryptionKeySource> CreateFromHexStrings(
const std::string& key_id_hex,
const std::string& key_hex,
const std::string& pssh_data_hex,
@ -62,7 +62,7 @@ class EncryptorSource {
static std::string TrackTypeToString(TrackType track_type);
protected:
EncryptorSource();
EncryptionKeySource();
/// @return the raw bytes of the pssh box with system ID and box header
/// included.
@ -70,13 +70,13 @@ class EncryptorSource {
const std::vector<uint8>& pssh_data);
private:
explicit EncryptorSource(scoped_ptr<EncryptionKey> encryption_key);
explicit EncryptionKeySource(scoped_ptr<EncryptionKey> encryption_key);
scoped_ptr<EncryptionKey> encryption_key_;
DISALLOW_COPY_AND_ASSIGN(EncryptorSource);
DISALLOW_COPY_AND_ASSIGN(EncryptionKeySource);
};
} // namespace media
#endif // MEDIA_BASE_ENCRYPTOR_SOURCE_H_
#endif // MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_

View File

@ -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

View File

@ -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_

View File

@ -74,8 +74,8 @@
'decrypt_config.cc',
'decrypt_config.h',
'decryptor_source.h',
'encryptor_source.cc',
'encryptor_source.h',
'encryption_key_source.cc',
'encryption_key_source.h',
'limits.h',
'media_parser.h',
'media_sample.cc',
@ -99,8 +99,8 @@
'timestamp.h',
'video_stream_info.cc',
'video_stream_info.h',
'widevine_encryptor_source.cc',
'widevine_encryptor_source.h',
'widevine_encryption_key_source.cc',
'widevine_encryption_key_source.h',
],
'dependencies': [
'../../base/base.gyp:base',
@ -129,7 +129,7 @@
'status_test_util.h',
'status_test_util_unittest.cc',
'status_unittest.cc',
'widevine_encryptor_source_unittest.cc',
'widevine_encryption_key_source_unittest.cc',
],
'dependencies': [
'../../testing/gtest.gyp:gtest',

View File

@ -6,7 +6,7 @@
#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_stream.h"
@ -14,19 +14,19 @@ namespace media {
Muxer::Muxer(const MuxerOptions& options)
: options_(options),
encryptor_source_(NULL),
encryption_key_source_(NULL),
initialized_(false),
track_type_(EncryptorSource::TRACK_TYPE_SD),
track_type_(EncryptionKeySource::TRACK_TYPE_SD),
clear_lead_in_seconds_(0),
muxer_listener_(NULL),
clock_(NULL) {}
Muxer::~Muxer() {}
void Muxer::SetEncryptorSource(EncryptorSource* encryptor_source,
EncryptorSource::TrackType track_type,
double clear_lead_in_seconds) {
encryptor_source_ = encryptor_source;
void Muxer::SetEncryptionKeySource(EncryptionKeySource* encryption_key_source,
EncryptionKeySource::TrackType track_type,
double clear_lead_in_seconds) {
encryption_key_source_ = encryption_key_source;
track_type_ = track_type;
clear_lead_in_seconds_ = clear_lead_in_seconds;
}

View File

@ -13,7 +13,7 @@
#include "base/memory/ref_counted.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/status.h"
@ -23,7 +23,7 @@ class Clock;
namespace media {
class EncryptorSource;
class EncryptionKeySource;
class MediaSample;
class MediaStream;
@ -32,22 +32,22 @@ class MuxerListener;
}
/// Muxer is responsible for taking elementary stream samples and producing
/// media containers. An optional EncryptorSource can be provided to Muxer to
/// generate encrypted outputs.
/// media containers. An optional EncryptionKeySource can be provided to Muxer
/// to generate encrypted outputs.
class Muxer {
public:
explicit Muxer(const MuxerOptions& options);
virtual ~Muxer();
/// Set encryptor source.
/// @param encryptor_source points to the encryptor source to be injected.
/// Should not be NULL.
/// Set encryption key source.
/// @param encryption_key_source points to the encryption key source to be
/// injected. Should not be NULL.
/// @param track_type should be either SD or HD. It affects whether SD key or
/// HD key is used to encrypt the video content.
/// @param clear_lead_in_seconds specifies clear lead duration in seconds.
void SetEncryptorSource(EncryptorSource* encryptor_source,
EncryptorSource::TrackType track_type,
double clear_lead_in_seconds);
void SetEncryptionKeySource(EncryptionKeySource* encryption_key_source,
EncryptionKeySource::TrackType track_type,
double clear_lead_in_seconds);
/// Add video/audio stream.
void AddStream(MediaStream* stream);
@ -73,8 +73,10 @@ class Muxer {
protected:
const MuxerOptions& options() const { return options_; }
EncryptorSource* encryptor_source() { return encryptor_source_; }
EncryptorSource::TrackType track_type() const { return track_type_; }
EncryptionKeySource* encryption_key_source() {
return encryption_key_source_;
}
EncryptionKeySource::TrackType track_type() const { return track_type_; }
double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
event::MuxerListener* muxer_listener() { return muxer_listener_; }
base::Clock* clock() { return clock_; }
@ -98,9 +100,9 @@ class Muxer {
MuxerOptions options_;
std::vector<MediaStream*> streams_;
EncryptorSource* encryptor_source_;
EncryptionKeySource* encryption_key_source_;
bool initialized_;
EncryptorSource::TrackType track_type_;
EncryptionKeySource::TrackType track_type_;
double clear_lead_in_seconds_;
event::MuxerListener* muxer_listener_;

View File

@ -4,14 +4,12 @@
// license that can be found in the LICENSE file or at
// 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/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/stl_util.h"
#include "base/time/time.h"
#include "base/threading/platform_thread.h"
#include "base/values.h"
#include "media/base/http_fetcher.h"
#include "media/base/request_signer.h"
@ -95,7 +93,7 @@ bool GetPsshData(const base::DictionaryValue& track_dict,
namespace media {
WidevineEncryptorSource::WidevineEncryptorSource(
WidevineEncryptionKeySource::WidevineEncryptionKeySource(
const std::string& server_url,
const std::string& content_id,
scoped_ptr<RequestSigner> signer)
@ -106,12 +104,12 @@ WidevineEncryptorSource::WidevineEncryptorSource(
key_fetched_(false) {
DCHECK(signer_);
}
WidevineEncryptorSource::~WidevineEncryptorSource() {
WidevineEncryptionKeySource::~WidevineEncryptionKeySource() {
STLDeleteValues(&encryption_key_map_);
}
Status WidevineEncryptorSource::GetKey(TrackType track_type,
EncryptionKey* key) {
Status WidevineEncryptionKeySource::GetKey(TrackType track_type,
EncryptionKey* key) {
DCHECK(track_type == TRACK_TYPE_SD || track_type == TRACK_TYPE_HD ||
track_type == TRACK_TYPE_AUDIO);
Status status;
@ -133,12 +131,12 @@ Status WidevineEncryptorSource::GetKey(TrackType track_type,
return Status::OK;
}
void WidevineEncryptorSource::set_http_fetcher(
void WidevineEncryptionKeySource::set_http_fetcher(
scoped_ptr<HttpFetcher> http_fetcher) {
http_fetcher_ = http_fetcher.Pass();
}
Status WidevineEncryptorSource::FetchKeys() {
Status WidevineEncryptionKeySource::FetchKeys() {
std::string request;
FillRequest(content_id_, &request);
@ -186,8 +184,8 @@ Status WidevineEncryptorSource::FetchKeys() {
"Failed to recover from server internal error.");
}
void WidevineEncryptorSource::FillRequest(const std::string& content_id,
std::string* request) {
void WidevineEncryptionKeySource::FillRequest(const std::string& content_id,
std::string* request) {
DCHECK(request);
std::string content_id_base64_string;
@ -220,8 +218,8 @@ void WidevineEncryptorSource::FillRequest(const std::string& content_id,
base::JSONWriter::Write(&request_dict, request);
}
Status WidevineEncryptorSource::SignRequest(const std::string& request,
std::string* signed_request) {
Status WidevineEncryptionKeySource::SignRequest(const std::string& request,
std::string* signed_request) {
DCHECK(signed_request);
// Sign the request.
@ -245,8 +243,9 @@ Status WidevineEncryptorSource::SignRequest(const std::string& request,
return Status::OK;
}
bool WidevineEncryptorSource::DecodeResponse(const std::string& raw_response,
std::string* response) {
bool WidevineEncryptionKeySource::DecodeResponse(
const std::string& raw_response,
std::string* response) {
DCHECK(response);
// Extract base64 formatted response from JSON formatted raw response.
@ -264,8 +263,9 @@ bool WidevineEncryptorSource::DecodeResponse(const std::string& raw_response,
return true;
}
bool WidevineEncryptorSource::ExtractEncryptionKey(const std::string& response,
bool* transient_error) {
bool WidevineEncryptionKeySource::ExtractEncryptionKey(
const std::string& response,
bool* transient_error) {
DCHECK(transient_error);
*transient_error = false;
@ -302,8 +302,8 @@ bool WidevineEncryptorSource::ExtractEncryptionKey(const std::string& response,
scoped_ptr<EncryptionKey> encryption_key(new EncryptionKey());
std::vector<uint8> pssh_data;
if (!GetKeyAndKeyId(*track_dict, &encryption_key->key,
&encryption_key->key_id) ||
if (!GetKeyAndKeyId(
*track_dict, &encryption_key->key, &encryption_key->key_id) ||
!GetPsshData(*track_dict, &pssh_data))
return false;
encryption_key->pssh = PsshBoxFromPsshData(pssh_data);

View File

@ -4,33 +4,34 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
#define MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
#ifndef MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_
#define MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_
#include <map>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "media/base/encryptor_source.h"
#include "media/base/encryption_key_source.h"
namespace media {
class HttpFetcher;
class RequestSigner;
/// Encryptor source which talks to the Widevine encryption service.
class WidevineEncryptorSource : public EncryptorSource {
/// WidevineEncryptionKeySource talks to the Widevine encryption service to
/// acquire the encryption keys.
class WidevineEncryptionKeySource : public EncryptionKeySource {
public:
/// @param server_url is the Widevine common encryption server url.
/// @param content_id the unique id identify the content to be encrypted.
/// @param signer must not be NULL.
WidevineEncryptorSource(const std::string& server_url,
const std::string& content_id,
scoped_ptr<RequestSigner> signer);
virtual ~WidevineEncryptorSource();
WidevineEncryptionKeySource(const std::string& server_url,
const std::string& content_id,
scoped_ptr<RequestSigner> signer);
virtual ~WidevineEncryptionKeySource();
/// EncryptorSource implementation override.
/// EncryptionKeySource implementation override.
virtual Status GetKey(TrackType track_type, EncryptionKey* key) OVERRIDE;
/// 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
// failure is because of a transient error from the server. |transient_error|
// should not be NULL.
bool ExtractEncryptionKey(const std::string& response,
bool* transient_error);
bool ExtractEncryptionKey(const std::string& response, bool* transient_error);
// The fetcher object used to fetch HTTP response from server.
// It is initialized to a default fetcher on class initialization.
@ -69,9 +69,9 @@ class WidevineEncryptorSource : public EncryptorSource {
bool key_fetched_; // Protected by lock_;
std::map<TrackType, EncryptionKey*> encryption_key_map_;
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptorSource);
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptionKeySource);
};
} // namespace media
#endif // MEDIA_BASE_WIDEVINE_ENCRYPTOR_SOURCE_H_
#endif // MEDIA_BASE_WIDEVINE_ENCRYPTION_KEY_SOURCE_H_

View File

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file or at
// 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/strings/stringprintf.h"
@ -23,9 +23,10 @@ const char kMockSignature[] = "MockSignature";
// The license service may return an error indicating a transient error has
// just happened in the server, or other types of errors.
// WidevineEncryptorSource will perform a number of retries on transient errors;
// WidevineEncryptorSource does not know about other errors and retries are not
// performed.
// WidevineEncryptionKeySource will perform a number of retries on transient
// errors;
// WidevineEncryptionKeySource does not know about other errors and retries are
// not performed.
const char kLicenseStatusTransientError[] = "INTERNAL_ERROR";
const char kLicenseStatusUnknownError[] = "UNKNOWN_ERROR";
@ -37,8 +38,7 @@ const char kExpectedSignedMessageFormat[] =
const char kTrackFormat[] =
"{\"type\":\"%s\",\"key_id\":\"%s\",\"key\":"
"\"%s\",\"pssh\":[{\"drm_type\":\"WIDEVINE\",\"data\":\"%s\"}]}";
const char kLicenseResponseFormat[] =
"{\"status\":\"%s\",\"tracks\":[%s]}";
const char kLicenseResponseFormat[] = "{\"status\":\"%s\",\"tracks\":[%s]}";
const char kHttpResponseFormat[] = "{\"response\":\"%s\"}";
std::string Base64Encode(const std::string& input) {
@ -122,55 +122,53 @@ class MockHttpFetcher : public HttpFetcher {
DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher);
};
class WidevineEncryptorSourceTest : public ::testing::Test {
class WidevineEncryptionKeySourceTest : public ::testing::Test {
public:
WidevineEncryptorSourceTest()
WidevineEncryptionKeySourceTest()
: mock_request_signer_(new MockRequestSigner(kSignerName)),
mock_http_fetcher_(new MockHttpFetcher()) {}
protected:
void CreateWidevineEncryptorSource() {
widevine_encryptor_source_.reset(new WidevineEncryptorSource(
kServerUrl,
kContentId,
mock_request_signer_.PassAs<RequestSigner>()));
widevine_encryptor_source_->set_http_fetcher(
void CreateWidevineEncryptionKeySource() {
widevine_encryption_key_source_.reset(new WidevineEncryptionKeySource(
kServerUrl, kContentId, mock_request_signer_.PassAs<RequestSigner>()));
widevine_encryption_key_source_->set_http_fetcher(
mock_http_fetcher_.PassAs<HttpFetcher>());
}
scoped_ptr<MockRequestSigner> mock_request_signer_;
scoped_ptr<MockHttpFetcher> mock_http_fetcher_;
scoped_ptr<WidevineEncryptorSource> widevine_encryptor_source_;
scoped_ptr<WidevineEncryptionKeySource> widevine_encryption_key_source_;
private:
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptorSourceTest);
DISALLOW_COPY_AND_ASSIGN(WidevineEncryptionKeySourceTest);
};
TEST_F(WidevineEncryptorSourceTest, GetTrackTypeFromString) {
EXPECT_EQ(EncryptorSource::TRACK_TYPE_SD,
EncryptorSource::GetTrackTypeFromString("SD"));
EXPECT_EQ(EncryptorSource::TRACK_TYPE_HD,
EncryptorSource::GetTrackTypeFromString("HD"));
EXPECT_EQ(EncryptorSource::TRACK_TYPE_AUDIO,
EncryptorSource::GetTrackTypeFromString("AUDIO"));
EXPECT_EQ(EncryptorSource::TRACK_TYPE_UNKNOWN,
EncryptorSource::GetTrackTypeFromString("FOO"));
TEST_F(WidevineEncryptionKeySourceTest, GetTrackTypeFromString) {
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_SD,
EncryptionKeySource::GetTrackTypeFromString("SD"));
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_HD,
EncryptionKeySource::GetTrackTypeFromString("HD"));
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_AUDIO,
EncryptionKeySource::GetTrackTypeFromString("AUDIO"));
EXPECT_EQ(EncryptionKeySource::TRACK_TYPE_UNKNOWN,
EncryptionKeySource::GetTrackTypeFromString("FOO"));
}
TEST_F(WidevineEncryptorSourceTest, GeneratureSignatureFailure) {
TEST_F(WidevineEncryptionKeySourceTest, GeneratureSignatureFailure) {
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
.WillOnce(Return(false));
CreateWidevineEncryptorSource();
CreateWidevineEncryptionKeySource();
EncryptionKey encryption_key;
ASSERT_EQ(Status(error::INTERNAL_ERROR, "Signature generation failed."),
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
&encryption_key));
widevine_encryption_key_source_->GetKey(
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
}
// Check whether expected request message and post data was generated and
// verify the correct behavior on http failure.
TEST_F(WidevineEncryptorSourceTest, HttpPostFailure) {
TEST_F(WidevineEncryptionKeySourceTest, HttpPostFailure) {
std::string expected_message = base::StringPrintf(
kExpectedRequestMessageFormat, Base64Encode(kContentId).c_str());
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, _))
.WillOnce(Return(kMockStatus));
CreateWidevineEncryptorSource();
CreateWidevineEncryptionKeySource();
EncryptionKey encryption_key;
ASSERT_EQ(kMockStatus,
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
&encryption_key));
widevine_encryption_key_source_->GetKey(
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
}
TEST_F(WidevineEncryptorSourceTest, LicenseStatusOK) {
TEST_F(WidevineEncryptionKeySourceTest, LicenseStatusOK) {
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
.WillOnce(Return(true));
@ -202,13 +200,13 @@ TEST_F(WidevineEncryptorSourceTest, LicenseStatusOK) {
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
.WillOnce(DoAll(SetArgPointee<2>(expected_response), Return(Status::OK)));
CreateWidevineEncryptorSource();
CreateWidevineEncryptionKeySource();
EncryptionKey encryption_key;
const std::string kTrackTypes[] = {"SD", "HD", "AUDIO"};
for (size_t i = 0; i < 3; ++i) {
ASSERT_OK(widevine_encryptor_source_->GetKey(
EncryptorSource::GetTrackTypeFromString(kTrackTypes[i]),
ASSERT_OK(widevine_encryption_key_source_->GetKey(
EncryptionKeySource::GetTrackTypeFromString(kTrackTypes[i]),
&encryption_key));
EXPECT_EQ(GetMockKeyId(kTrackTypes[i]), ToString(encryption_key.key_id));
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(_, _))
.WillOnce(Return(true));
@ -235,17 +233,17 @@ TEST_F(WidevineEncryptorSourceTest, RetryOnTransientError) {
.WillOnce(DoAll(SetArgPointee<2>(expected_retried_response),
Return(Status::OK)));
CreateWidevineEncryptorSource();
CreateWidevineEncryptionKeySource();
EncryptionKey encryption_key;
ASSERT_OK(widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
&encryption_key));
ASSERT_OK(widevine_encryption_key_source_->GetKey(
EncryptionKeySource::TRACK_TYPE_SD, &encryption_key));
EXPECT_EQ(GetMockKeyId("SD"), ToString(encryption_key.key_id));
EXPECT_EQ(GetMockKey("SD"), ToString(encryption_key.key));
EXPECT_EQ(GetMockPsshData("SD"),
GetPsshDataFromPsshBox(ToString(encryption_key.pssh)));
}
TEST_F(WidevineEncryptorSourceTest, NoRetryOnUnknownError) {
TEST_F(WidevineEncryptionKeySourceTest, NoRetryOnUnknownError) {
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
.WillOnce(Return(true));
@ -257,11 +255,13 @@ TEST_F(WidevineEncryptorSourceTest, NoRetryOnUnknownError) {
EXPECT_CALL(*mock_http_fetcher_, Post(_, _, _))
.WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK)));
CreateWidevineEncryptorSource();
CreateWidevineEncryptionKeySource();
EncryptionKey encryption_key;
ASSERT_EQ(error::SERVER_ERROR,
widevine_encryptor_source_->GetKey(EncryptorSource::TRACK_TYPE_SD,
&encryption_key).error_code());
ASSERT_EQ(
error::SERVER_ERROR,
widevine_encryption_key_source_->GetKey(
EncryptionKeySource::TRACK_TYPE_SD,
&encryption_key).error_code());
}
} // namespace media

View File

@ -10,7 +10,7 @@
#include "base/time/time.h"
#include "media/base/aes_encryptor.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_stream.h"
#include "media/base/video_stream_info.h"
@ -98,8 +98,11 @@ Status MP4Muxer::Initialize() {
new MultiSegmentSegmenter(options(), ftyp.Pass(), moov.Pass()));
}
Status segmenter_initialized = segmenter_->Initialize(
streams(), encryptor_source(), track_type(), clear_lead_in_seconds());
Status segmenter_initialized =
segmenter_->Initialize(streams(),
encryption_key_source(),
track_type(),
clear_lead_in_seconds());
if (!segmenter_initialized.ok())
return segmenter_initialized;
@ -274,7 +277,7 @@ void MP4Muxer::FireOnMediaEndEvent() {
index_range_end,
duration_seconds,
file_size,
encryptor_source());
encryption_key_source());
}
uint64 MP4Muxer::IsoTimeNow() {

View File

@ -11,7 +11,7 @@
#include "base/stl_util.h"
#include "media/base/aes_encryptor.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_stream.h"
#include "media/base/muxer_options.h"
@ -108,8 +108,8 @@ Segmenter::Segmenter(const MuxerOptions& options,
Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); }
Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
EncryptorSource* encryptor_source,
EncryptorSource::TrackType track_type,
EncryptionKeySource* encryption_key_source,
EncryptionKeySource::TrackType track_type,
double clear_lead_in_seconds) {
DCHECK_LT(0u, streams.size());
moof_->header.sequence_number = 0;
@ -130,16 +130,16 @@ Status Segmenter::Initialize(const std::vector<MediaStream*>& streams,
sidx_->reference_id = i + 1;
}
scoped_ptr<AesCtrEncryptor> encryptor;
if (encryptor_source) {
if (encryption_key_source) {
SampleDescription& description =
moov_->tracks[i].media.information.sample_table.description;
DCHECK(track_type == EncryptorSource::TRACK_TYPE_SD ||
track_type == EncryptorSource::TRACK_TYPE_HD);
DCHECK(track_type == EncryptionKeySource::TRACK_TYPE_SD ||
track_type == EncryptionKeySource::TRACK_TYPE_HD);
EncryptionKey encryption_key;
Status status = encryptor_source->GetKey(
description.type == kAudio ? EncryptorSource::TRACK_TYPE_AUDIO
Status status = encryption_key_source->GetKey(
description.type == kAudio ? EncryptionKeySource::TRACK_TYPE_AUDIO
: track_type,
&encryption_key);
if (!status.ok())

View File

@ -12,7 +12,7 @@
#include "base/memory/ref_counted.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"
namespace media {
@ -20,7 +20,7 @@ namespace media {
struct MuxerOptions;
class BufferWriter;
class EncryptorSource;
class EncryptionKeySource;
class MediaSample;
class MediaStream;
@ -49,7 +49,7 @@ class Segmenter {
/// Initialize the segmenter.
/// Calling other public methods of this class without this method returning
/// 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
/// is required.
/// @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.
/// @return OK on success, an error status otherwise.
Status Initialize(const std::vector<MediaStream*>& streams,
EncryptorSource* encryptor_source,
EncryptorSource::TrackType track_type,
EncryptionKeySource* encryption_key_source,
EncryptionKeySource::TrackType track_type,
double clear_lead_in_seconds);
/// Finalize the segmenter.

View File

@ -9,7 +9,7 @@
#include "base/strings/stringprintf.h"
#include "base/time/clock.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/muxer.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_);
ASSERT_OK(demuxer.Initialize());
scoped_ptr<EncryptorSource> encryptor_source(
EncryptorSource::CreateFromHexStrings(kKeyIdHex, kKeyHex, kPsshHex, ""));
DCHECK(encryptor_source);
scoped_ptr<EncryptionKeySource> encryption_key_source(
EncryptionKeySource::CreateFromHexStrings(
kKeyIdHex, kKeyHex, kPsshHex, ""));
DCHECK(encryption_key_source);
scoped_ptr<Muxer> muxer_video;
if (!video_output.empty()) {
@ -161,9 +162,9 @@ void PackagerTestBasic::Remux(const std::string& input,
muxer_video->AddStream(FindFirstVideoStream(demuxer.streams()));
if (enable_encryption) {
muxer_video->SetEncryptorSource(encryptor_source.get(),
EncryptorSource::TRACK_TYPE_SD,
kClearLeadInSeconds);
muxer_video->SetEncryptionKeySource(encryption_key_source.get(),
EncryptionKeySource::TRACK_TYPE_SD,
kClearLeadInSeconds);
}
}
@ -176,9 +177,9 @@ void PackagerTestBasic::Remux(const std::string& input,
muxer_audio->AddStream(FindFirstAudioStream(demuxer.streams()));
if (enable_encryption) {
muxer_audio->SetEncryptorSource(encryptor_source.get(),
EncryptorSource::TRACK_TYPE_SD,
kClearLeadInSeconds);
muxer_audio->SetEncryptionKeySource(encryption_key_source.get(),
EncryptionKeySource::TRACK_TYPE_SD,
kClearLeadInSeconds);
}
}