cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / media / test / pipeline_integration_test.cc
blobf97929552bc6285aec85c3521b119b736d22d00c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "build/build_config.h"
12 #include "media/base/cdm_callback_promise.h"
13 #include "media/base/cdm_context.h"
14 #include "media/base/cdm_key_information.h"
15 #include "media/base/decoder_buffer.h"
16 #include "media/base/media.h"
17 #include "media/base/media_keys.h"
18 #include "media/base/media_switches.h"
19 #include "media/base/test_data_util.h"
20 #include "media/base/timestamp_constants.h"
21 #include "media/cdm/aes_decryptor.h"
22 #include "media/cdm/json_web_key.h"
23 #include "media/filters/chunk_demuxer.h"
24 #include "media/renderers/renderer_impl.h"
25 #include "media/test/pipeline_integration_test_base.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "url/gurl.h"
29 #if defined(MOJO_RENDERER)
30 #include "media/mojo/interfaces/renderer.mojom.h"
31 #include "media/mojo/interfaces/service_factory.mojom.h"
32 #include "media/mojo/services/mojo_renderer_impl.h"
33 #include "mojo/application/public/cpp/application_impl.h"
34 #include "mojo/application/public/cpp/application_test_base.h"
35 #include "mojo/application/public/cpp/connect.h"
37 // TODO(dalecurtis): The mojo renderer is in another process, so we have no way
38 // currently to get hashes for video and audio samples. This also means that
39 // real audio plays out for each test.
40 #define EXPECT_HASH_EQ(a, b)
41 #define EXPECT_VIDEO_FORMAT_EQ(a, b)
42 #define EXPECT_COLOR_SPACE_EQ(a, b)
44 // TODO(xhwang): EME support is not complete for the mojo renderer, so all
45 // encrypted tests are currently disabled.
46 #define DISABLE_EME_TESTS 1
48 // TODO(xhwang,dalecurtis): Text tracks are not currently supported by the mojo
49 // renderer.
50 #define DISABLE_TEXT_TRACK_TESTS 1
51 #else
52 #define EXPECT_HASH_EQ(a, b) EXPECT_EQ(a, b)
53 #define EXPECT_VIDEO_FORMAT_EQ(a, b) EXPECT_EQ(a, b)
54 #define EXPECT_COLOR_SPACE_EQ(a, b) EXPECT_EQ(a, b)
55 #endif
57 using testing::_;
58 using testing::AnyNumber;
59 using testing::AtLeast;
60 using testing::AtMost;
61 using testing::SaveArg;
63 namespace media {
65 const char kSourceId[] = "SourceId";
67 const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\"";
68 const char kWebMVP9[] = "video/webm; codecs=\"vp9\"";
69 const char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\"";
70 const char kOpusAudioOnlyWebM[] = "video/webm; codecs=\"opus\"";
71 const char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\"";
72 #if defined(USE_PROPRIETARY_CODECS)
73 const char kADTS[] = "audio/aac";
74 const char kMP4[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\"";
75 const char kMP4VideoAVC3[] = "video/mp4; codecs=\"avc3.64001f\"";
76 #if !defined(DISABLE_EME_TESTS)
77 const char kMP4Video[] = "video/mp4; codecs=\"avc1.4D4041\"";
78 const char kMP4Audio[] = "audio/mp4; codecs=\"mp4a.40.2\"";
79 #endif // !defined(DISABLE_EME_TESTS)
80 const char kMP3[] = "audio/mpeg";
81 #endif // defined(USE_PROPRIETARY_CODECS)
83 // Key used to encrypt test files.
84 const uint8_t kSecretKey[] = {
85 0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
86 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
89 // The key ID for all encrypted files.
90 const uint8_t kKeyId[] = {
91 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
92 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
95 const int kAppendWholeFile = -1;
97 // Constants for the Media Source config change tests.
98 const int kAppendTimeSec = 1;
99 const int kAppendTimeMs = kAppendTimeSec * 1000;
100 const int k320WebMFileDurationMs = 2736;
101 #if !defined(DISABLE_EME_TESTS)
102 const int k320EncWebMFileDurationMs = 2737;
103 #endif // !defined(DISABLE_EME_TESTS)
104 const int k640WebMFileDurationMs = 2749;
105 const int kOpusEndTrimmingWebMFileDurationMs = 2741;
106 const int kVP9WebMFileDurationMs = 2736;
107 const int kVP8AWebMFileDurationMs = 2734;
109 #if !defined(MOJO_RENDERER)
110 #if defined(OPUS_FIXED_POINT)
111 static const char kOpusEndTrimmingHash_1[] =
112 "-4.57,-5.68,-6.54,-6.29,-4.35,-3.59,";
113 static const char kOpusEndTrimmingHash_2[] =
114 "-11.93,-11.12,-8.27,-7.10,-7.84,-10.00,";
115 static const char kOpusEndTrimmingHash_3[] =
116 "-13.32,-14.38,-13.70,-11.69,-10.20,-10.48,";
117 #else
118 // Hash for a full playthrough of "opus-trimming-test.(webm|ogg)".
119 static const char kOpusEndTrimmingHash_1[] =
120 "-4.56,-5.65,-6.51,-6.29,-4.36,-3.59,";
121 // The above hash, plus an additional playthrough starting from T=1s.
122 static const char kOpusEndTrimmingHash_2[] =
123 "-11.89,-11.09,-8.25,-7.11,-7.84,-9.97,";
124 // The above hash, plus an additional playthrough starting from T=6.36s.
125 static const char kOpusEndTrimmingHash_3[] =
126 "-13.28,-14.35,-13.67,-11.68,-10.18,-10.46,";
127 #endif // defined(OPUS_FIXED_POINT)
128 #endif
130 #if defined(USE_PROPRIETARY_CODECS)
131 #if !defined(DISABLE_EME_TESTS)
132 const int k640IsoFileDurationMs = 2737;
133 const int k640IsoCencFileDurationMs = 2736;
134 #endif // !defined(DISABLE_EME_TESTS)
135 const int k1280IsoFileDurationMs = 2736;
136 const int k1280IsoAVC3FileDurationMs = 2736;
137 #endif // defined(USE_PROPRIETARY_CODECS)
139 // Return a timeline offset for bear-320x240-live.webm.
140 static base::Time kLiveTimelineOffset() {
141 // The file contians the following UTC timeline offset:
142 // 2012-11-10 12:34:56.789123456
143 // Since base::Time only has a resolution of microseconds,
144 // construct a base::Time for 2012-11-10 12:34:56.789123.
145 base::Time::Exploded exploded_time;
146 exploded_time.year = 2012;
147 exploded_time.month = 11;
148 exploded_time.day_of_month = 10;
149 exploded_time.hour = 12;
150 exploded_time.minute = 34;
151 exploded_time.second = 56;
152 exploded_time.millisecond = 789;
153 base::Time timeline_offset = base::Time::FromUTCExploded(exploded_time);
155 timeline_offset += base::TimeDelta::FromMicroseconds(123);
157 return timeline_offset;
160 // FFmpeg only supports time a resolution of seconds so this
161 // helper function truncates a base::Time to seconds resolution.
162 static base::Time TruncateToFFmpegTimeResolution(base::Time t) {
163 base::Time::Exploded exploded_time;
164 t.UTCExplode(&exploded_time);
165 exploded_time.millisecond = 0;
167 return base::Time::FromUTCExploded(exploded_time);
170 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
171 // They do not exercise the Decrypting{Audio|Video}Decoder path.
172 class FakeEncryptedMedia {
173 public:
174 // Defines the behavior of the "app" that responds to EME events.
175 class AppBase {
176 public:
177 virtual ~AppBase() {}
179 virtual void OnSessionMessage(const std::string& session_id,
180 MediaKeys::MessageType message_type,
181 const std::vector<uint8_t>& message,
182 const GURL& legacy_destination_url,
183 AesDecryptor* decryptor) = 0;
185 virtual void OnSessionClosed(const std::string& session_id) = 0;
187 virtual void OnSessionKeysChange(const std::string& session_id,
188 bool has_additional_usable_key,
189 CdmKeysInfo keys_info) = 0;
191 // Errors are not expected unless overridden.
192 virtual void OnLegacySessionError(const std::string& session_id,
193 const std::string& error_name,
194 uint32_t system_code,
195 const std::string& error_message) {
196 FAIL() << "Unexpected Key Error";
199 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
200 const std::vector<uint8_t>& init_data,
201 AesDecryptor* decryptor) = 0;
204 FakeEncryptedMedia(AppBase* app)
205 : decryptor_(GURL::EmptyGURL(),
206 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
207 base::Unretained(this)),
208 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
209 base::Unretained(this)),
210 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
211 base::Unretained(this))),
212 cdm_context_(&decryptor_),
213 app_(app) {}
215 CdmContext* GetCdmContext() { return &cdm_context_; }
217 // Callbacks for firing session events. Delegate to |app_|.
218 void OnSessionMessage(const std::string& session_id,
219 MediaKeys::MessageType message_type,
220 const std::vector<uint8_t>& message,
221 const GURL& legacy_destination_url) {
222 app_->OnSessionMessage(session_id, message_type, message,
223 legacy_destination_url, &decryptor_);
226 void OnSessionClosed(const std::string& session_id) {
227 app_->OnSessionClosed(session_id);
230 void OnSessionKeysChange(const std::string& session_id,
231 bool has_additional_usable_key,
232 CdmKeysInfo keys_info) {
233 app_->OnSessionKeysChange(session_id, has_additional_usable_key,
234 keys_info.Pass());
237 void OnLegacySessionError(const std::string& session_id,
238 const std::string& error_name,
239 uint32_t system_code,
240 const std::string& error_message) {
241 app_->OnLegacySessionError(session_id, error_name, system_code,
242 error_message);
245 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
246 const std::vector<uint8_t>& init_data) {
247 app_->OnEncryptedMediaInitData(init_data_type, init_data, &decryptor_);
250 private:
251 class TestCdmContext : public CdmContext {
252 public:
253 TestCdmContext(Decryptor* decryptor) : decryptor_(decryptor) {}
255 Decryptor* GetDecryptor() final { return decryptor_; }
256 int GetCdmId() const final { return kInvalidCdmId; }
258 private:
259 Decryptor* decryptor_;
262 AesDecryptor decryptor_;
263 TestCdmContext cdm_context_;
264 scoped_ptr<AppBase> app_;
267 enum PromiseResult { RESOLVED, REJECTED };
269 // Provides |kSecretKey| in response to needkey.
270 class KeyProvidingApp : public FakeEncryptedMedia::AppBase {
271 public:
272 KeyProvidingApp() {}
274 void OnResolveWithSession(PromiseResult expected,
275 const std::string& session_id) {
276 EXPECT_EQ(expected, RESOLVED);
277 EXPECT_GT(session_id.length(), 0ul);
278 current_session_id_ = session_id;
281 void OnResolve(PromiseResult expected) {
282 EXPECT_EQ(expected, RESOLVED);
285 void OnReject(PromiseResult expected,
286 media::MediaKeys::Exception exception_code,
287 uint32_t system_code,
288 const std::string& error_message) {
289 EXPECT_EQ(expected, REJECTED) << error_message;
292 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
293 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>(
294 base::Bind(
295 &KeyProvidingApp::OnResolve, base::Unretained(this), expected),
296 base::Bind(
297 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
298 return promise.Pass();
301 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
302 PromiseResult expected) {
303 scoped_ptr<media::NewSessionCdmPromise> promise(
304 new media::CdmCallbackPromise<std::string>(
305 base::Bind(&KeyProvidingApp::OnResolveWithSession,
306 base::Unretained(this),
307 expected),
308 base::Bind(
309 &KeyProvidingApp::OnReject, base::Unretained(this), expected)));
310 return promise.Pass();
313 void OnSessionMessage(const std::string& session_id,
314 MediaKeys::MessageType message_type,
315 const std::vector<uint8_t>& message,
316 const GURL& legacy_destination_url,
317 AesDecryptor* decryptor) override {
318 EXPECT_FALSE(session_id.empty());
319 EXPECT_FALSE(message.empty());
320 EXPECT_EQ(current_session_id_, session_id);
321 EXPECT_EQ(MediaKeys::MessageType::LICENSE_REQUEST, message_type);
323 // Extract the key ID from |message|. For Clear Key this is a JSON object
324 // containing a set of "kids". There should only be 1 key ID in |message|.
325 std::string message_string(message.begin(), message.end());
326 KeyIdList key_ids;
327 std::string error_message;
328 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids,
329 &error_message))
330 << error_message;
331 EXPECT_EQ(1u, key_ids.size());
333 // Determine the key that matches the key ID |key_ids[0]|.
334 std::vector<uint8_t> key;
335 EXPECT_TRUE(LookupKey(key_ids[0], &key));
337 // Update the session with the key ID and key.
338 std::string jwk =
339 GenerateJWKSet(vector_as_array(&key), key.size(),
340 vector_as_array(&key_ids[0]), key_ids[0].size());
341 decryptor->UpdateSession(session_id,
342 std::vector<uint8_t>(jwk.begin(), jwk.end()),
343 CreatePromise(RESOLVED));
346 void OnSessionClosed(const std::string& session_id) override {
347 EXPECT_EQ(current_session_id_, session_id);
350 void OnSessionKeysChange(const std::string& session_id,
351 bool has_additional_usable_key,
352 CdmKeysInfo keys_info) override {
353 EXPECT_EQ(current_session_id_, session_id);
354 EXPECT_EQ(has_additional_usable_key, true);
357 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
358 const std::vector<uint8_t>& init_data,
359 AesDecryptor* decryptor) override {
360 // Since only 1 session is created, skip the request if the |init_data|
361 // has been seen before (no need to add the same key again).
362 if (init_data == prev_init_data_)
363 return;
364 prev_init_data_ = init_data;
366 if (current_session_id_.empty()) {
367 decryptor->CreateSessionAndGenerateRequest(
368 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data,
369 CreateSessionPromise(RESOLVED));
370 EXPECT_FALSE(current_session_id_.empty());
374 virtual bool LookupKey(const std::vector<uint8_t>& key_id,
375 std::vector<uint8_t>* key) {
376 // As there is no key rotation, the key ID provided should be |kKeyId|
377 // which uses |kSecretKey| as the key.
378 EXPECT_EQ(std::vector<uint8_t>(kKeyId, kKeyId + arraysize(kKeyId)), key_id);
379 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
380 return true;
383 std::string current_session_id_;
384 std::vector<uint8_t> prev_init_data_;
387 class RotatingKeyProvidingApp : public KeyProvidingApp {
388 public:
389 RotatingKeyProvidingApp() : num_distinct_need_key_calls_(0) {}
390 ~RotatingKeyProvidingApp() override {
391 // Expect that OnEncryptedMediaInitData is fired multiple times with
392 // different |init_data|.
393 EXPECT_GT(num_distinct_need_key_calls_, 1u);
396 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
397 const std::vector<uint8_t>& init_data,
398 AesDecryptor* decryptor) override {
399 // Skip the request if the |init_data| has been seen.
400 if (init_data == prev_init_data_)
401 return;
402 prev_init_data_ = init_data;
403 ++num_distinct_need_key_calls_;
405 decryptor->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
406 init_data_type, init_data,
407 CreateSessionPromise(RESOLVED));
410 bool LookupKey(const std::vector<uint8_t>& key_id,
411 std::vector<uint8_t>* key) override {
412 // The Key and KeyId for this testing key provider are created by left
413 // rotating |kSecretKey| and |kKeyId|. Note that this implementation is
414 // only intended for testing purpose. The actual key rotation algorithm
415 // can be much more complicated.
416 // Find out the rotating position from |starting_key_id| and apply on |key|.
417 std::vector<uint8_t> starting_key_id(kKeyId, kKeyId + arraysize(kKeyId));
418 for (size_t pos = 0; pos < starting_key_id.size(); ++pos) {
419 std::rotate(starting_key_id.begin(), starting_key_id.begin() + pos,
420 starting_key_id.end());
421 if (key_id == starting_key_id) {
422 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
423 std::rotate(key->begin(), key->begin() + pos, key->end());
424 return true;
427 return false;
430 uint32_t num_distinct_need_key_calls_;
433 // Ignores needkey and does not perform a license request
434 class NoResponseApp : public FakeEncryptedMedia::AppBase {
435 public:
436 void OnSessionMessage(const std::string& session_id,
437 MediaKeys::MessageType message_type,
438 const std::vector<uint8_t>& message,
439 const GURL& legacy_destination_url,
440 AesDecryptor* decryptor) 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_t>& 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 scoped_refptr<MediaLog>(new MediaLog()),
478 true)),
479 owned_chunk_demuxer_(chunk_demuxer_) {
480 file_data_ = ReadTestDataFile(filename);
482 if (initial_append_size_ == kAppendWholeFile)
483 initial_append_size_ = file_data_->data_size();
485 DCHECK_GT(initial_append_size_, 0);
486 DCHECK_LE(initial_append_size_, file_data_->data_size());
489 virtual ~MockMediaSource() {}
491 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); }
493 void set_encrypted_media_init_data_cb(
494 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
495 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
498 void Seek(base::TimeDelta seek_time, int new_position, int seek_append_size) {
499 chunk_demuxer_->StartWaitingForSeek(seek_time);
501 chunk_demuxer_->Abort(
502 kSourceId,
503 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_);
505 DCHECK_GE(new_position, 0);
506 DCHECK_LT(new_position, file_data_->data_size());
507 current_position_ = new_position;
509 AppendData(seek_append_size);
512 void Seek(base::TimeDelta seek_time) {
513 chunk_demuxer_->StartWaitingForSeek(seek_time);
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_t* 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_t* 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 codecs = base::SplitString(
598 codecs_param, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
601 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk);
603 AppendData(initial_append_size_);
606 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
607 const std::vector<uint8_t>& init_data) {
608 DCHECK(!init_data.empty());
609 CHECK(!encrypted_media_init_data_cb_.is_null());
610 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
613 base::TimeDelta last_timestamp_offset() const {
614 return last_timestamp_offset_;
617 MOCK_METHOD0(InitSegmentReceived, void(void));
619 private:
620 scoped_refptr<DecoderBuffer> file_data_;
621 int current_position_;
622 int initial_append_size_;
623 std::string mimetype_;
624 ChunkDemuxer* chunk_demuxer_;
625 scoped_ptr<Demuxer> owned_chunk_demuxer_;
626 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
627 base::TimeDelta last_timestamp_offset_;
630 #if defined(MOJO_RENDERER)
631 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase,
632 public PipelineIntegrationTestBase {
633 public:
634 bool ShouldCreateDefaultRunLoop() override { return false; }
636 void SetUp() override {
637 ApplicationTestBase::SetUp();
638 InitializeMediaLibrary();
641 protected:
642 scoped_ptr<Renderer> CreateRenderer() override {
643 mojo::URLRequestPtr request(mojo::URLRequest::New());
644 request->url = mojo::String::From("mojo:media");
645 mojo::ServiceProvider* service_provider =
646 application_impl()
647 ->ConnectToApplication(request.Pass())
648 ->GetServiceProvider();
650 mojo::ConnectToService(service_provider, &media_service_factory_);
652 interfaces::RendererPtr mojo_renderer;
653 media_service_factory_->CreateRenderer(mojo::GetProxy(&mojo_renderer));
655 return make_scoped_ptr(new MojoRendererImpl(message_loop_.task_runner(),
656 mojo_renderer.Pass()));
659 private:
660 interfaces::ServiceFactoryPtr media_service_factory_;
662 #else
663 class PipelineIntegrationTestHost : public testing::Test,
664 public PipelineIntegrationTestBase {};
665 #endif
667 class PipelineIntegrationTest : public PipelineIntegrationTestHost {
668 public:
669 void StartPipelineWithMediaSource(MockMediaSource* source) {
670 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
671 EXPECT_CALL(*this, OnMetadata(_))
672 .Times(AtMost(1))
673 .WillRepeatedly(SaveArg<0>(&metadata_));
674 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
675 .Times(AnyNumber());
676 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
677 .Times(AnyNumber());
679 // Encrypted content not used, so this is never called.
680 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
682 demuxer_ = source->GetDemuxer().Pass();
683 pipeline_->Start(
684 demuxer_.get(), CreateRenderer(),
685 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
686 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
687 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
688 base::Unretained(this)),
689 base::Bind(&PipelineIntegrationTest::OnMetadata,
690 base::Unretained(this)),
691 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
692 base::Unretained(this)),
693 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
694 base::Unretained(this)),
695 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
696 base::Unretained(this)));
697 message_loop_.Run();
698 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
701 void StartHashedPipelineWithMediaSource(MockMediaSource* source) {
702 hashing_enabled_ = true;
703 StartPipelineWithMediaSource(source);
706 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource* source) {
707 hashing_enabled_ = true;
708 clockless_playback_ = true;
709 StartPipelineWithMediaSource(source);
712 void StartPipelineWithEncryptedMedia(
713 MockMediaSource* source,
714 FakeEncryptedMedia* encrypted_media) {
715 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1));
716 EXPECT_CALL(*this, OnMetadata(_))
717 .Times(AtMost(1))
718 .WillRepeatedly(SaveArg<0>(&metadata_));
719 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH))
720 .Times(AnyNumber());
721 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING))
722 .Times(AnyNumber());
723 EXPECT_CALL(*this, DecryptorAttached(true));
725 // Encrypted content used but keys provided in advance, so this is
726 // never called.
727 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
729 demuxer_ = source->GetDemuxer().Pass();
731 pipeline_->SetCdm(encrypted_media->GetCdmContext(),
732 base::Bind(&PipelineIntegrationTest::DecryptorAttached,
733 base::Unretained(this)));
735 pipeline_->Start(
736 demuxer_.get(), CreateRenderer(),
737 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)),
738 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)),
739 base::Bind(&PipelineIntegrationTest::OnStatusCallback,
740 base::Unretained(this)),
741 base::Bind(&PipelineIntegrationTest::OnMetadata,
742 base::Unretained(this)),
743 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged,
744 base::Unretained(this)),
745 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack,
746 base::Unretained(this)),
747 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey,
748 base::Unretained(this)));
750 source->set_encrypted_media_init_data_cb(
751 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
752 base::Unretained(encrypted_media)));
754 message_loop_.Run();
755 EXPECT_EQ(PIPELINE_OK, pipeline_status_);
758 // Verifies that seeking works properly for ChunkDemuxer when the
759 // seek happens while there is a pending read on the ChunkDemuxer
760 // and no data is available.
761 bool TestSeekDuringRead(const std::string& filename,
762 const std::string& mimetype,
763 int initial_append_size,
764 base::TimeDelta start_seek_time,
765 base::TimeDelta seek_time,
766 int seek_file_position,
767 int seek_append_size) {
768 MockMediaSource source(filename, mimetype, initial_append_size);
769 StartPipelineWithMediaSource(&source);
771 if (pipeline_status_ != PIPELINE_OK)
772 return false;
774 Play();
775 if (!WaitUntilCurrentTimeIsAfter(start_seek_time))
776 return false;
778 source.Seek(seek_time, seek_file_position, seek_append_size);
779 if (!Seek(seek_time))
780 return false;
782 source.EndOfStream();
784 source.Abort();
785 Stop();
786 return true;
790 TEST_F(PipelineIntegrationTest, BasicPlayback) {
791 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
793 Play();
795 ASSERT_TRUE(WaitUntilOnEnded());
798 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) {
799 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg"));
801 Play();
803 ASSERT_TRUE(WaitUntilOnEnded());
806 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) {
807 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", kHashed));
809 Play();
811 ASSERT_TRUE(WaitUntilOnEnded());
813 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
814 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
815 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
818 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOggTrimmingHashed) {
819 ASSERT_EQ(PIPELINE_OK,
820 Start("opus-trimming-test.webm", kHashed | kClockless));
822 Play();
824 ASSERT_TRUE(WaitUntilOnEnded());
825 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
827 // Seek within the pre-skip section, this should not cause a beep.
828 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
829 Play();
830 ASSERT_TRUE(WaitUntilOnEnded());
831 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
833 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
834 // correctly preroll enough to accurately decode this segment.
835 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
836 Play();
837 ASSERT_TRUE(WaitUntilOnEnded());
838 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
841 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusWebmTrimmingHashed) {
842 ASSERT_EQ(PIPELINE_OK,
843 Start("opus-trimming-test.webm", kHashed | kClockless));
845 Play();
847 ASSERT_TRUE(WaitUntilOnEnded());
848 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
850 // Seek within the pre-skip section, this should not cause a beep.
851 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
852 Play();
853 ASSERT_TRUE(WaitUntilOnEnded());
854 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
856 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
857 // correctly preroll enough to accurately decode this segment.
858 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
859 Play();
860 ASSERT_TRUE(WaitUntilOnEnded());
861 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
864 TEST_F(PipelineIntegrationTest,
865 BasicPlaybackOpusWebmTrimmingHashed_MediaSource) {
866 MockMediaSource source("opus-trimming-test.webm", kOpusAudioOnlyWebM,
867 kAppendWholeFile);
868 StartHashedClocklessPipelineWithMediaSource(&source);
869 source.EndOfStream();
871 Play();
873 ASSERT_TRUE(WaitUntilOnEnded());
874 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1, GetAudioHash());
876 // Seek within the pre-skip section, this should not cause a beep.
877 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(1);
878 source.Seek(seek_time);
879 ASSERT_TRUE(Seek(seek_time));
880 Play();
881 ASSERT_TRUE(WaitUntilOnEnded());
882 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2, GetAudioHash());
884 // Seek somewhere outside of the pre-skip / end-trim section, demuxer should
885 // correctly preroll enough to accurately decode this segment.
886 seek_time = base::TimeDelta::FromMilliseconds(6360);
887 source.Seek(seek_time);
888 ASSERT_TRUE(Seek(seek_time));
889 Play();
890 ASSERT_TRUE(WaitUntilOnEnded());
891 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3, GetAudioHash());
894 // TODO(dalecurtis): Add an opus test file which FFmpeg and ChunkDemuxer will
895 // both seek the same in and shows the difference of preroll.
896 // http://crbug.com/509894
898 TEST_F(PipelineIntegrationTest, BasicPlaybackLive) {
899 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-live.webm", kHashed));
901 Play();
903 ASSERT_TRUE(WaitUntilOnEnded());
905 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
906 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
908 // TODO: Fix FFmpeg code to return higher resolution time values so
909 // we don't have to truncate our expectations here.
910 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
911 demuxer_->GetTimelineOffset());
914 TEST_F(PipelineIntegrationTest, F32PlaybackHashed) {
915 ASSERT_EQ(PIPELINE_OK, Start("sfx_f32le.wav", kHashed));
916 Play();
917 ASSERT_TRUE(WaitUntilOnEnded());
918 EXPECT_HASH_EQ(std::string(kNullVideoHash), GetVideoHash());
919 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
922 #if !defined(DISABLE_EME_TESTS)
923 TEST_F(PipelineIntegrationTest, BasicPlaybackEncrypted) {
924 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
925 set_encrypted_media_init_data_cb(
926 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
927 base::Unretained(&encrypted_media)));
929 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-av_enc-av.webm",
930 encrypted_media.GetCdmContext()));
932 Play();
934 ASSERT_TRUE(WaitUntilOnEnded());
935 Stop();
937 #endif // !defined(DISABLE_EME_TESTS)
939 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource) {
940 MockMediaSource source("bear-320x240.webm", kWebM, 219229);
941 StartPipelineWithMediaSource(&source);
942 source.EndOfStream();
944 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
945 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
946 EXPECT_EQ(k320WebMFileDurationMs,
947 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
949 Play();
951 ASSERT_TRUE(WaitUntilOnEnded());
953 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null());
954 source.Abort();
955 Stop();
958 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Live) {
959 MockMediaSource source("bear-320x240-live.webm", kWebM, 219221);
960 StartPipelineWithMediaSource(&source);
961 source.EndOfStream();
963 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
964 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
965 EXPECT_EQ(k320WebMFileDurationMs,
966 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
968 Play();
970 ASSERT_TRUE(WaitUntilOnEnded());
972 EXPECT_EQ(kLiveTimelineOffset(),
973 demuxer_->GetTimelineOffset());
974 source.Abort();
975 Stop();
978 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP9_WebM) {
979 MockMediaSource source("bear-vp9.webm", kWebMVP9, 67504);
980 StartPipelineWithMediaSource(&source);
981 source.EndOfStream();
983 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
984 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
985 EXPECT_EQ(kVP9WebMFileDurationMs,
986 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
988 Play();
990 ASSERT_TRUE(WaitUntilOnEnded());
991 source.Abort();
992 Stop();
995 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VP8A_WebM) {
996 MockMediaSource source("bear-vp8a.webm", kVideoOnlyWebM, kAppendWholeFile);
997 StartPipelineWithMediaSource(&source);
998 source.EndOfStream();
1000 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1001 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1002 EXPECT_EQ(kVP8AWebMFileDurationMs,
1003 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1005 Play();
1007 ASSERT_TRUE(WaitUntilOnEnded());
1008 source.Abort();
1009 Stop();
1012 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus_WebM) {
1013 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
1014 kAppendWholeFile);
1015 StartPipelineWithMediaSource(&source);
1016 source.EndOfStream();
1018 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1019 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1020 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
1021 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1022 Play();
1024 ASSERT_TRUE(WaitUntilOnEnded());
1025 source.Abort();
1026 Stop();
1029 // Flaky. http://crbug.com/304776
1030 TEST_F(PipelineIntegrationTest, DISABLED_MediaSource_Opus_Seeking_WebM) {
1031 MockMediaSource source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM,
1032 kAppendWholeFile);
1033 StartHashedPipelineWithMediaSource(&source);
1035 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1036 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1037 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs,
1038 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1040 base::TimeDelta start_seek_time = base::TimeDelta::FromMilliseconds(1000);
1041 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
1043 Play();
1044 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1045 source.Seek(seek_time, 0x1D5, 34017);
1046 source.EndOfStream();
1047 ASSERT_TRUE(Seek(seek_time));
1049 ASSERT_TRUE(WaitUntilOnEnded());
1051 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
1053 source.Abort();
1054 Stop();
1057 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) {
1058 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1059 kAppendWholeFile);
1060 StartPipelineWithMediaSource(&source);
1062 scoped_refptr<DecoderBuffer> second_file =
1063 ReadTestDataFile("bear-640x360.webm");
1065 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1066 second_file->data(), second_file->data_size());
1068 source.EndOfStream();
1070 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1071 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1072 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
1073 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1075 Play();
1077 EXPECT_TRUE(WaitUntilOnEnded());
1078 source.Abort();
1079 Stop();
1082 #if !defined(DISABLE_EME_TESTS)
1083 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) {
1084 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1085 kAppendWholeFile);
1086 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1087 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1089 scoped_refptr<DecoderBuffer> second_file =
1090 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1092 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1093 second_file->data(), second_file->data_size());
1095 source.EndOfStream();
1097 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1098 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1099 EXPECT_EQ(kAppendTimeMs + k640WebMFileDurationMs,
1100 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1102 Play();
1104 EXPECT_TRUE(WaitUntilOnEnded());
1105 source.Abort();
1106 Stop();
1109 // Config changes from encrypted to clear are not currently supported.
1110 TEST_F(PipelineIntegrationTest,
1111 MediaSource_ConfigChange_ClearThenEncrypted_WebM) {
1112 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM,
1113 kAppendWholeFile);
1114 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1115 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1117 scoped_refptr<DecoderBuffer> second_file =
1118 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1120 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1121 second_file->data(), second_file->data_size());
1123 source.EndOfStream();
1125 message_loop_.Run();
1126 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1128 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1129 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1130 // The second video was not added, so its time has not been added.
1131 EXPECT_EQ(k320WebMFileDurationMs,
1132 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1134 Play();
1136 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1137 source.Abort();
1140 // Config changes from clear to encrypted are not currently supported.
1141 TEST_F(PipelineIntegrationTest,
1142 MediaSource_ConfigChange_EncryptedThenClear_WebM) {
1143 MockMediaSource source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM,
1144 kAppendWholeFile);
1145 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1146 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1148 scoped_refptr<DecoderBuffer> second_file =
1149 ReadTestDataFile("bear-640x360.webm");
1151 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1152 second_file->data(), second_file->data_size());
1154 source.EndOfStream();
1156 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1157 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1158 // The second video was not added, so its time has not been added.
1159 EXPECT_EQ(k320EncWebMFileDurationMs,
1160 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1162 Play();
1164 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1165 source.Abort();
1167 #endif // !defined(DISABLE_EME_TESTS)
1169 #if defined(USE_PROPRIETARY_CODECS)
1170 TEST_F(PipelineIntegrationTest, MediaSource_ADTS) {
1171 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1172 StartPipelineWithMediaSource(&source);
1173 source.EndOfStream();
1175 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1176 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1177 EXPECT_EQ(325, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1179 Play();
1181 EXPECT_TRUE(WaitUntilOnEnded());
1184 TEST_F(PipelineIntegrationTest, MediaSource_ADTS_TimestampOffset) {
1185 MockMediaSource source("sfx.adts", kADTS, kAppendWholeFile);
1186 StartHashedPipelineWithMediaSource(&source);
1187 EXPECT_EQ(325, source.last_timestamp_offset().InMilliseconds());
1189 // Trim off multiple frames off the beginning of the segment which will cause
1190 // the first decoded frame to be incorrect if preroll isn't implemented.
1191 const base::TimeDelta adts_preroll_duration =
1192 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1193 const base::TimeDelta append_time =
1194 source.last_timestamp_offset() - adts_preroll_duration;
1196 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.adts");
1197 source.AppendAtTimeWithWindow(append_time,
1198 append_time + adts_preroll_duration,
1199 kInfiniteDuration(),
1200 second_file->data(),
1201 second_file->data_size());
1202 source.EndOfStream();
1204 EXPECT_EQ(592, source.last_timestamp_offset().InMilliseconds());
1205 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1206 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1207 EXPECT_EQ(592, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1209 Play();
1211 EXPECT_TRUE(WaitUntilOnEnded());
1213 // Verify preroll is stripped.
1214 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1217 TEST_F(PipelineIntegrationTest, BasicPlaybackHashed_MP3) {
1218 ASSERT_EQ(PIPELINE_OK, Start("sfx.mp3", kHashed));
1220 Play();
1222 ASSERT_TRUE(WaitUntilOnEnded());
1224 // Verify codec delay and preroll are stripped.
1225 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1228 TEST_F(PipelineIntegrationTest, MediaSource_MP3) {
1229 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1230 StartHashedPipelineWithMediaSource(&source);
1231 source.EndOfStream();
1233 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1234 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1235 EXPECT_EQ(313, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1237 Play();
1239 EXPECT_TRUE(WaitUntilOnEnded());
1241 // Verify that codec delay was stripped.
1242 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1245 TEST_F(PipelineIntegrationTest, MediaSource_MP3_TimestampOffset) {
1246 MockMediaSource source("sfx.mp3", kMP3, kAppendWholeFile);
1247 StartPipelineWithMediaSource(&source);
1248 EXPECT_EQ(313, source.last_timestamp_offset().InMilliseconds());
1250 // There are 576 silent frames at the start of this mp3. The second append
1251 // should trim them off.
1252 const base::TimeDelta mp3_preroll_duration =
1253 base::TimeDelta::FromSecondsD(576.0 / 44100);
1254 const base::TimeDelta append_time =
1255 source.last_timestamp_offset() - mp3_preroll_duration;
1257 scoped_refptr<DecoderBuffer> second_file = ReadTestDataFile("sfx.mp3");
1258 source.AppendAtTimeWithWindow(append_time,
1259 append_time + mp3_preroll_duration,
1260 kInfiniteDuration(),
1261 second_file->data(),
1262 second_file->data_size());
1263 source.EndOfStream();
1265 EXPECT_EQ(613, source.last_timestamp_offset().InMilliseconds());
1266 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1267 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1268 EXPECT_EQ(613, pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1270 Play();
1272 EXPECT_TRUE(WaitUntilOnEnded());
1275 TEST_F(PipelineIntegrationTest, MediaSource_MP3_Icecast) {
1276 MockMediaSource source("icy_sfx.mp3", kMP3, kAppendWholeFile);
1277 StartPipelineWithMediaSource(&source);
1278 source.EndOfStream();
1280 Play();
1282 EXPECT_TRUE(WaitUntilOnEnded());
1285 TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_MP4) {
1286 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4, kAppendWholeFile);
1287 StartPipelineWithMediaSource(&source);
1289 scoped_refptr<DecoderBuffer> second_file =
1290 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1292 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1293 second_file->data(), second_file->data_size());
1295 source.EndOfStream();
1297 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1298 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1299 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1300 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1302 Play();
1304 EXPECT_TRUE(WaitUntilOnEnded());
1305 source.Abort();
1306 Stop();
1309 #if !defined(DISABLE_EME_TESTS)
1310 TEST_F(PipelineIntegrationTest,
1311 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly) {
1312 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1313 kAppendWholeFile);
1314 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1315 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1317 scoped_refptr<DecoderBuffer> second_file =
1318 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1320 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1321 second_file->data(), second_file->data_size());
1323 source.EndOfStream();
1325 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1326 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1327 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1328 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1330 Play();
1332 EXPECT_TRUE(WaitUntilOnEnded());
1333 source.Abort();
1334 Stop();
1337 TEST_F(PipelineIntegrationTest,
1338 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1339 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video,
1340 kAppendWholeFile);
1341 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1342 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1344 scoped_refptr<DecoderBuffer> second_file =
1345 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1347 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1348 second_file->data(), second_file->data_size());
1350 source.EndOfStream();
1352 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1353 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1354 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1355 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1357 Play();
1359 EXPECT_TRUE(WaitUntilOnEnded());
1360 source.Abort();
1361 Stop();
1364 // Config changes from clear to encrypted are not currently supported.
1365 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1366 TEST_F(PipelineIntegrationTest,
1367 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1368 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1369 kAppendWholeFile);
1370 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1371 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1373 scoped_refptr<DecoderBuffer> second_file =
1374 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1376 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1377 second_file->data(), second_file->data_size());
1379 source.EndOfStream();
1381 message_loop_.Run();
1382 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_);
1384 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1385 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1386 // The second video was not added, so its time has not been added.
1387 EXPECT_EQ(k640IsoFileDurationMs,
1388 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1390 Play();
1392 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1393 source.Abort();
1396 // Config changes from encrypted to clear are not currently supported.
1397 TEST_F(PipelineIntegrationTest,
1398 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC) {
1399 MockMediaSource source("bear-640x360-v_frag-cenc.mp4", kMP4Video,
1400 kAppendWholeFile);
1401 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1402 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1404 scoped_refptr<DecoderBuffer> second_file =
1405 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1407 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1408 second_file->data(), second_file->data_size());
1410 source.EndOfStream();
1412 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1413 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1414 // The second video was not added, so its time has not been added.
1415 EXPECT_EQ(k640IsoCencFileDurationMs,
1416 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1418 Play();
1420 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1421 source.Abort();
1423 #endif // !defined(DISABLE_EME_TESTS)
1425 // Verify files which change configuration midstream fail gracefully.
1426 TEST_F(PipelineIntegrationTest, MidStreamConfigChangesFail) {
1427 ASSERT_EQ(PIPELINE_OK, Start("midstream_config_change.mp3"));
1428 Play();
1429 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE);
1432 #endif
1434 TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) {
1435 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-16x9-aspect.webm"));
1436 Play();
1437 ASSERT_TRUE(WaitUntilOnEnded());
1440 #if !defined(DISABLE_EME_TESTS)
1441 TEST_F(PipelineIntegrationTest, EncryptedPlayback_WebM) {
1442 MockMediaSource source("bear-320x240-av_enc-av.webm", kWebM, 219816);
1443 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
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_ClearStart_WebM) {
1457 MockMediaSource source("bear-320x240-av_enc-av_clear-1s.webm", kWebM,
1458 kAppendWholeFile);
1459 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
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_NoEncryptedFrames_WebM) {
1473 MockMediaSource source("bear-320x240-av_enc-av_clear-all.webm", kWebM,
1474 kAppendWholeFile);
1475 FakeEncryptedMedia encrypted_media(new NoResponseApp());
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 #if defined(USE_PROPRIETARY_CODECS)
1490 #if !defined(DISABLE_EME_TESTS)
1491 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_VideoOnly) {
1492 MockMediaSource source("bear-1280x720-v_frag-cenc.mp4", kMP4Video,
1493 kAppendWholeFile);
1494 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1495 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1497 source.EndOfStream();
1498 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1500 Play();
1502 ASSERT_TRUE(WaitUntilOnEnded());
1503 source.Abort();
1504 Stop();
1507 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_AudioOnly) {
1508 MockMediaSource source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio,
1509 kAppendWholeFile);
1510 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1511 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1513 source.EndOfStream();
1514 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1516 Play();
1518 ASSERT_TRUE(WaitUntilOnEnded());
1519 source.Abort();
1520 Stop();
1523 TEST_F(PipelineIntegrationTest,
1524 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly) {
1525 MockMediaSource source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video,
1526 kAppendWholeFile);
1527 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1528 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1530 source.EndOfStream();
1531 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1533 Play();
1535 ASSERT_TRUE(WaitUntilOnEnded());
1536 source.Abort();
1537 Stop();
1540 TEST_F(PipelineIntegrationTest,
1541 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly) {
1542 MockMediaSource source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio,
1543 kAppendWholeFile);
1544 FakeEncryptedMedia encrypted_media(new NoResponseApp());
1545 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1547 source.EndOfStream();
1548 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1550 Play();
1552 ASSERT_TRUE(WaitUntilOnEnded());
1553 source.Abort();
1554 Stop();
1557 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1558 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1559 kMP4Video, kAppendWholeFile);
1560 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1561 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1563 source.EndOfStream();
1564 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1566 Play();
1568 ASSERT_TRUE(WaitUntilOnEnded());
1569 source.Abort();
1570 Stop();
1573 TEST_F(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1574 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1575 kMP4Audio, kAppendWholeFile);
1576 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1577 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1579 source.EndOfStream();
1580 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1582 Play();
1584 ASSERT_TRUE(WaitUntilOnEnded());
1585 source.Abort();
1586 Stop();
1588 #endif // !defined(DISABLE_EME_TESTS)
1590 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3) {
1591 MockMediaSource source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3,
1592 kAppendWholeFile);
1593 StartPipelineWithMediaSource(&source);
1594 source.EndOfStream();
1596 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1597 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1598 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1599 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1601 Play();
1603 ASSERT_TRUE(WaitUntilOnEnded());
1604 source.Abort();
1605 Stop();
1607 #endif // defined(USE_PROPRIETARY_CODECS)
1609 TEST_F(PipelineIntegrationTest, SeekWhilePaused) {
1610 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1612 base::TimeDelta duration(pipeline_->GetMediaDuration());
1613 base::TimeDelta start_seek_time(duration / 4);
1614 base::TimeDelta seek_time(duration * 3 / 4);
1616 Play();
1617 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1618 Pause();
1619 ASSERT_TRUE(Seek(seek_time));
1620 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1621 Play();
1622 ASSERT_TRUE(WaitUntilOnEnded());
1624 // Make sure seeking after reaching the end works as expected.
1625 Pause();
1626 ASSERT_TRUE(Seek(seek_time));
1627 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
1628 Play();
1629 ASSERT_TRUE(WaitUntilOnEnded());
1632 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) {
1633 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm"));
1635 base::TimeDelta duration(pipeline_->GetMediaDuration());
1636 base::TimeDelta start_seek_time(duration / 4);
1637 base::TimeDelta seek_time(duration * 3 / 4);
1639 Play();
1640 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time));
1641 ASSERT_TRUE(Seek(seek_time));
1642 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1643 ASSERT_TRUE(WaitUntilOnEnded());
1645 // Make sure seeking after reaching the end works as expected.
1646 ASSERT_TRUE(Seek(seek_time));
1647 EXPECT_GE(pipeline_->GetMediaTime(), seek_time);
1648 ASSERT_TRUE(WaitUntilOnEnded());
1651 #if defined(USE_PROPRIETARY_CODECS)
1652 TEST_F(PipelineIntegrationTest, Rotated_Metadata_0) {
1653 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_0.mp4"));
1654 ASSERT_EQ(VIDEO_ROTATION_0, metadata_.video_rotation);
1657 TEST_F(PipelineIntegrationTest, Rotated_Metadata_90) {
1658 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_90.mp4"));
1659 ASSERT_EQ(VIDEO_ROTATION_90, metadata_.video_rotation);
1662 TEST_F(PipelineIntegrationTest, Rotated_Metadata_180) {
1663 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_180.mp4"));
1664 ASSERT_EQ(VIDEO_ROTATION_180, metadata_.video_rotation);
1667 TEST_F(PipelineIntegrationTest, Rotated_Metadata_270) {
1668 ASSERT_EQ(PIPELINE_OK, Start("bear_rotate_270.mp4"));
1669 ASSERT_EQ(VIDEO_ROTATION_270, metadata_.video_rotation);
1671 #endif
1673 // Verify audio decoder & renderer can handle aborted demuxer reads.
1674 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) {
1675 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM,
1676 16384,
1677 base::TimeDelta::FromMilliseconds(464),
1678 base::TimeDelta::FromMilliseconds(617),
1679 0x10CA, 19730));
1682 // Verify video decoder & renderer can handle aborted demuxer reads.
1683 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) {
1684 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM,
1685 32768,
1686 base::TimeDelta::FromMilliseconds(167),
1687 base::TimeDelta::FromMilliseconds(1668),
1688 0x1C896, 65536));
1691 // Verify that Opus audio in WebM containers can be played back.
1692 TEST_F(PipelineIntegrationTest, BasicPlayback_AudioOnly_Opus_WebM) {
1693 ASSERT_EQ(PIPELINE_OK, Start("bear-opus-end-trimming.webm"));
1694 Play();
1695 ASSERT_TRUE(WaitUntilOnEnded());
1698 // Verify that VP9 video in WebM containers can be played back.
1699 TEST_F(PipelineIntegrationTest, BasicPlayback_VideoOnly_VP9_WebM) {
1700 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
1701 Play();
1702 ASSERT_TRUE(WaitUntilOnEnded());
1705 // Verify that VP9 video and Opus audio in the same WebM container can be played
1706 // back.
1707 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Opus_WebM) {
1708 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-opus.webm"));
1709 Play();
1710 ASSERT_TRUE(WaitUntilOnEnded());
1713 // Verify that VP8 video with alpha channel can be played back.
1714 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_WebM) {
1715 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a.webm"));
1716 Play();
1717 ASSERT_TRUE(WaitUntilOnEnded());
1718 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1721 // Verify that VP8A video with odd width/height can be played back.
1722 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8A_Odd_WebM) {
1723 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8a-odd-dimensions.webm"));
1724 Play();
1725 ASSERT_TRUE(WaitUntilOnEnded());
1726 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12A);
1729 // Verify that VP9 video with odd width/height can be played back.
1730 TEST_F(PipelineIntegrationTest, BasicPlayback_VP9_Odd_WebM) {
1731 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-odd-dimensions.webm"));
1732 Play();
1733 ASSERT_TRUE(WaitUntilOnEnded());
1736 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1737 // Verify that VP8 video with inband text track can be played back.
1738 TEST_F(PipelineIntegrationTest, BasicPlayback_VP8_WebVTT_WebM) {
1739 EXPECT_CALL(*this, OnAddTextTrack(_, _));
1740 ASSERT_EQ(PIPELINE_OK, Start("bear-vp8-webvtt.webm"));
1741 Play();
1742 ASSERT_TRUE(WaitUntilOnEnded());
1744 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1746 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1747 TEST_F(PipelineIntegrationTest, P444_VP9_WebM) {
1748 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240-P444.webm"));
1749 Play();
1750 ASSERT_TRUE(WaitUntilOnEnded());
1751 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV24);
1754 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1755 // format.
1756 TEST_F(PipelineIntegrationTest, BT709_VP9_WebM) {
1757 ASSERT_EQ(PIPELINE_OK, Start("bear-vp9-bt709.webm"));
1758 Play();
1759 ASSERT_TRUE(WaitUntilOnEnded());
1760 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_, PIXEL_FORMAT_YV12);
1761 EXPECT_COLOR_SPACE_EQ(last_video_frame_color_space_, COLOR_SPACE_HD_REC709);
1764 // Verify that videos with an odd frame size playback successfully.
1765 TEST_F(PipelineIntegrationTest, BasicPlayback_OddVideoSize) {
1766 ASSERT_EQ(PIPELINE_OK, Start("butterfly-853x480.webm"));
1767 Play();
1768 ASSERT_TRUE(WaitUntilOnEnded());
1771 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1772 // correctly at 48kHz
1773 TEST_F(PipelineIntegrationTest, BasicPlayback_Opus441kHz) {
1774 ASSERT_EQ(PIPELINE_OK, Start("sfx-opus-441.webm"));
1775 Play();
1776 ASSERT_TRUE(WaitUntilOnEnded());
1777 EXPECT_EQ(48000,
1778 demuxer_->GetStream(DemuxerStream::AUDIO)
1779 ->audio_decoder_config()
1780 .samples_per_second());
1783 // Same as above but using MediaSource.
1784 TEST_F(PipelineIntegrationTest, BasicPlayback_MediaSource_Opus441kHz) {
1785 MockMediaSource source(
1786 "sfx-opus-441.webm", kOpusAudioOnlyWebM, kAppendWholeFile);
1787 StartPipelineWithMediaSource(&source);
1788 source.EndOfStream();
1789 Play();
1790 ASSERT_TRUE(WaitUntilOnEnded());
1791 source.Abort();
1792 Stop();
1793 EXPECT_EQ(48000,
1794 demuxer_->GetStream(DemuxerStream::AUDIO)
1795 ->audio_decoder_config()
1796 .samples_per_second());
1799 // Ensures audio-only playback with missing or negative timestamps works. Tests
1800 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1801 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOgg) {
1802 ASSERT_EQ(PIPELINE_OK, Start("double-sfx.ogg"));
1803 Play();
1804 ASSERT_TRUE(WaitUntilOnEnded());
1805 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1808 // Ensures audio-video playback with missing or negative timestamps fails softly
1809 // instead of crashing. See http://crbug.com/396864.
1810 TEST_F(PipelineIntegrationTest, BasicPlaybackChainedOggVideo) {
1811 ASSERT_EQ(PIPELINE_OK, Start("double-bear.ogv"));
1812 Play();
1813 EXPECT_EQ(PIPELINE_ERROR_DECODE, WaitUntilEndedOrError());
1814 ASSERT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
1817 // Tests that we signal ended even when audio runs longer than video track.
1818 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioLongerThanVideo) {
1819 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv"));
1820 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1821 // of the two.
1822 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds());
1823 Play();
1824 ASSERT_TRUE(WaitUntilOnEnded());
1827 // Tests that we signal ended even when audio runs shorter than video track.
1828 TEST_F(PipelineIntegrationTest, BasicPlaybackAudioShorterThanVideo) {
1829 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv"));
1830 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1831 // the two.
1832 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds());
1833 Play();
1834 ASSERT_TRUE(WaitUntilOnEnded());
1837 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
1838 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
1839 Play();
1840 ASSERT_TRUE(WaitUntilOnEnded());
1841 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1842 demuxer_->GetStartTime());
1845 } // namespace media