OLD | NEW |
---|---|
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 "media/base/decryptor.h" |
8 #include "media/crypto/aes_decryptor.h" | 8 #include "media/crypto/aes_decryptor.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
10 #include "webkit/media/crypto/ppapi_decryptor.h" | |
10 | 11 |
11 namespace webkit_media { | 12 namespace webkit_media { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 16 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
17 const char kExternalClearKeyKeySystem[] = "webkit-org.w3.external-clearkey"; | |
ddorwin
2012/07/17 21:31:28
I haven't thought this through entirely, but it se
xhwang
2012/07/18 19:43:17
Done.
| |
16 | 18 |
17 struct MediaFormatAndKeySystem { | 19 struct MediaFormatAndKeySystem { |
18 const char* mime_type; | 20 const char* mime_type; |
19 const char* codec; | 21 const char* codec; |
20 const char* key_system; | 22 const char* key_system; |
21 }; | 23 }; |
22 | 24 |
25 struct KeySystemPluginNamePair { | |
ddorwin
2012/07/17 21:31:28
MimeType here and below.
xhwang
2012/07/18 19:43:17
Use PluginType as discussed.
| |
26 const char* key_system; | |
27 const char* plugin_name; | |
28 }; | |
29 | |
23 static const MediaFormatAndKeySystem | 30 static const MediaFormatAndKeySystem |
24 supported_format_key_system_combinations[] = { | 31 supported_format_key_system_combinations[] = { |
25 // TODO(ddorwin): Reconsider based on how usage of this class evolves. | 32 // 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 | 33 // For now, this class is stateless, so we do not have the opportunity to |
27 // build a list using ParseCodecString() like | 34 // build a list using ParseCodecString() like |
28 // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must | 35 // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must |
29 // be separate entries. | 36 // be separate entries. |
30 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, | 37 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, |
31 { "video/webm", "vorbis", kClearKeyKeySystem }, | 38 { "video/webm", "vorbis", kClearKeyKeySystem }, |
32 { "video/webm", "vp8", kClearKeyKeySystem }, | 39 { "video/webm", "vp8", kClearKeyKeySystem }, |
33 { "video/webm", "vp8.0", kClearKeyKeySystem }, | 40 { "video/webm", "vp8.0", kClearKeyKeySystem }, |
34 { "audio/webm", "vorbis", kClearKeyKeySystem }, | 41 { "audio/webm", "vorbis", kClearKeyKeySystem }, |
35 { "video/webm", "", kClearKeyKeySystem }, | 42 { "video/webm", "", kClearKeyKeySystem }, |
36 { "audio/webm", "", kClearKeyKeySystem } | 43 { "audio/webm", "", kClearKeyKeySystem } |
ddorwin
2012/07/17 21:31:28
Need to update these tables too.
xhwang
2012/07/18 19:43:17
Done.
| |
37 }; | 44 }; |
38 | 45 |
46 static const KeySystemPluginNamePair key_system_to_plugin_name_mapping[] = { | |
47 // TODO(xhwang): Update this with the real plugin name. | |
48 { kExternalClearKeyKeySystem, "application/x-ppapi-example" } | |
ddorwin
2012/07/17 21:31:28
FYI, the same TODO as in the above table would app
| |
49 }; | |
50 | |
39 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, | 51 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, |
40 const std::string& codec, | 52 const std::string& codec, |
41 const std::string& key_system) { | 53 const std::string& key_system) { |
42 for (size_t i = 0; | 54 for (size_t i = 0; |
43 i < arraysize(supported_format_key_system_combinations); | 55 i < arraysize(supported_format_key_system_combinations); |
44 ++i) { | 56 ++i) { |
45 const MediaFormatAndKeySystem& combination = | 57 const MediaFormatAndKeySystem& combination = |
46 supported_format_key_system_combinations[i]; | 58 supported_format_key_system_combinations[i]; |
47 if (combination.mime_type == mime_type && | 59 if (combination.mime_type == mime_type && |
48 combination.codec == codec && | 60 combination.codec == codec && |
49 combination.key_system == key_system) | 61 combination.key_system == key_system) |
50 return true; | 62 return true; |
51 } | 63 } |
52 | 64 |
53 return false; | 65 return false; |
54 } | 66 } |
55 | 67 |
56 } // namespace | 68 } // namespace |
57 | 69 |
58 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { | 70 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { |
59 if (key_system == kClearKeyKeySystem) | 71 if (key_system == kClearKeyKeySystem) |
ddorwin
2012/07/17 21:31:28
Need to add new key system(s). Maybe we should bas
xhwang
2012/07/18 19:43:17
Done. I'll keep "if" here instead of using table a
| |
60 return true; | 72 return true; |
61 return false; | 73 return false; |
62 } | 74 } |
63 | 75 |
64 bool IsSupportedKeySystemWithMediaMimeType( | 76 bool IsSupportedKeySystemWithMediaMimeType( |
65 const std::string& mime_type, | 77 const std::string& mime_type, |
66 const std::vector<std::string>& codecs, | 78 const std::vector<std::string>& codecs, |
67 const std::string& key_system) { | 79 const std::string& key_system) { |
68 if (codecs.empty()) | 80 if (codecs.empty()) |
69 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); | 81 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); |
70 | 82 |
71 for (size_t i = 0; i < codecs.size(); ++i) { | 83 for (size_t i = 0; i < codecs.size(); ++i) { |
72 if (!IsSupportedKeySystemWithContainerAndCodec( | 84 if (!IsSupportedKeySystemWithContainerAndCodec( |
73 mime_type, codecs[i], key_system)) | 85 mime_type, codecs[i], key_system)) |
74 return false; | 86 return false; |
75 } | 87 } |
76 | 88 |
77 return true; | 89 return true; |
78 } | 90 } |
79 | 91 |
80 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system, | 92 const char* GetPluginName(const std::string& key_system) { |
81 media::DecryptorClient* client) { | 93 for (size_t i = 0; i < arraysize(key_system_to_plugin_name_mapping); ++i) { |
94 if (key_system_to_plugin_name_mapping[i].key_system == key_system) | |
95 return key_system_to_plugin_name_mapping[i].plugin_name; | |
96 } | |
97 | |
98 return NULL; | |
99 } | |
100 | |
101 scoped_ptr<media::Decryptor> CreateDecryptor( | |
102 const std::string& key_system, | |
103 media::DecryptorClient* client, | |
104 const CreatePluginCB& create_plugin_cb) { | |
ddorwin
2012/07/17 21:31:28
It's unexpected that this cb isn't always called.
xhwang
2012/07/18 19:43:17
Removed CreatePluginCB and just passing the client
| |
82 if (key_system == kClearKeyKeySystem) | 105 if (key_system == kClearKeyKeySystem) |
83 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client)); | 106 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client)); |
107 else if (key_system == kExternalClearKeyKeySystem) | |
ddorwin
2012/07/17 21:31:28
I think we should GetPlugingMimeType() and if not
xhwang
2012/07/18 19:43:17
Moved this check and related logic into PpapiDecry
| |
108 return scoped_ptr<media::Decryptor>( | |
109 new webkit_media::PpapiDecryptor(client, create_plugin_cb)); | |
84 return scoped_ptr<media::Decryptor>(); | 110 return scoped_ptr<media::Decryptor>(); |
85 } | 111 } |
86 | 112 |
87 } // namespace webkit_media | 113 } // namespace webkit_media |
OLD | NEW |