44 std::vector<ProtectionSystemSpecificInfo>* pssh_infos) {
45 std::map<std::vector<uint8_t>,
size_t> info_map;
51 RCHECK(reader.Read4(&size));
53 RCHECK(size > kPsshBoxHeaderSize + kSystemIdSize);
55 const std::vector<uint8_t> system_id(
56 data + kPsshBoxHeaderSize, data + kPsshBoxHeaderSize + kSystemIdSize);
57 auto iter = info_map.find(system_id);
58 if (iter != info_map.end()) {
60 info.psshs.insert(info.psshs.end(), data, data + size);
62 pssh_infos->push_back(
63 {system_id, std::vector<uint8_t>(data, data + size)});
64 info_map[system_id] = pssh_infos->size() - 1;
81 uint32_t version_and_flags;
82 RETURN_NULL_IF_FALSE(reader.Read4(&size));
83 RETURN_NULL_IF_FALSE(reader.Read4(&box_type));
84 RETURN_NULL_IF_FALSE(box_type == FOURCC_pssh);
85 RETURN_NULL_IF_FALSE(reader.Read4(&version_and_flags));
87 pssh_builder->version_ = (version_and_flags >> 24);
88 RETURN_NULL_IF_FALSE(pssh_builder->version_ < 2);
91 reader.ReadToVector(&pssh_builder->system_id_, kSystemIdSize));
93 if (pssh_builder->version_ == 1) {
94 uint32_t key_id_count;
95 RETURN_NULL_IF_FALSE(reader.Read4(&key_id_count));
97 pssh_builder->key_ids_.resize(key_id_count);
98 for (uint32_t i = 0; i < key_id_count; i++) {
100 reader.ReadToVector(&pssh_builder->key_ids_[i], kKeyIdSize));
105 uint32_t pssh_data_size;
106 RETURN_NULL_IF_FALSE(reader.Read4(&pssh_data_size));
107 RETURN_NULL_IF_FALSE(
108 reader.ReadToVector(&pssh_builder->pssh_data_, pssh_data_size));
115 DCHECK_EQ(kSystemIdSize, system_id_.size());
117 const uint32_t box_type = FOURCC_pssh;
118 const uint32_t version_and_flags = (
static_cast<uint32_t
>(version_) << 24);
119 const uint32_t pssh_data_size = pssh_data_.size();
121 const uint32_t key_id_count = key_ids_.size();
122 const uint32_t key_ids_size =
123 sizeof(key_id_count) + kKeyIdSize * key_id_count;
124 const uint32_t extra_size = version_ == 1 ? key_ids_size : 0;
126 const uint32_t total_size =
127 sizeof(total_size) +
sizeof(box_type) +
sizeof(version_and_flags) +
128 kSystemIdSize + extra_size +
sizeof(pssh_data_size) + pssh_data_size;
134 writer.AppendVector(system_id_);
137 for (
size_t i = 0; i < key_id_count; i++) {
138 DCHECK_EQ(kKeyIdSize, key_ids_[i].size());
139 writer.AppendVector(key_ids_[i]);
143 writer.AppendVector(pssh_data_);
145 DCHECK_EQ(total_size, writer.Size());
146 return std::vector<uint8_t>(writer.
Buffer(), writer.
Buffer() + writer.Size());