Commit c9abf4ae authored by John Delaney's avatar John Delaney Committed by Commit Bot

Buffer bytes received updates from WebMediaPlayer to metrics

Currently reporting bytes to the MediaMetricsProvider is causing a
performance regression due to the frequency of IPCs being sent. Buffer
updates in the media player and send every 500 milliseconds to limit the
number of IPCs sent over the lifetime of the mediaplayer.

Bug: 897145
Change-Id: I7468a750e2a96106aa080559321902cf0636d3c0
Reviewed-on: https://chromium-review.googlesource.com/c/1308761
Commit-Queue: John Delaney <johnidel@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604079}
parent f34a24ea
......@@ -2215,8 +2215,27 @@ void WebMediaPlayerImpl::OnPictureInPictureControlClicked(
}
}
void WebMediaPlayerImpl::SendBytesReceivedUpdate() {
media_metrics_provider_->AddBytesReceived(bytes_received_since_last_update_);
bytes_received_since_last_update_ = 0;
}
void WebMediaPlayerImpl::OnBytesReceived(uint64_t data_length) {
media_metrics_provider_->AddBytesReceived(data_length);
bytes_received_since_last_update_ += data_length;
constexpr base::TimeDelta kBytesReceivedUpdateInterval =
base::TimeDelta::FromMilliseconds(500);
auto current_time = base::TimeTicks::Now();
if (earliest_time_next_bytes_received_update_.is_null() ||
earliest_time_next_bytes_received_update_ <= current_time) {
report_bytes_received_timer_.Stop();
SendBytesReceivedUpdate();
earliest_time_next_bytes_received_update_ =
current_time + kBytesReceivedUpdateInterval;
} else {
report_bytes_received_timer_.Start(
FROM_HERE, kBytesReceivedUpdateInterval, this,
&WebMediaPlayerImpl::SendBytesReceivedUpdate);
}
}
void WebMediaPlayerImpl::ScheduleRestart() {
......
......@@ -608,6 +608,8 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// Switch to SurfaceLayer, either initially or from VideoLayer.
void ActivateSurfaceLayerForVideo();
void SendBytesReceivedUpdate();
blink::WebLocalFrame* const frame_;
// The playback state last reported to |delegate_|, to avoid setting duplicate
......@@ -826,6 +828,16 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// devices we might use MediaPlayerRenderer for non HLS playback.
bool demuxer_found_hls_ = false;
// Bytes received since the last update was sent to |media_metrics_provider_|.
uint64_t bytes_received_since_last_update_ = 0;
// The time that a bytes received update should be sent.
base::TimeTicks earliest_time_next_bytes_received_update_;
// Ensures that all bytes received will eventually be reported, even if
// updates stop being received.
base::OneShotTimer report_bytes_received_timer_;
// Called sometime after the media is suspended in a playing state in
// OnFrameHidden(), causing the state to change to paused.
base::OneShotTimer background_pause_timer_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment