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/strings/string_util.h"
9 #include "build/build_config.h"
10 #include "media/base/cdm_callback_promise.h"
11 #include "media/base/cdm_context.h"
12 #include "media/base/cdm_key_information.h"
13 #include "media/base/decoder_buffer.h"
14 #include "media/base/media.h"
15 #include "media/base/media_keys.h"
16 #include "media/base/media_switches.h"
17 #include "media/base/test_data_util.h"
18 #include "media/cdm/aes_decryptor.h"
19 #include "media/cdm/json_web_key.h"
20 #include "media/filters/chunk_demuxer.h"
21 #include "media/filters/renderer_impl.h"
22 #include "media/test/pipeline_integration_test_base.h"
23 #include "testing/gmock/include/gmock/gmock.h"
25 #if defined(MOJO_RENDERER)
26 #include "media/mojo/services/mojo_renderer_impl.h"
27 #include "mojo/public/cpp/application/application_impl.h"
28 #include "mojo/public/cpp/application/application_test_base.h"
29 #include "mojo/public/cpp/application/connect.h"
31 // TODO(dalecurtis): The mojo renderer is in another process, so we have no way
32 // currently to get hashes for video and audio samples. This also means that
33 // real audio plays out for each test.
34 #define EXPECT_HASH_EQ(a, b)
35 #define EXPECT_VIDEO_FORMAT_EQ(a, b)
37 // TODO(xhwang): EME support is not complete for the mojo renderer, so all
38 // encrypted tests are currently disabled.
39 #define DISABLE_EME_TESTS 1
41 // TODO(xhwang,dalecurtis): Text tracks are not currently supported by the mojo
43 #define DISABLE_TEXT_TRACK_TESTS 1
45 #define EXPECT_HASH_EQ(a, b) EXPECT_EQ(a, b)
46 #define EXPECT_VIDEO_FORMAT_EQ(a, b) EXPECT_EQ(a, b)
50 using testing::AnyNumber
;
51 using testing::AtLeast
;
52 using testing::AtMost
;
53 using testing::SaveArg
;
57 const char kSourceId
[] = "SourceId";
58 const char kCencInitDataType
[] = "cenc";
59 const uint8 kInitData
[] = { 0x69, 0x6e, 0x69, 0x74 };
61 const char kWebM
[] = "video/webm; codecs=\"vp8,vorbis\"";
62 const char kWebMVP9
[] = "video/webm; codecs=\"vp9\"";
63 const char kAudioOnlyWebM
[] = "video/webm; codecs=\"vorbis\"";
64 const char kOpusAudioOnlyWebM
[] = "video/webm; codecs=\"opus\"";
65 const char kVideoOnlyWebM
[] = "video/webm; codecs=\"vp8\"";
66 #if defined(USE_PROPRIETARY_CODECS)
67 const char kADTS
[] = "audio/aac";
68 const char kMP4
[] = "video/mp4; codecs=\"avc1.4D4041,mp4a.40.2\"";
69 const char kMP4VideoAVC3
[] = "video/mp4; codecs=\"avc3.64001f\"";
70 #if !defined(DISABLE_EME_TESTS)
71 const char kMP4Video
[] = "video/mp4; codecs=\"avc1.4D4041\"";
72 const char kMP4Audio
[] = "audio/mp4; codecs=\"mp4a.40.2\"";
73 #endif // !defined(DISABLE_EME_TESTS)
74 const char kMP3
[] = "audio/mpeg";
75 #endif // defined(USE_PROPRIETARY_CODECS)
77 // Key used to encrypt test files.
78 const uint8 kSecretKey
[] = {
79 0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
80 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c
83 // The key ID for all encrypted files.
84 const uint8 kKeyId
[] = {
85 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
86 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35
89 const int kAppendWholeFile
= -1;
91 // Constants for the Media Source config change tests.
92 const int kAppendTimeSec
= 1;
93 const int kAppendTimeMs
= kAppendTimeSec
* 1000;
94 const int k320WebMFileDurationMs
= 2736;
95 const int k640WebMFileDurationMs
= 2749;
96 const int kOpusEndTrimmingWebMFileDurationMs
= 2741;
97 const int kVP9WebMFileDurationMs
= 2736;
98 const int kVP8AWebMFileDurationMs
= 2733;
100 #if defined(USE_PROPRIETARY_CODECS)
101 #if !defined(DISABLE_EME_TESTS)
102 const int k640IsoFileDurationMs
= 2737;
103 const int k640IsoCencFileDurationMs
= 2736;
104 #endif // !defined(DISABLE_EME_TESTS)
105 const int k1280IsoFileDurationMs
= 2736;
106 const int k1280IsoAVC3FileDurationMs
= 2736;
107 #endif // defined(USE_PROPRIETARY_CODECS)
109 // Return a timeline offset for bear-320x240-live.webm.
110 static base::Time
kLiveTimelineOffset() {
111 // The file contians the following UTC timeline offset:
112 // 2012-11-10 12:34:56.789123456
113 // Since base::Time only has a resolution of microseconds,
114 // construct a base::Time for 2012-11-10 12:34:56.789123.
115 base::Time::Exploded exploded_time
;
116 exploded_time
.year
= 2012;
117 exploded_time
.month
= 11;
118 exploded_time
.day_of_month
= 10;
119 exploded_time
.hour
= 12;
120 exploded_time
.minute
= 34;
121 exploded_time
.second
= 56;
122 exploded_time
.millisecond
= 789;
123 base::Time timeline_offset
= base::Time::FromUTCExploded(exploded_time
);
125 timeline_offset
+= base::TimeDelta::FromMicroseconds(123);
127 return timeline_offset
;
130 // FFmpeg only supports time a resolution of seconds so this
131 // helper function truncates a base::Time to seconds resolution.
132 static base::Time
TruncateToFFmpegTimeResolution(base::Time t
) {
133 base::Time::Exploded exploded_time
;
134 t
.UTCExplode(&exploded_time
);
135 exploded_time
.millisecond
= 0;
137 return base::Time::FromUTCExploded(exploded_time
);
140 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
141 // They do not exercise the Decrypting{Audio|Video}Decoder path.
142 class FakeEncryptedMedia
{
144 // Defines the behavior of the "app" that responds to EME events.
147 virtual ~AppBase() {}
149 virtual void OnSessionMessage(const std::string
& web_session_id
,
150 MediaKeys::MessageType message_type
,
151 const std::vector
<uint8
>& message
,
152 const GURL
& legacy_destination_url
) = 0;
154 virtual void OnSessionClosed(const std::string
& web_session_id
) = 0;
156 virtual void OnSessionKeysChange(const std::string
& web_session_id
,
157 bool has_additional_usable_key
,
158 CdmKeysInfo keys_info
) = 0;
160 // Errors are not expected unless overridden.
161 virtual void OnSessionError(const std::string
& web_session_id
,
162 const std::string
& error_name
,
164 const std::string
& error_message
) {
165 FAIL() << "Unexpected Key Error";
168 virtual void OnEncryptedMediaInitData(const std::string
& init_data_type
,
169 const std::vector
<uint8
>& init_data
,
170 AesDecryptor
* decryptor
) = 0;
173 FakeEncryptedMedia(AppBase
* app
)
174 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage
,
175 base::Unretained(this)),
176 base::Bind(&FakeEncryptedMedia::OnSessionClosed
,
177 base::Unretained(this)),
178 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange
,
179 base::Unretained(this))),
180 cdm_context_(&decryptor_
),
183 CdmContext
* GetCdmContext() { return &cdm_context_
; }
185 // Callbacks for firing session events. Delegate to |app_|.
186 void OnSessionMessage(const std::string
& web_session_id
,
187 MediaKeys::MessageType message_type
,
188 const std::vector
<uint8
>& message
,
189 const GURL
& legacy_destination_url
) {
190 app_
->OnSessionMessage(web_session_id
, message_type
, message
,
191 legacy_destination_url
);
194 void OnSessionClosed(const std::string
& web_session_id
) {
195 app_
->OnSessionClosed(web_session_id
);
198 void OnSessionKeysChange(const std::string
& web_session_id
,
199 bool has_additional_usable_key
,
200 CdmKeysInfo keys_info
) {
201 app_
->OnSessionKeysChange(web_session_id
, has_additional_usable_key
,
205 void OnSessionError(const std::string
& web_session_id
,
206 const std::string
& error_name
,
208 const std::string
& error_message
) {
209 app_
->OnSessionError(
210 web_session_id
, error_name
, system_code
, error_message
);
213 void OnEncryptedMediaInitData(const std::string
& init_data_type
,
214 const std::vector
<uint8
>& init_data
) {
215 app_
->OnEncryptedMediaInitData(init_data_type
, init_data
, &decryptor_
);
219 class TestCdmContext
: public CdmContext
{
221 TestCdmContext(Decryptor
* decryptor
) : decryptor_(decryptor
) {}
223 Decryptor
* GetDecryptor() final
{ return decryptor_
; }
225 #if defined(ENABLE_BROWSER_CDMS)
226 int GetCdmId() const final
{ return kInvalidCdmId
; }
230 Decryptor
* decryptor_
;
233 AesDecryptor decryptor_
;
234 TestCdmContext cdm_context_
;
235 scoped_ptr
<AppBase
> app_
;
238 enum PromiseResult
{ RESOLVED
, REJECTED
};
240 // Provides |kSecretKey| in response to needkey.
241 class KeyProvidingApp
: public FakeEncryptedMedia::AppBase
{
245 void OnResolveWithSession(PromiseResult expected
,
246 const std::string
& web_session_id
) {
247 EXPECT_EQ(expected
, RESOLVED
);
248 EXPECT_GT(web_session_id
.length(), 0ul);
249 current_session_id_
= web_session_id
;
252 void OnResolve(PromiseResult expected
) {
253 EXPECT_EQ(expected
, RESOLVED
);
256 void OnReject(PromiseResult expected
,
257 media::MediaKeys::Exception exception_code
,
259 const std::string
& error_message
) {
260 EXPECT_EQ(expected
, REJECTED
);
263 scoped_ptr
<SimpleCdmPromise
> CreatePromise(PromiseResult expected
) {
264 scoped_ptr
<media::SimpleCdmPromise
> promise(new media::CdmCallbackPromise
<>(
266 &KeyProvidingApp::OnResolve
, base::Unretained(this), expected
),
268 &KeyProvidingApp::OnReject
, base::Unretained(this), expected
)));
269 return promise
.Pass();
272 scoped_ptr
<NewSessionCdmPromise
> CreateSessionPromise(
273 PromiseResult expected
) {
274 scoped_ptr
<media::NewSessionCdmPromise
> promise(
275 new media::CdmCallbackPromise
<std::string
>(
276 base::Bind(&KeyProvidingApp::OnResolveWithSession
,
277 base::Unretained(this),
280 &KeyProvidingApp::OnReject
, base::Unretained(this), expected
)));
281 return promise
.Pass();
284 void OnSessionMessage(const std::string
& web_session_id
,
285 MediaKeys::MessageType message_type
,
286 const std::vector
<uint8
>& message
,
287 const GURL
& legacy_destination_url
) override
{
288 EXPECT_FALSE(web_session_id
.empty());
289 EXPECT_FALSE(message
.empty());
290 EXPECT_EQ(current_session_id_
, web_session_id
);
293 void OnSessionClosed(const std::string
& web_session_id
) override
{
294 EXPECT_EQ(current_session_id_
, web_session_id
);
297 void OnSessionKeysChange(const std::string
& web_session_id
,
298 bool has_additional_usable_key
,
299 CdmKeysInfo keys_info
) override
{
300 EXPECT_EQ(current_session_id_
, web_session_id
);
301 EXPECT_EQ(has_additional_usable_key
, true);
304 void OnEncryptedMediaInitData(const std::string
& init_data_type
,
305 const std::vector
<uint8
>& init_data
,
306 AesDecryptor
* decryptor
) override
{
307 if (current_session_id_
.empty()) {
308 decryptor
->CreateSessionAndGenerateRequest(
309 MediaKeys::TEMPORARY_SESSION
, init_data_type
, kInitData
,
310 arraysize(kInitData
), CreateSessionPromise(RESOLVED
));
311 EXPECT_FALSE(current_session_id_
.empty());
314 // Clear Key really needs the key ID in |init_data|. For WebM, they are the
315 // same, but this is not the case for ISO CENC. Therefore, provide the
317 const uint8
* key_id
= init_data
.empty() ? NULL
: &init_data
[0];
318 size_t key_id_length
= init_data
.size();
319 if (init_data_type
== kCencInitDataType
) {
321 key_id_length
= arraysize(kKeyId
);
324 // Convert key into a JSON structure and then add it.
325 std::string jwk
= GenerateJWKSet(
326 kSecretKey
, arraysize(kSecretKey
), key_id
, key_id_length
);
327 decryptor
->UpdateSession(current_session_id_
,
328 reinterpret_cast<const uint8
*>(jwk
.data()),
330 CreatePromise(RESOLVED
));
333 std::string current_session_id_
;
336 class RotatingKeyProvidingApp
: public KeyProvidingApp
{
338 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {}
339 ~RotatingKeyProvidingApp() override
{
340 // Expect that OnEncryptedMediaInitData is fired multiple times with
341 // different |init_data|.
342 EXPECT_GT(num_distint_need_key_calls_
, 1u);
345 void OnEncryptedMediaInitData(const std::string
& init_data_type
,
346 const std::vector
<uint8
>& init_data
,
347 AesDecryptor
* decryptor
) override
{
348 // Skip the request if the |init_data| has been seen.
349 if (init_data
== prev_init_data_
)
351 prev_init_data_
= init_data
;
352 ++num_distint_need_key_calls_
;
354 decryptor
->CreateSessionAndGenerateRequest(
355 MediaKeys::TEMPORARY_SESSION
, init_data_type
,
356 vector_as_array(&init_data
), init_data
.size(),
357 CreateSessionPromise(RESOLVED
));
359 std::vector
<uint8
> key_id
;
360 std::vector
<uint8
> key
;
361 EXPECT_TRUE(GetKeyAndKeyId(init_data
, &key
, &key_id
));
363 // Convert key into a JSON structure and then add it.
364 std::string jwk
= GenerateJWKSet(vector_as_array(&key
),
366 vector_as_array(&key_id
),
368 decryptor
->UpdateSession(current_session_id_
,
369 reinterpret_cast<const uint8
*>(jwk
.data()),
371 CreatePromise(RESOLVED
));
375 bool GetKeyAndKeyId(std::vector
<uint8
> init_data
,
376 std::vector
<uint8
>* key
,
377 std::vector
<uint8
>* key_id
) {
378 // For WebM, init_data is key_id; for ISO CENC, init_data should contain
379 // the key_id. We assume key_id is in the end of init_data here (that is
380 // only a reasonable assumption for WebM and clear key ISO CENC).
381 DCHECK_GE(init_data
.size(), arraysize(kKeyId
));
382 std::vector
<uint8
> key_id_from_init_data(
383 init_data
.end() - arraysize(kKeyId
), init_data
.end());
385 key
->assign(kSecretKey
, kSecretKey
+ arraysize(kSecretKey
));
386 key_id
->assign(kKeyId
, kKeyId
+ arraysize(kKeyId
));
388 // The Key and KeyId for this testing key provider are created by left
389 // rotating kSecretKey and kKeyId. Note that this implementation is only
390 // intended for testing purpose. The actual key rotation algorithm can be
391 // much more complicated.
392 // Find out the rotating position from |key_id_from_init_data| and apply on
394 for (size_t pos
= 0; pos
< arraysize(kKeyId
); ++pos
) {
395 std::rotate(key_id
->begin(), key_id
->begin() + pos
, key_id
->end());
396 if (*key_id
== key_id_from_init_data
) {
397 std::rotate(key
->begin(), key
->begin() + pos
, key
->end());
404 std::vector
<uint8
> prev_init_data_
;
405 uint32 num_distint_need_key_calls_
;
408 // Ignores needkey and does not perform a license request
409 class NoResponseApp
: public FakeEncryptedMedia::AppBase
{
411 void OnSessionMessage(const std::string
& web_session_id
,
412 MediaKeys::MessageType message_type
,
413 const std::vector
<uint8
>& message
,
414 const GURL
& legacy_destination_url
) override
{
415 EXPECT_FALSE(web_session_id
.empty());
416 EXPECT_FALSE(message
.empty());
417 FAIL() << "Unexpected Message";
420 void OnSessionClosed(const std::string
& web_session_id
) override
{
421 EXPECT_FALSE(web_session_id
.empty());
422 FAIL() << "Unexpected Closed";
425 void OnSessionKeysChange(const std::string
& web_session_id
,
426 bool has_additional_usable_key
,
427 CdmKeysInfo keys_info
) override
{
428 EXPECT_FALSE(web_session_id
.empty());
429 EXPECT_EQ(has_additional_usable_key
, true);
432 void OnEncryptedMediaInitData(const std::string
& init_data_type
,
433 const std::vector
<uint8
>& init_data
,
434 AesDecryptor
* decryptor
) override
{}
437 // Helper class that emulates calls made on the ChunkDemuxer by the
439 class MockMediaSource
{
441 MockMediaSource(const std::string
& filename
,
442 const std::string
& mimetype
,
443 int initial_append_size
)
444 : current_position_(0),
445 initial_append_size_(initial_append_size
),
447 chunk_demuxer_(new ChunkDemuxer(
448 base::Bind(&MockMediaSource::DemuxerOpened
, base::Unretained(this)),
449 base::Bind(&MockMediaSource::OnEncryptedMediaInitData
,
450 base::Unretained(this)),
452 scoped_refptr
<MediaLog
>(new MediaLog()),
454 owned_chunk_demuxer_(chunk_demuxer_
) {
455 file_data_
= ReadTestDataFile(filename
);
457 if (initial_append_size_
== kAppendWholeFile
)
458 initial_append_size_
= file_data_
->data_size();
460 DCHECK_GT(initial_append_size_
, 0);
461 DCHECK_LE(initial_append_size_
, file_data_
->data_size());
464 virtual ~MockMediaSource() {}
466 scoped_ptr
<Demuxer
> GetDemuxer() { return owned_chunk_demuxer_
.Pass(); }
468 void set_encrypted_media_init_data_cb(
469 const Demuxer::EncryptedMediaInitDataCB
& encrypted_media_init_data_cb
) {
470 encrypted_media_init_data_cb_
= encrypted_media_init_data_cb
;
473 void Seek(base::TimeDelta seek_time
, int new_position
, int seek_append_size
) {
474 chunk_demuxer_
->StartWaitingForSeek(seek_time
);
476 chunk_demuxer_
->Abort(
478 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_
);
480 DCHECK_GE(new_position
, 0);
481 DCHECK_LT(new_position
, file_data_
->data_size());
482 current_position_
= new_position
;
484 AppendData(seek_append_size
);
487 void AppendData(int size
) {
488 DCHECK(chunk_demuxer_
);
489 DCHECK_LT(current_position_
, file_data_
->data_size());
490 DCHECK_LE(current_position_
+ size
, file_data_
->data_size());
492 chunk_demuxer_
->AppendData(
493 kSourceId
, file_data_
->data() + current_position_
, size
,
494 base::TimeDelta(), kInfiniteDuration(), &last_timestamp_offset_
,
495 base::Bind(&MockMediaSource::InitSegmentReceived
,
496 base::Unretained(this)));
497 current_position_
+= size
;
500 void AppendAtTime(base::TimeDelta timestamp_offset
,
503 CHECK(!chunk_demuxer_
->IsParsingMediaSegment(kSourceId
));
504 chunk_demuxer_
->AppendData(kSourceId
, pData
, size
,
505 base::TimeDelta(), kInfiniteDuration(),
507 base::Bind(&MockMediaSource::InitSegmentReceived
,
508 base::Unretained(this)));
509 last_timestamp_offset_
= timestamp_offset
;
512 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset
,
513 base::TimeDelta append_window_start
,
514 base::TimeDelta append_window_end
,
517 CHECK(!chunk_demuxer_
->IsParsingMediaSegment(kSourceId
));
518 chunk_demuxer_
->AppendData(kSourceId
,
524 base::Bind(&MockMediaSource::InitSegmentReceived
,
525 base::Unretained(this)));
526 last_timestamp_offset_
= timestamp_offset
;
530 chunk_demuxer_
->MarkEndOfStream(PIPELINE_OK
);
536 chunk_demuxer_
->Shutdown();
537 chunk_demuxer_
= NULL
;
540 void DemuxerOpened() {
541 base::MessageLoop::current()->PostTask(
542 FROM_HERE
, base::Bind(&MockMediaSource::DemuxerOpenedTask
,
543 base::Unretained(this)));
546 void DemuxerOpenedTask() {
547 // This code assumes that |mimetype_| is one of the following forms.
549 // 2. video/webm;codec="vorbis,vp8".
550 size_t semicolon
= mimetype_
.find(";");
551 std::string type
= mimetype_
;
552 std::vector
<std::string
> codecs
;
553 if (semicolon
!= std::string::npos
) {
554 type
= mimetype_
.substr(0, semicolon
);
555 size_t codecs_param_start
= mimetype_
.find("codecs=\"", semicolon
);
557 CHECK_NE(codecs_param_start
, std::string::npos
);
559 codecs_param_start
+= 8; // Skip over the codecs=".
561 size_t codecs_param_end
= mimetype_
.find("\"", codecs_param_start
);
563 CHECK_NE(codecs_param_end
, std::string::npos
);
565 std::string codecs_param
=
566 mimetype_
.substr(codecs_param_start
,
567 codecs_param_end
- codecs_param_start
);
568 Tokenize(codecs_param
, ",", &codecs
);
571 CHECK_EQ(chunk_demuxer_
->AddId(kSourceId
, type
, codecs
), ChunkDemuxer::kOk
);
573 AppendData(initial_append_size_
);
576 void OnEncryptedMediaInitData(const std::string
& init_data_type
,
577 const std::vector
<uint8
>& init_data
) {
578 DCHECK(!init_data
.empty());
579 CHECK(!encrypted_media_init_data_cb_
.is_null());
580 encrypted_media_init_data_cb_
.Run(init_data_type
, init_data
);
583 base::TimeDelta
last_timestamp_offset() const {
584 return last_timestamp_offset_
;
587 MOCK_METHOD0(InitSegmentReceived
, void(void));
590 scoped_refptr
<DecoderBuffer
> file_data_
;
591 int current_position_
;
592 int initial_append_size_
;
593 std::string mimetype_
;
594 ChunkDemuxer
* chunk_demuxer_
;
595 scoped_ptr
<Demuxer
> owned_chunk_demuxer_
;
596 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
597 base::TimeDelta last_timestamp_offset_
;
600 #if defined(MOJO_RENDERER)
601 class PipelineIntegrationTestHost
: public mojo::test::ApplicationTestBase
,
602 public PipelineIntegrationTestBase
{
604 bool ShouldCreateDefaultRunLoop() override
{ return false; }
606 void SetUp() override
{
607 ApplicationTestBase::SetUp();
609 // TODO(dalecurtis): For some reason this isn't done...
610 if (!base::CommandLine::InitializedForCurrentProcess()) {
611 base::CommandLine::Init(0, NULL
);
612 InitializeMediaLibraryForTesting();
617 scoped_ptr
<Renderer
> CreateRenderer() override
{
618 mojo::ServiceProvider
* service_provider
=
620 ->ConnectToApplication("mojo://media")
621 ->GetServiceProvider();
623 mojo::MediaRendererPtr mojo_media_renderer
;
624 mojo::ConnectToService(service_provider
, &mojo_media_renderer
);
625 return make_scoped_ptr(new MojoRendererImpl(message_loop_
.task_runner(),
626 mojo_media_renderer
.Pass()));
630 class PipelineIntegrationTestHost
: public testing::Test
,
631 public PipelineIntegrationTestBase
{};
634 class PipelineIntegrationTest
: public PipelineIntegrationTestHost
{
636 void StartPipelineWithMediaSource(MockMediaSource
* source
) {
637 EXPECT_CALL(*source
, InitSegmentReceived()).Times(AtLeast(1));
638 EXPECT_CALL(*this, OnMetadata(_
))
640 .WillRepeatedly(SaveArg
<0>(&metadata_
));
641 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH
))
643 demuxer_
= source
->GetDemuxer().Pass();
645 demuxer_
.get(), CreateRenderer(),
646 base::Bind(&PipelineIntegrationTest::OnEnded
, base::Unretained(this)),
647 base::Bind(&PipelineIntegrationTest::OnError
, base::Unretained(this)),
648 base::Bind(&PipelineIntegrationTest::OnStatusCallback
,
649 base::Unretained(this)),
650 base::Bind(&PipelineIntegrationTest::OnMetadata
,
651 base::Unretained(this)),
652 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged
,
653 base::Unretained(this)),
654 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint
,
655 base::Unretained(this)),
656 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack
,
657 base::Unretained(this)));
659 EXPECT_EQ(PIPELINE_OK
, pipeline_status_
);
662 void StartHashedPipelineWithMediaSource(MockMediaSource
* source
) {
663 hashing_enabled_
= true;
664 StartPipelineWithMediaSource(source
);
667 void StartPipelineWithEncryptedMedia(
668 MockMediaSource
* source
,
669 FakeEncryptedMedia
* encrypted_media
) {
670 EXPECT_CALL(*source
, InitSegmentReceived()).Times(AtLeast(1));
671 EXPECT_CALL(*this, OnMetadata(_
))
673 .WillRepeatedly(SaveArg
<0>(&metadata_
));
674 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH
))
676 EXPECT_CALL(*this, DecryptorAttached(true));
678 demuxer_
= source
->GetDemuxer().Pass();
680 pipeline_
->SetCdm(encrypted_media
->GetCdmContext(),
681 base::Bind(&PipelineIntegrationTest::DecryptorAttached
,
682 base::Unretained(this)));
685 demuxer_
.get(), CreateRenderer(),
686 base::Bind(&PipelineIntegrationTest::OnEnded
, base::Unretained(this)),
687 base::Bind(&PipelineIntegrationTest::OnError
, base::Unretained(this)),
688 base::Bind(&PipelineIntegrationTest::OnStatusCallback
,
689 base::Unretained(this)),
690 base::Bind(&PipelineIntegrationTest::OnMetadata
,
691 base::Unretained(this)),
692 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged
,
693 base::Unretained(this)),
694 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint
,
695 base::Unretained(this)),
696 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack
,
697 base::Unretained(this)));
699 source
->set_encrypted_media_init_data_cb(
700 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData
,
701 base::Unretained(encrypted_media
)));
704 EXPECT_EQ(PIPELINE_OK
, pipeline_status_
);
707 // Verifies that seeking works properly for ChunkDemuxer when the
708 // seek happens while there is a pending read on the ChunkDemuxer
709 // and no data is available.
710 bool TestSeekDuringRead(const std::string
& filename
,
711 const std::string
& mimetype
,
712 int initial_append_size
,
713 base::TimeDelta start_seek_time
,
714 base::TimeDelta seek_time
,
715 int seek_file_position
,
716 int seek_append_size
) {
717 MockMediaSource
source(filename
, mimetype
, initial_append_size
);
718 StartPipelineWithMediaSource(&source
);
720 if (pipeline_status_
!= PIPELINE_OK
)
724 if (!WaitUntilCurrentTimeIsAfter(start_seek_time
))
727 source
.Seek(seek_time
, seek_file_position
, seek_append_size
);
728 if (!Seek(seek_time
))
731 source
.EndOfStream();
739 TEST_F(PipelineIntegrationTest
, BasicPlayback
) {
740 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
744 ASSERT_TRUE(WaitUntilOnEnded());
747 TEST_F(PipelineIntegrationTest
, BasicPlaybackOpusOgg
) {
748 ASSERT_EQ(PIPELINE_OK
, Start("bear-opus.ogg"));
752 ASSERT_TRUE(WaitUntilOnEnded());
755 TEST_F(PipelineIntegrationTest
, BasicPlaybackHashed
) {
756 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm", kHashed
));
760 ASSERT_TRUE(WaitUntilOnEnded());
762 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
763 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
764 EXPECT_TRUE(demuxer_
->GetTimelineOffset().is_null());
767 TEST_F(PipelineIntegrationTest
, BasicPlaybackLive
) {
768 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-live.webm", kHashed
));
772 ASSERT_TRUE(WaitUntilOnEnded());
774 EXPECT_HASH_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash());
775 EXPECT_HASH_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash());
777 // TODO: Fix FFmpeg code to return higher resolution time values so
778 // we don't have to truncate our expectations here.
779 EXPECT_EQ(TruncateToFFmpegTimeResolution(kLiveTimelineOffset()),
780 demuxer_
->GetTimelineOffset());
783 TEST_F(PipelineIntegrationTest
, F32PlaybackHashed
) {
784 ASSERT_EQ(PIPELINE_OK
, Start("sfx_f32le.wav", kHashed
));
786 ASSERT_TRUE(WaitUntilOnEnded());
787 EXPECT_HASH_EQ(std::string(kNullVideoHash
), GetVideoHash());
788 EXPECT_HASH_EQ("3.03,2.86,2.99,3.31,3.57,4.06,", GetAudioHash());
791 #if !defined(DISABLE_EME_TESTS)
792 TEST_F(PipelineIntegrationTest
, BasicPlaybackEncrypted
) {
793 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
794 set_encrypted_media_init_data_cb(
795 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData
,
796 base::Unretained(&encrypted_media
)));
798 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-av_enc-av.webm",
799 encrypted_media
.GetCdmContext()));
803 ASSERT_TRUE(WaitUntilOnEnded());
806 #endif // !defined(DISABLE_EME_TESTS)
808 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource
) {
809 MockMediaSource
source("bear-320x240.webm", kWebM
, 219229);
810 StartPipelineWithMediaSource(&source
);
811 source
.EndOfStream();
813 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
814 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
815 EXPECT_EQ(k320WebMFileDurationMs
,
816 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
820 ASSERT_TRUE(WaitUntilOnEnded());
822 EXPECT_TRUE(demuxer_
->GetTimelineOffset().is_null());
827 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Live
) {
828 MockMediaSource
source("bear-320x240-live.webm", kWebM
, 219221);
829 StartPipelineWithMediaSource(&source
);
830 source
.EndOfStream();
832 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
833 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
834 EXPECT_EQ(k320WebMFileDurationMs
,
835 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
839 ASSERT_TRUE(WaitUntilOnEnded());
841 EXPECT_EQ(kLiveTimelineOffset(),
842 demuxer_
->GetTimelineOffset());
847 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VP9_WebM
) {
848 MockMediaSource
source("bear-vp9.webm", kWebMVP9
, 67504);
849 StartPipelineWithMediaSource(&source
);
850 source
.EndOfStream();
852 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
853 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
854 EXPECT_EQ(kVP9WebMFileDurationMs
,
855 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
859 ASSERT_TRUE(WaitUntilOnEnded());
864 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VP8A_WebM
) {
865 MockMediaSource
source("bear-vp8a.webm", kVideoOnlyWebM
, kAppendWholeFile
);
866 StartPipelineWithMediaSource(&source
);
867 source
.EndOfStream();
869 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
870 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
871 EXPECT_EQ(kVP8AWebMFileDurationMs
,
872 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
876 ASSERT_TRUE(WaitUntilOnEnded());
881 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Opus_WebM
) {
882 MockMediaSource
source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM
,
884 StartPipelineWithMediaSource(&source
);
885 source
.EndOfStream();
887 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
888 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
889 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs
,
890 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
893 ASSERT_TRUE(WaitUntilOnEnded());
898 // Flaky. http://crbug.com/304776
899 TEST_F(PipelineIntegrationTest
, DISABLED_MediaSource_Opus_Seeking_WebM
) {
900 MockMediaSource
source("bear-opus-end-trimming.webm", kOpusAudioOnlyWebM
,
902 StartHashedPipelineWithMediaSource(&source
);
904 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
905 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
906 EXPECT_EQ(kOpusEndTrimmingWebMFileDurationMs
,
907 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
909 base::TimeDelta start_seek_time
= base::TimeDelta::FromMilliseconds(1000);
910 base::TimeDelta seek_time
= base::TimeDelta::FromMilliseconds(2000);
913 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
914 source
.Seek(seek_time
, 0x1D5, 34017);
915 source
.EndOfStream();
916 ASSERT_TRUE(Seek(seek_time
));
918 ASSERT_TRUE(WaitUntilOnEnded());
920 EXPECT_HASH_EQ("0.76,0.20,-0.82,-0.58,-1.29,-0.29,", GetAudioHash());
926 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_WebM
) {
927 MockMediaSource
source("bear-320x240-16x9-aspect.webm", kWebM
,
929 StartPipelineWithMediaSource(&source
);
931 scoped_refptr
<DecoderBuffer
> second_file
=
932 ReadTestDataFile("bear-640x360.webm");
934 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
935 second_file
->data(), second_file
->data_size());
937 source
.EndOfStream();
939 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
940 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
941 EXPECT_EQ(kAppendTimeMs
+ k640WebMFileDurationMs
,
942 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
946 EXPECT_TRUE(WaitUntilOnEnded());
951 #if !defined(DISABLE_EME_TESTS)
952 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_Encrypted_WebM
) {
953 MockMediaSource
source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM
,
955 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
956 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
958 scoped_refptr
<DecoderBuffer
> second_file
=
959 ReadTestDataFile("bear-640x360-av_enc-av.webm");
961 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
962 second_file
->data(), second_file
->data_size());
964 source
.EndOfStream();
966 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
967 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
968 EXPECT_EQ(kAppendTimeMs
+ k640WebMFileDurationMs
,
969 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
973 EXPECT_TRUE(WaitUntilOnEnded());
978 // Config changes from encrypted to clear are not currently supported.
979 TEST_F(PipelineIntegrationTest
,
980 MediaSource_ConfigChange_ClearThenEncrypted_WebM
) {
981 MockMediaSource
source("bear-320x240-16x9-aspect.webm", kWebM
,
983 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
984 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
986 scoped_refptr
<DecoderBuffer
> second_file
=
987 ReadTestDataFile("bear-640x360-av_enc-av.webm");
989 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
990 second_file
->data(), second_file
->data_size());
992 source
.EndOfStream();
995 EXPECT_EQ(PIPELINE_ERROR_DECODE
, pipeline_status_
);
997 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
998 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
999 // The second video was not added, so its time has not been added.
1000 EXPECT_EQ(k320WebMFileDurationMs
,
1001 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1005 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1009 // Config changes from clear to encrypted are not currently supported.
1010 TEST_F(PipelineIntegrationTest
,
1011 MediaSource_ConfigChange_EncryptedThenClear_WebM
) {
1012 MockMediaSource
source("bear-320x240-16x9-aspect-av_enc-av.webm", kWebM
,
1014 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1015 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1017 scoped_refptr
<DecoderBuffer
> second_file
=
1018 ReadTestDataFile("bear-640x360.webm");
1020 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1021 second_file
->data(), second_file
->data_size());
1023 source
.EndOfStream();
1025 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1026 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1027 // The second video was not added, so its time has not been added.
1028 EXPECT_EQ(k320WebMFileDurationMs
,
1029 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1033 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1036 #endif // !defined(DISABLE_EME_TESTS)
1038 #if defined(USE_PROPRIETARY_CODECS)
1039 TEST_F(PipelineIntegrationTest
, MediaSource_ADTS
) {
1040 MockMediaSource
source("sfx.adts", kADTS
, kAppendWholeFile
);
1041 StartPipelineWithMediaSource(&source
);
1042 source
.EndOfStream();
1044 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1045 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1046 EXPECT_EQ(325, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1050 EXPECT_TRUE(WaitUntilOnEnded());
1053 TEST_F(PipelineIntegrationTest
, MediaSource_ADTS_TimestampOffset
) {
1054 MockMediaSource
source("sfx.adts", kADTS
, kAppendWholeFile
);
1055 StartHashedPipelineWithMediaSource(&source
);
1056 EXPECT_EQ(325, source
.last_timestamp_offset().InMilliseconds());
1058 // Trim off multiple frames off the beginning of the segment which will cause
1059 // the first decoded frame to be incorrect if preroll isn't implemented.
1060 const base::TimeDelta adts_preroll_duration
=
1061 base::TimeDelta::FromSecondsD(2.5 * 1024 / 44100);
1062 const base::TimeDelta append_time
=
1063 source
.last_timestamp_offset() - adts_preroll_duration
;
1065 scoped_refptr
<DecoderBuffer
> second_file
= ReadTestDataFile("sfx.adts");
1066 source
.AppendAtTimeWithWindow(append_time
,
1067 append_time
+ adts_preroll_duration
,
1068 kInfiniteDuration(),
1069 second_file
->data(),
1070 second_file
->data_size());
1071 source
.EndOfStream();
1073 EXPECT_EQ(592, source
.last_timestamp_offset().InMilliseconds());
1074 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1075 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1076 EXPECT_EQ(592, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1080 EXPECT_TRUE(WaitUntilOnEnded());
1082 // Verify preroll is stripped.
1083 EXPECT_HASH_EQ("-0.06,0.97,-0.90,-0.70,-0.53,-0.34,", GetAudioHash());
1086 TEST_F(PipelineIntegrationTest
, BasicPlaybackHashed_MP3
) {
1087 ASSERT_EQ(PIPELINE_OK
, Start("sfx.mp3", kHashed
));
1091 ASSERT_TRUE(WaitUntilOnEnded());
1093 // Verify codec delay and preroll are stripped.
1094 EXPECT_HASH_EQ("1.30,2.72,4.56,5.08,3.74,2.03,", GetAudioHash());
1097 TEST_F(PipelineIntegrationTest
, MediaSource_MP3
) {
1098 MockMediaSource
source("sfx.mp3", kMP3
, kAppendWholeFile
);
1099 StartHashedPipelineWithMediaSource(&source
);
1100 source
.EndOfStream();
1102 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1103 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1104 EXPECT_EQ(313, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1108 EXPECT_TRUE(WaitUntilOnEnded());
1110 // Verify that codec delay was stripped.
1111 EXPECT_HASH_EQ("1.01,2.71,4.18,4.32,3.04,1.12,", GetAudioHash());
1114 TEST_F(PipelineIntegrationTest
, MediaSource_MP3_TimestampOffset
) {
1115 MockMediaSource
source("sfx.mp3", kMP3
, kAppendWholeFile
);
1116 StartPipelineWithMediaSource(&source
);
1117 EXPECT_EQ(313, source
.last_timestamp_offset().InMilliseconds());
1119 // There are 576 silent frames at the start of this mp3. The second append
1120 // should trim them off.
1121 const base::TimeDelta mp3_preroll_duration
=
1122 base::TimeDelta::FromSecondsD(576.0 / 44100);
1123 const base::TimeDelta append_time
=
1124 source
.last_timestamp_offset() - mp3_preroll_duration
;
1126 scoped_refptr
<DecoderBuffer
> second_file
= ReadTestDataFile("sfx.mp3");
1127 source
.AppendAtTimeWithWindow(append_time
,
1128 append_time
+ mp3_preroll_duration
,
1129 kInfiniteDuration(),
1130 second_file
->data(),
1131 second_file
->data_size());
1132 source
.EndOfStream();
1134 EXPECT_EQ(613, source
.last_timestamp_offset().InMilliseconds());
1135 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1136 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1137 EXPECT_EQ(613, pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1141 EXPECT_TRUE(WaitUntilOnEnded());
1144 TEST_F(PipelineIntegrationTest
, MediaSource_MP3_Icecast
) {
1145 MockMediaSource
source("icy_sfx.mp3", kMP3
, kAppendWholeFile
);
1146 StartPipelineWithMediaSource(&source
);
1147 source
.EndOfStream();
1151 EXPECT_TRUE(WaitUntilOnEnded());
1154 TEST_F(PipelineIntegrationTest
, MediaSource_ConfigChange_MP4
) {
1155 MockMediaSource
source("bear-640x360-av_frag.mp4", kMP4
, kAppendWholeFile
);
1156 StartPipelineWithMediaSource(&source
);
1158 scoped_refptr
<DecoderBuffer
> second_file
=
1159 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1161 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1162 second_file
->data(), second_file
->data_size());
1164 source
.EndOfStream();
1166 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1167 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1168 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1169 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1173 EXPECT_TRUE(WaitUntilOnEnded());
1178 #if !defined(DISABLE_EME_TESTS)
1179 TEST_F(PipelineIntegrationTest
,
1180 MediaSource_ConfigChange_Encrypted_MP4_CENC_VideoOnly
) {
1181 MockMediaSource
source("bear-640x360-v_frag-cenc.mp4", kMP4Video
,
1183 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1184 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1186 scoped_refptr
<DecoderBuffer
> second_file
=
1187 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1189 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1190 second_file
->data(), second_file
->data_size());
1192 source
.EndOfStream();
1194 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1195 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1196 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1197 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1201 EXPECT_TRUE(WaitUntilOnEnded());
1206 TEST_F(PipelineIntegrationTest
,
1207 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly
) {
1208 MockMediaSource
source("bear-640x360-v_frag-cenc-key_rotation.mp4", kMP4Video
,
1210 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1211 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1213 scoped_refptr
<DecoderBuffer
> second_file
=
1214 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1216 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1217 second_file
->data(), second_file
->data_size());
1219 source
.EndOfStream();
1221 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1222 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1223 EXPECT_EQ(kAppendTimeMs
+ k1280IsoFileDurationMs
,
1224 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1228 EXPECT_TRUE(WaitUntilOnEnded());
1233 // Config changes from clear to encrypted are not currently supported.
1234 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
1235 TEST_F(PipelineIntegrationTest
,
1236 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC
) {
1237 MockMediaSource
source("bear-640x360-av_frag.mp4", kMP4Video
,
1239 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1240 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1242 scoped_refptr
<DecoderBuffer
> second_file
=
1243 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4");
1245 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1246 second_file
->data(), second_file
->data_size());
1248 source
.EndOfStream();
1250 message_loop_
.Run();
1251 EXPECT_EQ(PIPELINE_ERROR_DECODE
, pipeline_status_
);
1253 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1254 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1255 // The second video was not added, so its time has not been added.
1256 EXPECT_EQ(k640IsoFileDurationMs
,
1257 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1261 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1265 // Config changes from encrypted to clear are not currently supported.
1266 TEST_F(PipelineIntegrationTest
,
1267 MediaSource_ConfigChange_EncryptedThenClear_MP4_CENC
) {
1268 MockMediaSource
source("bear-640x360-v_frag-cenc.mp4", kMP4Video
,
1270 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1271 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1273 scoped_refptr
<DecoderBuffer
> second_file
=
1274 ReadTestDataFile("bear-1280x720-av_frag.mp4");
1276 source
.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec
),
1277 second_file
->data(), second_file
->data_size());
1279 source
.EndOfStream();
1281 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1282 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1283 // The second video was not added, so its time has not been added.
1284 EXPECT_EQ(k640IsoCencFileDurationMs
,
1285 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1289 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1292 #endif // !defined(DISABLE_EME_TESTS)
1294 // Verify files which change configuration midstream fail gracefully.
1295 TEST_F(PipelineIntegrationTest
, MidStreamConfigChangesFail
) {
1296 ASSERT_EQ(PIPELINE_OK
, Start("midstream_config_change.mp3"));
1298 ASSERT_EQ(WaitUntilEndedOrError(), PIPELINE_ERROR_DECODE
);
1303 TEST_F(PipelineIntegrationTest
, BasicPlayback_16x9AspectRatio
) {
1304 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-16x9-aspect.webm"));
1306 ASSERT_TRUE(WaitUntilOnEnded());
1309 #if !defined(DISABLE_EME_TESTS)
1310 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_WebM
) {
1311 MockMediaSource
source("bear-320x240-av_enc-av.webm", kWebM
, 219816);
1312 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1313 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1315 source
.EndOfStream();
1316 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1320 ASSERT_TRUE(WaitUntilOnEnded());
1325 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_ClearStart_WebM
) {
1326 MockMediaSource
source("bear-320x240-av_enc-av_clear-1s.webm", kWebM
,
1328 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1329 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1331 source
.EndOfStream();
1332 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1336 ASSERT_TRUE(WaitUntilOnEnded());
1341 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_NoEncryptedFrames_WebM
) {
1342 MockMediaSource
source("bear-320x240-av_enc-av_clear-all.webm", kWebM
,
1344 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1345 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1347 source
.EndOfStream();
1348 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1352 ASSERT_TRUE(WaitUntilOnEnded());
1356 #endif // !defined(DISABLE_EME_TESTS)
1358 #if defined(USE_PROPRIETARY_CODECS)
1359 #if !defined(DISABLE_EME_TESTS)
1360 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_VideoOnly
) {
1361 MockMediaSource
source("bear-1280x720-v_frag-cenc.mp4", kMP4Video
,
1363 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1364 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1366 source
.EndOfStream();
1367 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1371 ASSERT_TRUE(WaitUntilOnEnded());
1376 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_AudioOnly
) {
1377 MockMediaSource
source("bear-1280x720-a_frag-cenc.mp4", kMP4Audio
,
1379 FakeEncryptedMedia
encrypted_media(new KeyProvidingApp());
1380 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1382 source
.EndOfStream();
1383 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1387 ASSERT_TRUE(WaitUntilOnEnded());
1392 TEST_F(PipelineIntegrationTest
,
1393 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_VideoOnly
) {
1394 MockMediaSource
source("bear-1280x720-v_frag-cenc_clear-all.mp4", kMP4Video
,
1396 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1397 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1399 source
.EndOfStream();
1400 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1404 ASSERT_TRUE(WaitUntilOnEnded());
1409 TEST_F(PipelineIntegrationTest
,
1410 EncryptedPlayback_NoEncryptedFrames_MP4_CENC_AudioOnly
) {
1411 MockMediaSource
source("bear-1280x720-a_frag-cenc_clear-all.mp4", kMP4Audio
,
1413 FakeEncryptedMedia
encrypted_media(new NoResponseApp());
1414 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1416 source
.EndOfStream();
1417 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1421 ASSERT_TRUE(WaitUntilOnEnded());
1426 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_KeyRotation_Video
) {
1427 MockMediaSource
source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1428 kMP4Video
, kAppendWholeFile
);
1429 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1430 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1432 source
.EndOfStream();
1433 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1437 ASSERT_TRUE(WaitUntilOnEnded());
1442 TEST_F(PipelineIntegrationTest
, EncryptedPlayback_MP4_CENC_KeyRotation_Audio
) {
1443 MockMediaSource
source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1444 kMP4Audio
, kAppendWholeFile
);
1445 FakeEncryptedMedia
encrypted_media(new RotatingKeyProvidingApp());
1446 StartPipelineWithEncryptedMedia(&source
, &encrypted_media
);
1448 source
.EndOfStream();
1449 ASSERT_EQ(PIPELINE_OK
, pipeline_status_
);
1453 ASSERT_TRUE(WaitUntilOnEnded());
1457 #endif // !defined(DISABLE_EME_TESTS)
1459 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_VideoOnly_MP4_AVC3
) {
1460 MockMediaSource
source("bear-1280x720-v_frag-avc3.mp4", kMP4VideoAVC3
,
1462 StartPipelineWithMediaSource(&source
);
1463 source
.EndOfStream();
1465 EXPECT_EQ(1u, pipeline_
->GetBufferedTimeRanges().size());
1466 EXPECT_EQ(0, pipeline_
->GetBufferedTimeRanges().start(0).InMilliseconds());
1467 EXPECT_EQ(k1280IsoAVC3FileDurationMs
,
1468 pipeline_
->GetBufferedTimeRanges().end(0).InMilliseconds());
1472 ASSERT_TRUE(WaitUntilOnEnded());
1476 #endif // defined(USE_PROPRIETARY_CODECS)
1478 TEST_F(PipelineIntegrationTest
, SeekWhilePaused
) {
1479 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
1481 base::TimeDelta
duration(pipeline_
->GetMediaDuration());
1482 base::TimeDelta
start_seek_time(duration
/ 4);
1483 base::TimeDelta
seek_time(duration
* 3 / 4);
1486 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
1488 ASSERT_TRUE(Seek(seek_time
));
1489 EXPECT_EQ(seek_time
, pipeline_
->GetMediaTime());
1491 ASSERT_TRUE(WaitUntilOnEnded());
1493 // Make sure seeking after reaching the end works as expected.
1495 ASSERT_TRUE(Seek(seek_time
));
1496 EXPECT_EQ(seek_time
, pipeline_
->GetMediaTime());
1498 ASSERT_TRUE(WaitUntilOnEnded());
1501 TEST_F(PipelineIntegrationTest
, SeekWhilePlaying
) {
1502 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240.webm"));
1504 base::TimeDelta
duration(pipeline_
->GetMediaDuration());
1505 base::TimeDelta
start_seek_time(duration
/ 4);
1506 base::TimeDelta
seek_time(duration
* 3 / 4);
1509 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time
));
1510 ASSERT_TRUE(Seek(seek_time
));
1511 EXPECT_GE(pipeline_
->GetMediaTime(), seek_time
);
1512 ASSERT_TRUE(WaitUntilOnEnded());
1514 // Make sure seeking after reaching the end works as expected.
1515 ASSERT_TRUE(Seek(seek_time
));
1516 EXPECT_GE(pipeline_
->GetMediaTime(), seek_time
);
1517 ASSERT_TRUE(WaitUntilOnEnded());
1520 #if defined(USE_PROPRIETARY_CODECS)
1521 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_0
) {
1522 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_0.mp4"));
1523 ASSERT_EQ(VIDEO_ROTATION_0
, metadata_
.video_rotation
);
1526 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_90
) {
1527 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_90.mp4"));
1528 ASSERT_EQ(VIDEO_ROTATION_90
, metadata_
.video_rotation
);
1531 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_180
) {
1532 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_180.mp4"));
1533 ASSERT_EQ(VIDEO_ROTATION_180
, metadata_
.video_rotation
);
1536 TEST_F(PipelineIntegrationTest
, Rotated_Metadata_270
) {
1537 ASSERT_EQ(PIPELINE_OK
, Start("bear_rotate_270.mp4"));
1538 ASSERT_EQ(VIDEO_ROTATION_270
, metadata_
.video_rotation
);
1542 // Verify audio decoder & renderer can handle aborted demuxer reads.
1543 TEST_F(PipelineIntegrationTest
, ChunkDemuxerAbortRead_AudioOnly
) {
1544 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM
,
1546 base::TimeDelta::FromMilliseconds(464),
1547 base::TimeDelta::FromMilliseconds(617),
1551 // Verify video decoder & renderer can handle aborted demuxer reads.
1552 TEST_F(PipelineIntegrationTest
, ChunkDemuxerAbortRead_VideoOnly
) {
1553 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM
,
1555 base::TimeDelta::FromMilliseconds(167),
1556 base::TimeDelta::FromMilliseconds(1668),
1560 // Verify that Opus audio in WebM containers can be played back.
1561 TEST_F(PipelineIntegrationTest
, BasicPlayback_AudioOnly_Opus_WebM
) {
1562 ASSERT_EQ(PIPELINE_OK
, Start("bear-opus-end-trimming.webm"));
1564 ASSERT_TRUE(WaitUntilOnEnded());
1567 // Verify that VP9 video in WebM containers can be played back.
1568 TEST_F(PipelineIntegrationTest
, BasicPlayback_VideoOnly_VP9_WebM
) {
1569 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9.webm"));
1571 ASSERT_TRUE(WaitUntilOnEnded());
1574 // Verify that VP9 video and Opus audio in the same WebM container can be played
1576 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP9_Opus_WebM
) {
1577 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9-opus.webm"));
1579 ASSERT_TRUE(WaitUntilOnEnded());
1582 // Verify that VP8 video with alpha channel can be played back.
1583 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8A_WebM
) {
1584 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8a.webm"));
1586 ASSERT_TRUE(WaitUntilOnEnded());
1587 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, VideoFrame::YV12A
);
1590 // Verify that VP8A video with odd width/height can be played back.
1591 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8A_Odd_WebM
) {
1592 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8a-odd-dimensions.webm"));
1594 ASSERT_TRUE(WaitUntilOnEnded());
1595 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, VideoFrame::YV12A
);
1598 // Verify that VP9 video with odd width/height can be played back.
1599 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP9_Odd_WebM
) {
1600 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp9-odd-dimensions.webm"));
1602 ASSERT_TRUE(WaitUntilOnEnded());
1605 #if !defined(DISABLE_TEXT_TRACK_TESTS)
1606 // Verify that VP8 video with inband text track can be played back.
1607 TEST_F(PipelineIntegrationTest
, BasicPlayback_VP8_WebVTT_WebM
) {
1608 EXPECT_CALL(*this, OnAddTextTrack(_
, _
));
1609 ASSERT_EQ(PIPELINE_OK
, Start("bear-vp8-webvtt.webm"));
1611 ASSERT_TRUE(WaitUntilOnEnded());
1613 #endif // !defined(DISABLE_TEXT_TRACK_TESTS)
1615 // Verify that VP9 video with 4:4:4 subsampling can be played back.
1616 TEST_F(PipelineIntegrationTest
, P444_VP9_WebM
) {
1617 ASSERT_EQ(PIPELINE_OK
, Start("bear-320x240-P444.webm"));
1619 ASSERT_TRUE(WaitUntilOnEnded());
1620 EXPECT_VIDEO_FORMAT_EQ(last_video_frame_format_
, VideoFrame::YV24
);
1623 // Verify that videos with an odd frame size playback successfully.
1624 TEST_F(PipelineIntegrationTest
, BasicPlayback_OddVideoSize
) {
1625 ASSERT_EQ(PIPELINE_OK
, Start("butterfly-853x480.webm"));
1627 ASSERT_TRUE(WaitUntilOnEnded());
1630 // Verify that OPUS audio in a webm which reports a 44.1kHz sample rate plays
1631 // correctly at 48kHz
1632 TEST_F(PipelineIntegrationTest
, BasicPlayback_Opus441kHz
) {
1633 ASSERT_EQ(PIPELINE_OK
, Start("sfx-opus-441.webm"));
1635 ASSERT_TRUE(WaitUntilOnEnded());
1637 demuxer_
->GetStream(DemuxerStream::AUDIO
)
1638 ->audio_decoder_config()
1639 .samples_per_second());
1642 // Same as above but using MediaSource.
1643 TEST_F(PipelineIntegrationTest
, BasicPlayback_MediaSource_Opus441kHz
) {
1644 MockMediaSource
source(
1645 "sfx-opus-441.webm", kOpusAudioOnlyWebM
, kAppendWholeFile
);
1646 StartPipelineWithMediaSource(&source
);
1647 source
.EndOfStream();
1649 ASSERT_TRUE(WaitUntilOnEnded());
1653 demuxer_
->GetStream(DemuxerStream::AUDIO
)
1654 ->audio_decoder_config()
1655 .samples_per_second());
1658 // Ensures audio-only playback with missing or negative timestamps works. Tests
1659 // the common live-streaming case for chained ogg. See http://crbug.com/396864.
1660 TEST_F(PipelineIntegrationTest
, BasicPlaybackChainedOgg
) {
1661 ASSERT_EQ(PIPELINE_OK
, Start("double-sfx.ogg"));
1663 ASSERT_TRUE(WaitUntilOnEnded());
1664 ASSERT_EQ(base::TimeDelta(), demuxer_
->GetStartTime());
1667 // Ensures audio-video playback with missing or negative timestamps fails softly
1668 // instead of crashing. See http://crbug.com/396864.
1669 TEST_F(PipelineIntegrationTest
, BasicPlaybackChainedOggVideo
) {
1670 ASSERT_EQ(PIPELINE_OK
, Start("double-bear.ogv"));
1672 EXPECT_EQ(PIPELINE_ERROR_DECODE
, WaitUntilEndedOrError());
1673 ASSERT_EQ(base::TimeDelta(), demuxer_
->GetStartTime());
1676 // Tests that we signal ended even when audio runs longer than video track.
1677 TEST_F(PipelineIntegrationTest
, BasicPlaybackAudioLongerThanVideo
) {
1678 ASSERT_EQ(PIPELINE_OK
, Start("bear_audio_longer_than_video.ogv"));
1679 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher
1681 EXPECT_EQ(2000, pipeline_
->GetMediaDuration().InMilliseconds());
1683 ASSERT_TRUE(WaitUntilOnEnded());
1686 // Tests that we signal ended even when audio runs shorter than video track.
1687 TEST_F(PipelineIntegrationTest
, BasicPlaybackAudioShorterThanVideo
) {
1688 ASSERT_EQ(PIPELINE_OK
, Start("bear_audio_shorter_than_video.ogv"));
1689 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of
1691 EXPECT_EQ(1001, pipeline_
->GetMediaDuration().InMilliseconds());
1693 ASSERT_TRUE(WaitUntilOnEnded());
1696 TEST_F(PipelineIntegrationTest
, BasicPlaybackPositiveStartTime
) {
1697 ASSERT_EQ(PIPELINE_OK
, Start("nonzero-start-time.webm"));
1699 ASSERT_TRUE(WaitUntilOnEnded());
1700 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
1701 demuxer_
->GetStartTime());
1704 } // namespace media