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

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: fixing nits 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
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | media/base/android/video_decoder_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 valid configs and data are passed to
839 // the audio decoder job.
794 StartAudioDecoderJob(); 840 StartAudioDecoderJob();
795 EXPECT_EQ(0, demuxer_->num_seek_requests()); 841 EXPECT_EQ(0, demuxer_->num_seek_requests());
842 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
843 EXPECT_TRUE(GetMediaCodecBridge(true));
796 } 844 }
797 845
798 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { 846 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) {
799 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 847 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
800 848
801 // Test audio decoder job will not be created when failed to start the codec. 849 // Test audio decoder job will not be created when failed to start the codec.
802 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 850 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
803 // Replace with invalid |audio_extra_data| 851 // Replace with invalid |audio_extra_data|
804 configs.audio_extra_data.clear(); 852 configs.audio_extra_data.clear();
805 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; 853 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff };
806 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), 854 configs.audio_extra_data.insert(configs.audio_extra_data.begin(),
807 invalid_codec_data, invalid_codec_data + 4); 855 invalid_codec_data, invalid_codec_data + 4);
808 Start(configs); 856 Start(configs);
809 EXPECT_EQ(0, demuxer_->num_seek_requests()); 857
858 // Decoder is not created after data is received.
859 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
860 EXPECT_FALSE(GetMediaCodecBridge(true));
810 } 861 }
811 862
812 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { 863 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) {
813 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 864 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
814 865
815 // Test video decoder job will be created when surface is valid. 866 // 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(); 867 StartVideoDecoderJob();
818 868
819 // Set both an initial and a later video surface without receiving any 869 // Set both an initial and a later video surface without receiving any
820 // demuxed data yet. 870 // demuxed data yet.
821 CreateNextTextureAndSetVideoSurface(); 871 CreateNextTextureAndSetVideoSurface();
822 MediaDecoderJob* first_job = GetMediaDecoderJob(false); 872 EXPECT_FALSE(GetMediaCodecBridge(false));
823 EXPECT_TRUE(first_job);
824 CreateNextTextureAndSetVideoSurface(); 873 CreateNextTextureAndSetVideoSurface();
825 874 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 875
830 // No seeks, even on setting surface, should have occurred. (Browser seeks can 876 // No seeks, even on setting surface, should have occurred. (Browser seeks can
831 // occur on setting surface, but only after previously receiving video data.) 877 // occur on setting surface, but only after previously receiving video data.)
832 EXPECT_EQ(0, demuxer_->num_seek_requests()); 878 EXPECT_EQ(0, demuxer_->num_seek_requests());
833 879
834 // Note, the decoder job for the second surface set, above, will be created 880 // 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 881 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
836 // browser seek is done. See BrowserSeek_* tests for this coverage. 882 EXPECT_TRUE(GetMediaCodecBridge(false));
837 } 883 }
838 884
839 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { 885 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) {
840 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 886 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
841 887
842 // Test video decoder job will not be created when surface is invalid. 888 // Test video codec will not be created when surface is invalid.
843 scoped_refptr<gfx::SurfaceTexture> surface_texture( 889 scoped_refptr<gfx::SurfaceTexture> surface_texture(
844 gfx::SurfaceTexture::Create(0)); 890 gfx::SurfaceTexture::Create(0));
845 gfx::ScopedJavaSurface surface(surface_texture.get()); 891 gfx::ScopedJavaSurface surface(surface_texture.get());
846 StartVideoDecoderJob(); 892 StartVideoDecoderJob();
847 893
848 // Release the surface texture. 894 // Release the surface texture.
849 surface_texture = NULL; 895 surface_texture = NULL;
850 player_.SetVideoSurface(surface.Pass()); 896 player_.SetVideoSurface(surface.Pass());
851 897
852 // Player should not seek the demuxer on setting initial surface. 898 // Player should not seek the demuxer on setting initial surface.
853 EXPECT_EQ(0, demuxer_->num_seek_requests()); 899 EXPECT_EQ(0, demuxer_->num_seek_requests());
900 EXPECT_EQ(1, demuxer_->num_data_requests());
854 901
855 EXPECT_FALSE(GetMediaDecoderJob(false)); 902 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
856 EXPECT_EQ(0, demuxer_->num_data_requests()); 903 EXPECT_FALSE(GetMediaCodecBridge(false));
857 } 904 }
858 905
859 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { 906 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) {
860 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 907 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
861 908
862 // Test decoder job will resend a ReadFromDemuxer request after seek. 909 // Test decoder job will resend a ReadFromDemuxer request after seek.
863 StartAudioDecoderJob(); 910 StartAudioDecoderJob();
864 SeekPlayerWithAbort(true, base::TimeDelta()); 911 SeekPlayerWithAbort(true, base::TimeDelta());
865 } 912 }
866 913
867 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 914 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
868 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 915 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
869 916
870 // Test SetVideoSurface() will not cause an extra seek while the player is 917 // Test SetVideoSurface() will not cause an extra seek while the player is
871 // waiting for demuxer to indicate seek is done. 918 // waiting for demuxer to indicate seek is done.
872 // Player is still waiting for SetVideoSurface(), so no request is sent. 919 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs(kCodecVP8));
873 StartVideoDecoderJob(); // Verifies no data requested.
874 920
875 // Initiate a seek. Skip requesting element seek of renderer. 921 // Initiate a seek. Skip requesting element seek of renderer.
876 // Instead behave as if the renderer has asked us to seek. 922 // Instead behave as if the renderer has asked us to seek.
877 EXPECT_EQ(0, demuxer_->num_seek_requests());
878 player_.SeekTo(base::TimeDelta()); 923 player_.SeekTo(base::TimeDelta());
879 EXPECT_EQ(1, demuxer_->num_seek_requests()); 924 EXPECT_EQ(1, demuxer_->num_seek_requests());
880 925
881 CreateNextTextureAndSetVideoSurface(); 926 CreateNextTextureAndSetVideoSurface();
882 EXPECT_FALSE(GetMediaDecoderJob(false));
883 EXPECT_EQ(1, demuxer_->num_seek_requests()); 927 EXPECT_EQ(1, demuxer_->num_seek_requests());
884 928 player_.Start();
885 // Reconfirm player has not yet requested data.
886 EXPECT_EQ(0, demuxer_->num_data_requests());
887 929
888 // Send the seek done notification. The player should start requesting data. 930 // Send the seek done notification. The player should start requesting data.
889 player_.OnDemuxerSeekDone(kNoTimestamp()); 931 player_.OnDemuxerSeekDone(kNoTimestamp());
890 EXPECT_TRUE(GetMediaDecoderJob(false)); 932 EXPECT_FALSE(GetMediaCodecBridge(false));
891 EXPECT_EQ(1, demuxer_->num_data_requests()); 933 EXPECT_EQ(1, demuxer_->num_data_requests());
934 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
935 EXPECT_TRUE(GetMediaCodecBridge(false));
892 936
893 // Reconfirm exactly 1 seek request has been made of demuxer, and that it 937 // Reconfirm exactly 1 seek request has been made of demuxer, and that it
894 // was not a browser seek request. 938 // was not a browser seek request.
895 EXPECT_EQ(1, demuxer_->num_seek_requests()); 939 EXPECT_EQ(1, demuxer_->num_seek_requests());
896 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 940 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
897 } 941 }
898 942
899 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { 943 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) {
900 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 944 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
901 945
902 // Test MediaSourcePlayer can switch multiple surfaces during decoding. 946 // Test MediaSourcePlayer can switch multiple surfaces during decoding.
903 CreateNextTextureAndSetVideoSurface(); 947 CreateNextTextureAndSetVideoSurface();
904 StartVideoDecoderJob(); 948 StartVideoDecoderJob();
905 EXPECT_EQ(0, demuxer_->num_seek_requests()); 949 EXPECT_EQ(0, demuxer_->num_seek_requests());
906 950
907 // Send the first input chunk. 951 // Send the first input chunk.
908 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 952 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
909 953
910 // While the decoder is decoding, change multiple surfaces. Pass an empty 954 // While the decoder is decoding, change multiple surfaces. Pass an empty
911 // surface first. 955 // surface first.
912 gfx::ScopedJavaSurface empty_surface; 956 gfx::ScopedJavaSurface empty_surface;
913 player_.SetVideoSurface(empty_surface.Pass()); 957 player_.SetVideoSurface(empty_surface.Pass());
914 // Next, pass a new non-empty surface. 958 // Next, pass a new non-empty surface.
915 CreateNextTextureAndSetVideoSurface(); 959 CreateNextTextureAndSetVideoSurface();
916 960
917 // Wait for the decoder job to finish decoding and be reset pending a browser 961 // Wait for the media codec bridge to finish decoding and be reset pending a
918 // seek. 962 // browser seek.
919 WaitForVideoDecodeDone(); 963 WaitForVideoDecodeDone();
920 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 964 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
921 965
922 // Only one browser seek should have been initiated. No further data request 966 // Only one browser seek should have been initiated. No further data request
923 // should have been processed on |message_loop_| before surface change event 967 // should have been processed on |message_loop_| before surface change event
924 // became pending, above. 968 // became pending, above.
925 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 969 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
926 EXPECT_EQ(2, demuxer_->num_data_requests()); 970 EXPECT_EQ(2, demuxer_->num_data_requests());
927 971
928 // Simulate browser seek is done and confirm player requests more data for new 972 // Simulate browser seek is done and confirm player requests more data for new
929 // video decoder job. 973 // video codec.
930 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); 974 player_.OnDemuxerSeekDone(player_.GetCurrentTime());
931 EXPECT_TRUE(GetMediaDecoderJob(false)); 975 EXPECT_FALSE(GetMediaCodecBridge(false));
932 EXPECT_EQ(3, demuxer_->num_data_requests()); 976 EXPECT_EQ(3, demuxer_->num_data_requests());
933 EXPECT_EQ(1, demuxer_->num_seek_requests()); 977 EXPECT_EQ(1, demuxer_->num_seek_requests());
978
979 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
980 EXPECT_TRUE(GetMediaCodecBridge(false));
934 } 981 }
935 982
936 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { 983 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) {
937 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 984 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
938 985
939 // Test player pauses if an empty surface is passed. 986 // Test player pauses if an empty surface is passed.
940 CreateNextTextureAndSetVideoSurface(); 987 CreateNextTextureAndSetVideoSurface();
941 StartVideoDecoderJob(); 988 StartVideoDecoderJob();
942 EXPECT_EQ(1, demuxer_->num_data_requests()); 989 EXPECT_EQ(1, demuxer_->num_data_requests());
943 990
944 // Send the first input chunk. 991 // Send the first input chunk.
945 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 992 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
946 993
947 // While the decoder is decoding, pass an empty surface. 994 // While the decoder is decoding, pass an empty surface.
948 gfx::ScopedJavaSurface empty_surface; 995 gfx::ScopedJavaSurface empty_surface;
949 player_.SetVideoSurface(empty_surface.Pass()); 996 player_.SetVideoSurface(empty_surface.Pass());
950 // Let the player starve. However, it should not issue any new data request in 997 // Let the player starve. However, it should not issue any new data request in
951 // this case. 998 // this case.
952 TriggerPlayerStarvation(); 999 TriggerPlayerStarvation();
953 // Wait for the decoder job to finish decoding and be reset. 1000 // Wait for the media codec bridge to finish decoding and be reset.
954 while (GetMediaDecoderJob(false)) 1001 while (GetMediaDecoderJob(false)->is_decoding())
955 message_loop_.RunUntilIdle(); 1002 message_loop_.RunUntilIdle();
956 1003
957 // No further seek or data requests should have been received since the 1004 // No further seek or data requests should have been received since the
958 // surface is empty. 1005 // surface is empty.
959 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1006 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
960 EXPECT_EQ(2, demuxer_->num_data_requests()); 1007 EXPECT_EQ(2, demuxer_->num_data_requests());
961 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1008 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
962 1009
963 // Playback resumes once a non-empty surface is passed. 1010 // Playback resumes once a non-empty surface is passed.
964 CreateNextTextureAndSetVideoSurface(); 1011 CreateNextTextureAndSetVideoSurface();
965 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1012 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
966 } 1013 }
967 1014
968 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 1015 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1016 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
970 1017
971 // Test that if video decoder is released while decoding, the resources will 1018 // Test that if video decoder is released while decoding, the resources will
972 // not be immediately released. 1019 // not be immediately released.
973 CreateNextTextureAndSetVideoSurface(); 1020 CreateNextTextureAndSetVideoSurface();
974 StartVideoDecoderJob(); 1021 StartVideoDecoderJob();
975 EXPECT_EQ(1, manager_.num_resources_requested()); 1022 // No resource is requested since there is no data to decode.
1023 EXPECT_EQ(0, manager_.num_resources_requested());
976 ReleasePlayer(); 1024 ReleasePlayer();
977 // The resources will be immediately released since the decoder is idle. 1025 EXPECT_EQ(0, manager_.num_resources_released());
978 EXPECT_EQ(1, manager_.num_resources_released());
979 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1026 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
980 1027
981 // Recreate the video decoder. 1028 // Recreate the video decoder.
982 CreateNextTextureAndSetVideoSurface(); 1029 CreateNextTextureAndSetVideoSurface();
983 player_.Start(); 1030 player_.Start();
984 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1031 while (!GetMediaDecoderJob(false)->is_decoding())
985 player_.OnDemuxerSeekDone(base::TimeDelta()); 1032 message_loop_.RunUntilIdle();
986 EXPECT_EQ(2, manager_.num_resources_requested()); 1033 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
987 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1034 EXPECT_EQ(1, manager_.num_resources_requested());
988 ReleasePlayer(); 1035 ReleasePlayer();
989 // The resource is still held by the video decoder until it finishes decoding. 1036 // The resource is still held by the video decoder until it finishes decoding.
990 EXPECT_EQ(1, manager_.num_resources_released()); 1037 EXPECT_EQ(0, manager_.num_resources_released());
991 // Wait for the decoder job to finish decoding and be reset. 1038 // Wait for the media codec bridge to finish decoding and be reset.
992 while (manager_.num_resources_released() != 2) 1039 while (manager_.num_resources_released() != 1)
993 message_loop_.RunUntilIdle(); 1040 message_loop_.RunUntilIdle();
994 } 1041 }
995 1042
996 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 1043 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
997 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1044 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
998 1045
999 // Test audio decoder job will not start until pending seek event is handled. 1046 // Test audio decoder job will not start until pending seek event is handled.
1000 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); 1047 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
1001 player_.OnDemuxerConfigsAvailable(configs); 1048 player_.OnDemuxerConfigsAvailable(configs);
1002 EXPECT_FALSE(GetMediaDecoderJob(true));
1003 1049
1004 // Initiate a seek. Skip requesting element seek of renderer. 1050 // Initiate a seek. Skip requesting element seek of renderer.
1005 // Instead behave as if the renderer has asked us to seek. 1051 // Instead behave as if the renderer has asked us to seek.
1006 player_.SeekTo(base::TimeDelta()); 1052 player_.SeekTo(base::TimeDelta());
1007 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1053 EXPECT_EQ(1, demuxer_->num_seek_requests());
1008 1054
1009 player_.Start(); 1055 player_.Start();
1010 EXPECT_FALSE(GetMediaDecoderJob(true));
1011 EXPECT_EQ(0, demuxer_->num_data_requests()); 1056 EXPECT_EQ(0, demuxer_->num_data_requests());
1012 1057
1013 // Sending back the seek done notification. 1058 // Sending back the seek done notification.
1014 player_.OnDemuxerSeekDone(kNoTimestamp()); 1059 player_.OnDemuxerSeekDone(kNoTimestamp());
1015 EXPECT_TRUE(GetMediaDecoderJob(true)); 1060 EXPECT_FALSE(GetMediaCodecBridge(true));
1016 EXPECT_EQ(1, demuxer_->num_data_requests()); 1061 EXPECT_EQ(1, demuxer_->num_data_requests());
1017 1062
1018 // Reconfirm exactly 1 seek request has been made of demuxer. 1063 // Reconfirm exactly 1 seek request has been made of demuxer.
1019 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1064 EXPECT_EQ(1, demuxer_->num_seek_requests());
1065
1066 // Decoder is created after data is received.
1067 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1068 EXPECT_TRUE(GetMediaCodecBridge(true));
1020 } 1069 }
1021 1070
1022 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { 1071 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) {
1023 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1072 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1024 1073
1025 // Test video decoder job will not start until pending seek event is handled. 1074 // Test video decoder job will not start until pending seek event is handled.
1026 CreateNextTextureAndSetVideoSurface(); 1075 CreateNextTextureAndSetVideoSurface();
1027 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); 1076 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8);
1028 player_.OnDemuxerConfigsAvailable(configs); 1077 player_.OnDemuxerConfigsAvailable(configs);
1029 EXPECT_FALSE(GetMediaDecoderJob(false));
1030 1078
1031 // Initiate a seek. Skip requesting element seek of renderer. 1079 // Initiate a seek. Skip requesting element seek of renderer.
1032 // Instead behave as if the renderer has asked us to seek. 1080 // Instead behave as if the renderer has asked us to seek.
1033 player_.SeekTo(base::TimeDelta()); 1081 player_.SeekTo(base::TimeDelta());
1034 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1082 EXPECT_EQ(1, demuxer_->num_seek_requests());
1035 1083
1036 player_.Start(); 1084 player_.Start();
1037 EXPECT_FALSE(GetMediaDecoderJob(false));
1038 EXPECT_EQ(0, demuxer_->num_data_requests()); 1085 EXPECT_EQ(0, demuxer_->num_data_requests());
1039 1086
1040 // Sending back the seek done notification. 1087 // Sending back the seek done notification.
1041 player_.OnDemuxerSeekDone(kNoTimestamp()); 1088 player_.OnDemuxerSeekDone(kNoTimestamp());
1042 EXPECT_TRUE(GetMediaDecoderJob(false)); 1089 EXPECT_FALSE(GetMediaCodecBridge(false));
1043 EXPECT_EQ(1, demuxer_->num_data_requests()); 1090 EXPECT_EQ(1, demuxer_->num_data_requests());
1044 1091
1045 // Reconfirm exactly 1 seek request has been made of demuxer. 1092 // Reconfirm exactly 1 seek request has been made of demuxer.
1046 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1093 EXPECT_EQ(1, demuxer_->num_seek_requests());
1094
1095 // Decoder is created after data is received.
1096 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1097 EXPECT_TRUE(GetMediaCodecBridge(false));
1047 } 1098 }
1048 1099
1049 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { 1100 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {
1050 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1101 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1051 1102
1052 // Test that if the decoding job is not fully stopped after Pause(), 1103 // Test that if the decoding job is not fully stopped after Pause(),
1053 // calling Start() will be a noop. 1104 // calling Start() will be a noop.
1054 StartAudioDecoderJob(); 1105 StartAudioDecoderJob();
1055 1106
1056 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); 1107 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true);
1057 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 1108 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding());
1058 1109
1059 // Sending data to player. 1110 // Sending data to player.
1060 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1111 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1061 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1112 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1062 EXPECT_EQ(2, demuxer_->num_data_requests()); 1113 EXPECT_EQ(2, demuxer_->num_data_requests());
1063 1114
1064 // Decoder job will not immediately stop after Pause() since it is 1115 // Decoder job will not immediately stop after Pause() since it is
1065 // running on another thread. 1116 // running on another thread.
1066 player_.Pause(true); 1117 player_.Pause(true);
1067 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1118 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1068 1119
1069 // Nothing happens when calling Start() again. 1120 // Nothing happens when calling Start() again.
1070 player_.Start(); 1121 player_.Start();
1071 // Verify that Start() will not destroy and recreate the decoder job. 1122 // Verify that Start() will not destroy and recreate the media codec bridge.
1072 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1123 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1073 1124
1074 while (GetMediaDecoderJob(true)->is_decoding()) 1125 while (GetMediaDecoderJob(true)->is_decoding())
1075 message_loop_.RunUntilIdle(); 1126 message_loop_.RunUntilIdle();
1076 // The decoder job should finish and wait for data. 1127 // The decoder job should finish and wait for data.
1077 EXPECT_EQ(2, demuxer_->num_data_requests()); 1128 EXPECT_EQ(2, demuxer_->num_data_requests());
1078 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data()); 1129 EXPECT_TRUE(IsRequestingDemuxerData(true));
1079 } 1130 }
1080 1131
1081 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { 1132 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) {
1082 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1133 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1083 1134
1084 // Test that when Start() is called, video decoder jobs will wait for audio 1135 // Test that when Start() is called, video decoder job will wait for audio
1085 // decoder job before start decoding the data. 1136 // decoder job before start decoding the data.
1086 CreateNextTextureAndSetVideoSurface(); 1137 CreateNextTextureAndSetVideoSurface();
1087 Start(CreateAudioVideoDemuxerConfigs()); 1138 Start(CreateAudioVideoDemuxerConfigs());
1088 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); 1139 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true);
1089 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false); 1140 MediaDecoderJob* video_decoder_job = GetMediaDecoderJob(false);
1090 1141
1091 EXPECT_FALSE(audio_decoder_job->is_decoding()); 1142 EXPECT_FALSE(audio_decoder_job->is_decoding());
1092 EXPECT_FALSE(video_decoder_job->is_decoding()); 1143 EXPECT_FALSE(video_decoder_job->is_decoding());
1093 1144
1094 // Sending video data to player, video decoder should not start. 1145 // Sending video data to player, video decoder should not start.
(...skipping 17 matching lines...) Expand all
1112 1163
1113 DecodeAudioDataUntilOutputBecomesAvailable(); 1164 DecodeAudioDataUntilOutputBecomesAvailable();
1114 1165
1115 // The decoder job should finish and a new request will be sent. 1166 // The decoder job should finish and a new request will be sent.
1116 base::TimeTicks previous = StartTimeTicks(); 1167 base::TimeTicks previous = StartTimeTicks();
1117 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1168 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1118 1169
1119 // Let the decoder starve. 1170 // Let the decoder starve.
1120 TriggerPlayerStarvation(); 1171 TriggerPlayerStarvation();
1121 WaitForAudioDecodeDone(); 1172 WaitForAudioDecodeDone();
1122 1173 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 1174
1127 // Send new data to the decoder so it can finish prefetching. This should 1175 // Send new data to the decoder so it can finish prefetching. This should
1128 // reset the start time ticks. 1176 // reset the start time ticks.
1129 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); 1177 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3));
1130 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); 1178 EXPECT_TRUE(StartTimeTicks() != previous);
1131 1179
1132 base::TimeTicks current = StartTimeTicks(); 1180 base::TimeTicks current = StartTimeTicks();
1133 EXPECT_LE(0, (current - previous).InMillisecondsF()); 1181 EXPECT_LE(0, (current - previous).InMillisecondsF());
1134 } 1182 }
1135 1183
1136 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { 1184 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) {
1137 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1185 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1138 1186
1139 // Test MediaSourcePlayer can replay video after input EOS is reached. 1187 // Test MediaSourcePlayer can replay video after input EOS is reached.
1140 CreateNextTextureAndSetVideoSurface(); 1188 CreateNextTextureAndSetVideoSurface();
1141 StartVideoDecoderJob(); 1189 StartVideoDecoderJob();
1142 1190
1143 // Send the first input chunk. 1191 // Send the first input chunk.
1144 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1192 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1145 WaitForVideoDecodeDone(); 1193 WaitForVideoDecodeDone();
1146 1194
1147 VerifyPlaybackCompletesOnEOSDecode(true, false); 1195 VerifyPlaybackCompletesOnEOSDecode(true, false);
1148 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true); 1196 VerifyCompletedPlaybackResumesOnSeekPlusStart(false, true);
1149 } 1197 }
1150 1198
1151 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) { 1199 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitIsEOSAndResumePlayAfterSeek) {
1152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1200 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1153 1201
1154 // Test decode of audio EOS buffer without any prior decode. See also 1202 // Test decode of audio EOS buffer without any prior decode. See also
1155 // http://b/11696552. 1203 // http://b/11696552.
1156 // Also tests that seeking+Start() after completing audio playback resumes 1204 // Also tests that seeking+Start() after completing audio playback resumes
1157 // playback. 1205 // playback.
1158 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1206 Start(CreateAudioDemuxerConfigs(kCodecAAC, false));
1159 VerifyPlaybackCompletesOnEOSDecode(true, true); 1207 VerifyPlaybackCompletesOnEOSDecode(true, true);
1160 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false); 1208 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, false);
1161 } 1209 }
1162 1210
1163 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) { 1211 TEST_F(MediaSourcePlayerTest, V_FirstAccessUnitAfterSeekIsEOS) {
1164 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1212 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1165 1213
1166 // Test decode of video EOS buffer, just after seeking, without any prior 1214 // Test decode of video EOS buffer, just after seeking, without any prior
1167 // decode (other than the simulated |kAborted| resulting from the seek 1215 // decode (other than the simulated |kAborted| resulting from the seek
1168 // process.) 1216 // process.)
1169 CreateNextTextureAndSetVideoSurface(); 1217 CreateNextTextureAndSetVideoSurface();
1170 StartVideoDecoderJob(); 1218 StartVideoDecoderJob();
1171 SeekPlayerWithAbort(false, base::TimeDelta()); 1219 SeekPlayerWithAbort(false, base::TimeDelta());
1172 VerifyPlaybackCompletesOnEOSDecode(true, false); 1220 VerifyPlaybackCompletesOnEOSDecode(true, false);
1173 } 1221 }
1174 1222
1175 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) { 1223 TEST_F(MediaSourcePlayerTest, A_FirstAccessUnitAfterSeekIsEOS) {
1176 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1224 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1177 1225
1178 // Test decode of audio EOS buffer, just after seeking, without any prior 1226 // Test decode of audio EOS buffer, just after seeking, without any prior
1179 // decode (other than the simulated |kAborted| resulting from the seek 1227 // decode (other than the simulated |kAborted| resulting from the seek
1180 // process.) See also http://b/11696552. 1228 // process.) See also http://b/11696552.
1181 Start(CreateAudioDemuxerConfigs(kCodecAAC)); 1229 Start(CreateAudioDemuxerConfigs(kCodecAAC, false));
1182 SeekPlayerWithAbort(true, base::TimeDelta()); 1230 SeekPlayerWithAbort(true, base::TimeDelta());
1183 VerifyPlaybackCompletesOnEOSDecode(true, true); 1231 VerifyPlaybackCompletesOnEOSDecode(true, true);
1184 } 1232 }
1185 1233
1186 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) { 1234 TEST_F(MediaSourcePlayerTest, AV_PlaybackCompletionAcrossConfigChange) {
1187 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1235 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1188 1236
1189 // Test that if one stream (audio) has completed decode of EOS and the other 1237 // 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 1238 // stream (video) processes config change, that subsequent video EOS completes
1191 // A/V playback. 1239 // A/V playback.
1192 // Also tests that seeking+Start() after completing playback resumes playback. 1240 // Also tests that seeking+Start() after completing playback resumes playback.
1193 CreateNextTextureAndSetVideoSurface(); 1241 CreateNextTextureAndSetVideoSurface();
1194 Start(CreateAudioVideoDemuxerConfigs()); 1242 Start(CreateAudioVideoDemuxerConfigs());
1195 1243
1196 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS 1244 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS
1245 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP9);
1197 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1246 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1198 false, 0)); // Video |kConfigChanged| as first unit. 1247 false, 0, configs)); // Video |kConfigChanged| as first unit.
1199 1248
1200 WaitForAudioVideoDecodeDone(); 1249 WaitForAudioVideoDecodeDone();
1201 1250
1202 EXPECT_EQ(3, demuxer_->num_data_requests()); 1251 EXPECT_EQ(3, demuxer_->num_data_requests());
1203 1252
1204 // At no time after completing audio EOS decode, above, should the 1253 // At no time after completing audio EOS decode, above, should the
1205 // audio decoder job resume decoding. Send and decode video EOS. 1254 // audio decoder job resume decoding. Send and decode video EOS.
1206 VerifyPlaybackCompletesOnEOSDecode(true, false); 1255 VerifyPlaybackCompletesOnEOSDecode(true, false);
1207 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1256 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1208 } 1257 }
1209 1258
1210 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { 1259 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) {
1211 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1260 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1212 1261
1213 // Test that if one stream (video) has completed decode of EOS and the other 1262 // 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 1263 // stream (audio) processes config change, that subsequent audio EOS completes
1215 // A/V playback. 1264 // A/V playback.
1216 // Also tests that seeking+Start() after completing playback resumes playback. 1265 // Also tests that seeking+Start() after completing playback resumes playback.
1217 CreateNextTextureAndSetVideoSurface(); 1266 CreateNextTextureAndSetVideoSurface();
1218 Start(CreateAudioVideoDemuxerConfigs()); 1267 Start(CreateAudioVideoDemuxerConfigs());
1219 1268
1220 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS 1269 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS
1270 // Audio |kConfigChanged| as first unit.
1221 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( 1271 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged(
1222 true, 0)); // Audio |kConfigChanged| as first unit. 1272 true, 0, CreateAudioDemuxerConfigs(kCodecVorbis, false)));
1223 1273
1224 WaitForAudioVideoDecodeDone(); 1274 WaitForAudioVideoDecodeDone();
1225 1275
1226 EXPECT_EQ(3, demuxer_->num_data_requests()); 1276 EXPECT_EQ(3, demuxer_->num_data_requests());
1227 1277
1228 // At no time after completing video EOS decode, above, should the 1278 // At no time after completing video EOS decode, above, should the
1229 // video decoder job resume decoding. Send and decode audio EOS. 1279 // video decoder job resume decoding. Send and decode audio EOS.
1230 VerifyPlaybackCompletesOnEOSDecode(true, true); 1280 VerifyPlaybackCompletesOnEOSDecode(true, true);
1231 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); 1281 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true);
1232 } 1282 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { 1415 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) {
1366 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1416 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1367 1417
1368 // Test that the decoder should not crash if demuxer data arrives after 1418 // Test that the decoder should not crash if demuxer data arrives after
1369 // Release(). 1419 // Release().
1370 StartAudioDecoderJob(); 1420 StartAudioDecoderJob();
1371 1421
1372 ReleasePlayer(); 1422 ReleasePlayer();
1373 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1423 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1374 1424
1375 // The decoder job should have been released. 1425 // The media codec bridge should have been released.
1376 EXPECT_FALSE(player_.IsPlaying()); 1426 EXPECT_FALSE(player_.IsPlaying());
1377 1427
1378 // No further data should have been requested. 1428 // No further data should have been requested.
1379 EXPECT_EQ(1, demuxer_->num_data_requests()); 1429 EXPECT_EQ(1, demuxer_->num_data_requests());
1380 1430
1381 // No seek requests should have occurred. 1431 // No seek requests should have occurred.
1382 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1432 EXPECT_EQ(0, demuxer_->num_seek_requests());
1383 } 1433 }
1384 1434
1385 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { 1435 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) {
1386 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1436 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1387 1437
1388 // Test that a browser seek, once started, delays a newly arrived regular 1438 // Test that a browser seek, once started, delays a newly arrived regular
1389 // SeekTo() request's demuxer seek until the browser seek is done. 1439 // SeekTo() request's demuxer seek until the browser seek is done.
1390 BrowserSeekPlayer(false); 1440 BrowserSeekPlayer(false);
1391 1441
1392 // Simulate renderer requesting a regular seek while browser seek in progress. 1442 // Simulate renderer requesting a regular seek while browser seek in progress.
1393 player_.SeekTo(base::TimeDelta()); 1443 player_.SeekTo(base::TimeDelta());
1394 EXPECT_FALSE(GetMediaDecoderJob(false));
1395 1444
1396 // Simulate browser seek is done. Confirm player requests the regular seek, 1445 // Simulate browser seek is done. Confirm player requests the regular seek,
1397 // still has no video decoder job configured, and has not requested any 1446 // still has no video codec configured, and has not requested any
1398 // further data since the surface change event became pending in 1447 // further data since the surface change event became pending in
1399 // BrowserSeekPlayer(). 1448 // BrowserSeekPlayer().
1400 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1449 EXPECT_EQ(1, demuxer_->num_seek_requests());
1401 player_.OnDemuxerSeekDone(base::TimeDelta()); 1450 player_.OnDemuxerSeekDone(base::TimeDelta());
1402 EXPECT_FALSE(GetMediaDecoderJob(false));
1403 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1451 EXPECT_EQ(2, demuxer_->num_seek_requests());
1404 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1452 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1405 1453
1406 // Simulate regular seek is done and confirm player requests more data for 1454 // Simulate regular seek is done and confirm player requests more data for
1407 // new video decoder job. 1455 // new video codec.
1408 player_.OnDemuxerSeekDone(kNoTimestamp()); 1456 player_.OnDemuxerSeekDone(kNoTimestamp());
1409 EXPECT_TRUE(GetMediaDecoderJob(false)); 1457 EXPECT_FALSE(GetMediaCodecBridge(false));
1410 EXPECT_EQ(3, demuxer_->num_data_requests()); 1458 EXPECT_EQ(3, demuxer_->num_data_requests());
1411 EXPECT_EQ(2, demuxer_->num_seek_requests()); 1459 EXPECT_EQ(2, demuxer_->num_seek_requests());
1460 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1461 EXPECT_TRUE(GetMediaCodecBridge(false));
1412 } 1462 }
1413 1463
1414 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { 1464 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) {
1415 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1465 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1416 1466
1417 // Test that browser seek is requested if player Release() + Start() occurs 1467 // Test that no browser seek is requested if player Release() + Start() occurs
1418 // prior to receiving any data. 1468 // prior to receiving any data.
1419 CreateNextTextureAndSetVideoSurface(); 1469 CreateNextTextureAndSetVideoSurface();
1420 StartVideoDecoderJob(); 1470 StartVideoDecoderJob();
1421 ReleasePlayer(); 1471 ReleasePlayer();
1422 1472
1423 // Pass a new non-empty surface. 1473 // Pass a new non-empty surface.
1424 CreateNextTextureAndSetVideoSurface(); 1474 CreateNextTextureAndSetVideoSurface();
1425 1475
1426 player_.Start(); 1476 player_.Start();
1427 1477
1428 // The new player won't be created until the pending data request is 1478 // No data request is issued since there is still one pending.
1429 // processed.
1430 EXPECT_EQ(1, demuxer_->num_data_requests()); 1479 EXPECT_EQ(1, demuxer_->num_data_requests());
1431 EXPECT_FALSE(GetMediaDecoderJob(false)); 1480 EXPECT_FALSE(GetMediaCodecBridge(false));
1432 1481
1433 // A browser seek should be requested. 1482 // No browser seek is needed.
1434 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1483 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1435 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1484 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1436 EXPECT_EQ(1, demuxer_->num_data_requests()); 1485 EXPECT_EQ(2, demuxer_->num_data_requests());
1437 } 1486 }
1438 1487
1439 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { 1488 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) {
1440 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1489 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1441 1490
1442 // Test that one browser seek is requested if player Release() + Start(), with 1491 // Test that one browser seek is requested if player Release() + Start(), with
1443 // video data received between Release() and Start(). 1492 // video data received between Release() and Start().
1444 BrowserSeekPlayer(true); 1493 BrowserSeekPlayer(true);
1445 1494
1446 // Simulate browser seek is done and confirm player requests more data. 1495 // Simulate browser seek is done and confirm player requests more data.
1447 player_.OnDemuxerSeekDone(base::TimeDelta()); 1496 player_.OnDemuxerSeekDone(base::TimeDelta());
1448 EXPECT_TRUE(GetMediaDecoderJob(false)); 1497 EXPECT_EQ(3, demuxer_->num_data_requests());
1449 EXPECT_EQ(2, demuxer_->num_data_requests());
1450 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1498 EXPECT_EQ(1, demuxer_->num_seek_requests());
1451 } 1499 }
1452 1500
1453 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { 1501 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) {
1454 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1502 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1455 1503
1456 // Test decoder job will preroll the media to the seek position. 1504 // Test decoder job will preroll the media to the seek position.
1457 StartAudioDecoderJob(); 1505 StartAudioDecoderJob();
1458 1506
1459 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1507 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 DemuxerData data = CreateReadFromDemuxerAckForAudio(i); 1547 DemuxerData data = CreateReadFromDemuxerAckForAudio(i);
1500 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds( 1548 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(
1501 500 + 30 * (i - 1)); 1549 500 + 30 * (i - 1));
1502 player_.OnDemuxerDataAvailable(data); 1550 player_.OnDemuxerDataAvailable(data);
1503 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1551 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1504 WaitForAudioDecodeDone(); 1552 WaitForAudioDecodeDone();
1505 } 1553 }
1506 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF()); 1554 EXPECT_LT(500.0, player_.GetCurrentTime().InMillisecondsF());
1507 EXPECT_FALSE(IsPrerolling(true)); 1555 EXPECT_FALSE(IsPrerolling(true));
1508 1556
1509 // Throughout this test, we should have not re-created the decoder job, so 1557 // 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 1558 // so IsPrerolling() transition from false to true was not due to constructor
1511 // initialization. It was due to BeginPrerolling(). 1559 // initialization. It was due to BeginPrerolling().
1512 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); 1560 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true));
1513 } 1561 }
1514 1562
1515 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) { 1563 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossReleaseAndStart) {
1516 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1564 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1517 1565
1518 // Test decoder job will resume media prerolling if interrupted by Release() 1566 // Test decoder job will resume media prerolling if interrupted by Release()
1519 // and Start(). 1567 // and Start().
1520 StartAudioDecoderJob(); 1568 StartAudioDecoderJob();
1521 1569
1522 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100); 1570 base::TimeDelta target_timestamp = base::TimeDelta::FromMilliseconds(100);
1523 SeekPlayerWithAbort(true, target_timestamp); 1571 SeekPlayerWithAbort(true, target_timestamp);
1524 EXPECT_TRUE(IsPrerolling(true)); 1572 EXPECT_TRUE(IsPrerolling(true));
1525 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1573 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1526 1574
1527 // Send some data before the seek position. 1575 // Send some data before the seek position.
1528 // Test uses 'large' number of iterations because decoder job may not get 1576 // 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. 1577 // MEDIA_CODEC_OK output status until after a few dequeue output attempts.
1530 // This allows decoder status to stabilize prior to AU timestamp reaching 1578 // This allows decoder status to stabilize prior to AU timestamp reaching
1531 // the preroll target. 1579 // the preroll target.
1532 DemuxerData data; 1580 DemuxerData data;
1533 for (int i = 0; i < 10; ++i) { 1581 for (int i = 0; i < 10; ++i) {
1534 data = CreateReadFromDemuxerAckForAudio(3); 1582 data = CreateReadFromDemuxerAckForAudio(3);
1535 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10); 1583 data.access_units[0].timestamp = base::TimeDelta::FromMilliseconds(i * 10);
1536 if (i == 1) { 1584 if (i == 1) {
1537 // While still prerolling, Release() and Start() the player. 1585 // 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(); 1586 ReleasePlayer();
1547 player_.OnDemuxerDataAvailable(data); 1587 // The decoder is still decoding and will not be immediately released.
1548 WaitForAudioDecodeDone(); 1588 EXPECT_TRUE(GetMediaCodecBridge(true));
1549 EXPECT_FALSE(GetMediaDecoderJob(true)); 1589 Resume(false, false);
1550 Resume(true, false);
1551 } else { 1590 } else {
1552 player_.OnDemuxerDataAvailable(data); 1591 player_.OnDemuxerDataAvailable(data);
1553 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1592 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1554 WaitForAudioDecodeDone(); 1593 WaitForAudioDecodeDone();
1555 } 1594 }
1556 EXPECT_TRUE(IsPrerolling(true)); 1595 EXPECT_TRUE(IsPrerolling(true));
1557 } 1596 }
1558 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1597 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1559 EXPECT_TRUE(IsPrerolling(true)); 1598 EXPECT_TRUE(IsPrerolling(true));
1560 1599
1561 // Send data after the seek position. 1600 // Send data after the seek position.
1562 PrerollDecoderToTime(true, target_timestamp, target_timestamp); 1601 PrerollDecoderToTime(true, target_timestamp, target_timestamp);
1563 } 1602 }
1564 1603
1565 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { 1604 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) {
1566 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1605 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1567 1606
1568 // Test decoder job will resume media prerolling if interrupted by 1607 // Test decoder job will resume media prerolling if interrupted by
1569 // |kConfigChanged| and OnDemuxerConfigsAvailable(). 1608 // |kConfigChanged| and OnDemuxerConfigsAvailable().
1570 StartAudioDecoderJob(); 1609 StartAudioDecoderJob();
1571 1610
1572 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); 1611 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1573 EXPECT_TRUE(IsPrerolling(true)); 1612 EXPECT_TRUE(IsPrerolling(true));
1574 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1613 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1575 1614
1615 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
1576 1616
1577 // In response to data request, simulate that demuxer signals config change by 1617 // In response to data request, simulate that demuxer signals config change by
1578 // sending an AU with |kConfigChanged|. Player should reconfigure the 1618 // sending an AU with |kConfigChanged|.
1579 // audio decoder job with the supplied configs. 1619 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
1580 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); 1620 true, 0, configs);
1581 player_.OnDemuxerDataAvailable(data); 1621 player_.OnDemuxerDataAvailable(data);
1582 PrerollDecoderToTime( 1622 PrerollDecoderToTime(
1583 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1623 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1624 }
1625
1626 TEST_F(MediaSourcePlayerTest, PrerollContinuesAfterUnchangedConfigs) {
1627 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1628
1629 // Test decoder job will resume media prerolling if interrupted by a config
1630 // change access unit with unchanged configs.
1631 StartAudioDecoderJob();
1632
1633 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100));
1634 EXPECT_TRUE(IsPrerolling(true));
1635 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1636
1637 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
1638
1639 // In response to data request, simulate that demuxer signals config change by
1640 // sending an AU with |kConfigChanged|.
1641 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
1642 true, 0, configs);
1643 player_.OnDemuxerDataAvailable(data);
1644 PrerollDecoderToTime(
1645 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1584 } 1646 }
1585 1647
1586 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { 1648 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) {
1587 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1649 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1588 1650
1589 // Test that the player allows simultaneous audio and video config change, 1651 // Test that the player allows simultaneous audio and video config change,
1590 // such as might occur during OnPrefetchDone() if next access unit for both 1652 // such as might occur during OnPrefetchDone() if next access unit for both
1591 // audio and video jobs is |kConfigChanged|. 1653 // audio and video jobs is |kConfigChanged|.
1592 CreateNextTextureAndSetVideoSurface(); 1654 CreateNextTextureAndSetVideoSurface();
1593 Start(CreateAudioVideoDemuxerConfigs()); 1655 Start(CreateAudioVideoDemuxerConfigs());
1594 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); 1656 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1595 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); 1657 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1658 EXPECT_TRUE(GetMediaCodecBridge(true));
1659 EXPECT_TRUE(GetMediaCodecBridge(false));
1660 WaitForAudioVideoDecodeDone();
1596 1661
1597 // Simulate audio |kConfigChanged| prefetched as standalone access unit. 1662 // Simulate audio |kConfigChanged| prefetched as standalone access unit.
1663 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
1598 player_.OnDemuxerDataAvailable( 1664 player_.OnDemuxerDataAvailable(
1599 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); 1665 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs));
1600 1666
1601 // Simulate video |kConfigChanged| prefetched as standalone access unit. 1667 // Simulate video |kConfigChanged| prefetched as standalone access unit.
1602 player_.OnDemuxerDataAvailable( 1668 player_.OnDemuxerDataAvailable(
1603 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); 1669 CreateReadFromDemuxerAckWithConfigChanged(
1604 EXPECT_EQ(4, demuxer_->num_data_requests()); 1670 false, 0, CreateVideoDemuxerConfigs(kCodecVP9)));
1671 EXPECT_EQ(6, demuxer_->num_data_requests());
1672 EXPECT_TRUE(IsDrainingDecoder(true));
1673 EXPECT_TRUE(IsDrainingDecoder(false));
1605 1674
1606 // Both jobs should have been reconfigured by now. 1675 // Waiting for decoder to finish draining.
1607 // TODO(qinmin): Fix flaky pointer-based MDJ inequality testing. 1676 while (IsDrainingDecoder(true) || IsDrainingDecoder(false))
1608 // See http://crbug.com/327839. 1677 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 } 1678 }
1613 1679
1614 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { 1680 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) {
1615 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1681 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1616 1682
1617 // Test that the player detects need for and requests demuxer configs if 1683 // 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 1684 // the |kConfigChanged| unit is the very first unit in the set of units
1619 // received in OnDemuxerDataAvailable() ostensibly while 1685 // received in OnDemuxerDataAvailable() ostensibly while
1620 // |PREFETCH_DONE_EVENT_PENDING|. 1686 // |PREFETCH_DONE_EVENT_PENDING|.
1621 StartConfigChange(true, true, 0); 1687 StartConfigChange(true, true, 0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) { 1720 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) {
1655 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1721 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1656 1722
1657 // Test decoder job will preroll the media to the actual seek position 1723 // Test decoder job will preroll the media to the actual seek position
1658 // resulting from a browser seek. 1724 // resulting from a browser seek.
1659 BrowserSeekPlayer(false); 1725 BrowserSeekPlayer(false);
1660 1726
1661 // Simulate browser seek is done, but to a later time than was requested. 1727 // Simulate browser seek is done, but to a later time than was requested.
1662 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); 1728 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100);
1663 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); 1729 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100));
1664 EXPECT_TRUE(GetMediaDecoderJob(false)); 1730 // Because next AU is not I-frame, MediaCodecBridge will not be recreated.
1731 EXPECT_FALSE(GetMediaCodecBridge(false));
1665 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); 1732 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF());
1666 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1733 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1667 EXPECT_EQ(3, demuxer_->num_data_requests()); 1734 EXPECT_EQ(3, demuxer_->num_data_requests());
1668 1735
1669 PrerollDecoderToTime( 1736 PrerollDecoderToTime(
1670 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); 1737 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100));
1671 } 1738 }
1672 1739
1673 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { 1740 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) {
1674 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1741 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1675 1742
1676 // Test that video config change notification results in creating a new 1743 // Test that video config change notification results in creating a new
1677 // video decoder job results without any browser seek. 1744 // video codec without any browser seek.
1678 StartConfigChange(false, true, 1); 1745 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 1746
1684 TEST_F(MediaSourcePlayerTest, NewSurfaceAfterChangingConfigs) { 1747 // New video codec should have been created and configured, without any
1685 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1748 // browser seek.
1686 1749 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()); 1750 EXPECT_EQ(3, demuxer_->num_data_requests());
1697 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1751 EXPECT_EQ(0, demuxer_->num_seek_requests());
1698 } 1752 }
1699 1753
1754 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) {
1755 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1756
1757 // Test if a decoder is being drained while receiving a seek request, draining
1758 // is canceled.
1759 SendConfigChangeToDecoder(true, false, 0);
1760 EXPECT_TRUE(IsDrainingDecoder(true));
1761
1762 player_.SeekTo(base::TimeDelta::FromMilliseconds(100));
1763 WaitForAudioDecodeDone();
1764 EXPECT_FALSE(IsDrainingDecoder(true));
1765 player_.OnDemuxerSeekDone(kNoTimestamp());
1766
1767 EXPECT_EQ(1, demuxer_->num_seek_requests());
1768 EXPECT_EQ(4, demuxer_->num_data_requests());
1769 }
1770
1771 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedByRelease) {
1772 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1773
1774 // Test if a decoder is being drained while receiving a release request,
1775 // draining is canceled.
1776 SendConfigChangeToDecoder(true, false, 0);
1777 EXPECT_TRUE(IsDrainingDecoder(true));
1778
1779 ReleasePlayer();
1780 WaitForAudioDecodeDone();
1781 EXPECT_EQ(3, demuxer_->num_data_requests());
1782 EXPECT_FALSE(IsDrainingDecoder(true));
1783
1784 EXPECT_FALSE(GetMediaCodecBridge(true));
1785 EXPECT_FALSE(player_.IsPlaying());
1786
1787 player_.Start();
1788 EXPECT_TRUE(player_.IsPlaying());
1789 EXPECT_EQ(3, demuxer_->num_data_requests());
1790 }
1791
1792 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySurfaceChange) {
1793 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1794
1795 // Test if a video decoder is being drained while surface changes, draining
1796 // is canceled.
1797 SendConfigChangeToDecoder(false, false, 0);
1798 EXPECT_TRUE(IsDrainingDecoder(false));
1799
1800 CreateNextTextureAndSetVideoSurface();
1801 WaitForVideoDecodeDone();
1802
1803 EXPECT_FALSE(IsDrainingDecoder(false));
1804 EXPECT_FALSE(GetMediaCodecBridge(false));
1805 EXPECT_TRUE(player_.IsPlaying());
1806 EXPECT_EQ(3, demuxer_->num_data_requests());
1807
1808 // Finish the browser seek introduced by surface change.
1809 player_.OnDemuxerSeekDone(base::TimeDelta());
1810 EXPECT_EQ(4, demuxer_->num_data_requests());
1811 }
1812
1700 TEST_F(MediaSourcePlayerTest, 1813 TEST_F(MediaSourcePlayerTest,
1701 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { 1814 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) {
1702 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1815 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1703 1816
1704 // Test video decoder starvation while handling a pending surface change 1817 // Test video decoder starvation while handling a pending surface change
1705 // should not cause any crashes. 1818 // should not cause any crashes.
1706 CreateNextTextureAndSetVideoSurface(); 1819 CreateNextTextureAndSetVideoSurface();
1707 StartVideoDecoderJob(); 1820 StartVideoDecoderJob();
1708 DemuxerData data = CreateReadFromDemuxerAckForVideo(); 1821 DemuxerData data = CreateReadFromDemuxerAckForVideo();
1709 player_.OnDemuxerDataAvailable(data); 1822 player_.OnDemuxerDataAvailable(data);
1710 1823
1711 // Trigger a surface change and decoder starvation. 1824 // Trigger a surface change and decoder starvation.
1712 CreateNextTextureAndSetVideoSurface(); 1825 CreateNextTextureAndSetVideoSurface();
1713 TriggerPlayerStarvation(); 1826 TriggerPlayerStarvation();
1714 WaitForVideoDecodeDone(); 1827 WaitForVideoDecodeDone();
1715 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1828 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1716 1829
1717 // Surface change should trigger a seek. 1830 // Surface change should trigger a seek.
1718 player_.OnDemuxerDataAvailable(data); 1831 player_.OnDemuxerDataAvailable(data);
1719 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); 1832 EXPECT_EQ(1, demuxer_->num_browser_seek_requests());
1720 player_.OnDemuxerSeekDone(base::TimeDelta()); 1833 player_.OnDemuxerSeekDone(base::TimeDelta());
1721 EXPECT_TRUE(GetMediaDecoderJob(false)); 1834 // After seek is done, prefetch is handled first. MediaCodecBridge is not
1835 // created at this moment.
1836 EXPECT_FALSE(GetMediaCodecBridge(false));
1722 1837
1723 // A new data request should be sent. 1838 // A new data request should be sent.
1724 EXPECT_EQ(3, demuxer_->num_data_requests()); 1839 EXPECT_EQ(3, demuxer_->num_data_requests());
1725 } 1840 }
1726 1841
1727 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { 1842 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) {
1728 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1843 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1729 1844
1730 // Test if OnPrefetchDone() had already been posted before and is executed 1845 // Test if OnPrefetchDone() had already been posted before and is executed
1731 // after Release(), then player does not DCHECK. This test is fragile to 1846 // after Release(), then player does not DCHECK. This test is fragile to
1732 // change to MediaDecoderJob::Prefetch() implementation; it assumes task 1847 // change to MediaDecoderJob::Prefetch() implementation; it assumes task
1733 // is posted to run |prefetch_cb| if the job already HasData(). 1848 // is posted to run |prefetch_cb| if the job already HasData().
1734 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test 1849 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test
1735 // becomes obsolete. See http://crbug.com/304234. 1850 // becomes obsolete. See http://crbug.com/304234.
1736 StartAudioDecoderJob(); 1851 StartAudioDecoderJob();
1737 1852
1738 // Escape the original prefetch by decoding a single access unit. 1853 // Escape the original prefetch by decoding a single access unit.
1739 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); 1854 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0));
1740 WaitForAudioDecodeDone(); 1855 WaitForAudioDecodeDone();
1741 1856
1742 // Prime the job with a few more access units, so that a later prefetch, 1857 // Prime the job with a few more access units, so that a later prefetch,
1743 // triggered by starvation to simulate decoder underrun, can trivially 1858 // triggered by starvation to simulate decoder underrun, can trivially
1744 // post task to run OnPrefetchDone(). 1859 // post task to run OnPrefetchDone().
1745 player_.OnDemuxerDataAvailable( 1860 player_.OnDemuxerDataAvailable(
1746 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); 1861 CreateReadFromDemuxerAckWithConfigChanged(
1862 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis, false)));
1747 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 1863 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
1748 1864
1749 // Simulate decoder underrun, so trivial prefetch starts while still decoding. 1865 // Simulate decoder underrun, so trivial prefetch starts while still decoding.
1750 // The prefetch and posting of OnPrefetchDone() will not occur until next 1866 // The prefetch and posting of OnPrefetchDone() will not occur until next
1751 // MediaDecoderCallBack() occurs. 1867 // MediaDecoderCallBack() occurs.
1752 TriggerPlayerStarvation(); 1868 TriggerPlayerStarvation();
1753 1869
1754 // Upon the next successful decode callback, post a task to call Release() on 1870 // Upon the next successful decode callback, post a task to call Release() on
1755 // the |player_|, such that the trivial OnPrefetchDone() task posting also 1871 // the |player_|, such that the trivial OnPrefetchDone() task posting also
1756 // occurs and should execute after the Release(). 1872 // occurs and should execute after the Release().
1757 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); 1873 OnNextTestDecodeCallbackPostTaskToReleasePlayer();
1758 1874
1759 WaitForAudioDecodeDone(); 1875 WaitForAudioDecodeDone();
1760 EXPECT_TRUE(decoder_callback_hook_executed_); 1876 EXPECT_TRUE(decoder_callback_hook_executed_);
1761 EXPECT_EQ(2, demuxer_->num_data_requests());
1762 1877
1763 // Player should have no decoder job until after Start(). 1878 EXPECT_EQ(3, demuxer_->num_data_requests());
1764 Resume(true, false); 1879
1880 // Player should not request any new data since the access units haven't
1881 // been fully decoded yet.
1882 Resume(false, false);
1765 } 1883 }
1766 1884
1767 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { 1885 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) {
1768 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1886 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1769 1887
1770 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1888 // 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, 1889 // 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 1890 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player
1773 // will resume correct post-seek preroll upon Start(). 1891 // will resume correct post-seek preroll upon Start().
1774 StartAudioDecoderJobAndSeekToWhileDecoding( 1892 StartAudioDecoderJobAndSeekToWhileDecoding(
1775 base::TimeDelta::FromMilliseconds(100)); 1893 base::TimeDelta::FromMilliseconds(100));
1776 ReleasePlayer(); 1894 ReleasePlayer();
1895 EXPECT_EQ(0, demuxer_->num_seek_requests());
1896 WaitForAudioDecodeDone();
1777 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1897 EXPECT_EQ(1, demuxer_->num_seek_requests());
1778 1898
1779 player_.OnDemuxerSeekDone(kNoTimestamp()); 1899 player_.OnDemuxerSeekDone(kNoTimestamp());
1780 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1900 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1781 EXPECT_FALSE(GetMediaDecoderJob(true)); 1901 EXPECT_FALSE(GetMediaCodecBridge(true));
1782 EXPECT_FALSE(player_.IsPlaying()); 1902 EXPECT_FALSE(player_.IsPlaying());
1783 1903
1784 // Player should begin prefetch and resume preroll upon Start(). 1904 // Player should begin prefetch and resume preroll upon Start().
1785 EXPECT_EQ(2, demuxer_->num_data_requests()); 1905 EXPECT_EQ(2, demuxer_->num_data_requests());
1786 Resume(true, false); 1906 Resume(true, false);
1787 EXPECT_TRUE(IsPrerolling(true)); 1907 EXPECT_TRUE(IsPrerolling(true));
1788 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1908 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1789 1909
1790 // No further seek should have been requested since Release(), above. 1910 // No further seek should have been requested since Release(), above.
1791 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1911 EXPECT_EQ(1, demuxer_->num_seek_requests());
1792 } 1912 }
1793 1913
1794 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { 1914 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) {
1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1915 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1796 1916
1797 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request 1917 // 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, 1918 // 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(), 1919 // test if OnDemuxerSeekDone() does not occur until after the next Start(),
1800 // then the player remains pending seek done until (and resumes correct 1920 // then the player remains pending seek done until (and resumes correct
1801 // post-seek preroll after) OnDemuxerSeekDone(). 1921 // post-seek preroll after) OnDemuxerSeekDone().
1802 StartAudioDecoderJobAndSeekToWhileDecoding( 1922 StartAudioDecoderJobAndSeekToWhileDecoding(
1803 base::TimeDelta::FromMilliseconds(100)); 1923 base::TimeDelta::FromMilliseconds(100));
1804 ReleasePlayer(); 1924 ReleasePlayer();
1805 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1925 EXPECT_EQ(0, demuxer_->num_seek_requests());
1806 1926
1807 // Player should not prefetch upon Start() nor create the decoder job, due to 1927 // Player should not prefetch upon Start() nor create the media codec bridge,
1808 // awaiting DemuxerSeekDone. 1928 // due to awaiting DemuxerSeekDone.
1809 EXPECT_EQ(2, demuxer_->num_data_requests()); 1929 EXPECT_EQ(2, demuxer_->num_data_requests());
1810 Resume(false, false); 1930 Resume(false, false);
1811 1931
1932 WaitForAudioDecodeDone();
1933 EXPECT_EQ(1, demuxer_->num_seek_requests());
1812 player_.OnDemuxerSeekDone(kNoTimestamp()); 1934 player_.OnDemuxerSeekDone(kNoTimestamp());
1813 EXPECT_TRUE(GetMediaDecoderJob(true)); 1935 EXPECT_TRUE(GetMediaDecoderJob(true));
1814 EXPECT_TRUE(IsPrerolling(true)); 1936 EXPECT_TRUE(IsPrerolling(true));
1815 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1937 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1816 EXPECT_EQ(3, demuxer_->num_data_requests()); 1938 EXPECT_EQ(3, demuxer_->num_data_requests());
1817 1939
1818 // No further seek should have been requested since Release(), above. 1940 // No further seek should have been requested since Release(), above.
1819 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1941 EXPECT_EQ(1, demuxer_->num_seek_requests());
1820 } 1942 }
1821 1943
1822 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { 1944 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) {
1823 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1945 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1824 1946
1825 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC 1947 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC
1826 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the 1948 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the
1827 // player will resume correct post-seek preroll upon Start(). 1949 // player will resume correct post-seek preroll upon Start().
1828 StartAudioDecoderJobAndSeekToWhileDecoding( 1950 StartAudioDecoderJobAndSeekToWhileDecoding(
1829 base::TimeDelta::FromMilliseconds(100)); 1951 base::TimeDelta::FromMilliseconds(100));
1830 WaitForAudioDecodeDone(); 1952 WaitForAudioDecodeDone();
1831 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1953 EXPECT_EQ(1, demuxer_->num_seek_requests());
1832 1954
1833 ReleasePlayer(); 1955 ReleasePlayer();
1834 player_.OnDemuxerSeekDone(kNoTimestamp()); 1956 player_.OnDemuxerSeekDone(kNoTimestamp());
1835 EXPECT_FALSE(player_.IsPlaying()); 1957 EXPECT_FALSE(player_.IsPlaying());
1836 EXPECT_FALSE(GetMediaDecoderJob(true)); 1958 EXPECT_FALSE(GetMediaCodecBridge(true));
1837 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1959 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1838 1960
1839 // Player should begin prefetch and resume preroll upon Start(). 1961 // Player should begin prefetch and resume preroll upon Start().
1840 EXPECT_EQ(2, demuxer_->num_data_requests()); 1962 EXPECT_EQ(2, demuxer_->num_data_requests());
1841 Resume(true, false); 1963 Resume(true, false);
1842 EXPECT_TRUE(IsPrerolling(true)); 1964 EXPECT_TRUE(IsPrerolling(true));
1843 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1965 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1844 1966
1845 // No further seek should have been requested since before Release(), above. 1967 // No further seek should have been requested since before Release(), above.
1846 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1968 EXPECT_EQ(1, demuxer_->num_seek_requests());
1847 } 1969 }
1848 1970
1849 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { 1971 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) {
1850 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1972 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1851 1973
1852 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC 1974 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC
1853 // request and OnDemuxerSeekDone() does not occur until after the next 1975 // request and OnDemuxerSeekDone() does not occur until after the next
1854 // Start(), then the player remains pending seek done until (and resumes 1976 // Start(), then the player remains pending seek done until (and resumes
1855 // correct post-seek preroll after) OnDemuxerSeekDone(). 1977 // correct post-seek preroll after) OnDemuxerSeekDone().
1856 StartAudioDecoderJobAndSeekToWhileDecoding( 1978 StartAudioDecoderJobAndSeekToWhileDecoding(
1857 base::TimeDelta::FromMilliseconds(100)); 1979 base::TimeDelta::FromMilliseconds(100));
1858 WaitForAudioDecodeDone(); 1980 WaitForAudioDecodeDone();
1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1981 EXPECT_EQ(1, demuxer_->num_seek_requests());
1860 1982
1861 ReleasePlayer(); 1983 ReleasePlayer();
1862 EXPECT_EQ(2, demuxer_->num_data_requests()); 1984 EXPECT_EQ(2, demuxer_->num_data_requests());
1863 Resume(false, false); 1985 Resume(false, false);
1864 1986
1865 player_.OnDemuxerSeekDone(kNoTimestamp()); 1987 player_.OnDemuxerSeekDone(kNoTimestamp());
1866 EXPECT_TRUE(GetMediaDecoderJob(true)); 1988 EXPECT_FALSE(GetMediaCodecBridge(true));
1867 EXPECT_TRUE(IsPrerolling(true)); 1989 EXPECT_TRUE(IsPrerolling(true));
1868 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); 1990 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF());
1869 EXPECT_EQ(3, demuxer_->num_data_requests()); 1991 EXPECT_EQ(3, demuxer_->num_data_requests());
1870 1992
1871 // No further seek should have been requested since before Release(), above. 1993 // No further seek should have been requested since before Release(), above.
1872 EXPECT_EQ(1, demuxer_->num_seek_requests()); 1994 EXPECT_EQ(1, demuxer_->num_seek_requests());
1873 } 1995 }
1874 1996
1875 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { 1997 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) {
1876 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1998 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1877 1999
1878 // Test if Release() occurs after |kConfigChanged| detected, and then Start() 2000 // 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 2001 // requested of demuxer, and the requested data arrive before the next
1880 // still waiting for the previous one. 2002 // Start(), then the player starts to decode the new data without any 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
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | media/base/android/video_decoder_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698