Skip to content

Commit

Permalink
media: Add External Clear Key content browser test on Android
Browse files Browse the repository at this point in the history
This CL adds External Clear Key support on Android for testing.
This is implemented by running AesDecryptor in the MojoCdmService,
which runs in the MojoMediaApplication in the GPU process. This is
only enabled when kExternalClearKeyForTesting feature is enabled.

A new content browser test is added to use External Clear Key on
Android. Since AesDecryptor doesn't support decoding, the media
pipeline is configured to do decrypt-only using the mojo CDM
(MojoDecryptor on MojoCdm), and then use the normal Android
pipeline (AVDA/MojoAudioDecoder) to decode encrypted audio/video.

Note that this is different from the default mode how Android
media pipeline works for encrypted content (decryption/decoding
both happens in the GPU process). When browser_tests are enabled
on Android, we should be able to have test coverage on that.

Here's what the new test covers:
- MojoCdm / MojoCdmService
- MojoDecryptor / MojoDecryptorService
- MojoMediaApplication
- Connection to services hosted in MojoMediaApplication through
  MojoShellContext.

This CL also fixes a bug in MojoCdm where the decryptor_ptr is bound to
one thread but is used on another thread.

BUG=581893
TEST=This CL adds a new test. No other functionality change.

Review-Url: https://codereview.chromium.org/2268283003
Cr-Commit-Position: refs/heads/master@{#420500}
  • Loading branch information
xhwang-chromium authored and Commit bot committed Sep 22, 2016
1 parent 70e44d1 commit bcd6858
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 99 deletions.
96 changes: 12 additions & 84 deletions chrome/renderer/media/chrome_key_systems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/common/render_messages.h"
#include "components/cdm/renderer/external_clear_key_key_system_properties.h"
#include "components/cdm/renderer/widevine_key_system_properties.h"
#include "content/public/renderer/render_thread.h"
#include "media/base/eme_constants.h"
Expand Down Expand Up @@ -42,9 +43,6 @@ using media::KeySystemProperties;
using media::SupportedCodecs;

#if defined(ENABLE_PEPPER_CDMS)
static const char kExternalClearKeyPepperType[] =
"application/x-ppapi-clearkey-cdm";

static bool IsPepperCdmAvailable(
const std::string& pepper_type,
std::vector<base::string16>* additional_param_names,
Expand All @@ -60,76 +58,6 @@ static bool IsPepperCdmAvailable(
return is_available;
}

// KeySystemProperties implementation for external Clear Key systems.
class ExternalClearKeyProperties : public KeySystemProperties {
public:
explicit ExternalClearKeyProperties(const std::string& key_system_name)
: key_system_name_(key_system_name) {}

std::string GetKeySystemName() const override { return key_system_name_; }
bool IsSupportedInitDataType(
media::EmeInitDataType init_data_type) const override {
switch (init_data_type) {
case media::EmeInitDataType::WEBM:
case media::EmeInitDataType::KEYIDS:
return true;

case media::EmeInitDataType::CENC:
#if defined(USE_PROPRIETARY_CODECS)
return true;
#else
return false;
#endif // defined(USE_PROPRIETARY_CODECS)

case media::EmeInitDataType::UNKNOWN:
return false;
}
NOTREACHED();
return false;
}

SupportedCodecs GetSupportedCodecs() const override {
#if defined(USE_PROPRIETARY_CODECS)
return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL;
#else
return media::EME_CODEC_WEBM_ALL;
#endif
}

media::EmeConfigRule GetRobustnessConfigRule(
media::EmeMediaType media_type,
const std::string& requested_robustness) const override {
return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED
: media::EmeConfigRule::NOT_SUPPORTED;
}

// Persistent license sessions are faked.
media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport()
const override {
return media::EmeSessionTypeSupport::SUPPORTED;
}

media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport()
const override {
return media::EmeSessionTypeSupport::NOT_SUPPORTED;
}

media::EmeFeatureSupport GetPersistentStateSupport() const override {
return media::EmeFeatureSupport::REQUESTABLE;
}

media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override {
return media::EmeFeatureSupport::NOT_SUPPORTED;
}

std::string GetPepperType() const override {
return kExternalClearKeyPepperType;
}

private:
const std::string key_system_name_;
};

// External Clear Key (used for testing).
static void AddExternalClearKey(
std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) {
Expand All @@ -150,40 +78,40 @@ static void AddExternalClearKey(

std::vector<base::string16> additional_param_names;
std::vector<base::string16> additional_param_values;
if (!IsPepperCdmAvailable(kExternalClearKeyPepperType,
if (!IsPepperCdmAvailable(cdm::kExternalClearKeyPepperType,
&additional_param_names,
&additional_param_values)) {
return;
}

concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyKeySystem));
new cdm::ExternalClearKeyProperties(kExternalClearKeyKeySystem));

// Add support of decrypt-only mode in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyDecryptOnlyKeySystem));
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyDecryptOnlyKeySystem));

// A key system that triggers renewal message in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyRenewalKeySystem));
new cdm::ExternalClearKeyProperties(kExternalClearKeyRenewalKeySystem));

