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

Side by Side Diff: media/cdm/ppapi/external_clear_key/clear_key_cdm.cc

Issue 1428753010: Add unit tests for CdmAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes for bots Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/cdm/ppapi/external_clear_key/clear_key_cdm.h" 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 for (const auto& key_info : keys_info) { 205 for (const auto& key_info : keys_info) {
206 cdm::KeyInformation key; 206 cdm::KeyInformation key;
207 key.key_id = vector_as_array(&key_info->key_id); 207 key.key_id = vector_as_array(&key_info->key_id);
208 key.key_id_size = key_info->key_id.size(); 208 key.key_id_size = key_info->key_id.size();
209 key.status = ConvertKeyStatus(key_info->status); 209 key.status = ConvertKeyStatus(key_info->status);
210 key.system_code = key_info->system_code; 210 key.system_code = key_info->system_code;
211 keys_vector->push_back(key); 211 keys_vector->push_back(key);
212 } 212 }
213 } 213 }
214 214
215 template<typename Type> 215 // If GURL::EmptyGURL() is used then a static object is created, and
216 class ScopedResetter { 216 // never freed. This means the LeakSanitizer will complain that that
217 public: 217 // an object is never freed. Creating our own copy, which also verifies
218 explicit ScopedResetter(Type* object) : object_(object) {} 218 // that DeinitializeCdmModule() is called.
219 ~ScopedResetter() { object_->Reset(); } 219 static GURL* empty_gurl;
220
221 private:
222 Type* const object_;
223 };
224 220
225 void INITIALIZE_CDM_MODULE() { 221 void INITIALIZE_CDM_MODULE() {
222 DVLOG(1) << __FUNCTION__;
223 DCHECK(!empty_gurl) << "Only call INITIALIZE_CDM_MODULE() once.";
224
225 empty_gurl = new GURL();
226 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) 226 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER)
227 av_register_all(); 227 av_register_all();
228 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER 228 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER
229 } 229 }
230 230
231 void DeinitializeCdmModule() { 231 void DeinitializeCdmModule() {
232 DVLOG(1) << __FUNCTION__;
233 delete empty_gurl;
232 } 234 }
233 235
234 void* CreateCdmInstance(int cdm_interface_version, 236 void* CreateCdmInstance(int cdm_interface_version,
235 const char* key_system, uint32_t key_system_size, 237 const char* key_system, uint32_t key_system_size,
236 GetCdmHostFunc get_cdm_host_func, 238 GetCdmHostFunc get_cdm_host_func,
237 void* user_data) { 239 void* user_data) {
238 DVLOG(1) << "CreateCdmInstance()"; 240 DVLOG(1) << "CreateCdmInstance()";
239 241
240 std::string key_system_string(key_system, key_system_size); 242 std::string key_system_string(key_system, key_system_size);
241 if (key_system_string != kExternalClearKeyKeySystem && 243 if (key_system_string != kExternalClearKeyKeySystem &&
242 key_system_string != kExternalClearKeyDecryptOnlyKeySystem && 244 key_system_string != kExternalClearKeyDecryptOnlyKeySystem &&
243 key_system_string != kExternalClearKeyFileIOTestKeySystem && 245 key_system_string != kExternalClearKeyFileIOTestKeySystem &&
244 key_system_string != kExternalClearKeyCrashKeySystem) { 246 key_system_string != kExternalClearKeyCrashKeySystem) {
245 DVLOG(1) << "Unsupported key system:" << key_system_string; 247 DVLOG(1) << "Unsupported key system:" << key_system_string;
246 return NULL; 248 return NULL;
247 } 249 }
248 250
249 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) 251 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion)
250 return NULL; 252 return NULL;
251 253
252 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>( 254 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>(
253 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data)); 255 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data));
254 if (!host) 256 if (!host)
255 return NULL; 257 return NULL;
256 258
257 // TODO(jrummell): Obtain the proper origin for this instance. 259 // TODO(jrummell): Obtain the proper origin for this instance.
258 return new media::ClearKeyCdm(host, key_system_string, GURL::EmptyGURL()); 260 return new media::ClearKeyCdm(host, key_system_string, *empty_gurl);
xhwang 2015/11/13 00:03:22 Can we just create a temp local GURL here instead
jrummell 2015/11/13 00:35:20 Done.
259 } 261 }
260 262
261 const char* GetCdmVersion() { 263 const char* GetCdmVersion() {
262 return kClearKeyCdmVersion; 264 return kClearKeyCdmVersion;
263 } 265 }
264 266
265 namespace media { 267 namespace media {
266 268
267 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, 269 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host,
268 const std::string& key_system, 270 const std::string& key_system,
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 void ClearKeyCdm::OnFileIOTestComplete(bool success) { 911 void ClearKeyCdm::OnFileIOTestComplete(bool success) {
910 DVLOG(1) << __FUNCTION__ << ": " << success; 912 DVLOG(1) << __FUNCTION__ << ": " << success;
911 std::string message = GetFileIOTestResultMessage(success); 913 std::string message = GetFileIOTestResultMessage(success);
912 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), 914 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(),
913 cdm::kLicenseRequest, message.data(), 915 cdm::kLicenseRequest, message.data(),
914 message.length(), NULL, 0); 916 message.length(), NULL, 0);
915 file_io_test_runner_.reset(); 917 file_io_test_runner_.reset();
916 } 918 }
917 919
918 } // namespace media 920 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698