File: media_capabilities.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (237 lines) | stat: -rw-r--r-- 9,924 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIA_CAPABILITIES_MEDIA_CAPABILITIES_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIA_CAPABILITIES_MEDIA_CAPABILITIES_H_

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "media/base/video_codecs.h"  // for media::VideoCodecProfile
#include "media/base/video_color_space.h"
#include "media/learning/mojo/public/cpp/mojo_learning_task_controller.h"
#include "media/learning/mojo/public/mojom/learning_task_controller.mojom-blink.h"
#include "media/mojo/mojom/video_decode_perf_history.mojom-blink.h"
#include "media/mojo/mojom/webrtc_video_perf.mojom-blink.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_video_configuration.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/peerconnection/webrtc_decoding_info_handler.h"
#include "third_party/blink/renderer/platform/peerconnection/webrtc_encoding_info_handler.h"
#include "third_party/blink/renderer/platform/supplementable.h"

namespace blink {

class ExceptionState;
class ExecutionContext;
class MediaCapabilitiesDecodingInfo;
class MediaCapabilitiesInfo;
class MediaDecodingConfiguration;
class MediaEncodingConfiguration;
class MediaKeySystemAccess;
class NavigatorBase;
class ScriptState;

class MODULES_EXPORT MediaCapabilities final
    : public ScriptWrappable,
      public Supplement<NavigatorBase> {
  DEFINE_WRAPPERTYPEINFO();

 public:
  static const char kLearningBadWindowThresholdParamName[];
  static const char kLearningNnrThresholdParamName[];
  static const char kWebrtcDecodeSmoothIfPowerEfficientParamName[];
  static const char kWebrtcEncodeSmoothIfPowerEfficientParamName[];

  static const char kSupplementName[];

  // Getter for navigator.mediaCapabilities
  static MediaCapabilities* mediaCapabilities(NavigatorBase&);

  explicit MediaCapabilities(NavigatorBase&);

  void Trace(blink::Visitor* visitor) const override;

  ScriptPromise<MediaCapabilitiesDecodingInfo> decodingInfo(
      ScriptState*,
      const MediaDecodingConfiguration*,
      ExceptionState&);
  ScriptPromise<MediaCapabilitiesInfo> encodingInfo(
      ScriptState*,
      const MediaEncodingConfiguration*,
      ExceptionState&);

 private:
  // Stores pending callback state from and intermediate prediction values while
  // we wait for all predictions to arrive.
  class PendingCallbackState : public GarbageCollected<PendingCallbackState> {
   public:
    PendingCallbackState(ScriptPromiseResolverBase* resolver,
                         MediaKeySystemAccess* access,
                         const base::TimeTicks& request_time,
                         std::optional<IdentifiableToken> input_token);
    virtual void Trace(blink::Visitor* visitor) const;

    Member<ScriptPromiseResolverBase> resolver;
    Member<MediaKeySystemAccess> key_system_access;
    std::optional<bool> is_supported;
    std::optional<bool> is_bad_window_prediction_smooth;
    std::optional<bool> is_nnr_prediction_smooth;
    std::optional<bool> db_is_smooth;
    std::optional<bool> db_is_power_efficient;
    std::optional<bool> is_gpu_factories_supported;
    std::optional<bool> is_builtin_video_codec;
    base::TimeTicks request_time;
    std::optional<IdentifiableToken> input_token;
  };

  FRIEND_TEST_ALL_PREFIXES(MediaCapabilitiesTests,
                           WebrtcDecodePowerEfficientIsSmooth);
  FRIEND_TEST_ALL_PREFIXES(MediaCapabilitiesTests,
                           WebrtcDecodeOverridePowerEfficientIsSmooth);
  FRIEND_TEST_ALL_PREFIXES(MediaCapabilitiesTests,
                           WebrtcEncodePowerEfficientIsSmooth);
  FRIEND_TEST_ALL_PREFIXES(MediaCapabilitiesTests,
                           WebrtcEncodeOverridePowerEfficientIsSmooth);

  // Lazily binds remote LearningTaskControllers for ML smoothness predictions
  // and returns whether binding succeeds. Returns true if it was already bound.
  bool EnsureLearningPredictors(ExecutionContext*);

  // Lazily binds to the VideoDecodePerfHistory service. Returns whether it was
  // successful. Returns true if it was already bound.
  bool EnsurePerfHistoryService(ExecutionContext*);

  // Lazily binds to the WebrtcVideoPerfHistory service. Returns whether it was
  // successful. Returns true if it was already bound.
  bool EnsureWebrtcPerfHistoryService(ExecutionContext* execution_context);

  ScriptPromise<MediaCapabilitiesDecodingInfo> GetEmeSupport(
      ScriptState*,
      media::VideoCodec,
      media::VideoCodecProfile,
      media::VideoColorSpace,
      const MediaDecodingConfiguration*,
      const base::TimeTicks& request_time,
      ExceptionState&);
  // Gets perf info from VideoDecodePerrHistory DB. Will optionally kick off
  // parallel request to GetPerfInfo_ML() when learning experiment is enabled.
  void GetPerfInfo(media::VideoCodec,
                   media::VideoCodecProfile,
                   media::VideoColorSpace,
                   const MediaDecodingConfiguration*,
                   const base::TimeTicks& request_time,
                   ScriptPromiseResolver<MediaCapabilitiesDecodingInfo>*,
                   MediaKeySystemAccess*);

  // Gets ML perf predictions from remote LearingTaskControllers.
  void GetPerfInfo_ML(ExecutionContext* execution_context,
                      int callback_id,
                      media::VideoCodec video_codec,
                      media::VideoCodecProfile video_profile,
                      int width,
                      double framerate);

  // Query media::GpuVideoAcceleratorFactories for support of hardware
  // accelerate decode. Only called when |UseGpuFactoriesForPowerEfficient()|
  // is true.
  void GetGpuFactoriesSupport(int callback_id,
                              media::VideoCodec video_codec,
                              media::VideoCodecProfile video_profile,
                              media::VideoColorSpace,
                              const MediaDecodingConfiguration*);

  // Callback for perf info from the VideoDecodePerfHistory service.
  void OnPerfHistoryInfo(int callback_id,
                         bool is_smooth,
                         bool is_power_efficient);

  // Callback for predictions from |bad_window_predictor_|.
  void OnBadWindowPrediction(
      int callback_id,
      const std::optional<::media::learning::TargetHistogram>& histogram);

  // Callback for predictions from |nnr_predictor_|.
  void OnNnrPrediction(
      int callback_id,
      const std::optional<::media::learning::TargetHistogram>& histogram);

  // Callback for GetGpuFactoriesSupport().
  void OnGpuFactoriesSupport(int callback_id,
                             bool is_supported,
                             media::VideoCodec video_codec);

  // Resolves the callback with associated |callback_id| and removes it from the
  // |pending_callback_map_|.
  void ResolveCallbackIfReady(int callback_id);

  enum class OperationType { kEncoding, kDecoding };
  void OnWebrtcSupportInfo(
      int callback_id,
      media::mojom::blink::WebrtcPredictionFeaturesPtr features,
      float frames_per_second,
      OperationType,
      bool is_supported,
      bool is_power_efficient);

  void OnWebrtcPerfHistoryInfo(int callback_id, OperationType, bool is_smooth);

  // Creates a new (incremented) callback ID from |last_callback_id_| for
  // mapping in |pending_cb_map_|.
  int CreateCallbackId();

  void set_webrtc_decoding_info_handler_for_test(
      WebrtcDecodingInfoHandler* handler) {
    webrtc_decoding_info_handler_for_test_ = handler;
  }

  void set_webrtc_encoding_info_handler_for_test(
      WebrtcEncodingInfoHandler* handler) {
    webrtc_encoding_info_handler_for_test_ = handler;
  }

  HeapMojoRemote<media::mojom::blink::VideoDecodePerfHistory>
      decode_history_service_;

  // Connection to a browser-process LearningTaskController for predicting the
  // number of consecutive "bad" dropped frame windows during a playback. See
  // media::SmoothnessHelper.
  HeapMojoRemote<media::learning::mojom::blink::LearningTaskController>
      bad_window_predictor_;

  // Connects to a browser-process LearningTaskController for predicting the
  // number of consecutive non-network re-buffers (NNRs). See
  // media::SmoothnessHelper.
  HeapMojoRemote<media::learning::mojom::blink::LearningTaskController>
      nnr_predictor_;

  HeapMojoRemote<media::mojom::blink::WebrtcVideoPerfHistory>
      webrtc_history_service_;

  // Holds the last key for callbacks in the map below. Incremented for each
  // usage.
  int last_callback_id_ = 0;

  // Maps a callback ID to state for pending callbacks.
  HeapHashMap<int, Member<PendingCallbackState>> pending_cb_map_;

  // Makes it possible to override the WebrtcDecodingInfoHandler in tests.
  raw_ptr<WebrtcDecodingInfoHandler> webrtc_decoding_info_handler_for_test_ =
      nullptr;

  // Makes it possible to override the WebrtcEncodingInfoHandler in tests.
  raw_ptr<WebrtcEncodingInfoHandler> webrtc_encoding_info_handler_for_test_ =
      nullptr;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIA_CAPABILITIES_MEDIA_CAPABILITIES_H_