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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/media_effects/test/fake_video_capture_service.h"
#include "base/test/test_future.h"
#include "content/public/browser/video_capture_service.h"
namespace media_effects {
void FakeVideoCaptureService::AddFakeCamera(
const media::VideoCaptureDeviceDescriptor& descriptor) {
fake_provider_.AddFakeCamera(descriptor);
}
bool FakeVideoCaptureService::AddFakeCameraBlocking(
const media::VideoCaptureDeviceDescriptor& descriptor) {
base::test::TestFuture<void> test_future;
SetOnRepliedWithSourceInfosCallback(test_future.GetCallback());
AddFakeCamera(descriptor);
return test_future.WaitAndClear();
}
void FakeVideoCaptureService::RemoveFakeCamera(const std::string& device_id) {
fake_provider_.RemoveFakeCamera(device_id);
}
bool FakeVideoCaptureService::RemoveFakeCameraBlocking(
const std::string& device_id) {
base::test::TestFuture<void> test_future;
SetOnRepliedWithSourceInfosCallback(test_future.GetCallback());
RemoveFakeCamera(device_id);
return test_future.WaitAndClear();
}
void FakeVideoCaptureService::SetOnRepliedWithSourceInfosCallback(
base::OnceClosure callback) {
fake_provider_.SetOnRepliedWithSourceInfosCallback(std::move(callback));
}
// `callback` will be triggered when the source provider receives a
// GetVideoSource call.
void FakeVideoCaptureService::SetOnGetVideoSourceCallback(
FakeVideoSourceProvider::GetVideoSourceCallback callback) {
fake_provider_.SetOnGetVideoSourceCallback(std::move(callback));
}
void FakeVideoCaptureService::ConnectToVideoSourceProvider(
mojo::PendingReceiver<video_capture::mojom::VideoSourceProvider> receiver) {
fake_provider_.Bind(std::move(receiver));
}
ScopedFakeVideoCaptureService::ScopedFakeVideoCaptureService() {
content::OverrideVideoCaptureServiceForTesting(this);
}
ScopedFakeVideoCaptureService::~ScopedFakeVideoCaptureService() {
content::OverrideVideoCaptureServiceForTesting(nullptr);
}
} // namespace media_effects
|