File: media_session_controllers_manager.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,260 bytes parent folder | download | duplicates (7)
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
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_CONTROLLERS_MANAGER_H_
#define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_CONTROLLERS_MANAGER_H_

#include <map>
#include <memory>
#include <utility>

#include "base/memory/raw_ptr.h"
#include "content/common/content_export.h"
#include "content/public/browser/web_contents_observer.h"  // For MediaPlayerId.
#include "services/media_session/public/mojom/media_session.mojom.h"

namespace media {
enum class MediaContentType;
}  // namespace media

namespace media_session {
struct MediaPosition;
}  // namespace media_session

namespace content {

class MediaSessionController;
class RenderFrameHost;
class WebContentsImpl;

// MediaSessionControllersManager is a delegate of MediaWebContentsObserver that
// handles MediaSessionController instances.
class CONTENT_EXPORT MediaSessionControllersManager {
 public:
  explicit MediaSessionControllersManager(WebContentsImpl* web_contents);

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

  ~MediaSessionControllersManager();

  // Clear all the MediaSessionController associated with the given
  // |render_frame_host|.
  void RenderFrameDeleted(RenderFrameHost* render_frame_host);

  // Called whenever a player's metadata changes.
  void OnMetadata(const MediaPlayerId& id,
                  bool has_audio,
                  bool has_video,
                  media::MediaContentType media_content_type);

  // Called before a player starts playing. It will be added to the media
  // session and will have a controller associated with it.
  // Returns whether the player was added to the session and can start playing.
  bool RequestPlay(const MediaPlayerId& id);

  // Called when the given player |id| has paused.
  void OnPause(const MediaPlayerId& id, bool reached_end_of_stream);

  // Called when the given player |id| has been destroyed.
  void OnEnd(const MediaPlayerId& id);

  // Called when the media position state for the player |id| has changed.
  void OnMediaPositionStateChanged(
      const MediaPlayerId& id,
      const media_session::MediaPosition& position);

  // Called when entering/leaving Picture-in-Picture for the associated
  // WebContents.
  void PictureInPictureStateChanged(bool is_picture_in_picture);

  // Called when the WebContents was muted or unmuted.
  void WebContentsMutedStateChanged(bool muted);

  // Called when the player's mute status changed.
  void OnMediaMutedStatusChanged(const MediaPlayerId& id, bool mute);

  // Called when picture-in-picture availability for the player |id| has
  // changed.
  void OnPictureInPictureAvailabilityChanged(const MediaPlayerId& id,
                                             bool available);

  // Called when the audio output device for the player |id| has changed.
  void OnAudioOutputSinkChanged(const MediaPlayerId& id,
                                const std::string& raw_device_id);

  // Called when the ability to switch audio output devices for the player |id|
  // has been disabled.
  void OnAudioOutputSinkChangingDisabled(const MediaPlayerId& id);

  // Called when the RemotePlayback metadata has changed.
  void OnRemotePlaybackMetadataChange(
      const MediaPlayerId& id,
      media_session::mojom::RemotePlaybackMetadataPtr remote_playback_metadata);

  // Called when video visibility for the player |id| has changed.
  void OnVideoVisibilityChanged(const MediaPlayerId& id,
                                bool meets_visibility_threshold);

 private:
  using ControllersMap =
      std::map<MediaPlayerId, std::unique_ptr<MediaSessionController>>;

  // Returns the controller for the player identified by |id|, creating a new
  // one and placing it in |controllers_map_| if necessary.
  MediaSessionController* FindOrCreateController(const MediaPlayerId& id);

  const raw_ptr<WebContentsImpl> web_contents_;

  ControllersMap controllers_map_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_CONTROLLERS_MANAGER_H_