Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: media/base/android/media_source_player_unittest.cc

Issue 254473010: Refactor MSE implementation on Android to simplify the logic and improve the performance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments on unit tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "media/base/android/audio_decoder_job.h"
11 #include "media/base/android/media_codec_bridge.h" 12 #include "media/base/android/media_codec_bridge.h"
12 #include "media/base/android/media_drm_bridge.h" 13 #include "media/base/android/media_drm_bridge.h"
13 #include "media/base/android/media_player_manager.h" 14 #include "media/base/android/media_player_manager.h"
14 #include "media/base/android/media_source_player.h" 15 #include "media/base/android/media_source_player.h"
16 #include "media/base/android/video_decoder_job.h"
15 #include "media/base/bind_to_current_loop.h" 17 #include "media/base/bind_to_current_loop.h"
16 #include "media/base/decoder_buffer.h" 18 #include "media/base/decoder_buffer.h"
17 #include "media/base/test_data_util.h" 19 #include "media/base/test_data_util.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "ui/gl/android/surface_texture.h" 21 #include "ui/gl/android/surface_texture.h"
20 22
21 namespace media { 23 namespace media {
22 24
23 // Helper macro to skip the test if MediaCodecBridge isn't available. 25 // Helper macro to skip the test if MediaCodecBridge isn't available.
24 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \ 26 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, 181 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested,
180 base::Unretained(&manager_)), 182 base::Unretained(&manager_)),
181 base::Bind(&MockMediaPlayerManager::OnMediaResourcesReleased, 183 base::Bind(&MockMediaPlayerManager::OnMediaResourcesReleased,
182 base::Unretained(&manager_)), 184 base::Unretained(&manager_)),
183 scoped_ptr<DemuxerAndroid>(demuxer_)), 185 scoped_ptr<DemuxerAndroid>(demuxer_)),
184 decoder_callback_hook_executed_(false), 186 decoder_callback_hook_executed_(false),
185 surface_texture_a_is_next_(true) {} 187 surface_texture_a_is_next_(true) {}
186 virtual ~MediaSourcePlayerTest() {} 188 virtual ~MediaSourcePlayerTest() {}
187 189
188 protected: 190 protected:
189 // Get the decoder job from the MediaSourcePlayer. 191 // Get the decoder job from the MediaSourcePlayer. The return value must not
192 // be NULL.
190 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) { 193 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) {
191 if (is_audio) { 194 if (is_audio) {
192 return reinterpret_cast<MediaDecoderJob*>( 195 return reinterpret_cast<MediaDecoderJob*>(
193 player_.audio_decoder_job_.get()); 196 player_.audio_decoder_job_.get());
194 } 197 }
195 return reinterpret_cast<MediaDecoderJob*>( 198 return reinterpret_cast<MediaDecoderJob*>(
196 player_.video_decoder_job_.get()); 199 player_.video_decoder_job_.get());
197 } 200 }
198 201
202 // Get the MediaCodecBridge from the decoder job. The return value could be
203 // NULL if the decoder is not yet created.
204 MediaCodecBridge* GetMediaCodecBridge(bool is_audio) {
205 if (is_audio)
206 return player_.audio_decoder_job_->media_codec_bridge_.get();
207 return player_.video_decoder_job_->media_codec_bridge_.get();
208 }
209
199 // Get the per-job prerolling status from the MediaSourcePlayer's job matching 210 // Get the per-job prerolling status from the MediaSourcePlayer's job matching
200 // |is_audio|. Caller must guard against NPE if the player's job is NULL. 211 // |is_audio|. Caller must guard against NPE if the player's job is NULL.
201 bool IsPrerolling(bool is_audio) { 212 bool IsPrerolling(bool is_audio) {
202 return GetMediaDecoderJob(is_audio)->prerolling(); 213 return GetMediaDecoderJob(is_audio)->prerolling_;
203 } 214 }
204 215
205 // Get the preroll timestamp from the MediaSourcePlayer. 216 // Get the preroll timestamp from the MediaSourcePlayer.
206 base::TimeDelta GetPrerollTimestamp() { 217 base::TimeDelta GetPrerollTimestamp() {
207 return player_.preroll_timestamp_; 218 return player_.preroll_timestamp_;
208 } 219 }
209 220
210 // Simulate player has reached starvation timeout. 221 // Simulate player has reached starvation timeout.
211 void TriggerPlayerStarvation() { 222 void TriggerPlayerStarvation() {
212 player_.decoder_starvation_callback_.Cancel(); 223 player_.decoder_starvation_callback_.Cancel();
213 player_.OnDecoderStarved(); 224 player_.OnDecoderStarved();
214 } 225 }
215 226
216 // Release() the player. 227 // Release() the player.
217 void ReleasePlayer() { 228 void ReleasePlayer() {
218 EXPECT_TRUE(player_.IsPlaying()); 229 EXPECT_TRUE(player_.IsPlaying());
219 player_.Release(); 230 player_.Release();
220 EXPECT_FALSE(player_.IsPlaying()); 231 EXPECT_FALSE(player_.IsPlaying());
221 EXPECT_FALSE(GetMediaDecoderJob(true));
222 EXPECT_FALSE(GetMediaDecoderJob(false));
223 } 232 }
224 233
225 // Upon the next successful decode callback, post a task to call Release() 234 // Upon the next successful decode callback, post a task to call Release()
226 // on the |player_|. TEST_F's do not have access to the private player 235 // on the |player_|. TEST_F's do not have access to the private player
227 // members, hence this helper method. 236 // members, hence this helper method.
228 // Prevent usage creep of MSP::set_decode_callback_for_testing() by 237 // Prevent usage creep of MSP::set_decode_callback_for_testing() by
229 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test. 238 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test.
230 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() { 239 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() {
231 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 240 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
232 player_.set_decode_callback_for_testing(media::BindToCurrentLoop( 241 player_.set_decode_callback_for_testing(media::BindToCurrentLoop(
233 base::Bind( 242 base::Bind(
234 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification, 243 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification,
235 base::Unretained(this)))); 244 base::Unretained(this))));
236 } 245 }
237 246
238 // Asynch test callback posted upon decode completion to verify that a pending 247 // Asynch test callback posted upon decode completion to verify that a pending
239 // prefetch done event is cleared across |player_|'s Release(). This helps 248 // prefetch done event is not cleared across |player_|'s Release(). This helps
240 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met. 249 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met.
241 void ReleaseWithPendingPrefetchDoneVerification() { 250 void ReleaseWithPendingPrefetchDoneVerification() {
242 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); 251 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING));
243 ReleasePlayer(); 252 ReleasePlayer();
244 EXPECT_FALSE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); 253 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING));
245 EXPECT_FALSE(decoder_callback_hook_executed_); 254 EXPECT_FALSE(decoder_callback_hook_executed_);
255 EXPECT_FALSE(GetMediaCodecBridge(true));
246 decoder_callback_hook_executed_ = true; 256 decoder_callback_hook_executed_ = true;
247 } 257 }
248 258
249 // Inspect internal pending_event_ state of |player_|. This is for infrequent 259 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec,
250 // use by tests, only where required. 260 bool use_low_sample_rate) {
251 bool IsPendingSurfaceChange() {
252 return player_.IsEventPending(player_.SURFACE_CHANGE_EVENT_PENDING);
253 }
254
255 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec) {
256 DemuxerConfigs configs; 261 DemuxerConfigs configs;
257 configs.audio_codec = audio_codec; 262 configs.audio_codec = audio_codec;
258 configs.audio_channels = 2; 263 configs.audio_channels = 2;
259 configs.is_audio_encrypted = false; 264 configs.is_audio_encrypted = false;
260 configs.duration = kDefaultDuration; 265 configs.duration = kDefaultDuration;
261 266
262 if (audio_codec == kCodecVorbis) { 267 if (audio_codec == kCodecVorbis) {
263 configs.audio_sampling_rate = 44100; 268 configs.audio_sampling_rate = use_low_sample_rate ? 11025 : 44100;
264 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( 269 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(
265 "vorbis-extradata"); 270 "vorbis-extradata");
266 configs.audio_extra_data = std::vector<uint8>( 271 configs.audio_extra_data = std::vector<uint8>(
267 buffer->data(), 272 buffer->data(),
268 buffer->data() + buffer->data_size()); 273 buffer->data() + buffer->data_size());
269 return configs; 274 return configs;
270 } 275 }
271 276
272 // Other codecs are not yet supported by this helper. 277 // Other codecs are not yet supported by this helper.
273 EXPECT_EQ(audio_codec, kCodecAAC); 278 EXPECT_EQ(audio_codec, kCodecAAC);
274 279
275 configs.audio_sampling_rate = 48000; 280 configs.audio_sampling_rate = 48000;
276 uint8 aac_extra_data[] = { 0x13, 0x10 }; 281 uint8 aac_extra_data[] = { 0x13, 0x10 };
277 configs.audio_extra_data = std::vector<uint8>( 282 configs.audio_extra_data = std::vector<uint8>(
278 aac_extra_data, 283 aac_extra_data,
279 aac_extra_data + 2); 284 aac_extra_data + 2);
280 return configs; 285 return configs;
281 } 286 }
282 287
283 DemuxerConfigs CreateVideoDemuxerConfigs() { 288 DemuxerConfigs CreateVideoDemuxerConfigs(VideoCodec video_codec) {
284 DemuxerConfigs configs; 289 DemuxerConfigs configs;
285 configs.video_codec = kCodecVP8; 290 configs.video_codec = video_codec;
286 configs.video_size = gfx::Size(320, 240); 291 configs.video_size = gfx::Size(320, 240);
287 configs.is_video_encrypted = false; 292 configs.is_video_encrypted = false;
288 configs.duration = kDefaultDuration; 293 configs.duration = kDefaultDuration;
289 return configs; 294 return configs;
290 } 295 }
291 296
292 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { 297 DemuxerConfigs CreateAudioVideoDemuxerConfigs() {
293 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 298 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
294 configs.video_codec = kCodecVP8; 299 configs.video_codec = kCodecVP8;
295 configs.video_size = gfx::Size(320, 240); 300 configs.video_size = gfx::Size(320, 240);
296 configs.is_video_encrypted = false; 301 configs.is_video_encrypted = false;
297 return configs; 302 return configs;
298 } 303 }
299 304
300 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { 305 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) {
301 DCHECK(have_audio || have_video); 306 DCHECK(have_audio || have_video);
302 307
303 if (have_audio && !have_video) 308 if (have_audio && !have_video)
304 return CreateAudioDemuxerConfigs(kCodecVorbis); 309 return CreateAudioDemuxerConfigs(kCodecVorbis, false);
305 310
306 if (have_video && !have_audio) 311 if (have_video && !have_audio)
307 return CreateVideoDemuxerConfigs(); 312 return CreateVideoDemuxerConfigs(kCodecVP8);
308 313
309 return CreateAudioVideoDemuxerConfigs(); 314 return CreateAudioVideoDemuxerConfigs();
310 } 315 }
311 316
312 // Starts an audio decoder job. 317 // Starts an audio decoder job.
313 void StartAudioDecoderJob() { 318 void StartAudioDecoderJob() {
314 Start(CreateAudioDemuxerConfigs(kCodecVorbis)); 319 Start(CreateAudioDemuxerConfigs(kCodecVorbis, false));
315 } 320 }
316 321
317 // Starts a video decoder job. 322 // Starts a video decoder job.
318 void StartVideoDecoderJob() { 323 void StartVideoDecoderJob() {
319 Start(CreateVideoDemuxerConfigs()); 324 Start(CreateVideoDemuxerConfigs(kCodecVP8));
320 } 325 }
321 326
322 // Starts decoding the data. 327 // Starts decoding the data.
323 void Start(const DemuxerConfigs& configs) { 328 void Start(const DemuxerConfigs& configs) {
324 EXPECT_EQ(demuxer_->num_data_requests(), 0); 329 EXPECT_EQ(demuxer_->num_data_requests(), 0);
325 player_.OnDemuxerConfigsAvailable(configs); 330 player_.OnDemuxerConfigsAvailable(configs);
326 player_.Start(); 331 player_.Start();
327 332
328 EXPECT_TRUE(player_.IsPlaying()); 333 EXPECT_TRUE(player_.IsPlaying());
329 int expected_num_requests = (GetMediaDecoderJob(true) ? 1 : 0) + 334 int expected_num_requests = (player_.HasAudio() ? 1 : 0) +
330 (GetMediaDecoderJob(false) ? 1 : 0); 335 (player_.HasVideo() ? 1 : 0);
331 EXPECT_EQ(expected_num_requests, demuxer_->num_data_requests()); 336 EXPECT_EQ(expected_num_requests, demuxer_->num_data_requests());
332 } 337 }
333 338
334 // Resumes decoding the data. Verifies player behavior relative to 339 // Resumes decoding the data. Verifies player behavior relative to
335 // |expect_player_requests_audio_data| and 340 // |expect_player_requests_audio_data| and
336 // |expect_player_requests_video_data|. 341 // |expect_player_requests_video_data|.
337 void Resume(bool expect_player_requests_audio_data, 342 void Resume(bool expect_player_requests_audio_data,
338 bool expect_player_requests_video_data) { 343 bool expect_player_requests_video_data) {
339 EXPECT_FALSE(player_.IsPlaying()); 344 EXPECT_FALSE(player_.IsPlaying());
340 EXPECT_TRUE(player_.HasVideo() || player_.HasAudio()); 345 EXPECT_TRUE(player_.HasVideo() || player_.HasAudio());
341 int original_num_data_requests = demuxer_->num_data_requests(); 346 int original_num_data_requests = demuxer_->num_data_requests();
342 int expected_request_delta = 347 int expected_request_delta =
343 (expect_player_requests_audio_data ? 1 : 0) + 348 (expect_player_requests_audio_data ? 1 : 0) +
344 (expect_player_requests_video_data ? 1 : 0); 349 (expect_player_requests_video_data ? 1 : 0);
345 350
346 player_.Start(); 351 player_.Start();
347 352
348 EXPECT_TRUE(player_.IsPlaying()); 353 EXPECT_TRUE(player_.IsPlaying());
349 EXPECT_EQ(original_num_data_requests + expected_request_delta, 354 EXPECT_EQ(original_num_data_requests + expected_request_delta,
350 demuxer_->num_data_requests()); 355 demuxer_->num_data_requests());
351 EXPECT_EQ(expect_player_requests_audio_data,
352 expect_player_requests_audio_data && GetMediaDecoderJob(true));
353 EXPECT_EQ(expect_player_requests_video_data,
354 expect_player_requests_video_data && GetMediaDecoderJob(false));
355 } 356 }
356 357
357 // Keeps decoding audio data until the decoder starts to output samples. 358 // Keeps decoding audio data until the decoder starts to output samples.
358 // Gives up if no audio output after decoding 10 frames. 359 // Gives up if no audio output after decoding 10 frames.
359 void DecodeAudioDataUntilOutputBecomesAvailable() { 360 void DecodeAudioDataUntilOutputBecomesAvailable() {
360 EXPECT_TRUE(player_.IsPlaying()); 361 EXPECT_TRUE(player_.IsPlaying());
361 base::TimeDelta current_time = player_.GetCurrentTime(); 362 base::TimeDelta current_time = player_.GetCurrentTime();
362 base::TimeDelta start_timestamp = current_time; 363 base::TimeDelta start_timestamp = current_time;
363 for (int i = 0; i < 10; ++i) { 364 for (int i = 0; i < 10; ++i) {
364 manager_.ResetTimestampUpdated(); 365 manager_.ResetTimestampUpdated();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 433 }
433 434
434 // Helper method for use at test start. It starts an audio decoder job and 435 // Helper method for use at test start. It starts an audio decoder job and
435 // immediately feeds it some data to decode. Then, without letting the decoder 436 // immediately feeds it some data to decode. Then, without letting the decoder
436 // job complete a decode cycle, it also starts player SeekTo(). Upon return, 437 // job complete a decode cycle, it also starts player SeekTo(). Upon return,
437 // the player should not yet have sent the DemuxerSeek IPC request, though 438 // the player should not yet have sent the DemuxerSeek IPC request, though
438 // seek event should be pending. The audio decoder job will also still be 439 // seek event should be pending. The audio decoder job will also still be
439 // decoding. 440 // decoding.
440 void StartAudioDecoderJobAndSeekToWhileDecoding( 441 void StartAudioDecoderJobAndSeekToWhileDecoding(
441 const base::TimeDelta& seek_time) { 442 const base::TimeDelta& seek_time) {
442 EXPECT_FALSE(GetMediaDecoderJob(true)); 443 EXPECT_FALSE(GetMediaCodecBridge(true));
443 EXPECT_FALSE(player_.IsPlaying()); 444 EXPECT_FALSE(player_.IsPlaying());
444 EXPECT_EQ(0, demuxer_->num_data_requests()); 445 EXPECT_EQ(0, demuxer_->num_data_requests());
445 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 446 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
446 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); 447 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp());
447 StartAudioDecoderJob(); 448 StartAudioDecoderJob();
448 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 449 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
449 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 450 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
450 EXPECT_EQ(2, demuxer_->num_data_requests()); 451 EXPECT_EQ(2, demuxer_->num_data_requests());
451 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 452 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
452 player_.SeekTo(seek_time); 453 player_.SeekTo(seek_time);
453 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); 454 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF());
454 EXPECT_EQ(0, demuxer_->num_seek_requests()); 455 EXPECT_EQ(0, demuxer_->num_seek_requests());
455 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 456 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
456 } 457 }
457 458
458 // Seek, including simulated receipt of |kAborted| read between SeekTo() and 459 // Seek, including simulated receipt of |kAborted| read between SeekTo() and
459 // OnDemuxerSeekDone(). Use this helper method only when the player already 460 // OnDemuxerSeekDone(). Use this helper method only when the player already
460 // has created the decoder job. Exactly one request for more data is expected 461 // has created the media codec bridge. Exactly one request for more data is
461 // following the seek, so use this helper for players with only audio or only 462 // expected following the seek, so use this helper for players with only audio
462 // video. 463 // or only video.
463 void SeekPlayerWithAbort(bool is_audio, const base::TimeDelta& seek_time) { 464 void SeekPlayerWithAbort(bool is_audio, const base::TimeDelta& seek_time) {
464 int original_num_seeks = demuxer_->num_seek_requests(); 465 int original_num_seeks = demuxer_->num_seek_requests();
465 int original_num_data_requests = demuxer_->num_data_requests(); 466 int original_num_data_requests = demuxer_->num_data_requests();
466 467
467 // Initiate a seek. Skip the round-trip of requesting seek from renderer. 468 // Initiate a seek. Skip the round-trip of requesting seek from renderer.
468 // Instead behave as if the renderer has asked us to seek. 469 // Instead behave as if the renderer has asked us to seek.
469 player_.SeekTo(seek_time); 470 player_.SeekTo(seek_time);
470 471
471 // Verify that the seek does not occur until previously outstanding data 472 // Verify that the seek does not occur until previously outstanding data
472 // request is satisfied. 473 // request is satisfied.
473 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests()); 474 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests());
474 475
475 // Simulate seeking causes the demuxer to abort the outstanding read 476 // Simulate seeking causes the demuxer to abort the outstanding read
476 // caused by the seek. 477 // caused by the seek.
477 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio)); 478 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio));
478 479
480 // Wait for the decode job to finish so we can process the seek request.
481 WaitForDecodeDone(is_audio, !is_audio);
482
479 // Verify that the seek is requested. 483 // Verify that the seek is requested.
480 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); 484 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests());
481 485
482 // Send back the seek done notification. This should trigger the player to 486 // Send back the seek done notification. This should trigger the player to
483 // call OnReadFromDemuxer() again. 487 // call OnReadFromDemuxer() again.
484 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests()); 488 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests());
485 player_.OnDemuxerSeekDone(kNoTimestamp()); 489 player_.OnDemuxerSeekDone(kNoTimestamp());
486 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests()); 490 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests());
487 491
488 // No other seek should have been requested. 492 // No other seek should have been requested.
(...skipping 17 matching lines...) Expand all
506 // Send some data with access unit timestamps before the |target_timestamp|, 510 // Send some data with access unit timestamps before the |target_timestamp|,
507 // and continue sending the data until preroll finishes. 511 // and continue sending the data until preroll finishes.
508 // This simulates the common condition that AUs received after browser 512 // This simulates the common condition that AUs received after browser
509 // seek begin with timestamps before the seek target, and don't 513 // seek begin with timestamps before the seek target, and don't
510 // immediately complete preroll. 514 // immediately complete preroll.
511 while (IsPrerolling(is_audio)) { 515 while (IsPrerolling(is_audio)) {
512 data.access_units[0].timestamp = 516 data.access_units[0].timestamp =
513 base::TimeDelta::FromMilliseconds(current_timestamp); 517 base::TimeDelta::FromMilliseconds(current_timestamp);
514 player_.OnDemuxerDataAvailable(data); 518 player_.OnDemuxerDataAvailable(data);
515 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding()); 519 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding());
520 EXPECT_TRUE(GetMediaCodecBridge(is_audio));
516 EXPECT_EQ(target_timestamp, player_.GetCurrentTime()); 521 EXPECT_EQ(target_timestamp, player_.GetCurrentTime());
517 current_timestamp += 30; 522 current_timestamp += 30;
518 WaitForDecodeDone(is_audio, !is_audio); 523 WaitForDecodeDone(is_audio, !is_audio);
519 } 524 }
520 EXPECT_LE(target_timestamp, player_.GetCurrentTime()); 525 EXPECT_LE(target_timestamp, player_.GetCurrentTime());
521 } 526 }
522 527
523 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio, 528 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(
524 int config_unit_index) { 529 bool is_audio,
530 int config_unit_index,
531 const DemuxerConfigs& configs) {
525 DemuxerData data; 532 DemuxerData data;
526 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; 533 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO;
527 data.access_units.resize(config_unit_index + 1); 534 data.access_units.resize(config_unit_index + 1);
528 535
529 for (int i = 0; i < config_unit_index; ++i) 536 for (int i = 0; i < config_unit_index; ++i)
530 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); 537 data.access_units[i] = CreateAccessUnitWithData(is_audio, i);
531 538
532 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; 539 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged;
533 data.demuxer_configs.resize(1); 540 data.demuxer_configs.resize(1);
534 data.demuxer_configs[0] = CreateDemuxerConfigs(is_audio, !is_audio); 541 data.demuxer_configs[0] = configs;
535 return data; 542 return data;
536 } 543 }
537 544
538 // Valid only for video-only player tests. If |trigger_with_release_start| is 545 // Valid only for video-only player tests. If |trigger_with_release_start| is
539 // true, triggers the browser seek with a Release() + video data received + 546 // true, triggers the browser seek with a Release() + video data received +
540 // Start() with a new surface. If false, triggers the browser seek by 547 // Start() with a new surface. If false, triggers the browser seek by
541 // setting a new video surface after beginning decode of received video data. 548 // setting a new video surface after beginning decode of received video data.
542 // Such data receipt causes possibility that an I-frame is not next, and 549 // Such data receipt causes possibility that an I-frame is not next, and
543 // browser seek results once decode completes and surface change processing 550 // browser seek results once decode completes and surface change processing
544 // begins. 551 // begins.
545 void BrowserSeekPlayer(bool trigger_with_release_start) { 552 void BrowserSeekPlayer(bool trigger_with_release_start) {
546 int expected_num_data_requests = demuxer_->num_data_requests() + 553 int expected_num_data_requests = demuxer_->num_data_requests() + 2;
547 (trigger_with_release_start ? 1 : 2);
548 int expected_num_seek_requests = demuxer_->num_seek_requests(); 554 int expected_num_seek_requests = demuxer_->num_seek_requests();
549 int expected_num_browser_seek_requests = 555 int expected_num_browser_seek_requests =
550 demuxer_->num_browser_seek_requests(); 556 demuxer_->num_browser_seek_requests();
551 557
552 EXPECT_FALSE(GetMediaDecoderJob(false));
553 CreateNextTextureAndSetVideoSurface(); 558 CreateNextTextureAndSetVideoSurface();
554 StartVideoDecoderJob(); 559 StartVideoDecoderJob();
555 if (trigger_with_release_start) { 560 if (trigger_with_release_start) {
561 // Consume the first frame, so that the next VideoDecoderJob will not
562 // inherit the I-frame from the previous decoder.
563 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
556 ReleasePlayer(); 564 ReleasePlayer();
565 WaitForVideoDecodeDone();
566
557 // Simulate demuxer's response to the video data request. The data will be 567 // Simulate demuxer's response to the video data request. The data will be
558 // discarded. 568 // passed to the next MediaCodecBridge.
559 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 569 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
560 EXPECT_FALSE(GetMediaDecoderJob(false)); 570 EXPECT_FALSE(GetMediaCodecBridge(false));
561 EXPECT_FALSE(player_.IsPlaying()); 571 EXPECT_FALSE(player_.IsPlaying());
562 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 572 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
563 573
564 CreateNextTextureAndSetVideoSurface(); 574 CreateNextTextureAndSetVideoSurface();
565 Resume(false, false); 575 Resume(false, false);
566 EXPECT_FALSE(GetMediaDecoderJob(false)); 576 EXPECT_FALSE(GetMediaCodecBridge(false));
577
578 // Run the message loop so that prefetch will complete.
579 while (expected_num_seek_requests == demuxer_->num_seek_requests())
580 message_loop_.RunUntilIdle();
567 } else { 581 } else {
568 // Simulate demuxer's response to the video data request. 582 // Simulate demuxer's response to the video data request.
569 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 583 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
570 584
571 // While the decoder is decoding, trigger a browser seek by changing 585 // While the decoder is decoding, trigger a browser seek by changing
572 // surface. Demuxer does not know of browser seek in advance, so no 586 // surface. Demuxer does not know of browser seek in advance, so no
573 // |kAborted| data is required (though |kAborted| can certainly occur for 587 // |kAborted| data is required (though |kAborted| can certainly occur for
574 // any pending read in reality due to renderer preparing for a regular 588 // any pending read in reality due to renderer preparing for a regular
575 // seek). 589 // seek).
576 CreateNextTextureAndSetVideoSurface(); 590 CreateNextTextureAndSetVideoSurface();
577 591
578 // Browser seek should not begin until decoding has completed. 592 // Browser seek should not begin until decoding has completed.
579 EXPECT_TRUE(GetMediaDecoderJob(false)); 593 EXPECT_TRUE(GetMediaCodecBridge(false));
580 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 594 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
581 595
582 // Wait for the decoder job to finish decoding and be reset pending the 596 // Wait for the media codec bridge to finish decoding and be reset pending
583 // browser seek. 597 // the browser seek.
584 WaitForVideoDecodeDone(); 598 WaitForVideoDecodeDone();
585 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 599 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
586 } 600 }
587 601
588 // Only one browser seek should have been initiated, and no further data 602 // Only one browser seek should have been initiated, and no further data
589 // should have been requested. 603 // should have been requested.
590 expected_num_seek_requests++; 604 expected_num_seek_requests++;
591 expected_num_browser_seek_requests++; 605 expected_num_browser_seek_requests++;
592 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); 606 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests());
593 EXPECT_EQ(expected_num_browser_seek_requests, 607 EXPECT_EQ(expected_num_browser_seek_requests,
594 demuxer_->num_browser_seek_requests()); 608 demuxer_->num_browser_seek_requests());
595 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 609 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
596 } 610 }
597 611
598 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| 612 // Creates a new media codec bridge and feeds it data ending with a
599 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config 613 // |kConfigChanged| access unit. If |config_unit_in_prefetch| is true, sends
600 // change AU in response to the job's first read request (prefetch). If 614 // feeds the config change AU in response to the job's first read request
601 // false, regular data is fed and decoded prior to feeding the config change 615 // (prefetch). If false, regular data is fed and decoded prior to feeding the
602 // AU in response to the second data request (after prefetch completed). 616 // config change AU in response to the second data request (after prefetch
603 // |config_unit_index| controls which access unit is |kConfigChanged|. 617 // completed). |config_unit_index| controls which access unit is
604 void StartConfigChange(bool is_audio, 618 // |kConfigChanged|.
605 bool config_unit_in_prefetch, 619 void SendConfigChangeToDecoder(bool is_audio,
606 int config_unit_index) { 620 bool config_unit_in_prefetch,
607 EXPECT_FALSE(GetMediaDecoderJob(is_audio)); 621 int config_unit_index) {
622 EXPECT_FALSE(GetMediaCodecBridge(is_audio));
608 if (is_audio) { 623 if (is_audio) {
609 StartAudioDecoderJob(); 624 StartAudioDecoderJob();
610 } else { 625 } else {
611 CreateNextTextureAndSetVideoSurface(); 626 CreateNextTextureAndSetVideoSurface();
612 StartVideoDecoderJob(); 627 StartVideoDecoderJob();
613 } 628 }
614 629
615 int expected_num_data_requests = demuxer_->num_data_requests(); 630 int expected_num_data_requests = demuxer_->num_data_requests();
616
617 // Feed and decode a standalone access unit so the player exits prefetch. 631 // Feed and decode a standalone access unit so the player exits prefetch.
618 if (!config_unit_in_prefetch) { 632 if (!config_unit_in_prefetch) {
619 if (is_audio) 633 if (is_audio)
620 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 634 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
621 else 635 else
622 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 636 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
623 637
624 WaitForDecodeDone(is_audio, !is_audio); 638 WaitForDecodeDone(is_audio, !is_audio);
625 639
626 // We should have completed the prefetch phase at this point. 640 // We should have completed the prefetch phase at this point.
627 expected_num_data_requests++; 641 expected_num_data_requests++;
628 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); 642 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
629 } 643 }
630 644
645 DemuxerConfigs configs = is_audio ?
646 CreateAudioDemuxerConfigs(kCodecAAC, false) :
647 CreateVideoDemuxerConfigs(kCodecVP9);
631 // Feed and decode access units with data for any units prior to 648 // Feed and decode access units with data for any units prior to
632 // |config_unit_index|, and a |kConfigChanged| unit at that index. 649 // |config_unit_index|, and a |kConfigChanged| unit at that index.
633 // Player should prepare to reconfigure the decoder job, and should request 650 // Player should prepare to reconfigure the decoder job, and should request
634 // new demuxer configs. 651 // new demuxer configs.
635 player_.OnDemuxerDataAvailable( 652 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
636 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index)); 653 is_audio, config_unit_index, configs));
654
655 expected_num_data_requests++;
656 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests());
657 if (is_audio)
658 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
659 else
660 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
661 }
662
663 // Send a config change to the decoder job and drain the decoder so that the
664 // config change is processed.
665 void StartConfigChange(bool is_audio,
666 bool config_unit_in_prefetch,
667 int config_unit_index) {
668 SendConfigChangeToDecoder(is_audio, config_unit_in_prefetch,
669 config_unit_index);
670 EXPECT_EQ(!config_unit_in_prefetch && config_unit_index == 0,
671 IsDrainingDecoder(is_audio));
672 int expected_num_data_requests = demuxer_->num_data_requests();
637 // Run until decoder starts to request new data. 673 // Run until decoder starts to request new data.
638 while (demuxer_->num_data_requests() == expected_num_data_requests) 674 while (demuxer_->num_data_requests() == expected_num_data_requests)
639 message_loop_.RunUntilIdle(); 675 message_loop_.RunUntilIdle();
676 EXPECT_FALSE(IsDrainingDecoder(is_audio));
640 } 677 }
641 678
642 void CreateNextTextureAndSetVideoSurface() { 679 void CreateNextTextureAndSetVideoSurface() {
643 gfx::SurfaceTexture* surface_texture; 680 gfx::SurfaceTexture* surface_texture;
644 if (surface_texture_a_is_next_) { 681 if (surface_texture_a_is_next_) {
645 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); 682 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++);
646 surface_texture = surface_texture_a_.get(); 683 surface_texture = surface_texture_a_.get();
647 } else { 684 } else {
648 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); 685 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++);
649 surface_texture = surface_texture_b_.get(); 686 surface_texture = surface_texture_b_.get();
650 } 687 }
651 688
652 surface_texture_a_is_next_ = !surface_texture_a_is_next_; 689 surface_texture_a_is_next_ = !surface_texture_a_is_next_;
653 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); 690 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture);
654 player_.SetVideoSurface(surface.Pass()); 691 player_.SetVideoSurface(surface.Pass());
655 } 692 }
656 693
657 // Wait for one or both of the jobs to complete decoding. Decoder jobs are 694 // Wait for one or both of the jobs to complete decoding. Media codec bridges
658 // assumed to exist for any stream whose decode completion is awaited. 695 // are assumed to exist for any stream whose decode completion is awaited.
659 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { 696 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) {
660 DCHECK(wait_for_audio || wait_for_video); 697 DCHECK(wait_for_audio || wait_for_video);
661 while ((wait_for_audio && GetMediaDecoderJob(true) && 698 while ((wait_for_audio && GetMediaCodecBridge(true) &&
662 GetMediaDecoderJob(true)->HasData() && 699 GetMediaDecoderJob(true)->HasData() &&
663 GetMediaDecoderJob(true)->is_decoding()) || 700 GetMediaDecoderJob(true)->is_decoding()) ||
664 (wait_for_video && GetMediaDecoderJob(false) && 701 (wait_for_video && GetMediaCodecBridge(false) &&
665 GetMediaDecoderJob(false)->HasData() && 702 GetMediaDecoderJob(false)->HasData() &&
666 GetMediaDecoderJob(false)->is_decoding())) { 703 GetMediaDecoderJob(false)->is_decoding())) {
667 message_loop_.RunUntilIdle(); 704 message_loop_.RunUntilIdle();
668 } 705 }
669 } 706 }
670 707
671 void WaitForAudioDecodeDone() { 708 void WaitForAudioDecodeDone() {
672 WaitForDecodeDone(true, false); 709 WaitForDecodeDone(true, false);
673 } 710 }
674 711
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 EXPECT_EQ(1, demuxer_->num_seek_requests()); 794 EXPECT_EQ(1, demuxer_->num_seek_requests());
758 795
759 player_.OnDemuxerSeekDone(kNoTimestamp()); 796 player_.OnDemuxerSeekDone(kNoTimestamp());
760 EXPECT_FALSE(manager_.playback_completed()); 797 EXPECT_FALSE(manager_.playback_completed());
761 } 798 }
762 799
763 base::TimeTicks StartTimeTicks() { 800 base::TimeTicks StartTimeTicks() {
764 return player_.start_time_ticks_; 801 return player_.start_time_ticks_;
765 } 802 }
766 803
804 bool IsRequestingDemuxerData(bool is_audio) {
805 return GetMediaDecoderJob(is_audio)->is_requesting_demuxer_data_;
806 }
807
808 bool IsDrainingDecoder(bool is_audio) {
809 return GetMediaDecoderJob(is_audio)->drain_decoder_;
810 }
811
767 base::MessageLoop message_loop_; 812 base::MessageLoop message_loop_;
768 MockMediaPlayerManager manager_; 813 MockMediaPlayerManager manager_;
769 MockDemuxerAndroid* demuxer_; // Owned by |player_|. 814 MockDemuxerAndroid* demuxer_; // Owned by |player_|.
770 MediaSourcePlayer player_; 815 MediaSourcePlayer player_;
771 816
772 // Track whether a possibly async decoder callback test hook has run. 817 // Track whether a possibly async decoder callback test hook has run.
773 bool decoder_callback_hook_executed_; 818 bool decoder_callback_hook_executed_;
774 819
775 // We need to keep the surface texture while the decoder is actively decoding. 820 // We need to keep the surface texture while the decoder is actively decoding.
776 // Otherwise, it may trigger unexpected crashes on some devices. To switch 821 // Otherwise, it may trigger unexpected crashes on some devices. To switch
777 // surfaces, tests need to create a new surface texture without releasing 822 // surfaces, tests need to create a new surface texture without releasing
778 // their previous one. In CreateNextTextureAndSetVideoSurface(), we toggle 823 // their previous one. In CreateNextTextureAndSetVideoSurface(), we toggle
779 // between two surface textures, only replacing the N-2 texture. Assumption is 824 // between two surface textures, only replacing the N-2 texture. Assumption is
780 // that no more than N-1 texture is in use by decoder when 825 // that no more than N-1 texture is in use by decoder when
781 // CreateNextTextureAndSetVideoSurface() is called. 826 // CreateNextTextureAndSetVideoSurface() is called.
782 scoped_refptr<gfx::SurfaceTexture> surface_texture_a_; 827 scoped_refptr<gfx::SurfaceTexture> surface_texture_a_;
783 scoped_refptr<gfx::SurfaceTexture> surface_texture_b_; 828 scoped_refptr<gfx::SurfaceTexture> surface_texture_b_;
784 bool surface_texture_a_is_next_; 829 bool surface_texture_a_is_next_;
785 int next_texture_id_; 830 int next_texture_id_;
786 831
787 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); 832 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest);
788 }; 833 };
789 834
790 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { 835 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) {
791 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 836 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
792 837
793 // Test audio decoder job will be created when codec is successfully started. 838 // Test audio codec will be created when codec is successfully started.
wolenetz 2014/06/04 21:42:24 nit: circular / recursive comment :)
qinmin 2014/06/04 22:34:03 fixed On 2014/06/04 21:42:24, wolenetz wrote:
794 StartAudioDecoderJob(); 839 StartAudioDecoderJob();
795 EXPECT_EQ(0, demuxer_->num_seek_requests()); 840 EXPECT_EQ(0, demuxer_->num_seek_requests());
841 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
842 EXPECT_TRUE(GetMediaCodecBridge(true));
796 } 843 }
797 844
798 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { 845 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) {
799 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 846 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
800 847
801 // Test audio decoder job will not be created when failed to start the codec. 848 // Test audio decoder job will not be created when failed to start the codec.
802 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 849 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
803 // Replace with invalid |audio_extra_data| 850 // Replace with invalid |audio_extra_data|
804 configs.audio_extra_data.clear(); 851 configs.audio_extra_data.clear();
805 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 852 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
806 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 853 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
807 invalid_codec_data, invalid_codec_data + 4); 854 invalid_codec_data, invalid_codec_data + 4);
808 Start(configs); 855 Start(configs);
809 EXPECT_EQ(0, demuxer_->num_seek_requests()); 856
857 // Decoder is not created after data is received.
858 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
859 EXPECT_FALSE(GetMediaCodecBridge(true));
810 } 860 }
811 861
812 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 862 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
813 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 863 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
814 864
815 // Test video decoder job will be created when surface is valid. 865 // Test video codec will not be created until data is received.
816 // Video decoder job will not be created until surface is available.
817 StartVideoDecoderJob(); 866 StartVideoDecoderJob();
818 867
819 // Set both an initial and a later video surface without receiving any 868 // Set both an initial and a later video surface without receiving any
820 // demuxed data yet. 869 // demuxed data yet.
821 CreateNextTextureAndSetVideoSurface(); 870 CreateNextTextureAndSetVideoSurface();
822 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 871 EXPECT_FALSE(GetMediaCodecBridge(false));
823 EXPECT_TRUE(first_job);
824 CreateNextTextureAndSetVideoSurface(); 872 CreateNextTextureAndSetVideoSurface();
825 873 EXPECT_FALSE(GetMediaCodecBridge(false));
826 // Setting another surface will not create a new job until any pending
827 // read is satisfied (and job is no longer decoding).
828 EXPECT_EQ(first_job, GetMediaDecoderJob(false));
829 874
830 // No seeks, even on setting surface, should have occurred. (Browser seeks can 875 // No seeks, even on setting surface, should have occurred. (Browser seeks can
831 // occur on setting surface, but only after previously receiving video data.) 876 // occur on setting surface, but only after previously receiving video data.)
832 EXPECT_EQ(0, demuxer_->num_seek_requests()); 877 EXPECT_EQ(0, demuxer_->num_seek_requests());
833 878
834 // Note, the decoder job for the second surface set, above, will be created 879 // Send the first input chunk and verify that decoder will be created.
835 // only after the pending read is satisfied and decoded, and the resulting 880 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
836 // browser seek is done. See BrowserSeek_* tests for this coverage. 881 EXPECT_TRUE(GetMediaCodecBridge(false));
837 } 882 }
838 883
839 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 884 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
840 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 885 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
841 886
842 // Test video decoder job will not be created when surface is invalid. 887 // Test video codec will not be created when surface is invalid.
843 scoped_refptr<gfx::SurfaceTexture> surface_texture( 888 scoped_refptr<gfx::SurfaceTexture> surface_texture(
844 gfx::SurfaceTexture::Create(0)); 889 gfx::SurfaceTexture::Create(0));
845 gfx::ScopedJavaSurface surface(surface_texture.get()); 890 gfx::ScopedJavaSurface surface(surface_texture.get());
846 StartVideoDecoderJob(); 891 StartVideoDecoderJob();
847 892
848 // Release the surface texture. 893 // Release the surface texture.
849 surface_texture = NULL; 894 surface_texture = NULL;
850 player_.SetVideoSurface(surface.Pass()); 895 player_.SetVideoSurface(surface.Pass());
851 896
852 // Player should not seek the demuxer on setting initial surface. 897 // Player should not seek the demuxer on setting initial surface.
853 EXPECT_EQ(0, demuxer_->num_seek_requests()); 898 EXPECT_EQ(0, demuxer_->num_seek_requests());
899 EXPECT_EQ(1, demuxer_->num_data_requests());
854 900
855 EXPECT_FALSE(GetMediaDecoderJob(false)); 901 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
856 EXPECT_EQ(0, demuxer_->num_data_requests()); 902 EXPECT_FALSE(GetMediaCodecBridge(false));
857 } 903 }
858 904
859 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 905 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
860 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 906 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
861 907
862 // Test decoder job will resend a ReadFromDemuxer request after seek. 908 // Test decoder job will resend a ReadFromDemuxer request after seek.
863 StartAudioDecoderJob(); 909 StartAudioDecoderJob();
864 SeekPlayerWithAbort(true, base::TimeDelta()); 910 SeekPlayerWithAbort(true, base::TimeDelta());
865 } 911 }
866 912
867 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 913 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
868 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 914 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
869 915
870 // Test SetVideoSurface() will not cause an extra seek while the player is 916 // Test SetVideoSurface() will not cause an extra seek while the player is
871 // waiting for demuxer to indicate seek is done. 917 // waiting for demuxer to indicate seek is done.
872 // Player is still waiting for SetVideoSurface(), so no request is sent. 918 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs(kCodecVP8));
873 StartVideoDecoderJob(); // Verifies no data requested.
874 919
875 // Initiate a seek. Skip requesting element seek of renderer. 920 // Initiate a seek. Skip requesting element seek of renderer.
876 // Instead behave as if the renderer has asked us to seek. 921 // Instead behave as if the renderer has asked us to seek.
877 EXPECT_EQ(0, demuxer_->num_seek_requests());
878 player_.SeekTo(base::TimeDelta()); 922 player_.SeekTo(base::TimeDelta());
879 EXPECT_EQ(1, demuxer_->num_seek_requests()); 923 EXPECT_EQ(1, demuxer_->num_seek_requests());
880 924
881 CreateNextTextureAndSetVideoSurface(); 925 CreateNextTextureAndSetVideoSurface();
882 EXPECT_FALSE(GetMediaDecoderJob(false));
883 EXPECT_EQ(1, demuxer_->num_seek_requests()); 926 EXPECT_EQ(1, demuxer_->num_seek_requests());
884 927 player_.Start();
885 // Reconfirm player has not yet requested data.
886 EXPECT_EQ(0, demuxer_->num_data_requests());
887 928
888 // Send the seek done notification. The player should start requesting data. 929 // Send the seek done notification. The player should start requesting data.
889 player_.OnDemuxerSeekDone(kNoTimestamp()); 930 player_.OnDemuxerSeekDone(kNoTimestamp());
890 EXPECT_TRUE(GetMediaDecoderJob(false)); 931 EXPECT_FALSE(GetMediaCodecBridge(false));
891 EXPECT_EQ(1, demuxer_->num_data_requests()); 932 EXPECT_EQ(1, demuxer_->num_data_requests());
933 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
934 EXPECT_TRUE(GetMediaCodecBridge(false));
892 935
893 // Reconfirm exactly 1 seek request has been made of demuxer, and that it 936 // Reconfirm exactly 1 seek request has been made of demuxer, and that it
894 // was not a browser seek request. 937 // was not a browser seek request.
895 EXPECT_EQ(1, demuxer_->num_seek_requests()); 938 EXPECT_EQ(1, demuxer_->num_seek_requests());
896 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 939 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
897 } 940 }
898 941
899 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 942 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
900 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 943 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
901 944
902 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 945 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
903 CreateNextTextureAndSetVideoSurface(); 946 CreateNextTextureAndSetVideoSurface();
904 StartVideoDecoderJob(); 947 StartVideoDecoderJob();
905 EXPECT_EQ(0, demuxer_->num_seek_requests()); 948 EXPECT_EQ(0, demuxer_->num_seek_requests());
906 949
907 // Send the first input chunk. 950 // Send the first input chunk.
908 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 951 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
909 952
910 // While the decoder is decoding, change multiple surfaces. Pass an empty 953 // While the decoder is decoding, change multiple surfaces. Pass an empty
911 // surface first. 954 // surface first.
912 gfx::ScopedJavaSurface empty_surface; 955 gfx::ScopedJavaSurface empty_surface;
913 player_.SetVideoSurface(empty_surface.Pass()); 956 player_.SetVideoSurface(empty_surface.Pass());
914 // Next, pass a new non-empty surface. 957 // Next, pass a new non-empty surface.
915 CreateNextTextureAndSetVideoSurface(); 958 CreateNextTextureAndSetVideoSurface();
916 959
917 // Wait for the decoder job to finish decoding and be reset pending a browser 960 // Wait for the media codec bridge to finish decoding and be reset pending a
918 // seek. 961 // browser seek.
919 WaitForVideoDecodeDone(); 962 WaitForVideoDecodeDone();
920 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 963 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
921 964
922 // Only one browser seek should have been initiated. No further data request 965 // Only one browser seek should have been initiated. No further data request
923 // should have been processed on |message_loop_| before surface change event 966 // should have been processed on |message_loop_| before surface change event
924 // became pending, above. 967 // became pending, above.
925 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 968 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
926 EXPECT_EQ(2, demuxer_->num_data_requests()); 969 EXPECT_EQ(2, demuxer_->num_data_requests());
927 970
928 // Simulate browser seek is done and confirm player requests more data for new 971 // Simulate browser seek is done and confirm player requests more data for new
929 // video decoder job. 972 // video codec.
930 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 973 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
931 EXPECT_TRUE(GetMediaDecoderJob(false)); 974 EXPECT_FALSE(GetMediaCodecBridge(false));
932 EXPECT_EQ(3, demuxer_->num_data_requests()); 975 EXPECT_EQ(3, demuxer_->num_data_requests());
933 EXPECT_EQ(1, demuxer_->num_seek_requests()); 976 EXPECT_EQ(1, demuxer_->num_seek_requests());
977
978 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
979 EXPECT_TRUE(GetMediaCodecBridge(false));
934 } 980 }
935 981
936 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { 982 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) {
937 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 983 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
938 984
939 // Test player pauses if an empty surface is passed. 985 // Test player pauses if an empty surface is passed.
940 CreateNextTextureAndSetVideoSurface(); 986 CreateNextTextureAndSetVideoSurface();
941 StartVideoDecoderJob(); 987 StartVideoDecoderJob();
942 EXPECT_EQ(1, demuxer_->num_data_requests()); 988 EXPECT_EQ(1, demuxer_->num_data_requests());
943 989
944 // Send the first input chunk. 990 // Send the first input chunk.
945 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 991 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
946 992
947 // While the decoder is decoding, pass an empty surface. 993 // While the decoder is decoding, pass an empty surface.
948 gfx::ScopedJavaSurface empty_surface; 994 gfx::ScopedJavaSurface empty_surface;
949 player_.SetVideoSurface(empty_surface.Pass()); 995 player_.SetVideoSurface(empty_surface.Pass());
950 // Let the player starve. However, it should not issue any new data request in 996 // Let the player starve. However, it should not issue any new data request in
951 // this case. 997 // this case.
952 TriggerPlayerStarvation(); 998 TriggerPlayerStarvation();
953 // Wait for the decoder job to finish decoding and be reset. 999 // Wait for the media codec bridge to finish decoding and be reset.
954 while (GetMediaDecoderJob(false)) 1000 while (GetMediaDecoderJob(false)->is_decoding())
955 message_loop_.RunUntilIdle(); 1001 message_loop_.RunUntilIdle();
956 1002
957 // No further seek or data requests should have been received since the 1003 // No further seek or data requests should have been received since the
958 // surface is empty. 1004 // surface is empty.
959 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1005 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
960 EXPECT_EQ(2, demuxer_->num_data_requests()); 1006 EXPECT_EQ(2, demuxer_->num_data_requests());
961 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1007 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
962 1008
963 // Playback resumes once a non-empty surface is passed. 1009 // Playback resumes once a non-empty surface is passed.
964 CreateNextTextureAndSetVideoSurface(); 1010 CreateNextTextureAndSetVideoSurface();
965 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1011 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
966 } 1012 }
967 1013
968 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 1014 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1015 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
970 1016
971 // Test that if video decoder is released while decoding, the resources will 1017 // Test that if video decoder is released while decoding, the resources will
972 // not be immediately released. 1018 // not be immediately released.
973 CreateNextTextureAndSetVideoSurface(); 1019 CreateNextTextureAndSetVideoSurface();
974 StartVideoDecoderJob(); 1020 StartVideoDecoderJob();
975 EXPECT_EQ(1, manager_.num_resources_requested()); 1021 // No resource is requested since there is no data to decode.
1022 EXPECT_EQ(0, manager_.num_resources_requested());
976 ReleasePlayer(); 1023 ReleasePlayer();
977 // The resources will be immediately released since the decoder is idle. 1024 EXPECT_EQ(0, manager_.num_resources_released());
978 EXPECT_EQ(1, manager_.num_resources_released());
979 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1025 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
980 1026
981 // Recreate the video decoder. 1027 // Recreate the video decoder.
982 CreateNextTextureAndSetVideoSurface(); 1028 CreateNextTextureAndSetVideoSurface();
983 player_.Start(); 1029 player_.Start();
984 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1030 while (!GetMediaDecoderJob(false)->is_decoding())
985 player_.OnDemuxerSeekDone(base::TimeDelta()); 1031 message_loop_.RunUntilIdle();
986 EXPECT_EQ(2, manager_.num_resources_requested()); 1032 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
987 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1033 EXPECT_EQ(1, manager_.num_resources_requested());
988 ReleasePlayer(); 1034 ReleasePlayer();
989 // The resource is still held by the video decoder until it finishes decoding. 1035 // The resource is still held by the video decoder until it finishes decoding.
990 EXPECT_EQ(1, manager_.num_resources_released()); 1036 EXPECT_EQ(0, manager_.num_resources_released());
991 // Wait for the decoder job to finish decoding and be reset. 1037 // Wait for the media codec bridge to finish decoding and be reset.
992 while (manager_.num_resources_released() != 2) 1038 while (manager_.num_resources_released() != 1)
993 message_loop_.RunUntilIdle(); 1039 message_loop_.RunUntilIdle();
994 } 1040 }
995 1041
996 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 1042 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
997 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1043 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
998 1044
999 // Test audio decoder job will not start until pending seek event is handled. 1045 // Test audio decoder job will not start until pending seek event is handled.
1000 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 1046 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
1001 player_.OnDemuxerConfigsAvailable(configs); 1047 player_.OnDemuxerConfigsAvailable(configs);
1002 EXPECT_FALSE(GetMediaDecoderJob(true));
1003 1048
1004 // Initiate a seek. Skip requesting element seek of renderer. 1049 // Initiate a seek. Skip requesting element seek of renderer.
1005 // Instead behave as if the renderer has asked us to seek. 1050 // Instead behave as if the renderer has asked us to seek.
1006 player_.SeekTo(base::TimeDelta()); 1051 player_.SeekTo(base::TimeDelta());
1007 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1052 EXPECT_EQ(1, demuxer_->num_seek_requests());
1008 1053
1009 player_.Start(); 1054 player_.Start();
1010 EXPECT_FALSE(GetMediaDecoderJob(true));
1011 EXPECT_EQ(0, demuxer_->num_data_requests()); 1055 EXPECT_EQ(0, demuxer_->num_data_requests());
1012 1056
1013 // Sending back the seek done notification. 1057 // Sending back the seek done notification.
1014 player_.OnDemuxerSeekDone(kNoTimestamp()); 1058 player_.OnDemuxerSeekDone(kNoTimestamp());
1015 EXPECT_TRUE(GetMediaDecoderJob(true)); 1059 EXPECT_FALSE(GetMediaCodecBridge(true));
1016 EXPECT_EQ(1, demuxer_->num_data_requests()); 1060 EXPECT_EQ(1, demuxer_->num_data_requests());
1017 1061
1018 // Reconfirm exactly 1 seek request has been made of demuxer. 1062 // Reconfirm exactly 1 seek request has been made of demuxer.
1019 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1063 EXPECT_EQ(1, demuxer_->num_seek_requests());
1064
1065 // Decoder is created after data is received.
1066 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1067 EXPECT_TRUE(GetMediaCodecBridge(true));
1020 } 1068 }
1021 1069
1022 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { 1070 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) {
1023 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1071 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1024 1072
1025 // Test video decoder job will not start until pending seek event is handled. 1073 // Test video decoder job will not start until pending seek event is handled.
1026 CreateNextTextureAndSetVideoSurface(); 1074 CreateNextTextureAndSetVideoSurface();
1027 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 1075 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8);
1028 player_.OnDemuxerConfigsAvailable(configs); 1076 player_.OnDemuxerConfigsAvailable(configs);
1029 EXPECT_FALSE(GetMediaDecoderJob(false));
1030 1077
1031 // Initiate a seek. Skip requesting element seek of renderer. 1078 // Initiate a seek. Skip requesting element seek of renderer.
1032 // Instead behave as if the renderer has asked us to seek. 1079 // Instead behave as if the renderer has asked us to seek.
1033 player_.SeekTo(base::TimeDelta()); 1080 player_.SeekTo(base::TimeDelta());
1034 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1081 EXPECT_EQ(1, demuxer_->num_seek_requests());
1035 1082
1036 player_.Start(); 1083 player_.Start();
1037 EXPECT_FALSE(GetMediaDecoderJob(false));
1038 EXPECT_EQ(0, demuxer_->num_data_requests()); 1084 EXPECT_EQ(0, demuxer_->num_data_requests());
1039 1085
1040 // Sending back the seek done notification. 1086 // Sending back the seek done notification.
1041 player_.OnDemuxerSeekDone(kNoTimestamp()); 1087 player_.OnDemuxerSeekDone(kNoTimestamp());
1042 EXPECT_TRUE(GetMediaDecoderJob(false)); 1088 EXPECT_FALSE(GetMediaCodecBridge(false));
1043 EXPECT_EQ(1, demuxer_->num_data_requests()); 1089 EXPECT_EQ(1, demuxer_->num_data_requests());
1044 1090
1045 // Reconfirm exactly 1 seek request has been made of demuxer. 1091 // Reconfirm exactly 1 seek request has been made of demuxer.
1046 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1092 EXPECT_EQ(1, demuxer_->num_seek_requests());
1093
1094 // Decoder is created after data is received.
1095 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1096 EXPECT_TRUE(GetMediaCodecBridge(false));
1047 } 1097 }
1048 1098
1049 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 1099 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
1050 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1100 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1051 1101
1052 // Test that if the decoding job is not fully stopped after Pause(), 1102 // Test that if the decoding job is not fully stopped after Pause(),
1053 // calling Start() will be a noop. 1103 // calling Start() will be a noop.
1054 StartAudioDecoderJob(); 1104 StartAudioDecoderJob();
1055 1105
1056 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1106 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1057 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 1107 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
1058 1108
1059 // Sending data to player. 1109 // Sending data to player.
1060 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1110 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1061 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1111 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1062 EXPECT_EQ(2, demuxer_->num_data_requests()); 1112 EXPECT_EQ(2, demuxer_->num_data_requests());
1063 1113
1064 // Decoder job will not immediately stop after Pause() since it is 1114 // Decoder job will not immediately stop after Pause() since it is
1065 // running on another thread. 1115 // running on another thread.
1066 player_.Pause(true); 1116 player_.Pause(true);
1067 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1117 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1068 1118
1069 // Nothing happens when calling Start() again. 1119 // Nothing happens when calling Start() again.
1070 player_.Start(); 1120 player_.Start();
1071 // Verify that Start() will not destroy and recreate the decoder job. 1121 // Verify that Start() will not destroy and recreate the media codec bridge.
1072 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1122 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1073 1123
1074 while (GetMediaDecoderJob(true)->is_decoding()) 1124 while (GetMediaDecoderJob(true)->is_decoding())
1075 message_loop_.RunUntilIdle(); 1125 message_loop_.RunUntilIdle();
1076 // The decoder job should finish and wait for data. 1126 // The decoder job should finish and wait for data.
1077 EXPECT_EQ(2, demuxer_->num_data_requests()); 1127 EXPECT_EQ(2, demuxer_->num_data_requests());
1078 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data()); 1128 EXPECT_TRUE(IsRequestingDemuxerData(true));
1079 } 1129 }
1080 1130
1081 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 1131 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
1082 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1132 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1083 1133
1084 // Test that when Start() is called, video decoder jobs will wait for audio 1134 // Test that when Start() is called, video decoder job will wait for audio
1085 // decoder job before start decoding the data. 1135 // decoder job before start decoding the data.
1086 CreateNextTextureAndSetVideoSurface(); 1136 CreateNextTextureAndSetVideoSurface();
1087 Start(CreateAudioVideoDemuxerConfigs()); 1137 Start(CreateAudioVideoDemuxerConfigs());
1088 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 1138 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
1089 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false); 1139 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false);
1090 1140
1091 EXPECT_FALSE(audio_decoder_job->is_decoding()); 1141 EXPECT_FALSE(audio_decoder_job->is_decoding());
1092 EXPECT_FALSE(video_decoder_job->is_decoding()); 1142 EXPECT_FALSE(video_decoder_job->is_decoding());
1093 1143
1094 // Sending video data to player, video decoder should not start. 1144 // Sending video data to player, video decoder should not start.
(...skipping 17 matching lines...) Expand all
1112 1162
1113 DecodeAudioDataUntilOutputBecomesAvailable(); 1163 DecodeAudioDataUntilOutputBecomesAvailable();
1114 1164
1115 // The decoder job should finish and a new request will be sent. 1165 // The decoder job should finish and a new request will be sent.
1116 base::TimeTicks previous = StartTimeTicks(); 1166 base::TimeTicks previous = StartTimeTicks();
1117 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1167 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1118 1168
1119 // Let the decoder starve. 1169 // Let the decoder starve.
1120 TriggerPlayerStarvation(); 1170 TriggerPlayerStarvation();
1121 WaitForAudioDecodeDone(); 1171 WaitForAudioDecodeDone();
1122 1172 EXPECT_TRUE(StartTimeTicks() == previous);
1123 // Verify the start time ticks is cleared at this point because the
1124 // player is prefetching.
1125 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
1126 1173
1127 // Send new data to the decoder so it can finish prefetching. This should 1174 // Send new data to the decoder so it can finish prefetching. This should
1128 // reset the start time ticks. 1175 // reset the start time ticks.
1129 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1176 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1130 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1177 EXPECT_TRUE(StartTimeTicks() != previous);
1131 1178
1132 base::TimeTicks current = StartTimeTicks(); 1179 base::TimeTicks current = StartTimeTicks();
1133 EXPECT_LE(0, (current - previous).InMillisecondsF()); 1180 EXPECT_LE(0, (current - previous).InMillisecondsF());
1134 } 1181 }
1135 1182
1136 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { 1183 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
1137 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1184 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1138 1185
1139 // Test MediaSourcePlayer can replay video after input EOS is reached. 1186 // Test MediaSourcePlayer can replay video after input EOS is reached.
1140 CreateNextTextureAndSetVideoSurface(); 1187 CreateNextTextureAndSetVideoSurface();
1141 StartVideoDecoderJob(); 1188 StartVideoDecoderJob();
1142 1189
1143 // Send the first input chunk. 1190 // Send the first input chunk.
1144 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1191 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1145 WaitForVideoDecodeDone(); 1192 WaitForVideoDecodeDone();
1146 1193
1147 VerifyPlaybackCompletesOnEOSDecode(true, false); 1194 VerifyPlaybackCompletesOnEOSDecode(true, false);
1148 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); 1195 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1149 } 1196 }
1150 1197
1151 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { 1198 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1199 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1153 1200
1154 // Test decode of audio EOS buffer without any prior decode. See also 1201 // Test decode of audio EOS buffer without any prior decode. See also
1155 // http://b/11696552. 1202 // http://b/11696552.
1156 // Also tests that seeking+Start() after completing audio playback resumes 1203 // Also tests that seeking+Start() after completing audio playback resumes
1157 // playback. 1204 // playback.
1158 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1205 Start(CreateAudioDemuxerConfigs(kCodecAAC, false));
1159 VerifyPlaybackCompletesOnEOSDecode(true, true); 1206 VerifyPlaybackCompletesOnEOSDecode(true, true);
1160 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false); 1207 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false);
1161 } 1208 }
1162 1209
1163 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) { 1210 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) {
1164 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1211 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1165 1212
1166 // Test decode of video EOS buffer, just after seeking, without any prior 1213 // Test decode of video EOS buffer, just after seeking, without any prior
1167 // decode (other than the simulated |kAborted| resulting from the seek 1214 // decode (other than the simulated |kAborted| resulting from the seek
1168 // process.) 1215 // process.)
1169 CreateNextTextureAndSetVideoSurface(); 1216 CreateNextTextureAndSetVideoSurface();
1170 StartVideoDecoderJob(); 1217 StartVideoDecoderJob();
1171 SeekPlayerWithAbort(false, base::TimeDelta()); 1218 SeekPlayerWithAbort(false, base::TimeDelta());
1172 VerifyPlaybackCompletesOnEOSDecode(true, false); 1219 VerifyPlaybackCompletesOnEOSDecode(true, false);
1173 } 1220 }
1174 1221
1175 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) { 1222 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) {
1176 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1223 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1177 1224
1178 // Test decode of audio EOS buffer, just after seeking, without any prior 1225 // Test decode of audio EOS buffer, just after seeking, without any prior
1179 // decode (other than the simulated |kAborted| resulting from the seek 1226 // decode (other than the simulated |kAborted| resulting from the seek
1180 // process.) See also http://b/11696552. 1227 // process.) See also http://b/11696552.
1181 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1228 Start(CreateAudioDemuxerConfigs(kCodecAAC, false));
1182 SeekPlayerWithAbort(true, base::TimeDelta()); 1229 SeekPlayerWithAbort(true, base::TimeDelta());
1183 VerifyPlaybackCompletesOnEOSDecode(true, true); 1230 VerifyPlaybackCompletesOnEOSDecode(true, true);
1184 } 1231 }
1185 1232
1186 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) { 1233 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) {
1187 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1234 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1188 1235
1189 // Test that if one stream (audio) has completed decode of EOS and the other 1236 // Test that if one stream (audio) has completed decode of EOS and the other
1190 // stream (video) processes config change, that subsequent video EOS completes 1237 // stream (video) processes config change, that subsequent video EOS completes
1191 // A/V playback. 1238 // A/V playback.
1192 // Also tests that seeking+Start() after completing playback resumes playback. 1239 // Also tests that seeking+Start() after completing playback resumes playback.
1193 CreateNextTextureAndSetVideoSurface(); 1240 CreateNextTextureAndSetVideoSurface();
1194 Start(CreateAudioVideoDemuxerConfigs()); 1241 Start(CreateAudioVideoDemuxerConfigs());
1195 1242
1196 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1243 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1244 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP9);
1197 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1245 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1198 false, 0)); // Video |kConfigChanged| as first unit. 1246 false, 0, configs)); // Video |kConfigChanged| as first unit.
1199 1247
1200 WaitForAudioVideoDecodeDone(); 1248 WaitForAudioVideoDecodeDone();
1201 1249
1202 EXPECT_EQ(3, demuxer_->num_data_requests()); 1250 EXPECT_EQ(3, demuxer_->num_data_requests());
1203 1251
1204 // At no time after completing audio EOS decode, above, should the 1252 // At no time after completing audio EOS decode, above, should the
1205 // audio decoder job resume decoding. Send and decode video EOS. 1253 // audio decoder job resume decoding. Send and decode video EOS.
1206 VerifyPlaybackCompletesOnEOSDecode(true, false); 1254 VerifyPlaybackCompletesOnEOSDecode(true, false);
1207 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1255 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1208 } 1256 }
1209 1257
1210 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { 1258 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1211 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1259 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1212 1260
1213 // Test that if one stream (video) has completed decode of EOS and the other 1261 // Test that if one stream (video) has completed decode of EOS and the other
1214 // stream (audio) processes config change, that subsequent audio EOS completes 1262 // stream (audio) processes config change, that subsequent audio EOS completes
1215 // A/V playback. 1263 // A/V playback.
1216 // Also tests that seeking+Start() after completing playback resumes playback. 1264 // Also tests that seeking+Start() after completing playback resumes playback.
1217 CreateNextTextureAndSetVideoSurface(); 1265 CreateNextTextureAndSetVideoSurface();
1218 Start(CreateAudioVideoDemuxerConfigs()); 1266 Start(CreateAudioVideoDemuxerConfigs());
1219 1267
1220 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1268 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1269 // Audio |kConfigChanged| as first unit.
1221 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1270 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1222 true, 0)); // Audio |kConfigChanged| as first unit. 1271 true, 0, CreateAudioDemuxerConfigs(kCodecVorbis, false)));
1223 1272
1224 WaitForAudioVideoDecodeDone(); 1273 WaitForAudioVideoDecodeDone();
1225 1274
1226 EXPECT_EQ(3, demuxer_->num_data_requests()); 1275 EXPECT_EQ(3, demuxer_->num_data_requests());
1227 1276
1228 // At no time after completing video EOS decode, above, should the 1277 // At no time after completing video EOS decode, above, should the
1229 // video decoder job resume decoding. Send and decode audio EOS. 1278 // video decoder job resume decoding. Send and decode audio EOS.
1230 VerifyPlaybackCompletesOnEOSDecode(true, true); 1279 VerifyPlaybackCompletesOnEOSDecode(true, true);
1231 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1280 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1232 } 1281 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { 1414 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) {
1366 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1415 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1367 1416
1368 // Test that the decoder should not crash if demuxer data arrives after 1417 // Test that the decoder should not crash if demuxer data arrives after
1369 // Release(). 1418 // Release().
1370 StartAudioDecoderJob(); 1419 StartAudioDecoderJob();
1371 1420
1372 ReleasePlayer(); 1421 ReleasePlayer();
1373 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1422 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1374 1423
1375 // The decoder job should have been released. 1424 // The media codec bridge should have been released.
1376 EXPECT_FALSE(player_.IsPlaying()); 1425 EXPECT_FALSE(player_.IsPlaying());
1377 1426
1378 // No further data should have been requested. 1427 // No further data should have been requested.
1379 EXPECT_EQ(1, demuxer_->num_data_requests()); 1428 EXPECT_EQ(1, demuxer_->num_data_requests());
1380 1429
1381 // No seek requests should have occurred. 1430 // No seek requests should have occurred.
1382 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1431 EXPECT_EQ(0, demuxer_->num_seek_requests());
1383 } 1432 }
1384 1433
1385 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { 1434 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) {
1386 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1435 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1387 1436
1388 // Test that a browser seek, once started, delays a newly arrived regular 1437 // Test that a browser seek, once started, delays a newly arrived regular
1389 // SeekTo() request's demuxer seek until the browser seek is done. 1438 // SeekTo() request's demuxer seek until the browser seek is done.
1390 BrowserSeekPlayer(false); 1439 BrowserSeekPlayer(false);
1391 1440
1392 // Simulate renderer requesting a regular seek while browser seek in progress. 1441 // Simulate renderer requesting a regular seek while browser seek in progress.
1393 player_.SeekTo(base::TimeDelta()); 1442 player_.SeekTo(base::TimeDelta());
1394 EXPECT_FALSE(GetMediaDecoderJob(false));
1395 1443
1396 // Simulate browser seek is done. Confirm player requests the regular seek, 1444 // Simulate browser seek is done. Confirm player requests the regular seek,
1397 // still has no video decoder job configured, and has not requested any 1445 // still has no video codec configured, and has not requested any
1398 // further data since the surface change event became pending in 1446 // further data since the surface change event became pending in
1399 // BrowserSeekPlayer(). 1447 // BrowserSeekPlayer().
1400 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1448 EXPECT_EQ(1, demuxer_->num_seek_requests());
1401 player_.OnDemuxerSeekDone(base::TimeDelta()); 1449 player_.OnDemuxerSeekDone(base::TimeDelta());
1402 EXPECT_FALSE(GetMediaDecoderJob(false));
1403 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1450 EXPECT_EQ(2, demuxer_->num_seek_requests());
1404 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1451 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1405 1452
1406 // Simulate regular seek is done and confirm player requests more data for 1453 // Simulate regular seek is done and confirm player requests more data for
1407 // new video decoder job. 1454 // new video codec.
1408 player_.OnDemuxerSeekDone(kNoTimestamp()); 1455 player_.OnDemuxerSeekDone(kNoTimestamp());
1409 EXPECT_TRUE(GetMediaDecoderJob(false)); 1456 EXPECT_FALSE(GetMediaCodecBridge(false));
1410 EXPECT_EQ(3, demuxer_->num_data_requests()); 1457 EXPECT_EQ(3, demuxer_->num_data_requests());
1411 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1458 EXPECT_EQ(2, demuxer_->num_seek_requests());
1459 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1460 EXPECT_TRUE(GetMediaCodecBridge(false));
1412 } 1461 }
1413 1462
1414 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { 1463 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) {
1415 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1464 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1416 1465
1417 // Test that browser seek is requested if player Release() + Start() occurs 1466 // Test that no browser seek is requested if player Release() + Start() occurs
1418 // prior to receiving any data. 1467 // prior to receiving any data.
1419 CreateNextTextureAndSetVideoSurface(); 1468 CreateNextTextureAndSetVideoSurface();
1420 StartVideoDecoderJob(); 1469 StartVideoDecoderJob();
1421 ReleasePlayer(); 1470 ReleasePlayer();
1422 1471
1423 // Pass a new non-empty surface. 1472 // Pass a new non-empty surface.
1424 CreateNextTextureAndSetVideoSurface(); 1473 CreateNextTextureAndSetVideoSurface();
1425 1474
1426 player_.Start(); 1475 player_.Start();
1427 1476
1428 // The new player won't be created until the pending data request is 1477 // No data request is issued since there is still one pending.
1429 // processed.
1430 EXPECT_EQ(1, demuxer_->num_data_requests()); 1478 EXPECT_EQ(1, demuxer_->num_data_requests());
1431 EXPECT_FALSE(GetMediaDecoderJob(false)); 1479 EXPECT_FALSE(GetMediaCodecBridge(false));
1432 1480
1433 // A browser seek should be requested. 1481 // No browser seek is needed.
1434 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1482 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1435 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1483 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1436 EXPECT_EQ(1, demuxer_->num_data_requests()); 1484 EXPECT_EQ(2, demuxer_->num_data_requests());
1437 } 1485 }
1438 1486
1439 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1487 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1488 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1441 1489
1442 // Test that one browser seek is requested if player Release() + Start(), with 1490 // Test that one browser seek is requested if player Release() + Start(), with
1443 // video data received between Release() and Start(). 1491 // video data received between Release() and Start().
1444 BrowserSeekPlayer(true); 1492 BrowserSeekPlayer(true);
1445 1493
1446 // Simulate browser seek is done and confirm player requests more data. 1494 // Simulate browser seek is done and confirm player requests more data.
1447 player_.OnDemuxerSeekDone(base::TimeDelta()); 1495 player_.OnDemuxerSeekDone(base::TimeDelta());
1448 EXPECT_TRUE(GetMediaDecoderJob(false)); 1496 EXPECT_EQ(3, demuxer_->num_data_requests());
1449 EXPECT_EQ(2, demuxer_->num_data_requests());
1450 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1497 EXPECT_EQ(1, demuxer_->num_seek_requests());
1451 } 1498 }
1452 1499
1453 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1500 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1454 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1501 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1455 1502
1456 // Test decoder job will preroll the media to the seek position. 1503 // Test decoder job will preroll the media to the seek position.
1457 StartAudioDecoderJob(); 1504 StartAudioDecoderJob();
1458 1505
1459 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1506 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); 1546 DemuxerData data = CreateReadFromDemuxerAckForAudio(i);
1500 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( 1547 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(
1501 500 + 30 * (i - 1)); 1548 500 + 30 * (i - 1));
1502 player_.OnDemuxerDataAvailable(data); 1549 player_.OnDemuxerDataAvailable(data);
1503 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1550 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1504 WaitForAudioDecodeDone(); 1551 WaitForAudioDecodeDone();
1505 } 1552 }
1506 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); 1553 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF());
1507 EXPECT_FALSE(IsPrerolling(true)); 1554 EXPECT_FALSE(IsPrerolling(true));
1508 1555
1509 // Throughout this test, we should have not re-created the decoder job, so 1556 // Throughout this test, we should have not re-created the media codec bridge,
1510 // IsPrerolling() transition from false to true was not due to constructor 1557 // so IsPrerolling() transition from false to true was not due to constructor
1511 // initialization. It was due to BeginPrerolling(). 1558 // initialization. It was due to BeginPrerolling().
1512 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1559 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1513 } 1560 }
1514 1561
1515 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) { 1562 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) {
1516 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1563 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1517 1564
1518 // Test decoder job will resume media prerolling if interrupted by Release() 1565 // Test decoder job will resume media prerolling if interrupted by Release()
1519 // and Start(). 1566 // and Start().
1520 StartAudioDecoderJob(); 1567 StartAudioDecoderJob();
1521 1568
1522 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100); 1569 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100);
1523 SeekPlayerWithAbort(true, target_timestamp); 1570 SeekPlayerWithAbort(true, target_timestamp);
1524 EXPECT_TRUE(IsPrerolling(true)); 1571 EXPECT_TRUE(IsPrerolling(true));
1525 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1572 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1526 1573
1527 // Send some data before the seek position. 1574 // Send some data before the seek position.
1528 // Test uses 'large' number of iterations because decoder job may not get 1575 // Test uses 'large' number of iterations because decoder job may not get
1529 // MEDIA_CODEC_OK output status until after a few dequeue output attempts. 1576 // MEDIA_CODEC_OK output status until after a few dequeue output attempts.
1530 // This allows decoder status to stabilize prior to AU timestamp reaching 1577 // This allows decoder status to stabilize prior to AU timestamp reaching
1531 // the preroll target. 1578 // the preroll target.
1532 DemuxerData data; 1579 DemuxerData data;
1533 for (int i = 0; i < 10; ++i) { 1580 for (int i = 0; i < 10; ++i) {
1534 data = CreateReadFromDemuxerAckForAudio(3); 1581 data = CreateReadFromDemuxerAckForAudio(3);
1535 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10); 1582 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10);
1536 if (i == 1) { 1583 if (i == 1) {
1537 // While still prerolling, Release() and Start() the player. 1584 // While still prerolling, Release() and Start() the player.
1538 // TODO(qinmin): Simulation of multiple in-flight data requests (one from
1539 // before Release(), one from after Start()) is not included here, and
1540 // neither is any data enqueued for later decode if it arrives after
1541 // Release() and before Start(). See http://crbug.com/306314. Assumption
1542 // for this test, to prevent flakiness until the bug is fixed, is the
1543 // first request's data arrives before Start(). Though that data is not
1544 // seen by decoder, this assumption allows preroll continuation
1545 // verification and prevents multiple in-flight data requests.
1546 ReleasePlayer(); 1585 ReleasePlayer();
1547 player_.OnDemuxerDataAvailable(data); 1586 // The decoder is still decoding and will not be immediately released.
1548 WaitForAudioDecodeDone(); 1587 EXPECT_TRUE(GetMediaCodecBridge(true));
1549 EXPECT_FALSE(GetMediaDecoderJob(true)); 1588 Resume(false, false);
1550 Resume(true, false);
1551 } else { 1589 } else {
1552 player_.OnDemuxerDataAvailable(data); 1590 player_.OnDemuxerDataAvailable(data);
1553 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1591 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1554 WaitForAudioDecodeDone(); 1592 WaitForAudioDecodeDone();
1555 } 1593 }
1556 EXPECT_TRUE(IsPrerolling(true)); 1594 EXPECT_TRUE(IsPrerolling(true));
1557 } 1595 }
1558 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1596 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1559 EXPECT_TRUE(IsPrerolling(true)); 1597 EXPECT_TRUE(IsPrerolling(true));
1560 1598
1561 // Send data after the seek position. 1599 // Send data after the seek position.
1562 PrerollDecoderToTime(true, target_timestamp, target_timestamp); 1600 PrerollDecoderToTime(true, target_timestamp, target_timestamp);
1563 } 1601 }
1564 1602
1565 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1603 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1566 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1604 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1567 1605
1568 // Test decoder job will resume media prerolling if interrupted by 1606 // Test decoder job will resume media prerolling if interrupted by
1569 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1607 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1570 StartAudioDecoderJob(); 1608 StartAudioDecoderJob();
1571 1609
1572 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1610 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1573 EXPECT_TRUE(IsPrerolling(true)); 1611 EXPECT_TRUE(IsPrerolling(true));
1574 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1612 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1575 1613
1614 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
1576 1615
1577 // In response to data request, simulate that demuxer signals config change by 1616 // In response to data request, simulate that demuxer signals config change by
1578 // sending an AU with |kConfigChanged|. Player should reconfigure the 1617 // sending an AU with |kConfigChanged|.
1579 // audio decoder job with the supplied configs. 1618 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
1580 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1619 true, 0, configs);
1581 player_.OnDemuxerDataAvailable(data); 1620 player_.OnDemuxerDataAvailable(data);
1582 PrerollDecoderToTime( 1621 PrerollDecoderToTime(
1583 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1622 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1623 }
1624
1625 TEST_F(MediaSourcePlayerTest, PrerollContinuesAfterUnchangedConfigs) {
1626 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1627
1628 // Test decoder job will resume media prerolling if interrupted by a config
1629 // change access unit with unchanged configs.
1630 StartAudioDecoderJob();
1631
1632 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1633 EXPECT_TRUE(IsPrerolling(true));
1634 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1635
1636 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
1637
1638 // In response to data request, simulate that demuxer signals config change by
1639 // sending an AU with |kConfigChanged|.
1640 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
1641 true, 0, configs);
1642 player_.OnDemuxerDataAvailable(data);
1643 PrerollDecoderToTime(
1644 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1584 } 1645 }
1585 1646
1586 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1647 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1587 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1648 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1588 1649
1589 // Test that the player allows simultaneous audio and video config change, 1650 // Test that the player allows simultaneous audio and video config change,
1590 // such as might occur during OnPrefetchDone() if next access unit for both 1651 // such as might occur during OnPrefetchDone() if next access unit for both
1591 // audio and video jobs is |kConfigChanged|. 1652 // audio and video jobs is |kConfigChanged|.
1592 CreateNextTextureAndSetVideoSurface(); 1653 CreateNextTextureAndSetVideoSurface();
1593 Start(CreateAudioVideoDemuxerConfigs()); 1654 Start(CreateAudioVideoDemuxerConfigs());
1594 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1655 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1595 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1656 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1657 EXPECT_TRUE(GetMediaCodecBridge(true));
1658 EXPECT_TRUE(GetMediaCodecBridge(false));
1659 WaitForAudioVideoDecodeDone();
1596 1660
1597 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1661 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1662 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
1598 player_.OnDemuxerDataAvailable( 1663 player_.OnDemuxerDataAvailable(
1599 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1664 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs));
1600 1665
1601 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1666 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1602 player_.OnDemuxerDataAvailable( 1667 player_.OnDemuxerDataAvailable(
1603 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1668 CreateReadFromDemuxerAckWithConfigChanged(
1604 EXPECT_EQ(4, demuxer_->num_data_requests()); 1669 false, 0, CreateVideoDemuxerConfigs(kCodecVP9)));
1670 EXPECT_EQ(6, demuxer_->num_data_requests());
1671 EXPECT_TRUE(IsDrainingDecoder(true));
1672 EXPECT_TRUE(IsDrainingDecoder(false));
1605 1673
1606 // Both jobs should have been reconfigured by now. 1674 // Waiting for decoder to finish draining.
1607 // TODO(qinmin): Fix flaky pointer-based MDJ inequality testing. 1675 while (IsDrainingDecoder(true) || IsDrainingDecoder(false))
1608 // See http://crbug.com/327839. 1676 message_loop_.RunUntilIdle();
1609 EXPECT_NE(first_audio_job, GetMediaDecoderJob(true));
1610 EXPECT_NE(first_video_job, GetMediaDecoderJob(false));
1611 EXPECT_TRUE(GetMediaDecoderJob(true) && GetMediaDecoderJob(false));
1612 } 1677 }
1613 1678
1614 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { 1679 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) {
1615 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1680 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1616 1681
1617 // Test that the player detects need for and requests demuxer configs if 1682 // Test that the player detects need for and requests demuxer configs if
1618 // the |kConfigChanged| unit is the very first unit in the set of units 1683 // the |kConfigChanged| unit is the very first unit in the set of units
1619 // received in OnDemuxerDataAvailable() ostensibly while 1684 // received in OnDemuxerDataAvailable() ostensibly while
1620 // |PREFETCH_DONE_EVENT_PENDING|. 1685 // |PREFETCH_DONE_EVENT_PENDING|.
1621 StartConfigChange(true, true, 0); 1686 StartConfigChange(true, true, 0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) { 1719 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) {
1655 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1720 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1656 1721
1657 // Test decoder job will preroll the media to the actual seek position 1722 // Test decoder job will preroll the media to the actual seek position
1658 // resulting from a browser seek. 1723 // resulting from a browser seek.
1659 BrowserSeekPlayer(false); 1724 BrowserSeekPlayer(false);
1660 1725
1661 // Simulate browser seek is done, but to a later time than was requested. 1726 // Simulate browser seek is done, but to a later time than was requested.
1662 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); 1727 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100);
1663 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); 1728 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100));
1664 EXPECT_TRUE(GetMediaDecoderJob(false)); 1729 // Because next AU is not I-frame, MediaCodecBridge will not be recreated.
1730 EXPECT_FALSE(GetMediaCodecBridge(false));
1665 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1731 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1666 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1732 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1667 EXPECT_EQ(3, demuxer_->num_data_requests()); 1733 EXPECT_EQ(3, demuxer_->num_data_requests());
1668 1734
1669 PrerollDecoderToTime( 1735 PrerollDecoderToTime(
1670 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1736 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1671 } 1737 }
1672 1738
1673 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { 1739 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) {
1674 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1740 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1675 1741
1676 // Test that video config change notification results in creating a new 1742 // Test that video config change notification results in creating a new
1677 // video decoder job results without any browser seek. 1743 // video codec without any browser seek.
1678 StartConfigChange(false, true, 1); 1744 StartConfigChange(false, true, 1);
1679 EXPECT_TRUE(GetMediaDecoderJob(false));
1680 EXPECT_EQ(2, demuxer_->num_data_requests());
1681 EXPECT_EQ(0, demuxer_->num_seek_requests());
1682 }
1683 1745
1684 TEST_F(MediaSourcePlayerTest, NewSurfaceAfterChangingConfigs) { 1746 // New video codec should have been created and configured, without any
1685 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1747 // browser seek.
1686 1748 EXPECT_TRUE(GetMediaCodecBridge(false));
1687 // Test that no seek results from a SetVideoSurface() that occurs after
1688 // the player processes new demuxer configs. This test may be good to keep
1689 // beyond browser seek hack.
1690 StartConfigChange(false, false, 1);
1691 EXPECT_TRUE(GetMediaDecoderJob(false));
1692 EXPECT_EQ(3, demuxer_->num_data_requests());
1693
1694 CreateNextTextureAndSetVideoSurface();
1695 EXPECT_TRUE(GetMediaDecoderJob(false));
1696 EXPECT_EQ(3, demuxer_->num_data_requests()); 1749 EXPECT_EQ(3, demuxer_->num_data_requests());
1697 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1750 EXPECT_EQ(0, demuxer_->num_seek_requests());
1698 } 1751 }
1699 1752
1753 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) {
1754 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1755
1756 // Test if a decoder is being drained while receiving a seek request, draining
1757 // is canceled.
1758 SendConfigChangeToDecoder(true, false, 0);
1759 EXPECT_TRUE(IsDrainingDecoder(true));
1760
1761 player_.SeekTo(base::TimeDelta::FromMilliseconds(100));
1762 WaitForAudioDecodeDone();
1763 EXPECT_FALSE(IsDrainingDecoder(true));
1764 player_.OnDemuxerSeekDone(kNoTimestamp());
1765
1766 EXPECT_EQ(1, demuxer_->num_seek_requests());
1767 EXPECT_EQ(4, demuxer_->num_data_requests());
1768 }
1769
1770 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedByRelease) {
1771 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1772
1773 // Test if a decoder is being drained while receiving a release request,
1774 // draining is canceled.
1775 SendConfigChangeToDecoder(true, false, 0);
1776 EXPECT_TRUE(IsDrainingDecoder(true));
1777
1778 ReleasePlayer();
1779 WaitForAudioDecodeDone();
1780 EXPECT_EQ(3, demuxer_->num_data_requests());
1781 EXPECT_FALSE(IsDrainingDecoder(true));
1782
1783 EXPECT_FALSE(GetMediaCodecBridge(true));
1784 EXPECT_FALSE(player_.IsPlaying());
1785
1786 player_.Start();
1787 EXPECT_TRUE(player_.IsPlaying());
1788 EXPECT_EQ(3, demuxer_->num_data_requests());
1789 }
1790
1791 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySurfaceChange) {
1792 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1793
1794 // Test if a video decoder is being drained while surface changes, draining
1795 // is canceled.
1796 SendConfigChangeToDecoder(false, false, 0);
1797 EXPECT_TRUE(IsDrainingDecoder(false));
1798
1799 CreateNextTextureAndSetVideoSurface();
1800 WaitForVideoDecodeDone();
1801
1802 EXPECT_FALSE(IsDrainingDecoder(false));
1803 EXPECT_FALSE(GetMediaCodecBridge(false));
1804 EXPECT_TRUE(player_.IsPlaying());
1805 EXPECT_EQ(3, demuxer_->num_data_requests());
1806
1807 // Finish the browser seek introduced by surface change.
1808 player_.OnDemuxerSeekDone(base::TimeDelta());
1809 EXPECT_EQ(4, demuxer_->num_data_requests());
1810 }
1811
1700 TEST_F(MediaSourcePlayerTest, 1812 TEST_F(MediaSourcePlayerTest,
1701 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { 1813 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) {
1702 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1814 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1703 1815
1704 // Test video decoder starvation while handling a pending surface change 1816 // Test video decoder starvation while handling a pending surface change
1705 // should not cause any crashes. 1817 // should not cause any crashes.
1706 CreateNextTextureAndSetVideoSurface(); 1818 CreateNextTextureAndSetVideoSurface();
1707 StartVideoDecoderJob(); 1819 StartVideoDecoderJob();
1708 DemuxerData data = CreateReadFromDemuxerAckForVideo(); 1820 DemuxerData data = CreateReadFromDemuxerAckForVideo();
1709 player_.OnDemuxerDataAvailable(data); 1821 player_.OnDemuxerDataAvailable(data);
1710 1822
1711 // Trigger a surface change and decoder starvation. 1823 // Trigger a surface change and decoder starvation.
1712 CreateNextTextureAndSetVideoSurface(); 1824 CreateNextTextureAndSetVideoSurface();
1713 TriggerPlayerStarvation(); 1825 TriggerPlayerStarvation();
1714 WaitForVideoDecodeDone(); 1826 WaitForVideoDecodeDone();
1715 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1827 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1716 1828
1717 // Surface change should trigger a seek. 1829 // Surface change should trigger a seek.
1718 player_.OnDemuxerDataAvailable(data); 1830 player_.OnDemuxerDataAvailable(data);
1719 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1831 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1720 player_.OnDemuxerSeekDone(base::TimeDelta()); 1832 player_.OnDemuxerSeekDone(base::TimeDelta());
1721 EXPECT_TRUE(GetMediaDecoderJob(false)); 1833 // After seek is done, prefetch is handled first. MediaCodecBridge is not
1834 // created at this moment.
1835 EXPECT_FALSE(GetMediaCodecBridge(false));
1722 1836
1723 // A new data request should be sent. 1837 // A new data request should be sent.
1724 EXPECT_EQ(3, demuxer_->num_data_requests()); 1838 EXPECT_EQ(3, demuxer_->num_data_requests());
1725 } 1839 }
1726 1840
1727 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1841 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1728 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1842 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1729 1843
1730 // Test if OnPrefetchDone() had already been posted before and is executed 1844 // Test if OnPrefetchDone() had already been posted before and is executed
1731 // after Release(), then player does not DCHECK. This test is fragile to 1845 // after Release(), then player does not DCHECK. This test is fragile to
1732 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1846 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1733 // is posted to run |prefetch_cb| if the job already HasData(). 1847 // is posted to run |prefetch_cb| if the job already HasData().
1734 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1848 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1735 // becomes obsolete. See http://crbug.com/304234. 1849 // becomes obsolete. See http://crbug.com/304234.
1736 StartAudioDecoderJob(); 1850 StartAudioDecoderJob();
1737 1851
1738 // Escape the original prefetch by decoding a single access unit. 1852 // Escape the original prefetch by decoding a single access unit.
1739 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1853 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1740 WaitForAudioDecodeDone(); 1854 WaitForAudioDecodeDone();
1741 1855
1742 // Prime the job with a few more access units, so that a later prefetch, 1856 // Prime the job with a few more access units, so that a later prefetch,
1743 // triggered by starvation to simulate decoder underrun, can trivially 1857 // triggered by starvation to simulate decoder underrun, can trivially
1744 // post task to run OnPrefetchDone(). 1858 // post task to run OnPrefetchDone().
1745 player_.OnDemuxerDataAvailable( 1859 player_.OnDemuxerDataAvailable(
1746 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1860 CreateReadFromDemuxerAckWithConfigChanged(
1861 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis, false)));
1747 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1862 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1748 1863
1749 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1864 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1750 // The prefetch and posting of OnPrefetchDone() will not occur until next 1865 // The prefetch and posting of OnPrefetchDone() will not occur until next
1751 // MediaDecoderCallBack() occurs. 1866 // MediaDecoderCallBack() occurs.
1752 TriggerPlayerStarvation(); 1867 TriggerPlayerStarvation();
1753 1868
1754 // Upon the next successful decode callback, post a task to call Release() on 1869 // Upon the next successful decode callback, post a task to call Release() on
1755 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1870 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1756 // occurs and should execute after the Release(). 1871 // occurs and should execute after the Release().
1757 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1872 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1758 1873
1759 WaitForAudioDecodeDone(); 1874 WaitForAudioDecodeDone();
1760 EXPECT_TRUE(decoder_callback_hook_executed_); 1875 EXPECT_TRUE(decoder_callback_hook_executed_);
1761 EXPECT_EQ(2, demuxer_->num_data_requests());
1762 1876
1763 // Player should have no decoder job until after Start(). 1877 EXPECT_EQ(3, demuxer_->num_data_requests());
1764 Resume(true, false); 1878
1879 // Player should not request any new data since the access units haven't
1880 // been fully decoded yet.
1881 Resume(false, false);
1765 } 1882 }
1766 1883
1767 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1884 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1768 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1885 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1769 1886
1770 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1887 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1771 // has not yet been sent, then the seek request is sent after Release(). Also, 1888 // has not yet been sent, then the seek request is sent after Release(). Also,
1772 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player 1889 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1773 // will resume correct post-seek preroll upon Start(). 1890 // will resume correct post-seek preroll upon Start().
1774 StartAudioDecoderJobAndSeekToWhileDecoding( 1891 StartAudioDecoderJobAndSeekToWhileDecoding(
1775 base::TimeDelta::FromMilliseconds(100)); 1892 base::TimeDelta::FromMilliseconds(100));
1776 ReleasePlayer(); 1893 ReleasePlayer();
1894 EXPECT_EQ(0, demuxer_->num_seek_requests());
1895 WaitForAudioDecodeDone();
1777 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1896 EXPECT_EQ(1, demuxer_->num_seek_requests());
1778 1897
1779 player_.OnDemuxerSeekDone(kNoTimestamp()); 1898 player_.OnDemuxerSeekDone(kNoTimestamp());
1780 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1899 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1781 EXPECT_FALSE(GetMediaDecoderJob(true)); 1900 EXPECT_FALSE(GetMediaCodecBridge(true));
1782 EXPECT_FALSE(player_.IsPlaying()); 1901 EXPECT_FALSE(player_.IsPlaying());
1783 1902
1784 // Player should begin prefetch and resume preroll upon Start(). 1903 // Player should begin prefetch and resume preroll upon Start().
1785 EXPECT_EQ(2, demuxer_->num_data_requests()); 1904 EXPECT_EQ(2, demuxer_->num_data_requests());
1786 Resume(true, false); 1905 Resume(true, false);
1787 EXPECT_TRUE(IsPrerolling(true)); 1906 EXPECT_TRUE(IsPrerolling(true));
1788 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1907 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1789 1908
1790 // No further seek should have been requested since Release(), above. 1909 // No further seek should have been requested since Release(), above.
1791 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1910 EXPECT_EQ(1, demuxer_->num_seek_requests());
1792 } 1911 }
1793 1912
1794 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1913 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1914 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1796 1915
1797 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1916 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request
1798 // has not yet been sent, then the seek request is sent after Release(). Also, 1917 // has not yet been sent, then the seek request is sent after Release(). Also,
1799 // test if OnDemuxerSeekDone() does not occur until after the next Start(), 1918 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1800 // then the player remains pending seek done until (and resumes correct 1919 // then the player remains pending seek done until (and resumes correct
1801 // post-seek preroll after) OnDemuxerSeekDone(). 1920 // post-seek preroll after) OnDemuxerSeekDone().
1802 StartAudioDecoderJobAndSeekToWhileDecoding( 1921 StartAudioDecoderJobAndSeekToWhileDecoding(
1803 base::TimeDelta::FromMilliseconds(100)); 1922 base::TimeDelta::FromMilliseconds(100));
1804 ReleasePlayer(); 1923 ReleasePlayer();
1805 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1924 EXPECT_EQ(0, demuxer_->num_seek_requests());
1806 1925
1807 // Player should not prefetch upon Start() nor create the decoder job, due to 1926 // Player should not prefetch upon Start() nor create the media codec bridge,
1808 // awaiting DemuxerSeekDone. 1927 // due to awaiting DemuxerSeekDone.
1809 EXPECT_EQ(2, demuxer_->num_data_requests()); 1928 EXPECT_EQ(2, demuxer_->num_data_requests());
1810 Resume(false, false); 1929 Resume(false, false);
1811 1930
1931 WaitForAudioDecodeDone();
1932 EXPECT_EQ(1, demuxer_->num_seek_requests());
1812 player_.OnDemuxerSeekDone(kNoTimestamp()); 1933 player_.OnDemuxerSeekDone(kNoTimestamp());
1813 EXPECT_TRUE(GetMediaDecoderJob(true)); 1934 EXPECT_TRUE(GetMediaDecoderJob(true));
1814 EXPECT_TRUE(IsPrerolling(true)); 1935 EXPECT_TRUE(IsPrerolling(true));
1815 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1936 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1816 EXPECT_EQ(3, demuxer_->num_data_requests()); 1937 EXPECT_EQ(3, demuxer_->num_data_requests());
1817 1938
1818 // No further seek should have been requested since Release(), above. 1939 // No further seek should have been requested since Release(), above.
1819 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1940 EXPECT_EQ(1, demuxer_->num_seek_requests());
1820 } 1941 }
1821 1942
1822 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1943 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1823 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1944 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1824 1945
1825 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1946 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1826 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1947 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1827 // player will resume correct post-seek preroll upon Start(). 1948 // player will resume correct post-seek preroll upon Start().
1828 StartAudioDecoderJobAndSeekToWhileDecoding( 1949 StartAudioDecoderJobAndSeekToWhileDecoding(
1829 base::TimeDelta::FromMilliseconds(100)); 1950 base::TimeDelta::FromMilliseconds(100));
1830 WaitForAudioDecodeDone(); 1951 WaitForAudioDecodeDone();
1831 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1952 EXPECT_EQ(1, demuxer_->num_seek_requests());
1832 1953
1833 ReleasePlayer(); 1954 ReleasePlayer();
1834 player_.OnDemuxerSeekDone(kNoTimestamp()); 1955 player_.OnDemuxerSeekDone(kNoTimestamp());
1835 EXPECT_FALSE(player_.IsPlaying()); 1956 EXPECT_FALSE(player_.IsPlaying());
1836 EXPECT_FALSE(GetMediaDecoderJob(true)); 1957 EXPECT_FALSE(GetMediaCodecBridge(true));
1837 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1958 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1838 1959
1839 // Player should begin prefetch and resume preroll upon Start(). 1960 // Player should begin prefetch and resume preroll upon Start().
1840 EXPECT_EQ(2, demuxer_->num_data_requests()); 1961 EXPECT_EQ(2, demuxer_->num_data_requests());
1841 Resume(true, false); 1962 Resume(true, false);
1842 EXPECT_TRUE(IsPrerolling(true)); 1963 EXPECT_TRUE(IsPrerolling(true));
1843 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1964 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1844 1965
1845 // No further seek should have been requested since before Release(), above. 1966 // No further seek should have been requested since before Release(), above.
1846 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1967 EXPECT_EQ(1, demuxer_->num_seek_requests());
1847 } 1968 }
1848 1969
1849 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1970 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1850 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1971 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1851 1972
1852 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1973 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1853 // request and OnDemuxerSeekDone() does not occur until after the next 1974 // request and OnDemuxerSeekDone() does not occur until after the next
1854 // Start(), then the player remains pending seek done until (and resumes 1975 // Start(), then the player remains pending seek done until (and resumes
1855 // correct post-seek preroll after) OnDemuxerSeekDone(). 1976 // correct post-seek preroll after) OnDemuxerSeekDone().
1856 StartAudioDecoderJobAndSeekToWhileDecoding( 1977 StartAudioDecoderJobAndSeekToWhileDecoding(
1857 base::TimeDelta::FromMilliseconds(100)); 1978 base::TimeDelta::FromMilliseconds(100));
1858 WaitForAudioDecodeDone(); 1979 WaitForAudioDecodeDone();
1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1980 EXPECT_EQ(1, demuxer_->num_seek_requests());
1860 1981
1861 ReleasePlayer(); 1982 ReleasePlayer();
1862 EXPECT_EQ(2, demuxer_->num_data_requests()); 1983 EXPECT_EQ(2, demuxer_->num_data_requests());
1863 Resume(false, false); 1984 Resume(false, false);
1864 1985
1865 player_.OnDemuxerSeekDone(kNoTimestamp()); 1986 player_.OnDemuxerSeekDone(kNoTimestamp());
1866 EXPECT_TRUE(GetMediaDecoderJob(true)); 1987 EXPECT_FALSE(GetMediaCodecBridge(true));
1867 EXPECT_TRUE(IsPrerolling(true)); 1988 EXPECT_TRUE(IsPrerolling(true));
1868 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1989 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1869 EXPECT_EQ(3, demuxer_->num_data_requests()); 1990 EXPECT_EQ(3, demuxer_->num_data_requests());
1870 1991
1871 // No further seek should have been requested since before Release(), above. 1992 // No further seek should have been requested since before Release(), above.
1872 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1993 EXPECT_EQ(1, demuxer_->num_seek_requests());
1873 } 1994 }
1874 1995
1875 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { 1996 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) {
1876 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1997 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1877 1998
1878 // Test if Release() occurs after |kConfigChanged| detected, and then Start() 1999 // Test if Release() occurs after |kConfigChanged| is processed, new data
1879 // is called, then the player does not issue any new data request since it is 2000 // requested of demuxer, and the requested data arrive before the next
1880 // still waiting for the previous one. 2001 // Start(), then the player starts to decode the new data without any
wolenetz 2014/06/04 21:42:24 nit: un-wrap to next line.
qinmin 2014/06/04 22:34:03 Done.
2002 // seek.
1881 StartConfigChange(true, true, 0); 2003 StartConfigChange(true, true, 0);
1882 ReleasePlayer(); 2004 ReleasePlayer();
1883 2005
1884 EXPECT_FALSE(GetMediaDecoderJob(true)); 2006 EXPECT_TRUE(GetMediaCodecBridge(true));
1885 EXPECT_FALSE(player_.IsPlaying()); 2007 EXPECT_FALSE(player_.IsPlaying());
1886 EXPECT_EQ(2, demuxer_->num_data_requests()); 2008 EXPECT_EQ(3, demuxer_->num_data_requests());
2009 player_.OnDemuxerDataAvailable(
2010 CreateReadFromDemuxerAckWithConfigChanged(
2011 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis, false)));
2012 WaitForAudioDecodeDone();
2013 EXPECT_FALSE(GetMediaCodecBridge(true));
1887 2014
1888 // Player should resume upon Start(). 2015 // Player should resume upon Start(), even without further configs supplied.
1889 Resume(false, false); 2016 player_.Start();
1890 EXPECT_TRUE(GetMediaDecoderJob(true));
1891 EXPECT_TRUE(player_.IsPlaying()); 2017 EXPECT_TRUE(player_.IsPlaying());
1892 EXPECT_EQ(2, demuxer_->num_data_requests()); 2018 EXPECT_EQ(3, demuxer_->num_data_requests());
2019 EXPECT_EQ(0, demuxer_->num_seek_requests());
1893 } 2020 }
1894 2021
1895 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) { 2022 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) {
1896 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2023 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1897 2024
1898 // Test that Release() after a browser seek's DemuxerSeek IPC request has been 2025 // Test that Release() after a browser seek's DemuxerSeek IPC request has been
1899 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs 2026 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs
1900 // before the next Start()+SetVideoSurface(), then the player will resume 2027 // before the next Start()+SetVideoSurface(), then the player will resume
1901 // correct post-seek preroll upon Start()+SetVideoSurface(). 2028 // correct post-seek preroll upon Start()+SetVideoSurface().
1902 BrowserSeekPlayer(false); 2029 BrowserSeekPlayer(false);
1903 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2030 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1904 ReleasePlayer(); 2031 ReleasePlayer();
1905 2032
1906 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2033 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1907 EXPECT_FALSE(player_.IsPlaying()); 2034 EXPECT_FALSE(player_.IsPlaying());
1908 EXPECT_FALSE(GetMediaDecoderJob(false)); 2035 EXPECT_FALSE(GetMediaCodecBridge(false));
1909 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2036 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1910 2037
1911 // Player should begin prefetch and resume preroll upon Start(). 2038 // Player should begin prefetch and resume preroll upon Start().
1912 EXPECT_EQ(2, demuxer_->num_data_requests()); 2039 EXPECT_EQ(2, demuxer_->num_data_requests());
1913 CreateNextTextureAndSetVideoSurface(); 2040 CreateNextTextureAndSetVideoSurface();
1914 Resume(false, true); 2041 Resume(false, true);
1915 EXPECT_TRUE(IsPrerolling(false)); 2042 EXPECT_TRUE(IsPrerolling(false));
1916 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2043 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1917 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2044 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1918 2045
(...skipping 11 matching lines...) Expand all
1930 // after) OnDemuxerSeekDone(). 2057 // after) OnDemuxerSeekDone().
1931 BrowserSeekPlayer(false); 2058 BrowserSeekPlayer(false);
1932 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); 2059 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime();
1933 ReleasePlayer(); 2060 ReleasePlayer();
1934 2061
1935 EXPECT_EQ(2, demuxer_->num_data_requests()); 2062 EXPECT_EQ(2, demuxer_->num_data_requests());
1936 CreateNextTextureAndSetVideoSurface(); 2063 CreateNextTextureAndSetVideoSurface();
1937 Resume(false, false); 2064 Resume(false, false);
1938 2065
1939 player_.OnDemuxerSeekDone(expected_preroll_timestamp); 2066 player_.OnDemuxerSeekDone(expected_preroll_timestamp);
1940 EXPECT_TRUE(GetMediaDecoderJob(false)); 2067 // Prefetch takes place first, and the decoder is not created yet.
2068 EXPECT_FALSE(GetMediaCodecBridge(false));
1941 EXPECT_TRUE(IsPrerolling(false)); 2069 EXPECT_TRUE(IsPrerolling(false));
1942 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); 2070 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp());
1943 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); 2071 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime());
1944 EXPECT_EQ(3, demuxer_->num_data_requests()); 2072 EXPECT_EQ(3, demuxer_->num_data_requests());
1945 2073
1946 // No further seek should have been requested since BrowserSeekPlayer(). 2074 // No further seek should have been requested since BrowserSeekPlayer().
1947 EXPECT_EQ(1, demuxer_->num_seek_requests()); 2075 EXPECT_EQ(1, demuxer_->num_seek_requests());
2076
2077 // Decoder will be created once data is received.
2078 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
2079 while (!GetMediaCodecBridge(false))
2080 message_loop_.RunUntilIdle();
1948 } 2081 }
1949 2082
1950 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to 2083 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to
1951 // also verify that the job is successfully created if SetDrmBridge(), Start() 2084 // also verify that the job is successfully created if SetDrmBridge(), Start()
1952 // and eventually OnMediaCrypto() occur. This would increase test coverage of 2085 // and eventually OnMediaCrypto() occur. This would increase test coverage of
1953 // http://crbug.com/313470 and allow us to remove inspection of internal player 2086 // http://crbug.com/313470 and allow us to remove inspection of internal player
1954 // pending event state. See http://crbug.com/313860. 2087 // pending event state. See http://crbug.com/313860.
1955 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { 2088 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) {
1956 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2089 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1957 2090
1958 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after 2091 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after
1959 // SetVideoSurface() for a player configured for encrypted video, when the 2092 // SetVideoSurface() for a player configured for encrypted video, when the
1960 // player has not yet received media crypto. 2093 // player has not yet received media crypto.
1961 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 2094 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8);
1962 configs.is_video_encrypted = true; 2095 configs.is_video_encrypted = true;
1963 2096
1964 player_.OnDemuxerConfigsAvailable(configs); 2097 player_.OnDemuxerConfigsAvailable(configs);
1965 CreateNextTextureAndSetVideoSurface(); 2098 CreateNextTextureAndSetVideoSurface();
1966 EXPECT_FALSE(IsPendingSurfaceChange()); 2099 EXPECT_FALSE(GetMediaCodecBridge(false));
1967 EXPECT_FALSE(GetMediaDecoderJob(false));
1968 } 2100 }
1969 2101
1970 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { 2102 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) {
1971 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2103 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1972 2104
1973 // Test that current time is updated while decoder is starved. 2105 // Test that current time is updated while decoder is starved.
1974 StartAudioDecoderJob(); 2106 StartAudioDecoderJob();
1975 DecodeAudioDataUntilOutputBecomesAvailable(); 2107 DecodeAudioDataUntilOutputBecomesAvailable();
1976 2108
1977 // Trigger starvation while the decoder is decoding. 2109 // Trigger starvation while the decoder is decoding.
1978 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 2110 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1979 manager_.ResetTimestampUpdated(); 2111 manager_.ResetTimestampUpdated();
1980 TriggerPlayerStarvation(); 2112 TriggerPlayerStarvation();
1981 WaitForAudioDecodeDone(); 2113 WaitForAudioDecodeDone();
1982 2114
1983 // Current time should be updated. 2115 // Current time should be updated.
1984 EXPECT_TRUE(manager_.timestamp_updated()); 2116 EXPECT_TRUE(manager_.timestamp_updated());
1985 } 2117 }
1986 2118
1987 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { 2119 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) {
1988 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 2120 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1989 2121
1990 // Test current time keep on increasing after audio config change. 2122 // Test current time keep on increasing after audio config change.
1991 // Test that current time is updated while decoder is starved. 2123 // Test that current time is updated while decoder is starved.
1992 StartAudioDecoderJob(); 2124 StartAudioDecoderJob();
1993 2125
1994 DecodeAudioDataUntilOutputBecomesAvailable(); 2126 DecodeAudioDataUntilOutputBecomesAvailable();
1995 2127
1996 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 2128 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
2129 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
2130 true, 0, configs);
1997 player_.OnDemuxerDataAvailable(data); 2131 player_.OnDemuxerDataAvailable(data);
1998 WaitForAudioDecodeDone(); 2132 WaitForAudioDecodeDone();
1999 DecodeAudioDataUntilOutputBecomesAvailable(); 2133 DecodeAudioDataUntilOutputBecomesAvailable();
2000 } 2134 }
2001 2135
2002 } // namespace media 2136 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698