OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/cdm/renderer/android_key_systems.h" | 5 #include "components/cdm/renderer/android_key_systems.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "components/cdm/common/cdm_messages_android.h" | 12 #include "components/cdm/common/cdm_messages_android.h" |
13 #include "components/cdm/renderer/widevine_key_systems.h" | 13 #include "components/cdm/renderer/widevine_key_system_properties.h" |
14 #include "content/public/renderer/render_thread.h" | 14 #include "content/public/renderer/render_thread.h" |
15 #include "media/base/eme_constants.h" | 15 #include "media/base/eme_constants.h" |
16 #include "media/base/media_switches.h" | 16 #include "media/base/media_switches.h" |
17 | 17 |
18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
19 | 19 |
| 20 using media::EmeConfigRule; |
20 using media::EmeFeatureSupport; | 21 using media::EmeFeatureSupport; |
| 22 using media::EmeInitDataType; |
21 using media::EmeRobustness; | 23 using media::EmeRobustness; |
22 using media::EmeSessionTypeSupport; | 24 using media::EmeSessionTypeSupport; |
23 using media::KeySystemInfo; | 25 using media::KeySystemProperties; |
24 using media::SupportedCodecs; | 26 using media::SupportedCodecs; |
25 | 27 |
26 namespace cdm { | 28 namespace cdm { |
27 | 29 |
| 30 namespace { |
| 31 |
| 32 // Implementation of KeySystemProperties for platform-supported key systems. |
| 33 // Assumes that platform key systems support no features but can and will |
| 34 // make use of persistence and identifiers. |
| 35 class AndroidPlatformKeySystemProperties : public KeySystemProperties { |
| 36 public: |
| 37 AndroidPlatformKeySystemProperties(const std::string& name, |
| 38 SupportedCodecs supported_codecs) |
| 39 : name_(name), supported_codecs_(supported_codecs) {} |
| 40 |
| 41 std::string GetKeySystemName() const override { return name_; } |
| 42 |
| 43 bool IsSupportedInitDataType(EmeInitDataType init_data_type) const override { |
| 44 // Here we assume that support for a container implies support for the |
| 45 // associated initialization data type. KeySystems handles validating |
| 46 // |init_data_type| x |container| pairings. |
| 47 switch (init_data_type) { |
| 48 case EmeInitDataType::WEBM: |
| 49 return (supported_codecs_ & media::EME_CODEC_WEBM_ALL) != 0; |
| 50 case EmeInitDataType::CENC: |
| 51 #if defined(USE_PROPRIETARY_CODECS) |
| 52 return (supported_codecs_ & media::EME_CODEC_MP4_ALL) != 0; |
| 53 #else |
| 54 return false; |
| 55 #endif // defined(USE_PROPRIETARY_CODECS) |
| 56 case EmeInitDataType::KEYIDS: |
| 57 case EmeInitDataType::UNKNOWN: |
| 58 return false; |
| 59 } |
| 60 NOTREACHED(); |
| 61 return false; |
| 62 } |
| 63 |
| 64 SupportedCodecs GetSupportedCodecs() const override { |
| 65 return supported_codecs_; |
| 66 } |
| 67 |
| 68 EmeConfigRule GetRobustnessConfigRule( |
| 69 media::EmeMediaType media_type, |
| 70 const std::string& requested_robustness) const override { |
| 71 return requested_robustness.empty() ? EmeConfigRule::SUPPORTED |
| 72 : EmeConfigRule::NOT_SUPPORTED; |
| 73 } |
| 74 |
| 75 EmeSessionTypeSupport GetPersistentLicenseSessionSupport() const override { |
| 76 return EmeSessionTypeSupport::NOT_SUPPORTED; |
| 77 } |
| 78 EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport() |
| 79 const override { |
| 80 return EmeSessionTypeSupport::NOT_SUPPORTED; |
| 81 } |
| 82 EmeFeatureSupport GetPersistentStateSupport() const override { |
| 83 return EmeFeatureSupport::ALWAYS_ENABLED; |
| 84 } |
| 85 EmeFeatureSupport GetDistinctiveIdentifierSupport() const override { |
| 86 return EmeFeatureSupport::ALWAYS_ENABLED; |
| 87 } |
| 88 |
| 89 private: |
| 90 const std::string name_; |
| 91 const SupportedCodecs supported_codecs_; |
| 92 }; |
| 93 |
| 94 } // namespace |
| 95 |
28 static SupportedKeySystemResponse QueryKeySystemSupport( | 96 static SupportedKeySystemResponse QueryKeySystemSupport( |
29 const std::string& key_system) { | 97 const std::string& key_system) { |
30 SupportedKeySystemRequest request; | 98 SupportedKeySystemRequest request; |
31 SupportedKeySystemResponse response; | 99 SupportedKeySystemResponse response; |
32 | 100 |
33 request.key_system = key_system; | 101 request.key_system = key_system; |
34 request.codecs = media::EME_CODEC_ALL; | 102 request.codecs = media::EME_CODEC_ALL; |
35 content::RenderThread::Get()->Send( | 103 content::RenderThread::Get()->Send( |
36 new ChromeViewHostMsg_QueryKeySystemSupport(request, &response)); | 104 new ChromeViewHostMsg_QueryKeySystemSupport(request, &response)); |
37 DCHECK(!(response.compositing_codecs & ~media::EME_CODEC_ALL)) | 105 DCHECK(!(response.compositing_codecs & ~media::EME_CODEC_ALL)) |
38 << "unrecognized codec"; | 106 << "unrecognized codec"; |
39 DCHECK(!(response.non_compositing_codecs & ~media::EME_CODEC_ALL)) | 107 DCHECK(!(response.non_compositing_codecs & ~media::EME_CODEC_ALL)) |
40 << "unrecognized codec"; | 108 << "unrecognized codec"; |
41 return response; | 109 return response; |
42 } | 110 } |
43 | 111 |
44 void AddAndroidWidevine(std::vector<KeySystemInfo>* concrete_key_systems) { | 112 void AddAndroidWidevine( |
| 113 std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) { |
45 SupportedKeySystemResponse response = QueryKeySystemSupport( | 114 SupportedKeySystemResponse response = QueryKeySystemSupport( |
46 kWidevineKeySystem); | 115 kWidevineKeySystem); |
47 | 116 |
48 // Since we do not control the implementation of the MediaDrm API on Android, | 117 // 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 | 118 // we assume that it can and will make use of persistence even though no |
50 // persistence-based features are supported. | 119 // persistence-based features are supported. |
51 | 120 |
52 if (response.compositing_codecs != media::EME_CODEC_NONE) { | 121 if (response.compositing_codecs != media::EME_CODEC_NONE) { |
53 AddWidevineWithCodecs( | 122 concrete_key_systems->emplace_back(new WidevineKeySystemProperties( |
54 response.compositing_codecs, // Regular codecs. | 123 response.compositing_codecs, // Regular codecs. |
55 response.non_compositing_codecs, // Hardware-secure codecs. | 124 response.non_compositing_codecs, // Hardware-secure codecs. |
56 EmeRobustness::HW_SECURE_CRYPTO, // Max audio robustness. | 125 EmeRobustness::HW_SECURE_CRYPTO, // Max audio robustness. |
57 EmeRobustness::HW_SECURE_ALL, // Max video robustness. | 126 EmeRobustness::HW_SECURE_ALL, // Max video robustness. |
58 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license. | 127 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license. |
59 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-release-message. | 128 EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-release-message. |
60 EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state. | 129 EmeFeatureSupport::ALWAYS_ENABLED, // Persistent state. |
61 EmeFeatureSupport::ALWAYS_ENABLED, // Distinctive identifier. | 130 EmeFeatureSupport::ALWAYS_ENABLED)); // Distinctive identifier. |
62 concrete_key_systems); | |
63 } else { | 131 } else { |
64 // It doesn't make sense to support secure codecs but not regular codecs. | 132 // It doesn't make sense to support secure codecs but not regular codecs. |
65 DCHECK(response.non_compositing_codecs == media::EME_CODEC_NONE); | 133 DCHECK(response.non_compositing_codecs == media::EME_CODEC_NONE); |
66 } | 134 } |
67 } | 135 } |
68 | 136 |
69 void AddAndroidPlatformKeySystems( | 137 void AddAndroidPlatformKeySystems( |
70 std::vector<KeySystemInfo>* concrete_key_systems) { | 138 std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) { |
71 std::vector<std::string> key_system_names; | 139 std::vector<std::string> key_system_names; |
72 content::RenderThread::Get()->Send( | 140 content::RenderThread::Get()->Send( |
73 new ChromeViewHostMsg_GetPlatformKeySystemNames(&key_system_names)); | 141 new ChromeViewHostMsg_GetPlatformKeySystemNames(&key_system_names)); |
74 | 142 |
75 for (std::vector<std::string>::const_iterator it = key_system_names.begin(); | 143 for (std::vector<std::string>::const_iterator it = key_system_names.begin(); |
76 it != key_system_names.end(); ++it) { | 144 it != key_system_names.end(); ++it) { |
77 SupportedKeySystemResponse response = QueryKeySystemSupport(*it); | 145 SupportedKeySystemResponse response = QueryKeySystemSupport(*it); |
78 if (response.compositing_codecs != media::EME_CODEC_NONE) { | 146 if (response.compositing_codecs != media::EME_CODEC_NONE) { |
79 KeySystemInfo info; | 147 concrete_key_systems->emplace_back(new AndroidPlatformKeySystemProperties( |
80 info.key_system = *it; | 148 *it, response.compositing_codecs)); |
81 info.supported_codecs = response.compositing_codecs; | |
82 // Here we assume that support for a container implies support for the | |
83 // associated initialization data type. KeySystems handles validating | |
84 // |init_data_type| x |container| pairings. | |
85 if (response.compositing_codecs & media::EME_CODEC_WEBM_ALL) | |
86 info.supported_init_data_types |= media::kInitDataTypeMaskWebM; | |
87 #if defined(USE_PROPRIETARY_CODECS) | |
88 if (response.compositing_codecs & media::EME_CODEC_MP4_ALL) | |
89 info.supported_init_data_types |= media::kInitDataTypeMaskCenc; | |
90 #endif // defined(USE_PROPRIETARY_CODECS) | |
91 info.max_audio_robustness = EmeRobustness::EMPTY; | |
92 info.max_video_robustness = EmeRobustness::EMPTY; | |
93 // Assume that platform key systems support no features but can and will | |
94 // make use of persistence and identifiers. | |
95 info.persistent_license_support = | |
96 media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
97 info.persistent_release_message_support = | |
98 media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
99 info.persistent_state_support = media::EmeFeatureSupport::ALWAYS_ENABLED; | |
100 info.distinctive_identifier_support = | |
101 media::EmeFeatureSupport::ALWAYS_ENABLED; | |
102 concrete_key_systems->push_back(info); | |
103 } | 149 } |
104 } | 150 } |
105 } | 151 } |
106 | 152 |
107 } // namespace cdm | 153 } // namespace cdm |
OLD | NEW |