OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
6 #include <climits> | 6 #include <climits> |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <cstdio> | 8 #include <cstdio> |
9 #include <deque> | 9 #include <deque> |
10 #include <map> | 10 #include <map> |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 #endif // OS_LINUX | 417 #endif // OS_LINUX |
418 } | 418 } |
419 ScheduleVideoPlayout(); | 419 ScheduleVideoPlayout(); |
420 CheckAVSync(); | 420 CheckAVSync(); |
421 } | 421 } |
422 | 422 |
423 scoped_refptr<VideoFrame> PopOneVideoFrame(bool is_being_skipped) { | 423 scoped_refptr<VideoFrame> PopOneVideoFrame(bool is_being_skipped) { |
424 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 424 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
425 | 425 |
426 if (is_being_skipped) { | 426 if (is_being_skipped) { |
427 VLOG(1) << "VideoFrame[" << num_video_frames_processed_ << "]: Skipped."; | 427 VLOG(1) << "VideoFrame[" << num_video_frames_processed_ |
| 428 << " (dt=" << (video_playout_queue_.front().first - |
| 429 last_popped_video_playout_time_).InMicroseconds() |
| 430 << " usec)]: Skipped."; |
428 } else { | 431 } else { |
429 VLOG(1) << "VideoFrame[" << num_video_frames_processed_ << "]: Playing " | 432 VLOG(1) << "VideoFrame[" << num_video_frames_processed_ |
| 433 << " (dt=" << (video_playout_queue_.front().first - |
| 434 last_popped_video_playout_time_).InMicroseconds() |
| 435 << " usec)]: Playing " |
430 << (cast_env()->Clock()->NowTicks() - | 436 << (cast_env()->Clock()->NowTicks() - |
431 video_playout_queue_.front().first).InMicroseconds() | 437 video_playout_queue_.front().first).InMicroseconds() |
432 << " usec later than intended."; | 438 << " usec later than intended."; |
433 } | 439 } |
434 | 440 |
| 441 last_popped_video_playout_time_ = video_playout_queue_.front().first; |
435 const scoped_refptr<VideoFrame> ret = video_playout_queue_.front().second; | 442 const scoped_refptr<VideoFrame> ret = video_playout_queue_.front().second; |
436 video_playout_queue_.pop_front(); | 443 video_playout_queue_.pop_front(); |
437 ++num_video_frames_processed_; | 444 ++num_video_frames_processed_; |
438 return ret; | 445 return ret; |
439 } | 446 } |
440 | 447 |
441 scoped_ptr<AudioBus> PopOneAudioFrame(bool was_skipped) { | 448 scoped_ptr<AudioBus> PopOneAudioFrame(bool was_skipped) { |
442 audio_lock_.AssertAcquired(); | 449 audio_lock_.AssertAcquired(); |
443 | 450 |
444 if (was_skipped) { | 451 if (was_skipped) { |
445 VLOG(1) << "AudioFrame[" << num_audio_frames_processed_ << "]: Skipped"; | 452 VLOG(1) << "AudioFrame[" << num_audio_frames_processed_ |
| 453 << " (dt=" << (audio_playout_queue_.front().first - |
| 454 last_popped_audio_playout_time_).InMicroseconds() |
| 455 << " usec)]: Skipped."; |
446 } else { | 456 } else { |
447 VLOG(1) << "AudioFrame[" << num_audio_frames_processed_ << "]: Playing " | 457 VLOG(1) << "AudioFrame[" << num_audio_frames_processed_ |
| 458 << " (dt=" << (audio_playout_queue_.front().first - |
| 459 last_popped_audio_playout_time_).InMicroseconds() |
| 460 << " usec)]: Playing " |
448 << (cast_env()->Clock()->NowTicks() - | 461 << (cast_env()->Clock()->NowTicks() - |
449 audio_playout_queue_.front().first).InMicroseconds() | 462 audio_playout_queue_.front().first).InMicroseconds() |
450 << " usec later than intended."; | 463 << " usec later than intended."; |
451 } | 464 } |
452 | 465 |
| 466 last_popped_audio_playout_time_ = audio_playout_queue_.front().first; |
453 scoped_ptr<AudioBus> ret(audio_playout_queue_.front().second); | 467 scoped_ptr<AudioBus> ret(audio_playout_queue_.front().second); |
454 audio_playout_queue_.pop_front(); | 468 audio_playout_queue_.pop_front(); |
455 ++num_audio_frames_processed_; | 469 ++num_audio_frames_processed_; |
456 return ret.Pass(); | 470 return ret.Pass(); |
457 } | 471 } |
458 | 472 |
459 void CheckAVSync() { | 473 void CheckAVSync() { |
460 if (video_play_times_.size() > 30 && | 474 if (video_play_times_.size() > 30 && |
461 audio_play_times_.size() > 30) { | 475 audio_play_times_.size() > 30) { |
462 size_t num_events = 0; | 476 size_t num_events = 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // Outputs created, started, and destroyed by this NaivePlayer. | 508 // Outputs created, started, and destroyed by this NaivePlayer. |
495 #ifdef OS_LINUX | 509 #ifdef OS_LINUX |
496 test::LinuxOutputWindow render_; | 510 test::LinuxOutputWindow render_; |
497 #endif // OS_LINUX | 511 #endif // OS_LINUX |
498 scoped_ptr<AudioOutputStream> audio_output_stream_; | 512 scoped_ptr<AudioOutputStream> audio_output_stream_; |
499 | 513 |
500 // Video playout queue. | 514 // Video playout queue. |
501 typedef std::pair<base::TimeTicks, scoped_refptr<VideoFrame> > | 515 typedef std::pair<base::TimeTicks, scoped_refptr<VideoFrame> > |
502 VideoQueueEntry; | 516 VideoQueueEntry; |
503 std::deque<VideoQueueEntry> video_playout_queue_; | 517 std::deque<VideoQueueEntry> video_playout_queue_; |
| 518 base::TimeTicks last_popped_video_playout_time_; |
504 int64 num_video_frames_processed_; | 519 int64 num_video_frames_processed_; |
505 | 520 |
506 base::OneShotTimer<NaivePlayer> video_playout_timer_; | 521 base::OneShotTimer<NaivePlayer> video_playout_timer_; |
507 | 522 |
508 // Audio playout queue, synchronized by |audio_lock_|. | 523 // Audio playout queue, synchronized by |audio_lock_|. |
509 base::Lock audio_lock_; | 524 base::Lock audio_lock_; |
510 typedef std::pair<base::TimeTicks, AudioBus*> AudioQueueEntry; | 525 typedef std::pair<base::TimeTicks, AudioBus*> AudioQueueEntry; |
511 std::deque<AudioQueueEntry> audio_playout_queue_; | 526 std::deque<AudioQueueEntry> audio_playout_queue_; |
| 527 base::TimeTicks last_popped_audio_playout_time_; |
512 int64 num_audio_frames_processed_; | 528 int64 num_audio_frames_processed_; |
513 | 529 |
514 // These must only be used on the audio thread calling OnMoreData(). | 530 // These must only be used on the audio thread calling OnMoreData(). |
515 scoped_ptr<AudioBus> currently_playing_audio_frame_; | 531 scoped_ptr<AudioBus> currently_playing_audio_frame_; |
516 int currently_playing_audio_frame_start_; | 532 int currently_playing_audio_frame_start_; |
517 | 533 |
518 std::map<uint16, base::TimeTicks> audio_play_times_; | 534 std::map<uint16, base::TimeTicks> audio_play_times_; |
519 std::map<uint16, base::TimeTicks> video_play_times_; | 535 std::map<uint16, base::TimeTicks> video_play_times_; |
520 int32 last_audio_frame_no_; | 536 int32 last_audio_frame_no_; |
521 }; | 537 }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 audio_config, | 592 audio_config, |
577 video_config, | 593 video_config, |
578 window_width, | 594 window_width, |
579 window_height); | 595 window_height); |
580 player.Start(); | 596 player.Start(); |
581 | 597 |
582 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). | 598 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). |
583 NOTREACHED(); | 599 NOTREACHED(); |
584 return 0; | 600 return 0; |
585 } | 601 } |
OLD | NEW |