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.
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"
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
50 #define DISABLE_TEXT_TRACK_TESTS 1
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)
58 using testing::AnyNumber
;
59 using testing::AtLeast
;
60 using testing::AtMost
;
61 using testing::SaveArg
;
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,";
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)
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
{
174 // Defines the behavior of the "app" that responds to EME events.
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_
),
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
,
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
,
245 void OnEncryptedMediaInitData(EmeInitDataType init_data_type
,
246 const std::vector
<uint8_t>& init_data
) {
247 app_
->OnEncryptedMediaInitData(init_data_type
, init_data
, &decryptor_
);
251 class TestCdmContext
: public CdmContext
{
253 TestCdmContext(Decryptor
* decryptor
) : decryptor_(decryptor
) {}
255 Decryptor
* GetDecryptor() final
{ return decryptor_
; }
256 int GetCdmId() const final
{ return kInvalidCdmId
; }
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
{
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
<>(
295 &KeyProvidingApp::OnResolve
, base::Unretained(this), expected
),
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),
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());
327 std::string error_message
;
328 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string
, &key_ids
,
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.
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_
)
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
));
383 std::string current_session_id_
;
384 std::vector
<uint8_t> prev_init_data_
;
387 class RotatingKeyProvidingApp
: public KeyProvidingApp
{
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_
)
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());
430 uint32_t num_distinct_need_key_calls_
;
433 // Ignores needkey and does not perform a license request
434 class NoResponseApp
: public FakeEncryptedMedia::AppBase
{
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
465 class MockMediaSource
{
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
),
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()),
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_
->ResetParserState(
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
,
532 CHECK(!chunk_demuxer_
->IsParsingMediaSegment(kSourceId
));
533 chunk_demuxer_
->AppendData(kSourceId
, pData
, size
,
534 base::TimeDelta(), kInfiniteDuration(),
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
,
546 CHECK(!chunk_demuxer_
->IsParsingMediaSegment(kSourceId
));
547 chunk_demuxer_
->AppendData(kSourceId
,
553 base::Bind(&MockMediaSource::InitSegmentReceived
,
554 base::Unretained(this)));
555 last_timestamp_offset_
= timestamp_offset
;
559 chunk_demuxer_
->MarkEndOfStream(PIPELINE_OK
);
565 chunk_demuxer_
->ResetParserState(
567 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_
);
568 chunk_demuxer_
->Shutdown();
569 chunk_demuxer_
= NULL
;
572 void DemuxerOpened() {
573 base::MessageLoop::current()->PostTask(
574 FROM_HERE
, base::Bind(&MockMediaSource::DemuxerOpenedTask
,
575 base::Unretained(this)));
578 void DemuxerOpenedTask() {
579 // This code assumes that |mimetype_| is one of the following forms.
581 // 2. video/webm;codec="vorbis,vp8".
582 size_t semicolon
= mimetype_
.find(";");
583 std::string type
= mimetype_
;
584 std::vector
<std::string
> codecs
;
585 if (semicolon
!= std::string::npos
) {
586 type
= mimetype_
.substr(0, semicolon
);
587 size_t codecs_param_start
= mimetype_
.find("codecs=\"", semicolon
);
589 CHECK_NE(codecs_param_start
, std::string::npos
);
591 codecs_param_start
+= 8; // Skip over the codecs=".
593 size_t codecs_param_end
= mimetype_
.find("\"", codecs_param_start
);
595 CHECK_NE(codecs_param_end
, std::string::npos
);
597 std::string codecs_param
=
598 mimetype_
.substr(codecs_param_start
,
599 codecs_param_end
- codecs_param_start
);
600 codecs
= base::SplitString(
601 codecs_param
, ",", base::KEEP_WHITESPACE
, base::SPLIT_WANT_NONEMPTY
);
604 CHECK_EQ(chunk_demuxer_
->AddId(kSourceId
, type
, codecs
), ChunkDemuxer::kOk
);
606 AppendData(initial_append_size_
);
609 void OnEncryptedMediaInitData(EmeInitDataType init_data_type
,
610 const std::vector
<uint8_t>& init_data
) {
611 DCHECK(!init_data
.empty());
612 CHECK(!encrypted_media_init_data_cb_
.is_null());
613 encrypted_media_init_data_cb_
.Run(init_data_type
, init_data
);
616 base::TimeDelta
last_timestamp_offset() const {
617 return last_timestamp_offset_
;
620 MOCK_METHOD0(InitSegmentReceived
, void(void));
623 scoped_refptr
<DecoderBuffer
> file_data_
;
624 int current_position_
;
625 int initial_append_size_
;
626 std::string mimetype_
;
627 ChunkDemuxer
* chunk_demuxer_
;
628 scoped_ptr
<Demuxer
> owned_chunk_demuxer_
;
629 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
630 base::TimeDelta last_timestamp_offset_
;
633 #if defined(MOJO_RENDERER)
634 class PipelineIntegrationTestHost
: public mojo::test::ApplicationTestBase
,
635 public PipelineIntegrationTestBase
{
637 bool ShouldCreateDefaultRunLoop() override
{ return false; }
639 void SetUp() override
{
640 ApplicationTestBase::SetUp();
641 InitializeMediaLibrary();
645 scoped_ptr
<Renderer
> CreateRenderer() override
{
646 mojo::URLRequestPtr
request(mojo::URLRequest::New());
647 request
->url
= mojo::String::From("mojo:media");
648 mojo::ServiceProvider
* service_provider
=
650 ->ConnectToApplication(request
.Pass())
651 ->GetServiceProvider();
653 mojo::ConnectToService(service_provider
, &media_service_factory_
);
655 interfaces::RendererPtr mojo_renderer
;
656 media_service_factory_
->CreateRenderer(mojo::GetProxy(&mojo_renderer
));
658 return make_scoped_ptr(new MojoRendererImpl(message_loop_
.task_runner(),
659 mojo_renderer
.Pass()));
663 interfaces::ServiceFactoryPtr media_service_factory_
;
666 class PipelineIntegrationTestHost
: public testing::Test
,
667 public PipelineIntegrationTestBase
{};
670 class PipelineIntegrationTest
: public PipelineIntegrationTestHost
{
672 void StartPipelineWithMediaSource(MockMediaSource
* source
) {
673 EXPECT_CALL(*source
, InitSegmentReceived()).Times(AtLeast(1));
674 EXPECT_CALL(*this, OnMetadata(_
))
676 .WillRepeatedly(SaveArg
<0>(&metadata_
));
677 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH
))
679 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING
))
682 // Encrypted content not used, so this is never called.
683 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
685 demuxer_
= source
->GetDemuxer().Pass();
687 demuxer_
.get(), CreateRenderer(),
688 base::Bind(&PipelineIntegrationTest::OnEnded
, base::Unretained(this)),
689 base::Bind(&PipelineIntegrationTest::OnError
, base::Unretained(this)),
690 base::Bind(&PipelineIntegrationTest::OnStatusCallback
,
691 base::Unretained(this)),
692 base::Bind(&PipelineIntegrationTest::OnMetadata
,
693 base::Unretained(this)),
694 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged
,
695 base::Unretained(this)),
696 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack
,
697 base::Unretained(this)),
698 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey
,
699 base::Unretained(this)));
701 EXPECT_EQ(PIPELINE_OK
, pipeline_status_
);
704 void StartHashedPipelineWithMediaSource(MockMediaSource
* source
) {
705 hashing_enabled_
= true;
706 StartPipelineWithMediaSource(source
);
709 void StartHashedClocklessPipelineWithMediaSource(MockMediaSource
* source
) {
710 hashing_enabled_
= true;
711 clockless_playback_
= true;
712 StartPipelineWithMediaSource(source
);
715 void StartPipelineWithEncryptedMedia(
716 MockMediaSource
* source
,
717 FakeEncryptedMedia
* encrypted_media
) {
718 EXPECT_CALL(*source
, InitSegmentReceived()).Times(AtLeast(1));
719 EXPECT_CALL(*this, OnMetadata(_
))
721 .WillRepeatedly(SaveArg
<0>(&metadata_
));
722 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH
))
724 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING
))
726 EXPECT_CALL(*this, DecryptorAttached(true));
728 // Encrypted content used but keys provided in advance, so this is
730 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
732 demuxer_
= source
->GetDemuxer().Pass();
734 pipeline_
->SetCdm(encrypted_media
->GetCdmContext(),
735 base::Bind(&PipelineIntegrationTest::DecryptorAttached
,
736 base::Unretained(this)));
739 demuxer_
.get(), CreateRenderer(),
740 base::Bind(&PipelineIntegrationTest::OnEnded
, base::Unretained(this)),
741 base::Bind(&PipelineIntegrationTest::OnError
, base::Unretained(this)),
742 base::Bind(&PipelineIntegrationTest::OnStatusCallback
,
743 base::Unretained(this)),
744 base::Bind(&PipelineIntegrationTest::OnMetadata
,
745 base::Unretained(this)),
746 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged
,
747 base::Unretained(this)),
748 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack
,
749 base::Unretained(this)),
750 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey
,
751 base::Unretained(this)));
753 source
->set_encrypted_media_init_data_cb(
754 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData
,
755 base::Unretained(encrypted_media
)));
758 EXPECT_EQ(PIPELINE_OK
, pipeline_status_
);
761 // Verifies that seeking works properly for ChunkDemuxer when the
762 // seek happens while there is a pending read on the ChunkDemuxer
763 // and no data is available.
764 bool TestSeekDuringRead(const std::string
& filename
,
765 const std::string
& mimetype
,
766 int initial_append_size
,
767 base::TimeDelta start_seek_time
,
768 base::TimeDelta seek_time
,
769 int seek_file_position
,
770 int seek_append_size
) {
771 MockMediaSource
source(filename
, mimetype
, initial_append_size
);
772 StartPipelineWithMediaSource(&source
);
774 if (pipeline_status_
!= PIPELINE_OK
)
778 if (!WaitUntilCurrentTimeIsAfter(start_seek_time
))
781 source
.Seek(seek_time
, seek_file_position
, seek_append_size
);
782 if (!Seek(seek_time
))
785 source
.EndOfStream();
793 TEST_F(PipelineIntegrationTest
, BasicPlayback
) {
794 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
798 ASSERT_TRUE(WaitUntilOnEnded());
801 TEST_F(PipelineIntegrationTest
, BasicPlaybackOpusOgg
) {
802 ASSERT_EQ(PIPELINE_OK
, Start("bear-opus.ogg"));
806 ASSERT_TRUE(WaitUntilOnEnded());
809 TEST_F(PipelineIntegrationTest
, BasicPlaybackHashed
) {
810 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm", kHashed
));
814 ASSERT_TRUE(WaitUntilOnEnded());
816 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
817 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
818 EXPECT_TRUE(demuxer_
->GetTimelineOffset().is_null());
821 TEST_F(PipelineIntegrationTest
, BasicPlaybackOpusOggTrimmingHashed
) {
822 ASSERT_EQ(PIPELINE_OK
,
823 Start("opus-trimming-test.webm", kHashed
| kClockless
));
827 ASSERT_TRUE(WaitUntilOnEnded());
828 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1
, GetAudioHash());
830 // Seek within the pre-skip section, this should not cause a beep.
831 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
833 ASSERT_TRUE(WaitUntilOnEnded());
834 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2
, GetAudioHash());
836 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
837 // correctly preroll enough to accurately decode this segment.
838 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
840 ASSERT_TRUE(WaitUntilOnEnded());
841 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3
, GetAudioHash());
844 TEST_F(PipelineIntegrationTest
, BasicPlaybackOpusWebmTrimmingHashed
) {
845 ASSERT_EQ(PIPELINE_OK
,
846 Start("opus-trimming-test.webm", kHashed
| kClockless
));
850 ASSERT_TRUE(WaitUntilOnEnded());
851 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1
, GetAudioHash());
853 // Seek within the pre-skip section, this should not cause a beep.
854 ASSERT_TRUE(Seek(base::TimeDelta::FromSeconds(1)));
856 ASSERT_TRUE(WaitUntilOnEnded());
857 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2
, GetAudioHash());
859 // Seek somewhere outside of the pre-skip / end-trim section, demxuer should
860 // correctly preroll enough to accurately decode this segment.
861 ASSERT_TRUE(Seek(base::TimeDelta::FromMilliseconds(6360)));
863 ASSERT_TRUE(WaitUntilOnEnded());
864 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3
, GetAudioHash());
867 TEST_F(PipelineIntegrationTest
,
868 BasicPlaybackOpusWebmTrimmingHashed_MediaSource
) {
869 MockMediaSource
source("opus-trimming-test.webm", kOpusAudioOnlyWebM
,
871 StartHashedClocklessPipelineWithMediaSource(&source
);
872 source
.EndOfStream();
876 ASSERT_TRUE(WaitUntilOnEnded());
877 EXPECT_HASH_EQ(kOpusEndTrimmingHash_1
, GetAudioHash());
879 // Seek within the pre-skip section, this should not cause a beep.
880 base::TimeDelta seek_time
= base::TimeDelta::FromSeconds(1);
881 source
.Seek(seek_time
);
882 ASSERT_TRUE(Seek(seek_time
));
884 ASSERT_TRUE(WaitUntilOnEnded());
885 EXPECT_HASH_EQ(kOpusEndTrimmingHash_2
, GetAudioHash());
887 // Seek somewhere outside of the pre-skip / end-trim section, demuxer should
888 // correctly preroll enough to accurately decode this segment.
889 seek_time
= base::TimeDelta::FromMilliseconds(6360);
890 source
.Seek(seek_time
);
891 ASSERT_TRUE(Seek(seek_time
));
893 ASSERT_TRUE(WaitUntilOnEnded());
894 EXPECT_HASH_EQ(kOpusEndTrimmingHash_3
, GetAudioHash());
897 // TODO(dalecurtis): Add an opus test file which FFmpeg and ChunkDemuxer will
898 // both seek the same in and shows the difference of preroll.
899 // http://crbug.com/509894
901 TEST_F(PipelineIntegrationTest
, BasicPlaybackLive
) {
902 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-live.webm", kHashed
));
906 ASSERT_TRUE(WaitUntilOnEnded());
908 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
909 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
911 // TODO: Fix FFmpeg code to return higher resolution time values so
912 // we don't have to truncate our expectations here.
913 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
914 demuxer_
->GetTimelineOffset());
917 TEST_F(PipelineIntegrationTest
, F32PlaybackHashed
) {
918 ASSERT_EQ(PIPELINE_OK
, Start("sfx_f32le.wav", kHashed
));
920 ASSERT_TRUE(WaitUntilOnEnded());
921 EXPECT_HASH_EQ(std::string(kNullVideoHash
), GetVideoHash());
922 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
925 #if !defined(DISABLE_EME_TESTS)
926 TEST_F(PipelineIntegrationTest
, BasicPlaybackEncrypted
) {
927 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
928 set_encrypted_media_init_data_cb(
929 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData
,
930 base::Unretained(&encrypted_media
)));
932 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-av_enc-av.webm",
933 encrypted_media
.GetCdmContext()));
937 ASSERT_TRUE(WaitUntilOnEnded());
940 #endif // !defined(DISABLE_EME_TESTS)
942 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource
) {
943 MockMediaSource
source("bear-320x240.webm", kWebM
, 219229);
944 StartPipelineWithMediaSource(&source
);
945 source
.EndOfStream();
947 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
948 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
949 EXPECT_EQ(k320WebMFileDurationMs
,
950 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
954 ASSERT_TRUE(WaitUntilOnEnded());
956 EXPECT_TRUE(demuxer_
->GetTimelineOffset().is_null());
961 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Live
) {
962 MockMediaSource
source("bear-320x240-live.webm", kWebM
, 219221);
963 StartPipelineWithMediaSource(&source
);
964 source
.EndOfStream();
966 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
967 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
968 EXPECT_EQ(k320WebMFileDurationMs
,
969 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
973 ASSERT_TRUE(WaitUntilOnEnded());
975 EXPECT_EQ(kLiveTimelineOffset(),
976 demuxer_
->GetTimelineOffset());
981 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VP9_WebM
) {
982 MockMediaSource
source("bear-vp9.webm", kWebMVP9
, 67504);
983 StartPipelineWithMediaSource(&source
);
984 source
.EndOfStream();
986 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
987 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
988 EXPECT_EQ(kVP9WebMFileDurationMs
,
989 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
993 ASSERT_TRUE(WaitUntilOnEnded());
998 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VP8A_WebM
) {
999 MockMediaSource
source("bear-vp8a.webm", kVideoOnlyWebM
, kAppendWholeFile
);
1000 StartPipelineWithMediaSource(&source
);
1001 source
.EndOfStream();
1003 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1004 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1005 EXPECT_EQ(kVP8AWebMFileDurationMs
,
1006 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1010 ASSERT_TRUE(WaitUntilOnEnded());
1015 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Opus_WebM
) {
1016 MockMediaSource
source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM
,
1018 StartPipelineWithMediaSource(&source
);
1019 source
.EndOfStream();
1021 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1022 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1023 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs
,
1024 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1027 ASSERT_TRUE(WaitUntilOnEnded());
1032 // Flaky. http://crbug.com/304776
1033 TEST_F(PipelineIntegrationTest
, DISABLED_MediaSource_Opus_Seeking_WebM
) {
1034 MockMediaSource
source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM
,
1036 StartHashedPipelineWithMediaSource(&source
);
1038 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1039 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1040 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs
,
1041 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1043 base::TimeDelta start_seek_time
= base::TimeDelta::FromMilliseconds(1000);
1044 base::TimeDelta seek_time
= base::TimeDelta::FromMilliseconds(2000);
1047 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
1048 source
.Seek(seek_time
, 0x1D5, 34017);
1049 source
.EndOfStream();
1050 ASSERT_TRUE(Seek(seek_time
));
1052 ASSERT_TRUE(WaitUntilOnEnded());
1054 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
1060 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_WebM
) {
1061 MockMediaSource
source("bear-320x240-16x9-aspect.webm", kWebM
,
1063 StartPipelineWithMediaSource(&source
);
1065 scoped_refptr
<DecoderBuffer
> second_file
=
1066 ReadTestDataFile("bear-640x360.webm");
1068 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1069 second_file
->data(), second_file
->data_size());
1071 source
.EndOfStream();
1073 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1074 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1075 EXPECT_EQ(kAppendTimeMs
+ k640WebMFileDurationMs
,
1076 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1080 EXPECT_TRUE(WaitUntilOnEnded());
1085 #if !defined(DISABLE_EME_TESTS)
1086 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_Encrypted_WebM
) {
1087 MockMediaSource
source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM
,
1089 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1090 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1092 scoped_refptr
<DecoderBuffer
> second_file
=
1093 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1095 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1096 second_file
->data(), second_file
->data_size());
1098 source
.EndOfStream();
1100 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1101 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1102 EXPECT_EQ(kAppendTimeMs
+ k640WebMFileDurationMs
,
1103 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1107 EXPECT_TRUE(WaitUntilOnEnded());
1112 // Config changes from encrypted to clear are not currently supported.
1113 TEST_F(PipelineIntegrationTest
,
1114 MediaSource_ConfigChange_ClearThenEncrypted_WebM
) {
1115 MockMediaSource
source("bear-320x240-16x9-aspect.webm", kWebM
,
1117 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1118 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1120 scoped_refptr
<DecoderBuffer
> second_file
=
1121 ReadTestDataFile("bear-640x360-av_enc-av.webm");
1123 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1124 second_file
->data(), second_file
->data_size());
1126 source
.EndOfStream();
1128 message_loop_
.Run();
1129 EXPECT_EQ(PIPELINE_ERROR_DECODE
, pipeline_status_
);
1131 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1132 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1133 // The second video was not added, so its time has not been added.
1134 EXPECT_EQ(k320WebMFileDurationMs
,
1135 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1139 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1143 // Config changes from clear to encrypted are not currently supported.
1144 TEST_F(PipelineIntegrationTest
,
1145 MediaSource_ConfigChange_EncryptedThenClear_WebM
) {
1146 MockMediaSource
source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM
,
1148 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1149 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1151 scoped_refptr
<DecoderBuffer
> second_file
=
1152 ReadTestDataFile("bear-640x360.webm");
1154 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1155 second_file
->data(), second_file
->data_size());
1157 source
.EndOfStream();
1159 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1160 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1161 // The second video was not added, so its time has not been added.
1162 EXPECT_EQ(k320EncWebMFileDurationMs
,
1163 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1167 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1170 #endif // !defined(DISABLE_EME_TESTS)
1172 #if defined(USE_PROPRIETARY_CODECS)
1173 TEST_F(PipelineIntegrationTest
, MediaSource_ADTS
) {
1174 MockMediaSource
source("sfx.adts", kADTS
, kAppendWholeFile
);
1175 StartPipelineWithMediaSource(&source
);
1176 source
.EndOfStream();
1178 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1179 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1180 EXPECT_EQ(325, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1184 EXPECT_TRUE(WaitUntilOnEnded());
1187 TEST_F(PipelineIntegrationTest
, MediaSource_ADTS_TimestampOffset
) {
1188 MockMediaSource
source("sfx.adts", kADTS
, kAppendWholeFile
);
1189 StartHashedPipelineWithMediaSource(&source
);
1190 EXPECT_EQ(325, source
.last_timestamp_offset().InMilliseconds());
1192 // Trim off multiple frames off the beginning of the segment which will cause
1193 // the first decoded frame to be incorrect if preroll isn't implemented.
1194 const base::TimeDelta adts_preroll_duration
=
1195 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1196 const base::TimeDelta append_time
=
1197 source
.last_timestamp_offset() - adts_preroll_duration
;
1199 scoped_refptr
<DecoderBuffer
> second_file
= ReadTestDataFile("sfx.adts");
1200 source
.AppendAtTimeWithWindow(append_time
,
1201 append_time
+ adts_preroll_duration
,
1202 kInfiniteDuration(),
1203 second_file
->data(),
1204 second_file
->data_size());
1205 source
.EndOfStream();
1207 EXPECT_EQ(592, source
.last_timestamp_offset().InMilliseconds());
1208 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1209 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1210 EXPECT_EQ(592, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1214 EXPECT_TRUE(WaitUntilOnEnded());
1216 // Verify preroll is stripped.
1217 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1220 TEST_F(PipelineIntegrationTest
, BasicPlaybackHashed_MP3
) {
1221 ASSERT_EQ(PIPELINE_OK
, Start("sfx.mp3", kHashed
));
1225 ASSERT_TRUE(WaitUntilOnEnded());
1227 // Verify codec delay and preroll are stripped.
1228 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1231 TEST_F(PipelineIntegrationTest
, MediaSource_MP3
) {
1232 MockMediaSource
source("sfx.mp3", kMP3
, kAppendWholeFile
);
1233 StartHashedPipelineWithMediaSource(&source
);
1234 source
.EndOfStream();
1236 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1237 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1238 EXPECT_EQ(313, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1242 EXPECT_TRUE(WaitUntilOnEnded());
1244 // Verify that codec delay was stripped.
1245 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1248 TEST_F(PipelineIntegrationTest
, MediaSource_MP3_TimestampOffset
) {
1249 MockMediaSource
source("sfx.mp3", kMP3
, kAppendWholeFile
);
1250 StartPipelineWithMediaSource(&source
);
1251 EXPECT_EQ(313, source
.last_timestamp_offset().InMilliseconds());
1253 // There are 576 silent frames at the start of this mp3. The second append
1254 // should trim them off.
1255 const base::TimeDelta mp3_preroll_duration
=
1256 base::TimeDelta::FromSecondsD(576.0 / 44100);
1257 const base::TimeDelta append_time
=
1258 source
.last_timestamp_offset() - mp3_preroll_duration
;
1260 scoped_refptr
<DecoderBuffer
> second_file
= ReadTestDataFile("sfx.mp3");
1261 source
.AppendAtTimeWithWindow(append_time
,
1262 append_time
+ mp3_preroll_duration
,
1263 kInfiniteDuration(),
1264 second_file
->data(),
1265 second_file
->data_size());
1266 source
.EndOfStream();
1268 EXPECT_EQ(613, source
.last_timestamp_offset().InMilliseconds());
1269 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1270 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1271 EXPECT_EQ(613, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1275 EXPECT_TRUE(WaitUntilOnEnded());
1278 TEST_F(PipelineIntegrationTest
, MediaSource_MP3_Icecast
) {
1279 MockMediaSource
source("icy_sfx.mp3", kMP3
, kAppendWholeFile
);
1280 StartPipelineWithMediaSource(&source
);
1281 source
.EndOfStream();
1285 EXPECT_TRUE(WaitUntilOnEnded());
1288 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_MP4
) {
1289 MockMediaSource
source("bear-640x360-av_frag.mp4", kMP4
, kAppendWholeFile
);
1290 StartPipelineWithMediaSource(&source
);
1292 scoped_refptr
<DecoderBuffer
> second_file
=
1293 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1295 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1296 second_file
->data(), second_file
->data_size());
1298 source
.EndOfStream();
1300 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1301 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1302 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1303 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1307 EXPECT_TRUE(WaitUntilOnEnded());
1312 #if !defined(DISABLE_EME_TESTS)
1313 TEST_F(PipelineIntegrationTest
,
1314 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly
) {
1315 MockMediaSource
source("bear-640x360-v_frag-cenc.mp4", kMP4Video
,
1317 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1318 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1320 scoped_refptr
<DecoderBuffer
> second_file
=
1321 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1323 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1324 second_file
->data(), second_file
->data_size());
1326 source
.EndOfStream();
1328 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1329 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1330 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1331 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1335 EXPECT_TRUE(WaitUntilOnEnded());
1340 TEST_F(PipelineIntegrationTest
,
1341 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly
) {
1342 MockMediaSource
source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video
,
1344 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1345 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1347 scoped_refptr
<DecoderBuffer
> second_file
=
1348 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1350 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1351 second_file
->data(), second_file
->data_size());
1353 source
.EndOfStream();
1355 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1356 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1357 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1358 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1362 EXPECT_TRUE(WaitUntilOnEnded());
1367 // Config changes from clear to encrypted are not currently supported.
1368 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1369 TEST_F(PipelineIntegrationTest
,
1370 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC
) {
1371 MockMediaSource
source("bear-640x360-av_frag.mp4", kMP4Video
,
1373 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1374 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1376 scoped_refptr
<DecoderBuffer
> second_file
=
1377 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1379 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1380 second_file
->data(), second_file
->data_size());
1382 source
.EndOfStream();
1384 message_loop_
.Run();
1385 EXPECT_EQ(PIPELINE_ERROR_DECODE
, pipeline_status_
);
1387 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1388 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1389 // The second video was not added, so its time has not been added.
1390 EXPECT_EQ(k640IsoFileDurationMs
,
1391 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1395 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1399 // Config changes from encrypted to clear are not currently supported.
1400 TEST_F(PipelineIntegrationTest
,
1401 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC
) {
1402 MockMediaSource
source("bear-640x360-v_frag-cenc.mp4", kMP4Video
,
1404 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1405 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1407 scoped_refptr
<DecoderBuffer
> second_file
=
1408 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1410 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1411 second_file
->data(), second_file
->data_size());
1413 source
.EndOfStream();
1415 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1416 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1417 // The second video was not added, so its time has not been added.
1418 EXPECT_EQ(k640IsoCencFileDurationMs
,
1419 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1423 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1426 #endif // !defined(DISABLE_EME_TESTS)
1428 // Verify files which change configuration midstream fail gracefully.
1429 TEST_F(PipelineIntegrationTest
, MidStreamConfigChangesFail
) {
1430 ASSERT_EQ(PIPELINE_OK
, Start("midstream_config_change.mp3"));
1432 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE
);
1437 TEST_F(PipelineIntegrationTest
, BasicPlayback_16x9AspectRatio
) {
1438 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-16x9-aspect.webm"));
1440 ASSERT_TRUE(WaitUntilOnEnded());
1443 #if !defined(DISABLE_EME_TESTS)
1444 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_WebM
) {
1445 MockMediaSource
source("bear-320x240-av_enc-av.webm", kWebM
, 219816);
1446 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1447 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1449 source
.EndOfStream();
1450 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1454 ASSERT_TRUE(WaitUntilOnEnded());
1459 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_ClearStart_WebM
) {
1460 MockMediaSource
source("bear-320x240-av_enc-av_clear-1s.webm", kWebM
,
1462 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1463 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1465 source
.EndOfStream();
1466 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1470 ASSERT_TRUE(WaitUntilOnEnded());
1475 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_NoEncryptedFrames_WebM
) {
1476 MockMediaSource
source("bear-320x240-av_enc-av_clear-all.webm", kWebM
,
1478 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1479 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1481 source
.EndOfStream();
1482 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1486 ASSERT_TRUE(WaitUntilOnEnded());
1490 #endif // !defined(DISABLE_EME_TESTS)
1492 #if defined(USE_PROPRIETARY_CODECS)
1493 #if !defined(DISABLE_EME_TESTS)
1494 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_VideoOnly
) {
1495 MockMediaSource
source("bear-1280x720-v_frag-cenc.mp4", kMP4Video
,
1497 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1498 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1500 source
.EndOfStream();
1501 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1505 ASSERT_TRUE(WaitUntilOnEnded());
1510 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_AudioOnly
) {
1511 MockMediaSource
source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio
,
1513 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1514 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1516 source
.EndOfStream();
1517 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1521 ASSERT_TRUE(WaitUntilOnEnded());
1526 TEST_F(PipelineIntegrationTest
,
1527 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly
) {
1528 MockMediaSource
source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video
,
1530 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1531 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1533 source
.EndOfStream();
1534 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1538 ASSERT_TRUE(WaitUntilOnEnded());
1543 TEST_F(PipelineIntegrationTest
,
1544 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly
) {
1545 MockMediaSource
source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio
,
1547 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1548 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1550 source
.EndOfStream();
1551 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1555 ASSERT_TRUE(WaitUntilOnEnded());
1560 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_KeyRotation_Video
) {
1561 MockMediaSource
source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1562 kMP4Video
, kAppendWholeFile
);
1563 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1564 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1566 source
.EndOfStream();
1567 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1571 ASSERT_TRUE(WaitUntilOnEnded());
1576 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_KeyRotation_Audio
) {
1577 MockMediaSource
source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1578 kMP4Audio
, kAppendWholeFile
);
1579 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1580 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1582 source
.EndOfStream();
1583 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1587 ASSERT_TRUE(WaitUntilOnEnded());
1591 #endif // !defined(DISABLE_EME_TESTS)
1593 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3
) {
1594 MockMediaSource
source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3
,
1596 StartPipelineWithMediaSource(&source
);
1597 source
.EndOfStream();
1599 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1600 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1601 EXPECT_EQ(k1280IsoAVC3FileDurationMs
,
1602 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1606 ASSERT_TRUE(WaitUntilOnEnded());
1610 #endif // defined(USE_PROPRIETARY_CODECS)
1612 TEST_F(PipelineIntegrationTest
, SeekWhilePaused
) {
1613 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
1615 base::TimeDelta
duration(pipeline_
->GetMediaDuration());
1616 base::TimeDelta
start_seek_time(duration
/ 4);
1617 base::TimeDelta
seek_time(duration
* 3 / 4);
1620 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
1622 ASSERT_TRUE(Seek(seek_time
));
1623 EXPECT_EQ(seek_time
, pipeline_
->GetMediaTime());
1625 ASSERT_TRUE(WaitUntilOnEnded());
1627 // Make sure seeking after reaching the end works as expected.
1629 ASSERT_TRUE(Seek(seek_time
));
1630 EXPECT_EQ(seek_time
, pipeline_
->GetMediaTime());
1632 ASSERT_TRUE(WaitUntilOnEnded());
1635 TEST_F(PipelineIntegrationTest
, SeekWhilePlaying
) {
1636 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
1638 base::TimeDelta
duration(pipeline_
->GetMediaDuration());
1639 base::TimeDelta
start_seek_time(duration
/ 4);
1640 base::TimeDelta
seek_time(duration
* 3 / 4);
1643 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
1644 ASSERT_TRUE(Seek(seek_time
));
1645 EXPECT_GE(pipeline_
->GetMediaTime(), seek_time
);
1646 ASSERT_TRUE(WaitUntilOnEnded());
1648 // Make sure seeking after reaching the end works as expected.
1649 ASSERT_TRUE(Seek(seek_time
));
1650 EXPECT_GE(pipeline_
->GetMediaTime(), seek_time
);
1651 ASSERT_TRUE(WaitUntilOnEnded());
1654 #if defined(USE_PROPRIETARY_CODECS)
1655 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_0
) {
1656 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_0.mp4"));
1657 ASSERT_EQ(VIDEO_ROTATION_0
, metadata_
.video_rotation
);
1660 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_90
) {
1661 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_90.mp4"));
1662 ASSERT_EQ(VIDEO_ROTATION_90
, metadata_
.video_rotation
);
1665 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_180
) {
1666 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_180.mp4"));
1667 ASSERT_EQ(VIDEO_ROTATION_180
, metadata_
.video_rotation
);
1670 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_270
) {
1671 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_270.mp4"));
1672 ASSERT_EQ(VIDEO_ROTATION_270
, metadata_
.video_rotation
);
1676 // Verify audio decoder & renderer can handle aborted demuxer reads.
1677 TEST_F(PipelineIntegrationTest
, ChunkDemuxerAbortRead_AudioOnly
) {
1678 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM
,
1680 base::TimeDelta::FromMilliseconds(464),
1681 base::TimeDelta::FromMilliseconds(617),
1685 // Verify video decoder & renderer can handle aborted demuxer reads.
1686 TEST_F(PipelineIntegrationTest
, ChunkDemuxerAbortRead_VideoOnly
) {
1687 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM
,
1689 base::TimeDelta::FromMilliseconds(167),
1690 base::TimeDelta::FromMilliseconds(1668),
1694 // Verify that Opus audio in WebM containers can be played back.
1695 TEST_F(PipelineIntegrationTest
, BasicPlayback_AudioOnly_Opus_WebM
) {
1696 ASSERT_EQ(PIPELINE_OK
, Start("bear-opus-end-trimming.webm"));
1698 ASSERT_TRUE(WaitUntilOnEnded());
1701 // Verify that VP9 video in WebM containers can be played back.
1702 TEST_F(PipelineIntegrationTest
, BasicPlayback_VideoOnly_VP9_WebM
) {
1703 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9.webm"));
1705 ASSERT_TRUE(WaitUntilOnEnded());
1708 // Verify that VP9 video and Opus audio in the same WebM container can be played
1710 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP9_Opus_WebM
) {
1711 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9-opus.webm"));
1713 ASSERT_TRUE(WaitUntilOnEnded());
1716 // Verify that VP8 video with alpha channel can be played back.
1717 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8A_WebM
) {
1718 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8a.webm"));
1720 ASSERT_TRUE(WaitUntilOnEnded());
1721 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, PIXEL_FORMAT_YV12A
);
1724 // Verify that VP8A video with odd width/height can be played back.
1725 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8A_Odd_WebM
) {
1726 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8a-odd-dimensions.webm"));
1728 ASSERT_TRUE(WaitUntilOnEnded());
1729 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, PIXEL_FORMAT_YV12A
);
1732 // Verify that VP9 video with odd width/height can be played back.
1733 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP9_Odd_WebM
) {
1734 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9-odd-dimensions.webm"));
1736 ASSERT_TRUE(WaitUntilOnEnded());
1739 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1740 // Verify that VP8 video with inband text track can be played back.
1741 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8_WebVTT_WebM
) {
1742 EXPECT_CALL(*this, OnAddTextTrack(_
, _
));
1743 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8-webvtt.webm"));
1745 ASSERT_TRUE(WaitUntilOnEnded());
1747 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1749 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1750 TEST_F(PipelineIntegrationTest
, P444_VP9_WebM
) {
1751 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-P444.webm"));
1753 ASSERT_TRUE(WaitUntilOnEnded());
1754 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, PIXEL_FORMAT_YV24
);
1757 // Verify that frames of VP9 video in the BT.709 color space have the YV12HD
1759 TEST_F(PipelineIntegrationTest
, BT709_VP9_WebM
) {
1760 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9-bt709.webm"));
1762 ASSERT_TRUE(WaitUntilOnEnded());
1763 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, PIXEL_FORMAT_YV12
);
1764 EXPECT_COLOR_SPACE_EQ(last_video_frame_color_space_
, COLOR_SPACE_HD_REC709
);
1767 // Verify that videos with an odd frame size playback successfully.
1768 TEST_F(PipelineIntegrationTest
, BasicPlayback_OddVideoSize
) {
1769 ASSERT_EQ(PIPELINE_OK
, Start("butterfly-853x480.webm"));
1771 ASSERT_TRUE(WaitUntilOnEnded());
1774 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1775 // correctly at 48kHz
1776 TEST_F(PipelineIntegrationTest
, BasicPlayback_Opus441kHz
) {
1777 ASSERT_EQ(PIPELINE_OK
, Start("sfx-opus-441.webm"));
1779 ASSERT_TRUE(WaitUntilOnEnded());
1781 demuxer_
->GetStream(DemuxerStream::AUDIO
)
1782 ->audio_decoder_config()
1783 .samples_per_second());
1786 // Same as above but using MediaSource.
1787 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Opus441kHz
) {
1788 MockMediaSource
source(
1789 "sfx-opus-441.webm", kOpusAudioOnlyWebM
, kAppendWholeFile
);
1790 StartPipelineWithMediaSource(&source
);
1791 source
.EndOfStream();
1793 ASSERT_TRUE(WaitUntilOnEnded());
1797 demuxer_
->GetStream(DemuxerStream::AUDIO
)
1798 ->audio_decoder_config()
1799 .samples_per_second());
1802 // Ensures audio-only playback with missing or negative timestamps works. Tests
1803 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1804 TEST_F(PipelineIntegrationTest
, BasicPlaybackChainedOgg
) {
1805 ASSERT_EQ(PIPELINE_OK
, Start("double-sfx.ogg"));
1807 ASSERT_TRUE(WaitUntilOnEnded());
1808 ASSERT_EQ(base::TimeDelta(), demuxer_
->GetStartTime());
1811 // Ensures audio-video playback with missing or negative timestamps fails softly
1812 // instead of crashing. See http://crbug.com/396864.
1813 TEST_F(PipelineIntegrationTest
, BasicPlaybackChainedOggVideo
) {
1814 ASSERT_EQ(PIPELINE_OK
, Start("double-bear.ogv"));
1816 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1817 ASSERT_EQ(base::TimeDelta(), demuxer_
->GetStartTime());
1820 // Tests that we signal ended even when audio runs longer than video track.
1821 TEST_F(PipelineIntegrationTest
, BasicPlaybackAudioLongerThanVideo
) {
1822 ASSERT_EQ(PIPELINE_OK
, Start("bear_audio_longer_than_video.ogv"));
1823 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1825 EXPECT_EQ(2000, pipeline_
->GetMediaDuration().InMilliseconds());
1827 ASSERT_TRUE(WaitUntilOnEnded());
1830 // Tests that we signal ended even when audio runs shorter than video track.
1831 TEST_F(PipelineIntegrationTest
, BasicPlaybackAudioShorterThanVideo
) {
1832 ASSERT_EQ(PIPELINE_OK
, Start("bear_audio_shorter_than_video.ogv"));
1833 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1835 EXPECT_EQ(1001, pipeline_
->GetMediaDuration().InMilliseconds());
1837 ASSERT_TRUE(WaitUntilOnEnded());
1840 TEST_F(PipelineIntegrationTest
, BasicPlaybackPositiveStartTime
) {
1841 ASSERT_EQ(PIPELINE_OK
, Start("nonzero-start-time.webm"));
1843 ASSERT_TRUE(WaitUntilOnEnded());
1844 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1845 demuxer_
->GetStartTime());
1848 } // namespace media