Files.app: make default-action as a command.
[chromium-blink-merge.git] / components / cdm / renderer / android_key_systems.cc
blobb9521d3ad9e7a3fbb16085c514b9c20c0fe471d5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/cdm/renderer/android_key_systems.h"
7 #include <string>
8 #include <vector>
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "components/cdm/common/cdm_messages_android.h"
13 #include "components/cdm/renderer/widevine_key_systems.h"
14 #include "content/public/renderer/render_thread.h"
15 #include "media/base/eme_constants.h"
16 #include "media/base/media_switches.h"
18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
20 using media::EmeFeatureSupport;
21 using media::EmeRobustness;
22 using media::EmeSessionTypeSupport;
23 using media::KeySystemInfo;
24 using media::SupportedCodecs;
26 namespace cdm {
28 static SupportedKeySystemResponse QueryKeySystemSupport(
29 const std::string& key_system) {
30 SupportedKeySystemRequest request;
31 SupportedKeySystemResponse response;
33 request.key_system = key_system;
34 request.codecs = media::EME_CODEC_ALL;
35 content::RenderThread::Get()->Send(
36 new ChromeViewHostMsg_QueryKeySystemSupport(request, &response));
37 DCHECK(!(response.compositing_codecs & ~media::EME_CODEC_ALL))
38 << "unrecognized codec";
39 DCHECK(!(response.non_compositing_codecs & ~media::EME_CODEC_ALL))
40 << "unrecognized codec";
41 return response;
44 void AddAndroidWidevine(std::vector<KeySystemInfo>* concrete_key_systems) {
45 SupportedKeySystemResponse response = QueryKeySystemSupport(
46 kWidevineKeySystem);
48 // Since we do not control the implementation of the MediaDrm API on Android,
49 // we assume that it can and will make use of persistence even though no
50 // persistence-based features are supported.
52 if (response.compositing_codecs != media::EME_CODEC_NONE) {
53 AddWidevineWithCodecs(
54 WIDEVINE,
55 response.compositing_codecs, // Regular codecs.
56 response.non_compositing_codecs, // Hardware-secure codecs.
57 EmeRobustness::HW_SECURE_CRYPTO, // Max audio robustness.
58 EmeRobustness::HW_SECURE_ALL, // Max video robustness.
59 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
60 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-release-message.
61 EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state.
62 EmeFeatureSupport::ALWAYS_ENABLED, // Distinctive identifier.
63 concrete_key_systems);
64 } else {
65 // It doesn't make sense to support secure codecs but not regular codecs.
66 DCHECK(response.non_compositing_codecs == media::EME_CODEC_NONE);
69 // For compatibility with the prefixed API, register a separate L1 key system.
70 // This key systems acts as though only hardware-secure codecs are available.
71 // We only register support for codecs with both regular and hardware-secure
72 // variants so that we can be sure they will work regardless of the renderer
73 // preference.
74 SupportedCodecs secure_codecs =
75 response.compositing_codecs & response.non_compositing_codecs;
76 if (secure_codecs != media::EME_CODEC_NONE) {
77 // Note: The prefixed API only consults the regular codecs field.
78 AddWidevineWithCodecs(
79 WIDEVINE_HR_NON_COMPOSITING,
80 secure_codecs, // Regular codecs.
81 media::EME_CODEC_NONE, // Hardware-secure codecs.
82 EmeRobustness::HW_SECURE_CRYPTO, // Max audio robustness.
83 EmeRobustness::HW_SECURE_ALL, // Max video robustness.
84 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license.
85 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-release-message.
86 EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state.
87 EmeFeatureSupport::ALWAYS_ENABLED, // Distinctive identifier.
88 concrete_key_systems);
92 void AddAndroidPlatformKeySystems(
93 std::vector<KeySystemInfo>* concrete_key_systems) {
94 std::vector<std::string> key_system_names;
95 content::RenderThread::Get()->Send(
96 new ChromeViewHostMsg_GetPlatformKeySystemNames(&key_system_names));
98 for (std::vector<std::string>::const_iterator it = key_system_names.begin();
99 it != key_system_names.end(); ++it) {
100 SupportedKeySystemResponse response = QueryKeySystemSupport(*it);
101 if (response.compositing_codecs != media::EME_CODEC_NONE) {
102 KeySystemInfo info;
103 info.key_system = *it;
104 info.supported_codecs = response.compositing_codecs;
105 // Here we assume that support for a container implies support for the
106 // associated initialization data type. KeySystems handles validating
107 // |init_data_type| x |container| pairings.
108 if (response.compositing_codecs & media::EME_CODEC_WEBM_ALL)
109 info.supported_init_data_types |= media::kInitDataTypeMaskWebM;
110 #if defined(USE_PROPRIETARY_CODECS)
111 if (response.compositing_codecs & media::EME_CODEC_MP4_ALL)
112 info.supported_init_data_types |= media::kInitDataTypeMaskCenc;
113 #endif // defined(USE_PROPRIETARY_CODECS)
114 info.max_audio_robustness = EmeRobustness::EMPTY;
115 info.max_video_robustness = EmeRobustness::EMPTY;
116 // Assume that platform key systems support no features but can and will
117 // make use of persistence and identifiers.
118 info.persistent_license_support =
119 media::EmeSessionTypeSupport::NOT_SUPPORTED;
120 info.persistent_release_message_support =
121 media::EmeSessionTypeSupport::NOT_SUPPORTED;
122 info.persistent_state_support = media::EmeFeatureSupport::ALWAYS_ENABLED;
123 info.distinctive_identifier_support =
124 media::EmeFeatureSupport::ALWAYS_ENABLED;
125 concrete_key_systems->push_back(info);
130 } // namespace cdm