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

Side by Side Diff: media/mojo/services/mojo_cdm_service.cc

Issue 1165633004: media: Add MojoCdmServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 6 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
« no previous file with comments | « media/mojo/services/mojo_cdm_service.h ('k') | media/mojo/services/mojo_cdm_service_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/mojo/services/mojo_cdm_service.h" 5 #include "media/mojo/services/mojo_cdm_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "media/base/cdm_key_information.h" 8 #include "media/base/cdm_key_information.h"
9 #include "media/base/key_systems.h" 9 #include "media/base/key_systems.h"
10 #include "media/cdm/aes_decryptor.h" 10 #include "media/cdm/aes_decryptor.h"
11 #include "media/mojo/services/media_type_converters.h" 11 #include "media/mojo/services/media_type_converters.h"
12 #include "media/mojo/services/mojo_cdm_promise.h" 12 #include "media/mojo/services/mojo_cdm_promise.h"
13 #include "media/mojo/services/mojo_cdm_service_context.h"
13 #include "mojo/common/common_type_converters.h" 14 #include "mojo/common/common_type_converters.h"
14 #include "mojo/common/url_type_converters.h" 15 #include "mojo/common/url_type_converters.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace media { 18 namespace media {
18 19
19 typedef MojoCdmPromise<> SimpleMojoCdmPromise; 20 typedef MojoCdmPromise<> SimpleMojoCdmPromise;
20 typedef MojoCdmPromise<std::string> NewSessionMojoCdmPromise; 21 typedef MojoCdmPromise<std::string> NewSessionMojoCdmPromise;
21 22
23 scopted_ptr<MojoCdmService> MojoCdmService::Create(
24 const mojo::String& key_system,
25 MojoCdmServiceContext* context,
26 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) {
27 // Only AesDecryptor is supported.
28 // TODO(xhwang): Use a CdmFactory to create the CDM here. See
29 // http://crbug.com/495273
30 if (!CanUseAesDecryptor(key_system))
31 return nullptr;
32
33 // TODO(xhwang): Pass security origin through.
34 return make_scoped_ptr(
35 new MojoCdmService(key_system, context, request.Pass()));
36 }
37
22 MojoCdmService::MojoCdmService( 38 MojoCdmService::MojoCdmService(
23 const mojo::String& key_system, 39 const mojo::String& key_system,
40 MojoCdmServiceContext* context,
24 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) 41 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request)
25 : binding_(this, request.Pass()), weak_factory_(this) { 42 : binding_(this, request.Pass()), context_(context), weak_factory_(this) {
43 DVLOG(1) << __FUNCTION__ << ": " << key_system;
44 DCHECK(CanUseAesDecryptor(key_system));
45
26 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); 46 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr();
27 47 cdm_.reset(new AesDecryptor(
28 if (CanUseAesDecryptor(key_system)) { 48 GURL::EmptyGURL(),
29 // TODO(jrummell): Determine proper origin. 49 base::Bind(&MojoCdmService::OnSessionMessage, weak_this),
30 cdm_.reset(new AesDecryptor( 50 base::Bind(&MojoCdmService::OnSessionClosed, weak_this),
31 GURL::EmptyGURL(), 51 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this)));
32 base::Bind(&MojoCdmService::OnSessionMessage, weak_this),
33 base::Bind(&MojoCdmService::OnSessionClosed, weak_this),
34 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this)));
35 }
36
37 // TODO(xhwang): Check key system support in the app.
38 NOTREACHED();
39 } 52 }
40 53
41 MojoCdmService::~MojoCdmService() { 54 MojoCdmService::~MojoCdmService() {
42 } 55 }
43 56
44 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { 57 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) {
45 client_ = client.Pass(); 58 client_ = client.Pass();
46 } 59 }
47 60
48 // mojo::MediaRenderer implementation. 61 // mojo::MediaRenderer implementation.
49 void MojoCdmService::SetServerCertificate( 62 void MojoCdmService::SetServerCertificate(
50 mojo::Array<uint8_t> certificate_data, 63 mojo::Array<uint8_t> certificate_data,
51 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 64 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
65 DVLOG(2) << __FUNCTION__;
52 cdm_->SetServerCertificate( 66 cdm_->SetServerCertificate(
53 certificate_data.storage(), 67 certificate_data.storage(),
54 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 68 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
55 } 69 }
56 70
57 void MojoCdmService::CreateSessionAndGenerateRequest( 71 void MojoCdmService::CreateSessionAndGenerateRequest(
58 mojo::ContentDecryptionModule::SessionType session_type, 72 mojo::ContentDecryptionModule::SessionType session_type,
59 mojo::ContentDecryptionModule::InitDataType init_data_type, 73 mojo::ContentDecryptionModule::InitDataType init_data_type,
60 mojo::Array<uint8_t> init_data, 74 mojo::Array<uint8_t> init_data,
61 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& 75 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>&
62 callback) { 76 callback) {
77 DVLOG(2) << __FUNCTION__;
63 cdm_->CreateSessionAndGenerateRequest( 78 cdm_->CreateSessionAndGenerateRequest(
64 static_cast<MediaKeys::SessionType>(session_type), 79 static_cast<MediaKeys::SessionType>(session_type),
65 static_cast<EmeInitDataType>(init_data_type), init_data.storage(), 80 static_cast<EmeInitDataType>(init_data_type), init_data.storage(),
66 scoped_ptr<NewSessionCdmPromise>(new NewSessionMojoCdmPromise(callback))); 81 make_scoped_ptr(new NewSessionMojoCdmPromise(callback)));
67 } 82 }
68 83
69 void MojoCdmService::LoadSession( 84 void MojoCdmService::LoadSession(
70 mojo::ContentDecryptionModule::SessionType session_type, 85 mojo::ContentDecryptionModule::SessionType session_type,
71 const mojo::String& session_id, 86 const mojo::String& session_id,
72 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& 87 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>&
73 callback) { 88 callback) {
74 cdm_->LoadSession( 89 DVLOG(2) << __FUNCTION__;
75 static_cast<MediaKeys::SessionType>(session_type), 90 cdm_->LoadSession(static_cast<MediaKeys::SessionType>(session_type),
76 session_id.To<std::string>(), 91 session_id.To<std::string>(),
77 scoped_ptr<NewSessionCdmPromise>(new NewSessionMojoCdmPromise(callback))); 92 make_scoped_ptr(new NewSessionMojoCdmPromise(callback)));
78 } 93 }
79 94
80 void MojoCdmService::UpdateSession( 95 void MojoCdmService::UpdateSession(
81 const mojo::String& session_id, 96 const mojo::String& session_id,
82 mojo::Array<uint8_t> response, 97 mojo::Array<uint8_t> response,
83 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 98 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
99 DVLOG(2) << __FUNCTION__;
84 cdm_->UpdateSession( 100 cdm_->UpdateSession(
85 session_id.To<std::string>(), response.storage(), 101 session_id.To<std::string>(), response.storage(),
86 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 102 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback)));
87 } 103 }
88 104
89 void MojoCdmService::CloseSession( 105 void MojoCdmService::CloseSession(
90 const mojo::String& session_id, 106 const mojo::String& session_id,
91 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 107 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
92 cdm_->CloseSession( 108 DVLOG(2) << __FUNCTION__;
93 session_id.To<std::string>(), 109 cdm_->CloseSession(session_id.To<std::string>(),
94 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 110 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
95 } 111 }
96 112
97 void MojoCdmService::RemoveSession( 113 void MojoCdmService::RemoveSession(
98 const mojo::String& session_id, 114 const mojo::String& session_id,
99 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 115 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
100 cdm_->RemoveSession( 116 DVLOG(2) << __FUNCTION__;
101 session_id.To<std::string>(), 117 cdm_->RemoveSession(session_id.To<std::string>(),
102 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 118 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
103 } 119 }
104 120
105 void MojoCdmService::GetCdmContext( 121 void MojoCdmService::GetCdmContext(
106 int32_t cdm_id, 122 int32_t cdm_id,
107 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { 123 mojo::InterfaceRequest<mojo::Decryptor> decryptor) {
108 NOTIMPLEMENTED(); 124 NOTIMPLEMENTED();
109 } 125 }
110 126
127 CdmContext* MojoCdmService::GetCdmContext() {
128 return cdm_->GetCdmContext();
129 }
130
131 void MojoCdmService::OnConnectionError() {
132 DVLOG(1) << __FUNCTION__;
133 context_->ServiceHadConnectionError(this);
134 // The above call deleted this instance, so the only safe thing to do is
135 // return.
136 }
137
111 void MojoCdmService::OnSessionMessage(const std::string& session_id, 138 void MojoCdmService::OnSessionMessage(const std::string& session_id,
112 MediaKeys::MessageType message_type, 139 MediaKeys::MessageType message_type,
113 const std::vector<uint8_t>& message, 140 const std::vector<uint8_t>& message,
114 const GURL& legacy_destination_url) { 141 const GURL& legacy_destination_url) {
142 DVLOG(2) << __FUNCTION__;
115 client_->OnSessionMessage(session_id, 143 client_->OnSessionMessage(session_id,
116 static_cast<mojo::CdmMessageType>(message_type), 144 static_cast<mojo::CdmMessageType>(message_type),
117 mojo::Array<uint8_t>::From(message), 145 mojo::Array<uint8_t>::From(message),
118 mojo::String::From(legacy_destination_url)); 146 mojo::String::From(legacy_destination_url));
119 } 147 }
120 148
121 void MojoCdmService::OnSessionKeysChange(const std::string& session_id, 149 void MojoCdmService::OnSessionKeysChange(const std::string& session_id,
122 bool has_additional_usable_key, 150 bool has_additional_usable_key,
123 CdmKeysInfo keys_info) { 151 CdmKeysInfo keys_info) {
152 DVLOG(2) << __FUNCTION__;
124 mojo::Array<mojo::CdmKeyInformationPtr> keys_data; 153 mojo::Array<mojo::CdmKeyInformationPtr> keys_data;
125 for (const auto& key : keys_info) 154 for (const auto& key : keys_info)
126 keys_data.push_back(mojo::CdmKeyInformation::From(*key)); 155 keys_data.push_back(mojo::CdmKeyInformation::From(*key));
127 client_->OnSessionKeysChange(session_id, has_additional_usable_key, 156 client_->OnSessionKeysChange(session_id, has_additional_usable_key,
128 keys_data.Pass()); 157 keys_data.Pass());
129 } 158 }
130 159
131 void MojoCdmService::OnSessionExpirationUpdate( 160 void MojoCdmService::OnSessionExpirationUpdate(
132 const std::string& session_id, 161 const std::string& session_id,
133 const base::Time& new_expiry_time_sec) { 162 const base::Time& new_expiry_time_sec) {
163 DVLOG(2) << __FUNCTION__;
134 client_->OnSessionExpirationUpdate(session_id, 164 client_->OnSessionExpirationUpdate(session_id,
135 new_expiry_time_sec.ToDoubleT()); 165 new_expiry_time_sec.ToDoubleT());
136 } 166 }
137 167
138 void MojoCdmService::OnSessionClosed(const std::string& session_id) { 168 void MojoCdmService::OnSessionClosed(const std::string& session_id) {
169 DVLOG(2) << __FUNCTION__;
139 client_->OnSessionClosed(session_id); 170 client_->OnSessionClosed(session_id);
140 } 171 }
141 172
142 void MojoCdmService::OnLegacySessionError(const std::string& session_id, 173 void MojoCdmService::OnLegacySessionError(const std::string& session_id,
143 MediaKeys::Exception exception, 174 MediaKeys::Exception exception,
144 uint32_t system_code, 175 uint32_t system_code,
145 const std::string& error_message) { 176 const std::string& error_message) {
177 DVLOG(2) << __FUNCTION__;
146 client_->OnLegacySessionError(session_id, 178 client_->OnLegacySessionError(session_id,
147 static_cast<mojo::CdmException>(exception), 179 static_cast<mojo::CdmException>(exception),
148 system_code, error_message); 180 system_code, error_message);
149 } 181 }
150 182
151 } // namespace media 183 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_cdm_service.h ('k') | media/mojo/services/mojo_cdm_service_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698