[chromedriver] Explicitly set page loading state when document.readyState != "complete".
[chromium-blink-merge.git] / media / test / pipeline_integration_test.cc
blobb81a19cba477d6bf0151ec6170855c95c49dd580
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(USE_PROPRIETARY_CODECS)
109 #if !defined(DISABLE_EME_TESTS)
110 const int k640IsoFileDurationMs = 2737;
111 const int k640IsoCencFileDurationMs = 2736;
112 #endif // !defined(DISABLE_EME_TESTS)
113 const int k1280IsoFileDurationMs = 2736;
114 const int k1280IsoAVC3FileDurationMs = 2736;
115 #endif // defined(USE_PROPRIETARY_CODECS)
117 // Return a timeline offset for bear-320x240-live.webm.
118 static base::Time kLiveTimelineOffset() {
119 // The file contians the following UTC timeline offset:
120 // 2012-11-10 12:34:56.789123456
121 // Since base::Time only has a resolution of microseconds,
122 // construct a base::Time for 2012-11-10 12:34:56.789123.
123 base::Time::Exploded exploded_time;
124 exploded_time.year = 2012;
125 exploded_time.month = 11;
126 exploded_time.day_of_month = 10;
127 exploded_time.hour = 12;
128 exploded_time.minute = 34;
129 exploded_time.second = 56;
130 exploded_time.millisecond = 789;
131 base::Time timeline_offset = base::Time::FromUTCExploded(exploded_time);
133 timeline_offset += base::TimeDelta::FromMicroseconds(123);
135 return timeline_offset;
138 // FFmpeg only supports time a resolution of seconds so this
139 // helper function truncates a base::Time to seconds resolution.
140 static base::Time TruncateToFFmpegTimeResolution(base::Time t) {
141 base::Time::Exploded exploded_time;
142 t.UTCExplode(&exploded_time);
143 exploded_time.millisecond = 0;
145 return base::Time::FromUTCExploded(exploded_time);
148 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
149 // They do not exercise the Decrypting{Audio|Video}Decoder path.
150 class FakeEncryptedMedia {
151 public:
152 // Defines the behavior of the "app" that responds to EME events.
153 class AppBase {
154 public:
155 virtual ~AppBase() {}
157 virtual void OnSessionMessage(const std::string& session_id,
158 MediaKeys::MessageType message_type,
159 const std::vector<uint8_t>& message,
160 const GURL& legacy_destination_url,
161 AesDecryptor* decryptor) = 0;
163 virtual void OnSessionClosed(const std::string& session_id) = 0;
165 virtual void OnSessionKeysChange(const std::string& session_id,
166 bool has_additional_usable_key,
167 CdmKeysInfo keys_info) = 0;
169 // Errors are not expected unless overridden.
170 virtual void OnLegacySessionError(const std::string& session_id,
171 const std::string& error_name,
172 uint32_t system_code,
173 const std::string& error_message) {
174 FAIL() << "Unexpected Key Error";
177 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
178 const std::vector<uint8_t>& init_data,
179 AesDecryptor* decryptor) = 0;
182 FakeEncryptedMedia(AppBase* app)
183 : decryptor_(GURL::EmptyGURL(),
184 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
185 base::Unretained(this)),
186 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
187 base::Unretained(this)),
188 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
189 base::Unretained(this))),
190 cdm_context_(&decryptor_),
191 app_(app) {}
193 CdmContext* GetCdmContext() { return &cdm_context_; }
195 // Callbacks for firing session events. Delegate to |app_|.
196 void OnSessionMessage(const std::string& session_id,
197 MediaKeys::MessageType message_type,
198 const std::vector<uint8_t>& message,
199 const GURL& legacy_destination_url) {
200 app_->OnSessionMessage(session_id, message_type, message,
201 legacy_destination_url, &decryptor_);
204 void OnSessionClosed(const std::string& session_id) {
205 app_->OnSessionClosed(session_id);
208 void OnSessionKeysChange(const std::string& session_id,
209 bool has_additional_usable_key,
210 CdmKeysInfo keys_info) {
211 app_->OnSessionKeysChange(session_id, has_additional_usable_key,
212 keys_info.Pass());
215 void OnLegacySessionError(const std::string& session_id,
216 const std::string& error_name,
217 uint32_t system_code,
218 const std::string& error_message) {
219 app_->OnLegacySessionError(session_id, error_name, system_code,
220 error_message);
223 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
224 const std::vector<uint8_t>& init_data) {
225 app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
228 private:
229 class TestCdmContext : public CdmContext {
230 public:
231 TestCdmContext(Decryptor* decryptor) : decryptor_(decryptor) {}
233 Decryptor* GetDecryptor() final { return decryptor_; }
234 int GetCdmId() const final { return kInvalidCdmId; }
236 private:
237 Decryptor* decryptor_;
240 AesDecryptor decryptor_;
241 TestCdmContext cdm_context_;
242 scoped_ptr<AppBase> app_;
245 enum PromiseResult { RESOLVED, REJECTED };
247 // Provides |kSecretKey| in response to needkey.
248 class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
249 public:
250 KeyProvidingApp() {}
252 void OnResolveWithSession(PromiseResult expected,
253 const std::string& session_id) {
254 EXPECT_EQ(expected, RESOLVED);
255 EXPECT_GT(session_id.length(), 0ul);
256 current_session_id_ = session_id;
259 void OnResolve(PromiseResult expected) {
260 EXPECT_EQ(expected, RESOLVED);
263 void OnReject(PromiseResult expected,
264 media::MediaKeys::Exception exception_code,
265 uint32_t system_code,
266 const std::string& error_message) {
267 EXPECT_EQ(expected, REJECTED) << error_message;
270 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
271 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
272 base::Bind(
273 &KeyProvidingApp::OnResolve, base::Unretained(this), expected),
274 base::Bind(
275 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
276 return promise.Pass();
279 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
280 PromiseResult expected) {
281 scoped_ptr<media::NewSessionCdmPromise> promise(
282 new media::CdmCallbackPromise<std::string>(
283 base::Bind(&KeyProvidingApp::OnResolveWithSession,
284 base::Unretained(this),
285 expected),
286 base::Bind(
287 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
288 return promise.Pass();
291 void OnSessionMessage(const std::string& session_id,
292 MediaKeys::MessageType message_type,
293 const std::vector<uint8_t>& message,
294 const GURL& legacy_destination_url,
295 AesDecryptor* decryptor) override {
296 EXPECT_FALSE(session_id.empty());
297 EXPECT_FALSE(message.empty());
298 EXPECT_EQ(current_session_id_, session_id);
299 EXPECT_EQ(MediaKeys::MessageType::LICENSE_REQUEST, message_type);
301 // Extract the key ID from |message|. For Clear Key this is a JSON object
302 // containing a set of "kids". There should only be 1 key ID in |message|.
303 std::string message_string(message.begin(), message.end());
304 KeyIdList key_ids;
305 std::string error_message;
306 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids,
307 &error_message))
308 << error_message;
309 EXPECT_EQ(1u, key_ids.size());
311 // Determine the key that matches the key ID |key_ids[0]|.
312 std::vector<uint8_t> key;
313 EXPECT_TRUE(LookupKey(key_ids[0], &key));
315 // Update the session with the key ID and key.
316 std::string jwk =
317 GenerateJWKSet(vector_as_array(&key), key.size(),
318 vector_as_array(&key_ids[0]), key_ids[0].size());
319 decryptor->UpdateSession(session_id,
320 std::vector<uint8_t>(jwk.begin(), jwk.end()),
321 CreatePromise(RESOLVED));
324 void OnSessionClosed(const std::string& session_id) override {
325 EXPECT_EQ(current_session_id_, session_id);
328 void OnSessionKeysChange(const std::string& session_id,
329 bool has_additional_usable_key,
330 CdmKeysInfo keys_info) override {
331 EXPECT_EQ(current_session_id_, session_id);
332 EXPECT_EQ(has_additional_usable_key, true);
335 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
336 const std::vector<uint8_t>& init_data,
337 AesDecryptor* decryptor) override {
338 // Since only 1 session is created, skip the request if the |init_data|
339 // has been seen before (no need to add the same key again).
340 if (init_data == prev_init_data_)
341 return;
342 prev_init_data_ = init_data;
344 if (current_session_id_.empty()) {
345 decryptor->CreateSessionAndGenerateRequest(
346 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
347 CreateSessionPromise(RESOLVED));
348 EXPECT_FALSE(current_session_id_.empty());
352 virtual bool LookupKey(const std::vector<uint8_t>& key_id,
353 std::vector<uint8_t>* key) {
354 // As there is no key rotation, the key ID provided should be |kKeyId|
355 // which uses |kSecretKey| as the key.
356 EXPECT_EQ(std::vector<uint8_t>(kKeyId, kKeyId + arraysize(kKeyId)), key_id);
357 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
358 return true;
361 std::string current_session_id_;
362 std::vector<uint8_t> prev_init_data_;
365 class RotatingKeyProvidingApp : public KeyProvidingApp {
366 public:
367 RotatingKeyProvidingApp() : num_distinct_need_key_calls_(0) {}
368 ~RotatingKeyProvidingApp() override {
369 // Expect that OnEncryptedMediaInitData is fired multiple times with
370 // different |init_data|.
371 EXPECT_GT(num_distinct_need_key_calls_, 1u);
374 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
375 const std::vector<uint8_t>& init_data,
376 AesDecryptor* decryptor) override {
377 // Skip the request if the |init_data| has been seen.
378 if (init_data == prev_init_data_)
379 return;
380 prev_init_data_ = init_data;
381 ++num_distinct_need_key_calls_;
383 decryptor->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
384 init_data_type, init_data,
385 CreateSessionPromise(RESOLVED));
388 bool LookupKey(const std::vector<uint8_t>& key_id,
389 std::vector<uint8_t>* key) override {
390 // The Key and KeyId for this testing key provider are created by left
391 // rotating |kSecretKey| and |kKeyId|. Note that this implementation is
392 // only intended for testing purpose. The actual key rotation algorithm
393 // can be much more complicated.
394 // Find out the rotating position from |starting_key_id| and apply on |key|.
395 std::vector<uint8_t> starting_key_id(kKeyId, kKeyId + arraysize(kKeyId));
396 for (size_t pos = 0; pos < starting_key_id.size(); ++pos) {
397 std::rotate(starting_key_id.begin(), starting_key_id.begin() + pos,
398 starting_key_id.end());
399 if (key_id == starting_key_id) {
400 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
401 std::rotate(key->begin(), key->begin() + pos, key->end());
402 return true;
405 return false;
408 uint32_t num_distinct_need_key_calls_;
411 // Ignores needkey and does not perform a license request
412 class NoResponseApp : public FakeEncryptedMedia::AppBase {
413 public:
414 void OnSessionMessage(const std::string& session_id,
415 MediaKeys::MessageType message_type,
416 const std::vector<uint8_t>& message,
417 const GURL& legacy_destination_url,
418 AesDecryptor* decryptor) override {
419 EXPECT_FALSE(session_id.empty());
420 EXPECT_FALSE(message.empty());
421 FAIL() << "Unexpected Message";
424 void OnSessionClosed(const std::string& session_id) override {
425 EXPECT_FALSE(session_id.empty());
426 FAIL() << "Unexpected Closed";
429 void OnSessionKeysChange(const std::string& session_id,
430 bool has_additional_usable_key,
431 CdmKeysInfo keys_info) override {
432 EXPECT_FALSE(session_id.empty());
433 EXPECT_EQ(has_additional_usable_key, true);
436 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
437 const std::vector<uint8_t>& init_data,
438 AesDecryptor* decryptor) override {}
441 // Helper class that emulates calls made on the ChunkDemuxer by the
442 // Media Source API.
443 class MockMediaSource {
444 public:
445 MockMediaSource(const std::string& filename,
446 const std::string& mimetype,
447 int initial_append_size)
448 : current_position_(0),
449 initial_append_size_(initial_append_size),
450 mimetype_(mimetype),
451 chunk_demuxer_(new ChunkDemuxer(
452 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)),
453 base::Bind(&MockMediaSource::OnEncryptedMediaInitData,
454 base::Unretained(this)),
455 scoped_refptr<MediaLog>(new MediaLog()),
456 true)),
457 owned_chunk_demuxer_(chunk_demuxer_) {
458 file_data_ = ReadTestDataFile(filename);
460 if (initial_append_size_ == kAppendWholeFile)
461 initial_append_size_ = file_data_->data_size();
463 DCHECK_GT(initial_append_size_, 0);
464 DCHECK_LE(initial_append_size_, file_data_->data_size());
467 virtual ~MockMediaSource() {}
469 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); }
471 void set_encrypted_media_init_data_cb(
472 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
473 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
476 void Seek(base::TimeDelta seek_time, int new_position, int seek_append_size) {
477 chunk_demuxer_->StartWaitingForSeek(seek_time);
479 chunk_demuxer_->Abort(
480 kSourceId,
481 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_);
483 DCHECK_GE(new_position, 0);
484 DCHECK_LT(new_position, file_data_->data_size());
485 current_position_ = new_position;
487 AppendData(seek_append_size);
490 void AppendData(int size) {
491 DCHECK(chunk_demuxer_);
492 DCHECK_LT(current_position_, file_data_->data_size());
493 DCHECK_LE(current_position_ + size, file_data_->data_size());
495 chunk_demuxer_->AppendData(
496 kSourceId, file_data_->data() + current_position_, size,
497 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_,
498 base::Bind(&MockMediaSource::InitSegmentReceived,
499 base::Unretained(this)));
500 current_position_ += size;
503 void AppendAtTime(base::TimeDelta timestamp_offset,
504 const uint8_t* pData,
505 int size) {
506 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
507 chunk_demuxer_->AppendData(kSourceId, pData, size,
508 base::TimeDelta(), kInfiniteDuration(),
509 &timestamp_offset,
510 base::Bind(&MockMediaSource::InitSegmentReceived,
511 base::Unretained(this)));
512 last_timestamp_offset_ = timestamp_offset;
515 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset,
516 base::TimeDelta append_window_start,
517 base::TimeDelta append_window_end,
518 const uint8_t* pData,
519 int size) {
520 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
521 chunk_demuxer_->AppendData(kSourceId,
522 pData,
523 size,
524 append_window_start,
525 append_window_end,
526 &timestamp_offset,
527 base::Bind(&MockMediaSource::InitSegmentReceived,
528 base::Unretained(this)));
529 last_timestamp_offset_ = timestamp_offset;
532 void EndOfStream() {
533 chunk_demuxer_->MarkEndOfStream(PIPELINE_OK);
536 void Abort() {
537 if (!chunk_demuxer_)
538 return;
539 chunk_demuxer_->Shutdown();
540 chunk_demuxer_ = NULL;
543 void DemuxerOpened() {
544 base::MessageLoop::current()->PostTask(
545 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask,
546 base::Unretained(this)));
549 void DemuxerOpenedTask() {
550 // This code assumes that |mimetype_| is one of the following forms.
551 // 1. audio/mpeg
552 // 2. video/webm;codec="vorbis,vp8".
553 size_t semicolon = mimetype_.find(";");
554 std::string type = mimetype_;
555 std::vector<std::string> codecs;
556 if (semicolon != std::string::npos) {
557 type = mimetype_.substr(0, semicolon);
558 size_t codecs_param_start = mimetype_.find("codecs=\"", semicolon);
560 CHECK_NE(codecs_param_start, std::string::npos);
562 codecs_param_start += 8; // Skip over the codecs=".
564 size_t codecs_param_end = mimetype_.find("\"", codecs_param_start);
566 CHECK_NE(codecs_param_end, std::string::npos);
568 std::string codecs_param =
569 mimetype_.substr(codecs_param_start,
570 codecs_param_end - codecs_param_start);
571 codecs = base::SplitString(
572 codecs_param, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
575 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk);
577 AppendData(initial_append_size_);
580 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
581 const std::vector<uint8_t>& init_data) {
582 DCHECK(!init_data.empty());
583 CHECK(!encrypted_media_init_data_cb_.is_null());
584 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
587 base::TimeDelta last_timestamp_offset() const {
588 return last_timestamp_offset_;
591 MOCK_METHOD0(InitSegmentReceived, void(void));
593 private:
594 scoped_refptr<DecoderBuffer> file_data_;
595 int current_position_;
596 int initial_append_size_;
597 std::string mimetype_;
598 ChunkDemuxer* chunk_demuxer_;
599 scoped_ptr<Demuxer> owned_chunk_demuxer_;
600 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
601 base::TimeDelta last_timestamp_offset_;
604 #if defined(MOJO_RENDERER)
605 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase,
606 public PipelineIntegrationTestBase {
607 public:
608 bool ShouldCreateDefaultRunLoop() override { return false; }
610 void SetUp() override {
611 ApplicationTestBase::SetUp();
612 InitializeMediaLibrary();
615 protected:
616 scoped_ptr<Renderer> CreateRenderer() override {
617 mojo::URLRequestPtr request(mojo::URLRequest::New());
618 request->url = mojo::String::From("mojo:media");
619 mojo::ServiceProvider* service_provider =
620 application_impl()
621 ->ConnectToApplication(request.Pass())
622 ->GetServiceProvider();
624 mojo::ConnectToService(service_provider, &media_service_factory_);
626 interfaces::RendererPtr mojo_renderer;
627 media_service_factory_->CreateRenderer(mojo::GetProxy(&mojo_renderer));
629 return make_scoped_ptr(new MojoRendererImpl(message_loop_.task_runner(),
630 mojo_renderer.Pass()));
633 private:
634 interfaces::ServiceFactoryPtr media_service_factory_;
636 #else
637 class PipelineIntegrationTestHost : public testing::Test,
638 public PipelineIntegrationTestBase {};
639 #endif
641 class PipelineIntegrationTest : public PipelineIntegrationTestHost {
642 public:
643 void StartPipelineWithMediaSource(MockMediaSource* source) {
644 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
645 EXPECT_CALL(*this, OnMetadata(_))
646 .Times(AtMost(1))
647 .WillRepeatedly(SaveArg<0>(&metadata_));
648 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
649 .Times(AnyNumber());
650 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
651 .Times(AnyNumber());
653 // Encrypted content not used, so this is never called.
654 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
656 demuxer_ = source->GetDemuxer().Pass();
657 pipeline_->Start(
658 demuxer_.get(), CreateRenderer(),
659 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
660 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
661 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
662 base::Unretained(this)),
663 base::Bind(&PipelineIntegrationTest::OnMetadata,
664 base::Unretained(this)),
665 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
666 base::Unretained(this)),
667 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
668 base::Unretained(this)),
669 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
670 base::Unretained(this)));
671 message_loop_.Run();
672 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
675 void StartHashedPipelineWithMediaSource(MockMediaSource* source) {
676 hashing_enabled_ = true;
677 StartPipelineWithMediaSource(source);
680 void StartPipelineWithEncryptedMedia(
681 MockMediaSource* source,
682 FakeEncryptedMedia* encrypted_media) {
683 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
684 EXPECT_CALL(*this, OnMetadata(_))
685 .Times(AtMost(1))
686 .WillRepeatedly(SaveArg<0>(&metadata_));
687 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
688 .Times(AnyNumber());
689 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
690 .Times(AnyNumber());
691 EXPECT_CALL(*this, DecryptorAttached(true));
693 // Encrypted content used but keys provided in advance, so this is
694 // never called.
695 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
697 demuxer_ = source->GetDemuxer().Pass();
699 pipeline_->SetCdm(encrypted_media->GetCdmContext(),
700 base::Bind(&PipelineIntegrationTest::DecryptorAttached,
701 base::Unretained(this)));
703 pipeline_->Start(
704 demuxer_.get(), CreateRenderer(),
705 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
706 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
707 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
708 base::Unretained(this)),
709 base::Bind(&PipelineIntegrationTest::OnMetadata,
710 base::Unretained(this)),
711 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
712 base::Unretained(this)),
713 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
714 base::Unretained(this)),
715 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
716 base::Unretained(this)));
718 source->set_encrypted_media_init_data_cb(
719 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
720 base::Unretained(encrypted_media)));
722 message_loop_.Run();
723 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
726 // Verifies that seeking works properly for ChunkDemuxer when the
727 // seek happens while there is a pending read on the ChunkDemuxer
728 // and no data is available.
729 bool TestSeekDuringRead(const std::string& filename,
730 const std::string& mimetype,
731 int initial_append_size,
732 base::TimeDelta start_seek_time,
733 base::TimeDelta seek_time,
734 int seek_file_position,
735 int seek_append_size) {
736 MockMediaSource source(filename, mimetype, initial_append_size);
737 StartPipelineWithMediaSource(&source);
739 if (pipeline_status_ != PIPELINE_OK)
740 return false;
742 Play();
743 if (!WaitUntilCurrentTimeIsAfter(start_seek_time))
744 return false;
746 source.Seek(seek_time, seek_file_position, seek_append_size);
747 if (!Seek(seek_time))
748 return false;
750 source.EndOfStream();
752 source.Abort();
753 Stop();
754 return true;
758 TEST_F(PipelineIntegrationTest, BasicPlayback) {
759 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
761 Play();
763 ASSERT_TRUE(WaitUntilOnEnded());
766 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) {
767 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg"));
769 Play();
771 ASSERT_TRUE(WaitUntilOnEnded());
774 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
775 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed));
777 Play();
779 ASSERT_TRUE(WaitUntilOnEnded());
781 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
782 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
783 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
786 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) {
787 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed));
789 Play();
791 ASSERT_TRUE(WaitUntilOnEnded());
793 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
794 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
796 // TODO: Fix FFmpeg code to return higher resolution time values so
797 // we don't have to truncate our expectations here.
798 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
799 demuxer_->GetTimelineOffset());
802 TEST_F(PipelineIntegrationTest, F32PlaybackHashed) {
803 ASSERT_EQ(PIPELINE_OK, Start("sfx_f32le.wav", kHashed));
804 Play();
805 ASSERT_TRUE(WaitUntilOnEnded());
806 EXPECT_HASH_EQ(std::string(kNullVideoHash), GetVideoHash());
807 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
810 #if !defined(DISABLE_EME_TESTS)
811 TEST_F(PipelineIntegrationTest, BasicPlaybackEncrypted) {
812 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
813 set_encrypted_media_init_data_cb(
814 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
815 base::Unretained(&encrypted_media)));
817 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-av_enc-av.webm",
818 encrypted_media.GetCdmContext()));
820 Play();
822 ASSERT_TRUE(WaitUntilOnEnded());
823 Stop();
825 #endif // !defined(DISABLE_EME_TESTS)
827 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource) {
828 MockMediaSource source("bear-320x240.webm", kWebM, 219229);
829 StartPipelineWithMediaSource(&source);
830 source.EndOfStream();
832 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
833 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
834 EXPECT_EQ(k320WebMFileDurationMs,
835 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
837 Play();
839 ASSERT_TRUE(WaitUntilOnEnded());
841 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
842 source.Abort();
843 Stop();
846 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Live) {
847 MockMediaSource source("bear-320x240-live.webm", kWebM, 219221);
848 StartPipelineWithMediaSource(&source);
849 source.EndOfStream();
851 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
852 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
853 EXPECT_EQ(k320WebMFileDurationMs,
854 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
856 Play();
858 ASSERT_TRUE(WaitUntilOnEnded());
860 EXPECT_EQ(kLiveTimelineOffset(),
861 demuxer_->GetTimelineOffset());
862 source.Abort();
863 Stop();
866 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP9_WebM) {
867 MockMediaSource source("bear-vp9.webm", kWebMVP9, 67504);
868 StartPipelineWithMediaSource(&source);
869 source.EndOfStream();
871 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
872 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
873 EXPECT_EQ(kVP9WebMFileDurationMs,
874 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
876 Play();
878 ASSERT_TRUE(WaitUntilOnEnded());
879 source.Abort();
880 Stop();
883 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP8A_WebM) {
884 MockMediaSource source("bear-vp8a.webm", kVideoOnlyWebM, kAppendWholeFile);
885 StartPipelineWithMediaSource(&source);
886 source.EndOfStream();
888 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
889 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
890 EXPECT_EQ(kVP8AWebMFileDurationMs,
891 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
893 Play();
895 ASSERT_TRUE(WaitUntilOnEnded());
896 source.Abort();
897 Stop();
900 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus_WebM) {
901 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
902 kAppendWholeFile);
903 StartPipelineWithMediaSource(&source);
904 source.EndOfStream();
906 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
907 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
908 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
909 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
910 Play();
912 ASSERT_TRUE(WaitUntilOnEnded());
913 source.Abort();
914 Stop();
917 // Flaky. http://crbug.com/304776
918 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) {
919 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
920 kAppendWholeFile);
921 StartHashedPipelineWithMediaSource(&source);
923 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
924 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
925 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
926 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
928 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000);
929 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
931 Play();
932 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
933 source.Seek(seek_time, 0x1D5, 34017);
934 source.EndOfStream();
935 ASSERT_TRUE(Seek(seek_time));
937 ASSERT_TRUE(WaitUntilOnEnded());
939 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
941 source.Abort();
942 Stop();
945 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) {
946 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
947 kAppendWholeFile);
948 StartPipelineWithMediaSource(&source);
950 scoped_refptr<DecoderBuffer> second_file =
951 ReadTestDataFile("bear-640x360.webm");
953 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
954 second_file->data(), second_file->data_size());
956 source.EndOfStream();
958 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
959 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
960 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
961 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
963 Play();
965 EXPECT_TRUE(WaitUntilOnEnded());
966 source.Abort();
967 Stop();
970 #if !defined(DISABLE_EME_TESTS)
971 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) {
972 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
973 kAppendWholeFile);
974 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
975 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
977 scoped_refptr<DecoderBuffer> second_file =
978 ReadTestDataFile("bear-640x360-av_enc-av.webm");
980 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
981 second_file->data(), second_file->data_size());
983 source.EndOfStream();
985 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
986 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
987 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
988 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
990 Play();
992 EXPECT_TRUE(WaitUntilOnEnded());
993 source.Abort();
994 Stop();
997 // Config changes from encrypted to clear are not currently supported.
998 TEST_F(PipelineIntegrationTest,
999 MediaSource_ConfigChange_ClearThenEncrypted_WebM) {
1000 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1001 kAppendWholeFile);
1002 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1003 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1005 scoped_refptr<DecoderBuffer> second_file =
1006 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1008 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1009 second_file->data(), second_file->data_size());
1011 source.EndOfStream();
1013 message_loop_.Run();
1014 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1016 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1017 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1018 // The second video was not added, so its time has not been added.
1019 EXPECT_EQ(k320WebMFileDurationMs,
1020 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1022 Play();
1024 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1025 source.Abort();
1028 // Config changes from clear to encrypted are not currently supported.
1029 TEST_F(PipelineIntegrationTest,
1030 MediaSource_ConfigChange_EncryptedThenClear_WebM) {
1031 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1032 kAppendWholeFile);
1033 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1034 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1036 scoped_refptr<DecoderBuffer> second_file =
1037 ReadTestDataFile("bear-640x360.webm");
1039 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1040 second_file->data(), second_file->data_size());
1042 source.EndOfStream();
1044 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1045 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1046 // The second video was not added, so its time has not been added.
1047 EXPECT_EQ(k320EncWebMFileDurationMs,
1048 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1050 Play();
1052 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1053 source.Abort();
1055 #endif // !defined(DISABLE_EME_TESTS)
1057 #if defined(USE_PROPRIETARY_CODECS)
1058 TEST_F(PipelineIntegrationTest, MediaSource_ADTS) {
1059 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1060 StartPipelineWithMediaSource(&source);
1061 source.EndOfStream();
1063 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1064 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1065 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1067 Play();
1069 EXPECT_TRUE(WaitUntilOnEnded());
1072 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) {
1073 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1074 StartHashedPipelineWithMediaSource(&source);
1075 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds());
1077 // Trim off multiple frames off the beginning of the segment which will cause
1078 // the first decoded frame to be incorrect if preroll isn't implemented.
1079 const base::TimeDelta adts_preroll_duration =
1080 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1081 const base::TimeDelta append_time =
1082 source.last_timestamp_offset() - adts_preroll_duration;
1084 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts");
1085 source.AppendAtTimeWithWindow(append_time,
1086 append_time + adts_preroll_duration,
1087 kInfiniteDuration(),
1088 second_file->data(),
1089 second_file->data_size());
1090 source.EndOfStream();
1092 EXPECT_EQ(592, source.last_timestamp_offset().InMilliseconds());
1093 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1094 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1095 EXPECT_EQ(592, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1097 Play();
1099 EXPECT_TRUE(WaitUntilOnEnded());
1101 // Verify preroll is stripped.
1102 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1105 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed_MP3) {
1106 ASSERT_EQ(PIPELINE_OK, Start("sfx.mp3", kHashed));
1108 Play();
1110 ASSERT_TRUE(WaitUntilOnEnded());
1112 // Verify codec delay and preroll are stripped.
1113 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1116 TEST_F(PipelineIntegrationTest, MediaSource_MP3) {
1117 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1118 StartHashedPipelineWithMediaSource(&source);
1119 source.EndOfStream();
1121 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1122 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1123 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1125 Play();
1127 EXPECT_TRUE(WaitUntilOnEnded());
1129 // Verify that codec delay was stripped.
1130 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1133 TEST_F(PipelineIntegrationTest, MediaSource_MP3_TimestampOffset) {
1134 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1135 StartPipelineWithMediaSource(&source);
1136 EXPECT_EQ(313, source.last_timestamp_offset().InMilliseconds());
1138 // There are 576 silent frames at the start of this mp3. The second append
1139 // should trim them off.
1140 const base::TimeDelta mp3_preroll_duration =
1141 base::TimeDelta::FromSecondsD(576.0 / 44100);
1142 const base::TimeDelta append_time =
1143 source.last_timestamp_offset() - mp3_preroll_duration;
1145 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.mp3");
1146 source.AppendAtTimeWithWindow(append_time,
1147 append_time + mp3_preroll_duration,
1148 kInfiniteDuration(),
1149 second_file->data(),
1150 second_file->data_size());
1151 source.EndOfStream();
1153 EXPECT_EQ(613, source.last_timestamp_offset().InMilliseconds());
1154 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1155 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1156 EXPECT_EQ(613, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1158 Play();
1160 EXPECT_TRUE(WaitUntilOnEnded());
1163 TEST_F(PipelineIntegrationTest, MediaSource_MP3_Icecast) {
1164 MockMediaSource source("icy_sfx.mp3", kMP3, kAppendWholeFile);
1165 StartPipelineWithMediaSource(&source);
1166 source.EndOfStream();
1168 Play();
1170 EXPECT_TRUE(WaitUntilOnEnded());
1173 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_MP4) {
1174 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4, kAppendWholeFile);
1175 StartPipelineWithMediaSource(&source);
1177 scoped_refptr<DecoderBuffer> second_file =
1178 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1180 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1181 second_file->data(), second_file->data_size());
1183 source.EndOfStream();
1185 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1186 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1187 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1188 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1190 Play();
1192 EXPECT_TRUE(WaitUntilOnEnded());
1193 source.Abort();
1194 Stop();
1197 #if !defined(DISABLE_EME_TESTS)
1198 TEST_F(PipelineIntegrationTest,
1199 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly) {
1200 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1201 kAppendWholeFile);
1202 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1203 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1205 scoped_refptr<DecoderBuffer> second_file =
1206 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1208 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1209 second_file->data(), second_file->data_size());
1211 source.EndOfStream();
1213 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1214 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1215 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1216 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1218 Play();
1220 EXPECT_TRUE(WaitUntilOnEnded());
1221 source.Abort();
1222 Stop();
1225 TEST_F(PipelineIntegrationTest,
1226 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1227 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video,
1228 kAppendWholeFile);
1229 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1230 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1232 scoped_refptr<DecoderBuffer> second_file =
1233 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1235 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1236 second_file->data(), second_file->data_size());
1238 source.EndOfStream();
1240 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1241 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1242 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1243 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1245 Play();
1247 EXPECT_TRUE(WaitUntilOnEnded());
1248 source.Abort();
1249 Stop();
1252 // Config changes from clear to encrypted are not currently supported.
1253 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1254 TEST_F(PipelineIntegrationTest,
1255 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1256 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1257 kAppendWholeFile);
1258 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1259 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1261 scoped_refptr<DecoderBuffer> second_file =
1262 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1264 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1265 second_file->data(), second_file->data_size());
1267 source.EndOfStream();
1269 message_loop_.Run();
1270 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1272 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1273 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1274 // The second video was not added, so its time has not been added.
1275 EXPECT_EQ(k640IsoFileDurationMs,
1276 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1278 Play();
1280 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1281 source.Abort();
1284 // Config changes from encrypted to clear are not currently supported.
1285 TEST_F(PipelineIntegrationTest,
1286 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC) {
1287 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1288 kAppendWholeFile);
1289 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1290 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1292 scoped_refptr<DecoderBuffer> second_file =
1293 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1295 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1296 second_file->data(), second_file->data_size());
1298 source.EndOfStream();
1300 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1301 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1302 // The second video was not added, so its time has not been added.
1303 EXPECT_EQ(k640IsoCencFileDurationMs,
1304 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1306 Play();
1308 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1309 source.Abort();
1311 #endif // !defined(DISABLE_EME_TESTS)
1313 // Verify files which change configuration midstream fail gracefully.
1314 TEST_F(PipelineIntegrationTest, MidStreamConfigChangesFail) {
1315 ASSERT_EQ(PIPELINE_OK, Start("midstream_config_change.mp3"));
1316 Play();
1317 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE);
1320 #endif
1322 TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) {
1323 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-16x9-aspect.webm"));
1324 Play();
1325 ASSERT_TRUE(WaitUntilOnEnded());
1328 #if !defined(DISABLE_EME_TESTS)
1329 TEST_F(PipelineIntegrationTest, EncryptedPlayback_WebM) {
1330 MockMediaSource source("bear-320x240-av_enc-av.webm", kWebM, 219816);
1331 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1332 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1334 source.EndOfStream();
1335 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1337 Play();
1339 ASSERT_TRUE(WaitUntilOnEnded());
1340 source.Abort();
1341 Stop();
1344 TEST_F(PipelineIntegrationTest, EncryptedPlayback_ClearStart_WebM) {
1345 MockMediaSource source("bear-320x240-av_enc-av_clear-1s.webm", kWebM,
1346 kAppendWholeFile);
1347 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1348 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1350 source.EndOfStream();
1351 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1353 Play();
1355 ASSERT_TRUE(WaitUntilOnEnded());
1356 source.Abort();
1357 Stop();
1360 TEST_F(PipelineIntegrationTest, EncryptedPlayback_NoEncryptedFrames_WebM) {
1361 MockMediaSource source("bear-320x240-av_enc-av_clear-all.webm", kWebM,
1362 kAppendWholeFile);
1363 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1364 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1366 source.EndOfStream();
1367 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1369 Play();
1371 ASSERT_TRUE(WaitUntilOnEnded());
1372 source.Abort();
1373 Stop();
1375 #endif // !defined(DISABLE_EME_TESTS)
1377 #if defined(USE_PROPRIETARY_CODECS)
1378 #if !defined(DISABLE_EME_TESTS)
1379 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_VideoOnly) {
1380 MockMediaSource source("bear-1280x720-v_frag-cenc.mp4", kMP4Video,
1381 kAppendWholeFile);
1382 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1383 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1385 source.EndOfStream();
1386 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1388 Play();
1390 ASSERT_TRUE(WaitUntilOnEnded());
1391 source.Abort();
1392 Stop();
1395 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_AudioOnly) {
1396 MockMediaSource source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio,
1397 kAppendWholeFile);
1398 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1399 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1401 source.EndOfStream();
1402 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1404 Play();
1406 ASSERT_TRUE(WaitUntilOnEnded());
1407 source.Abort();
1408 Stop();
1411 TEST_F(PipelineIntegrationTest,
1412 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly) {
1413 MockMediaSource source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video,
1414 kAppendWholeFile);
1415 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1416 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1418 source.EndOfStream();
1419 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1421 Play();
1423 ASSERT_TRUE(WaitUntilOnEnded());
1424 source.Abort();
1425 Stop();
1428 TEST_F(PipelineIntegrationTest,
1429 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly) {
1430 MockMediaSource source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio,
1431 kAppendWholeFile);
1432 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1433 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1435 source.EndOfStream();
1436 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1438 Play();
1440 ASSERT_TRUE(WaitUntilOnEnded());
1441 source.Abort();
1442 Stop();
1445 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1446 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1447 kMP4Video, kAppendWholeFile);
1448 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1449 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1451 source.EndOfStream();
1452 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1454 Play();
1456 ASSERT_TRUE(WaitUntilOnEnded());
1457 source.Abort();
1458 Stop();
1461 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1462 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1463 kMP4Audio, kAppendWholeFile);
1464 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1465 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1467 source.EndOfStream();
1468 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1470 Play();
1472 ASSERT_TRUE(WaitUntilOnEnded());
1473 source.Abort();
1474 Stop();
1476 #endif // !defined(DISABLE_EME_TESTS)
1478 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3) {
1479 MockMediaSource source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3,
1480 kAppendWholeFile);
1481 StartPipelineWithMediaSource(&source);
1482 source.EndOfStream();
1484 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1485 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1486 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1487 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1489 Play();
1491 ASSERT_TRUE(WaitUntilOnEnded());
1492 source.Abort();
1493 Stop();
1495 #endif // defined(USE_PROPRIETARY_CODECS)
1497 TEST_F(PipelineIntegrationTest, SeekWhilePaused) {
1498 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1500 base::TimeDelta duration(pipeline_->GetMediaDuration());
1501 base::TimeDelta start_seek_time(duration / 4);
1502 base::TimeDelta seek_time(duration * 3 / 4);
1504 Play();
1505 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1506 Pause();
1507 ASSERT_TRUE(Seek(seek_time));
1508 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1509 Play();
1510 ASSERT_TRUE(WaitUntilOnEnded());
1512 // Make sure seeking after reaching the end works as expected.
1513 Pause();
1514 ASSERT_TRUE(Seek(seek_time));
1515 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1516 Play();
1517 ASSERT_TRUE(WaitUntilOnEnded());
1520 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) {
1521 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1523 base::TimeDelta duration(pipeline_->GetMediaDuration());
1524 base::TimeDelta start_seek_time(duration / 4);
1525 base::TimeDelta seek_time(duration * 3 / 4);
1527 Play();
1528 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1529 ASSERT_TRUE(Seek(seek_time));
1530 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1531 ASSERT_TRUE(WaitUntilOnEnded());
1533 // Make sure seeking after reaching the end works as expected.
1534 ASSERT_TRUE(Seek(seek_time));
1535 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1536 ASSERT_TRUE(WaitUntilOnEnded());
1539 #if defined(USE_PROPRIETARY_CODECS)
1540 TEST_F(PipelineIntegrationTest, Rotated_Metadata_0) {
1541 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_0.mp4"));
1542 ASSERT_EQ(VIDEO_ROTATION_0, metadata_.video_rotation);
1545 TEST_F(PipelineIntegrationTest, Rotated_Metadata_90) {
1546 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_90.mp4"));
1547 ASSERT_EQ(VIDEO_ROTATION_90, metadata_.video_rotation);
1550 TEST_F(PipelineIntegrationTest, Rotated_Metadata_180) {
1551 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_180.mp4"));
1552 ASSERT_EQ(VIDEO_ROTATION_180, metadata_.video_rotation);
1555 TEST_F(PipelineIntegrationTest, Rotated_Metadata_270) {
1556 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_270.mp4"));
1557 ASSERT_EQ(VIDEO_ROTATION_270, metadata_.video_rotation);
1559 #endif
1561 // Verify audio decoder & renderer can handle aborted demuxer reads.
1562 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) {
1563 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM,
1564 16384,
1565 base::TimeDelta::FromMilliseconds(464),
1566 base::TimeDelta::FromMilliseconds(617),
1567 0x10CA, 19730));
1570 // Verify video decoder & renderer can handle aborted demuxer reads.
1571 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
1572 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM,
1573 32768,
1574 base::TimeDelta::FromMilliseconds(167),
1575 base::TimeDelta::FromMilliseconds(1668),
1576 0x1C896, 65536));
1579 // Verify that Opus audio in WebM containers can be played back.
1580 TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
1581 ASSERT_EQ(PIPELINE_OK, Start("bear-opus-end-trimming.webm"));
1582 Play();
1583 ASSERT_TRUE(WaitUntilOnEnded());
1586 // Verify that VP9 video in WebM containers can be played back.
1587 TEST_F(PipelineIntegrationTest, BasicPlayback_VideoOnly_VP9_WebM) {
1588 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
1589 Play();
1590 ASSERT_TRUE(WaitUntilOnEnded());
1593 // Verify that VP9 video and Opus audio in the same WebM container can be played
1594 // back.
1595 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Opus_WebM) {
1596 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-opus.webm"));
1597 Play();
1598 ASSERT_TRUE(WaitUntilOnEnded());
1601 // Verify that VP8 video with alpha channel can be played back.
1602 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_WebM) {
1603 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a.webm"));
1604 Play();
1605 ASSERT_TRUE(WaitUntilOnEnded());
1606 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1609 // Verify that VP8A video with odd width/height can be played back.
1610 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_Odd_WebM) {
1611 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a-odd-dimensions.webm"));
1612 Play();
1613 ASSERT_TRUE(WaitUntilOnEnded());
1614 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1617 // Verify that VP9 video with odd width/height can be played back.
1618 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Odd_WebM) {
1619 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-odd-dimensions.webm"));
1620 Play();
1621 ASSERT_TRUE(WaitUntilOnEnded());
1624 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1625 // Verify that VP8 video with inband text track can be played back.
1626 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) {
1627 EXPECT_CALL(*this, OnAddTextTrack(_, _));
1628 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8-webvtt.webm"));
1629 Play();
1630 ASSERT_TRUE(WaitUntilOnEnded());
1632 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1634 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1635 TEST_F(PipelineIntegrationTest, P444_VP9_WebM) {
1636 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-P444.webm"));
1637 Play();
1638 ASSERT_TRUE(WaitUntilOnEnded());
1639 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV24);
1642 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1643 // format.
1644 TEST_F(PipelineIntegrationTest, BT709_VP9_WebM) {
1645 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-bt709.webm"));
1646 Play();
1647 ASSERT_TRUE(WaitUntilOnEnded());
1648 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12);
1649 EXPECT_COLOR_SPACE_EQ(last_video_frame_color_space_, COLOR_SPACE_HD_REC709);
1652 // Verify that videos with an odd frame size playback successfully.
1653 TEST_F(PipelineIntegrationTest, BasicPlayback_OddVideoSize) {
1654 ASSERT_EQ(PIPELINE_OK, Start("butterfly-853x480.webm"));
1655 Play();
1656 ASSERT_TRUE(WaitUntilOnEnded());
1659 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1660 // correctly at 48kHz
1661 TEST_F(PipelineIntegrationTest, BasicPlayback_Opus441kHz) {
1662 ASSERT_EQ(PIPELINE_OK, Start("sfx-opus-441.webm"));
1663 Play();
1664 ASSERT_TRUE(WaitUntilOnEnded());
1665 EXPECT_EQ(48000,
1666 demuxer_->GetStream(DemuxerStream::AUDIO)
1667 ->audio_decoder_config()
1668 .samples_per_second());
1671 // Same as above but using MediaSource.
1672 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus441kHz) {
1673 MockMediaSource source(
1674 "sfx-opus-441.webm", kOpusAudioOnlyWebM, kAppendWholeFile);
1675 StartPipelineWithMediaSource(&source);
1676 source.EndOfStream();
1677 Play();
1678 ASSERT_TRUE(WaitUntilOnEnded());
1679 source.Abort();
1680 Stop();
1681 EXPECT_EQ(48000,
1682 demuxer_->GetStream(DemuxerStream::AUDIO)
1683 ->audio_decoder_config()
1684 .samples_per_second());
1687 // Ensures audio-only playback with missing or negative timestamps works. Tests
1688 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1689 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOgg) {
1690 ASSERT_EQ(PIPELINE_OK, Start("double-sfx.ogg"));
1691 Play();
1692 ASSERT_TRUE(WaitUntilOnEnded());
1693 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1696 // Ensures audio-video playback with missing or negative timestamps fails softly
1697 // instead of crashing. See http://crbug.com/396864.
1698 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOggVideo) {
1699 ASSERT_EQ(PIPELINE_OK, Start("double-bear.ogv"));
1700 Play();
1701 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1702 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1705 // Tests that we signal ended even when audio runs longer than video track.
1706 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioLongerThanVideo) {
1707 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv"));
1708 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1709 // of the two.
1710 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds());
1711 Play();
1712 ASSERT_TRUE(WaitUntilOnEnded());
1715 // Tests that we signal ended even when audio runs shorter than video track.
1716 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioShorterThanVideo) {
1717 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv"));
1718 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1719 // the two.
1720 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds());
1721 Play();
1722 ASSERT_TRUE(WaitUntilOnEnded());
1725 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
1726 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
1727 Play();
1728 ASSERT_TRUE(WaitUntilOnEnded());
1729 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1730 demuxer_->GetStartTime());
1733 } // namespace media