Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / media / test / pipeline_integration_test.cc
blob54d355ca8822f02da6555133cea94373a9048718
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/strings/string_util.h"
9 #include "build/build_config.h"
10 #include "media/base/cdm_callback_promise.h"
11 #include "media/base/cdm_context.h"
12 #include "media/base/cdm_key_information.h"
13 #include "media/base/decoder_buffer.h"
14 #include "media/base/media.h"
15 #include "media/base/media_keys.h"
16 #include "media/base/media_switches.h"
17 #include "media/base/test_data_util.h"
18 #include "media/cdm/aes_decryptor.h"
19 #include "media/cdm/json_web_key.h"
20 #include "media/filters/chunk_demuxer.h"
21 #include "media/renderers/renderer_impl.h"
22 #include "media/test/pipeline_integration_test_base.h"
23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "url/gurl.h"
26 #if defined(MOJO_RENDERER)
27 #include "media/mojo/services/mojo_renderer_impl.h"
28 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
29 #include "third_party/mojo/src/mojo/public/cpp/application/application_test_base.h"
30 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h"
32 // TODO(dalecurtis): The mojo renderer is in another process, so we have no way
33 // currently to get hashes for video and audio samples. This also means that
34 // real audio plays out for each test.
35 #define EXPECT_HASH_EQ(a, b)
36 #define EXPECT_VIDEO_FORMAT_EQ(a, b)
38 // TODO(xhwang): EME support is not complete for the mojo renderer, so all
39 // encrypted tests are currently disabled.
40 #define DISABLE_EME_TESTS 1
42 // TODO(xhwang,dalecurtis): Text tracks are not currently supported by the mojo
43 // renderer.
44 #define DISABLE_TEXT_TRACK_TESTS 1
45 #else
46 #define EXPECT_HASH_EQ(a, b) EXPECT_EQ(a, b)
47 #define EXPECT_VIDEO_FORMAT_EQ(a, b) EXPECT_EQ(a, b)
48 #endif
50 using testing::_;
51 using testing::AnyNumber;
52 using testing::AtLeast;
53 using testing::AtMost;
54 using testing::SaveArg;
56 namespace media {
58 const char kSourceId[] = "SourceId";
60 const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\"";
61 const char kWebMVP9[] = "video/webm; codecs=\"vp9\"";
62 const char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\"";
63 const char kOpusAudioOnlyWebM[] = "video/webm; codecs=\"opus\"";
64 const char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\"";
65 #if defined(USE_PROPRIETARY_CODECS)
66 const char kADTS[] = "audio/aac";
67 const char kMP4[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\"";
68 const char kMP4VideoAVC3[] = "video/mp4; codecs=\"avc3.64001f\"";
69 #if !defined(DISABLE_EME_TESTS)
70 const char kMP4Video[] = "video/mp4; codecs=\"avc1.4D4041\"";
71 const char kMP4Audio[] = "audio/mp4; codecs=\"mp4a.40.2\"";
72 #endif // !defined(DISABLE_EME_TESTS)
73 const char kMP3[] = "audio/mpeg";
74 #endif // defined(USE_PROPRIETARY_CODECS)
76 // Key used to encrypt test files.
77 const uint8 kSecretKey[] = {
78 0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
79 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
82 // The key ID for all encrypted files.
83 const uint8 kKeyId[] = {
84 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
85 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
88 const int kAppendWholeFile = -1;
90 // Constants for the Media Source config change tests.
91 const int kAppendTimeSec = 1;
92 const int kAppendTimeMs = kAppendTimeSec * 1000;
93 const int k320WebMFileDurationMs = 2736;
94 #if !defined(DISABLE_EME_TESTS)
95 const int k320EncWebMFileDurationMs = 2737;
96 #endif // !defined(DISABLE_EME_TESTS)
97 const int k640WebMFileDurationMs = 2749;
98 const int kOpusEndTrimmingWebMFileDurationMs = 2741;
99 const int kVP9WebMFileDurationMs = 2736;
100 const int kVP8AWebMFileDurationMs = 2734;
102 #if defined(USE_PROPRIETARY_CODECS)
103 #if !defined(DISABLE_EME_TESTS)
104 const int k640IsoFileDurationMs = 2737;
105 const int k640IsoCencFileDurationMs = 2736;
106 #endif // !defined(DISABLE_EME_TESTS)
107 const int k1280IsoFileDurationMs = 2736;
108 const int k1280IsoAVC3FileDurationMs = 2736;
109 #endif // defined(USE_PROPRIETARY_CODECS)
111 // Return a timeline offset for bear-320x240-live.webm.
112 static base::Time kLiveTimelineOffset() {
113 // The file contians the following UTC timeline offset:
114 // 2012-11-10 12:34:56.789123456
115 // Since base::Time only has a resolution of microseconds,
116 // construct a base::Time for 2012-11-10 12:34:56.789123.
117 base::Time::Exploded exploded_time;
118 exploded_time.year = 2012;
119 exploded_time.month = 11;
120 exploded_time.day_of_month = 10;
121 exploded_time.hour = 12;
122 exploded_time.minute = 34;
123 exploded_time.second = 56;
124 exploded_time.millisecond = 789;
125 base::Time timeline_offset = base::Time::FromUTCExploded(exploded_time);
127 timeline_offset += base::TimeDelta::FromMicroseconds(123);
129 return timeline_offset;
132 // FFmpeg only supports time a resolution of seconds so this
133 // helper function truncates a base::Time to seconds resolution.
134 static base::Time TruncateToFFmpegTimeResolution(base::Time t) {
135 base::Time::Exploded exploded_time;
136 t.UTCExplode(&exploded_time);
137 exploded_time.millisecond = 0;
139 return base::Time::FromUTCExploded(exploded_time);
142 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
143 // They do not exercise the Decrypting{Audio|Video}Decoder path.
144 class FakeEncryptedMedia {
145 public:
146 // Defines the behavior of the "app" that responds to EME events.
147 class AppBase {
148 public:
149 virtual ~AppBase() {}
151 virtual void OnSessionMessage(const std::string& session_id,
152 MediaKeys::MessageType message_type,
153 const std::vector<uint8>& message,
154 const GURL& legacy_destination_url) = 0;
156 virtual void OnSessionClosed(const std::string& session_id) = 0;
158 virtual void OnSessionKeysChange(const std::string& session_id,
159 bool has_additional_usable_key,
160 CdmKeysInfo keys_info) = 0;
162 // Errors are not expected unless overridden.
163 virtual void OnLegacySessionError(const std::string& session_id,
164 const std::string& error_name,
165 uint32 system_code,
166 const std::string& error_message) {
167 FAIL() << "Unexpected Key Error";
170 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
171 const std::vector<uint8>& init_data,
172 AesDecryptor* decryptor) = 0;
175 FakeEncryptedMedia(AppBase* app)
176 : decryptor_(GURL::EmptyGURL(),
177 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
178 base::Unretained(this)),
179 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
180 base::Unretained(this)),
181 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
182 base::Unretained(this))),
183 cdm_context_(&decryptor_),
184 app_(app) {}
186 CdmContext* GetCdmContext() { return &cdm_context_; }
188 // Callbacks for firing session events. Delegate to |app_|.
189 void OnSessionMessage(const std::string& session_id,
190 MediaKeys::MessageType message_type,
191 const std::vector<uint8>& message,
192 const GURL& legacy_destination_url) {
193 app_->OnSessionMessage(session_id, message_type, message,
194 legacy_destination_url);
197 void OnSessionClosed(const std::string& session_id) {
198 app_->OnSessionClosed(session_id);
201 void OnSessionKeysChange(const std::string& session_id,
202 bool has_additional_usable_key,
203 CdmKeysInfo keys_info) {
204 app_->OnSessionKeysChange(session_id, has_additional_usable_key,
205 keys_info.Pass());
208 void OnLegacySessionError(const std::string& session_id,
209 const std::string& error_name,
210 uint32 system_code,
211 const std::string& error_message) {
212 app_->OnLegacySessionError(session_id, error_name, system_code,
213 error_message);
216 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
217 const std::vector<uint8>& init_data) {
218 app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
221 private:
222 class TestCdmContext : public CdmContext {
223 public:
224 TestCdmContext(Decryptor* decryptor) : decryptor_(decryptor) {}
226 Decryptor* GetDecryptor() final { return decryptor_; }
227 int GetCdmId() const final { return kInvalidCdmId; }
229 private:
230 Decryptor* decryptor_;
233 AesDecryptor decryptor_;
234 TestCdmContext cdm_context_;
235 scoped_ptr<AppBase> app_;
238 enum PromiseResult { RESOLVED, REJECTED };
240 // Provides |kSecretKey| in response to needkey.
241 class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
242 public:
243 KeyProvidingApp() {}
245 void OnResolveWithSession(PromiseResult expected,
246 const std::string& session_id) {
247 EXPECT_EQ(expected, RESOLVED);
248 EXPECT_GT(session_id.length(), 0ul);
249 current_session_id_ = session_id;
252 void OnResolve(PromiseResult expected) {
253 EXPECT_EQ(expected, RESOLVED);
256 void OnReject(PromiseResult expected,
257 media::MediaKeys::Exception exception_code,
258 uint32 system_code,
259 const std::string& error_message) {
260 EXPECT_EQ(expected, REJECTED) << error_message;
263 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
264 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
265 base::Bind(
266 &KeyProvidingApp::OnResolve, base::Unretained(this), expected),
267 base::Bind(
268 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
269 return promise.Pass();
272 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
273 PromiseResult expected) {
274 scoped_ptr<media::NewSessionCdmPromise> promise(
275 new media::CdmCallbackPromise<std::string>(
276 base::Bind(&KeyProvidingApp::OnResolveWithSession,
277 base::Unretained(this),
278 expected),
279 base::Bind(
280 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
281 return promise.Pass();
284 void OnSessionMessage(const std::string& session_id,
285 MediaKeys::MessageType message_type,
286 const std::vector<uint8>& message,
287 const GURL& legacy_destination_url) override {
288 EXPECT_FALSE(session_id.empty());
289 EXPECT_FALSE(message.empty());
290 EXPECT_EQ(current_session_id_, session_id);
293 void OnSessionClosed(const std::string& session_id) override {
294 EXPECT_EQ(current_session_id_, session_id);
297 void OnSessionKeysChange(const std::string& session_id,
298 bool has_additional_usable_key,
299 CdmKeysInfo keys_info) override {
300 EXPECT_EQ(current_session_id_, session_id);
301 EXPECT_EQ(has_additional_usable_key, true);
304 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
305 const std::vector<uint8>& init_data,
306 AesDecryptor* decryptor) override {
307 // Since only 1 session is created, skip the request if the |init_data|
308 // has been seen before (no need to add the same key again).
309 if (init_data == prev_init_data_)
310 return;
311 prev_init_data_ = init_data;
313 if (current_session_id_.empty()) {
314 if (init_data_type == EmeInitDataType::CENC) {
315 // Since the 'cenc' files are not created with proper 'pssh' boxes,
316 // simply pretend that this is a webm file and pass the expected
317 // key ID as the init_data.
318 // http://crbug.com/460308
319 decryptor->CreateSessionAndGenerateRequest(
320 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, kKeyId,
321 arraysize(kKeyId), CreateSessionPromise(RESOLVED));
322 } else {
323 decryptor->CreateSessionAndGenerateRequest(
324 MediaKeys::TEMPORARY_SESSION, init_data_type,
325 vector_as_array(&init_data), init_data.size(),
326 CreateSessionPromise(RESOLVED));
328 EXPECT_FALSE(current_session_id_.empty());
331 // Clear Key really needs the key ID from |init_data|. For WebM, they are
332 // the same, but this is not the case for ISO CENC (key ID embedded in a
333 // 'pssh' box). Therefore, provide the correct key ID.
334 const uint8* key_id = vector_as_array(&init_data);
335 size_t key_id_length = init_data.size();
336 if (init_data_type == EmeInitDataType::CENC) {
337 key_id = kKeyId;
338 key_id_length = arraysize(kKeyId);
341 // Convert key into a JSON structure and then add it.
342 std::string jwk = GenerateJWKSet(
343 kSecretKey, arraysize(kSecretKey), key_id, key_id_length);
344 decryptor->UpdateSession(current_session_id_,
345 reinterpret_cast<const uint8*>(jwk.data()),
346 jwk.size(),
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,
383 vector_as_array(&key_id), key_id.size(),
384 CreateSessionPromise(RESOLVED));
385 } else {
386 decryptor->CreateSessionAndGenerateRequest(
387 MediaKeys::TEMPORARY_SESSION, init_data_type,
388 vector_as_array(&init_data), init_data.size(),
389 CreateSessionPromise(RESOLVED));
392 // Convert key into a JSON structure and then add it.
393 std::string jwk = GenerateJWKSet(vector_as_array(&key),
394 key.size(),
395 vector_as_array(&key_id),
396 key_id.size());
397 decryptor->UpdateSession(current_session_id_,
398 reinterpret_cast<const uint8*>(jwk.data()),
399 jwk.size(),
400 CreatePromise(RESOLVED));
403 private:
404 bool GetKeyAndKeyId(std::vector<uint8> init_data,
405 std::vector<uint8>* key,
406 std::vector<uint8>* key_id) {
407 // For WebM, init_data is key_id; for ISO CENC, init_data should contain
408 // the key_id. We assume key_id is in the end of init_data here (that is
409 // only a reasonable assumption for WebM and clear key ISO CENC).
410 DCHECK_GE(init_data.size(), arraysize(kKeyId));
411 std::vector<uint8> key_id_from_init_data(
412 init_data.end() - arraysize(kKeyId), init_data.end());
414 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
415 key_id->assign(kKeyId, kKeyId + arraysize(kKeyId));
417 // The Key and KeyId for this testing key provider are created by left
418 // rotating kSecretKey and kKeyId. Note that this implementation is only
419 // intended for testing purpose. The actual key rotation algorithm can be
420 // much more complicated.
421 // Find out the rotating position from |key_id_from_init_data| and apply on
422 // |key|.
423 for (size_t pos = 0; pos < arraysize(kKeyId); ++pos) {
424 std::rotate(key_id->begin(), key_id->begin() + pos, key_id->end());
425 if (*key_id == key_id_from_init_data) {
426 std::rotate(key->begin(), key->begin() + pos, key->end());
427 return true;
430 return false;
433 std::vector<uint8> prev_init_data_;
434 uint32 num_distint_need_key_calls_;
437 // Ignores needkey and does not perform a license request
438 class NoResponseApp : public FakeEncryptedMedia::AppBase {
439 public:
440 void OnSessionMessage(const std::string& session_id,
441 MediaKeys::MessageType message_type,
442 const std::vector<uint8>& message,
443 const GURL& legacy_destination_url) override {
444 EXPECT_FALSE(session_id.empty());
445 EXPECT_FALSE(message.empty());
446 FAIL() << "Unexpected Message";
449 void OnSessionClosed(const std::string& session_id) override {
450 EXPECT_FALSE(session_id.empty());
451 FAIL() << "Unexpected Closed";
454 void OnSessionKeysChange(const std::string& session_id,
455 bool has_additional_usable_key,
456 CdmKeysInfo keys_info) override {
457 EXPECT_FALSE(session_id.empty());
458 EXPECT_EQ(has_additional_usable_key, true);
461 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
462 const std::vector<uint8>& init_data,
463 AesDecryptor* decryptor) override {}
466 // Helper class that emulates calls made on the ChunkDemuxer by the
467 // Media Source API.
468 class MockMediaSource {
469 public:
470 MockMediaSource(const std::string& filename,
471 const std::string& mimetype,
472 int initial_append_size)
473 : current_position_(0),
474 initial_append_size_(initial_append_size),
475 mimetype_(mimetype),
476 chunk_demuxer_(new ChunkDemuxer(
477 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)),
478 base::Bind(&MockMediaSource::OnEncryptedMediaInitData,
479 base::Unretained(this)),
480 LogCB(),
481 scoped_refptr<MediaLog>(new MediaLog()),
482 true)),
483 owned_chunk_demuxer_(chunk_demuxer_) {
484 file_data_ = ReadTestDataFile(filename);
486 if (initial_append_size_ == kAppendWholeFile)
487 initial_append_size_ = file_data_->data_size();
489 DCHECK_GT(initial_append_size_, 0);
490 DCHECK_LE(initial_append_size_, file_data_->data_size());
493 virtual ~MockMediaSource() {}
495 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); }
497 void set_encrypted_media_init_data_cb(
498 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
499 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
502 void Seek(base::TimeDelta seek_time, int new_position, int seek_append_size) {
503 chunk_demuxer_->StartWaitingForSeek(seek_time);
505 chunk_demuxer_->Abort(
506 kSourceId,
507 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_);
509 DCHECK_GE(new_position, 0);
510 DCHECK_LT(new_position, file_data_->data_size());
511 current_position_ = new_position;
513 AppendData(seek_append_size);
516 void AppendData(int size) {
517 DCHECK(chunk_demuxer_);
518 DCHECK_LT(current_position_, file_data_->data_size());
519 DCHECK_LE(current_position_ + size, file_data_->data_size());
521 chunk_demuxer_->AppendData(
522 kSourceId, file_data_->data() + current_position_, size,
523 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_,
524 base::Bind(&MockMediaSource::InitSegmentReceived,
525 base::Unretained(this)));
526 current_position_ += size;
529 void AppendAtTime(base::TimeDelta timestamp_offset,
530 const uint8* pData,
531 int size) {
532 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
533 chunk_demuxer_->AppendData(kSourceId, pData, size,
534 base::TimeDelta(), kInfiniteDuration(),
535 &timestamp_offset,
536 base::Bind(&MockMediaSource::InitSegmentReceived,
537 base::Unretained(this)));
538 last_timestamp_offset_ = timestamp_offset;
541 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset,
542 base::TimeDelta append_window_start,
543 base::TimeDelta append_window_end,
544 const uint8* pData,
545 int size) {
546 CHECK(!chunk_demuxer_->IsParsingMediaSegment(kSourceId));
547 chunk_demuxer_->AppendData(kSourceId,
548 pData,
549 size,
550 append_window_start,
551 append_window_end,
552 &timestamp_offset,
553 base::Bind(&MockMediaSource::InitSegmentReceived,
554 base::Unretained(this)));
555 last_timestamp_offset_ = timestamp_offset;
558 void EndOfStream() {
559 chunk_demuxer_->MarkEndOfStream(PIPELINE_OK);
562 void Abort() {
563 if (!chunk_demuxer_)
564 return;
565 chunk_demuxer_->Shutdown();
566 chunk_demuxer_ = NULL;
569 void DemuxerOpened() {
570 base::MessageLoop::current()->PostTask(
571 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask,
572 base::Unretained(this)));
575 void DemuxerOpenedTask() {
576 // This code assumes that |mimetype_| is one of the following forms.
577 // 1. audio/mpeg
578 // 2. video/webm;codec="vorbis,vp8".
579 size_t semicolon = mimetype_.find(";");
580 std::string type = mimetype_;
581 std::vector<std::string> codecs;
582 if (semicolon != std::string::npos) {
583 type = mimetype_.substr(0, semicolon);
584 size_t codecs_param_start = mimetype_.find("codecs=\"", semicolon);
586 CHECK_NE(codecs_param_start, std::string::npos);
588 codecs_param_start += 8; // Skip over the codecs=".
590 size_t codecs_param_end = mimetype_.find("\"", codecs_param_start);
592 CHECK_NE(codecs_param_end, std::string::npos);
594 std::string codecs_param =
595 mimetype_.substr(codecs_param_start,
596 codecs_param_end - codecs_param_start);
597 Tokenize(codecs_param, ",", &codecs);
600 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk);
602 AppendData(initial_append_size_);
605 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
606 const std::vector<uint8>& init_data) {
607 DCHECK(!init_data.empty());
608 CHECK(!encrypted_media_init_data_cb_.is_null());
609 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
612 base::TimeDelta last_timestamp_offset() const {
613 return last_timestamp_offset_;
616 MOCK_METHOD0(InitSegmentReceived, void(void));
618 private:
619 scoped_refptr<DecoderBuffer> file_data_;
620 int current_position_;
621 int initial_append_size_;
622 std::string mimetype_;
623 ChunkDemuxer* chunk_demuxer_;
624 scoped_ptr<Demuxer> owned_chunk_demuxer_;
625 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
626 base::TimeDelta last_timestamp_offset_;
629 #if defined(MOJO_RENDERER)
630 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase,
631 public PipelineIntegrationTestBase {
632 public:
633 bool ShouldCreateDefaultRunLoop() override { return false; }
635 void SetUp() override {
636 ApplicationTestBase::SetUp();
637 if (!IsMediaLibraryInitialized())
638 InitializeMediaLibraryForTesting();
641 protected:
642 scoped_ptr<Renderer> CreateRenderer() override {
643 mojo::ServiceProvider* service_provider =
644 application_impl()
645 ->ConnectToApplication("mojo://media")
646 ->GetServiceProvider();
648 mojo::MediaRendererPtr mojo_media_renderer;
649 mojo::ConnectToService(service_provider, &mojo_media_renderer);
650 return make_scoped_ptr(new MojoRendererImpl(message_loop_.task_runner(),
651 mojo_media_renderer.Pass()));
654 #else
655 class PipelineIntegrationTestHost : public testing::Test,
656 public PipelineIntegrationTestBase {};
657 #endif
659 class PipelineIntegrationTest : public PipelineIntegrationTestHost {
660 public:
661 void StartPipelineWithMediaSource(MockMediaSource* source) {
662 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
663 EXPECT_CALL(*this, OnMetadata(_))
664 .Times(AtMost(1))
665 .WillRepeatedly(SaveArg<0>(&metadata_));
666 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
667 .Times(AtMost(1));
669 // Encrypted content not used, so this is never called.
670 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
672 demuxer_ = source->GetDemuxer().Pass();
673 pipeline_->Start(
674 demuxer_.get(), CreateRenderer(),
675 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
676 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
677 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
678 base::Unretained(this)),
679 base::Bind(&PipelineIntegrationTest::OnMetadata,
680 base::Unretained(this)),
681 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
682 base::Unretained(this)),
683 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
684 base::Unretained(this)),
685 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
686 base::Unretained(this)));
687 message_loop_.Run();
688 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
691 void StartHashedPipelineWithMediaSource(MockMediaSource* source) {
692 hashing_enabled_ = true;
693 StartPipelineWithMediaSource(source);
696 void StartPipelineWithEncryptedMedia(
697 MockMediaSource* source,
698 FakeEncryptedMedia* encrypted_media) {
699 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
700 EXPECT_CALL(*this, OnMetadata(_))
701 .Times(AtMost(1))
702 .WillRepeatedly(SaveArg<0>(&metadata_));
703 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
704 .Times(AtMost(1));
705 EXPECT_CALL(*this, DecryptorAttached(true));
707 // Encrypted content used but keys provided in advance, so this is
708 // never called.
709 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
711 demuxer_ = source->GetDemuxer().Pass();
713 pipeline_->SetCdm(encrypted_media->GetCdmContext(),
714 base::Bind(&PipelineIntegrationTest::DecryptorAttached,
715 base::Unretained(this)));
717 pipeline_->Start(
718 demuxer_.get(), CreateRenderer(),
719 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
720 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
721 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
722 base::Unretained(this)),
723 base::Bind(&PipelineIntegrationTest::OnMetadata,
724 base::Unretained(this)),
725 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
726 base::Unretained(this)),
727 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
728 base::Unretained(this)),
729 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
730 base::Unretained(this)));
732 source->set_encrypted_media_init_data_cb(
733 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
734 base::Unretained(encrypted_media)));
736 message_loop_.Run();
737 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
740 // Verifies that seeking works properly for ChunkDemuxer when the
741 // seek happens while there is a pending read on the ChunkDemuxer
742 // and no data is available.
743 bool TestSeekDuringRead(const std::string& filename,
744 const std::string& mimetype,
745 int initial_append_size,
746 base::TimeDelta start_seek_time,
747 base::TimeDelta seek_time,
748 int seek_file_position,
749 int seek_append_size) {
750 MockMediaSource source(filename, mimetype, initial_append_size);
751 StartPipelineWithMediaSource(&source);
753 if (pipeline_status_ != PIPELINE_OK)
754 return false;
756 Play();
757 if (!WaitUntilCurrentTimeIsAfter(start_seek_time))
758 return false;
760 source.Seek(seek_time, seek_file_position, seek_append_size);
761 if (!Seek(seek_time))
762 return false;
764 source.EndOfStream();
766 source.Abort();
767 Stop();
768 return true;
772 TEST_F(PipelineIntegrationTest, BasicPlayback) {
773 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
775 Play();
777 ASSERT_TRUE(WaitUntilOnEnded());
780 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) {
781 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg"));
783 Play();
785 ASSERT_TRUE(WaitUntilOnEnded());
788 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
789 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed));
791 Play();
793 ASSERT_TRUE(WaitUntilOnEnded());
795 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
796 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
797 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
800 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) {
801 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed));
803 Play();
805 ASSERT_TRUE(WaitUntilOnEnded());
807 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
808 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
810 // TODO: Fix FFmpeg code to return higher resolution time values so
811 // we don't have to truncate our expectations here.
812 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
813 demuxer_->GetTimelineOffset());
816 TEST_F(PipelineIntegrationTest, F32PlaybackHashed) {
817 ASSERT_EQ(PIPELINE_OK, Start("sfx_f32le.wav", kHashed));
818 Play();
819 ASSERT_TRUE(WaitUntilOnEnded());
820 EXPECT_HASH_EQ(std::string(kNullVideoHash), GetVideoHash());
821 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
824 #if !defined(DISABLE_EME_TESTS)
825 TEST_F(PipelineIntegrationTest, BasicPlaybackEncrypted) {
826 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
827 set_encrypted_media_init_data_cb(
828 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
829 base::Unretained(&encrypted_media)));
831 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-av_enc-av.webm",
832 encrypted_media.GetCdmContext()));
834 Play();
836 ASSERT_TRUE(WaitUntilOnEnded());
837 Stop();
839 #endif // !defined(DISABLE_EME_TESTS)
841 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource) {
842 MockMediaSource source("bear-320x240.webm", kWebM, 219229);
843 StartPipelineWithMediaSource(&source);
844 source.EndOfStream();
846 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
847 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
848 EXPECT_EQ(k320WebMFileDurationMs,
849 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
851 Play();
853 ASSERT_TRUE(WaitUntilOnEnded());
855 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
856 source.Abort();
857 Stop();
860 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Live) {
861 MockMediaSource source("bear-320x240-live.webm", kWebM, 219221);
862 StartPipelineWithMediaSource(&source);
863 source.EndOfStream();
865 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
866 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
867 EXPECT_EQ(k320WebMFileDurationMs,
868 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
870 Play();
872 ASSERT_TRUE(WaitUntilOnEnded());
874 EXPECT_EQ(kLiveTimelineOffset(),
875 demuxer_->GetTimelineOffset());
876 source.Abort();
877 Stop();
880 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP9_WebM) {
881 MockMediaSource source("bear-vp9.webm", kWebMVP9, 67504);
882 StartPipelineWithMediaSource(&source);
883 source.EndOfStream();
885 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
886 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
887 EXPECT_EQ(kVP9WebMFileDurationMs,
888 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
890 Play();
892 ASSERT_TRUE(WaitUntilOnEnded());
893 source.Abort();
894 Stop();
897 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP8A_WebM) {
898 MockMediaSource source("bear-vp8a.webm", kVideoOnlyWebM, kAppendWholeFile);
899 StartPipelineWithMediaSource(&source);
900 source.EndOfStream();
902 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
903 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
904 EXPECT_EQ(kVP8AWebMFileDurationMs,
905 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
907 Play();
909 ASSERT_TRUE(WaitUntilOnEnded());
910 source.Abort();
911 Stop();
914 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus_WebM) {
915 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
916 kAppendWholeFile);
917 StartPipelineWithMediaSource(&source);
918 source.EndOfStream();
920 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
921 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
922 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
923 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
924 Play();
926 ASSERT_TRUE(WaitUntilOnEnded());
927 source.Abort();
928 Stop();
931 // Flaky. http://crbug.com/304776
932 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) {
933 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
934 kAppendWholeFile);
935 StartHashedPipelineWithMediaSource(&source);
937 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
938 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
939 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
940 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
942 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000);
943 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
945 Play();
946 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
947 source.Seek(seek_time, 0x1D5, 34017);
948 source.EndOfStream();
949 ASSERT_TRUE(Seek(seek_time));
951 ASSERT_TRUE(WaitUntilOnEnded());
953 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
955 source.Abort();
956 Stop();
959 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) {
960 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
961 kAppendWholeFile);
962 StartPipelineWithMediaSource(&source);
964 scoped_refptr<DecoderBuffer> second_file =
965 ReadTestDataFile("bear-640x360.webm");
967 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
968 second_file->data(), second_file->data_size());
970 source.EndOfStream();
972 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
973 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
974 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
975 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
977 Play();
979 EXPECT_TRUE(WaitUntilOnEnded());
980 source.Abort();
981 Stop();
984 #if !defined(DISABLE_EME_TESTS)
985 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) {
986 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
987 kAppendWholeFile);
988 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
989 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
991 scoped_refptr<DecoderBuffer> second_file =
992 ReadTestDataFile("bear-640x360-av_enc-av.webm");
994 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
995 second_file->data(), second_file->data_size());
997 source.EndOfStream();
999 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1000 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1001 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
1002 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1004 Play();
1006 EXPECT_TRUE(WaitUntilOnEnded());
1007 source.Abort();
1008 Stop();
1011 // Config changes from encrypted to clear are not currently supported.
1012 TEST_F(PipelineIntegrationTest,
1013 MediaSource_ConfigChange_ClearThenEncrypted_WebM) {
1014 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1015 kAppendWholeFile);
1016 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1017 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1019 scoped_refptr<DecoderBuffer> second_file =
1020 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1022 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1023 second_file->data(), second_file->data_size());
1025 source.EndOfStream();
1027 message_loop_.Run();
1028 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1030 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1031 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1032 // The second video was not added, so its time has not been added.
1033 EXPECT_EQ(k320WebMFileDurationMs,
1034 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1036 Play();
1038 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1039 source.Abort();
1042 // Config changes from clear to encrypted are not currently supported.
1043 TEST_F(PipelineIntegrationTest,
1044 MediaSource_ConfigChange_EncryptedThenClear_WebM) {
1045 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1046 kAppendWholeFile);
1047 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1048 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1050 scoped_refptr<DecoderBuffer> second_file =
1051 ReadTestDataFile("bear-640x360.webm");
1053 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1054 second_file->data(), second_file->data_size());
1056 source.EndOfStream();
1058 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1059 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1060 // The second video was not added, so its time has not been added.
1061 EXPECT_EQ(k320EncWebMFileDurationMs,
1062 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1064 Play();
1066 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1067 source.Abort();
1069 #endif // !defined(DISABLE_EME_TESTS)
1071 #if defined(USE_PROPRIETARY_CODECS)
1072 TEST_F(PipelineIntegrationTest, MediaSource_ADTS) {
1073 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1074 StartPipelineWithMediaSource(&source);
1075 source.EndOfStream();
1077 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1078 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1079 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1081 Play();
1083 EXPECT_TRUE(WaitUntilOnEnded());
1086 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) {
1087 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1088 StartHashedPipelineWithMediaSource(&source);
1089 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds());
1091 // Trim off multiple frames off the beginning of the segment which will cause
1092 // the first decoded frame to be incorrect if preroll isn't implemented.
1093 const base::TimeDelta adts_preroll_duration =
1094 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1095 const base::TimeDelta append_time =
1096 source.last_timestamp_offset() - adts_preroll_duration;
1098 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts");
1099 source.AppendAtTimeWithWindow(append_time,
1100 append_time + adts_preroll_duration,
1101 kInfiniteDuration(),
1102 second_file->data(),
1103 second_file->data_size());
1104 source.EndOfStream();
1106 EXPECT_EQ(592, source.last_timestamp_offset().InMilliseconds());
1107 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1108 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1109 EXPECT_EQ(592, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1111 Play();
1113 EXPECT_TRUE(WaitUntilOnEnded());
1115 // Verify preroll is stripped.
1116 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1119 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed_MP3) {
1120 ASSERT_EQ(PIPELINE_OK, Start("sfx.mp3", kHashed));
1122 Play();
1124 ASSERT_TRUE(WaitUntilOnEnded());
1126 // Verify codec delay and preroll are stripped.
1127 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1130 TEST_F(PipelineIntegrationTest, MediaSource_MP3) {
1131 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1132 StartHashedPipelineWithMediaSource(&source);
1133 source.EndOfStream();
1135 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1136 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1137 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1139 Play();
1141 EXPECT_TRUE(WaitUntilOnEnded());
1143 // Verify that codec delay was stripped.
1144 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1147 TEST_F(PipelineIntegrationTest, MediaSource_MP3_TimestampOffset) {
1148 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1149 StartPipelineWithMediaSource(&source);
1150 EXPECT_EQ(313, source.last_timestamp_offset().InMilliseconds());
1152 // There are 576 silent frames at the start of this mp3. The second append
1153 // should trim them off.
1154 const base::TimeDelta mp3_preroll_duration =
1155 base::TimeDelta::FromSecondsD(576.0 / 44100);
1156 const base::TimeDelta append_time =
1157 source.last_timestamp_offset() - mp3_preroll_duration;
1159 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.mp3");
1160 source.AppendAtTimeWithWindow(append_time,
1161 append_time + mp3_preroll_duration,
1162 kInfiniteDuration(),
1163 second_file->data(),
1164 second_file->data_size());
1165 source.EndOfStream();
1167 EXPECT_EQ(613, source.last_timestamp_offset().InMilliseconds());
1168 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1169 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1170 EXPECT_EQ(613, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1172 Play();
1174 EXPECT_TRUE(WaitUntilOnEnded());
1177 TEST_F(PipelineIntegrationTest, MediaSource_MP3_Icecast) {
1178 MockMediaSource source("icy_sfx.mp3", kMP3, kAppendWholeFile);
1179 StartPipelineWithMediaSource(&source);
1180 source.EndOfStream();
1182 Play();
1184 EXPECT_TRUE(WaitUntilOnEnded());
1187 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_MP4) {
1188 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4, kAppendWholeFile);
1189 StartPipelineWithMediaSource(&source);
1191 scoped_refptr<DecoderBuffer> second_file =
1192 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1194 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1195 second_file->data(), second_file->data_size());
1197 source.EndOfStream();
1199 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1200 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1201 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1202 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1204 Play();
1206 EXPECT_TRUE(WaitUntilOnEnded());
1207 source.Abort();
1208 Stop();
1211 #if !defined(DISABLE_EME_TESTS)
1212 TEST_F(PipelineIntegrationTest,
1213 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly) {
1214 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1215 kAppendWholeFile);
1216 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1217 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1219 scoped_refptr<DecoderBuffer> second_file =
1220 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1222 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1223 second_file->data(), second_file->data_size());
1225 source.EndOfStream();
1227 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1228 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1229 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1230 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1232 Play();
1234 EXPECT_TRUE(WaitUntilOnEnded());
1235 source.Abort();
1236 Stop();
1239 TEST_F(PipelineIntegrationTest,
1240 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1241 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video,
1242 kAppendWholeFile);
1243 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1244 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1246 scoped_refptr<DecoderBuffer> second_file =
1247 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1249 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1250 second_file->data(), second_file->data_size());
1252 source.EndOfStream();
1254 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1255 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1256 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1257 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1259 Play();
1261 EXPECT_TRUE(WaitUntilOnEnded());
1262 source.Abort();
1263 Stop();
1266 // Config changes from clear to encrypted are not currently supported.
1267 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1268 TEST_F(PipelineIntegrationTest,
1269 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1270 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1271 kAppendWholeFile);
1272 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1273 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1275 scoped_refptr<DecoderBuffer> second_file =
1276 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1278 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1279 second_file->data(), second_file->data_size());
1281 source.EndOfStream();
1283 message_loop_.Run();
1284 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1286 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1287 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1288 // The second video was not added, so its time has not been added.
1289 EXPECT_EQ(k640IsoFileDurationMs,
1290 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1292 Play();
1294 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1295 source.Abort();
1298 // Config changes from encrypted to clear are not currently supported.
1299 TEST_F(PipelineIntegrationTest,
1300 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC) {
1301 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1302 kAppendWholeFile);
1303 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1304 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1306 scoped_refptr<DecoderBuffer> second_file =
1307 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1309 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1310 second_file->data(), second_file->data_size());
1312 source.EndOfStream();
1314 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1315 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1316 // The second video was not added, so its time has not been added.
1317 EXPECT_EQ(k640IsoCencFileDurationMs,
1318 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1320 Play();
1322 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1323 source.Abort();
1325 #endif // !defined(DISABLE_EME_TESTS)
1327 // Verify files which change configuration midstream fail gracefully.
1328 TEST_F(PipelineIntegrationTest, MidStreamConfigChangesFail) {
1329 ASSERT_EQ(PIPELINE_OK, Start("midstream_config_change.mp3"));
1330 Play();
1331 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE);
1334 #endif
1336 TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) {
1337 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-16x9-aspect.webm"));
1338 Play();
1339 ASSERT_TRUE(WaitUntilOnEnded());
1342 #if !defined(DISABLE_EME_TESTS)
1343 TEST_F(PipelineIntegrationTest, EncryptedPlayback_WebM) {
1344 MockMediaSource source("bear-320x240-av_enc-av.webm", kWebM, 219816);
1345 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1346 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1348 source.EndOfStream();
1349 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1351 Play();
1353 ASSERT_TRUE(WaitUntilOnEnded());
1354 source.Abort();
1355 Stop();
1358 TEST_F(PipelineIntegrationTest, EncryptedPlayback_ClearStart_WebM) {
1359 MockMediaSource source("bear-320x240-av_enc-av_clear-1s.webm", kWebM,
1360 kAppendWholeFile);
1361 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1362 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1364 source.EndOfStream();
1365 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1367 Play();
1369 ASSERT_TRUE(WaitUntilOnEnded());
1370 source.Abort();
1371 Stop();
1374 TEST_F(PipelineIntegrationTest, EncryptedPlayback_NoEncryptedFrames_WebM) {
1375 MockMediaSource source("bear-320x240-av_enc-av_clear-all.webm", kWebM,
1376 kAppendWholeFile);
1377 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1378 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1380 source.EndOfStream();
1381 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1383 Play();
1385 ASSERT_TRUE(WaitUntilOnEnded());
1386 source.Abort();
1387 Stop();
1389 #endif // !defined(DISABLE_EME_TESTS)
1391 #if defined(USE_PROPRIETARY_CODECS)
1392 #if !defined(DISABLE_EME_TESTS)
1393 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_VideoOnly) {
1394 MockMediaSource source("bear-1280x720-v_frag-cenc.mp4", kMP4Video,
1395 kAppendWholeFile);
1396 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1397 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1399 source.EndOfStream();
1400 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1402 Play();
1404 ASSERT_TRUE(WaitUntilOnEnded());
1405 source.Abort();
1406 Stop();
1409 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_AudioOnly) {
1410 MockMediaSource source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio,
1411 kAppendWholeFile);
1412 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1413 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1415 source.EndOfStream();
1416 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1418 Play();
1420 ASSERT_TRUE(WaitUntilOnEnded());
1421 source.Abort();
1422 Stop();
1425 TEST_F(PipelineIntegrationTest,
1426 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly) {
1427 MockMediaSource source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video,
1428 kAppendWholeFile);
1429 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1430 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1432 source.EndOfStream();
1433 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1435 Play();
1437 ASSERT_TRUE(WaitUntilOnEnded());
1438 source.Abort();
1439 Stop();
1442 TEST_F(PipelineIntegrationTest,
1443 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly) {
1444 MockMediaSource source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio,
1445 kAppendWholeFile);
1446 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1447 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1449 source.EndOfStream();
1450 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1452 Play();
1454 ASSERT_TRUE(WaitUntilOnEnded());
1455 source.Abort();
1456 Stop();
1459 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1460 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1461 kMP4Video, kAppendWholeFile);
1462 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1463 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1465 source.EndOfStream();
1466 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1468 Play();
1470 ASSERT_TRUE(WaitUntilOnEnded());
1471 source.Abort();
1472 Stop();
1475 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1476 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1477 kMP4Audio, kAppendWholeFile);
1478 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1479 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1481 source.EndOfStream();
1482 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1484 Play();
1486 ASSERT_TRUE(WaitUntilOnEnded());
1487 source.Abort();
1488 Stop();
1490 #endif // !defined(DISABLE_EME_TESTS)
1492 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3) {
1493 MockMediaSource source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3,
1494 kAppendWholeFile);
1495 StartPipelineWithMediaSource(&source);
1496 source.EndOfStream();
1498 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1499 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1500 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1501 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1503 Play();
1505 ASSERT_TRUE(WaitUntilOnEnded());
1506 source.Abort();
1507 Stop();
1509 #endif // defined(USE_PROPRIETARY_CODECS)
1511 TEST_F(PipelineIntegrationTest, SeekWhilePaused) {
1512 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1514 base::TimeDelta duration(pipeline_->GetMediaDuration());
1515 base::TimeDelta start_seek_time(duration / 4);
1516 base::TimeDelta seek_time(duration * 3 / 4);
1518 Play();
1519 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1520 Pause();
1521 ASSERT_TRUE(Seek(seek_time));
1522 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1523 Play();
1524 ASSERT_TRUE(WaitUntilOnEnded());
1526 // Make sure seeking after reaching the end works as expected.
1527 Pause();
1528 ASSERT_TRUE(Seek(seek_time));
1529 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1530 Play();
1531 ASSERT_TRUE(WaitUntilOnEnded());
1534 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) {
1535 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1537 base::TimeDelta duration(pipeline_->GetMediaDuration());
1538 base::TimeDelta start_seek_time(duration / 4);
1539 base::TimeDelta seek_time(duration * 3 / 4);
1541 Play();
1542 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1543 ASSERT_TRUE(Seek(seek_time));
1544 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1545 ASSERT_TRUE(WaitUntilOnEnded());
1547 // Make sure seeking after reaching the end works as expected.
1548 ASSERT_TRUE(Seek(seek_time));
1549 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1550 ASSERT_TRUE(WaitUntilOnEnded());
1553 #if defined(USE_PROPRIETARY_CODECS)
1554 TEST_F(PipelineIntegrationTest, Rotated_Metadata_0) {
1555 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_0.mp4"));
1556 ASSERT_EQ(VIDEO_ROTATION_0, metadata_.video_rotation);
1559 TEST_F(PipelineIntegrationTest, Rotated_Metadata_90) {
1560 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_90.mp4"));
1561 ASSERT_EQ(VIDEO_ROTATION_90, metadata_.video_rotation);
1564 TEST_F(PipelineIntegrationTest, Rotated_Metadata_180) {
1565 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_180.mp4"));
1566 ASSERT_EQ(VIDEO_ROTATION_180, metadata_.video_rotation);
1569 TEST_F(PipelineIntegrationTest, Rotated_Metadata_270) {
1570 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_270.mp4"));
1571 ASSERT_EQ(VIDEO_ROTATION_270, metadata_.video_rotation);
1573 #endif
1575 // Verify audio decoder & renderer can handle aborted demuxer reads.
1576 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) {
1577 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM,
1578 16384,
1579 base::TimeDelta::FromMilliseconds(464),
1580 base::TimeDelta::FromMilliseconds(617),
1581 0x10CA, 19730));
1584 // Verify video decoder & renderer can handle aborted demuxer reads.
1585 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
1586 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM,
1587 32768,
1588 base::TimeDelta::FromMilliseconds(167),
1589 base::TimeDelta::FromMilliseconds(1668),
1590 0x1C896, 65536));
1593 // Verify that Opus audio in WebM containers can be played back.
1594 TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
1595 ASSERT_EQ(PIPELINE_OK, Start("bear-opus-end-trimming.webm"));
1596 Play();
1597 ASSERT_TRUE(WaitUntilOnEnded());
1600 // Verify that VP9 video in WebM containers can be played back.
1601 TEST_F(PipelineIntegrationTest, BasicPlayback_VideoOnly_VP9_WebM) {
1602 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
1603 Play();
1604 ASSERT_TRUE(WaitUntilOnEnded());
1607 // Verify that VP9 video and Opus audio in the same WebM container can be played
1608 // back.
1609 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Opus_WebM) {
1610 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-opus.webm"));
1611 Play();
1612 ASSERT_TRUE(WaitUntilOnEnded());
1615 // Verify that VP8 video with alpha channel can be played back.
1616 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_WebM) {
1617 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a.webm"));
1618 Play();
1619 ASSERT_TRUE(WaitUntilOnEnded());
1620 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12A);
1623 // Verify that VP8A video with odd width/height can be played back.
1624 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_Odd_WebM) {
1625 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a-odd-dimensions.webm"));
1626 Play();
1627 ASSERT_TRUE(WaitUntilOnEnded());
1628 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12A);
1631 // Verify that VP9 video with odd width/height can be played back.
1632 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Odd_WebM) {
1633 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-odd-dimensions.webm"));
1634 Play();
1635 ASSERT_TRUE(WaitUntilOnEnded());
1638 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1639 // Verify that VP8 video with inband text track can be played back.
1640 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) {
1641 EXPECT_CALL(*this, OnAddTextTrack(_, _));
1642 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8-webvtt.webm"));
1643 Play();
1644 ASSERT_TRUE(WaitUntilOnEnded());
1646 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1648 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1649 TEST_F(PipelineIntegrationTest, P444_VP9_WebM) {
1650 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-P444.webm"));
1651 Play();
1652 ASSERT_TRUE(WaitUntilOnEnded());
1653 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV24);
1656 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1657 // format.
1658 TEST_F(PipelineIntegrationTest, BT709_VP9_WebM) {
1659 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-bt709.webm"));
1660 Play();
1661 ASSERT_TRUE(WaitUntilOnEnded());
1662 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, VideoFrame::YV12HD);
1665 // Verify that videos with an odd frame size playback successfully.
1666 TEST_F(PipelineIntegrationTest, BasicPlayback_OddVideoSize) {
1667 ASSERT_EQ(PIPELINE_OK, Start("butterfly-853x480.webm"));
1668 Play();
1669 ASSERT_TRUE(WaitUntilOnEnded());
1672 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1673 // correctly at 48kHz
1674 TEST_F(PipelineIntegrationTest, BasicPlayback_Opus441kHz) {
1675 ASSERT_EQ(PIPELINE_OK, Start("sfx-opus-441.webm"));
1676 Play();
1677 ASSERT_TRUE(WaitUntilOnEnded());
1678 EXPECT_EQ(48000,
1679 demuxer_->GetStream(DemuxerStream::AUDIO)
1680 ->audio_decoder_config()
1681 .samples_per_second());
1684 // Same as above but using MediaSource.
1685 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus441kHz) {
1686 MockMediaSource source(
1687 "sfx-opus-441.webm", kOpusAudioOnlyWebM, kAppendWholeFile);
1688 StartPipelineWithMediaSource(&source);
1689 source.EndOfStream();
1690 Play();
1691 ASSERT_TRUE(WaitUntilOnEnded());
1692 source.Abort();
1693 Stop();
1694 EXPECT_EQ(48000,
1695 demuxer_->GetStream(DemuxerStream::AUDIO)
1696 ->audio_decoder_config()
1697 .samples_per_second());
1700 // Ensures audio-only playback with missing or negative timestamps works. Tests
1701 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1702 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOgg) {
1703 ASSERT_EQ(PIPELINE_OK, Start("double-sfx.ogg"));
1704 Play();
1705 ASSERT_TRUE(WaitUntilOnEnded());
1706 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1709 // Ensures audio-video playback with missing or negative timestamps fails softly
1710 // instead of crashing. See http://crbug.com/396864.
1711 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOggVideo) {
1712 ASSERT_EQ(PIPELINE_OK, Start("double-bear.ogv"));
1713 Play();
1714 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1715 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1718 // Tests that we signal ended even when audio runs longer than video track.
1719 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioLongerThanVideo) {
1720 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv"));
1721 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1722 // of the two.
1723 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds());
1724 Play();
1725 ASSERT_TRUE(WaitUntilOnEnded());
1728 // Tests that we signal ended even when audio runs shorter than video track.
1729 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioShorterThanVideo) {
1730 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv"));
1731 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1732 // the two.
1733 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds());
1734 Play();
1735 ASSERT_TRUE(WaitUntilOnEnded());
1738 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
1739 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
1740 Play();
1741 ASSERT_TRUE(WaitUntilOnEnded());
1742 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1743 demuxer_->GetStartTime());
1746 } // namespace media