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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 int system_code) { | 79 int system_code) { |
80 FAIL() << "Unexpected Key Error"; | 80 FAIL() << "Unexpected Key Error"; |
81 } | 81 } |
82 | 82 |
83 virtual void KeyMessage(const std::string& session_id, | 83 virtual void KeyMessage(const std::string& session_id, |
84 const std::vector<uint8>& message, | 84 const std::vector<uint8>& message, |
85 const std::string& default_url) = 0; | 85 const std::string& default_url) = 0; |
86 | 86 |
87 virtual void NeedKey(const std::string& session_id, | 87 virtual void NeedKey(const std::string& session_id, |
88 const std::string& type, | 88 const std::string& type, |
89 scoped_ptr<uint8[]> init_data, int init_data_length, | 89 const std::vector<uint8>& init_data, |
90 AesDecryptor* decryptor) = 0; | 90 AesDecryptor* decryptor) = 0; |
91 }; | 91 }; |
92 | 92 |
93 FakeEncryptedMedia(AppBase* app) | 93 FakeEncryptedMedia(AppBase* app) |
94 : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, | 94 : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, |
95 base::Unretained(this)), | 95 base::Unretained(this)), |
96 base::Bind(&FakeEncryptedMedia::KeyError, | 96 base::Bind(&FakeEncryptedMedia::KeyError, |
97 base::Unretained(this)), | 97 base::Unretained(this)), |
98 base::Bind(&FakeEncryptedMedia::KeyMessage, | 98 base::Bind(&FakeEncryptedMedia::KeyMessage, |
99 base::Unretained(this))), | 99 base::Unretained(this))), |
(...skipping 16 matching lines...) Expand all Loading... |
116 } | 116 } |
117 | 117 |
118 void KeyMessage(const std::string& session_id, | 118 void KeyMessage(const std::string& session_id, |
119 const std::vector<uint8>& message, | 119 const std::vector<uint8>& message, |
120 const std::string& default_url) { | 120 const std::string& default_url) { |
121 app_->KeyMessage(session_id, message, default_url); | 121 app_->KeyMessage(session_id, message, default_url); |
122 } | 122 } |
123 | 123 |
124 void NeedKey(const std::string& session_id, | 124 void NeedKey(const std::string& session_id, |
125 const std::string& type, | 125 const std::string& type, |
126 scoped_ptr<uint8[]> init_data, int init_data_length) { | 126 const std::vector<uint8>& init_data) { |
127 app_->NeedKey(session_id, type, init_data.Pass(), init_data_length, | 127 app_->NeedKey(session_id, type, init_data, &decryptor_); |
128 &decryptor_); | |
129 } | 128 } |
130 | 129 |
131 private: | 130 private: |
132 AesDecryptor decryptor_; | 131 AesDecryptor decryptor_; |
133 scoped_ptr<AppBase> app_; | 132 scoped_ptr<AppBase> app_; |
134 }; | 133 }; |
135 | 134 |
136 // Provides |kSecretKey| in response to needkey. | 135 // Provides |kSecretKey| in response to needkey. |
137 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { | 136 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
138 public: | 137 public: |
139 virtual void KeyAdded(const std::string& session_id) OVERRIDE { | 138 virtual void KeyAdded(const std::string& session_id) OVERRIDE { |
140 EXPECT_FALSE(session_id.empty()); | 139 EXPECT_FALSE(session_id.empty()); |
141 } | 140 } |
142 | 141 |
143 virtual void KeyMessage(const std::string& session_id, | 142 virtual void KeyMessage(const std::string& session_id, |
144 const std::vector<uint8>& message, | 143 const std::vector<uint8>& message, |
145 const std::string& default_url) OVERRIDE { | 144 const std::string& default_url) OVERRIDE { |
146 EXPECT_FALSE(session_id.empty()); | 145 EXPECT_FALSE(session_id.empty()); |
147 EXPECT_FALSE(message.empty()); | 146 EXPECT_FALSE(message.empty()); |
148 | 147 |
149 current_session_id_ = session_id; | 148 current_session_id_ = session_id; |
150 } | 149 } |
151 | 150 |
152 virtual void NeedKey(const std::string& session_id, | 151 virtual void NeedKey(const std::string& session_id, |
153 const std::string& type, | 152 const std::string& type, |
154 scoped_ptr<uint8[]> init_data, int init_data_length, | 153 const std::vector<uint8>& init_data, |
155 AesDecryptor* decryptor) OVERRIDE { | 154 AesDecryptor* decryptor) OVERRIDE { |
156 current_session_id_ = session_id; | 155 current_session_id_ = session_id; |
157 | 156 |
158 if (current_session_id_.empty()) { | 157 if (current_session_id_.empty()) { |
159 EXPECT_TRUE(decryptor->GenerateKeyRequest(type, kInitData, | 158 EXPECT_TRUE(decryptor->GenerateKeyRequest(type, kInitData, |
160 arraysize(kInitData))); | 159 arraysize(kInitData))); |
161 } | 160 } |
162 | 161 |
163 EXPECT_FALSE(current_session_id_.empty()); | 162 EXPECT_FALSE(current_session_id_.empty()); |
164 | 163 |
165 // Clear Key really needs the key ID in |init_data|. For WebM, they are the | 164 // Clear Key really needs the key ID in |init_data|. For WebM, they are the |
166 // same, but this is not the case for ISO CENC. Therefore, provide the | 165 // same, but this is not the case for ISO CENC. Therefore, provide the |
167 // correct key ID. | 166 // correct key ID. |
168 const uint8* key_id = init_data.get(); | 167 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; |
169 int key_id_length = init_data_length; | 168 size_t key_id_length = init_data.size(); |
170 if (type == kMP4AudioType || type == kMP4VideoType) { | 169 if (type == kMP4AudioType || type == kMP4VideoType) { |
171 key_id = kKeyId; | 170 key_id = kKeyId; |
172 key_id_length = arraysize(kKeyId); | 171 key_id_length = arraysize(kKeyId); |
173 } | 172 } |
174 | 173 |
175 decryptor->AddKey(kSecretKey, arraysize(kSecretKey), | 174 decryptor->AddKey(kSecretKey, arraysize(kSecretKey), |
176 key_id, key_id_length, current_session_id_); | 175 key_id, key_id_length, current_session_id_); |
177 } | 176 } |
178 | 177 |
179 std::string current_session_id_; | 178 std::string current_session_id_; |
(...skipping 10 matching lines...) Expand all Loading... |
190 virtual void KeyMessage(const std::string& session_id, | 189 virtual void KeyMessage(const std::string& session_id, |
191 const std::vector<uint8>& message, | 190 const std::vector<uint8>& message, |
192 const std::string& default_url) OVERRIDE { | 191 const std::string& default_url) OVERRIDE { |
193 EXPECT_FALSE(session_id.empty()); | 192 EXPECT_FALSE(session_id.empty()); |
194 EXPECT_FALSE(message.empty()); | 193 EXPECT_FALSE(message.empty()); |
195 FAIL() << "Unexpected KeyMessage"; | 194 FAIL() << "Unexpected KeyMessage"; |
196 } | 195 } |
197 | 196 |
198 virtual void NeedKey(const std::string& session_id, | 197 virtual void NeedKey(const std::string& session_id, |
199 const std::string& type, | 198 const std::string& type, |
200 scoped_ptr<uint8[]> init_data, int init_data_length, | 199 const std::vector<uint8>& init_data, |
201 AesDecryptor* decryptor) OVERRIDE { | 200 AesDecryptor* decryptor) OVERRIDE { |
202 } | 201 } |
203 }; | 202 }; |
204 | 203 |
205 // Helper class that emulates calls made on the ChunkDemuxer by the | 204 // Helper class that emulates calls made on the ChunkDemuxer by the |
206 // Media Source API. | 205 // Media Source API. |
207 class MockMediaSource { | 206 class MockMediaSource { |
208 public: | 207 public: |
209 MockMediaSource(const std::string& filename, const std::string& mimetype, | 208 MockMediaSource(const std::string& filename, const std::string& mimetype, |
210 int initial_append_size) | 209 int initial_append_size) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 size_t quote2 = mimetype_.find("\"", quote1 + 1); | 290 size_t quote2 = mimetype_.find("\"", quote1 + 1); |
292 std::string codecStr = mimetype_.substr(quote1 + 1, quote2 - quote1 - 1); | 291 std::string codecStr = mimetype_.substr(quote1 + 1, quote2 - quote1 - 1); |
293 std::vector<std::string> codecs; | 292 std::vector<std::string> codecs; |
294 Tokenize(codecStr, ",", &codecs); | 293 Tokenize(codecStr, ",", &codecs); |
295 | 294 |
296 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); | 295 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); |
297 AppendData(initial_append_size_); | 296 AppendData(initial_append_size_); |
298 } | 297 } |
299 | 298 |
300 void DemuxerNeedKey(const std::string& type, | 299 void DemuxerNeedKey(const std::string& type, |
301 scoped_ptr<uint8[]> init_data, int init_data_size) { | 300 const std::vector<uint8>& init_data) { |
302 DCHECK(init_data.get()); | 301 DCHECK(!init_data.empty()); |
303 DCHECK_GT(init_data_size, 0); | |
304 CHECK(!need_key_cb_.is_null()); | 302 CHECK(!need_key_cb_.is_null()); |
305 need_key_cb_.Run(std::string(), type, init_data.Pass(), init_data_size); | 303 need_key_cb_.Run(std::string(), type, init_data); |
306 } | 304 } |
307 | 305 |
308 scoped_ptr<TextTrack> OnTextTrack(TextKind kind, | 306 scoped_ptr<TextTrack> OnTextTrack(TextKind kind, |
309 const std::string& label, | 307 const std::string& label, |
310 const std::string& language) { | 308 const std::string& language) { |
311 return scoped_ptr<TextTrack>(); | 309 return scoped_ptr<TextTrack>(); |
312 } | 310 } |
313 | 311 |
314 private: | 312 private: |
315 base::FilePath file_path_; | 313 base::FilePath file_path_; |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 973 |
976 // Verify that VP8 video with inband text track can be played back. | 974 // Verify that VP8 video with inband text track can be played back. |
977 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) { | 975 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) { |
978 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), | 976 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp8-webvtt.webm"), |
979 PIPELINE_OK)); | 977 PIPELINE_OK)); |
980 Play(); | 978 Play(); |
981 ASSERT_TRUE(WaitUntilOnEnded()); | 979 ASSERT_TRUE(WaitUntilOnEnded()); |
982 } | 980 } |
983 | 981 |
984 } // namespace media | 982 } // namespace media |
OLD | NEW |