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

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
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 MojoCdmService* MojoCdmService::Create(
24 MojoCdmServiceContext* context,
ddorwin 2015/06/08 18:33:10 Is this a pattern? Otherwise, it should be after c
xhwang 2015/06/08 22:12:33 Done.
25 const mojo::String& key_system,
26 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) {
27 // Only AesDecryptor is supported.
28 // TODO(xhwang): Use a CdmFactory to create the CDM here. See
ddorwin 2015/06/08 18:33:10 Would it be better to create AesDecryptor here now
xhwang 2015/06/08 22:12:33 I need to create the AesDecryptor in MojoCdmServic
29 // http://crbug.com/495273
30 if (!CanUseAesDecryptor(key_system))
31 return nullptr;
32
33 // TODO(xhwang): Pass security origin through.
34 return new MojoCdmService(context, key_system, request.Pass());
35 }
36
22 MojoCdmService::MojoCdmService( 37 MojoCdmService::MojoCdmService(
38 MojoCdmServiceContext* context,
23 const mojo::String& key_system, 39 const mojo::String& key_system,
24 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) 40 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request)
25 : binding_(this, request.Pass()), weak_factory_(this) { 41 : binding_(this, request.Pass()), context_(context), weak_factory_(this) {
42 DVLOG(1) << __FUNCTION__ << ": " << key_system;
43 DCHECK(CanUseAesDecryptor(key_system));
44
26 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); 45 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr();
27 46 cdm_.reset(new AesDecryptor(
28 if (CanUseAesDecryptor(key_system)) { 47 GURL::EmptyGURL(),
29 // TODO(jrummell): Determine proper origin. 48 base::Bind(&MojoCdmService::OnSessionMessage, weak_this),
30 cdm_.reset(new AesDecryptor( 49 base::Bind(&MojoCdmService::OnSessionClosed, weak_this),
31 GURL::EmptyGURL(), 50 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 } 51 }
40 52
41 MojoCdmService::~MojoCdmService() { 53 MojoCdmService::~MojoCdmService() {
42 } 54 }
43 55
44 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { 56 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) {
45 client_ = client.Pass(); 57 client_ = client.Pass();
46 } 58 }
47 59
48 // mojo::MediaRenderer implementation. 60 // mojo::MediaRenderer implementation.
49 void MojoCdmService::SetServerCertificate( 61 void MojoCdmService::SetServerCertificate(
50 mojo::Array<uint8_t> certificate_data, 62 mojo::Array<uint8_t> certificate_data,
51 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 63 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
64 DVLOG(2) << __FUNCTION__;
52 cdm_->SetServerCertificate( 65 cdm_->SetServerCertificate(
53 certificate_data.storage(), 66 certificate_data.storage(),
54 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 67 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
55 } 68 }
56 69
57 void MojoCdmService::CreateSessionAndGenerateRequest( 70 void MojoCdmService::CreateSessionAndGenerateRequest(
58 mojo::ContentDecryptionModule::SessionType session_type, 71 mojo::ContentDecryptionModule::SessionType session_type,
59 mojo::ContentDecryptionModule::InitDataType init_data_type, 72 mojo::ContentDecryptionModule::InitDataType init_data_type,
60 mojo::Array<uint8_t> init_data, 73 mojo::Array<uint8_t> init_data,
61 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& 74 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>&
62 callback) { 75 callback) {
76 DVLOG(2) << __FUNCTION__;
63 cdm_->CreateSessionAndGenerateRequest( 77 cdm_->CreateSessionAndGenerateRequest(
64 static_cast<MediaKeys::SessionType>(session_type), 78 static_cast<MediaKeys::SessionType>(session_type),
65 static_cast<EmeInitDataType>(init_data_type), init_data.storage(), 79 static_cast<EmeInitDataType>(init_data_type), init_data.storage(),
66 scoped_ptr<NewSessionCdmPromise>(new NewSessionMojoCdmPromise(callback))); 80 make_scoped_ptr(new NewSessionMojoCdmPromise(callback)));
67 } 81 }
68 82
69 void MojoCdmService::LoadSession( 83 void MojoCdmService::LoadSession(
70 mojo::ContentDecryptionModule::SessionType session_type, 84 mojo::ContentDecryptionModule::SessionType session_type,
71 const mojo::String& session_id, 85 const mojo::String& session_id,
72 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& 86 const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>&
73 callback) { 87 callback) {
74 cdm_->LoadSession( 88 DVLOG(2) << __FUNCTION__;
75 static_cast<MediaKeys::SessionType>(session_type), 89 cdm_->LoadSession(static_cast<MediaKeys::SessionType>(session_type),
76 session_id.To<std::string>(), 90 session_id.To<std::string>(),
77 scoped_ptr<NewSessionCdmPromise>(new NewSessionMojoCdmPromise(callback))); 91 make_scoped_ptr(new NewSessionMojoCdmPromise(callback)));
78 } 92 }
79 93
80 void MojoCdmService::UpdateSession( 94 void MojoCdmService::UpdateSession(
81 const mojo::String& session_id, 95 const mojo::String& session_id,
82 mojo::Array<uint8_t> response, 96 mojo::Array<uint8_t> response,
83 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 97 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
98 DVLOG(2) << __FUNCTION__;
84 cdm_->UpdateSession( 99 cdm_->UpdateSession(
85 session_id.To<std::string>(), response.storage(), 100 session_id.To<std::string>(), response.storage(),
86 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 101 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback)));
87 } 102 }
88 103
89 void MojoCdmService::CloseSession( 104 void MojoCdmService::CloseSession(
90 const mojo::String& session_id, 105 const mojo::String& session_id,
91 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 106 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
92 cdm_->CloseSession( 107 DVLOG(2) << __FUNCTION__;
93 session_id.To<std::string>(), 108 cdm_->CloseSession(session_id.To<std::string>(),
94 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 109 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
95 } 110 }
96 111
97 void MojoCdmService::RemoveSession( 112 void MojoCdmService::RemoveSession(
98 const mojo::String& session_id, 113 const mojo::String& session_id,
99 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { 114 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) {
100 cdm_->RemoveSession( 115 DVLOG(2) << __FUNCTION__;
101 session_id.To<std::string>(), 116 cdm_->RemoveSession(session_id.To<std::string>(),
102 scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); 117 make_scoped_ptr(new SimpleMojoCdmPromise(callback)));
103 } 118 }
104 119
105 void MojoCdmService::GetCdmContext( 120 void MojoCdmService::GetCdmContext(
106 int32_t cdm_id, 121 int32_t cdm_id,
107 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { 122 mojo::InterfaceRequest<mojo::Decryptor> decryptor) {
108 NOTIMPLEMENTED(); 123 NOTIMPLEMENTED();
109 } 124 }
110 125
126 CdmContext* MojoCdmService::GetCdmContext() {
127 return cdm_->GetCdmContext();
128 }
129
130 void MojoCdmService::OnConnectionError() {
131 DVLOG(1) << __FUNCTION__;
132 context_->ServiceHadConnectionError(this);
133 // The above call deleted this instance, so the only safe thing to do is
134 // return.
135 }
136
111 void MojoCdmService::OnSessionMessage(const std::string& session_id, 137 void MojoCdmService::OnSessionMessage(const std::string& session_id,
112 MediaKeys::MessageType message_type, 138 MediaKeys::MessageType message_type,
113 const std::vector<uint8_t>& message, 139 const std::vector<uint8_t>& message,
114 const GURL& legacy_destination_url) { 140 const GURL& legacy_destination_url) {
141 DVLOG(2) << __FUNCTION__;
115 client_->OnSessionMessage(session_id, 142 client_->OnSessionMessage(session_id,
116 static_cast<mojo::CdmMessageType>(message_type), 143 static_cast<mojo::CdmMessageType>(message_type),
117 mojo::Array<uint8_t>::From(message), 144 mojo::Array<uint8_t>::From(message),
118 mojo::String::From(legacy_destination_url)); 145 mojo::String::From(legacy_destination_url));
119 } 146 }
120 147
121 void MojoCdmService::OnSessionKeysChange(const std::string& session_id, 148 void MojoCdmService::OnSessionKeysChange(const std::string& session_id,
122 bool has_additional_usable_key, 149 bool has_additional_usable_key,
123 CdmKeysInfo keys_info) { 150 CdmKeysInfo keys_info) {
151 DVLOG(2) << __FUNCTION__;
124 mojo::Array<mojo::CdmKeyInformationPtr> keys_data; 152 mojo::Array<mojo::CdmKeyInformationPtr> keys_data;
125 for (const auto& key : keys_info) 153 for (const auto& key : keys_info)
126 keys_data.push_back(mojo::CdmKeyInformation::From(*key)); 154 keys_data.push_back(mojo::CdmKeyInformation::From(*key));
127 client_->OnSessionKeysChange(session_id, has_additional_usable_key, 155 client_->OnSessionKeysChange(session_id, has_additional_usable_key,
128 keys_data.Pass()); 156 keys_data.Pass());
129 } 157 }
130 158
131 void MojoCdmService::OnSessionExpirationUpdate( 159 void MojoCdmService::OnSessionExpirationUpdate(
132 const std::string& session_id, 160 const std::string& session_id,
133 const base::Time& new_expiry_time_sec) { 161 const base::Time& new_expiry_time_sec) {
162 DVLOG(2) << __FUNCTION__;
134 client_->OnSessionExpirationUpdate(session_id, 163 client_->OnSessionExpirationUpdate(session_id,
135 new_expiry_time_sec.ToDoubleT()); 164 new_expiry_time_sec.ToDoubleT());
136 } 165 }
137 166
138 void MojoCdmService::OnSessionClosed(const std::string& session_id) { 167 void MojoCdmService::OnSessionClosed(const std::string& session_id) {
168 DVLOG(2) << __FUNCTION__;
139 client_->OnSessionClosed(session_id); 169 client_->OnSessionClosed(session_id);
140 } 170 }
141 171
142 void MojoCdmService::OnLegacySessionError(const std::string& session_id, 172 void MojoCdmService::OnLegacySessionError(const std::string& session_id,
143 MediaKeys::Exception exception, 173 MediaKeys::Exception exception,
144 uint32_t system_code, 174 uint32_t system_code,
145 const std::string& error_message) { 175 const std::string& error_message) {
176 DVLOG(2) << __FUNCTION__;
146 client_->OnLegacySessionError(session_id, 177 client_->OnLegacySessionError(session_id,
147 static_cast<mojo::CdmException>(exception), 178 static_cast<mojo::CdmException>(exception),
148 system_code, error_message); 179 system_code, error_message);
149 } 180 }
150 181
151 } // namespace media 182 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698