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" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 73 |
74 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. | 74 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. |
75 // They do not exercise the Decrypting{Audio|Video}Decoder path. | 75 // They do not exercise the Decrypting{Audio|Video}Decoder path. |
76 class FakeEncryptedMedia { | 76 class FakeEncryptedMedia { |
77 public: | 77 public: |
78 // Defines the behavior of the "app" that responds to EME events. | 78 // Defines the behavior of the "app" that responds to EME events. |
79 class AppBase { | 79 class AppBase { |
80 public: | 80 public: |
81 virtual ~AppBase() {} | 81 virtual ~AppBase() {} |
82 | 82 |
83 virtual void SetSession(uint32 reference_id, | 83 virtual void SetSession(uint32 session_id, |
ddorwin
2013/12/05 00:44:52
Should we rename these? At least to On..., right?
jrummell
2013/12/06 23:42:35
Updated to match full names.
| |
84 const std::string& session_id) = 0; | 84 const std::string& web_session_id) = 0; |
85 | 85 |
86 virtual void Message(uint32 reference_id, | 86 virtual void Message(uint32 session_id, |
87 const std::vector<uint8>& message, | 87 const std::vector<uint8>& message, |
88 const std::string& destination_url) = 0; | 88 const std::string& destination_url) = 0; |
89 | 89 |
90 virtual void Ready(uint32 reference_id) = 0; | 90 virtual void Ready(uint32 session_id) = 0; |
91 | 91 |
92 virtual void Closed(uint32 reference_id) = 0; | 92 virtual void Closed(uint32 session_id) = 0; |
93 | 93 |
94 // Errors are not expected unless overridden. | 94 // Errors are not expected unless overridden. |
95 virtual void Error(uint32 reference_id, | 95 virtual void Error(uint32 session_id, |
96 MediaKeys::KeyError error_code, | 96 MediaKeys::KeyError error_code, |
97 int system_code) { | 97 int system_code) { |
98 FAIL() << "Unexpected Key Error"; | 98 FAIL() << "Unexpected Key Error"; |
99 } | 99 } |
100 | 100 |
101 virtual void NeedKey(const std::string& type, | 101 virtual void NeedKey(const std::string& type, |
102 const std::vector<uint8>& init_data, | 102 const std::vector<uint8>& init_data, |
103 AesDecryptor* decryptor) = 0; | 103 AesDecryptor* decryptor) = 0; |
104 }; | 104 }; |
105 | 105 |
106 FakeEncryptedMedia(AppBase* app) | 106 FakeEncryptedMedia(AppBase* app) |
107 : decryptor_( | 107 : decryptor_( |
108 base::Bind(&FakeEncryptedMedia::SetSession, base::Unretained(this)), | 108 base::Bind(&FakeEncryptedMedia::SetSession, base::Unretained(this)), |
109 base::Bind(&FakeEncryptedMedia::Message, base::Unretained(this)), | 109 base::Bind(&FakeEncryptedMedia::Message, base::Unretained(this)), |
110 base::Bind(&FakeEncryptedMedia::Ready, base::Unretained(this)), | 110 base::Bind(&FakeEncryptedMedia::Ready, base::Unretained(this)), |
111 base::Bind(&FakeEncryptedMedia::Closed, base::Unretained(this)), | 111 base::Bind(&FakeEncryptedMedia::Closed, base::Unretained(this)), |
112 base::Bind(&FakeEncryptedMedia::Error, base::Unretained(this))), | 112 base::Bind(&FakeEncryptedMedia::Error, base::Unretained(this))), |
113 app_(app) { | 113 app_(app) { |
114 } | 114 } |
115 | 115 |
116 AesDecryptor* decryptor() { | 116 AesDecryptor* decryptor() { |
117 return &decryptor_; | 117 return &decryptor_; |
118 } | 118 } |
119 | 119 |
120 // Callbacks for firing session events. Delegate to |app_|. | 120 // Callbacks for firing session events. Delegate to |app_|. |
121 void SetSession(uint32 reference_id, const std::string& session_id) { | 121 void SetSession(uint32 session_id, const std::string& web_session_id) { |
122 app_->SetSession(reference_id, session_id); | 122 app_->SetSession(session_id, web_session_id); |
123 } | 123 } |
124 | 124 |
125 void Message(uint32 reference_id, | 125 void Message(uint32 session_id, |
126 const std::vector<uint8>& message, | 126 const std::vector<uint8>& message, |
127 const std::string& destination_url) { | 127 const std::string& destination_url) { |
128 app_->Message(reference_id, message, destination_url); | 128 app_->Message(session_id, message, destination_url); |
129 } | 129 } |
130 | 130 |
131 void Ready(uint32 reference_id) { | 131 void Ready(uint32 session_id) { |
132 app_->Ready(reference_id); | 132 app_->Ready(session_id); |
133 } | 133 } |
134 | 134 |
135 void Closed(uint32 reference_id) { | 135 void Closed(uint32 session_id) { |
136 app_->Closed(reference_id); | 136 app_->Closed(session_id); |
137 } | 137 } |
138 | 138 |
139 void Error(uint32 reference_id, | 139 void Error(uint32 session_id, |
140 MediaKeys::KeyError error_code, | 140 MediaKeys::KeyError error_code, |
141 int system_code) { | 141 int system_code) { |
142 app_->Error(reference_id, error_code, system_code); | 142 app_->Error(session_id, error_code, system_code); |
143 } | 143 } |
144 | 144 |
145 void NeedKey(const std::string& type, | 145 void NeedKey(const std::string& type, |
146 const std::vector<uint8>& init_data) { | 146 const std::vector<uint8>& init_data) { |
147 app_->NeedKey(type, init_data, &decryptor_); | 147 app_->NeedKey(type, init_data, &decryptor_); |
148 } | 148 } |
149 | 149 |
150 private: | 150 private: |
151 AesDecryptor decryptor_; | 151 AesDecryptor decryptor_; |
152 scoped_ptr<AppBase> app_; | 152 scoped_ptr<AppBase> app_; |
153 }; | 153 }; |
154 | 154 |
155 // Provides |kSecretKey| in response to needkey. | 155 // Provides |kSecretKey| in response to needkey. |
156 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { | 156 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
157 public: | 157 public: |
158 KeyProvidingApp() : current_reference_id_(0) {} | 158 KeyProvidingApp() : current_session_id_(0) {} |
159 | 159 |
160 virtual void SetSession(uint32 reference_id, | 160 virtual void SetSession(uint32 session_id, |
161 const std::string& session_id) OVERRIDE { | 161 const std::string& web_session_id) OVERRIDE { |
162 EXPECT_GT(reference_id, 0u); | 162 EXPECT_GT(session_id, 0u); |
163 EXPECT_FALSE(session_id.empty()); | 163 EXPECT_FALSE(web_session_id.empty()); |
164 } | 164 } |
165 | 165 |
166 virtual void Message(uint32 reference_id, | 166 virtual void Message(uint32 session_id, |
167 const std::vector<uint8>& message, | 167 const std::vector<uint8>& message, |
168 const std::string& default_url) OVERRIDE { | 168 const std::string& default_url) OVERRIDE { |
169 EXPECT_GT(reference_id, 0u); | 169 EXPECT_GT(session_id, 0u); |
170 EXPECT_FALSE(message.empty()); | 170 EXPECT_FALSE(message.empty()); |
171 | 171 |
172 current_reference_id_ = reference_id; | 172 current_session_id_ = session_id; |
173 } | 173 } |
174 | 174 |
175 virtual void Ready(uint32 reference_id) OVERRIDE { | 175 virtual void Ready(uint32 session_id) OVERRIDE { |
176 EXPECT_GT(reference_id, 0u); | 176 EXPECT_GT(session_id, 0u); |
177 } | 177 } |
178 | 178 |
179 virtual void Closed(uint32 reference_id) OVERRIDE { | 179 virtual void Closed(uint32 session_id) OVERRIDE { |
180 EXPECT_GT(reference_id, 0u); | 180 EXPECT_GT(session_id, 0u); |
181 } | 181 } |
182 | 182 |
183 virtual void NeedKey(const std::string& type, | 183 virtual void NeedKey(const std::string& type, |
184 const std::vector<uint8>& init_data, | 184 const std::vector<uint8>& init_data, |
185 AesDecryptor* decryptor) OVERRIDE { | 185 AesDecryptor* decryptor) OVERRIDE { |
186 if (current_reference_id_ == 0u) { | 186 if (current_session_id_ == 0u) { |
187 EXPECT_TRUE( | 187 EXPECT_TRUE( |
188 decryptor->CreateSession(12, type, kInitData, arraysize(kInitData))); | 188 decryptor->CreateSession(12, type, kInitData, arraysize(kInitData))); |
189 } | 189 } |
190 | 190 |
191 EXPECT_EQ(current_reference_id_, 12u); | 191 EXPECT_EQ(current_session_id_, 12u); |
192 | 192 |
193 // Clear Key really needs the key ID in |init_data|. For WebM, they are the | 193 // Clear Key really needs the key ID in |init_data|. For WebM, they are the |
194 // same, but this is not the case for ISO CENC. Therefore, provide the | 194 // same, but this is not the case for ISO CENC. Therefore, provide the |
195 // correct key ID. | 195 // correct key ID. |
196 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; | 196 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; |
197 size_t key_id_length = init_data.size(); | 197 size_t key_id_length = init_data.size(); |
198 if (type == kMP4AudioType || type == kMP4VideoType) { | 198 if (type == kMP4AudioType || type == kMP4VideoType) { |
199 key_id = kKeyId; | 199 key_id = kKeyId; |
200 key_id_length = arraysize(kKeyId); | 200 key_id_length = arraysize(kKeyId); |
201 } | 201 } |
202 | 202 |
203 // Convert key into a JSON structure and then add it. | 203 // Convert key into a JSON structure and then add it. |
204 std::string jwk = GenerateJWKSet( | 204 std::string jwk = GenerateJWKSet( |
205 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); | 205 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); |
206 decryptor->UpdateSession(current_reference_id_, | 206 decryptor->UpdateSession(current_session_id_, |
207 reinterpret_cast<const uint8*>(jwk.data()), | 207 reinterpret_cast<const uint8*>(jwk.data()), |
208 jwk.size()); | 208 jwk.size()); |
209 } | 209 } |
210 | 210 |
211 uint32 current_reference_id_; | 211 uint32 current_session_id_; |
212 }; | 212 }; |
213 | 213 |
214 // Ignores needkey and does not perform a license request | 214 // Ignores needkey and does not perform a license request |
215 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 215 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
216 public: | 216 public: |
217 virtual void SetSession(uint32 reference_id, | 217 virtual void SetSession(uint32 session_id, |
218 const std::string& session_id) OVERRIDE { | 218 const std::string& web_session_id) OVERRIDE { |
219 EXPECT_GT(reference_id, 0u); | 219 EXPECT_GT(session_id, 0u); |
220 EXPECT_FALSE(session_id.empty()); | 220 EXPECT_FALSE(web_session_id.empty()); |
221 } | 221 } |
222 | 222 |
223 virtual void Message(uint32 reference_id, | 223 virtual void Message(uint32 session_id, |
224 const std::vector<uint8>& message, | 224 const std::vector<uint8>& message, |
225 const std::string& default_url) OVERRIDE { | 225 const std::string& default_url) OVERRIDE { |
226 EXPECT_GT(reference_id, 0u); | 226 EXPECT_GT(session_id, 0u); |
227 EXPECT_FALSE(message.empty()); | 227 EXPECT_FALSE(message.empty()); |
228 FAIL() << "Unexpected KeyMessage"; | 228 FAIL() << "Unexpected KeyMessage"; |
229 } | 229 } |
230 | 230 |
231 virtual void Ready(uint32 reference_id) OVERRIDE { | 231 virtual void Ready(uint32 session_id) OVERRIDE { |
232 EXPECT_GT(reference_id, 0u); | 232 EXPECT_GT(session_id, 0u); |
233 FAIL() << "Unexpected Ready"; | 233 FAIL() << "Unexpected Ready"; |
234 } | 234 } |
235 | 235 |
236 virtual void Closed(uint32 reference_id) OVERRIDE { | 236 virtual void Closed(uint32 session_id) OVERRIDE { |
237 EXPECT_GT(reference_id, 0u); | 237 EXPECT_GT(session_id, 0u); |
238 FAIL() << "Unexpected Closed"; | 238 FAIL() << "Unexpected Closed"; |
239 } | 239 } |
240 | 240 |
241 virtual void NeedKey(const std::string& type, | 241 virtual void NeedKey(const std::string& type, |
242 const std::vector<uint8>& init_data, | 242 const std::vector<uint8>& init_data, |
243 AesDecryptor* decryptor) OVERRIDE { | 243 AesDecryptor* decryptor) OVERRIDE { |
244 } | 244 } |
245 }; | 245 }; |
246 | 246 |
247 // Helper class that emulates calls made on the ChunkDemuxer by the | 247 // Helper class that emulates calls made on the ChunkDemuxer by the |
248 // Media Source API. | 248 // Media Source API. |
249 class MockMediaSource { | 249 class MockMediaSource { |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 // Verify that VP8 video with inband text track can be played back. | 1100 // Verify that VP8 video with inband text track can be played back. |
1101 TEST_F(PipelineIntegrationTest, | 1101 TEST_F(PipelineIntegrationTest, |
1102 BasicPlayback_VP8_WebVTT_WebM) { | 1102 BasicPlayback_VP8_WebVTT_WebM) { |
1103 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), | 1103 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), |
1104 PIPELINE_OK)); | 1104 PIPELINE_OK)); |
1105 Play(); | 1105 Play(); |
1106 ASSERT_TRUE(WaitUntilOnEnded()); | 1106 ASSERT_TRUE(WaitUntilOnEnded()); |
1107 } | 1107 } |
1108 | 1108 |
1109 } // namespace media | 1109 } // namespace media |
OLD | NEW |