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

Side by Side Diff: webkit/media/crypto/key_systems.cc

Issue 10704241: Add PpapiDecryptor which wraps a CDM plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve comments Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/media/crypto/key_systems.h" 5 #include "webkit/media/crypto/key_systems.h"
6 6
7 #include "media/base/decryptor.h" 7 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
8 #include "media/crypto/aes_decryptor.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
10 9
11 namespace webkit_media { 10 namespace webkit_media {
12 11
13 namespace { 12 namespace {
14 13
15 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 14 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
15 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
16 16
17 struct MediaFormatAndKeySystem { 17 struct MediaFormatAndKeySystem {
18 const char* mime_type; 18 const char* mime_type;
19 const char* codec; 19 const char* codec;
20 const char* key_system; 20 const char* key_system;
21 }; 21 };
22 22
23 struct KeySystemPluginTypePair {
24 const char* key_system;
25 const char* plugin_type;
26 };
27
23 static const MediaFormatAndKeySystem 28 static const MediaFormatAndKeySystem
24 supported_format_key_system_combinations[] = { 29 supported_format_key_system_combinations[] = {
25 // TODO(ddorwin): Reconsider based on how usage of this class evolves. 30 // TODO(ddorwin): Reconsider based on how usage of this class evolves.
26 // For now, this class is stateless, so we do not have the opportunity to 31 // For now, this class is stateless, so we do not have the opportunity to
27 // build a list using ParseCodecString() like 32 // build a list using ParseCodecString() like
28 // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must 33 // net::MimeUtil::InitializeMimeTypeMaps(). Therefore, the following line must
29 // be separate entries. 34 // be separate entries.
30 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, 35 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem },
31 { "video/webm", "vorbis", kClearKeyKeySystem }, 36 { "video/webm", "vorbis", kClearKeyKeySystem },
32 { "video/webm", "vp8", kClearKeyKeySystem }, 37 { "video/webm", "vp8", kClearKeyKeySystem },
33 { "video/webm", "vp8.0", kClearKeyKeySystem }, 38 { "video/webm", "vp8.0", kClearKeyKeySystem },
34 { "audio/webm", "vorbis", kClearKeyKeySystem }, 39 { "audio/webm", "vorbis", kClearKeyKeySystem },
35 { "video/webm", "", kClearKeyKeySystem }, 40 { "video/webm", "", kClearKeyKeySystem },
36 { "audio/webm", "", kClearKeyKeySystem } 41 { "audio/webm", "", kClearKeyKeySystem },
42 { "video/webm", "vorbis", kExternalClearKeyKeySystem },
43 { "video/webm", "vp8", kExternalClearKeyKeySystem },
44 { "video/webm", "vp8.0", kExternalClearKeyKeySystem },
45 { "audio/webm", "vorbis", kExternalClearKeyKeySystem },
46 { "video/webm", "", kExternalClearKeyKeySystem },
47 { "audio/webm", "", kExternalClearKeyKeySystem }
48 };
49
50 static const KeySystemPluginTypePair key_system_to_plugin_type_mapping[] = {
51 // TODO(xhwang): Update this with the real plugin name.
52 { kExternalClearKeyKeySystem, "application/x-ppapi-example" }
37 }; 53 };
38 54
39 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, 55 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type,
40 const std::string& codec, 56 const std::string& codec,
41 const std::string& key_system) { 57 const std::string& key_system) {
42 for (size_t i = 0; 58 for (size_t i = 0;
43 i < arraysize(supported_format_key_system_combinations); 59 i < arraysize(supported_format_key_system_combinations);
44 ++i) { 60 ++i) {
45 const MediaFormatAndKeySystem& combination = 61 const MediaFormatAndKeySystem& combination =
46 supported_format_key_system_combinations[i]; 62 supported_format_key_system_combinations[i];
47 if (combination.mime_type == mime_type && 63 if (combination.mime_type == mime_type &&
48 combination.codec == codec && 64 combination.codec == codec &&
49 combination.key_system == key_system) 65 combination.key_system == key_system)
50 return true; 66 return true;
51 } 67 }
52 68
53 return false; 69 return false;
54 } 70 }
55 71
56 } // namespace 72 } // namespace
57 73
58 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { 74 bool IsSupportedKeySystem(const WebKit::WebString& key_system) {
59 if (key_system == kClearKeyKeySystem) 75 return CanUseAesDecryptor(key_system.utf8().data()) ||
60 return true; 76 !GetPluginType(key_system.utf8().data()).empty();
61 return false;
62 } 77 }
63 78
64 bool IsSupportedKeySystemWithMediaMimeType( 79 bool IsSupportedKeySystemWithMediaMimeType(
65 const std::string& mime_type, 80 const std::string& mime_type,
66 const std::vector<std::string>& codecs, 81 const std::vector<std::string>& codecs,
67 const std::string& key_system) { 82 const std::string& key_system) {
68 if (codecs.empty()) 83 if (codecs.empty())
69 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); 84 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system);
70 85
71 for (size_t i = 0; i < codecs.size(); ++i) { 86 for (size_t i = 0; i < codecs.size(); ++i) {
72 if (!IsSupportedKeySystemWithContainerAndCodec( 87 if (!IsSupportedKeySystemWithContainerAndCodec(
73 mime_type, codecs[i], key_system)) 88 mime_type, codecs[i], key_system))
74 return false; 89 return false;
75 } 90 }
76 91
77 return true; 92 return true;
78 } 93 }
79 94
80 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system, 95 bool CanUseAesDecryptor(const std::string& key_system) {
81 media::DecryptorClient* client) { 96 return key_system == kClearKeyKeySystem;
82 if (key_system == kClearKeyKeySystem) 97 }
83 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client)); 98
84 return scoped_ptr<media::Decryptor>(); 99 std::string GetPluginType(const std::string& key_system) {
100 for (size_t i = 0; i < arraysize(key_system_to_plugin_type_mapping); ++i) {
101 if (key_system_to_plugin_type_mapping[i].key_system == key_system)
102 return key_system_to_plugin_type_mapping[i].plugin_type;
103 }
104
105 return std::string();
85 } 106 }
86 107
87 } // namespace webkit_media 108 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698