Commit 88f68163 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Convert CdmKeyInformation to use a typemap.

BUG=611224
TEST=new media_unittest passes

Change-Id: I7feadd34ca77bcacd406b61783e43143bb593f7f
Reviewed-on: https://chromium-review.googlesource.com/c/1338323
Commit-Queue: John Rummell <jrummell@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615729}
parent 8549eb68
......@@ -57,9 +57,6 @@ IPC_ENUM_TRAITS_MAX_VALUE(media::AudioParameters::Format,
IPC_ENUM_TRAITS_MAX_VALUE(media::BufferingState,
media::BufferingState::BUFFERING_STATE_MAX)
IPC_ENUM_TRAITS_MAX_VALUE(media::CdmKeyInformation::KeyStatus,
media::CdmKeyInformation::KEY_STATUS_MAX)
IPC_ENUM_TRAITS_MAX_VALUE(media::CdmMessageType,
media::CdmMessageType::MESSAGE_TYPE_MAX)
......@@ -168,12 +165,6 @@ IPC_STRUCT_TRAITS_BEGIN(media::CdmConfig)
IPC_STRUCT_TRAITS_MEMBER(use_hw_secure_codecs)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::CdmKeyInformation)
IPC_STRUCT_TRAITS_MEMBER(key_id)
IPC_STRUCT_TRAITS_MEMBER(status)
IPC_STRUCT_TRAITS_MEMBER(system_code)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::MediaLogEvent)
IPC_STRUCT_TRAITS_MEMBER(id)
IPC_STRUCT_TRAITS_MEMBER(type)
......
......@@ -352,7 +352,7 @@ void MojoCdm::OnSessionClosed(const std::string& session_id) {
void MojoCdm::OnSessionKeysChange(
const std::string& session_id,
bool has_additional_usable_key,
std::vector<mojom::CdmKeyInformationPtr> keys_info) {
std::vector<std::unique_ptr<CdmKeyInformation>> keys_info) {
DVLOG(2) << __func__;
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -368,13 +368,8 @@ void MojoCdm::OnSessionKeysChange(
}
}
CdmKeysInfo key_data;
key_data.reserve(keys_info.size());
for (size_t i = 0; i < keys_info.size(); ++i) {
key_data.push_back(keys_info[i].To<std::unique_ptr<CdmKeyInformation>>());
}
session_keys_change_cb_.Run(session_id, has_additional_usable_key,
std::move(key_data));
std::move(keys_info));
}
void MojoCdm::OnSessionExpirationUpdate(const std::string& session_id,
......
......@@ -114,7 +114,7 @@ class MojoCdm : public ContentDecryptionModule,
void OnSessionKeysChange(
const std::string& session_id,
bool has_additional_usable_key,
std::vector<mojom::CdmKeyInformationPtr> keys_info) final;
std::vector<std::unique_ptr<CdmKeyInformation>> keys_info) final;
void OnSessionExpirationUpdate(const std::string& session_id,
double new_expiry_time_sec) final;
......
......@@ -11,7 +11,6 @@
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "media/base/audio_buffer.h"
#include "media/base/cdm_key_information.h"
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
#include "media/base/subsample_entry.h"
......@@ -118,27 +117,6 @@ TypeConverter<scoped_refptr<media::DecoderBuffer>,
return buffer;
}
// static
media::mojom::CdmKeyInformationPtr TypeConverter<
media::mojom::CdmKeyInformationPtr,
media::CdmKeyInformation>::Convert(const media::CdmKeyInformation& input) {
media::mojom::CdmKeyInformationPtr info(
media::mojom::CdmKeyInformation::New());
info->key_id = input.key_id;
info->status = input.status;
info->system_code = input.system_code;
return info;
}
// static
std::unique_ptr<media::CdmKeyInformation>
TypeConverter<std::unique_ptr<media::CdmKeyInformation>,
media::mojom::CdmKeyInformationPtr>::
Convert(const media::mojom::CdmKeyInformationPtr& input) {
return std::make_unique<media::CdmKeyInformation>(
input->key_id, input->status, input->system_code);
}
// static
media::mojom::AudioBufferPtr
TypeConverter<media::mojom::AudioBufferPtr, scoped_refptr<media::AudioBuffer>>::
......
......@@ -16,7 +16,6 @@ namespace media {
class AudioBuffer;
class DecoderBuffer;
class DecryptConfig;
struct CdmKeyInformation;
}
// These are specializations of mojo::TypeConverter and have to be in the mojo
......@@ -47,19 +46,6 @@ struct TypeConverter<scoped_refptr<media::DecoderBuffer>,
const media::mojom::DecoderBufferPtr& input);
};
template <>
struct TypeConverter<media::mojom::CdmKeyInformationPtr,
media::CdmKeyInformation> {
static media::mojom::CdmKeyInformationPtr Convert(
const media::CdmKeyInformation& input);
};
template <>
struct TypeConverter<std::unique_ptr<media::CdmKeyInformation>,
media::mojom::CdmKeyInformationPtr> {
static std::unique_ptr<media::CdmKeyInformation> Convert(
const media::mojom::CdmKeyInformationPtr& input);
};
template <>
struct TypeConverter<media::mojom::AudioBufferPtr,
scoped_refptr<media::AudioBuffer>> {
......
......@@ -116,6 +116,7 @@ source_set("unit_tests") {
sources = [
"audio_decoder_config_struct_traits_unittest.cc",
"cdm_key_information_mojom_traits_unittest.cc",
"encryption_scheme_struct_traits_unittest.cc",
"video_decoder_config_struct_traits_unittest.cc",
"video_frame_struct_traits_unittest.cc",
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//media/mojo/interfaces/content_decryption_module.mojom"
public_headers = [ "//media/base/cdm_key_information.h" ]
traits_headers =
[ "//media/mojo/interfaces/cdm_key_information_mojom_traits.h" ]
sources = [
"//media/mojo/interfaces/cdm_key_information_mojom_traits.cc",
]
public_deps = [
"//media",
]
type_mappings = [
"media.mojom.CdmKeyInformation=std::unique_ptr<media::CdmKeyInformation>[move_only]",
"media.mojom.CdmKeyStatus=media::CdmKeyInformation::KeyStatus",
]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/mojo/interfaces/cdm_key_information_mojom_traits.h"
#include "base/logging.h"
namespace mojo {
using MojomKeyStatus = media::mojom::CdmKeyStatus;
using NativeKeyStatus = media::CdmKeyInformation::KeyStatus;
// static
MojomKeyStatus EnumTraits<MojomKeyStatus, NativeKeyStatus>::ToMojom(
NativeKeyStatus error) {
switch (error) {
case NativeKeyStatus::USABLE:
return MojomKeyStatus::USABLE;
case NativeKeyStatus::INTERNAL_ERROR:
return MojomKeyStatus::INTERNAL_ERROR;
case NativeKeyStatus::EXPIRED:
return MojomKeyStatus::EXPIRED;
case NativeKeyStatus::OUTPUT_RESTRICTED:
return MojomKeyStatus::OUTPUT_RESTRICTED;
case NativeKeyStatus::OUTPUT_DOWNSCALED:
return MojomKeyStatus::OUTPUT_DOWNSCALED;
case NativeKeyStatus::KEY_STATUS_PENDING:
return MojomKeyStatus::KEY_STATUS_PENDING;
case NativeKeyStatus::RELEASED:
return MojomKeyStatus::RELEASED;
}
NOTREACHED();
return MojomKeyStatus::INTERNAL_ERROR;
}
// static
bool EnumTraits<MojomKeyStatus, NativeKeyStatus>::FromMojom(
MojomKeyStatus error,
NativeKeyStatus* out) {
switch (error) {
case MojomKeyStatus::USABLE:
*out = NativeKeyStatus::USABLE;
return true;
case MojomKeyStatus::INTERNAL_ERROR:
*out = NativeKeyStatus::INTERNAL_ERROR;
return true;
case MojomKeyStatus::EXPIRED:
*out = NativeKeyStatus::EXPIRED;
return true;
case MojomKeyStatus::OUTPUT_RESTRICTED:
*out = NativeKeyStatus::OUTPUT_RESTRICTED;
return true;
case MojomKeyStatus::OUTPUT_DOWNSCALED:
*out = NativeKeyStatus::OUTPUT_DOWNSCALED;
return true;
case MojomKeyStatus::KEY_STATUS_PENDING:
*out = NativeKeyStatus::KEY_STATUS_PENDING;
return true;
case MojomKeyStatus::RELEASED:
*out = NativeKeyStatus::RELEASED;
return true;
}
NOTREACHED();
return false;
}
// static
bool StructTraits<media::mojom::CdmKeyInformationDataView,
std::unique_ptr<media::CdmKeyInformation>>::
Read(media::mojom::CdmKeyInformationDataView input,
std::unique_ptr<media::CdmKeyInformation>* output) {
mojo::ArrayDataView<uint8_t> key_id;
input.GetKeyIdDataView(&key_id);
NativeKeyStatus status;
if (!input.ReadStatus(&status))
return false;
*output = std::make_unique<media::CdmKeyInformation>(
key_id.data(), key_id.size(), status, input.system_code());
return true;
}
} // namespace mojo
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_MOJO_INTERFACES_CDM_KEY_INFORMATION_MOJOM_TRAITS_H_
#define MEDIA_MOJO_INTERFACES_CDM_KEY_INFORMATION_MOJOM_TRAITS_H_
#include "media/base/cdm_key_information.h"
#include "media/mojo/interfaces/content_decryption_module.mojom.h"
namespace mojo {
template <>
struct EnumTraits<media::mojom::CdmKeyStatus,
media::CdmKeyInformation::KeyStatus> {
static media::mojom::CdmKeyStatus ToMojom(
media::CdmKeyInformation::KeyStatus key_status);
static bool FromMojom(media::mojom::CdmKeyStatus input,
media::CdmKeyInformation::KeyStatus* out);
};
template <>
struct StructTraits<media::mojom::CdmKeyInformationDataView,
std::unique_ptr<media::CdmKeyInformation>> {
static const std::vector<uint8_t>& key_id(
const std::unique_ptr<media::CdmKeyInformation>& input) {
return input->key_id;
}
static media::CdmKeyInformation::KeyStatus status(
const std::unique_ptr<media::CdmKeyInformation>& input) {
return input->status;
}
static uint32_t system_code(
const std::unique_ptr<media::CdmKeyInformation>& input) {
return input->system_code;
}
static bool Read(media::mojom::CdmKeyInformationDataView input,
std::unique_ptr<media::CdmKeyInformation>* output);
};
} // namespace mojo
#endif // MEDIA_MOJO_INTERFACES_CDM_KEY_INFORMATION_MOJOM_TRAITS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/mojo/interfaces/cdm_key_information_mojom_traits.h"
#include "media/base/cdm_key_information.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
TEST(CdmKeyInformationStructTraitsTest, ConvertCdmKeyInformation) {
auto input = std::make_unique<CdmKeyInformation>(
"key_id", CdmKeyInformation::KeyStatus::USABLE, 23);
std::vector<uint8_t> data =
media::mojom::CdmKeyInformation::Serialize(&input);
std::unique_ptr<CdmKeyInformation> output;
EXPECT_TRUE(
media::mojom::CdmKeyInformation::Deserialize(std::move(data), &output));
EXPECT_EQ(input->key_id, output->key_id);
EXPECT_EQ(input->status, output->status);
EXPECT_EQ(input->system_code, output->system_code);
}
} // namespace media
......@@ -21,8 +21,15 @@ enum CdmSessionType;
enum CdmMessageType;
// See media::CdmKeyInformation::KeyStatus
[Native]
enum CdmKeyStatus;
enum CdmKeyStatus {
USABLE,
INTERNAL_ERROR,
EXPIRED,
OUTPUT_RESTRICTED,
OUTPUT_DOWNSCALED,
KEY_STATUS_PENDING,
RELEASED,
};
// See media::HdcpVersion
[Native]
......
......@@ -21,7 +21,6 @@ deps = [
type_mappings = [
"media.mojom.CdmConfig=media::CdmConfig",
"media.mojom.CdmKeyStatus=media::CdmKeyInformation::KeyStatus",
"media.mojom.CdmPromiseResult.Exception=media::CdmPromise::Exception",
"media.mojom.CdmSessionType=media::CdmSessionType",
"media.mojom.CdmMessageType=media::CdmMessageType",
......
......@@ -5,6 +5,7 @@
typemaps = [
"//media/mojo/interfaces/audio_decoder_config.typemap",
"//media/mojo/interfaces/audio_parameters.typemap",
"//media/mojo/interfaces/cdm_key_information.typemap",
"//media/mojo/interfaces/cdm_proxy.typemap",
"//media/mojo/interfaces/content_decryption_module.typemap",
"//media/mojo/interfaces/decryptor.typemap",
......
......@@ -209,11 +209,8 @@ void MojoCdmService::OnSessionKeysChange(const std::string& session_id,
DVLOG(2) << __func__
<< " has_additional_usable_key = " << has_additional_usable_key;
std::vector<mojom::CdmKeyInformationPtr> keys_data;
for (auto& key : keys_info)
keys_data.push_back(mojom::CdmKeyInformation::From(*(key.get())));
client_->OnSessionKeysChange(session_id, has_additional_usable_key,
std::move(keys_data));
std::move(keys_info));
}
void MojoCdmService::OnSessionExpirationUpdate(const std::string& session_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment