2014-02-14 23:21:05 +00:00
|
|
|
// 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
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
#ifndef MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|
|
|
|
#define MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-11-12 20:34:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/base/status.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
struct EncryptionKey {
|
|
|
|
EncryptionKey();
|
|
|
|
~EncryptionKey();
|
|
|
|
|
|
|
|
std::vector<uint8> key_id;
|
|
|
|
std::vector<uint8> key;
|
|
|
|
std::vector<uint8> pssh;
|
|
|
|
std::vector<uint8> iv;
|
|
|
|
};
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
/// EncryptionKeySource is responsible for encryption key acquisition.
|
|
|
|
class EncryptionKeySource {
|
2013-10-11 21:44:55 +00:00
|
|
|
public:
|
2014-04-15 22:18:26 +00:00
|
|
|
enum TrackType {
|
|
|
|
TRACK_TYPE_UNKNOWN = 0,
|
|
|
|
TRACK_TYPE_SD = 1,
|
|
|
|
TRACK_TYPE_HD = 2,
|
|
|
|
TRACK_TYPE_AUDIO = 3,
|
|
|
|
NUM_VALID_TRACK_TYPES = 3
|
|
|
|
};
|
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
virtual ~EncryptionKeySource();
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Get encryption key of the specified track type.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
virtual Status GetKey(TrackType track_type, EncryptionKey* key);
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-04-18 18:49:49 +00:00
|
|
|
/// Get encryption key of the specified track type at the specified index.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
2014-04-24 16:59:07 +00:00
|
|
|
virtual Status GetCryptoPeriodKey(uint32 crypto_period_index,
|
2014-04-18 18:49:49 +00:00
|
|
|
TrackType track_type,
|
|
|
|
EncryptionKey* key);
|
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
/// Create EncryptionKeySource object from hex strings.
|
2014-04-15 22:18:26 +00:00
|
|
|
/// @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.
|
|
|
|
/// @param iv_hex is the IV in hex string. If not specified, a randomly
|
|
|
|
/// 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.
|
2014-04-16 01:09:32 +00:00
|
|
|
static scoped_ptr<EncryptionKeySource> CreateFromHexStrings(
|
2014-04-15 22:18:26 +00:00
|
|
|
const std::string& key_id_hex,
|
|
|
|
const std::string& key_hex,
|
|
|
|
const std::string& pssh_data_hex,
|
|
|
|
const std::string& iv_hex);
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Convert string representation of track type to enum representation.
|
|
|
|
static TrackType GetTrackTypeFromString(const std::string& track_type_string);
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Convert TrackType to string.
|
|
|
|
static std::string TrackTypeToString(TrackType track_type);
|
2013-11-12 20:34:58 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-16 01:09:32 +00:00
|
|
|
EncryptionKeySource();
|
2014-04-15 22:18:26 +00:00
|
|
|
|
|
|
|
/// @return the raw bytes of the pssh box with system ID and box header
|
|
|
|
/// included.
|
|
|
|
static std::vector<uint8> PsshBoxFromPsshData(
|
|
|
|
const std::vector<uint8>& pssh_data);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-16 01:09:32 +00:00
|
|
|
explicit EncryptionKeySource(scoped_ptr<EncryptionKey> encryption_key);
|
2014-04-15 22:18:26 +00:00
|
|
|
|
|
|
|
scoped_ptr<EncryptionKey> encryption_key_;
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(EncryptionKeySource);
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
2014-04-15 22:18:26 +00:00
|
|
|
|
|
|
|
} // namespace media
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
#endif // MEDIA_BASE_ENCRYPTION_KEY_SOURCE_H_
|