| 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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. | 60 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. |
| 61 // They do not exercise the Decrypting{Audio|Video}Decoder path. | 61 // They do not exercise the Decrypting{Audio|Video}Decoder path. |
| 62 class FakeEncryptedMedia { | 62 class FakeEncryptedMedia { |
| 63 public: | 63 public: |
| 64 // Defines the behavior of the "app" that responds to EME events. | 64 // Defines the behavior of the "app" that responds to EME events. |
| 65 class AppBase { | 65 class AppBase { |
| 66 public: | 66 public: |
| 67 virtual ~AppBase() {} | 67 virtual ~AppBase() {} |
| 68 | 68 |
| 69 virtual void KeyAdded(const std::string& key_system, | 69 virtual void KeyAdded(const std::string& session_id) = 0; |
| 70 const std::string& session_id) = 0; | |
| 71 | 70 |
| 72 // Errors are not expected unless overridden. | 71 // Errors are not expected unless overridden. |
| 73 virtual void KeyError(const std::string& key_system, | 72 virtual void KeyError(const std::string& session_id, |
| 74 const std::string& session_id, | |
| 75 MediaKeys::KeyError error_code, | 73 MediaKeys::KeyError error_code, |
| 76 int system_code) { | 74 int system_code) { |
| 77 FAIL() << "Unexpected Key Error"; | 75 FAIL() << "Unexpected Key Error"; |
| 78 } | 76 } |
| 79 | 77 |
| 80 virtual void KeyMessage(const std::string& key_system, | 78 virtual void KeyMessage(const std::string& session_id, |
| 81 const std::string& session_id, | |
| 82 const std::string& message, | 79 const std::string& message, |
| 83 const std::string& default_url) = 0; | 80 const std::string& default_url) = 0; |
| 84 | 81 |
| 85 virtual void NeedKey(const std::string& key_system, | 82 virtual void NeedKey(const std::string& session_id, |
| 86 const std::string& session_id, | |
| 87 const std::string& type, | 83 const std::string& type, |
| 88 scoped_ptr<uint8[]> init_data, int init_data_length, | 84 scoped_ptr<uint8[]> init_data, int init_data_length, |
| 89 AesDecryptor* decryptor) = 0; | 85 AesDecryptor* decryptor) = 0; |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 FakeEncryptedMedia(AppBase* app) | 88 FakeEncryptedMedia(AppBase* app) |
| 93 : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, | 89 : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, |
| 94 base::Unretained(this)), | 90 base::Unretained(this)), |
| 95 base::Bind(&FakeEncryptedMedia::KeyError, | 91 base::Bind(&FakeEncryptedMedia::KeyError, |
| 96 base::Unretained(this)), | 92 base::Unretained(this)), |
| 97 base::Bind(&FakeEncryptedMedia::KeyMessage, | 93 base::Bind(&FakeEncryptedMedia::KeyMessage, |
| 98 base::Unretained(this)), | 94 base::Unretained(this)), |
| 99 base::Bind(&FakeEncryptedMedia::NeedKey, | 95 base::Bind(&FakeEncryptedMedia::NeedKey, |
| 100 base::Unretained(this))), | 96 base::Unretained(this))), |
| 101 app_(app) { | 97 app_(app) { |
| 102 } | 98 } |
| 103 | 99 |
| 104 AesDecryptor* decryptor() { | 100 AesDecryptor* decryptor() { |
| 105 return &decryptor_; | 101 return &decryptor_; |
| 106 } | 102 } |
| 107 | 103 |
| 108 // Callbacks for firing key events. Delegate to |app_|. | 104 // Callbacks for firing key events. Delegate to |app_|. |
| 109 void KeyAdded(const std::string& key_system, const std::string& session_id) { | 105 void KeyAdded(const std::string& session_id) { |
| 110 app_->KeyAdded(key_system, session_id); | 106 app_->KeyAdded(session_id); |
| 111 } | 107 } |
| 112 | 108 |
| 113 void KeyError(const std::string& key_system, | 109 void KeyError(const std::string& session_id, |
| 114 const std::string& session_id, | |
| 115 MediaKeys::KeyError error_code, | 110 MediaKeys::KeyError error_code, |
| 116 int system_code) { | 111 int system_code) { |
| 117 app_->KeyError(key_system, session_id, error_code, system_code); | 112 app_->KeyError(session_id, error_code, system_code); |
| 118 } | 113 } |
| 119 | 114 |
| 120 void KeyMessage(const std::string& key_system, | 115 void KeyMessage(const std::string& session_id, |
| 121 const std::string& session_id, | |
| 122 const std::string& message, | 116 const std::string& message, |
| 123 const std::string& default_url) { | 117 const std::string& default_url) { |
| 124 app_->KeyMessage(key_system, session_id, message, default_url); | 118 app_->KeyMessage(session_id, message, default_url); |
| 125 } | 119 } |
| 126 | 120 |
| 127 void NeedKey(const std::string& key_system, | 121 void NeedKey(const std::string& session_id, |
| 128 const std::string& session_id, | |
| 129 const std::string& type, | 122 const std::string& type, |
| 130 scoped_ptr<uint8[]> init_data, int init_data_length) { | 123 scoped_ptr<uint8[]> init_data, int init_data_length) { |
| 131 app_->NeedKey(key_system, session_id, type, | 124 app_->NeedKey(session_id, type, init_data.Pass(), init_data_length, |
| 132 init_data.Pass(), init_data_length, &decryptor_); | 125 &decryptor_); |
| 133 } | 126 } |
| 134 | 127 |
| 135 private: | 128 private: |
| 136 AesDecryptor decryptor_; | 129 AesDecryptor decryptor_; |
| 137 scoped_ptr<AppBase> app_; | 130 scoped_ptr<AppBase> app_; |
| 138 }; | 131 }; |
| 139 | 132 |
| 140 // Provides |kSecretKey| in response to needkey. | 133 // Provides |kSecretKey| in response to needkey. |
| 141 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { | 134 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
| 142 public: | 135 public: |
| 143 virtual void KeyAdded(const std::string& key_system, | 136 virtual void KeyAdded(const std::string& session_id) OVERRIDE { |
| 144 const std::string& session_id) OVERRIDE { | |
| 145 EXPECT_EQ(kClearKeySystem, key_system); | |
| 146 EXPECT_FALSE(session_id.empty()); | 137 EXPECT_FALSE(session_id.empty()); |
| 147 } | 138 } |
| 148 | 139 |
| 149 virtual void KeyMessage(const std::string& key_system, | 140 virtual void KeyMessage(const std::string& session_id, |
| 150 const std::string& session_id, | |
| 151 const std::string& message, | 141 const std::string& message, |
| 152 const std::string& default_url) OVERRIDE { | 142 const std::string& default_url) OVERRIDE { |
| 153 EXPECT_EQ(kClearKeySystem, key_system); | |
| 154 EXPECT_FALSE(session_id.empty()); | 143 EXPECT_FALSE(session_id.empty()); |
| 155 EXPECT_FALSE(message.empty()); | 144 EXPECT_FALSE(message.empty()); |
| 156 | 145 |
| 157 current_key_system_ = key_system; | |
| 158 current_session_id_ = session_id; | 146 current_session_id_ = session_id; |
| 159 } | 147 } |
| 160 | 148 |
| 161 virtual void NeedKey(const std::string& key_system, | 149 virtual void NeedKey(const std::string& session_id, |
| 162 const std::string& session_id, | |
| 163 const std::string& type, | 150 const std::string& type, |
| 164 scoped_ptr<uint8[]> init_data, int init_data_length, | 151 scoped_ptr<uint8[]> init_data, int init_data_length, |
| 165 AesDecryptor* decryptor) OVERRIDE { | 152 AesDecryptor* decryptor) OVERRIDE { |
| 166 current_key_system_ = key_system; | |
| 167 current_session_id_ = session_id; | 153 current_session_id_ = session_id; |
| 168 | 154 |
| 169 // When NeedKey is called from the demuxer, the |key_system| will be empty. | 155 if (current_session_id_.empty()) { |
| 170 // In this case, we need to call GenerateKeyRequest() to initialize a | 156 EXPECT_TRUE(decryptor->GenerateKeyRequest(type, kInitData, |
| 171 // session (which will call KeyMessage). | 157 arraysize(kInitData))); |
| 172 if (current_key_system_.empty()) { | |
| 173 EXPECT_TRUE(current_session_id_.empty()); | |
| 174 EXPECT_TRUE(decryptor->GenerateKeyRequest( | |
| 175 kClearKeySystem, type, kInitData, arraysize(kInitData))); | |
| 176 } | 158 } |
| 177 | 159 |
| 178 EXPECT_FALSE(current_key_system_.empty()); | |
| 179 EXPECT_FALSE(current_session_id_.empty()); | 160 EXPECT_FALSE(current_session_id_.empty()); |
| 180 | 161 |
| 181 // Clear Key really needs the key ID in |init_data|. For WebM, they are the | 162 // Clear Key really needs the key ID in |init_data|. For WebM, they are the |
| 182 // same, but this is not the case for ISO CENC. Therefore, provide the | 163 // same, but this is not the case for ISO CENC. Therefore, provide the |
| 183 // correct key ID. | 164 // correct key ID. |
| 184 const uint8* key_id = init_data.get(); | 165 const uint8* key_id = init_data.get(); |
| 185 int key_id_length = init_data_length; | 166 int key_id_length = init_data_length; |
| 186 if (type == kMP4AudioType || type == kMP4VideoType) { | 167 if (type == kMP4AudioType || type == kMP4VideoType) { |
| 187 key_id = kKeyId; | 168 key_id = kKeyId; |
| 188 key_id_length = arraysize(kKeyId); | 169 key_id_length = arraysize(kKeyId); |
| 189 } | 170 } |
| 190 | 171 |
| 191 decryptor->AddKey(current_key_system_, kSecretKey, arraysize(kSecretKey), | 172 decryptor->AddKey(kSecretKey, arraysize(kSecretKey), |
| 192 key_id, key_id_length, current_session_id_); | 173 key_id, key_id_length, current_session_id_); |
| 193 } | 174 } |
| 194 | 175 |
| 195 std::string current_key_system_; | |
| 196 std::string current_session_id_; | 176 std::string current_session_id_; |
| 197 }; | 177 }; |
| 198 | 178 |
| 199 // Ignores needkey and does not perform a license request | 179 // Ignores needkey and does not perform a license request |
| 200 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 180 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
| 201 public: | 181 public: |
| 202 virtual void KeyAdded(const std::string& key_system, | 182 virtual void KeyAdded(const std::string& session_id) OVERRIDE { |
| 203 const std::string& session_id) OVERRIDE { | |
| 204 EXPECT_EQ(kClearKeySystem, key_system); | |
| 205 EXPECT_FALSE(session_id.empty()); | 183 EXPECT_FALSE(session_id.empty()); |
| 206 FAIL() << "Unexpected KeyAdded"; | 184 FAIL() << "Unexpected KeyAdded"; |
| 207 } | 185 } |
| 208 | 186 |
| 209 virtual void KeyMessage(const std::string& key_system, | 187 virtual void KeyMessage(const std::string& session_id, |
| 210 const std::string& session_id, | |
| 211 const std::string& message, | 188 const std::string& message, |
| 212 const std::string& default_url) OVERRIDE { | 189 const std::string& default_url) OVERRIDE { |
| 213 EXPECT_EQ(kClearKeySystem, key_system); | |
| 214 EXPECT_FALSE(session_id.empty()); | 190 EXPECT_FALSE(session_id.empty()); |
| 215 EXPECT_FALSE(message.empty()); | 191 EXPECT_FALSE(message.empty()); |
| 216 FAIL() << "Unexpected KeyMessage"; | 192 FAIL() << "Unexpected KeyMessage"; |
| 217 } | 193 } |
| 218 | 194 |
| 219 virtual void NeedKey(const std::string& key_system, | 195 virtual void NeedKey(const std::string& session_id, |
| 220 const std::string& session_id, | |
| 221 const std::string& type, | 196 const std::string& type, |
| 222 scoped_ptr<uint8[]> init_data, int init_data_length, | 197 scoped_ptr<uint8[]> init_data, int init_data_length, |
| 223 AesDecryptor* decryptor) OVERRIDE { | 198 AesDecryptor* decryptor) OVERRIDE { |
| 224 } | 199 } |
| 225 }; | 200 }; |
| 226 | 201 |
| 227 // Helper class that emulates calls made on the ChunkDemuxer by the | 202 // Helper class that emulates calls made on the ChunkDemuxer by the |
| 228 // Media Source API. | 203 // Media Source API. |
| 229 class MockMediaSource { | 204 class MockMediaSource { |
| 230 public: | 205 public: |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 292 |
| 318 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); | 293 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); |
| 319 AppendData(initial_append_size_); | 294 AppendData(initial_append_size_); |
| 320 } | 295 } |
| 321 | 296 |
| 322 void DemuxerNeedKey(const std::string& type, | 297 void DemuxerNeedKey(const std::string& type, |
| 323 scoped_ptr<uint8[]> init_data, int init_data_size) { | 298 scoped_ptr<uint8[]> init_data, int init_data_size) { |
| 324 DCHECK(init_data.get()); | 299 DCHECK(init_data.get()); |
| 325 DCHECK_GT(init_data_size, 0); | 300 DCHECK_GT(init_data_size, 0); |
| 326 CHECK(!need_key_cb_.is_null()); | 301 CHECK(!need_key_cb_.is_null()); |
| 327 need_key_cb_.Run( | 302 need_key_cb_.Run(std::string(), type, init_data.Pass(), init_data_size); |
| 328 std::string(), std::string(), type, init_data.Pass(), init_data_size); | |
| 329 } | 303 } |
| 330 | 304 |
| 331 scoped_ptr<TextTrack> OnTextTrack(TextKind kind, | 305 scoped_ptr<TextTrack> OnTextTrack(TextKind kind, |
| 332 const std::string& label, | 306 const std::string& label, |
| 333 const std::string& language) { | 307 const std::string& language) { |
| 334 return scoped_ptr<TextTrack>(); | 308 return scoped_ptr<TextTrack>(); |
| 335 } | 309 } |
| 336 | 310 |
| 337 private: | 311 private: |
| 338 base::FilePath file_path_; | 312 base::FilePath file_path_; |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 944 |
| 971 // Verify that VP8 video with inband text track can be played back. | 945 // Verify that VP8 video with inband text track can be played back. |
| 972 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) { | 946 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) { |
| 973 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), | 947 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), |
| 974 PIPELINE_OK)); | 948 PIPELINE_OK)); |
| 975 Play(); | 949 Play(); |
| 976 ASSERT_TRUE(WaitUntilOnEnded()); | 950 ASSERT_TRUE(WaitUntilOnEnded()); |
| 977 } | 951 } |
| 978 | 952 |
| 979 } // namespace media | 953 } // namespace media |
| OLD | NEW |