diff options
author | isheriff <isheriff@chromium.org> | 2015-12-09 13:41:28 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-09 21:42:22 +0000 |
commit | 70bcae439e4adfdecbc508787d2334a88f7f7984 (patch) | |
tree | cf951778a3c051652de69a61662d32df1fbcccc0 /content/browser/media/capture/window_activity_tracker_aura.cc | |
parent | 25da8bd9c310a47d6be4909598abf49a1033dbeb (diff) | |
download | chromium_src-70bcae439e4adfdecbc508787d2334a88f7f7984.zip chromium_src-70bcae439e4adfdecbc508787d2334a88f7f7984.tar.gz chromium_src-70bcae439e4adfdecbc508787d2334a88f7f7984.tar.bz2 |
cast: Support for low-latency interactive mode
Add support to detect the presence of user interaction
while playing non-animated content and then adapt the
target playout latency accordingly.
We leverage the detection of animation content added for ZeroConfig and switch to a low-latency target playout mode
when there is sufficient user interaction and the content
being played is not detected to be animation content.
The goal is to address clear interactive user cases (slides
presentation etc.,) while keeping the impact on animated content watching experience minimal.
Testing involved switching between static and animated content while interacting and using a UDP proxy to observe the target playout time reduce during interaction with low-frame rate content and observe it go up once the sender observes a drop while playing animated content.
BUG=405339
Review URL: https://codereview.chromium.org/1484403002
Cr-Commit-Position: refs/heads/master@{#364160}
Diffstat (limited to 'content/browser/media/capture/window_activity_tracker_aura.cc')
-rw-r--r-- | content/browser/media/capture/window_activity_tracker_aura.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/content/browser/media/capture/window_activity_tracker_aura.cc b/content/browser/media/capture/window_activity_tracker_aura.cc new file mode 100644 index 0000000..e56e4a3 --- /dev/null +++ b/content/browser/media/capture/window_activity_tracker_aura.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/media/capture/window_activity_tracker_aura.h" + +#include "base/logging.h" +#include "ui/aura/window.h" +#include "ui/aura/window_tree_host.h" +#include "ui/events/event_utils.h" + +namespace content { + +namespace { +// The time period within which a triggered UI event is considered +// currently active. +const int kTimePeriodUiEventMicros = 100000; // 100 ms + +// Minimum number of user interactions before we consider the user to be in +// interactive mode. The goal is to prevent user interactions to launch +// animated content from causing target playout time flip-flop. +const int kMinUserInteractions = 5; +} // namespace + +WindowActivityTrackerAura::WindowActivityTrackerAura(aura::Window* window) + : window_(window), + last_time_ui_event_detected_(base::TimeTicks()), + ui_events_count_(0), + weak_factory_(this) { + if (window_) { + window_->AddObserver(this); + window_->AddPreTargetHandler(this); + } +} + +WindowActivityTrackerAura::~WindowActivityTrackerAura() { + if (window_) { + window_->RemoveObserver(this); + window_->RemovePreTargetHandler(this); + } +} + +base::WeakPtr<WindowActivityTracker> WindowActivityTrackerAura::GetWeakPtr() { + return weak_factory_.GetWeakPtr(); +} + +bool WindowActivityTrackerAura::IsUiInteractionActive() const { + return ui_events_count_ > kMinUserInteractions; +} + +void WindowActivityTrackerAura::Reset() { + ui_events_count_ = 0; + last_time_ui_event_detected_ = base::TimeTicks(); +} + +void WindowActivityTrackerAura::OnEvent(ui::Event* event) { + if (base::TimeTicks::Now() - last_time_ui_event_detected_ > + base::TimeDelta::FromMicroseconds(kTimePeriodUiEventMicros)) { + ui_events_count_++; + } + last_time_ui_event_detected_ = base::TimeTicks::Now(); +} + +void WindowActivityTrackerAura::OnWindowDestroying(aura::Window* window) { + DCHECK_EQ(window_, window); + window_->RemovePreTargetHandler(this); + window_->RemoveObserver(this); + window_ = nullptr; +} + +} // namespace content |