2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2016-02-17 22:03:43 +00:00
|
|
|
#include <string>
|
2013-11-12 20:34:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2023-10-14 16:36:01 +00:00
|
|
|
#include <packager/macros/classes.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/fourccs.h>
|
|
|
|
#include <packager/media/base/protection_system_specific_info.h>
|
|
|
|
#include <packager/media/base/pssh_generator.h>
|
2023-10-14 16:36:01 +00:00
|
|
|
#include <packager/status.h>
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
2017-04-04 19:43:41 +00:00
|
|
|
/// Encrypted media init data types. It is extended from:
|
|
|
|
/// https://www.w3.org/TR/eme-initdata-registry/#registry.
|
|
|
|
enum class EmeInitDataType {
|
|
|
|
UNKNOWN,
|
|
|
|
/// One or multiple PSSH boxes.
|
|
|
|
CENC,
|
|
|
|
/// WebM init data is basically KeyId.
|
|
|
|
WEBM,
|
|
|
|
/// JSON formatted key ids.
|
|
|
|
KEYIDS,
|
|
|
|
/// Widevine classic asset id.
|
|
|
|
WIDEVINE_CLASSIC,
|
|
|
|
MAX = WIDEVINE_CLASSIC
|
|
|
|
};
|
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
struct EncryptionKey {
|
2016-02-17 22:03:43 +00:00
|
|
|
std::vector<ProtectionSystemSpecificInfo> key_system_info;
|
2020-06-01 22:26:31 +00:00
|
|
|
/// The ID of this key.
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> key_id;
|
2020-06-01 22:26:31 +00:00
|
|
|
/// The IDs of the other keys to include in PSSH info.
|
|
|
|
std::vector<std::vector<uint8_t>> key_ids;
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> key;
|
|
|
|
std::vector<uint8_t> iv;
|
2014-04-15 22:18:26 +00:00
|
|
|
};
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
typedef std::map<std::string, std::unique_ptr<EncryptionKey>> EncryptionKeyMap;
|
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
/// KeySource is responsible for encryption key acquisition.
|
|
|
|
class KeySource {
|
2013-10-11 21:44:55 +00:00
|
|
|
public:
|
2020-06-01 22:26:31 +00:00
|
|
|
KeySource();
|
2017-09-12 19:22:39 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
virtual ~KeySource();
|
|
|
|
|
2017-04-04 19:43:41 +00:00
|
|
|
/// Fetch keys based on the specified encrypted media init data.
|
|
|
|
/// @param init_data_type specifies the encrypted media init data type.
|
|
|
|
/// @param init_data contains the init data.
|
2014-10-09 19:56:51 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2017-04-04 19:43:41 +00:00
|
|
|
virtual Status FetchKeys(EmeInitDataType init_data_type,
|
|
|
|
const std::vector<uint8_t>& init_data) = 0;
|
2014-10-09 19:56:51 +00:00
|
|
|
|
2017-06-13 21:54:12 +00:00
|
|
|
/// Get encryption key of the specified stream label.
|
|
|
|
/// @param stream_label is the label of stream for which retrieving the key.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
2014-04-15 22:18:26 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2017-06-13 21:54:12 +00:00
|
|
|
virtual Status GetKey(const std::string& stream_label,
|
|
|
|
EncryptionKey* key) = 0;
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
/// Get the encryption key specified by the CENC key ID.
|
|
|
|
/// @param key_id is the unique identifier for the key being retreived.
|
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
|
|
|
/// @return OK on success, or an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status GetKey(const std::vector<uint8_t>& key_id,
|
|
|
|
EncryptionKey* key) = 0;
|
2014-08-20 23:51:15 +00:00
|
|
|
|
2014-04-18 18:49:49 +00:00
|
|
|
/// Get encryption key of the specified track type at the specified index.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param crypto_period_index is the sequence number of the key rotation
|
|
|
|
/// period for which the key is being retrieved.
|
2019-01-24 18:39:54 +00:00
|
|
|
/// @param crypto_period_duration_in_seconds is the duration of the crypto
|
|
|
|
/// period in seconds.
|
2017-06-13 21:54:12 +00:00
|
|
|
/// @param stream_label is the label of stream for which retrieving the key.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
2014-04-18 18:49:49 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2014-09-30 21:52:21 +00:00
|
|
|
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
|
2021-08-04 18:56:44 +00:00
|
|
|
int32_t crypto_period_duration_in_seconds,
|
2017-06-13 21:54:12 +00:00
|
|
|
const std::string& stream_label,
|
2016-02-19 20:23:37 +00:00
|
|
|
EncryptionKey* key) = 0;
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
private:
|
2014-08-20 23:51:15 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(KeySource);
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
2014-04-15 22:18:26 +00:00
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_KEY_SOURCE_H_
|