Fork the mojo shell interfaces used by Mandoline.
[chromium-blink-merge.git] / media / test / pipeline_integration_test.cc
blob5af6938e449ebab685e82a1da1aed09c3ce67b96
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_util.h"
10 #include "build/build_config.h"
11 #include "media/base/cdm_callback_promise.h"
12 #include "media/base/cdm_context.h"
13 #include "media/base/cdm_key_information.h"
14 #include "media/base/decoder_buffer.h"
15 #include "media/base/media.h"
16 #include "media/base/media_keys.h"
17 #include "media/base/media_switches.h"
18 #include "media/base/test_data_util.h"
19 #include "media/cdm/aes_decryptor.h"
20 #include "media/cdm/json_web_key.h"
21 #include "media/filters/chunk_demuxer.h"
22 #include "media/renderers/renderer_impl.h"
23 #include "media/test/pipeline_integration_test_base.h"
24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "url/gurl.h"
27 #if defined(MOJO_RENDERER)
28 #include "media/mojo/services/mojo_renderer_impl.h"
29 #include "mojo/application/public/cpp/application_impl.h"
30 #include "mojo/application/public/cpp/application_test_base.h"
31 #include "mojo/application/public/cpp/connect.h"
33 // TODO(dalecurtis): The mojo renderer is in another process, so we have no way
34 // currently to get hashes for video and audio samples. This also means that
35 // real audio plays out for each test.
36 #define EXPECT_HASH_EQ(a, b)
37 #define EXPECT_VIDEO_FORMAT_EQ(a, b)
39 // TODO(xhwang): EME support is not complete for the mojo renderer, so all
40 // encrypted tests are currently disabled.
41 #define DISABLE_EME_TESTS 1
43 // TODO(xhwang,dalecurtis): Text tracks are not currently supported by the mojo
44 // renderer.
45 #define DISABLE_TEXT_TRACK_TESTS 1
46 #else
47 #define EXPECT_HASH_EQ(a, b) EXPECT_EQ(a, b)
48 #define EXPECT_VIDEO_FORMAT_EQ(a, b) EXPECT_EQ(a, b)
49 #endif
51 using testing::_;
52 using testing::AnyNumber;
53 using testing::AtLeast;
54 using testing::AtMost;
55 using testing::SaveArg;
57 namespace media {
59 const char kSourceId[] = "SourceId";
61 const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\"";
62 const char kWebMVP9[] = "video/webm; codecs=\"vp9\"";
63 const char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\"";
64 const char kOpusAudioOnlyWebM[] = "video/webm; codecs=\"opus\"";
65 const char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\"";
66 #if defined(USE_PROPRIETARY_CODECS)
67 const char kADTS[] = "audio/aac";
68 const char kMP4[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\"";
69 const char kMP4VideoAVC3[] = "video/mp4; codecs=\"avc3.64001f\"";
70 #if !defined(DISABLE_EME_TESTS)
71 const char kMP4Video[] = "video/mp4; codecs=\"avc1.4D4041\"";
72 const char kMP4Audio[] = "audio/mp4; codecs=\"mp4a.40.2\"";
73 #endif // !defined(DISABLE_EME_TESTS)
74 const char kMP3[] = "audio/mpeg";
75 #endif // defined(USE_PROPRIETARY_CODECS)
77 // Key used to encrypt test files.
78 const uint8 kSecretKey[] = {
79 0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
80 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
83 // The key ID for all encrypted files.
84 const uint8 kKeyId[] = {
85 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
86 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
89 const int kAppendWholeFile = -1;
91 // Constants for the Media Source config change tests.
92 const int kAppendTimeSec = 1;
93 const int kAppendTimeMs = kAppendTimeSec * 1000;
94 const int k320WebMFileDurationMs = 2736;
95 #if !defined(DISABLE_EME_TESTS)
96 const int k320EncWebMFileDurationMs = 2737;
97 #endif // !defined(DISABLE_EME_TESTS)
98 const int k640WebMFileDurationMs = 2749;
99 const int kOpusEndTrimmingWebMFileDurationMs = 2741;
100 const int kVP9WebMFileDurationMs = 2736;
101 const int kVP8AWebMFileDurationMs = 2734;
103 #if defined(USE_PROPRIETARY_CODECS)
104 #if !defined(DISABLE_EME_TESTS)
105 const int k640IsoFileDurationMs = 2737;
106 const int k640IsoCencFileDurationMs = 2736;
107 #endif // !defined(DISABLE_EME_TESTS)
108 const int k1280IsoFileDurationMs = 2736;
109 const int k1280IsoAVC3FileDurationMs = 2736;
110 #endif // defined(USE_PROPRIETARY_CODECS)
112 // Return a timeline offset for bear-320x240-live.webm.
113 static base::Time kLiveTimelineOffset() {
114 // The file contians the following UTC timeline offset:
115 // 2012-11-10 12:34:56.789123456
116 // Since base::Time only has a resolution of microseconds,
117 // construct a base::Time for 2012-11-10 12:34:56.789123.
118 base::Time::Exploded exploded_time;
119 exploded_time.year = 2012;
120 exploded_time.month = 11;
121 exploded_time.day_of_month = 10;
122 exploded_time.hour = 12;
123 exploded_time.minute = 34;
124 exploded_time.second = 56;
125 exploded_time.millisecond = 789;
126 base::Time timeline_offset = base::Time::FromUTCExploded(exploded_time);
128 timeline_offset += base::TimeDelta::FromMicroseconds(123);
130 return timeline_offset;
133 // FFmpeg only supports time a resolution of seconds so this
134 // helper function truncates a base::Time to seconds resolution.
135 static base::Time TruncateToFFmpegTimeResolution(base::Time t) {
136 base::Time::Exploded exploded_time;
137 t.UTCExplode(&exploded_time);
138 exploded_time.millisecond = 0;
140 return base::Time::FromUTCExploded(exploded_time);
143 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
144 // They do not exercise the Decrypting{Audio|Video}Decoder path.
145 class FakeEncryptedMedia {
146 public:
147 // Defines the behavior of the "app" that responds to EME events.
148 class AppBase {
149 public:
150 virtual ~AppBase() {}
152 virtual void OnSessionMessage(const std::string& session_id,
153 MediaKeys::MessageType message_type,
154 const std::vector<uint8>& message,
155 const GURL& legacy_destination_url) = 0;
157 virtual void OnSessionClosed(const std::string& session_id) = 0;
159 virtual void OnSessionKeysChange(const std::string& session_id,
160 bool has_additional_usable_key,
161 CdmKeysInfo keys_info) = 0;
163 // Errors are not expected unless overridden.
164 virtual void OnLegacySessionError(const std::string& session_id,
165 const std::string& error_name,
166 uint32 system_code,
167 const std::string& error_message) {
168 FAIL() << "Unexpected Key Error";
171 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
172 const std::vector<uint8>& init_data,
173 AesDecryptor* decryptor) = 0;
176 FakeEncryptedMedia(AppBase* app)
177 : decryptor_(GURL::EmptyGURL(),
178 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
179 base::Unretained(this)),
180 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
181 base::Unretained(this)),
182 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
183 base::Unretained(this))),
184 cdm_context_(&decryptor_),
185 app_(app) {}
187 CdmContext* GetCdmContext() { return &cdm_context_; }
189 // Callbacks for firing session events. Delegate to |app_|.
190 void OnSessionMessage(const std::string& session_id,
191 MediaKeys::MessageType message_type,
192 const std::vector<uint8>& message,
193 const GURL& legacy_destination_url) {
194 app_->OnSessionMessage(session_id, message_type, message,
195 legacy_destination_url);
198 void OnSessionClosed(const std::string& session_id) {
199 app_->OnSessionClosed(session_id);
202 void OnSessionKeysChange(const std::string& session_id,
203 bool has_additional_usable_key,
204 CdmKeysInfo keys_info) {
205 app_->OnSessionKeysChange(session_id, has_additional_usable_key,
206 keys_info.Pass());
209 void OnLegacySessionError(const std::string& session_id,
210 const std::string& error_name,
211 uint32 system_code,
212 const std::string& error_message) {
213 app_->OnLegacySessionError(session_id, error_name, system_code,
214 error_message);
217 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
218 const std::vector<uint8>& init_data) {
219 app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
222 private:
223 class TestCdmContext : public CdmContext {
224 public:
225 TestCdmContext(Decryptor* decryptor) : decryptor_(decryptor) {}
227 Decryptor* GetDecryptor() final { return decryptor_; }
228 int GetCdmId() const final { return kInvalidCdmId; }
230 private:
231 Decryptor* decryptor_;
234 AesDecryptor decryptor_;
235 TestCdmContext cdm_context_;
236 scoped_ptr<AppBase> app_;
239 enum PromiseResult { RESOLVED, REJECTED };
241 // Provides |kSecretKey| in response to needkey.
242 class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
243 public:
244 KeyProvidingApp() {}
246 void OnResolveWithSession(PromiseResult expected,
247 const std::string& session_id) {
248 EXPECT_EQ(expected, RESOLVED);
249 EXPECT_GT(session_id.length(), 0ul);
250 current_session_id_ = session_id;
253 void OnResolve(PromiseResult expected) {
254 EXPECT_EQ(expected, RESOLVED);
257 void OnReject(PromiseResult expected,
258 media::MediaKeys::Exception exception_code,
259 uint32 system_code,
260 const std::string& error_message) {
261 EXPECT_EQ(expected, REJECTED) << error_message;
264 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
265 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
266 base::Bind(
267 &KeyProvidingApp::OnResolve, base::Unretained(this), expected),
268 base::Bind(
269 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
270 return promise.Pass();
273 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
274 PromiseResult expected) {
275 scoped_ptr<media::NewSessionCdmPromise> promise(
276 new media::CdmCallbackPromise<std::string>(
277 base::Bind(&KeyProvidingApp::OnResolveWithSession,
278 base::Unretained(this),
279 expected),
280 base::Bind(
281 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
282 return promise.Pass();
285 void OnSessionMessage(const std::string& session_id,
286 MediaKeys::MessageType message_type,
287 const std::vector<uint8>& message,
288 const GURL& legacy_destination_url) override {
289 EXPECT_FALSE(session_id.empty());
290 EXPECT_FALSE(message.empty());
291 EXPECT_EQ(current_session_id_, session_id);
294 void OnSessionClosed(const std::string& session_id) override {
295 EXPECT_EQ(current_session_id_, session_id);
298 void OnSessionKeysChange(const std::string& session_id,
299 bool has_additional_usable_key,
300 CdmKeysInfo keys_info) override {
301 EXPECT_EQ(current_session_id_, session_id);
302 EXPECT_EQ(has_additional_usable_key, true);
305 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
306 const std::vector<uint8>& init_data,
307 AesDecryptor* decryptor) override {
308 // Since only 1 session is created, skip the request if the |init_data|
309 // has been seen before (no need to add the same key again).
310 if (init_data == prev_init_data_)
311 return;
312 prev_init_data_ = init_data;
314 if (current_session_id_.empty()) {
315 if (init_data_type == EmeInitDataType::CENC) {
316 // Since the 'cenc' files are not created with proper 'pssh' boxes,
317 // simply pretend that this is a webm file and pass the expected
318 // key ID as the init_data.
319 // http://crbug.com/460308
320 decryptor->CreateSessionAndGenerateRequest(
321 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM,
322 std::vector<uint8>(kKeyId, kKeyId + arraysize(kKeyId)),
323 CreateSessionPromise(RESOLVED));
324 } else {
325 decryptor->CreateSessionAndGenerateRequest(
326 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
327 CreateSessionPromise(RESOLVED));
329 EXPECT_FALSE(current_session_id_.empty());
332 // Clear Key really needs the key ID from |init_data|. For WebM, they are
333 // the same, but this is not the case for ISO CENC (key ID embedded in a
334 // 'pssh' box). Therefore, provide the correct key ID.
335 const uint8* key_id = vector_as_array(&init_data);
336 size_t key_id_length = init_data.size();
337 if (init_data_type == EmeInitDataType::CENC) {
338 key_id = kKeyId;
339 key_id_length = arraysize(kKeyId);
342 // Convert key into a JSON structure and then add it.
343 std::string jwk = GenerateJWKSet(
344 kSecretKey, arraysize(kSecretKey), key_id, key_id_length);
345 decryptor->UpdateSession(current_session_id_,
346 std::vector<uint8>(jwk.begin(), jwk.end()),
347 CreatePromise(RESOLVED));
350 std::string current_session_id_;
351 std::vector<uint8> prev_init_data_;
354 class RotatingKeyProvidingApp : public KeyProvidingApp {
355 public:
356 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {}
357 ~RotatingKeyProvidingApp() override {
358 // Expect that OnEncryptedMediaInitData is fired multiple times with
359 // different |init_data|.
360 EXPECT_GT(num_distint_need_key_calls_, 1u);
363 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
364 const std::vector<uint8>& init_data,
365 AesDecryptor* decryptor) override {
366 // Skip the request if the |init_data| has been seen.
367 if (init_data == prev_init_data_)
368 return;
369 prev_init_data_ = init_data;
370 ++num_distint_need_key_calls_;
372 std::vector<uint8> key_id;
373 std::vector<uint8> key;
374 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id));
376 if (init_data_type == EmeInitDataType::CENC) {
377 // Since the 'cenc' files are not created with proper 'pssh' boxes,
378 // simply pretend that this is a webm file and pass the expected
379 // key ID as the init_data.
380 // http://crbug.com/460308
381 decryptor->CreateSessionAndGenerateRequest(
382 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, key_id,
383 CreateSessionPromise(RESOLVED));
384 } else {
385 decryptor->CreateSessionAndGenerateRequest(
386 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
387 CreateSessionPromise(RESOLVED));
390 // Convert key into a JSON structure and then add it.
391 std::string jwk = GenerateJWKSet(vector_as_array(&key),
392 key.size(),
393 vector_as_array(&key_id),
394 key_id.size());
395 decryptor->UpdateSession(current_session_id_,
396 std::vector<uint8>(jwk.begin(), jwk.end()),
397 CreatePromise(RESOLVED));
400 private:
401 bool GetKeyAndKeyId(std::vector<uint8> init_data,
402 std::vector<uint8>* key,
403 std::vector<uint8>* key_id) {
404 // For WebM, init_data is key_id; for ISO CENC, init_data should contain
405 // the key_id. We assume key_id is in the end of init_data here (that is
406 // only a reasonable assumption for WebM and clear key ISO CENC).
407 DCHECK_GE(init_data.size(), arraysize(kKeyId));
408 std::vector<uint8> key_id_from_init_data(
409 init_data.end() - arraysize(kKeyId), init_data.end());
411 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
412 key_id->assign(kKeyId, kKeyId + arraysize(kKeyId));
414 // The Key and KeyId for this testing key provider are created by left
415 // rotating kSecretKey and kKeyId. Note that this implementation is only
416 // intended for testing purpose. The actual key rotation algorithm can be
417 // much more complicated.
418 // Find out the rotating position from |key_id_from_init_data| and apply on
419 // |key|.
420 for (size_t pos = 0; pos < arraysize(kKeyId); ++pos) {
421 std::rotate(key_id->begin(), key_id->begin() + pos, key_id->end());
422 if (*key_id == key_id_from_init_data) {
423 std::rotate(key->begin(), key->begin() + pos, key->end());
424 return true;
427 return false;
430 std::vector<uint8> prev_init_data_;
431 uint32 num_distint_need_key_calls_;
434 // Ignores needkey and does not perform a license request
435 class NoResponseApp : public FakeEncryptedMedia::AppBase {
436 public:
437 void OnSessionMessage(const std::string& session_id,
438 MediaKeys::MessageType message_type,
439 const std::vector<uint8>& message,
440 const GURL& legacy_destination_url) override {
441 EXPECT_FALSE(session_id.empty());
442 EXPECT_FALSE(message.empty());
443 FAIL() << "Unexpected Message";
446 void OnSessionClosed(const std::string& session_id) override {
447 EXPECT_FALSE(session_id.empty());
448 FAIL() << "Unexpected Closed";
451 void OnSessionKeysChange(const std::string& session_id,
452 bool has_additional_usable_key,
453 CdmKeysInfo keys_info) override {
454 EXPECT_FALSE(session_id.empty());
455 EXPECT_EQ(has_additional_usable_key, true);
458 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
459 const std::vector<uint8>& init_data,
460 AesDecryptor* decryptor) override {}
463 // Helper class that emulates calls made on the ChunkDemuxer by the
464 // Media Source API.
465 class MockMediaSource {
466 public:
467 MockMediaSource(const std::string& filename,
468 const std::string& mimetype,
469 int initial_append_size)
470 : current_position_(0),
471 initial_append_size_(initial_append_size),
472 mimetype_(mimetype),
473 chunk_demuxer_(new ChunkDemuxer(
474 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)),
475 base::Bind(&MockMediaSource::OnEncryptedMediaInitData,
476 base::Unretained(this)),
477 LogCB(),
478 scoped_refptr<MediaLog>(new MediaLog()),
479 true)),
480 owned_chunk_demuxer_(chunk_demuxer_) {
481 file_data_ = ReadTestDataFile(filename);
483 if (initial_append_size_ == kAppendWholeFile)
484 initial_append_size_ = file_data_->data_size();
486 DCHECK_GT(initial_append_size_, 0);
487 DCHECK_LE(initial_append_size_, file_data_->data_size());
490 virtual ~MockMediaSource() {}
492 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); }
494 void set_encrypted_media_init_data_cb(
495 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
496 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
499 void Seek(base::TimeDelta seek_time, int new_position, int seek_append_size) {
500 chunk_demuxer_->StartWaitingForSeek(seek_time);
502 chunk_demuxer_->Abort(
503 kSourceId,
504 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_);
506 DCHECK_GE(new_position, 0);
507 DCHECK_LT(new_position, file_data_->data_size());
508 current_position_ = new_position;
510 AppendData(seek_append_size);
513 void AppendData(int size) {
514 DCHECK(chunk_demuxer_);
515 DCHECK_LT(current_position_, file_data_->data_size());
516 DCHECK_LE(current_position_ + size, file_data_->data_size());
518 chunk_demuxer_->AppendData(
519 kSourceId, file_data_->data() + current_position_, size,
520 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_,
521 base::Bind(&MockMediaSource::InitSegmentReceived,
522 base::Unretained(this)));
523 current_position_ += size;
526 void AppendAtTime(base::TimeDelta timestamp_offset,
527 const uint8* pData,
528 int size) {
529 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
530 chunk_demuxer_->AppendData(kSourceId, pData, size,
531 base::TimeDelta(), kInfiniteDuration(),
532 &timestamp_offset,
533 base::Bind(&MockMediaSource::InitSegmentReceived,
534 base::Unretained(this)));
535 last_timestamp_offset_ = timestamp_offset;
538 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset,
539 base::TimeDelta append_window_start,
540 base::TimeDelta append_window_end,
541 const uint8* pData,
542 int size) {
543 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
544 chunk_demuxer_->AppendData(kSourceId,
545 pData,
546 size,
547 append_window_start,
548 append_window_end,
549 &timestamp_offset,
550 base::Bind(&MockMediaSource::InitSegmentReceived,
551 base::Unretained(this)));
552 last_timestamp_offset_ = timestamp_offset;
555 void EndOfStream() {
556 chunk_demuxer_->MarkEndOfStream(PIPELINE_OK);
559 void Abort() {
560 if (!chunk_demuxer_)
561 return;
562 chunk_demuxer_->Shutdown();
563 chunk_demuxer_ = NULL;
566 void DemuxerOpened() {
567 base::MessageLoop::current()->PostTask(
568 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask,
569 base::Unretained(this)));
572 void DemuxerOpenedTask() {
573 // This code assumes that |mimetype_| is one of the following forms.
574 // 1. audio/mpeg
575 // 2. video/webm;codec="vorbis,vp8".
576 size_t semicolon = mimetype_.find(";");
577 std::string type = mimetype_;
578 std::vector<std::string> codecs;
579 if (semicolon != std::string::npos) {
580 type = mimetype_.substr(0, semicolon);
581 size_t codecs_param_start = mimetype_.find("codecs=\"", semicolon);
583 CHECK_NE(codecs_param_start, std::string::npos);
585 codecs_param_start += 8; // Skip over the codecs=".
587 size_t codecs_param_end = mimetype_.find("\"", codecs_param_start);
589 CHECK_NE(codecs_param_end, std::string::npos);
591 std::string codecs_param =
592 mimetype_.substr(codecs_param_start,
593 codecs_param_end - codecs_param_start);
594 Tokenize(codecs_param, ",", &codecs);
597 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk);
599 AppendData(initial_append_size_);
602 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
603 const std::vector<uint8>& init_data) {
604 DCHECK(!init_data.empty());
605 CHECK(!encrypted_media_init_data_cb_.is_null());
606 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
609 base::TimeDelta last_timestamp_offset() const {
610 return last_timestamp_offset_;
613 MOCK_METHOD0(InitSegmentReceived, void(void));
615 private:
616 scoped_refptr<DecoderBuffer> file_data_;
617 int current_position_;
618 int initial_append_size_;
619 std::string mimetype_;
620 ChunkDemuxer* chunk_demuxer_;
621 scoped_ptr<Demuxer> owned_chunk_demuxer_;
622 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
623 base::TimeDelta last_timestamp_offset_;
626 #if defined(MOJO_RENDERER)
627 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase,
628 public PipelineIntegrationTestBase {
629 public:
630 bool ShouldCreateDefaultRunLoop() override { return false; }
632 void SetUp() override {
633 ApplicationTestBase::SetUp();
634 if (!IsMediaLibraryInitialized())
635 InitializeMediaLibraryForTesting();
638 protected:
639 scoped_ptr<Renderer> CreateRenderer() override {
640 mojo::ServiceProvider* service_provider =
641 application_impl()
642 ->ConnectToApplication("mojo://media")
643 ->GetServiceProvider();
645 mojo::MediaRendererPtr mojo_media_renderer;
646 mojo::ConnectToService(service_provider, &mojo_media_renderer);
647 return make_scoped_ptr(new MojoRendererImpl(message_loop_.task_runner(),
648 mojo_media_renderer.Pass()));
651 #else
652 class PipelineIntegrationTestHost : public testing::Test,
653 public PipelineIntegrationTestBase {};
654 #endif
656 class PipelineIntegrationTest : public PipelineIntegrationTestHost {
657 public:
658 void StartPipelineWithMediaSource(MockMediaSource* source) {
659 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
660 EXPECT_CALL(*this, OnMetadata(_))
661 .Times(AtMost(1))
662 .WillRepeatedly(SaveArg<0>(&metadata_));
663 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
664 .Times(AtMost(1));
666 // Encrypted content not used, so this is never called.
667 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
669 demuxer_ = source->GetDemuxer().Pass();
670 pipeline_->Start(
671 demuxer_.get(), CreateRenderer(),
672 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
673 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
674 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
675 base::Unretained(this)),
676 base::Bind(&PipelineIntegrationTest::OnMetadata,
677 base::Unretained(this)),
678 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
679 base::Unretained(this)),
680 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
681 base::Unretained(this)),
682 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
683 base::Unretained(this)));
684 message_loop_.Run();
685 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
688 void StartHashedPipelineWithMediaSource(MockMediaSource* source) {
689 hashing_enabled_ = true;
690 StartPipelineWithMediaSource(source);
693 void StartPipelineWithEncryptedMedia(
694 MockMediaSource* source,
695 FakeEncryptedMedia* encrypted_media) {
696 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
697 EXPECT_CALL(*this, OnMetadata(_))
698 .Times(AtMost(1))
699 .WillRepeatedly(SaveArg<0>(&metadata_));
700 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
701 .Times(AtMost(1));
702 EXPECT_CALL(*this, DecryptorAttached(true));
704 // Encrypted content used but keys provided in advance, so this is
705 // never called.
706 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
708 demuxer_ = source->GetDemuxer().Pass();
710 pipeline_->SetCdm(encrypted_media->GetCdmContext(),
711 base::Bind(&PipelineIntegrationTest::DecryptorAttached,
712 base::Unretained(this)));
714 pipeline_->Start(
715 demuxer_.get(), CreateRenderer(),
716 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
717 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
718 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
719 base::Unretained(this)),
720 base::Bind(&PipelineIntegrationTest::OnMetadata,
721 base::Unretained(this)),
722 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
723 base::Unretained(this)),
724 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
725 base::Unretained(this)),
726 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
727 base::Unretained(this)));
729 source->set_encrypted_media_init_data_cb(
730 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
731 base::Unretained(encrypted_media)));
733 message_loop_.Run();
734 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
737 // Verifies that seeking works properly for ChunkDemuxer when the
738 // seek happens while there is a pending read on the ChunkDemuxer
739 // and no data is available.
740 bool TestSeekDuringRead(const std::string& filename,
741 const std::string& mimetype,
742 int initial_append_size,
743 base::TimeDelta start_seek_time,
744 base::TimeDelta seek_time,
745 int seek_file_position,
746 int seek_append_size) {
747 MockMediaSource source(filename, mimetype, initial_append_size);
748 StartPipelineWithMediaSource(&source);
750 if (pipeline_status_ != PIPELINE_OK)
751 return false;
753 Play();
754 if (!WaitUntilCurrentTimeIsAfter(start_seek_time))
755 return false;
757 source.Seek(seek_time, seek_file_position, seek_append_size);
758 if (!Seek(seek_time))
759 return false;
761 source.EndOfStream();
763 source.Abort();
764 Stop();
765 return true;
769 TEST_F(PipelineIntegrationTest, BasicPlayback) {
770 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
772 Play();
774 ASSERT_TRUE(WaitUntilOnEnded());
777 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) {
778 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg"));
780 Play();
782 ASSERT_TRUE(WaitUntilOnEnded());
785 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
786 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed));
788 Play();
790 ASSERT_TRUE(WaitUntilOnEnded());
792 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
793 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
794 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
797 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) {
798 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed));
800 Play();
802 ASSERT_TRUE(WaitUntilOnEnded());
804 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
805 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
807 // TODO: Fix FFmpeg code to return higher resolution time values so
808 // we don't have to truncate our expectations here.
809 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
810 demuxer_->GetTimelineOffset());
813 TEST_F(PipelineIntegrationTest, F32PlaybackHashed) {
814 ASSERT_EQ(PIPELINE_OK, Start("sfx_f32le.wav", kHashed));
815 Play();
816 ASSERT_TRUE(WaitUntilOnEnded());
817 EXPECT_HASH_EQ(std::string(kNullVideoHash), GetVideoHash());
818 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
821 #if !defined(DISABLE_EME_TESTS)
822 TEST_F(PipelineIntegrationTest, BasicPlaybackEncrypted) {
823 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
824 set_encrypted_media_init_data_cb(
825 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
826 base::Unretained(&encrypted_media)));
828 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-av_enc-av.webm",
829 encrypted_media.GetCdmContext()));
831 Play();
833 ASSERT_TRUE(WaitUntilOnEnded());
834 Stop();
836 #endif // !defined(DISABLE_EME_TESTS)
838 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource) {
839 MockMediaSource source("bear-320x240.webm", kWebM, 219229);
840 StartPipelineWithMediaSource(&source);
841 source.EndOfStream();
843 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
844 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
845 EXPECT_EQ(k320WebMFileDurationMs,
846 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
848 Play();
850 ASSERT_TRUE(WaitUntilOnEnded());
852 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
853 source.Abort();
854 Stop();
857 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Live) {
858 MockMediaSource source("bear-320x240-live.webm", kWebM, 219221);
859 StartPipelineWithMediaSource(&source);
860 source.EndOfStream();
862 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
863 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
864 EXPECT_EQ(k320WebMFileDurationMs,
865 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
867 Play();
869 ASSERT_TRUE(WaitUntilOnEnded());
871 EXPECT_EQ(kLiveTimelineOffset(),
872 demuxer_->GetTimelineOffset());
873 source.Abort();
874 Stop();
877 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP9_WebM) {
878 MockMediaSource source("bear-vp9.webm", kWebMVP9, 67504);
879 StartPipelineWithMediaSource(&source);
880 source.EndOfStream();
882 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
883 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
884 EXPECT_EQ(kVP9WebMFileDurationMs,
885 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
887 Play();
889 ASSERT_TRUE(WaitUntilOnEnded());
890 source.Abort();
891 Stop();
894 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP8A_WebM) {
895 MockMediaSource source("bear-vp8a.webm", kVideoOnlyWebM, kAppendWholeFile);
896 StartPipelineWithMediaSource(&source);
897 source.EndOfStream();
899 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
900 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
901 EXPECT_EQ(kVP8AWebMFileDurationMs,
902 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
904 Play();
906 ASSERT_TRUE(WaitUntilOnEnded());
907 source.Abort();
908 Stop();
911 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus_WebM) {
912 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
913 kAppendWholeFile);
914 StartPipelineWithMediaSource(&source);
915 source.EndOfStream();
917 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
918 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
919 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
920 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
921 Play();
923 ASSERT_TRUE(WaitUntilOnEnded());
924 source.Abort();
925 Stop();
928 // Flaky. http://crbug.com/304776
929 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) {
930 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
931 kAppendWholeFile);
932 StartHashedPipelineWithMediaSource(&source);
934 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
935 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
936 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
937 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
939 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000);
940 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
942 Play();
943 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
944 source.Seek(seek_time, 0x1D5, 34017);
945 source.EndOfStream();
946 ASSERT_TRUE(Seek(seek_time));
948 ASSERT_TRUE(WaitUntilOnEnded());
950 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
952 source.Abort();
953 Stop();
956 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) {
957 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
958 kAppendWholeFile);
959 StartPipelineWithMediaSource(&source);
961 scoped_refptr<DecoderBuffer> second_file =
962 ReadTestDataFile("bear-640x360.webm");
964 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
965 second_file->data(), second_file->data_size());
967 source.EndOfStream();
969 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
970 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
971 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
972 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
974 Play();
976 EXPECT_TRUE(WaitUntilOnEnded());
977 source.Abort();
978 Stop();
981 #if !defined(DISABLE_EME_TESTS)
982 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) {
983 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
984 kAppendWholeFile);
985 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
986 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
988 scoped_refptr<DecoderBuffer> second_file =
989 ReadTestDataFile("bear-640x360-av_enc-av.webm");
991 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
992 second_file->data(), second_file->data_size());
994 source.EndOfStream();
996 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
997 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
998 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
999 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1001 Play();
1003 EXPECT_TRUE(WaitUntilOnEnded());
1004 source.Abort();
1005 Stop();
1008 // Config changes from encrypted to clear are not currently supported.
1009 TEST_F(PipelineIntegrationTest,
1010 MediaSource_ConfigChange_ClearThenEncrypted_WebM) {
1011 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1012 kAppendWholeFile);
1013 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1014 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1016 scoped_refptr<DecoderBuffer> second_file =
1017 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1019 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1020 second_file->data(), second_file->data_size());
1022 source.EndOfStream();
1024 message_loop_.Run();
1025 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1027 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1028 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1029 // The second video was not added, so its time has not been added.
1030 EXPECT_EQ(k320WebMFileDurationMs,
1031 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1033 Play();
1035 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1036 source.Abort();
1039 // Config changes from clear to encrypted are not currently supported.
1040 TEST_F(PipelineIntegrationTest,
1041 MediaSource_ConfigChange_EncryptedThenClear_WebM) {
1042 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1043 kAppendWholeFile);
1044 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1045 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1047 scoped_refptr<DecoderBuffer> second_file =
1048 ReadTestDataFile("bear-640x360.webm");
1050 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1051 second_file->data(), second_file->data_size());
1053 source.EndOfStream();
1055 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1056 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1057 // The second video was not added, so its time has not been added.
1058 EXPECT_EQ(k320EncWebMFileDurationMs,
1059 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1061 Play();
1063 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1064 source.Abort();
1066 #endif // !defined(DISABLE_EME_TESTS)
1068 #if defined(USE_PROPRIETARY_CODECS)
1069 TEST_F(PipelineIntegrationTest, MediaSource_ADTS) {
1070 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1071 StartPipelineWithMediaSource(&source);
1072 source.EndOfStream();
1074 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1075 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1076 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1078 Play();
1080 EXPECT_TRUE(WaitUntilOnEnded());
1083 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) {
1084 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1085 StartHashedPipelineWithMediaSource(&source);
1086 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds());
1088 // Trim off multiple frames off the beginning of the segment which will cause
1089 // the first decoded frame to be incorrect if preroll isn't implemented.
1090 const base::TimeDelta adts_preroll_duration =
1091 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1092 const base::TimeDelta append_time =
1093 source.last_timestamp_offset() - adts_preroll_duration;
1095 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts");
1096 source.AppendAtTimeWithWindow(append_time,
1097 append_time + adts_preroll_duration,
1098 kInfiniteDuration(),
1099 second_file->data(),
1100 second_file->data_size());
1101 source.EndOfStream();
1103 EXPECT_EQ(592, source.last_timestamp_offset().InMilliseconds());
1104 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1105 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1106 EXPECT_EQ(592, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1108 Play();
1110 EXPECT_TRUE(WaitUntilOnEnded());
1112 // Verify preroll is stripped.
1113 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1116 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed_MP3) {
1117 ASSERT_EQ(PIPELINE_OK, Start("sfx.mp3", kHashed));
1119 Play();
1121 ASSERT_TRUE(WaitUntilOnEnded());
1123 // Verify codec delay and preroll are stripped.
1124 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1127 TEST_F(PipelineIntegrationTest, MediaSource_MP3) {
1128 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1129 StartHashedPipelineWithMediaSource(&source);
1130 source.EndOfStream();
1132 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1133 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1134 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1136 Play();
1138 EXPECT_TRUE(WaitUntilOnEnded());
1140 // Verify that codec delay was stripped.
1141 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1144 TEST_F(PipelineIntegrationTest, MediaSource_MP3_TimestampOffset) {
1145 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1146 StartPipelineWithMediaSource(&source);
1147 EXPECT_EQ(313, source.last_timestamp_offset().InMilliseconds());
1149 // There are 576 silent frames at the start of this mp3. The second append
1150 // should trim them off.
1151 const base::TimeDelta mp3_preroll_duration =
1152 base::TimeDelta::FromSecondsD(576.0 / 44100);
1153 const base::TimeDelta append_time =
1154 source.last_timestamp_offset() - mp3_preroll_duration;
1156 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.mp3");
1157 source.AppendAtTimeWithWindow(append_time,
1158 append_time + mp3_preroll_duration,
1159 kInfiniteDuration(),
1160 second_file->data(),
1161 second_file->data_size());
1162 source.EndOfStream();
1164 EXPECT_EQ(613, source.last_timestamp_offset().InMilliseconds());
1165 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1166 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1167 EXPECT_EQ(613, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1169 Play();
1171 EXPECT_TRUE(WaitUntilOnEnded());
1174 TEST_F(PipelineIntegrationTest, MediaSource_MP3_Icecast) {
1175 MockMediaSource source("icy_sfx.mp3", kMP3, kAppendWholeFile);
1176 StartPipelineWithMediaSource(&source);
1177 source.EndOfStream();
1179 Play();
1181 EXPECT_TRUE(WaitUntilOnEnded());
1184 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_MP4) {
1185 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4, kAppendWholeFile);
1186 StartPipelineWithMediaSource(&source);
1188 scoped_refptr<DecoderBuffer> second_file =
1189 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1191 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1192 second_file->data(), second_file->data_size());
1194 source.EndOfStream();
1196 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1197 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1198 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1199 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1201 Play();
1203 EXPECT_TRUE(WaitUntilOnEnded());
1204 source.Abort();
1205 Stop();
1208 #if !defined(DISABLE_EME_TESTS)
1209 TEST_F(PipelineIntegrationTest,
1210 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly) {
1211 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1212 kAppendWholeFile);
1213 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1214 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1216 scoped_refptr<DecoderBuffer> second_file =
1217 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1219 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1220 second_file->data(), second_file->data_size());
1222 source.EndOfStream();
1224 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1225 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1226 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1227 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1229 Play();
1231 EXPECT_TRUE(WaitUntilOnEnded());
1232 source.Abort();
1233 Stop();
1236 TEST_F(PipelineIntegrationTest,
1237 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1238 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video,
1239 kAppendWholeFile);
1240 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1241 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1243 scoped_refptr<DecoderBuffer> second_file =
1244 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1246 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1247 second_file->data(), second_file->data_size());
1249 source.EndOfStream();
1251 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1252 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1253 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1254 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1256 Play();
1258 EXPECT_TRUE(WaitUntilOnEnded());
1259 source.Abort();
1260 Stop();
1263 // Config changes from clear to encrypted are not currently supported.
1264 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1265 TEST_F(PipelineIntegrationTest,
1266 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1267 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1268 kAppendWholeFile);
1269 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1270 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1272 scoped_refptr<DecoderBuffer> second_file =
1273 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1275 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1276 second_file->data(), second_file->data_size());
1278 source.EndOfStream();
1280 message_loop_.Run();
1281 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1283 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1284 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1285 // The second video was not added, so its time has not been added.
1286 EXPECT_EQ(k640IsoFileDurationMs,
1287 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1289 Play();
1291 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1292 source.Abort();
1295 // Config changes from encrypted to clear are not currently supported.
1296 TEST_F(PipelineIntegrationTest,
1297 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC) {
1298 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1299 kAppendWholeFile);
1300 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1301 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1303 scoped_refptr<DecoderBuffer> second_file =
1304 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1306 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1307 second_file->data(), second_file->data_size());
1309 source.EndOfStream();
1311 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1312 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1313 // The second video was not added, so its time has not been added.
1314 EXPECT_EQ(k640IsoCencFileDurationMs,
1315 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1317 Play();
1319 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1320 source.Abort();
1322 #endif // !defined(DISABLE_EME_TESTS)
1324 // Verify files which change configuration midstream fail gracefully.
1325 TEST_F(PipelineIntegrationTest, MidStreamConfigChangesFail) {
1326 ASSERT_EQ(PIPELINE_OK, Start("midstream_config_change.mp3"));
1327 Play();
1328 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE);
1331 #endif
1333 TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) {
1334 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-16x9-aspect.webm"));
1335 Play();
1336 ASSERT_TRUE(WaitUntilOnEnded());
1339 #if !defined(DISABLE_EME_TESTS)
1340 TEST_F(PipelineIntegrationTest, EncryptedPlayback_WebM) {
1341 MockMediaSource source("bear-320x240-av_enc-av.webm", kWebM, 219816);
1342 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1343 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1345 source.EndOfStream();
1346 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1348 Play();
1350 ASSERT_TRUE(WaitUntilOnEnded());
1351 source.Abort();
1352 Stop();
1355 TEST_F(PipelineIntegrationTest, EncryptedPlayback_ClearStart_WebM) {
1356 MockMediaSource source("bear-320x240-av_enc-av_clear-1s.webm", kWebM,
1357 kAppendWholeFile);
1358 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1359 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1361 source.EndOfStream();
1362 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1364 Play();
1366 ASSERT_TRUE(WaitUntilOnEnded());
1367 source.Abort();
1368 Stop();
1371 TEST_F(PipelineIntegrationTest, EncryptedPlayback_NoEncryptedFrames_WebM) {
1372 MockMediaSource source("bear-320x240-av_enc-av_clear-all.webm", kWebM,
1373 kAppendWholeFile);
1374 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1375 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1377 source.EndOfStream();
1378 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1380 Play();
1382 ASSERT_TRUE(WaitUntilOnEnded());
1383 source.Abort();
1384 Stop();
1386 #endif // !defined(DISABLE_EME_TESTS)
1388 #if defined(USE_PROPRIETARY_CODECS)
1389 #if !defined(DISABLE_EME_TESTS)
1390 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_VideoOnly) {
1391 MockMediaSource source("bear-1280x720-v_frag-cenc.mp4", kMP4Video,
1392 kAppendWholeFile);
1393 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1394 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1396 source.EndOfStream();
1397 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1399 Play();
1401 ASSERT_TRUE(WaitUntilOnEnded());
1402 source.Abort();
1403 Stop();
1406 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_AudioOnly) {
1407 MockMediaSource source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio,
1408 kAppendWholeFile);
1409 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1410 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1412 source.EndOfStream();
1413 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1415 Play();
1417 ASSERT_TRUE(WaitUntilOnEnded());
1418 source.Abort();
1419 Stop();
1422 TEST_F(PipelineIntegrationTest,
1423 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly) {
1424 MockMediaSource source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video,
1425 kAppendWholeFile);
1426 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1427 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1429 source.EndOfStream();
1430 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1432 Play();
1434 ASSERT_TRUE(WaitUntilOnEnded());
1435 source.Abort();
1436 Stop();
1439 TEST_F(PipelineIntegrationTest,
1440 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly) {
1441 MockMediaSource source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio,
1442 kAppendWholeFile);
1443 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1444 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1446 source.EndOfStream();
1447 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1449 Play();
1451 ASSERT_TRUE(WaitUntilOnEnded());
1452 source.Abort();
1453 Stop();
1456 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1457 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1458 kMP4Video, kAppendWholeFile);
1459 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1460 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1462 source.EndOfStream();
1463 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1465 Play();
1467 ASSERT_TRUE(WaitUntilOnEnded());
1468 source.Abort();
1469 Stop();
1472 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1473 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1474 kMP4Audio, kAppendWholeFile);
1475 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1476 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1478 source.EndOfStream();
1479 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1481 Play();
1483 ASSERT_TRUE(WaitUntilOnEnded());
1484 source.Abort();
1485 Stop();
1487 #endif // !defined(DISABLE_EME_TESTS)
1489 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3) {
1490 MockMediaSource source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3,
1491 kAppendWholeFile);
1492 StartPipelineWithMediaSource(&source);
1493 source.EndOfStream();
1495 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1496 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1497 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1498 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1500 Play();
1502 ASSERT_TRUE(WaitUntilOnEnded());
1503 source.Abort();
1504 Stop();
1506 #endif // defined(USE_PROPRIETARY_CODECS)
1508 TEST_F(PipelineIntegrationTest, SeekWhilePaused) {
1509 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1511 base::TimeDelta duration(pipeline_->GetMediaDuration());
1512 base::TimeDelta start_seek_time(duration / 4);
1513 base::TimeDelta seek_time(duration * 3 / 4);
1515 Play();
1516 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1517 Pause();
1518 ASSERT_TRUE(Seek(seek_time));
1519 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1520 Play();
1521 ASSERT_TRUE(WaitUntilOnEnded());
1523 // Make sure seeking after reaching the end works as expected.
1524 Pause();
1525 ASSERT_TRUE(Seek(seek_time));
1526 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1527 Play();
1528 ASSERT_TRUE(WaitUntilOnEnded());
1531 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) {
1532 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1534 base::TimeDelta duration(pipeline_->GetMediaDuration());
1535 base::TimeDelta start_seek_time(duration / 4);
1536 base::TimeDelta seek_time(duration * 3 / 4);
1538 Play();
1539 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1540 ASSERT_TRUE(Seek(seek_time));
1541 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1542 ASSERT_TRUE(WaitUntilOnEnded());
1544 // Make sure seeking after reaching the end works as expected.
1545 ASSERT_TRUE(Seek(seek_time));
1546 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1547 ASSERT_TRUE(WaitUntilOnEnded());
1550 #if defined(USE_PROPRIETARY_CODECS)
1551 TEST_F(PipelineIntegrationTest, Rotated_Metadata_0) {
1552 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_0.mp4"));
1553 ASSERT_EQ(VIDEO_ROTATION_0, metadata_.video_rotation);
1556 TEST_F(PipelineIntegrationTest, Rotated_Metadata_90) {
1557 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_90.mp4"));
1558 ASSERT_EQ(VIDEO_ROTATION_90, metadata_.video_rotation);
1561 TEST_F(PipelineIntegrationTest, Rotated_Metadata_180) {
1562 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_180.mp4"));
1563 ASSERT_EQ(VIDEO_ROTATION_180, metadata_.video_rotation);
1566 TEST_F(PipelineIntegrationTest, Rotated_Metadata_270) {
1567 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_270.mp4"));
1568 ASSERT_EQ(VIDEO_ROTATION_270, metadata_.video_rotation);
1570 #endif
1572 // Verify audio decoder & renderer can handle aborted demuxer reads.
1573 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) {
1574 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM,
1575 16384,
1576 base::TimeDelta::FromMilliseconds(464),
1577 base::TimeDelta::FromMilliseconds(617),
1578 0x10CA, 19730));
1581 // Verify video decoder & renderer can handle aborted demuxer reads.
1582 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
1583 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM,
1584 32768,
1585 base::TimeDelta::FromMilliseconds(167),
1586 base::TimeDelta::FromMilliseconds(1668),
1587 0x1C896, 65536));
1590 // Verify that Opus audio in WebM containers can be played back.
1591 TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
1592 ASSERT_EQ(PIPELINE_OK, Start("bear-opus-end-trimming.webm"));
1593 Play();
1594 ASSERT_TRUE(WaitUntilOnEnded());
1597 // Verify that VP9 video in WebM containers can be played back.
1598 TEST_F(PipelineIntegrationTest, BasicPlayback_VideoOnly_VP9_WebM) {
1599 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
1600 Play();
1601 ASSERT_TRUE(WaitUntilOnEnded());
1604 // Verify that VP9 video and Opus audio in the same WebM container can be played
1605 // back.
1606 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Opus_WebM) {
1607 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-opus.webm"));
1608 Play();
1609 ASSERT_TRUE(WaitUntilOnEnded());
1612 // Verify that VP8 video with alpha channel can be played back.
1613 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_WebM) {
1614 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a.webm"));
1615 Play();
1616 ASSERT_TRUE(WaitUntilOnEnded());
1617 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12A);
1620 // Verify that VP8A video with odd width/height can be played back.
1621 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_Odd_WebM) {
1622 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a-odd-dimensions.webm"));
1623 Play();
1624 ASSERT_TRUE(WaitUntilOnEnded());
1625 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12A);
1628 // Verify that VP9 video with odd width/height can be played back.
1629 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Odd_WebM) {
1630 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-odd-dimensions.webm"));
1631 Play();
1632 ASSERT_TRUE(WaitUntilOnEnded());
1635 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1636 // Verify that VP8 video with inband text track can be played back.
1637 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) {
1638 EXPECT_CALL(*this, OnAddTextTrack(_, _));
1639 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8-webvtt.webm"));
1640 Play();
1641 ASSERT_TRUE(WaitUntilOnEnded());
1643 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1645 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1646 TEST_F(PipelineIntegrationTest, P444_VP9_WebM) {
1647 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-P444.webm"));
1648 Play();
1649 ASSERT_TRUE(WaitUntilOnEnded());
1650 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV24);
1653 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1654 // format.
1655 TEST_F(PipelineIntegrationTest, BT709_VP9_WebM) {
1656 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-bt709.webm"));
1657 Play();
1658 ASSERT_TRUE(WaitUntilOnEnded());
1659 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12HD);
1662 // Verify that videos with an odd frame size playback successfully.
1663 TEST_F(PipelineIntegrationTest, BasicPlayback_OddVideoSize) {
1664 ASSERT_EQ(PIPELINE_OK, Start("butterfly-853x480.webm"));
1665 Play();
1666 ASSERT_TRUE(WaitUntilOnEnded());
1669 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1670 // correctly at 48kHz
1671 TEST_F(PipelineIntegrationTest, BasicPlayback_Opus441kHz) {
1672 ASSERT_EQ(PIPELINE_OK, Start("sfx-opus-441.webm"));
1673 Play();
1674 ASSERT_TRUE(WaitUntilOnEnded());
1675 EXPECT_EQ(48000,
1676 demuxer_->GetStream(DemuxerStream::AUDIO)
1677 ->audio_decoder_config()
1678 .samples_per_second());
1681 // Same as above but using MediaSource.
1682 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus441kHz) {
1683 MockMediaSource source(
1684 "sfx-opus-441.webm", kOpusAudioOnlyWebM, kAppendWholeFile);
1685 StartPipelineWithMediaSource(&source);
1686 source.EndOfStream();
1687 Play();
1688 ASSERT_TRUE(WaitUntilOnEnded());
1689 source.Abort();
1690 Stop();
1691 EXPECT_EQ(48000,
1692 demuxer_->GetStream(DemuxerStream::AUDIO)
1693 ->audio_decoder_config()
1694 .samples_per_second());
1697 // Ensures audio-only playback with missing or negative timestamps works. Tests
1698 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1699 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOgg) {
1700 ASSERT_EQ(PIPELINE_OK, Start("double-sfx.ogg"));
1701 Play();
1702 ASSERT_TRUE(WaitUntilOnEnded());
1703 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1706 // Ensures audio-video playback with missing or negative timestamps fails softly
1707 // instead of crashing. See http://crbug.com/396864.
1708 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOggVideo) {
1709 ASSERT_EQ(PIPELINE_OK, Start("double-bear.ogv"));
1710 Play();
1711 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1712 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1715 // Tests that we signal ended even when audio runs longer than video track.
1716 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioLongerThanVideo) {
1717 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv"));
1718 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1719 // of the two.
1720 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds());
1721 Play();
1722 ASSERT_TRUE(WaitUntilOnEnded());
1725 // Tests that we signal ended even when audio runs shorter than video track.
1726 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioShorterThanVideo) {
1727 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv"));
1728 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1729 // the two.
1730 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds());
1731 Play();
1732 ASSERT_TRUE(WaitUntilOnEnded());
1735 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
1736 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
1737 Play();
1738 ASSERT_TRUE(WaitUntilOnEnded());
1739 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1740 demuxer_->GetStartTime());
1743 } // namespace media