File: video_detector.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (122 lines) | stat: -rw-r--r-- 3,792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_VIDEO_DETECTOR_H_
#define ASH_WM_VIDEO_DETECTOR_H_

#include <map>
#include <memory>
#include <set>

#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/shell_observer.h"
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "base/scoped_multi_source_observation.h"
#include "base/timer/timer.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/viz/public/mojom/compositing/video_detector_observer.mojom.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"

namespace ash {

// Receives notifications from viz::VideoDetector about whether it is likely
// that a video is being played on screen. If video activity is detected, this
// class will classify it as full screen or windowed.
class ASH_EXPORT VideoDetector : public aura::EnvObserver,
                                 public aura::WindowObserver,
                                 public SessionObserver,
                                 public ShellObserver,
                                 public viz::mojom::VideoDetectorObserver {
 public:
  // State of detected video activity.
  enum class State {
    // Video activity has been detected recently and there are no fullscreen
    // windows.
    PLAYING_WINDOWED,
    // Video activity has been detected recently and there is at least one
    // fullscreen window.
    PLAYING_FULLSCREEN,
    // Video activity has not been detected recently.
    NOT_PLAYING,
  };

  class Observer {
   public:
    // Invoked when the video playback state has changed.
    virtual void OnVideoStateChanged(VideoDetector::State state) = 0;

   protected:
    virtual ~Observer() {}
  };

  VideoDetector();

  VideoDetector(const VideoDetector&) = delete;
  VideoDetector& operator=(const VideoDetector&) = delete;

  ~VideoDetector() override;

  State state() const { return state_; }

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  // EnvObserver overrides.
  void OnWindowInitialized(aura::Window* window) override;

  // aura::WindowObserver overrides.
  void OnWindowDestroyed(aura::Window* window) override;
  void OnWindowDestroying(aura::Window* window) override;

  // SessionStateController overrides.
  void OnChromeTerminating() override;

  // ShellObserver overrides.
  void OnFullscreenStateChanged(bool is_fullscreen,
                                aura::Window* container) override;

  // viz::mojom::VideoDetectorObserver implementation.
  void OnVideoActivityStarted() override;
  void OnVideoActivityEnded() override;

 private:
  // Updates |state_| and notifies |observers_| if it changed.
  void UpdateState();

  // Connects to Viz and starts observing video activities.
  void EstablishConnectionToViz();

  // Called when connection to Viz is lost. The connection will be
  // re-established after a short delay.
  void OnConnectionError();

  // Current playback state.
  State state_;

  // True if video has been observed in the last |kVideoTimeoutMs|.
  bool video_is_playing_;

  // Currently-fullscreen desks containers windows.
  std::set<aura::Window*> fullscreen_desks_containers_;

  base::ObserverList<Observer>::Unchecked observers_;

  base::ScopedMultiSourceObservation<aura::Window, aura::WindowObserver>
      window_observations_manager_{this};
  ScopedSessionObserver scoped_session_observer_{this};

  bool is_shutting_down_;

  mojo::Receiver<viz::mojom::VideoDetectorObserver> receiver_{this};

  base::WeakPtrFactory<VideoDetector> weak_factory_{this};
};

}  // namespace ash

#endif  // ASH_WM_VIDEO_DETECTOR_H_