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

Unified Diff: content/renderer/pepper/plugin_instance_throttler_impl.cc

Issue 879403002: Plugin Power Saver: Mute throttled plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove hack used for testing. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/pepper/plugin_instance_throttler_impl.h ('k') | content/renderer/pepper/ppb_audio_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper/plugin_instance_throttler_impl.cc
diff --git a/content/renderer/pepper/plugin_instance_throttler_impl.cc b/content/renderer/pepper/plugin_instance_throttler_impl.cc
index 097480dea87200d6842e54595f41b7dbeba911f8..6a48a4d6e01c21a6cae5792dcb84d45955550473 100644
--- a/content/renderer/pepper/plugin_instance_throttler_impl.cc
+++ b/content/renderer/pepper/plugin_instance_throttler_impl.cc
@@ -26,6 +26,11 @@ const double kAcceptableFrameMaximumBoringness = 0.94;
const int kMinimumConsecutiveInterestingFrames = 4;
+// When plugin audio is throttled, the plugin will sometimes stop generating
+// video frames. We use this timeout to prevent waiting forever for a good
+// poster image. Chosen arbitrarily.
+const int kAudioThrottledFrameTimeoutMilliseconds = 500;
+
} // namespace
// static
@@ -53,6 +58,13 @@ PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl(
web_plugin_(nullptr),
consecutive_interesting_frames_(0),
frames_examined_(0),
+ audio_throttled_(false),
+ audio_throttled_frame_timeout_(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(
+ kAudioThrottledFrameTimeoutMilliseconds),
+ this,
+ &PluginInstanceThrottlerImpl::EngageThrottle),
weak_factory_(this) {
}
@@ -101,6 +113,11 @@ blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const {
return web_plugin_;
}
+void PluginInstanceThrottlerImpl::NotifyAudioThrottled() {
+ audio_throttled_ = true;
+ audio_throttled_frame_timeout_.Reset();
+}
+
void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) {
DCHECK(!web_plugin_);
web_plugin_ = web_plugin;
@@ -148,9 +165,14 @@ void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) {
else
consecutive_interesting_frames_ = 0;
+ // Does not make a copy, just takes a reference to the underlying pixel data.
+ last_received_frame_ = *bitmap;
+
+ if (audio_throttled_)
+ audio_throttled_frame_timeout_.Reset();
+
if (frames_examined_ >= kMaximumFramesToExamine ||
consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames) {
- FOR_EACH_OBSERVER(Observer, observer_list_, OnKeyframeExtracted(bitmap));
EngageThrottle();
}
}
@@ -179,6 +201,14 @@ void PluginInstanceThrottlerImpl::EngageThrottle() {
if (state_ != THROTTLER_STATE_AWAITING_KEYFRAME)
return;
+ if (!last_received_frame_.empty()) {
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnKeyframeExtracted(&last_received_frame_));
+
+ // Release our reference to the underlying pixel data.
+ last_received_frame_.reset();
+ }
+
state_ = THROTTLER_STATE_PLUGIN_THROTTLED;
FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
}
« no previous file with comments | « content/renderer/pepper/plugin_instance_throttler_impl.h ('k') | content/renderer/pepper/ppb_audio_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698