2016-02-19 20:23:37 +00:00
|
|
|
// Copyright 2016 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_KEY_SOURCE_H_
|
|
|
|
#define MEDIA_BASE_FIXED_KEY_SOURCE_H_
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2016-02-19 20:23:37 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "packager/media/base/key_source.h"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-02-19 20:23:37 +00:00
|
|
|
namespace media {
|
|
|
|
|
2016-03-21 18:09:24 +00:00
|
|
|
// Common SystemID defined by EME, which requires Key System implementations
|
|
|
|
// supporting ISO Common Encryption to support this SystemID and format.
|
2016-07-26 20:57:28 +00:00
|
|
|
// https://goo.gl/kUv2Xd
|
2016-03-21 18:09:24 +00:00
|
|
|
const uint8_t kCommonSystemId[] = {0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2,
|
|
|
|
0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e,
|
|
|
|
0x52, 0xe2, 0xfb, 0x4b};
|
|
|
|
|
2016-02-19 20:23:37 +00:00
|
|
|
/// A key source that uses fixed keys for encryption.
|
|
|
|
class FixedKeySource : public KeySource {
|
|
|
|
public:
|
|
|
|
~FixedKeySource() override;
|
|
|
|
|
|
|
|
/// @name KeySource implementation overrides.
|
|
|
|
/// @{
|
2017-04-04 19:43:41 +00:00
|
|
|
Status FetchKeys(EmeInitDataType init_data_type,
|
|
|
|
const std::vector<uint8_t>& init_data) override;
|
2017-06-13 21:54:12 +00:00
|
|
|
Status GetKey(const std::string& stream_label, EncryptionKey* key) override;
|
2016-02-19 20:23:37 +00:00
|
|
|
Status GetKey(const std::vector<uint8_t>& key_id,
|
|
|
|
EncryptionKey* key) override;
|
|
|
|
Status GetCryptoPeriodKey(uint32_t crypto_period_index,
|
2017-06-13 21:54:12 +00:00
|
|
|
const std::string& stream_label,
|
2016-02-19 20:23:37 +00:00
|
|
|
EncryptionKey* key) override;
|
|
|
|
/// @}
|
|
|
|
|
2017-06-14 23:18:16 +00:00
|
|
|
/// Creates a new FixedKeySource from the given data. Returns null
|
2016-02-19 20:23:37 +00:00
|
|
|
/// if the strings are invalid.
|
2017-06-14 23:18:16 +00:00
|
|
|
/// @param key_id is the key identifier. Must be 16 bytes.
|
|
|
|
/// @param key is the encryption / decryption key. Must be 16 bytes.
|
|
|
|
/// @param pssh_boxes is the concatenated pssh boxes.
|
|
|
|
/// @param iv is the initialization vector. If not specified, a randomly
|
2016-02-19 20:23:37 +00:00
|
|
|
/// generated IV with the default length will be used.
|
2017-06-14 23:18:16 +00:00
|
|
|
/// Note: GetKey on the created key source will always return the same key for
|
|
|
|
/// all track types.
|
|
|
|
static std::unique_ptr<FixedKeySource> Create(
|
|
|
|
const std::vector<uint8_t>& key_id,
|
|
|
|
const std::vector<uint8_t>& key,
|
|
|
|
const std::vector<uint8_t>& pssh_boxes,
|
|
|
|
const std::vector<uint8_t>& iv);
|
2016-02-19 20:23:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Allow default constructor for mock key sources.
|
|
|
|
FixedKeySource();
|
|
|
|
|
|
|
|
private:
|
2016-08-17 17:41:40 +00:00
|
|
|
explicit FixedKeySource(std::unique_ptr<EncryptionKey> key);
|
2016-02-19 20:23:37 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<EncryptionKey> encryption_key_;
|
2016-02-19 20:23:37 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FixedKeySource);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-02-19 20:23:37 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_FIXED_KEY_SOURCE_H_
|