#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/media_capabilities/media_capabilities.h"
#include <memory>
#include <optional>
#include <sstream>
#include <utility>
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "media/base/media_switches.h"
#include "media/base/media_util.h"
#include "media/base/mime_util.h"
#include "media/base/supported_types.h"
#include "media/base/supported_video_decoder_config.h"
#include "media/base/video_decoder_config.h"
#include "media/filters/stream_parser_factory.h"
#include "media/learning/common/media_learning_tasks.h"
#include "media/learning/common/target_histogram.h"
#include "media/learning/mojo/public/mojom/learning_task_controller.mojom-blink.h"
#include "media/mojo/mojom/media_metrics_provider.mojom-blink.h"
#include "media/mojo/mojom/media_types.mojom-blink.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_encrypted_media_client.h"
#include "third_party/blink/public/platform/web_encrypted_media_request.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/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_key_system_track_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_capabilities_decoding_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_capabilities_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_capabilities_key_system_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_decoding_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_encoding_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_key_system_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_key_system_media_capability.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/execution_context/navigator_base.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/modules/encryptedmedia/encrypted_media_utils.h"
#include "third_party/blink/renderer/modules/encryptedmedia/media_key_system_access.h"
#include "third_party/blink/renderer/modules/encryptedmedia/media_key_system_access_initializer_base.h"
#include "third_party/blink/renderer/modules/media_capabilities/media_capabilities_identifiability_metrics.h"
#include "third_party/blink/renderer/modules/media_capabilities_names.h"
#include "third_party/blink/renderer/modules/mediarecorder/media_recorder_handler.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/media_capabilities/web_media_capabilities_info.h"
#include "third_party/blink/renderer/platform/media_capabilities/web_media_configuration.h"
#include "third_party/blink/renderer/platform/network/parsed_content_type.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/peerconnection/webrtc_util.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/webrtc/api/audio_codecs/audio_format.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
namespace blink {
namespace {
const double kLearningBadWindowThresholdDefault = …;
const double kLearningNnrThresholdDefault = …;
const bool kWebrtcDecodeSmoothIfPowerEfficientDefault = …;
const bool kWebrtcEncodeSmoothIfPowerEfficientDefault = …;
constexpr const char* kApplicationMimeTypePrefix = …;
constexpr const char* kAudioMimeTypePrefix = …;
constexpr const char* kVideoMimeTypePrefix = …;
constexpr const char* kCodecsMimeTypeParam = …;
constexpr const char* kSmpteSt2086HdrMetadataType = …;
constexpr const char* kSmpteSt209410HdrMetadataType = …;
constexpr const char* kSmpteSt209440HdrMetadataType = …;
constexpr const char* kSrgbColorGamut = …;
constexpr const char* kP3ColorGamut = …;
constexpr const char* kRec2020ColorGamut = …;
constexpr const char* kSrgbTransferFunction = …;
constexpr const char* kPqTransferFunction = …;
constexpr const char* kHlgTransferFunction = …;
double GetLearningBadWindowThreshold() { … }
double GetLearningNnrThreshold() { … }
bool WebrtcDecodeForceSmoothIfPowerEfficient() { … }
bool WebrtcEncodeForceSmoothIfPowerEfficient() { … }
bool UseGpuFactoriesForPowerEfficient(
ExecutionContext* execution_context,
const MediaKeySystemAccess* key_system_access) { … }
MediaCapabilitiesDecodingInfo* CreateDecodingInfoWith(bool value) { … }
MediaCapabilitiesInfo* CreateEncodingInfoWith(bool value) { … }
ScriptPromise<MediaCapabilitiesDecodingInfo>
CreateResolvedPromiseToDecodingInfoWith(
bool value,
ScriptState* script_state,
const MediaDecodingConfiguration* config) { … }
MediaCapabilitiesDecodingInfo* CreateEncryptedDecodingInfoWith(
bool value,
MediaKeySystemAccess* access) { … }
class MediaCapabilitiesKeySystemAccessInitializer final
: public MediaKeySystemAccessInitializerBase { … };
bool IsValidFrameRate(double framerate) { … }
bool IsValidMimeType(const String& content_type,
const String& prefix,
bool is_webrtc) { … }
bool IsValidMediaConfiguration(const MediaConfiguration* configuration) { … }
bool IsValidVideoConfiguration(const VideoConfiguration* configuration,
bool is_decode,
bool is_webrtc) { … }
bool IsValidAudioConfiguration(const AudioConfiguration* configuration,
bool is_webrtc) { … }
bool IsValidMediaDecodingConfiguration(
const MediaDecodingConfiguration* configuration,
bool is_webrtc,
String* message) { … }
bool IsValidMediaEncodingConfiguration(
const MediaEncodingConfiguration* configuration,
bool is_webrtc,
String* message) { … }
WebAudioConfiguration ToWebAudioConfiguration(
const AudioConfiguration* configuration) { … }
WebVideoConfiguration ToWebVideoConfiguration(
const VideoConfiguration* configuration) { … }
WebMediaConfiguration ToWebMediaConfiguration(
const MediaEncodingConfiguration* configuration) { … }
webrtc::SdpAudioFormat ToSdpAudioFormat(
const AudioConfiguration* configuration) { … }
webrtc::SdpVideoFormat ToSdpVideoFormat(
const VideoConfiguration* configuration) { … }
bool CheckMseSupport(const String& mime_type, const String& codec) { … }
void ParseDynamicRangeConfigurations(
const blink::VideoConfiguration* video_config,
media::VideoColorSpace* color_space,
gfx::HdrMetadataType* hdr_metadata) { … }
bool IsAudioCodecValid(const String& mime_type,
const String& codec,
String* console_warning) { … }
bool IsVideoCodecValid(const String& mime_type,
const String& codec,
media::VideoCodec* out_video_codec,
media::VideoCodecProfile* out_video_profile,
String* console_warning) { … }
bool IsAudioConfigurationSupported(
const blink::AudioConfiguration* audio_config,
const String& mime_type,
const String& codec) { … }
bool IsVideoConfigurationSupported(const String& mime_type,
const String& codec,
media::VideoColorSpace video_color_space,
gfx::HdrMetadataType hdr_metadata_type) { … }
void OnMediaCapabilitiesEncodingInfo(
ScriptPromiseResolver<MediaCapabilitiesInfo>* resolver,
std::unique_ptr<WebMediaCapabilitiesInfo> result) { … }
bool ParseContentType(const String& content_type,
String* mime_type,
String* codec) { … }
}
const char MediaCapabilities::kLearningBadWindowThresholdParamName[] = …;
const char MediaCapabilities::kLearningNnrThresholdParamName[] = …;
const char MediaCapabilities::kWebrtcDecodeSmoothIfPowerEfficientParamName[] = …;
const char MediaCapabilities::kWebrtcEncodeSmoothIfPowerEfficientParamName[] = …;
const char MediaCapabilities::kSupplementName[] = …;
MediaCapabilities* MediaCapabilities::mediaCapabilities(
NavigatorBase& navigator) { … }
MediaCapabilities::MediaCapabilities(NavigatorBase& navigator)
: … { … }
void MediaCapabilities::Trace(blink::Visitor* visitor) const { … }
MediaCapabilities::PendingCallbackState::PendingCallbackState(
ScriptPromiseResolverBase* resolver,
MediaKeySystemAccess* access,
const base::TimeTicks& request_time,
std::optional<IdentifiableToken> input_token)
: … { … }
void MediaCapabilities::PendingCallbackState::Trace(
blink::Visitor* visitor) const { … }
ScriptPromise<MediaCapabilitiesDecodingInfo> MediaCapabilities::decodingInfo(
ScriptState* script_state,
const MediaDecodingConfiguration* config,
ExceptionState& exception_state) { … }
ScriptPromise<MediaCapabilitiesInfo> MediaCapabilities::encodingInfo(
ScriptState* script_state,
const MediaEncodingConfiguration* config,
ExceptionState& exception_state) { … }
bool MediaCapabilities::EnsureLearningPredictors(
ExecutionContext* execution_context) { … }
bool MediaCapabilities::EnsurePerfHistoryService(
ExecutionContext* execution_context) { … }
bool MediaCapabilities::EnsureWebrtcPerfHistoryService(
ExecutionContext* execution_context) { … }
ScriptPromise<MediaCapabilitiesDecodingInfo> MediaCapabilities::GetEmeSupport(
ScriptState* script_state,
media::VideoCodec video_codec,
media::VideoCodecProfile video_profile,
media::VideoColorSpace video_color_space,
const MediaDecodingConfiguration* configuration,
const base::TimeTicks& request_time,
ExceptionState& exception_state) { … }
void MediaCapabilities::GetPerfInfo(
media::VideoCodec video_codec,
media::VideoCodecProfile video_profile,
media::VideoColorSpace video_color_space,
const MediaDecodingConfiguration* decoding_config,
const base::TimeTicks& request_time,
ScriptPromiseResolver<MediaCapabilitiesDecodingInfo>* resolver,
MediaKeySystemAccess* access) { … }
void MediaCapabilities::GetPerfInfo_ML(ExecutionContext* execution_context,
int callback_id,
media::VideoCodec video_codec,
media::VideoCodecProfile video_profile,
int width,
double framerate) { … }
void MediaCapabilities::GetGpuFactoriesSupport(
int callback_id,
media::VideoCodec video_codec,
media::VideoCodecProfile video_profile,
media::VideoColorSpace video_color_space,
const MediaDecodingConfiguration* decoding_config) { … }
void MediaCapabilities::ResolveCallbackIfReady(int callback_id) { … }
void MediaCapabilities::OnBadWindowPrediction(
int callback_id,
const std::optional<::media::learning::TargetHistogram>& histogram) { … }
void MediaCapabilities::OnNnrPrediction(
int callback_id,
const std::optional<::media::learning::TargetHistogram>& histogram) { … }
void MediaCapabilities::OnPerfHistoryInfo(int callback_id,
bool is_smooth,
bool is_power_efficient) { … }
void MediaCapabilities::OnGpuFactoriesSupport(int callback_id,
bool is_supported,
media::VideoCodec video_codec) { … }
void MediaCapabilities::OnWebrtcSupportInfo(
int callback_id,
media::mojom::blink::WebrtcPredictionFeaturesPtr features,
float frames_per_second,
OperationType type,
bool is_supported,
bool is_power_efficient) { … }
void MediaCapabilities::OnWebrtcPerfHistoryInfo(int callback_id,
OperationType type,
bool is_smooth) { … }
int MediaCapabilities::CreateCallbackId() { … }
}