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

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 and rebase. 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"
8 #include "media/crypto/aes_decryptor.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 7 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
10 8
11 namespace webkit_media { 9 namespace webkit_media {
12 10
13 namespace { 11 namespace {
14 12
15 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 13 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
14 const char kExternalClearKeyKeySystem[] = "org.chromium.external-clearkey";
ddorwin 2012/07/19 01:12:34 Not sure whether we should use a '-'. I guess it's
xhwang 2012/07/19 15:54:34 Done.
16 15
17 struct MediaFormatAndKeySystem { 16 struct MediaFormatAndKeySystem {
18 const char* mime_type; 17 const char* mime_type;
19 const char* codec; 18 const char* codec;
20 const char* key_system; 19 const char* key_system;
21 }; 20 };
22 21
22 struct KeySystemPluginTypePair {
23 const char* key_system;
24 const char* plugin_type;
25 };
26
23 static const MediaFormatAndKeySystem 27 static const MediaFormatAndKeySystem
xhwang 2012/07/19 15:54:34 We have both anonymous namespace and static functi
ddorwin 2012/07/19 20:50:09 SG. I guess both are allowed (last paragraph): htt
xhwang 2012/07/19 21:54:03 Done.
24 supported_format_key_system_combinations[] = { 28 supported_format_key_system_combinations[] = {
25 // TODO(ddorwin): Reconsider based on how usage of this class evolves. 29 // 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 30 // For now, this class is stateless, so we do not have the opportunity to
27 // build a list using ParseCodecString() like 31 // build a list using ParseCodecString() like
28 // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must 32 // net::MimeUtil::InitializeMimeTypeMaps(). Therefore, the following line must
29 // be separate entries. 33 // be separate entries.
30 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, 34 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem },
31 { "video/webm", "vorbis", kClearKeyKeySystem }, 35 { "video/webm", "vorbis", kClearKeyKeySystem },
32 { "video/webm", "vp8", kClearKeyKeySystem }, 36 { "video/webm", "vp8", kClearKeyKeySystem },
33 { "video/webm", "vp8.0", kClearKeyKeySystem }, 37 { "video/webm", "vp8.0", kClearKeyKeySystem },
34 { "audio/webm", "vorbis", kClearKeyKeySystem }, 38 { "audio/webm", "vorbis", kClearKeyKeySystem },
35 { "video/webm", "", kClearKeyKeySystem }, 39 { "video/webm", "", kClearKeyKeySystem },
36 { "audio/webm", "", kClearKeyKeySystem } 40 { "audio/webm", "", kClearKeyKeySystem },
41 { "video/webm", "vorbis", kExternalClearKeyKeySystem },
42 { "video/webm", "vp8", kExternalClearKeyKeySystem },
43 { "video/webm", "vp8.0", kExternalClearKeyKeySystem },
44 { "audio/webm", "vorbis", kExternalClearKeyKeySystem },
45 { "video/webm", "", kExternalClearKeyKeySystem },
46 { "audio/webm", "", kExternalClearKeyKeySystem }
47 };
48
49 static const KeySystemPluginTypePair key_system_to_plugin_type_mapping[] = {
50 // TODO(xhwang): Update this with the real plugin name.
51 { kExternalClearKeyKeySystem, "application/x-ppapi-example" }
37 }; 52 };
38 53
39 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, 54 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type,
40 const std::string& codec, 55 const std::string& codec,
41 const std::string& key_system) { 56 const std::string& key_system) {
42 for (size_t i = 0; 57 for (size_t i = 0;
43 i < arraysize(supported_format_key_system_combinations); 58 i < arraysize(supported_format_key_system_combinations);
44 ++i) { 59 ++i) {
45 const MediaFormatAndKeySystem& combination = 60 const MediaFormatAndKeySystem& combination =
46 supported_format_key_system_combinations[i]; 61 supported_format_key_system_combinations[i];
47 if (combination.mime_type == mime_type && 62 if (combination.mime_type == mime_type &&
48 combination.codec == codec && 63 combination.codec == codec &&
49 combination.key_system == key_system) 64 combination.key_system == key_system)
50 return true; 65 return true;
51 } 66 }
52 67
53 return false; 68 return false;
54 } 69 }
55 70
56 } // namespace 71 } // namespace
57 72
58 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { 73 bool IsSupportedKeySystem(const WebKit::WebString& key_system) {
59 if (key_system == kClearKeyKeySystem) 74 if (key_system == kClearKeyKeySystem ||
ddorwin 2012/07/19 01:12:34 We _could_ replace this with: if (CanUseAesDecry
xhwang 2012/07/19 15:54:34 Done.
75 key_system == kExternalClearKeyKeySystem)
60 return true; 76 return true;
61 return false; 77 return false;
62 } 78 }
63 79
64 bool IsSupportedKeySystemWithMediaMimeType( 80 bool IsSupportedKeySystemWithMediaMimeType(
65 const std::string& mime_type, 81 const std::string& mime_type,
66 const std::vector<std::string>& codecs, 82 const std::vector<std::string>& codecs,
67 const std::string& key_system) { 83 const std::string& key_system) {
68 if (codecs.empty()) 84 if (codecs.empty())
69 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); 85 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system);
70 86
71 for (size_t i = 0; i < codecs.size(); ++i) { 87 for (size_t i = 0; i < codecs.size(); ++i) {
72 if (!IsSupportedKeySystemWithContainerAndCodec( 88 if (!IsSupportedKeySystemWithContainerAndCodec(
73 mime_type, codecs[i], key_system)) 89 mime_type, codecs[i], key_system))
74 return false; 90 return false;
75 } 91 }
76 92
77 return true; 93 return true;
78 } 94 }
79 95
80 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system, 96 bool CanUseAesDecryptor(const std::string& key_system) {
81 media::DecryptorClient* client) { 97 return key_system == kClearKeyKeySystem;
82 if (key_system == kClearKeyKeySystem) 98 }
83 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client)); 99
84 return scoped_ptr<media::Decryptor>(); 100 const char* GetPluginType(const std::string& key_system) {
101 for (size_t i = 0; i < arraysize(key_system_to_plugin_type_mapping); ++i) {
102 if (key_system_to_plugin_type_mapping[i].key_system == key_system)
103 return key_system_to_plugin_type_mapping[i].plugin_type;
104 }
105
106 return NULL;
85 } 107 }
86 108
87 } // namespace webkit_media 109 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698