Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: content/renderer/media/crypto/key_systems.cc

Issue 557723003: Implement Chromium side of MediaKeys.isTypeSupported(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DEP from components/cdm/renderer to content/public/common. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/crypto/key_systems.cc
diff --git a/content/renderer/media/crypto/key_systems.cc b/content/renderer/media/crypto/key_systems.cc
index a15e0b3578172be5e3ddcbaa4dc6e41a307ebf21..8acbf35060aaa0aefbda764a6a069fe43273eebb 100644
--- a/content/renderer/media/crypto/key_systems.cc
+++ b/content/renderer/media/crypto/key_systems.cc
@@ -14,6 +14,7 @@
#include "base/time/time.h"
#include "content/public/common/content_client.h"
#include "content/public/common/eme_codec.h"
+#include "content/public/common/eme_init_data_type.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/key_system_info.h"
#include "content/renderer/media/crypto/key_systems_support_uma.h"
@@ -35,6 +36,11 @@ struct CodecMask {
EmeCodec mask;
};
+struct InitDataTypeMask {
ddorwin 2014/09/13 01:20:45 nit: move IDT stuff before container and codec to
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
+ const char* type;
+ EmeInitDataType mask;
ddorwin 2014/09/13 01:20:45 This seems like more of a type string to enum map.
sandersd (OOO until July 31) 2014/09/22 23:45:52 I had a go at renaming these, hopefully it's bette
+};
+
// Mapping between container types and the masks of associated codecs.
// Only audio codec can belong to a "audio/*" container. Both audio and video
// codecs can belong to a "video/*" container.
@@ -61,6 +67,13 @@ CodecMask kCodecMasks[] = {
#endif // defined(USE_PROPRIETARY_CODECS)
};
+// Mapping between initialization data types and their masks.
ddorwin 2014/09/13 01:20:45 ditto on moving
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
+InitDataTypeMask kInitDataTypeMasks[] = {
+ {"cenc", EME_INIT_DATA_TYPE_CENC},
ddorwin 2014/09/13 03:51:05 This is a straight conversion and never depends on
sandersd (OOO until July 31) 2014/09/22 23:45:53 We can, but then blink needs to know what the supp
ddorwin 2014/09/23 22:48:15 I think it's probably reasonable for Blink to know
+ {"webm", EME_INIT_DATA_TYPE_WEBM},
+ {"keyids", EME_INIT_DATA_TYPE_KEYIDS},
+};
+
static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
KeySystemInfo info(kClearKeyKeySystem);
@@ -80,6 +93,8 @@ static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
info.supported_codecs |= EME_CODEC_MP4_ALL;
#endif // defined(USE_PROPRIETARY_CODECS)
+ info.supported_init_data_types = EME_INIT_DATA_TYPE_ALL;
ddorwin 2014/09/13 01:20:46 ditto on moving (also in other files)
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
+
info.use_aes_decryptor = true;
concrete_key_systems->push_back(info);
@@ -93,6 +108,12 @@ class KeySystems {
bool IsConcreteSupportedKeySystem(const std::string& key_system);
+ bool IsSupportedKeySystem(const std::string& key_system);
+
+ bool IsSupportedKeySystemWithInitDataType(
+ const std::string& key_system,
+ const std::string& init_data_type);
+
bool IsSupportedKeySystemWithMediaMimeType(
const std::string& mime_type,
const std::vector<std::string>& codecs,
@@ -120,6 +141,7 @@ class KeySystems {
const std::string& pepper_type,
#endif
SupportedCodecs supported_codecs,
+ SupportedInitDataTypes supported_init_data_types,
ddorwin 2014/09/13 01:20:45 nit: move up one line to match ITS order.
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
const std::string& parent_key_system);
friend struct base::DefaultLazyInstanceTraits<KeySystems>;
@@ -133,12 +155,14 @@ class KeySystems {
std::string pepper_type;
#endif
SupportedCodecs supported_codecs;
+ SupportedInitDataTypes supported_init_data_types;
ddorwin 2014/09/13 01:20:45 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
};
typedef base::hash_map<std::string, KeySystemProperties>
KeySystemPropertiesMap;
typedef base::hash_map<std::string, std::string> ParentKeySystemMap;
typedef base::hash_map<std::string, EmeCodec> CodecMaskMap;
+ typedef base::hash_map<std::string, EmeInitDataType> InitDataTypeMaskMap;
ddorwin 2014/09/13 01:20:46 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
KeySystems();
~KeySystems() {}
@@ -167,6 +191,7 @@ class KeySystems {
CodecMaskMap container_codec_masks_;
CodecMaskMap codec_masks_;
+ InitDataTypeMaskMap init_data_type_masks_;
ddorwin 2014/09/13 01:20:45 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
bool needs_update_;
base::Time last_update_time_;
@@ -189,18 +214,15 @@ KeySystems& KeySystems::GetInstance() {
// the instance is lazily initiated.
KeySystems::KeySystems() : needs_update_(true) {
// Build container and codec masks for quick look up.
- for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) {
- const CodecMask& container_codec_mask = kContainerCodecMasks[i];
- DCHECK(container_codec_masks_.find(container_codec_mask.type) ==
- container_codec_masks_.end());
- container_codec_masks_[container_codec_mask.type] =
- container_codec_mask.mask;
- }
- for (size_t i = 0; i < arraysize(kCodecMasks); ++i) {
- const CodecMask& codec_mask = kCodecMasks[i];
- DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end());
- codec_masks_[codec_mask.type] = codec_mask.mask;
+#define BUILD_MASK(dst, src) \
ddorwin 2014/09/13 01:20:45 Macros aren't allowed. Would a template function w
sandersd (OOO until July 31) 2014/09/22 23:45:52 I've expanded the macro, but I do think the macro
+ for (size_t i = 0; i < arraysize(src); ++i) { \
+ DCHECK(dst.find(src[i].type) == dst.end()); \
+ dst[src[i].type] = src[i].mask; \
}
+ BUILD_MASK(container_codec_masks_, kContainerCodecMasks);
+ BUILD_MASK(codec_masks_, kCodecMasks);
+ BUILD_MASK(init_data_type_masks_, kInitDataTypeMasks);
+#undef BUILD_MASK
UpdateSupportedKeySystems();
@@ -264,6 +286,7 @@ void KeySystems::AddConcreteSupportedKeySystems(
key_system_info.pepper_type,
#endif
key_system_info.supported_codecs,
+ key_system_info.supported_init_data_types,
key_system_info.parent_key_system);
}
}
@@ -275,6 +298,7 @@ void KeySystems::AddConcreteSupportedKeySystem(
const std::string& pepper_type,
#endif
SupportedCodecs supported_codecs,
+ SupportedInitDataTypes supported_init_data_types,
const std::string& parent_key_system) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system))
@@ -291,6 +315,7 @@ void KeySystems::AddConcreteSupportedKeySystem(
#endif
properties.supported_codecs = supported_codecs;
+ properties.supported_init_data_types = supported_init_data_types;
concrete_key_system_map_[concrete_key_system] = properties;
@@ -306,8 +331,7 @@ void KeySystems::AddConcreteSupportedKeySystem(
bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) {
DCHECK(thread_checker_.CalledOnValidThread());
- return concrete_key_system_map_.find(key_system) !=
- concrete_key_system_map_.end();
+ return concrete_key_system_map_.count(key_system);
ddorwin 2014/09/13 01:20:45 Is there a reason you made this change? Not that i
sandersd (OOO until July 31) 2014/09/22 23:45:53 It's a hash_map.
}
bool KeySystems::IsSupportedContainer(
@@ -369,6 +393,45 @@ bool KeySystems::IsSupportedContainerAndCodecs(
return true;
}
+bool KeySystems::IsSupportedKeySystem(const std::string& key_system) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return (parent_key_system_map_.count(key_system) ||
ddorwin 2014/09/13 01:20:45 ditto.
sandersd (OOO until July 31) 2014/09/22 23:45:53 Acknowledged.
+ concrete_key_system_map_.count(key_system));
ddorwin 2014/09/13 01:20:45 minor: We're more likely to see concrete key syste
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
+}
+
+bool KeySystems::IsSupportedKeySystemWithInitDataType(
+ const std::string& key_system,
+ const std::string& init_data_type) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // If |key_system| is a parent key system, use its concrete child.
+ std::string concrete_key_system = key_system;
+ ParentKeySystemMap::const_iterator parent_key_system_iter =
+ parent_key_system_map_.find(key_system);
+ if (parent_key_system_iter != parent_key_system_map_.end())
+ concrete_key_system = parent_key_system_iter->second;
+
+ // Locate |concrete_key_system|.
+ KeySystemPropertiesMap::const_iterator key_system_iter =
+ concrete_key_system_map_.find(concrete_key_system);
+ if (key_system_iter == concrete_key_system_map_.end())
+ return false;
+
+ // Check |init_data_type|.
+ InitDataTypeMaskMap::const_iterator init_data_type_iter =
+ init_data_type_masks_.find(init_data_type);
+ if (init_data_type_iter == init_data_type_masks_.end())
+ return false;
+
+ // Check |key_system| x |init_data_type|.
+ const KeySystemProperties& properties = key_system_iter->second;
+ const EmeInitDataType& init_data_type_mask = init_data_type_iter->second;
+ if (!(properties.supported_init_data_types & init_data_type_mask))
+ return false;
+
+ return true;
+}
+
bool KeySystems::IsSupportedKeySystemWithMediaMimeType(
const std::string& mime_type,
const std::vector<std::string>& codecs,
@@ -488,6 +551,17 @@ bool IsConcreteSupportedKeySystem(const std::string& key_system) {
return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system);
}
+bool IsSupportedKeySystem(const std::string& key_system) {
+ return KeySystems::GetInstance().IsSupportedKeySystem(key_system);
+}
+
+bool IsSupportedKeySystemWithInitDataType(
+ const std::string& key_system,
+ const std::string& init_data_type) {
+ return KeySystems::GetInstance().IsSupportedKeySystemWithInitDataType(
+ key_system, init_data_type);
+}
+
bool IsSupportedKeySystemWithMediaMimeType(
const std::string& mime_type,
const std::vector<std::string>& codecs,

Powered by Google App Engine
This is Rietveld 408576698