Chromium Code Reviews| Index: webkit/media/key_systems.cc |
| diff --git a/webkit/media/key_systems.cc b/webkit/media/key_systems.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8d6e4f4d9ef9051fe8f14e3cc46b156cbbcf0a0e |
| --- /dev/null |
| +++ b/webkit/media/key_systems.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 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 "webkit/media/key_systems.h" |
| + |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| + |
| +namespace webkit_media { |
| + |
| +namespace key_systems { |
| + |
| +namespace { |
| + |
| +const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
|
darin (slow to review)
2012/04/18 23:57:40
nit: should we be concerned about claiming "webkit
ddorwin
2012/04/19 00:52:54
This is really a "webkit-" prefix to "org.w3.clear
|
| + |
| +struct MediaFormatAndKeySystem { |
| + const char* mime_type; |
| + const char* codec; |
| + const char* key_system; |
| +}; |
| + |
| +static const MediaFormatAndKeySystem |
| +supported_format_key_system_combinations[] = { |
| + // TODO(ddorwin): Reconsider based on how usage of this class evolves. |
| + // For now, this class is stateless, so we do not have the opportunity to |
| + // build a list using ParseCodecString() like MimeUtil. Therfore, the |
|
darin (slow to review)
2012/04/18 23:57:40
does "MimeUtil" in this comment refer to net/base/
ddorwin
2012/04/19 00:52:54
Done.
|
| + // following line must be separate entries. |
| + // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, |
| + { "video/webm", "vorbis", kClearKeyKeySystem }, |
|
darin (slow to review)
2012/04/18 23:57:40
do you intend for there to be other key_system val
ddorwin
2012/04/19 00:52:54
Yes. We will add to this table when we add new key
|
| + { "video/webm", "vp8", kClearKeyKeySystem }, |
| + { "video/webm", "vp8.0", kClearKeyKeySystem }, |
| + { "audio/webm", "vorbis", kClearKeyKeySystem }, |
| + { "video/webm", "", kClearKeyKeySystem }, |
| + { "audio/webm", "", kClearKeyKeySystem } |
| +}; |
| + |
| +bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, |
| + const std::string& codec, |
| + const std::string& key_system) { |
| + for (size_t i = 0; |
| + i < arraysize(supported_format_key_system_combinations); |
| + ++i) { |
| + const MediaFormatAndKeySystem& combination = |
| + supported_format_key_system_combinations[i]; |
| + if (combination.mime_type == mime_type && |
| + combination.codec == codec && |
| + combination.key_system == key_system) |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| +bool IsSupportedKeySystem(const WebKit::WebString& key_system) { |
| + if (key_system == kClearKeyKeySystem) |
| + return true; |
| + return false; |
| +} |
| + |
| +bool IsSupportedKeySystemWithMediaMimeType( |
| + const std::string& mime_type, |
| + const std::vector<std::string>& codecs, |
| + const std::string& key_system) { |
| + if (codecs.empty()) |
| + return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); |
| + |
| + for (size_t i = 0; i < codecs.size(); ++i) { |
| + if (!IsSupportedKeySystemWithContainerAndCodec( |
| + mime_type, codecs[i], key_system)) |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace key_systems |
| + |
| +} // namespace webkit_media |