#include "third_party/blink/renderer/modules/media_capabilities/media_capabilities.h"
#include <math.h>
#include <algorithm>
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "media/base/media_switches.h"
#include "media/base/video_codecs.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/clients/mojo_video_encoder_metrics_provider.h"
#include "media/mojo/mojom/media_metrics_provider.mojom-blink.h"
#include "media/mojo/mojom/media_types.mojom-blink.h"
#include "media/mojo/mojom/video_decode_perf_history.mojom-blink.h"
#include "media/mojo/mojom/watch_time_recorder.mojom-blink.h"
#include "media/mojo/mojom/webrtc_video_perf.mojom-blink.h"
#include "media/video/mock_gpu_video_accelerator_factories.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_configuration.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_capabilities_info.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_video_configuration.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_video_encoder_factory.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/wtf_size_t.h"
#include "third_party/googletest/src/googlemock/include/gmock/gmock-actions.h"
#include "ui/gfx/geometry/size.h"
FeatureValue;
ObservationCompletion;
TargetValue;
_;
InSequence;
Invoke;
Return;
Unused;
namespace blink {
namespace {
class MockPerfHistoryService
: public media::mojom::blink::VideoDecodePerfHistory { … };
class MockWebrtcPerfHistoryService
: public media::mojom::blink::WebrtcVideoPerfHistory { … };
class MockLearningTaskControllerService
: public media::learning::mojom::blink::LearningTaskController { … };
class FakeMediaMetricsProvider
: public media::mojom::blink::MediaMetricsProvider { … };
class CallbackSaver { … };
class MockPlatform : public TestingPlatformSupport { … };
class MediaCapabilitiesTestContext { … };
const char kVideoContentType[] = …;
const char kAudioContentType[] = …;
const media::VideoCodecProfile kCodecProfile = …;
const media::VideoCodec kCodec = …;
const double kFramerate = …;
const int kWidth = …;
const int kHeight = …;
const int kBitrate = …;
const char kWebrtcVideoContentType[] = …;
const char kWebrtcAudioContentType[] = …;
template <class T>
T* CreateAudioConfig(const char content_type[], const char type[]) { … }
MediaDecodingConfiguration* CreateAudioDecodingConfig() { … }
MediaDecodingConfiguration* CreateWebrtcAudioDecodingConfig() { … }
MediaEncodingConfiguration* CreateWebrtcAudioEncodingConfig() { … }
template <class T>
T* CreateVideoConfig(const char content_type[], const char type[]) { … }
MediaDecodingConfiguration* CreateDecodingConfig() { … }
MediaDecodingConfiguration* CreateWebrtcDecodingConfig() { … }
MediaEncodingConfiguration* CreateWebrtcEncodingConfig() { … }
media::mojom::blink::PredictionFeatures CreateFeatures() { … }
Vector<media::learning::FeatureValue> CreateFeaturesML() { … }
media::mojom::blink::WebrtcPredictionFeatures CreateWebrtcFeatures(
bool is_decode) { … }
enum class PredictionType { … };
media::learning::TargetHistogram MakeHistogram(double target_value) { … }
testing::Action<void(media::mojom::blink::PredictionFeaturesPtr,
MockPerfHistoryService::GetPerfInfoCallback)>
DbCallback(const media::mojom::blink::PredictionFeatures& expected_features,
bool is_smooth,
bool is_power_efficient) { … }
testing::Action<void(
const Vector<media::learning::FeatureValue>&,
MockLearningTaskControllerService::PredictDistributionCallback predict_cb)>
MlCallback(const Vector<media::learning::FeatureValue>& expected_features,
double histogram_target) { … }
testing::Action<void(media::mojom::blink::WebrtcPredictionFeaturesPtr,
int,
MockWebrtcPerfHistoryService::GetPerfInfoCallback)>
WebrtcDbCallback(
const media::mojom::blink::WebrtcPredictionFeatures& expected_features,
int expected_framerate,
bool is_smooth) { … }
testing::Action<void(base::OnceClosure)> GpuFactoriesNotifyCallback() { … }
base::FieldTrialParams MakeMlParams(double bad_window_threshold,
double nnr_threshold) { … }
MediaCapabilitiesInfo* DecodingInfo(
const MediaDecodingConfiguration* decoding_config,
MediaCapabilitiesTestContext* context) { … }
MediaCapabilitiesInfo* EncodingInfo(
const MediaEncodingConfiguration* encoding_config,
MediaCapabilitiesTestContext* context) { … }
}
TEST(MediaCapabilitiesTests, BasicAudio) { … }
TEST(MediaCapabilitiesTests, ConfigMatchesFeatures) { … }
TEST(MediaCapabilitiesTests, NonIntegerFramerate) { … }
TEST(MediaCapabilitiesTests, PredictWithJustDB) { … }
TEST(MediaCapabilitiesTests, PredictPowerEfficientWithGpuFactories) { … }
TEST(MediaCapabilitiesTests, PredictWithBadWindowMLService) { … }
TEST(MediaCapabilitiesTests, PredictWithNnrMLService) { … }
TEST(MediaCapabilitiesTests, PredictWithBothMLServices) { … }
void RunCallbackPermutationTest(std::vector<PredictionType> callback_order) { … }
TEST(MediaCapabilitiesTests, PredictionCallbackPermutations) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodingBasicAudio) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodingUnsupportedAudio) { … }
TEST(MediaCapabilitiesTests, WebrtcConfigMatchesFeatures) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodingBasicVideo) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodingUnsupportedVideo) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodingSpatialScalability) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodingBasicAudio) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodingUnsupportedAudio) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodingBasicVideo) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodingUnsupportedVideo) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodingScalabilityMode) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodePowerEfficientIsSmooth) { … }
TEST(MediaCapabilitiesTests, WebrtcDecodeOverridePowerEfficientIsSmooth) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodePowerEfficientIsSmooth) { … }
TEST(MediaCapabilitiesTests, WebrtcEncodeOverridePowerEfficientIsSmooth) { … }
}