| 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 "media/filters/pipeline_integration_test_base.h" | 5 #include "media/filters/pipeline_integration_test_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "media/base/cdm_promise.h" |
| 12 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
| 13 #include "media/base/media_keys.h" | 14 #include "media/base/media_keys.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 #include "media/base/test_data_util.h" | 16 #include "media/base/test_data_util.h" |
| 16 #include "media/cdm/aes_decryptor.h" | 17 #include "media/cdm/aes_decryptor.h" |
| 17 #include "media/cdm/json_web_key.h" | 18 #include "media/cdm/json_web_key.h" |
| 18 #include "media/filters/chunk_demuxer.h" | 19 #include "media/filters/chunk_demuxer.h" |
| 19 | 20 |
| 20 using testing::_; | 21 using testing::_; |
| 21 using testing::AnyNumber; | 22 using testing::AnyNumber; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. | 109 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. |
| 109 // They do not exercise the Decrypting{Audio|Video}Decoder path. | 110 // They do not exercise the Decrypting{Audio|Video}Decoder path. |
| 110 class FakeEncryptedMedia { | 111 class FakeEncryptedMedia { |
| 111 public: | 112 public: |
| 112 // Defines the behavior of the "app" that responds to EME events. | 113 // Defines the behavior of the "app" that responds to EME events. |
| 113 class AppBase { | 114 class AppBase { |
| 114 public: | 115 public: |
| 115 virtual ~AppBase() {} | 116 virtual ~AppBase() {} |
| 116 | 117 |
| 117 virtual void OnSessionCreated(uint32 session_id, | 118 virtual void OnSessionMessage(const std::string& web_session_id, |
| 118 const std::string& web_session_id) = 0; | |
| 119 | |
| 120 virtual void OnSessionMessage(uint32 session_id, | |
| 121 const std::vector<uint8>& message, | 119 const std::vector<uint8>& message, |
| 122 const std::string& destination_url) = 0; | 120 const std::string& destination_url) = 0; |
| 123 | 121 |
| 124 virtual void OnSessionReady(uint32 session_id) = 0; | 122 virtual void OnSessionReady(const std::string& web_session_id) = 0; |
| 125 | 123 |
| 126 virtual void OnSessionClosed(uint32 session_id) = 0; | 124 virtual void OnSessionClosed(const std::string& web_session_id) = 0; |
| 127 | 125 |
| 128 // Errors are not expected unless overridden. | 126 // Errors are not expected unless overridden. |
| 129 virtual void OnSessionError(uint32 session_id, | 127 virtual void OnSessionError(const std::string& web_session_id, |
| 130 MediaKeys::KeyError error_code, | 128 const std::string& error_name, |
| 131 uint32 system_code) { | 129 uint32 system_code, |
| 130 const std::string& error_message) { |
| 132 FAIL() << "Unexpected Key Error"; | 131 FAIL() << "Unexpected Key Error"; |
| 133 } | 132 } |
| 134 | 133 |
| 135 virtual void NeedKey(const std::string& type, | 134 virtual void NeedKey(const std::string& type, |
| 136 const std::vector<uint8>& init_data, | 135 const std::vector<uint8>& init_data, |
| 137 AesDecryptor* decryptor) = 0; | 136 AesDecryptor* decryptor) = 0; |
| 138 }; | 137 }; |
| 139 | 138 |
| 140 FakeEncryptedMedia(AppBase* app) | 139 FakeEncryptedMedia(AppBase* app) |
| 141 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionCreated, | 140 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, |
| 142 base::Unretained(this)), | |
| 143 base::Bind(&FakeEncryptedMedia::OnSessionMessage, | |
| 144 base::Unretained(this)), | |
| 145 base::Bind(&FakeEncryptedMedia::OnSessionReady, | |
| 146 base::Unretained(this)), | |
| 147 base::Bind(&FakeEncryptedMedia::OnSessionClosed, | |
| 148 base::Unretained(this)), | |
| 149 base::Bind(&FakeEncryptedMedia::OnSessionError, | |
| 150 base::Unretained(this))), | 141 base::Unretained(this))), |
| 151 app_(app) {} | 142 app_(app) {} |
| 152 | 143 |
| 153 AesDecryptor* decryptor() { | 144 AesDecryptor* decryptor() { |
| 154 return &decryptor_; | 145 return &decryptor_; |
| 155 } | 146 } |
| 156 | 147 |
| 157 // Callbacks for firing session events. Delegate to |app_|. | 148 // Callbacks for firing session events. Delegate to |app_|. |
| 158 void OnSessionCreated(uint32 session_id, const std::string& web_session_id) { | 149 void OnSessionMessage(const std::string& web_session_id, |
| 159 app_->OnSessionCreated(session_id, web_session_id); | 150 const std::vector<uint8>& message, |
| 151 const std::string& destination_url) { |
| 152 app_->OnSessionMessage(web_session_id, message, destination_url); |
| 160 } | 153 } |
| 161 | 154 |
| 162 void OnSessionMessage(uint32 session_id, | 155 void OnSessionReady(const std::string& web_session_id) { |
| 163 const std::vector<uint8>& message, | 156 app_->OnSessionReady(web_session_id); |
| 164 const std::string& destination_url) { | |
| 165 app_->OnSessionMessage(session_id, message, destination_url); | |
| 166 } | 157 } |
| 167 | 158 |
| 168 void OnSessionReady(uint32 session_id) { | 159 void OnSessionClosed(const std::string& web_session_id) { |
| 169 app_->OnSessionReady(session_id); | 160 app_->OnSessionClosed(web_session_id); |
| 170 } | 161 } |
| 171 | 162 |
| 172 void OnSessionClosed(uint32 session_id) { | 163 void OnSessionError(const std::string& web_session_id, |
| 173 app_->OnSessionClosed(session_id); | 164 const std::string& error_name, |
| 174 } | 165 uint32 system_code, |
| 175 | 166 const std::string& error_message) { |
| 176 void OnSessionError(uint32 session_id, | 167 app_->OnSessionError( |
| 177 MediaKeys::KeyError error_code, | 168 web_session_id, error_name, system_code, error_message); |
| 178 uint32 system_code) { | |
| 179 app_->OnSessionError(session_id, error_code, system_code); | |
| 180 } | 169 } |
| 181 | 170 |
| 182 void NeedKey(const std::string& type, | 171 void NeedKey(const std::string& type, |
| 183 const std::vector<uint8>& init_data) { | 172 const std::vector<uint8>& init_data) { |
| 184 app_->NeedKey(type, init_data, &decryptor_); | 173 app_->NeedKey(type, init_data, &decryptor_); |
| 185 } | 174 } |
| 186 | 175 |
| 187 private: | 176 private: |
| 188 AesDecryptor decryptor_; | 177 AesDecryptor decryptor_; |
| 189 scoped_ptr<AppBase> app_; | 178 scoped_ptr<AppBase> app_; |
| 190 }; | 179 }; |
| 191 | 180 |
| 181 enum PromiseResult { RESOLVED, REJECTED }; |
| 182 |
| 192 // Provides |kSecretKey| in response to needkey. | 183 // Provides |kSecretKey| in response to needkey. |
| 193 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { | 184 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
| 194 public: | 185 public: |
| 195 KeyProvidingApp() : current_session_id_(0) {} | 186 KeyProvidingApp() {} |
| 196 | 187 |
| 197 virtual void OnSessionCreated(uint32 session_id, | 188 void OnResolveWithSession(PromiseResult expected, |
| 198 const std::string& web_session_id) OVERRIDE { | 189 const std::string& web_session_id) { |
| 199 EXPECT_GT(session_id, 0u); | 190 EXPECT_EQ(expected, RESOLVED); |
| 200 EXPECT_FALSE(web_session_id.empty()); | 191 EXPECT_GT(web_session_id.length(), 0ul); |
| 192 current_session_id_ = web_session_id; |
| 201 } | 193 } |
| 202 | 194 |
| 203 virtual void OnSessionMessage(uint32 session_id, | 195 void OnResolve(PromiseResult expected) { |
| 204 const std::vector<uint8>& message, | 196 EXPECT_EQ(expected, RESOLVED); |
| 205 const std::string& default_url) OVERRIDE { | |
| 206 EXPECT_GT(session_id, 0u); | |
| 207 EXPECT_FALSE(message.empty()); | |
| 208 | |
| 209 current_session_id_ = session_id; | |
| 210 } | 197 } |
| 211 | 198 |
| 212 virtual void OnSessionReady(uint32 session_id) OVERRIDE { | 199 void OnReject(PromiseResult expected, |
| 213 EXPECT_GT(session_id, 0u); | 200 media::MediaKeys::MediaKeysException exception_code, |
| 201 uint32 system_code, |
| 202 const std::string& error_message) { |
| 203 EXPECT_EQ(expected, REJECTED); |
| 214 } | 204 } |
| 215 | 205 |
| 216 virtual void OnSessionClosed(uint32 session_id) OVERRIDE { | 206 scoped_ptr<CdmChangeSessionPromise> CreatePromise(PromiseResult expected) { |
| 217 EXPECT_GT(session_id, 0u); | 207 scoped_ptr<media::CdmChangeSessionPromise> promise( |
| 208 new media::CdmChangeSessionPromise( |
| 209 base::Bind( |
| 210 &KeyProvidingApp::OnResolve, base::Unretained(this), expected), |
| 211 base::Bind( |
| 212 &KeyProvidingApp::OnReject, base::Unretained(this), expected))); |
| 213 return promise.Pass(); |
| 214 } |
| 215 |
| 216 scoped_ptr<CdmNewSessionPromise> CreateSessionPromise( |
| 217 PromiseResult expected) { |
| 218 scoped_ptr<media::CdmNewSessionPromise> promise( |
| 219 new media::CdmNewSessionPromise( |
| 220 base::Bind(&KeyProvidingApp::OnResolveWithSession, |
| 221 base::Unretained(this), |
| 222 expected), |
| 223 base::Bind( |
| 224 &KeyProvidingApp::OnReject, base::Unretained(this), expected))); |
| 225 return promise.Pass(); |
| 226 } |
| 227 |
| 228 virtual void OnSessionMessage(const std::string& web_session_id, |
| 229 const std::vector<uint8>& message, |
| 230 const std::string& destination_url) OVERRIDE { |
| 231 EXPECT_FALSE(web_session_id.empty()); |
| 232 EXPECT_FALSE(message.empty()); |
| 233 EXPECT_EQ(current_session_id_, web_session_id); |
| 234 } |
| 235 |
| 236 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { |
| 237 EXPECT_EQ(current_session_id_, web_session_id); |
| 238 } |
| 239 |
| 240 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 241 EXPECT_EQ(current_session_id_, web_session_id); |
| 218 } | 242 } |
| 219 | 243 |
| 220 virtual void NeedKey(const std::string& type, | 244 virtual void NeedKey(const std::string& type, |
| 221 const std::vector<uint8>& init_data, | 245 const std::vector<uint8>& init_data, |
| 222 AesDecryptor* decryptor) OVERRIDE { | 246 AesDecryptor* decryptor) OVERRIDE { |
| 223 if (current_session_id_ == 0u) { | 247 if (current_session_id_.empty()) { |
| 224 EXPECT_TRUE( | 248 decryptor->CreateSession(type, |
| 225 decryptor->CreateSession(12, type, kInitData, arraysize(kInitData))); | 249 kInitData, |
| 250 arraysize(kInitData), |
| 251 MediaKeys::SESSION_TYPE_TEMPORARY, |
| 252 CreateSessionPromise(RESOLVED)); |
| 253 EXPECT_FALSE(current_session_id_.empty()); |
| 226 } | 254 } |
| 227 | 255 |
| 228 EXPECT_EQ(current_session_id_, 12u); | |
| 229 | |
| 230 // Clear Key really needs the key ID in |init_data|. For WebM, they are the | 256 // Clear Key really needs the key ID in |init_data|. For WebM, they are the |
| 231 // same, but this is not the case for ISO CENC. Therefore, provide the | 257 // same, but this is not the case for ISO CENC. Therefore, provide the |
| 232 // correct key ID. | 258 // correct key ID. |
| 233 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; | 259 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; |
| 234 size_t key_id_length = init_data.size(); | 260 size_t key_id_length = init_data.size(); |
| 235 if (type == kMP4AudioType || type == kMP4VideoType) { | 261 if (type == kMP4AudioType || type == kMP4VideoType) { |
| 236 key_id = kKeyId; | 262 key_id = kKeyId; |
| 237 key_id_length = arraysize(kKeyId); | 263 key_id_length = arraysize(kKeyId); |
| 238 } | 264 } |
| 239 | 265 |
| 240 // Convert key into a JSON structure and then add it. | 266 // Convert key into a JSON structure and then add it. |
| 241 std::string jwk = GenerateJWKSet( | 267 std::string jwk = GenerateJWKSet( |
| 242 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); | 268 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); |
| 243 decryptor->UpdateSession(current_session_id_, | 269 decryptor->UpdateSession(current_session_id_, |
| 244 reinterpret_cast<const uint8*>(jwk.data()), | 270 reinterpret_cast<const uint8*>(jwk.data()), |
| 245 jwk.size()); | 271 jwk.size(), |
| 272 CreatePromise(RESOLVED)); |
| 246 } | 273 } |
| 247 | 274 |
| 248 uint32 current_session_id_; | 275 std::string current_session_id_; |
| 249 }; | 276 }; |
| 250 | 277 |
| 251 class RotatingKeyProvidingApp : public KeyProvidingApp { | 278 class RotatingKeyProvidingApp : public KeyProvidingApp { |
| 252 public: | 279 public: |
| 253 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {} | 280 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {} |
| 254 virtual ~RotatingKeyProvidingApp() { | 281 virtual ~RotatingKeyProvidingApp() { |
| 255 // Expect that NeedKey is fired multiple times with different |init_data|. | 282 // Expect that NeedKey is fired multiple times with different |init_data|. |
| 256 EXPECT_GT(num_distint_need_key_calls_, 1u); | 283 EXPECT_GT(num_distint_need_key_calls_, 1u); |
| 257 } | 284 } |
| 258 | 285 |
| 259 virtual void NeedKey(const std::string& type, | 286 virtual void NeedKey(const std::string& type, |
| 260 const std::vector<uint8>& init_data, | 287 const std::vector<uint8>& init_data, |
| 261 AesDecryptor* decryptor) OVERRIDE { | 288 AesDecryptor* decryptor) OVERRIDE { |
| 262 // Skip the request if the |init_data| has been seen. | 289 // Skip the request if the |init_data| has been seen. |
| 263 if (init_data == prev_init_data_) | 290 if (init_data == prev_init_data_) |
| 264 return; | 291 return; |
| 265 prev_init_data_ = init_data; | 292 prev_init_data_ = init_data; |
| 266 ++num_distint_need_key_calls_; | 293 ++num_distint_need_key_calls_; |
| 267 | 294 |
| 268 EXPECT_TRUE(decryptor->CreateSession(current_session_id_ + 1, | 295 decryptor->CreateSession(type, |
| 269 type, | 296 vector_as_array(&init_data), |
| 270 vector_as_array(&init_data), | 297 init_data.size(), |
| 271 init_data.size())); | 298 MediaKeys::SESSION_TYPE_TEMPORARY, |
| 299 CreateSessionPromise(RESOLVED)); |
| 272 | 300 |
| 273 std::vector<uint8> key_id; | 301 std::vector<uint8> key_id; |
| 274 std::vector<uint8> key; | 302 std::vector<uint8> key; |
| 275 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id)); | 303 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id)); |
| 276 | 304 |
| 277 // Convert key into a JSON structure and then add it. | 305 // Convert key into a JSON structure and then add it. |
| 278 std::string jwk = GenerateJWKSet(vector_as_array(&key), | 306 std::string jwk = GenerateJWKSet(vector_as_array(&key), |
| 279 key.size(), | 307 key.size(), |
| 280 vector_as_array(&key_id), | 308 vector_as_array(&key_id), |
| 281 key_id.size()); | 309 key_id.size()); |
| 282 decryptor->UpdateSession(current_session_id_, | 310 decryptor->UpdateSession(current_session_id_, |
| 283 reinterpret_cast<const uint8*>(jwk.data()), | 311 reinterpret_cast<const uint8*>(jwk.data()), |
| 284 jwk.size()); | 312 jwk.size(), |
| 313 CreatePromise(RESOLVED)); |
| 285 } | 314 } |
| 286 | 315 |
| 287 private: | 316 private: |
| 288 bool GetKeyAndKeyId(std::vector<uint8> init_data, | 317 bool GetKeyAndKeyId(std::vector<uint8> init_data, |
| 289 std::vector<uint8>* key, | 318 std::vector<uint8>* key, |
| 290 std::vector<uint8>* key_id) { | 319 std::vector<uint8>* key_id) { |
| 291 // For WebM, init_data is key_id; for ISO CENC, init_data should contain | 320 // For WebM, init_data is key_id; for ISO CENC, init_data should contain |
| 292 // the key_id. We assume key_id is in the end of init_data here (that is | 321 // the key_id. We assume key_id is in the end of init_data here (that is |
| 293 // only a reasonable assumption for WebM and clear key ISO CENC). | 322 // only a reasonable assumption for WebM and clear key ISO CENC). |
| 294 DCHECK_GE(init_data.size(), arraysize(kKeyId)); | 323 DCHECK_GE(init_data.size(), arraysize(kKeyId)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 314 return false; | 343 return false; |
| 315 } | 344 } |
| 316 | 345 |
| 317 std::vector<uint8> prev_init_data_; | 346 std::vector<uint8> prev_init_data_; |
| 318 uint32 num_distint_need_key_calls_; | 347 uint32 num_distint_need_key_calls_; |
| 319 }; | 348 }; |
| 320 | 349 |
| 321 // Ignores needkey and does not perform a license request | 350 // Ignores needkey and does not perform a license request |
| 322 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 351 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
| 323 public: | 352 public: |
| 324 virtual void OnSessionCreated(uint32 session_id, | 353 virtual void OnSessionMessage(const std::string& web_session_id, |
| 325 const std::string& web_session_id) OVERRIDE { | 354 const std::vector<uint8>& message, |
| 326 EXPECT_GT(session_id, 0u); | 355 const std::string& destination_url) OVERRIDE { |
| 327 EXPECT_FALSE(web_session_id.empty()); | 356 EXPECT_FALSE(web_session_id.empty()); |
| 357 EXPECT_FALSE(message.empty()); |
| 358 FAIL() << "Unexpected Message"; |
| 328 } | 359 } |
| 329 | 360 |
| 330 virtual void OnSessionMessage(uint32 session_id, | 361 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { |
| 331 const std::vector<uint8>& message, | 362 EXPECT_FALSE(web_session_id.empty()); |
| 332 const std::string& default_url) OVERRIDE { | |
| 333 EXPECT_GT(session_id, 0u); | |
| 334 EXPECT_FALSE(message.empty()); | |
| 335 FAIL() << "Unexpected KeyMessage"; | |
| 336 } | |
| 337 | |
| 338 virtual void OnSessionReady(uint32 session_id) OVERRIDE { | |
| 339 EXPECT_GT(session_id, 0u); | |
| 340 FAIL() << "Unexpected Ready"; | 363 FAIL() << "Unexpected Ready"; |
| 341 } | 364 } |
| 342 | 365 |
| 343 virtual void OnSessionClosed(uint32 session_id) OVERRIDE { | 366 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 344 EXPECT_GT(session_id, 0u); | 367 EXPECT_FALSE(web_session_id.empty()); |
| 345 FAIL() << "Unexpected Closed"; | 368 FAIL() << "Unexpected Closed"; |
| 346 } | 369 } |
| 347 | 370 |
| 348 virtual void NeedKey(const std::string& type, | 371 virtual void NeedKey(const std::string& type, |
| 349 const std::vector<uint8>& init_data, | 372 const std::vector<uint8>& init_data, |
| 350 AesDecryptor* decryptor) OVERRIDE { | 373 AesDecryptor* decryptor) OVERRIDE { |
| 351 } | 374 } |
| 352 }; | 375 }; |
| 353 | 376 |
| 354 // Helper class that emulates calls made on the ChunkDemuxer by the | 377 // Helper class that emulates calls made on the ChunkDemuxer by the |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 } | 1468 } |
| 1446 | 1469 |
| 1447 // For MediaSource tests, generate two sets of tests: one using FrameProcessor, | 1470 // For MediaSource tests, generate two sets of tests: one using FrameProcessor, |
| 1448 // and one using LegacyFrameProcessor. | 1471 // and one using LegacyFrameProcessor. |
| 1449 INSTANTIATE_TEST_CASE_P(NewFrameProcessor, PipelineIntegrationTest, | 1472 INSTANTIATE_TEST_CASE_P(NewFrameProcessor, PipelineIntegrationTest, |
| 1450 Values(false)); | 1473 Values(false)); |
| 1451 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest, | 1474 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest, |
| 1452 Values(true)); | 1475 Values(true)); |
| 1453 | 1476 |
| 1454 } // namespace media | 1477 } // namespace media |
| OLD | NEW |