Roll src/third_party/WebKit 37b70da:e3be828 (svn 200645:200646)
[chromium-blink-merge.git] / media / test / pipeline_integration_test.cc
blob36ece631a476a5da4eaec0e74261e00a39cb907c
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "build/build_config.h"
12 #include "media/base/cdm_callback_promise.h"
13 #include "media/base/cdm_context.h"
14 #include "media/base/cdm_key_information.h"
15 #include "media/base/decoder_buffer.h"
16 #include "media/base/media.h"
17 #include "media/base/media_keys.h"
18 #include "media/base/media_switches.h"
19 #include "media/base/test_data_util.h"
20 #include "media/cdm/aes_decryptor.h"
21 #include "media/cdm/json_web_key.h"
22 #include "media/filters/chunk_demuxer.h"
23 #include "media/renderers/renderer_impl.h"
24 #include "media/test/pipeline_integration_test_base.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "url/gurl.h"
28 #if defined(MOJO_RENDERER)
29 #include "media/mojo/interfaces/renderer.mojom.h"
30 #include "media/mojo/interfaces/service_factory.mojom.h"
31 #include "media/mojo/services/mojo_renderer_impl.h"
32 #include "mojo/application/public/cpp/application_impl.h"
33 #include "mojo/application/public/cpp/application_test_base.h"
34 #include "mojo/application/public/cpp/connect.h"
36 // TODO(dalecurtis): The mojo renderer is in another process, so we have no way
37 // currently to get hashes for video and audio samples. This also means that
38 // real audio plays out for each test.
39 #define EXPECT_HASH_EQ(a, b)
40 #define EXPECT_VIDEO_FORMAT_EQ(a, b)
41 #define EXPECT_COLOR_SPACE_EQ(a, b)
43 // TODO(xhwang): EME support is not complete for the mojo renderer, so all
44 // encrypted tests are currently disabled.
45 #define DISABLE_EME_TESTS 1
47 // TODO(xhwang,dalecurtis): Text tracks are not currently supported by the mojo
48 // renderer.
49 #define DISABLE_TEXT_TRACK_TESTS 1
50 #else
51 #define EXPECT_HASH_EQ(a, b) EXPECT_EQ(a, b)
52 #define EXPECT_VIDEO_FORMAT_EQ(a, b) EXPECT_EQ(a, b)
53 #define EXPECT_COLOR_SPACE_EQ(a, b) EXPECT_EQ(a, b)
54 #endif
56 using testing::_;
57 using testing::AnyNumber;
58 using testing::AtLeast;
59 using testing::AtMost;
60 using testing::SaveArg;
62 namespace media {
64 const char kSourceId[] = "SourceId";
66 const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\"";
67 const char kWebMVP9[] = "video/webm; codecs=\"vp9\"";
68 const char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\"";
69 const char kOpusAudioOnlyWebM[] = "video/webm; codecs=\"opus\"";
70 const char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\"";
71 #if defined(USE_PROPRIETARY_CODECS)
72 const char kADTS[] = "audio/aac";
73 const char kMP4[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\"";
74 const char kMP4VideoAVC3[] = "video/mp4; codecs=\"avc3.64001f\"";
75 #if !defined(DISABLE_EME_TESTS)
76 const char kMP4Video[] = "video/mp4; codecs=\"avc1.4D4041\"";
77 const char kMP4Audio[] = "audio/mp4; codecs=\"mp4a.40.2\"";
78 #endif // !defined(DISABLE_EME_TESTS)
79 const char kMP3[] = "audio/mpeg";
80 #endif // defined(USE_PROPRIETARY_CODECS)
82 // Key used to encrypt test files.
83 const uint8_t kSecretKey[] = {
84 0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
85 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
88 // The key ID for all encrypted files.
89 const uint8_t kKeyId[] = {
90 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
91 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
94 const int kAppendWholeFile = -1;
96 // Constants for the Media Source config change tests.
97 const int kAppendTimeSec = 1;
98 const int kAppendTimeMs = kAppendTimeSec * 1000;
99 const int k320WebMFileDurationMs = 2736;
100 #if !defined(DISABLE_EME_TESTS)
101 const int k320EncWebMFileDurationMs = 2737;
102 #endif // !defined(DISABLE_EME_TESTS)
103 const int k640WebMFileDurationMs = 2749;
104 const int kOpusEndTrimmingWebMFileDurationMs = 2741;
105 const int kVP9WebMFileDurationMs = 2736;
106 const int kVP8AWebMFileDurationMs = 2734;
108 #if !defined(MOJO_RENDERER)
109 // Hash for a full playthrough of "opus-trimming-test.(webm|ogg)".
110 static const char kOpusEndTrimmingHash_1[] =
111 "-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,";
112 // The above hash, plus an additional playthrough starting from T=1s.
113 static const char kOpusEndTrimmingHash_2[] =
114 "-11.89,-11.09,-8.25,-7.11,-7.84,-9.97,";
115 // The above hash, plus an additional playthrough starting from T=6.36s.
116 static const char kOpusEndTrimmingHash_3[] =
117 "-13.28,-14.35,-13.67,-11.68,-10.18,-10.46,";
118 #endif
120 #if defined(USE_PROPRIETARY_CODECS)
121 #if !defined(DISABLE_EME_TESTS)
122 const int k640IsoFileDurationMs = 2737;
123 const int k640IsoCencFileDurationMs = 2736;
124 #endif // !defined(DISABLE_EME_TESTS)
125 const int k1280IsoFileDurationMs = 2736;
126 const int k1280IsoAVC3FileDurationMs = 2736;
127 #endif // defined(USE_PROPRIETARY_CODECS)
129 // Return a timeline offset for bear-320x240-live.webm.
130 static base::Time kLiveTimelineOffset() {
131 // The file contians the following UTC timeline offset:
132 // 2012-11-10 12:34:56.789123456
133 // Since base::Time only has a resolution of microseconds,
134 // construct a base::Time for 2012-11-10 12:34:56.789123.
135 base::Time::Exploded exploded_time;
136 exploded_time.year = 2012;
137 exploded_time.month = 11;
138 exploded_time.day_of_month = 10;
139 exploded_time.hour = 12;
140 exploded_time.minute = 34;
141 exploded_time.second = 56;
142 exploded_time.millisecond = 789;
143 base::Time timeline_offset = base::Time::FromUTCExploded(exploded_time);
145 timeline_offset += base::TimeDelta::FromMicroseconds(123);
147 return timeline_offset;
150 // FFmpeg only supports time a resolution of seconds so this
151 // helper function truncates a base::Time to seconds resolution.
152 static base::Time TruncateToFFmpegTimeResolution(base::Time t) {
153 base::Time::Exploded exploded_time;
154 t.UTCExplode(&exploded_time);
155 exploded_time.millisecond = 0;
157 return base::Time::FromUTCExploded(exploded_time);
160 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
161 // They do not exercise the Decrypting{Audio|Video}Decoder path.
162 class FakeEncryptedMedia {
163 public:
164 // Defines the behavior of the "app" that responds to EME events.
165 class AppBase {
166 public:
167 virtual ~AppBase() {}
169 virtual void OnSessionMessage(const std::string& session_id,
170 MediaKeys::MessageType message_type,
171 const std::vector<uint8_t>& message,
172 const GURL& legacy_destination_url,
173 AesDecryptor* decryptor) = 0;
175 virtual void OnSessionClosed(const std::string& session_id) = 0;
177 virtual void OnSessionKeysChange(const std::string& session_id,
178 bool has_additional_usable_key,
179 CdmKeysInfo keys_info) = 0;
181 // Errors are not expected unless overridden.
182 virtual void OnLegacySessionError(const std::string& session_id,
183 const std::string& error_name,
184 uint32_t system_code,
185 const std::string& error_message) {
186 FAIL() << "Unexpected Key Error";
189 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
190 const std::vector<uint8_t>& init_data,
191 AesDecryptor* decryptor) = 0;
194 FakeEncryptedMedia(AppBase* app)
195 : decryptor_(GURL::EmptyGURL(),
196 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
197 base::Unretained(this)),
198 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
199 base::Unretained(this)),
200 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
201 base::Unretained(this))),
202 cdm_context_(&decryptor_),
203 app_(app) {}
205 CdmContext* GetCdmContext() { return &cdm_context_; }
207 // Callbacks for firing session events. Delegate to |app_|.
208 void OnSessionMessage(const std::string& session_id,
209 MediaKeys::MessageType message_type,
210 const std::vector<uint8_t>& message,
211 const GURL& legacy_destination_url) {
212 app_->OnSessionMessage(session_id, message_type, message,
213 legacy_destination_url, &decryptor_);
216 void OnSessionClosed(const std::string& session_id) {
217 app_->OnSessionClosed(session_id);
220 void OnSessionKeysChange(const std::string& session_id,
221 bool has_additional_usable_key,
222 CdmKeysInfo keys_info) {
223 app_->OnSessionKeysChange(session_id, has_additional_usable_key,
224 keys_info.Pass());
227 void OnLegacySessionError(const std::string& session_id,
228 const std::string& error_name,
229 uint32_t system_code,
230 const std::string& error_message) {
231 app_->OnLegacySessionError(session_id, error_name, system_code,
232 error_message);
235 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
236 const std::vector<uint8_t>& init_data) {
237 app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
240 private:
241 class TestCdmContext : public CdmContext {
242 public:
243 TestCdmContext(Decryptor* decryptor) : decryptor_(decryptor) {}
245 Decryptor* GetDecryptor() final { return decryptor_; }
246 int GetCdmId() const final { return kInvalidCdmId; }
248 private:
249 Decryptor* decryptor_;
252 AesDecryptor decryptor_;
253 TestCdmContext cdm_context_;
254 scoped_ptr<AppBase> app_;
257 enum PromiseResult { RESOLVED, REJECTED };
259 // Provides |kSecretKey| in response to needkey.
260 class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
261 public:
262 KeyProvidingApp() {}
264 void OnResolveWithSession(PromiseResult expected,
265 const std::string& session_id) {
266 EXPECT_EQ(expected, RESOLVED);
267 EXPECT_GT(session_id.length(), 0ul);
268 current_session_id_ = session_id;
271 void OnResolve(PromiseResult expected) {
272 EXPECT_EQ(expected, RESOLVED);
275 void OnReject(PromiseResult expected,
276 media::MediaKeys::Exception exception_code,
277 uint32_t system_code,
278 const std::string& error_message) {
279 EXPECT_EQ(expected, REJECTED) << error_message;
282 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
283 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
284 base::Bind(
285 &KeyProvidingApp::OnResolve, base::Unretained(this), expected),
286 base::Bind(
287 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
288 return promise.Pass();
291 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
292 PromiseResult expected) {
293 scoped_ptr<media::NewSessionCdmPromise> promise(
294 new media::CdmCallbackPromise<std::string>(
295 base::Bind(&KeyProvidingApp::OnResolveWithSession,
296 base::Unretained(this),
297 expected),
298 base::Bind(
299 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
300 return promise.Pass();
303 void OnSessionMessage(const std::string& session_id,
304 MediaKeys::MessageType message_type,
305 const std::vector<uint8_t>& message,
306 const GURL& legacy_destination_url,
307 AesDecryptor* decryptor) override {
308 EXPECT_FALSE(session_id.empty());
309 EXPECT_FALSE(message.empty());
310 EXPECT_EQ(current_session_id_, session_id);
311 EXPECT_EQ(MediaKeys::MessageType::LICENSE_REQUEST, message_type);
313 // Extract the key ID from |message|. For Clear Key this is a JSON object
314 // containing a set of "kids". There should only be 1 key ID in |message|.
315 std::string message_string(message.begin(), message.end());
316 KeyIdList key_ids;
317 std::string error_message;
318 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids,
319 &error_message))
320 << error_message;
321 EXPECT_EQ(1u, key_ids.size());
323 // Determine the key that matches the key ID |key_ids[0]|.
324 std::vector<uint8_t> key;
325 EXPECT_TRUE(LookupKey(key_ids[0], &key));
327 // Update the session with the key ID and key.
328 std::string jwk =
329 GenerateJWKSet(vector_as_array(&key), key.size(),
330 vector_as_array(&key_ids[0]), key_ids[0].size());
331 decryptor->UpdateSession(session_id,
332 std::vector<uint8_t>(jwk.begin(), jwk.end()),
333 CreatePromise(RESOLVED));
336 void OnSessionClosed(const std::string& session_id) override {
337 EXPECT_EQ(current_session_id_, session_id);
340 void OnSessionKeysChange(const std::string& session_id,
341 bool has_additional_usable_key,
342 CdmKeysInfo keys_info) override {
343 EXPECT_EQ(current_session_id_, session_id);
344 EXPECT_EQ(has_additional_usable_key, true);
347 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
348 const std::vector<uint8_t>& init_data,
349 AesDecryptor* decryptor) override {
350 // Since only 1 session is created, skip the request if the |init_data|
351 // has been seen before (no need to add the same key again).
352 if (init_data == prev_init_data_)
353 return;
354 prev_init_data_ = init_data;
356 if (current_session_id_.empty()) {
357 decryptor->CreateSessionAndGenerateRequest(
358 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
359 CreateSessionPromise(RESOLVED));
360 EXPECT_FALSE(current_session_id_.empty());
364 virtual bool LookupKey(const std::vector<uint8_t>& key_id,
365 std::vector<uint8_t>* key) {
366 // As there is no key rotation, the key ID provided should be |kKeyId|
367 // which uses |kSecretKey| as the key.
368 EXPECT_EQ(std::vector<uint8_t>(kKeyId, kKeyId + arraysize(kKeyId)), key_id);
369 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
370 return true;
373 std::string current_session_id_;
374 std::vector<uint8_t> prev_init_data_;
377 class RotatingKeyProvidingApp : public KeyProvidingApp {
378 public:
379 RotatingKeyProvidingApp() : num_distinct_need_key_calls_(0) {}
380 ~RotatingKeyProvidingApp() override {
381 // Expect that OnEncryptedMediaInitData is fired multiple times with
382 // different |init_data|.
383 EXPECT_GT(num_distinct_need_key_calls_, 1u);
386 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
387 const std::vector<uint8_t>& init_data,
388 AesDecryptor* decryptor) override {
389 // Skip the request if the |init_data| has been seen.
390 if (init_data == prev_init_data_)
391 return;
392 prev_init_data_ = init_data;
393 ++num_distinct_need_key_calls_;
395 decryptor->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
396 init_data_type, init_data,
397 CreateSessionPromise(RESOLVED));
400 bool LookupKey(const std::vector<uint8_t>& key_id,
401 std::vector<uint8_t>* key) override {
402 // The Key and KeyId for this testing key provider are created by left
403 // rotating |kSecretKey| and |kKeyId|. Note that this implementation is
404 // only intended for testing purpose. The actual key rotation algorithm
405 // can be much more complicated.
406 // Find out the rotating position from |starting_key_id| and apply on |key|.
407 std::vector<uint8_t> starting_key_id(kKeyId, kKeyId + arraysize(kKeyId));
408 for (size_t pos = 0; pos < starting_key_id.size(); ++pos) {
409 std::rotate(starting_key_id.begin(), starting_key_id.begin() + pos,
410 starting_key_id.end());
411 if (key_id == starting_key_id) {
412 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
413 std::rotate(key->begin(), key->begin() + pos, key->end());
414 return true;
417 return false;
420 uint32_t num_distinct_need_key_calls_;
423 // Ignores needkey and does not perform a license request
424 class NoResponseApp : public FakeEncryptedMedia::AppBase {
425 public:
426 void OnSessionMessage(const std::string& session_id,
427 MediaKeys::MessageType message_type,
428 const std::vector<uint8_t>& message,
429 const GURL& legacy_destination_url,
430 AesDecryptor* decryptor) override {
431 EXPECT_FALSE(session_id.empty());
432 EXPECT_FALSE(message.empty());
433 FAIL() << "Unexpected Message";
436 void OnSessionClosed(const std::string& session_id) override {
437 EXPECT_FALSE(session_id.empty());
438 FAIL() << "Unexpected Closed";
441 void OnSessionKeysChange(const std::string& session_id,
442 bool has_additional_usable_key,
443 CdmKeysInfo keys_info) override {
444 EXPECT_FALSE(session_id.empty());
445 EXPECT_EQ(has_additional_usable_key, true);
448 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
449 const std::vector<uint8_t>& init_data,
450 AesDecryptor* decryptor) override {}
453 // Helper class that emulates calls made on the ChunkDemuxer by the
454 // Media Source API.
455 class MockMediaSource {
456 public:
457 MockMediaSource(const std::string& filename,
458 const std::string& mimetype,
459 int initial_append_size)
460 : current_position_(0),
461 initial_append_size_(initial_append_size),
462 mimetype_(mimetype),
463 chunk_demuxer_(new ChunkDemuxer(
464 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)),
465 base::Bind(&MockMediaSource::OnEncryptedMediaInitData,
466 base::Unretained(this)),
467 scoped_refptr<MediaLog>(new MediaLog()),
468 true)),
469 owned_chunk_demuxer_(chunk_demuxer_) {
470 file_data_ = ReadTestDataFile(filename);
472 if (initial_append_size_ == kAppendWholeFile)
473 initial_append_size_ = file_data_->data_size();
475 DCHECK_GT(initial_append_size_, 0);
476 DCHECK_LE(initial_append_size_, file_data_->data_size());
479 virtual ~MockMediaSource() {}
481 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); }
483 void set_encrypted_media_init_data_cb(
484 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
485 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
488 void Seek(base::TimeDelta seek_time, int new_position, int seek_append_size) {
489 chunk_demuxer_->StartWaitingForSeek(seek_time);
491 chunk_demuxer_->Abort(
492 kSourceId,
493 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_);
495 DCHECK_GE(new_position, 0);
496 DCHECK_LT(new_position, file_data_->data_size());
497 current_position_ = new_position;
499 AppendData(seek_append_size);
502 void Seek(base::TimeDelta seek_time) {
503 chunk_demuxer_->StartWaitingForSeek(seek_time);
506 void AppendData(int size) {
507 DCHECK(chunk_demuxer_);
508 DCHECK_LT(current_position_, file_data_->data_size());
509 DCHECK_LE(current_position_ + size, file_data_->data_size());
511 chunk_demuxer_->AppendData(
512 kSourceId, file_data_->data() + current_position_, size,
513 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_,
514 base::Bind(&MockMediaSource::InitSegmentReceived,
515 base::Unretained(this)));
516 current_position_ += size;
519 void AppendAtTime(base::TimeDelta timestamp_offset,
520 const uint8_t* pData,
521 int size) {
522 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
523 chunk_demuxer_->AppendData(kSourceId, pData, size,
524 base::TimeDelta(), kInfiniteDuration(),
525 &timestamp_offset,
526 base::Bind(&MockMediaSource::InitSegmentReceived,
527 base::Unretained(this)));
528 last_timestamp_offset_ = timestamp_offset;
531 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset,
532 base::TimeDelta append_window_start,
533 base::TimeDelta append_window_end,
534 const uint8_t* pData,
535 int size) {
536 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
537 chunk_demuxer_->AppendData(kSourceId,
538 pData,
539 size,
540 append_window_start,
541 append_window_end,
542 &timestamp_offset,
543 base::Bind(&MockMediaSource::InitSegmentReceived,
544 base::Unretained(this)));
545 last_timestamp_offset_ = timestamp_offset;
548 void EndOfStream() {
549 chunk_demuxer_->MarkEndOfStream(PIPELINE_OK);
552 void Abort() {
553 if (!chunk_demuxer_)
554 return;
555 chunk_demuxer_->Shutdown();
556 chunk_demuxer_ = NULL;
559 void DemuxerOpened() {
560 base::MessageLoop::current()->PostTask(
561 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask,
562 base::Unretained(this)));
565 void DemuxerOpenedTask() {
566 // This code assumes that |mimetype_| is one of the following forms.
567 // 1. audio/mpeg
568 // 2. video/webm;codec="vorbis,vp8".
569 size_t semicolon = mimetype_.find(";");
570 std::string type = mimetype_;
571 std::vector<std::string> codecs;
572 if (semicolon != std::string::npos) {
573 type = mimetype_.substr(0, semicolon);
574 size_t codecs_param_start = mimetype_.find("codecs=\"", semicolon);
576 CHECK_NE(codecs_param_start, std::string::npos);
578 codecs_param_start += 8; // Skip over the codecs=".
580 size_t codecs_param_end = mimetype_.find("\"", codecs_param_start);
582 CHECK_NE(codecs_param_end, std::string::npos);
584 std::string codecs_param =
585 mimetype_.substr(codecs_param_start,
586 codecs_param_end - codecs_param_start);
587 codecs = base::SplitString(
588 codecs_param, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
591 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk);
593 AppendData(initial_append_size_);
596 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
597 const std::vector<uint8_t>& init_data) {
598 DCHECK(!init_data.empty());
599 CHECK(!encrypted_media_init_data_cb_.is_null());
600 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
603 base::TimeDelta last_timestamp_offset() const {
604 return last_timestamp_offset_;
607 MOCK_METHOD0(InitSegmentReceived, void(void));
609 private:
610 scoped_refptr<DecoderBuffer> file_data_;
611 int current_position_;
612 int initial_append_size_;
613 std::string mimetype_;
614 ChunkDemuxer* chunk_demuxer_;
615 scoped_ptr<Demuxer> owned_chunk_demuxer_;
616 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
617 base::TimeDelta last_timestamp_offset_;
620 #if defined(MOJO_RENDERER)
621 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase,
622 public PipelineIntegrationTestBase {
623 public:
624 bool ShouldCreateDefaultRunLoop() override { return false; }
626 void SetUp() override {
627 ApplicationTestBase::SetUp();
628 InitializeMediaLibrary();
631 protected:
632 scoped_ptr<Renderer> CreateRenderer() override {
633 mojo::URLRequestPtr request(mojo::URLRequest::New());
634 request->url = mojo::String::From("mojo:media");
635 mojo::ServiceProvider* service_provider =
636 application_impl()
637 ->ConnectToApplication(request.Pass())
638 ->GetServiceProvider();
640 mojo::ConnectToService(service_provider, &media_service_factory_);
642 interfaces::RendererPtr mojo_renderer;
643 media_service_factory_->CreateRenderer(mojo::GetProxy(&mojo_renderer));
645 return make_scoped_ptr(new MojoRendererImpl(message_loop_.task_runner(),
646 mojo_renderer.Pass()));
649 private:
650 interfaces::ServiceFactoryPtr media_service_factory_;
652 #else
653 class PipelineIntegrationTestHost : public testing::Test,
654 public PipelineIntegrationTestBase {};
655 #endif
657 class PipelineIntegrationTest : public PipelineIntegrationTestHost {
658 public:
659 void StartPipelineWithMediaSource(MockMediaSource* source) {
660 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
661 EXPECT_CALL(*this, OnMetadata(_))
662 .Times(AtMost(1))
663 .WillRepeatedly(SaveArg<0>(&metadata_));
664 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
665 .Times(AnyNumber());
666 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
667 .Times(AnyNumber());
669 // Encrypted content not used, so this is never called.
670 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
672 demuxer_ = source->GetDemuxer().Pass();
673 pipeline_->Start(
674 demuxer_.get(), CreateRenderer(),
675 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
676 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
677 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
678 base::Unretained(this)),
679 base::Bind(&PipelineIntegrationTest::OnMetadata,
680 base::Unretained(this)),
681 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
682 base::Unretained(this)),
683 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
684 base::Unretained(this)),
685 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
686 base::Unretained(this)));
687 message_loop_.Run();
688 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
691 void StartHashedPipelineWithMediaSource(MockMediaSource* source) {
692 hashing_enabled_ = true;
693 StartPipelineWithMediaSource(source);
696 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource* source) {
697 hashing_enabled_ = true;
698 clockless_playback_ = true;
699 StartPipelineWithMediaSource(source);
702 void StartPipelineWithEncryptedMedia(
703 MockMediaSource* source,
704 FakeEncryptedMedia* encrypted_media) {
705 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
706 EXPECT_CALL(*this, OnMetadata(_))
707 .Times(AtMost(1))
708 .WillRepeatedly(SaveArg<0>(&metadata_));
709 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
710 .Times(AnyNumber());
711 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
712 .Times(AnyNumber());
713 EXPECT_CALL(*this, DecryptorAttached(true));
715 // Encrypted content used but keys provided in advance, so this is
716 // never called.
717 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
719 demuxer_ = source->GetDemuxer().Pass();
721 pipeline_->SetCdm(encrypted_media->GetCdmContext(),
722 base::Bind(&PipelineIntegrationTest::DecryptorAttached,
723 base::Unretained(this)));
725 pipeline_->Start(
726 demuxer_.get(), CreateRenderer(),
727 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
728 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
729 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
730 base::Unretained(this)),
731 base::Bind(&PipelineIntegrationTest::OnMetadata,
732 base::Unretained(this)),
733 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
734 base::Unretained(this)),
735 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
736 base::Unretained(this)),
737 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
738 base::Unretained(this)));
740 source->set_encrypted_media_init_data_cb(
741 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
742 base::Unretained(encrypted_media)));
744 message_loop_.Run();
745 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
748 // Verifies that seeking works properly for ChunkDemuxer when the
749 // seek happens while there is a pending read on the ChunkDemuxer
750 // and no data is available.
751 bool TestSeekDuringRead(const std::string& filename,
752 const std::string& mimetype,
753 int initial_append_size,
754 base::TimeDelta start_seek_time,
755 base::TimeDelta seek_time,
756 int seek_file_position,
757 int seek_append_size) {
758 MockMediaSource source(filename, mimetype, initial_append_size);
759 StartPipelineWithMediaSource(&source);
761 if (pipeline_status_ != PIPELINE_OK)
762 return false;
764 Play();
765 if (!WaitUntilCurrentTimeIsAfter(start_seek_time))
766 return false;
768 source.Seek(seek_time, seek_file_position, seek_append_size);
769 if (!Seek(seek_time))
770 return false;
772 source.EndOfStream();
774 source.Abort();
775 Stop();
776 return true;
780 TEST_F(PipelineIntegrationTest, BasicPlayback) {
781 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
783 Play();
785 ASSERT_TRUE(WaitUntilOnEnded());
788 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) {
789 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg"));
791 Play();
793 ASSERT_TRUE(WaitUntilOnEnded());
796 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
797 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed));
799 Play();
801 ASSERT_TRUE(WaitUntilOnEnded());
803 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
804 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
805 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
808 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOggTrimmingHashed) {
809 ASSERT_EQ(PIPELINE_OK,
810 Start("opus-trimming-test.webm", kHashed | kClockless));
812 Play();
814 ASSERT_TRUE(WaitUntilOnEnded());
815 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
817 // Seek within the pre-skip section, this should not cause a beep.
818 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
819 Play();
820 ASSERT_TRUE(WaitUntilOnEnded());
821 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
823 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
824 // correctly preroll enough to accurately decode this segment.
825 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
826 Play();
827 ASSERT_TRUE(WaitUntilOnEnded());
828 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
831 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusWebmTrimmingHashed) {
832 ASSERT_EQ(PIPELINE_OK,
833 Start("opus-trimming-test.webm", kHashed | kClockless));
835 Play();
837 ASSERT_TRUE(WaitUntilOnEnded());
838 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
840 // Seek within the pre-skip section, this should not cause a beep.
841 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
842 Play();
843 ASSERT_TRUE(WaitUntilOnEnded());
844 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
846 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
847 // correctly preroll enough to accurately decode this segment.
848 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
849 Play();
850 ASSERT_TRUE(WaitUntilOnEnded());
851 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
854 TEST_F(PipelineIntegrationTest,
855 BasicPlaybackOpusWebmTrimmingHashed_MediaSource) {
856 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM,
857 kAppendWholeFile);
858 StartHashedClocklessPipelineWithMediaSource(&source);
859 source.EndOfStream();
861 Play();
863 ASSERT_TRUE(WaitUntilOnEnded());
864 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
866 // Seek within the pre-skip section, this should not cause a beep.
867 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(1);
868 source.Seek(seek_time);
869 ASSERT_TRUE(Seek(seek_time));
870 Play();
871 ASSERT_TRUE(WaitUntilOnEnded());
872 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
874 // Seek somewhere outside of the pre-skip / end-trim section, demuxer should
875 // correctly preroll enough to accurately decode this segment.
876 seek_time = base::TimeDelta::FromMilliseconds(6360);
877 source.Seek(seek_time);
878 ASSERT_TRUE(Seek(seek_time));
879 Play();
880 ASSERT_TRUE(WaitUntilOnEnded());
881 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
884 // TODO(dalecurtis): Add an opus test file which FFmpeg and ChunkDemuxer will
885 // both seek the same in and shows the difference of preroll.
886 // http://crbug.com/509894
888 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) {
889 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed));
891 Play();
893 ASSERT_TRUE(WaitUntilOnEnded());
895 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
896 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
898 // TODO: Fix FFmpeg code to return higher resolution time values so
899 // we don't have to truncate our expectations here.
900 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
901 demuxer_->GetTimelineOffset());
904 TEST_F(PipelineIntegrationTest, F32PlaybackHashed) {
905 ASSERT_EQ(PIPELINE_OK, Start("sfx_f32le.wav", kHashed));
906 Play();
907 ASSERT_TRUE(WaitUntilOnEnded());
908 EXPECT_HASH_EQ(std::string(kNullVideoHash), GetVideoHash());
909 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
912 #if !defined(DISABLE_EME_TESTS)
913 TEST_F(PipelineIntegrationTest, BasicPlaybackEncrypted) {
914 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
915 set_encrypted_media_init_data_cb(
916 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
917 base::Unretained(&encrypted_media)));
919 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-av_enc-av.webm",
920 encrypted_media.GetCdmContext()));
922 Play();
924 ASSERT_TRUE(WaitUntilOnEnded());
925 Stop();
927 #endif // !defined(DISABLE_EME_TESTS)
929 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource) {
930 MockMediaSource source("bear-320x240.webm", kWebM, 219229);
931 StartPipelineWithMediaSource(&source);
932 source.EndOfStream();
934 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
935 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
936 EXPECT_EQ(k320WebMFileDurationMs,
937 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
939 Play();
941 ASSERT_TRUE(WaitUntilOnEnded());
943 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
944 source.Abort();
945 Stop();
948 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Live) {
949 MockMediaSource source("bear-320x240-live.webm", kWebM, 219221);
950 StartPipelineWithMediaSource(&source);
951 source.EndOfStream();
953 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
954 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
955 EXPECT_EQ(k320WebMFileDurationMs,
956 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
958 Play();
960 ASSERT_TRUE(WaitUntilOnEnded());
962 EXPECT_EQ(kLiveTimelineOffset(),
963 demuxer_->GetTimelineOffset());
964 source.Abort();
965 Stop();
968 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP9_WebM) {
969 MockMediaSource source("bear-vp9.webm", kWebMVP9, 67504);
970 StartPipelineWithMediaSource(&source);
971 source.EndOfStream();
973 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
974 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
975 EXPECT_EQ(kVP9WebMFileDurationMs,
976 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
978 Play();
980 ASSERT_TRUE(WaitUntilOnEnded());
981 source.Abort();
982 Stop();
985 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP8A_WebM) {
986 MockMediaSource source("bear-vp8a.webm", kVideoOnlyWebM, kAppendWholeFile);
987 StartPipelineWithMediaSource(&source);
988 source.EndOfStream();
990 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
991 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
992 EXPECT_EQ(kVP8AWebMFileDurationMs,
993 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
995 Play();
997 ASSERT_TRUE(WaitUntilOnEnded());
998 source.Abort();
999 Stop();
1002 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus_WebM) {
1003 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
1004 kAppendWholeFile);
1005 StartPipelineWithMediaSource(&source);
1006 source.EndOfStream();
1008 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1009 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1010 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
1011 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1012 Play();
1014 ASSERT_TRUE(WaitUntilOnEnded());
1015 source.Abort();
1016 Stop();
1019 // Flaky. http://crbug.com/304776
1020 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) {
1021 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
1022 kAppendWholeFile);
1023 StartHashedPipelineWithMediaSource(&source);
1025 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1026 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1027 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
1028 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1030 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000);
1031 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
1033 Play();
1034 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1035 source.Seek(seek_time, 0x1D5, 34017);
1036 source.EndOfStream();
1037 ASSERT_TRUE(Seek(seek_time));
1039 ASSERT_TRUE(WaitUntilOnEnded());
1041 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
1043 source.Abort();
1044 Stop();
1047 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) {
1048 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1049 kAppendWholeFile);
1050 StartPipelineWithMediaSource(&source);
1052 scoped_refptr<DecoderBuffer> second_file =
1053 ReadTestDataFile("bear-640x360.webm");
1055 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1056 second_file->data(), second_file->data_size());
1058 source.EndOfStream();
1060 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1061 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1062 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
1063 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1065 Play();
1067 EXPECT_TRUE(WaitUntilOnEnded());
1068 source.Abort();
1069 Stop();
1072 #if !defined(DISABLE_EME_TESTS)
1073 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) {
1074 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1075 kAppendWholeFile);
1076 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1077 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1079 scoped_refptr<DecoderBuffer> second_file =
1080 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1082 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1083 second_file->data(), second_file->data_size());
1085 source.EndOfStream();
1087 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1088 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1089 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
1090 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1092 Play();
1094 EXPECT_TRUE(WaitUntilOnEnded());
1095 source.Abort();
1096 Stop();
1099 // Config changes from encrypted to clear are not currently supported.
1100 TEST_F(PipelineIntegrationTest,
1101 MediaSource_ConfigChange_ClearThenEncrypted_WebM) {
1102 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1103 kAppendWholeFile);
1104 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1105 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1107 scoped_refptr<DecoderBuffer> second_file =
1108 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1110 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1111 second_file->data(), second_file->data_size());
1113 source.EndOfStream();
1115 message_loop_.Run();
1116 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1118 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1119 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1120 // The second video was not added, so its time has not been added.
1121 EXPECT_EQ(k320WebMFileDurationMs,
1122 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1124 Play();
1126 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1127 source.Abort();
1130 // Config changes from clear to encrypted are not currently supported.
1131 TEST_F(PipelineIntegrationTest,
1132 MediaSource_ConfigChange_EncryptedThenClear_WebM) {
1133 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1134 kAppendWholeFile);
1135 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1136 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1138 scoped_refptr<DecoderBuffer> second_file =
1139 ReadTestDataFile("bear-640x360.webm");
1141 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1142 second_file->data(), second_file->data_size());
1144 source.EndOfStream();
1146 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1147 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1148 // The second video was not added, so its time has not been added.
1149 EXPECT_EQ(k320EncWebMFileDurationMs,
1150 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1152 Play();
1154 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1155 source.Abort();
1157 #endif // !defined(DISABLE_EME_TESTS)
1159 #if defined(USE_PROPRIETARY_CODECS)
1160 TEST_F(PipelineIntegrationTest, MediaSource_ADTS) {
1161 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1162 StartPipelineWithMediaSource(&source);
1163 source.EndOfStream();
1165 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1166 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1167 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1169 Play();
1171 EXPECT_TRUE(WaitUntilOnEnded());
1174 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) {
1175 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1176 StartHashedPipelineWithMediaSource(&source);
1177 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds());
1179 // Trim off multiple frames off the beginning of the segment which will cause
1180 // the first decoded frame to be incorrect if preroll isn't implemented.
1181 const base::TimeDelta adts_preroll_duration =
1182 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1183 const base::TimeDelta append_time =
1184 source.last_timestamp_offset() - adts_preroll_duration;
1186 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts");
1187 source.AppendAtTimeWithWindow(append_time,
1188 append_time + adts_preroll_duration,
1189 kInfiniteDuration(),
1190 second_file->data(),
1191 second_file->data_size());
1192 source.EndOfStream();
1194 EXPECT_EQ(592, source.last_timestamp_offset().InMilliseconds());
1195 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1196 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1197 EXPECT_EQ(592, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1199 Play();
1201 EXPECT_TRUE(WaitUntilOnEnded());
1203 // Verify preroll is stripped.
1204 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1207 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed_MP3) {
1208 ASSERT_EQ(PIPELINE_OK, Start("sfx.mp3", kHashed));
1210 Play();
1212 ASSERT_TRUE(WaitUntilOnEnded());
1214 // Verify codec delay and preroll are stripped.
1215 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1218 TEST_F(PipelineIntegrationTest, MediaSource_MP3) {
1219 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1220 StartHashedPipelineWithMediaSource(&source);
1221 source.EndOfStream();
1223 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1224 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1225 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1227 Play();
1229 EXPECT_TRUE(WaitUntilOnEnded());
1231 // Verify that codec delay was stripped.
1232 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1235 TEST_F(PipelineIntegrationTest, MediaSource_MP3_TimestampOffset) {
1236 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1237 StartPipelineWithMediaSource(&source);
1238 EXPECT_EQ(313, source.last_timestamp_offset().InMilliseconds());
1240 // There are 576 silent frames at the start of this mp3. The second append
1241 // should trim them off.
1242 const base::TimeDelta mp3_preroll_duration =
1243 base::TimeDelta::FromSecondsD(576.0 / 44100);
1244 const base::TimeDelta append_time =
1245 source.last_timestamp_offset() - mp3_preroll_duration;
1247 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.mp3");
1248 source.AppendAtTimeWithWindow(append_time,
1249 append_time + mp3_preroll_duration,
1250 kInfiniteDuration(),
1251 second_file->data(),
1252 second_file->data_size());
1253 source.EndOfStream();
1255 EXPECT_EQ(613, source.last_timestamp_offset().InMilliseconds());
1256 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1257 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1258 EXPECT_EQ(613, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1260 Play();
1262 EXPECT_TRUE(WaitUntilOnEnded());
1265 TEST_F(PipelineIntegrationTest, MediaSource_MP3_Icecast) {
1266 MockMediaSource source("icy_sfx.mp3", kMP3, kAppendWholeFile);
1267 StartPipelineWithMediaSource(&source);
1268 source.EndOfStream();
1270 Play();
1272 EXPECT_TRUE(WaitUntilOnEnded());
1275 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_MP4) {
1276 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4, kAppendWholeFile);
1277 StartPipelineWithMediaSource(&source);
1279 scoped_refptr<DecoderBuffer> second_file =
1280 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1282 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1283 second_file->data(), second_file->data_size());
1285 source.EndOfStream();
1287 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1288 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1289 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1290 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1292 Play();
1294 EXPECT_TRUE(WaitUntilOnEnded());
1295 source.Abort();
1296 Stop();
1299 #if !defined(DISABLE_EME_TESTS)
1300 TEST_F(PipelineIntegrationTest,
1301 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly) {
1302 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1303 kAppendWholeFile);
1304 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1305 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1307 scoped_refptr<DecoderBuffer> second_file =
1308 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1310 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1311 second_file->data(), second_file->data_size());
1313 source.EndOfStream();
1315 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1316 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1317 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1318 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1320 Play();
1322 EXPECT_TRUE(WaitUntilOnEnded());
1323 source.Abort();
1324 Stop();
1327 TEST_F(PipelineIntegrationTest,
1328 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1329 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video,
1330 kAppendWholeFile);
1331 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1332 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1334 scoped_refptr<DecoderBuffer> second_file =
1335 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1337 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1338 second_file->data(), second_file->data_size());
1340 source.EndOfStream();
1342 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1343 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1344 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1345 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1347 Play();
1349 EXPECT_TRUE(WaitUntilOnEnded());
1350 source.Abort();
1351 Stop();
1354 // Config changes from clear to encrypted are not currently supported.
1355 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1356 TEST_F(PipelineIntegrationTest,
1357 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1358 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1359 kAppendWholeFile);
1360 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1361 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1363 scoped_refptr<DecoderBuffer> second_file =
1364 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1366 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1367 second_file->data(), second_file->data_size());
1369 source.EndOfStream();
1371 message_loop_.Run();
1372 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1374 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1375 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1376 // The second video was not added, so its time has not been added.
1377 EXPECT_EQ(k640IsoFileDurationMs,
1378 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1380 Play();
1382 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1383 source.Abort();
1386 // Config changes from encrypted to clear are not currently supported.
1387 TEST_F(PipelineIntegrationTest,
1388 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC) {
1389 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1390 kAppendWholeFile);
1391 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1392 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1394 scoped_refptr<DecoderBuffer> second_file =
1395 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1397 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1398 second_file->data(), second_file->data_size());
1400 source.EndOfStream();
1402 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1403 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1404 // The second video was not added, so its time has not been added.
1405 EXPECT_EQ(k640IsoCencFileDurationMs,
1406 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1408 Play();
1410 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1411 source.Abort();
1413 #endif // !defined(DISABLE_EME_TESTS)
1415 // Verify files which change configuration midstream fail gracefully.
1416 TEST_F(PipelineIntegrationTest, MidStreamConfigChangesFail) {
1417 ASSERT_EQ(PIPELINE_OK, Start("midstream_config_change.mp3"));
1418 Play();
1419 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE);
1422 #endif
1424 TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) {
1425 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-16x9-aspect.webm"));
1426 Play();
1427 ASSERT_TRUE(WaitUntilOnEnded());
1430 #if !defined(DISABLE_EME_TESTS)
1431 TEST_F(PipelineIntegrationTest, EncryptedPlayback_WebM) {
1432 MockMediaSource source("bear-320x240-av_enc-av.webm", kWebM, 219816);
1433 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1434 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1436 source.EndOfStream();
1437 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1439 Play();
1441 ASSERT_TRUE(WaitUntilOnEnded());
1442 source.Abort();
1443 Stop();
1446 TEST_F(PipelineIntegrationTest, EncryptedPlayback_ClearStart_WebM) {
1447 MockMediaSource source("bear-320x240-av_enc-av_clear-1s.webm", kWebM,
1448 kAppendWholeFile);
1449 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1450 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1452 source.EndOfStream();
1453 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1455 Play();
1457 ASSERT_TRUE(WaitUntilOnEnded());
1458 source.Abort();
1459 Stop();
1462 TEST_F(PipelineIntegrationTest, EncryptedPlayback_NoEncryptedFrames_WebM) {
1463 MockMediaSource source("bear-320x240-av_enc-av_clear-all.webm", kWebM,
1464 kAppendWholeFile);
1465 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1466 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1468 source.EndOfStream();
1469 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1471 Play();
1473 ASSERT_TRUE(WaitUntilOnEnded());
1474 source.Abort();
1475 Stop();
1477 #endif // !defined(DISABLE_EME_TESTS)
1479 #if defined(USE_PROPRIETARY_CODECS)
1480 #if !defined(DISABLE_EME_TESTS)
1481 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_VideoOnly) {
1482 MockMediaSource source("bear-1280x720-v_frag-cenc.mp4", kMP4Video,
1483 kAppendWholeFile);
1484 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1485 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1487 source.EndOfStream();
1488 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1490 Play();
1492 ASSERT_TRUE(WaitUntilOnEnded());
1493 source.Abort();
1494 Stop();
1497 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_AudioOnly) {
1498 MockMediaSource source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio,
1499 kAppendWholeFile);
1500 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1501 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1503 source.EndOfStream();
1504 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1506 Play();
1508 ASSERT_TRUE(WaitUntilOnEnded());
1509 source.Abort();
1510 Stop();
1513 TEST_F(PipelineIntegrationTest,
1514 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly) {
1515 MockMediaSource source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video,
1516 kAppendWholeFile);
1517 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1518 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1520 source.EndOfStream();
1521 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1523 Play();
1525 ASSERT_TRUE(WaitUntilOnEnded());
1526 source.Abort();
1527 Stop();
1530 TEST_F(PipelineIntegrationTest,
1531 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly) {
1532 MockMediaSource source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio,
1533 kAppendWholeFile);
1534 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1535 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1537 source.EndOfStream();
1538 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1540 Play();
1542 ASSERT_TRUE(WaitUntilOnEnded());
1543 source.Abort();
1544 Stop();
1547 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1548 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1549 kMP4Video, kAppendWholeFile);
1550 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1551 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1553 source.EndOfStream();
1554 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1556 Play();
1558 ASSERT_TRUE(WaitUntilOnEnded());
1559 source.Abort();
1560 Stop();
1563 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1564 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1565 kMP4Audio, kAppendWholeFile);
1566 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1567 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1569 source.EndOfStream();
1570 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1572 Play();
1574 ASSERT_TRUE(WaitUntilOnEnded());
1575 source.Abort();
1576 Stop();
1578 #endif // !defined(DISABLE_EME_TESTS)
1580 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3) {
1581 MockMediaSource source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3,
1582 kAppendWholeFile);
1583 StartPipelineWithMediaSource(&source);
1584 source.EndOfStream();
1586 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1587 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1588 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1589 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1591 Play();
1593 ASSERT_TRUE(WaitUntilOnEnded());
1594 source.Abort();
1595 Stop();
1597 #endif // defined(USE_PROPRIETARY_CODECS)
1599 TEST_F(PipelineIntegrationTest, SeekWhilePaused) {
1600 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1602 base::TimeDelta duration(pipeline_->GetMediaDuration());
1603 base::TimeDelta start_seek_time(duration / 4);
1604 base::TimeDelta seek_time(duration * 3 / 4);
1606 Play();
1607 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1608 Pause();
1609 ASSERT_TRUE(Seek(seek_time));
1610 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1611 Play();
1612 ASSERT_TRUE(WaitUntilOnEnded());
1614 // Make sure seeking after reaching the end works as expected.
1615 Pause();
1616 ASSERT_TRUE(Seek(seek_time));
1617 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1618 Play();
1619 ASSERT_TRUE(WaitUntilOnEnded());
1622 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) {
1623 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1625 base::TimeDelta duration(pipeline_->GetMediaDuration());
1626 base::TimeDelta start_seek_time(duration / 4);
1627 base::TimeDelta seek_time(duration * 3 / 4);
1629 Play();
1630 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1631 ASSERT_TRUE(Seek(seek_time));
1632 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1633 ASSERT_TRUE(WaitUntilOnEnded());
1635 // Make sure seeking after reaching the end works as expected.
1636 ASSERT_TRUE(Seek(seek_time));
1637 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1638 ASSERT_TRUE(WaitUntilOnEnded());
1641 #if defined(USE_PROPRIETARY_CODECS)
1642 TEST_F(PipelineIntegrationTest, Rotated_Metadata_0) {
1643 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_0.mp4"));
1644 ASSERT_EQ(VIDEO_ROTATION_0, metadata_.video_rotation);
1647 TEST_F(PipelineIntegrationTest, Rotated_Metadata_90) {
1648 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_90.mp4"));
1649 ASSERT_EQ(VIDEO_ROTATION_90, metadata_.video_rotation);
1652 TEST_F(PipelineIntegrationTest, Rotated_Metadata_180) {
1653 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_180.mp4"));
1654 ASSERT_EQ(VIDEO_ROTATION_180, metadata_.video_rotation);
1657 TEST_F(PipelineIntegrationTest, Rotated_Metadata_270) {
1658 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_270.mp4"));
1659 ASSERT_EQ(VIDEO_ROTATION_270, metadata_.video_rotation);
1661 #endif
1663 // Verify audio decoder & renderer can handle aborted demuxer reads.
1664 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) {
1665 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM,
1666 16384,
1667 base::TimeDelta::FromMilliseconds(464),
1668 base::TimeDelta::FromMilliseconds(617),
1669 0x10CA, 19730));
1672 // Verify video decoder & renderer can handle aborted demuxer reads.
1673 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
1674 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM,
1675 32768,
1676 base::TimeDelta::FromMilliseconds(167),
1677 base::TimeDelta::FromMilliseconds(1668),
1678 0x1C896, 65536));
1681 // Verify that Opus audio in WebM containers can be played back.
1682 TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
1683 ASSERT_EQ(PIPELINE_OK, Start("bear-opus-end-trimming.webm"));
1684 Play();
1685 ASSERT_TRUE(WaitUntilOnEnded());
1688 // Verify that VP9 video in WebM containers can be played back.
1689 TEST_F(PipelineIntegrationTest, BasicPlayback_VideoOnly_VP9_WebM) {
1690 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
1691 Play();
1692 ASSERT_TRUE(WaitUntilOnEnded());
1695 // Verify that VP9 video and Opus audio in the same WebM container can be played
1696 // back.
1697 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Opus_WebM) {
1698 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-opus.webm"));
1699 Play();
1700 ASSERT_TRUE(WaitUntilOnEnded());
1703 // Verify that VP8 video with alpha channel can be played back.
1704 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_WebM) {
1705 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a.webm"));
1706 Play();
1707 ASSERT_TRUE(WaitUntilOnEnded());
1708 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1711 // Verify that VP8A video with odd width/height can be played back.
1712 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_Odd_WebM) {
1713 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a-odd-dimensions.webm"));
1714 Play();
1715 ASSERT_TRUE(WaitUntilOnEnded());
1716 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1719 // Verify that VP9 video with odd width/height can be played back.
1720 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Odd_WebM) {
1721 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-odd-dimensions.webm"));
1722 Play();
1723 ASSERT_TRUE(WaitUntilOnEnded());
1726 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1727 // Verify that VP8 video with inband text track can be played back.
1728 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) {
1729 EXPECT_CALL(*this, OnAddTextTrack(_, _));
1730 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8-webvtt.webm"));
1731 Play();
1732 ASSERT_TRUE(WaitUntilOnEnded());
1734 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1736 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1737 TEST_F(PipelineIntegrationTest, P444_VP9_WebM) {
1738 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-P444.webm"));
1739 Play();
1740 ASSERT_TRUE(WaitUntilOnEnded());
1741 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV24);
1744 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1745 // format.
1746 TEST_F(PipelineIntegrationTest, BT709_VP9_WebM) {
1747 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-bt709.webm"));
1748 Play();
1749 ASSERT_TRUE(WaitUntilOnEnded());
1750 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12);
1751 EXPECT_COLOR_SPACE_EQ(last_video_frame_color_space_, COLOR_SPACE_HD_REC709);
1754 // Verify that videos with an odd frame size playback successfully.
1755 TEST_F(PipelineIntegrationTest, BasicPlayback_OddVideoSize) {
1756 ASSERT_EQ(PIPELINE_OK, Start("butterfly-853x480.webm"));
1757 Play();
1758 ASSERT_TRUE(WaitUntilOnEnded());
1761 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1762 // correctly at 48kHz
1763 TEST_F(PipelineIntegrationTest, BasicPlayback_Opus441kHz) {
1764 ASSERT_EQ(PIPELINE_OK, Start("sfx-opus-441.webm"));
1765 Play();
1766 ASSERT_TRUE(WaitUntilOnEnded());
1767 EXPECT_EQ(48000,
1768 demuxer_->GetStream(DemuxerStream::AUDIO)
1769 ->audio_decoder_config()
1770 .samples_per_second());
1773 // Same as above but using MediaSource.
1774 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus441kHz) {
1775 MockMediaSource source(
1776 "sfx-opus-441.webm", kOpusAudioOnlyWebM, kAppendWholeFile);
1777 StartPipelineWithMediaSource(&source);
1778 source.EndOfStream();
1779 Play();
1780 ASSERT_TRUE(WaitUntilOnEnded());
1781 source.Abort();
1782 Stop();
1783 EXPECT_EQ(48000,
1784 demuxer_->GetStream(DemuxerStream::AUDIO)
1785 ->audio_decoder_config()
1786 .samples_per_second());
1789 // Ensures audio-only playback with missing or negative timestamps works. Tests
1790 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1791 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOgg) {
1792 ASSERT_EQ(PIPELINE_OK, Start("double-sfx.ogg"));
1793 Play();
1794 ASSERT_TRUE(WaitUntilOnEnded());
1795 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1798 // Ensures audio-video playback with missing or negative timestamps fails softly
1799 // instead of crashing. See http://crbug.com/396864.
1800 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOggVideo) {
1801 ASSERT_EQ(PIPELINE_OK, Start("double-bear.ogv"));
1802 Play();
1803 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1804 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1807 // Tests that we signal ended even when audio runs longer than video track.
1808 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioLongerThanVideo) {
1809 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv"));
1810 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1811 // of the two.
1812 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds());
1813 Play();
1814 ASSERT_TRUE(WaitUntilOnEnded());
1817 // Tests that we signal ended even when audio runs shorter than video track.
1818 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioShorterThanVideo) {
1819 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv"));
1820 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1821 // the two.
1822 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds());
1823 Play();
1824 ASSERT_TRUE(WaitUntilOnEnded());
1827 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
1828 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
1829 Play();
1830 ASSERT_TRUE(WaitUntilOnEnded());
1831 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1832 demuxer_->GetStartTime());
1835 } // namespace media