2016-02-10 17:51:15 +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
|
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_PROTECTION_SYSTEM_SPECIFIC_INFO_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_PROTECTION_SYSTEM_SPECIFIC_INFO_H_
|
2016-02-10 17:51:15 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2018-05-03 00:54:10 +00:00
|
|
|
#include <memory>
|
2016-02-10 17:51:15 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "packager/base/logging.h"
|
2020-05-29 18:45:57 +00:00
|
|
|
#include "packager/media/public/crypto_params.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-02-10 17:51:15 +00:00
|
|
|
namespace media {
|
|
|
|
|
2018-05-03 00:54:10 +00:00
|
|
|
struct ProtectionSystemSpecificInfo {
|
|
|
|
std::vector<uint8_t> system_id;
|
|
|
|
std::vector<uint8_t> psshs;
|
2016-02-10 17:51:15 +00:00
|
|
|
|
|
|
|
/// Parses multiple PSSH boxes from @a data. These boxes should be
|
|
|
|
/// concatenated together. Any non-PSSH box is an error.
|
|
|
|
/// @return true on success; false on failure.
|
|
|
|
static bool ParseBoxes(
|
|
|
|
const uint8_t* data,
|
|
|
|
size_t data_size,
|
|
|
|
std::vector<ProtectionSystemSpecificInfo>* pssh_boxes);
|
2018-05-03 00:54:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PsshBoxBuilder {
|
|
|
|
public:
|
|
|
|
PsshBoxBuilder() = default;
|
|
|
|
~PsshBoxBuilder() = default;
|
2016-02-10 17:51:15 +00:00
|
|
|
|
|
|
|
/// Parses the given PSSH box into this object.
|
2018-05-03 00:54:10 +00:00
|
|
|
/// @return nullptr on failure.
|
|
|
|
static std::unique_ptr<PsshBoxBuilder> ParseFromBox(const uint8_t* data,
|
|
|
|
size_t data_size);
|
2016-02-10 17:51:15 +00:00
|
|
|
|
|
|
|
/// Creates a PSSH box for the current data.
|
|
|
|
std::vector<uint8_t> CreateBox() const;
|
|
|
|
|
2016-02-17 22:03:43 +00:00
|
|
|
uint8_t pssh_box_version() const { return version_; }
|
2016-02-10 17:51:15 +00:00
|
|
|
const std::vector<uint8_t>& system_id() const { return system_id_; }
|
|
|
|
const std::vector<std::vector<uint8_t>>& key_ids() const { return key_ids_; }
|
|
|
|
const std::vector<uint8_t>& pssh_data() const { return pssh_data_; }
|
|
|
|
|
2016-02-17 22:03:43 +00:00
|
|
|
void set_pssh_box_version(uint8_t version) {
|
2016-02-10 17:51:15 +00:00
|
|
|
DCHECK_LT(version, 2);
|
|
|
|
version_ = version;
|
|
|
|
}
|
2016-02-17 22:03:43 +00:00
|
|
|
void set_system_id(const uint8_t* system_id, size_t system_id_size) {
|
|
|
|
DCHECK_EQ(16u, system_id_size);
|
|
|
|
system_id_.assign(system_id, system_id + system_id_size);
|
2016-02-10 17:51:15 +00:00
|
|
|
}
|
|
|
|
void add_key_id(const std::vector<uint8_t>& key_id) {
|
|
|
|
key_ids_.push_back(key_id);
|
|
|
|
}
|
|
|
|
void clear_key_ids() { key_ids_.clear(); }
|
|
|
|
void set_pssh_data(const std::vector<uint8_t>& pssh_data) {
|
|
|
|
pssh_data_ = pssh_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-03 00:54:10 +00:00
|
|
|
PsshBoxBuilder(const PsshBoxBuilder&) = delete;
|
|
|
|
PsshBoxBuilder& operator=(const PsshBoxBuilder&) = delete;
|
|
|
|
|
|
|
|
uint8_t version_ = 0;
|
2016-02-10 17:51:15 +00:00
|
|
|
std::vector<uint8_t> system_id_;
|
|
|
|
std::vector<std::vector<uint8_t>> key_ids_;
|
|
|
|
std::vector<uint8_t> pssh_data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-02-10 17:51:15 +00:00
|
|
|
|
2017-09-12 19:22:39 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_PROTECTION_SYSTEM_SPECIFIC_INFO_H_
|