// A key system that triggers the FileIO test in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyFileIOTestKeySystem));
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyFileIOTestKeySystem));

// A key system that triggers the output protection test in ClearKeyCdm.
concrete_key_systems->emplace_back(new ExternalClearKeyProperties(
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyOutputProtectionTestKeySystem));

// A key system that Chrome thinks is supported by ClearKeyCdm, but actually
// will be refused by ClearKeyCdm. This is to test the CDM initialization
// failure case.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyInitializeFailKeySystem));
concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties(
kExternalClearKeyInitializeFailKeySystem));

// A key system that triggers a crash in ClearKeyCdm.
concrete_key_systems->emplace_back(
new ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem));
new cdm::ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem));
}

#if defined(WIDEVINE_CDM_AVAILABLE)
Expand Down
2 changes: 2 additions & 0 deletions components/cdm/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

static_library("renderer") {
sources = [
"external_clear_key_key_system_properties.cc",
"external_clear_key_key_system_properties.h",
"widevine_key_system_properties.cc",
"widevine_key_system_properties.h",
]
Expand Down
6 changes: 3 additions & 3 deletions components/cdm/renderer/android_key_systems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ class AndroidPlatformKeySystemProperties : public KeySystemProperties {
const SupportedCodecs supported_codecs_;
};

} // namespace

