Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/remoting/remote_renderer_impl.h" | 5 #include "media/remoting/remote_renderer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/numerics/safe_math.h" | 16 #include "base/numerics/safe_math.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
| 20 #include "media/base/demuxer_stream_provider.h" | 20 #include "media/base/demuxer_stream_provider.h" |
| 21 #include "media/remoting/remote_demuxer_stream_adapter.h" | 21 #include "media/remoting/remote_demuxer_stream_adapter.h" |
| 22 #include "media/remoting/remoting_renderer_controller.h" | 22 #include "media/remoting/remoting_renderer_controller.h" |
| 23 #include "media/remoting/rpc/proto_enum_utils.h" | 23 #include "media/remoting/rpc/proto_enum_utils.h" |
| 24 #include "media/remoting/rpc/proto_utils.h" | 24 #include "media/remoting/rpc/proto_utils.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // The moving time window to track the media time and statistics updates. | 28 // The moving time window to track the media time and statistics updates. |
| 29 constexpr base::TimeDelta kTrackingWindow = base::TimeDelta::FromSeconds(3); | 29 constexpr base::TimeDelta kTrackingWindow = base::TimeDelta::FromSeconds(5); |
| 30 | 30 |
| 31 // The allowed delay for the remoting playback. When exceeds this limit, the | 31 // The allowed delay for the remoting playback. When exceeds this limit |
| 32 // user experience is likely poor and the controller is notified. | 32 // continuously for |kMaxNumPlaybackDelayed| times, the user experience is |
| 33 // likely poor and the controller is notified. | |
| 33 constexpr base::TimeDelta kMediaPlaybackDelayThreshold = | 34 constexpr base::TimeDelta kMediaPlaybackDelayThreshold = |
| 34 base::TimeDelta::FromMilliseconds(450); | 35 base::TimeDelta::FromMilliseconds(750); |
| 36 constexpr int kMaxNumPlaybackDelayed = 3; | |
|
miu
2017/01/19 22:00:55
How about |kPlaybackDelayCountThreshold|?
xjz
2017/01/19 22:10:04
Done.
| |
| 35 | 37 |
| 36 // The allowed percentage of the number of video frames dropped vs. the number | 38 // The allowed percentage of the number of video frames dropped vs. the number |
| 37 // of the video frames decoded. When exceeds this limit, the user experience is | 39 // of the video frames decoded. When exceeds this limit, the user experience is |
| 38 // likely poor and the controller is notified. | 40 // likely poor and the controller is notified. |
| 39 constexpr int kMaxNumVideoFramesDroppedPercentage = 3; | 41 constexpr int kMaxNumVideoFramesDroppedPercentage = 3; |
| 40 | 42 |
| 41 // The time period to allow receiver get stable after playback rate change or | 43 // The time period to allow receiver get stable after playback rate change or |
| 42 // Flush(). | 44 // Flush(). |
| 43 constexpr base::TimeDelta kStabilizationPeriod = | 45 constexpr base::TimeDelta kStabilizationPeriod = |
| 44 base::TimeDelta::FromSeconds(2); | 46 base::TimeDelta::FromSeconds(2); |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 base::TimeDelta media_duration = | 742 base::TimeDelta media_duration = |
| 741 media_time_queue_.back().second - media_time_queue_.front().second; | 743 media_time_queue_.back().second - media_time_queue_.front().second; |
| 742 base::TimeDelta update_duration = | 744 base::TimeDelta update_duration = |
| 743 (media_time_queue_.back().first - media_time_queue_.front().first) * | 745 (media_time_queue_.back().first - media_time_queue_.front().first) * |
| 744 playback_rate_; | 746 playback_rate_; |
| 745 if ((media_duration - update_duration).magnitude() >= | 747 if ((media_duration - update_duration).magnitude() >= |
| 746 kMediaPlaybackDelayThreshold) { | 748 kMediaPlaybackDelayThreshold) { |
| 747 VLOG(1) << "Irregular playback detected: Media playback delayed." | 749 VLOG(1) << "Irregular playback detected: Media playback delayed." |
| 748 << " media_duration = " << media_duration | 750 << " media_duration = " << media_duration |
| 749 << " update_duration = " << update_duration; | 751 << " update_duration = " << update_duration; |
| 750 OnFatalError(remoting::PACING_TOO_SLOWLY); | 752 ++num_playback_delayed_; |
| 753 if (num_playback_delayed_ == kMaxNumPlaybackDelayed) | |
| 754 OnFatalError(remoting::PACING_TOO_SLOWLY); | |
| 755 } else { | |
| 756 num_playback_delayed_ = 0; | |
| 751 } | 757 } |
| 758 | |
| 752 // Prune |media_time_queue_|. | 759 // Prune |media_time_queue_|. |
| 753 while (media_time_queue_.back().first - media_time_queue_.front().first >= | 760 while (media_time_queue_.back().first - media_time_queue_.front().first >= |
| 754 kTrackingWindow) | 761 kTrackingWindow) |
| 755 media_time_queue_.pop_front(); | 762 media_time_queue_.pop_front(); |
| 756 } | 763 } |
| 757 | 764 |
| 758 void RemoteRendererImpl::UpdateVideoStatsQueue(int video_frames_decoded, | 765 void RemoteRendererImpl::UpdateVideoStatsQueue(int video_frames_decoded, |
| 759 int video_frames_dropped) { | 766 int video_frames_dropped) { |
| 760 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 767 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 761 if (!flush_cb_.is_null()) | 768 if (!flush_cb_.is_null()) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 kDataFlowPollPeriod.InSecondsF()) / | 857 kDataFlowPollPeriod.InSecondsF()) / |
| 851 kBytesPerKilobit; | 858 kBytesPerKilobit; |
| 852 DCHECK_GE(kilobits_per_second, 0); | 859 DCHECK_GE(kilobits_per_second, 0); |
| 853 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; | 860 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; |
| 854 metrics_recorder_.OnVideoRateEstimate( | 861 metrics_recorder_.OnVideoRateEstimate( |
| 855 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); | 862 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); |
| 856 } | 863 } |
| 857 } | 864 } |
| 858 | 865 |
| 859 } // namespace media | 866 } // namespace media |
| OLD | NEW |