File: media_internals_audio_focus_helper.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 3,172 bytes parent folder | download | duplicates (6)
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
// Copyright 2018 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_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_
#define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_

#include <map>
#include <string_view>

#include "base/values.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h"

namespace content {

// MediaInternalsAudioFocusHelper manages communication with the media session
// helper to populate the "audio focus" tab.
class MediaInternalsAudioFocusHelper
    : public media_session::mojom::AudioFocusObserver {
 public:
  MediaInternalsAudioFocusHelper();

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

  ~MediaInternalsAudioFocusHelper() override;

  // Sends all audio focus information to media internals.
  void SendAudioFocusState();

  // AudioFocusObserver implementation.
  void OnFocusGained(
      media_session::mojom::AudioFocusRequestStatePtr session) override;
  void OnFocusLost(
      media_session::mojom::AudioFocusRequestStatePtr session) override;
  void OnRequestIdReleased(const base::UnguessableToken&) override {}

  // Sets whether we should listen to audio focus events.
  void SetEnabled(bool enabled);

 private:
  bool EnsureServiceConnection();
  void OnMojoError();
  void OnDebugMojoError();

  // Called when we receive the list of audio focus requests to display.
  void DidGetAudioFocusRequestList(
      std::vector<media_session::mojom::AudioFocusRequestStatePtr>);

  // Called when we receive audio focus debug info to display for a single
  // audio focus request.
  void DidGetAudioFocusDebugInfo(
      const std::string& id,
      media_session::mojom::MediaSessionDebugInfoPtr info);

  void SerializeAndSendUpdate(std::string_view function,
                              const base::Value::Dict& value);

  // Build the name of the request to display and inject values from |state|.
  std::string BuildNameString(
      const media_session::mojom::AudioFocusRequestStatePtr& state,
      const std::string& provided_name) const;

  // Inject |state| values to display in the state information.
  std::string BuildStateString(
      const media_session::mojom::AudioFocusRequestStatePtr& state,
      const std::string& provided_state) const;

  // Holds a remote to the media session service and it's debug interface.
  mojo::Remote<media_session::mojom::AudioFocusManager> audio_focus_;
  mojo::Remote<media_session::mojom::AudioFocusManagerDebug> audio_focus_debug_;

  // Must only be accessed on the UI thread.
  base::Value::Dict audio_focus_data_;
  std::map<std::string, media_session::mojom::AudioFocusRequestStatePtr>
      request_state_;

  bool enabled_ = false;

  mojo::Receiver<media_session::mojom::AudioFocusObserver> receiver_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_AUDIO_FOCUS_HELPER_H_