1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/cdm_factory_daemon/mojom/decrypt_config_mojom_traits.h"
#include "base/notreached.h"
namespace mojo {
using MojomDecryptStatus = chromeos::cdm::mojom::DecryptStatus;
using NativeDecryptStatus = media::Decryptor::Status;
using MojomEncryptionScheme = chromeos::cdm::mojom::EncryptionScheme;
using NativeEncryptionScheme = media::EncryptionScheme;
// static
MojomDecryptStatus EnumTraits<MojomDecryptStatus, NativeDecryptStatus>::ToMojom(
NativeDecryptStatus input) {
switch (input) {
case NativeDecryptStatus::kSuccess:
return MojomDecryptStatus::kSuccess;
case NativeDecryptStatus::kNoKey:
return MojomDecryptStatus::kNoKey;
case NativeDecryptStatus::kNeedMoreData:
return MojomDecryptStatus::kFailure;
case NativeDecryptStatus::kError:
return MojomDecryptStatus::kFailure;
}
NOTREACHED();
}
// static
bool EnumTraits<MojomDecryptStatus, NativeDecryptStatus>::FromMojom(
MojomDecryptStatus input,
NativeDecryptStatus* out) {
switch (input) {
case MojomDecryptStatus::kSuccess:
*out = NativeDecryptStatus::kSuccess;
return true;
case MojomDecryptStatus::kNoKey:
*out = NativeDecryptStatus::kNoKey;
return true;
case MojomDecryptStatus::kFailure:
*out = NativeDecryptStatus::kError;
return true;
}
NOTREACHED();
}
// static
MojomEncryptionScheme
EnumTraits<MojomEncryptionScheme, NativeEncryptionScheme>::ToMojom(
NativeEncryptionScheme input) {
switch (input) {
// We should never encounter the unencrypted value.
case NativeEncryptionScheme::kUnencrypted:
NOTREACHED();
case NativeEncryptionScheme::kCenc:
return MojomEncryptionScheme::kCenc;
case NativeEncryptionScheme::kCbcs:
return MojomEncryptionScheme::kCbcs;
}
NOTREACHED();
}
// static
bool EnumTraits<MojomEncryptionScheme, NativeEncryptionScheme>::FromMojom(
MojomEncryptionScheme input,
NativeEncryptionScheme* out) {
switch (input) {
case MojomEncryptionScheme::kCenc:
*out = NativeEncryptionScheme::kCenc;
return true;
case MojomEncryptionScheme::kCbcs:
*out = NativeEncryptionScheme::kCbcs;
return true;
}
NOTREACHED();
}
// static
bool StructTraits<chromeos::cdm::mojom::EncryptionPatternDataView,
media::EncryptionPattern>::
Read(chromeos::cdm::mojom::EncryptionPatternDataView input,
media::EncryptionPattern* output) {
*output = media::EncryptionPattern(input.crypt_byte_block(),
input.skip_byte_block());
return true;
}
// static
bool StructTraits<chromeos::cdm::mojom::SubsampleEntryDataView,
media::SubsampleEntry>::
Read(chromeos::cdm::mojom::SubsampleEntryDataView input,
media::SubsampleEntry* output) {
*output = media::SubsampleEntry(input.clear_bytes(), input.cipher_bytes());
return true;
}
// static
bool StructTraits<chromeos::cdm::mojom::DecryptConfigDataView,
std::unique_ptr<media::DecryptConfig>>::
Read(chromeos::cdm::mojom::DecryptConfigDataView input,
std::unique_ptr<media::DecryptConfig>* output) {
media::EncryptionScheme encryption_scheme;
if (!input.ReadEncryptionScheme(&encryption_scheme))
return false;
std::string key_id;
if (!input.ReadKeyId(&key_id))
return false;
std::string iv;
if (!input.ReadIv(&iv))
return false;
std::vector<media::SubsampleEntry> subsamples;
if (!input.ReadSubsamples(&subsamples))
return false;
std::optional<media::EncryptionPattern> encryption_pattern;
if (!input.ReadEncryptionPattern(&encryption_pattern))
return false;
*output = std::make_unique<media::DecryptConfig>(
encryption_scheme, key_id, iv, subsamples, encryption_pattern);
return true;
}
} // namespace mojo
|