static SupportedKeySystemResponse QueryKeySystemSupport(
SupportedKeySystemResponse QueryKeySystemSupport(
const std::string& key_system) {
SupportedKeySystemRequest request;
SupportedKeySystemResponse response;
Expand All @@ -109,6 +107,8 @@ static SupportedKeySystemResponse QueryKeySystemSupport(
return response;
}

} // namespace

void AddAndroidWidevine(
std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) {
SupportedKeySystemResponse response = QueryKeySystemSupport(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2016 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 "components/cdm/renderer/external_clear_key_key_system_properties.h"

#include "base/logging.h"
#include "media/base/eme_constants.h"

namespace cdm {

#if defined(ENABLE_PEPPER_CDMS)
const char kExternalClearKeyPepperType[] = "application/x-ppapi-clearkey-cdm";
#endif

ExternalClearKeyProperties::ExternalClearKeyProperties(
const std::string& key_system_name)
: key_system_name_(key_system_name) {}

ExternalClearKeyProperties::~ExternalClearKeyProperties() {}

std::string ExternalClearKeyProperties::GetKeySystemName() const {
return key_system_name_;
}

bool ExternalClearKeyProperties::IsSupportedInitDataType(
media::EmeInitDataType init_data_type) const {
switch (init_data_type) {
case media::EmeInitDataType::WEBM:
case media::EmeInitDataType::KEYIDS:
return true;

case media::EmeInitDataType::CENC:
#if defined(USE_PROPRIETARY_CODECS)
return true;
#else
return false;
#endif // defined(USE_PROPRIETARY_CODECS)

case media::EmeInitDataType::UNKNOWN:
return false;
}
NOTREACHED();
return false;
}

media::SupportedCodecs ExternalClearKeyProperties::GetSupportedCodecs() const {
#if defined(USE_PROPRIETARY_CODECS)
return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL;
#else
return media::EME_CODEC_WEBM_ALL;
#endif
}

media::EmeConfigRule ExternalClearKeyProperties::GetRobustnessConfigRule(
media::EmeMediaType media_type,
const std::string& requested_robustness) const {
return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED
: media::EmeConfigRule::NOT_SUPPORTED;
}

// Persistent license sessions are faked.
media::EmeSessionTypeSupport
ExternalClearKeyProperties::GetPersistentLicenseSessionSupport() const {
return media::EmeSessionTypeSupport::SUPPORTED;
}

media::EmeSessionTypeSupport
ExternalClearKeyProperties::GetPersistentReleaseMessageSessionSupport() const {
return media::EmeSessionTypeSupport::NOT_SUPPORTED;
}

media::EmeFeatureSupport ExternalClearKeyProperties::GetPersistentStateSupport()
const {
return media::EmeFeatureSupport::REQUESTABLE;
}

media::EmeFeatureSupport
ExternalClearKeyProperties::GetDistinctiveIdentifierSupport() const {
return media::EmeFeatureSupport::NOT_SUPPORTED;
}

#if defined(ENABLE_PEPPER_CDMS)
std::string ExternalClearKeyProperties::GetPepperType() const {
return kExternalClearKeyPepperType;
}
#endif

} // namespace cdm
48 changes: 48 additions & 0 deletions components/cdm/renderer/external_clear_key_key_system_properties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2016 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 COMPONENTS_CDM_RENDERER_EXTERNAL_CLEAR_KEY_KEY_SYSTEM_PROPERTIES_H_
#define COMPONENTS_CDM_RENDERER_EXTERNAL_CLEAR_KEY_KEY_SYSTEM_PROPERTIES_H_

#include <string>

#include "build/build_config.h"
#include "media/base/key_system_properties.h"

namespace cdm {

#if defined(ENABLE_PEPPER_CDMS)
extern const char kExternalClearKeyPepperType[];
#endif

// KeySystemProperties implementation for external Clear Key key systems.
class ExternalClearKeyProperties : public media::KeySystemProperties {
public:
explicit ExternalClearKeyProperties(const std::string& key_system_name);
~ExternalClearKeyProperties() override;

std::string GetKeySystemName() const override;
bool IsSupportedInitDataType(
media::EmeInitDataType init_data_type) const override;
media::SupportedCodecs GetSupportedCodecs() const override;
media::EmeConfigRule GetRobustnessConfigRule(
media::EmeMediaType media_type,
const std::string& requested_robustness) const override;
media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport()
const override;
media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport()
const override;
media::EmeFeatureSupport GetPersistentStateSupport() const override;
media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override;
#if defined(ENABLE_PEPPER_CDMS)
std::string GetPepperType() const override;
#endif

private:
const std::string key_system_name_;
};

} // namespace cdm

#endif // COMPONENTS_CDM_RENDERER_EXTERNAL_CLEAR_KEY_KEY_SYSTEM_PROPERTIES_H_
26 changes: 25 additions & 1 deletion content/browser/media/encrypted_media_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/browser/shell.h"

#if defined(OS_ANDROID)
#include "base/android/build_info.h"
#include "media/base/media.h"
#include "media/base/media_switches.h"
#endif

#if defined(ENABLE_MOJO_RENDERER)
Expand All @@ -24,6 +26,10 @@
// Available key systems.
const char kClearKeyKeySystem[] = "org.w3.clearkey";

#if defined(OS_ANDROID)
const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
#endif

// Supported media types.
const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
#if !defined(DISABLE_ENCRYPTED_MEDIA_PLAYBACK_TESTS)
Expand Down Expand Up @@ -60,7 +66,9 @@ static bool IsMSESupported() {

// Tests encrypted media playback with a combination of parameters:
// - char*: Key system name.
// - bool: True to load media using MSE, otherwise use src.
// - SrcType: The type of video src used to load media, MSE or SRC.
// It is okay to run this test as a non-parameterized test, in this case,
// GetParam() should not be called.
class EncryptedMediaTest : public content::MediaBrowserTest,
public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
public:
Expand Down Expand Up @@ -142,6 +150,10 @@ class EncryptedMediaTest : public content::MediaBrowserTest,
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(
switches::kDisableGestureRequirementForMediaPlayback);
#if defined(OS_ANDROID)
command_line->AppendSwitchASCII(switches::kEnableFeatures,
media::kExternalClearKeyForTesting.name);
#endif
}
};

Expand Down Expand Up @@ -215,4 +227,16 @@ IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
kEmeNotSupportedError);
}

#if defined(OS_ANDROID)
// On Android, External Clear Key is supported in //content/shell/ by using mojo
// CDM with AesDecryptor running in the GPU process.
// On other platforms, External Clear Key is supported in chrome/, so it is
// tested in browser_tests.
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, ExternalClearKeyPlayback) {
RunSimpleEncryptedMediaTest("bear-320x240-av_enc-av.webm",
kWebMVorbisAudioVP8Video,
kExternalClearKeyKeySystem, MSE);
}
#endif

} // namespace content
1 change: 1 addition & 0 deletions content/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static_library("content_shell_lib") {
"//base:base_static",
"//base/third_party/dynamic_annotations",
"//cc",
"//components/cdm/renderer",
"//components/crash/content/app:app_breakpad_mac_win_to_be_deleted",
"//components/plugins/renderer",
"//components/test_runner:test_runner",
Expand Down
1 change: 1 addition & 0 deletions content/shell/renderer/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+gin",
"+components/cdm",
"+components/web_cache/renderer",
"+components/plugins/renderer",
"+components/test_runner",
Expand Down
Loading

0 comments on commit bcd6858

Please sign in to comment.