diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-04 17:20:24 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-12 08:15:25 +0000 |
commit | 8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b (patch) | |
tree | 788d8d7549712682703a0310ca4a0f0860d4802b /chromium/media/capture | |
parent | 606d85f2a5386472314d39923da28c70c60dc8e7 (diff) | |
download | qtwebengine-chromium-8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b.tar.gz |
BASELINE: Update Chromium to 98.0.4758.90
Change-Id: Ib7c41539bf8a8e0376bd639f27d68294de90f3c8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/capture')
99 files changed, 767 insertions, 492 deletions
diff --git a/chromium/media/capture/BUILD.gn b/chromium/media/capture/BUILD.gn index 5207dde66b7..e0cd3cdc88e 100644 --- a/chromium/media/capture/BUILD.gn +++ b/chromium/media/capture/BUILD.gn @@ -98,6 +98,7 @@ source_set("capture_device_specific") { "//media", "//media/capture/mojom:image_capture", "//media/capture/mojom:image_capture_types", + "//media/capture/mojom:video_capture", "//media/mojo/mojom", "//media/parsers", "//skia", @@ -135,8 +136,6 @@ component("capture_lib") { "video/video_frame_receiver.h", "video/video_frame_receiver_on_task_runner.cc", "video/video_frame_receiver_on_task_runner.h", - "video_capturer_source.cc", - "video_capturer_source.h", ] public_deps = [ @@ -253,7 +252,7 @@ component("capture_lib") { ] } - if (is_linux || is_chromeos_lacros) { + if (is_linux || is_chromeos) { sources += [ "video/linux/scoped_v4l2_device_fd.cc", "video/linux/scoped_v4l2_device_fd.h", @@ -325,8 +324,8 @@ component("capture_lib") { public_deps += [ "//media/capture/video/chromeos/public" ] deps += [ "//ash/constants", + "//ash/webui/camera_app_ui:document_scanning", "//build/config/linux/libdrm", - "//chromeos/components/camera_app_ui:document_scanning", "//chromeos/components/sensors:sensors", "//chromeos/dbus/power", "//components/chromeos_camera:mojo_mjpeg_decode_accelerator", diff --git a/chromium/media/capture/content/android/screen_capture_machine_android.cc b/chromium/media/capture/content/android/screen_capture_machine_android.cc index 9d6a08c60c1..d8d417fa1ec 100644 --- a/chromium/media/capture/content/android/screen_capture_machine_android.cc +++ b/chromium/media/capture/content/android/screen_capture_machine_android.cc @@ -21,9 +21,13 @@ using base::android::ScopedJavaLocalRef; namespace media { -ScreenCaptureMachineAndroid::ScreenCaptureMachineAndroid() {} +ScreenCaptureMachineAndroid::ScreenCaptureMachineAndroid() = default; -ScreenCaptureMachineAndroid::~ScreenCaptureMachineAndroid() {} +ScreenCaptureMachineAndroid::~ScreenCaptureMachineAndroid() { + if (j_capture_.obj() != nullptr) { + Java_ScreenCapture_onNativeDestroyed(AttachCurrentThread(), j_capture_); + } +} // static ScopedJavaLocalRef<jobject> diff --git a/chromium/media/capture/content/smooth_event_sampler.cc b/chromium/media/capture/content/smooth_event_sampler.cc index 40aa1c0b860..e614949cd24 100644 --- a/chromium/media/capture/content/smooth_event_sampler.cc +++ b/chromium/media/capture/content/smooth_event_sampler.cc @@ -53,7 +53,7 @@ bool SmoothEventSampler::ShouldSample() const { void SmoothEventSampler::RecordSample() { token_bucket_ -= min_capture_period_; - if (token_bucket_ < base::TimeDelta()) + if (token_bucket_.is_negative()) token_bucket_ = base::TimeDelta(); TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", std::max<int64_t>(0, token_bucket_.InMicroseconds())); diff --git a/chromium/media/capture/content/smooth_event_sampler.h b/chromium/media/capture/content/smooth_event_sampler.h index 47ed58e1372..29623c826dd 100644 --- a/chromium/media/capture/content/smooth_event_sampler.h +++ b/chromium/media/capture/content/smooth_event_sampler.h @@ -5,7 +5,6 @@ #ifndef MEDIA_CAPTURE_CONTENT_SMOOTH_EVENT_SAMPLER_H_ #define MEDIA_CAPTURE_CONTENT_SMOOTH_EVENT_SAMPLER_H_ -#include "base/macros.h" #include "base/time/time.h" #include "media/capture/capture_export.h" @@ -16,6 +15,9 @@ class CAPTURE_EXPORT SmoothEventSampler { public: explicit SmoothEventSampler(base::TimeDelta min_capture_period); + SmoothEventSampler(const SmoothEventSampler&) = delete; + SmoothEventSampler& operator=(const SmoothEventSampler&) = delete; + // Get/Set minimum capture period. When setting a new value, the state of the // sampler is retained so that sampling will continue smoothly. base::TimeDelta min_capture_period() const { return min_capture_period_; } @@ -45,8 +47,6 @@ class CAPTURE_EXPORT SmoothEventSampler { base::TimeTicks current_event_; base::TimeTicks last_sample_; base::TimeDelta token_bucket_; - - DISALLOW_COPY_AND_ASSIGN(SmoothEventSampler); }; } // namespace media diff --git a/chromium/media/capture/mojom/video_capture.mojom b/chromium/media/capture/mojom/video_capture.mojom index 32675d2ff4f..a17142ad3f7 100644 --- a/chromium/media/capture/mojom/video_capture.mojom +++ b/chromium/media/capture/mojom/video_capture.mojom @@ -55,15 +55,20 @@ enum VideoCaptureState { PAUSED, RESUMED, STOPPED, - FAILED, ENDED, }; +union VideoCaptureResult { + VideoCaptureState state; + media.mojom.VideoCaptureError error_code; +}; + // Interface for notifications from Browser/Host back to Renderer/Client. This // interface is used between VideoCaptureHost.Start() and Stop(). interface VideoCaptureObserver { - // Gets notified about a VideoCaptureState update. - OnStateChanged(VideoCaptureState state); + // Gets notified about a VideoCaptureState update or a VideoCaptureError that + // might have occurred during the capture. + OnStateChanged(VideoCaptureResult result); // Registers a |buffer_handle| at the Renderer/Client using the given // |buffer_id|. The Browser/Host may subsequently use |buffer_id| to share diff --git a/chromium/media/capture/mojom/video_capture_types.mojom b/chromium/media/capture/mojom/video_capture_types.mojom index c2778d818da..573afbba325 100644 --- a/chromium/media/capture/mojom/video_capture_types.mojom +++ b/chromium/media/capture/mojom/video_capture_types.mojom @@ -238,6 +238,8 @@ enum VideoCaptureError { kDesktopCaptureDeviceMacFailedStreamCreate, kDesktopCaptureDeviceMacFailedStreamStart, kCrosHalV3BufferManagerFailedToReserveBuffers, + [MinVersion=1] kWinMediaFoundationSystemPermissionDenied, + [MinVersion=2] kVideoCaptureImplTimedOutOnStart, }; [Stable, Extensible] @@ -352,3 +354,13 @@ struct VideoCaptureDeviceInfo { VideoCaptureDeviceDescriptor descriptor; array<VideoCaptureFormat> supported_formats; }; + +// The result of an attempt by the client to start/stop cropping. +// TODO(crbug.com/1247761): Remove kNotImplemented. +enum CropRequestResult { + kSuccess, + kErrorGeneric, + kUnsupportedCaptureDevice, + kErrorUnknownDeviceId, + kNotImplemented, +}; diff --git a/chromium/media/capture/mojom/video_capture_types_mojom_traits.cc b/chromium/media/capture/mojom/video_capture_types_mojom_traits.cc index c77bdd8148e..bfca3075996 100644 --- a/chromium/media/capture/mojom/video_capture_types_mojom_traits.cc +++ b/chromium/media/capture/mojom/video_capture_types_mojom_traits.cc @@ -718,6 +718,11 @@ EnumTraits<media::mojom::VideoCaptureError, media::VideoCaptureError>::ToMojom( kCrosHalV3BufferManagerFailedToReserveBuffers: return media::mojom::VideoCaptureError:: kCrosHalV3BufferManagerFailedToReserveBuffers; + case media::VideoCaptureError::kWinMediaFoundationSystemPermissionDenied: + return media::mojom::VideoCaptureError:: + kWinMediaFoundationSystemPermissionDenied; + case media::VideoCaptureError::kVideoCaptureImplTimedOutOnStart: + return media::mojom::VideoCaptureError::kVideoCaptureImplTimedOutOnStart; } NOTREACHED(); return media::mojom::VideoCaptureError::kNone; @@ -1280,6 +1285,14 @@ bool EnumTraits<media::mojom::VideoCaptureError, media::VideoCaptureError>:: *output = media::VideoCaptureError:: kCrosHalV3BufferManagerFailedToReserveBuffers; return true; + case media::mojom::VideoCaptureError:: + kWinMediaFoundationSystemPermissionDenied: + *output = + media::VideoCaptureError::kWinMediaFoundationSystemPermissionDenied; + return true; + case media::mojom::VideoCaptureError::kVideoCaptureImplTimedOutOnStart: + *output = media::VideoCaptureError::kVideoCaptureImplTimedOutOnStart; + return true; } NOTREACHED(); return false; diff --git a/chromium/media/capture/video/android/video_capture_device_android.h b/chromium/media/capture/video/android/video_capture_device_android.h index 9d4da1ca968..ffe0a6a9769 100644 --- a/chromium/media/capture/video/android/video_capture_device_android.h +++ b/chromium/media/capture/video/android/video_capture_device_android.h @@ -9,7 +9,6 @@ #include <string> #include "base/android/scoped_java_ref.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/synchronization/lock.h" #include "base/threading/thread.h" @@ -67,8 +66,15 @@ class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice { ANDROID_API_2_ACQUIRED_IMAGE_IS_NULL = 9, }; + VideoCaptureDeviceAndroid() = delete; + explicit VideoCaptureDeviceAndroid( const VideoCaptureDeviceDescriptor& device_descriptor); + + VideoCaptureDeviceAndroid(const VideoCaptureDeviceAndroid&) = delete; + VideoCaptureDeviceAndroid& operator=(const VideoCaptureDeviceAndroid&) = + delete; + ~VideoCaptureDeviceAndroid() override; static VideoCaptureDevice* Create( @@ -207,8 +213,6 @@ class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice { base::android::ScopedJavaLocalRef<jobject> j_capture_; base::WeakPtrFactory<VideoCaptureDeviceAndroid> weak_ptr_factory_{this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid); }; } // namespace media diff --git a/chromium/media/capture/video/android/video_capture_device_factory_android.cc b/chromium/media/capture/video/android/video_capture_device_factory_android.cc index 33e913c0785..aeddd59bcec 100644 --- a/chromium/media/capture/video/android/video_capture_device_factory_android.cc +++ b/chromium/media/capture/video/android/video_capture_device_factory_android.cc @@ -9,8 +9,8 @@ #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" #include "base/containers/cxx20_erase.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" +#include "base/task/single_thread_task_runner.h" #include "media/capture/video/android/capture_jni_headers/VideoCaptureFactory_jni.h" #include "media/capture/video/android/video_capture_device_android.h" @@ -32,13 +32,14 @@ VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( VideoCaptureDeviceFactoryAndroid::VideoCaptureDeviceFactoryAndroid() = default; VideoCaptureDeviceFactoryAndroid::~VideoCaptureDeviceFactoryAndroid() = default; -std::unique_ptr<VideoCaptureDevice> -VideoCaptureDeviceFactoryAndroid::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryAndroid::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); int id; if (!base::StringToInt(device_descriptor.device_id, &id)) - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); std::unique_ptr<VideoCaptureDeviceAndroid> video_capture_device( new VideoCaptureDeviceAndroid(device_descriptor)); @@ -46,11 +47,12 @@ VideoCaptureDeviceFactoryAndroid::CreateDevice( if (video_capture_device->Init()) { if (test_mode_) video_capture_device->ConfigureForTesting(); - return std::move(video_capture_device); + return VideoCaptureErrorOrDevice(std::move(video_capture_device)); } DLOG(ERROR) << "Error creating Video Capture Device."; - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError::kAndroidApi2ErrorConfiguringCamera); } void VideoCaptureDeviceFactoryAndroid::GetDevicesInfo( diff --git a/chromium/media/capture/video/android/video_capture_device_factory_android.h b/chromium/media/capture/video/android/video_capture_device_factory_android.h index a787f32a0cb..3eef79c97ac 100644 --- a/chromium/media/capture/video/android/video_capture_device_factory_android.h +++ b/chromium/media/capture/video/android/video_capture_device_factory_android.h @@ -11,7 +11,6 @@ #include "base/android/scoped_java_ref.h" #include "base/containers/flat_map.h" -#include "base/macros.h" #include "media/capture/video/video_capture_device.h" namespace media { @@ -34,7 +33,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryAndroid ~VideoCaptureDeviceFactoryAndroid() override; - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/chromeos/DEPS b/chromium/media/capture/video/chromeos/DEPS index 4c07d00c491..3518318db17 100644 --- a/chromium/media/capture/video/chromeos/DEPS +++ b/chromium/media/capture/video/chromeos/DEPS @@ -1,6 +1,6 @@ include_rules = [ "+ash/constants/ash_features.h", - "+chromeos/components/camera_app_ui/document_scanner_service_client.h", + "+ash/webui/camera_app_ui/document_scanner_service_client.h", "+chromeos/components/sensors", "+chromeos/dbus", "+components/chromeos_camera", diff --git a/chromium/media/capture/video/chromeos/camera_3a_controller.h b/chromium/media/capture/video/chromeos/camera_3a_controller.h index e87c8c2264c..10e7e0f76fe 100644 --- a/chromium/media/capture/video/chromeos/camera_3a_controller.h +++ b/chromium/media/capture/video/chromeos/camera_3a_controller.h @@ -21,9 +21,15 @@ namespace media { class CAPTURE_EXPORT Camera3AController final : public CaptureMetadataDispatcher::ResultMetadataObserver { public: + Camera3AController() = delete; + Camera3AController(const cros::mojom::CameraMetadataPtr& static_metadata, CaptureMetadataDispatcher* capture_metadata_dispatcher, scoped_refptr<base::SingleThreadTaskRunner> task_runner); + + Camera3AController(const Camera3AController&) = delete; + Camera3AController& operator=(const Camera3AController&) = delete; + ~Camera3AController() final; // Trigger the camera to start exposure, focus, and white-balance metering and @@ -150,8 +156,6 @@ class CAPTURE_EXPORT Camera3AController final base::CancelableOnceClosure delayed_ae_unlock_callback_; base::WeakPtrFactory<Camera3AController> weak_ptr_factory_{this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(Camera3AController); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/camera_app_device_impl.cc b/chromium/media/capture/video/chromeos/camera_app_device_impl.cc index 8637559c7af..c1e2e6b5af1 100644 --- a/chromium/media/capture/video/chromeos/camera_app_device_impl.cc +++ b/chromium/media/capture/video/chromeos/camera_app_device_impl.cc @@ -6,7 +6,7 @@ #include <cmath> -#include "base/bind_post_task.h" +#include "base/task/bind_post_task.h" #include "base/time/time.h" #include "gpu/ipc/common/gpu_memory_buffer_impl.h" #include "media/base/bind_to_current_loop.h" @@ -95,7 +95,7 @@ void CameraAppDeviceImpl::BindReceiver( weak_ptr_factory_for_mojo_.GetWeakPtr())); mojo_task_runner_ = base::ThreadTaskRunnerHandle::Get(); - document_scanner_service_ = chromeos::DocumentScannerServiceClient::Create(); + document_scanner_service_ = ash::DocumentScannerServiceClient::Create(); } base::WeakPtr<CameraAppDeviceImpl> CameraAppDeviceImpl::GetWeakPtr() { @@ -182,7 +182,7 @@ void CameraAppDeviceImpl::MaybeDetectDocumentCorners( return; } } - if (!chromeos::DocumentScannerServiceClient::IsSupported()) { + if (!ash::DocumentScannerServiceClient::IsSupported()) { return; } mojo_task_runner_->PostTask( diff --git a/chromium/media/capture/video/chromeos/camera_app_device_impl.h b/chromium/media/capture/video/chromeos/camera_app_device_impl.h index de6df72aff1..fbb516d7144 100644 --- a/chromium/media/capture/video/chromeos/camera_app_device_impl.h +++ b/chromium/media/capture/video/chromeos/camera_app_device_impl.h @@ -11,12 +11,12 @@ #include <utility> #include <vector> +#include "ash/webui/camera_app_ui/document_scanner_service_client.h" #include "base/containers/queue.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" +#include "base/task/single_thread_task_runner.h" #include "base/timer/elapsed_timer.h" -#include "chromeos/components/camera_app_ui/document_scanner_service_client.h" #include "media/base/video_transformation.h" #include "media/capture/capture_export.h" #include "media/capture/mojom/image_capture.mojom.h" @@ -233,8 +233,7 @@ class CAPTURE_EXPORT CameraAppDeviceImpl : public cros::mojom::CameraAppDevice { // Client to connect to document detection service. It should only be // used/destructed on the Mojo thread. - std::unique_ptr<chromeos::DocumentScannerServiceClient> - document_scanner_service_; + std::unique_ptr<ash::DocumentScannerServiceClient> document_scanner_service_; // The weak pointers should be dereferenced and invalidated on camera device // ipc thread. diff --git a/chromium/media/capture/video/chromeos/camera_device_delegate.cc b/chromium/media/capture/video/chromeos/camera_device_delegate.cc index 39764145072..823f8d28c34 100644 --- a/chromium/media/capture/video/chromeos/camera_device_delegate.cc +++ b/chromium/media/capture/video/chromeos/camera_device_delegate.cc @@ -52,6 +52,10 @@ constexpr char kZoomRange[] = "com.google.control.zoomRange"; constexpr int32_t kColorTemperatureStep = 100; constexpr int32_t kMicroToNano = 1000; +constexpr char kIntelPowerMode[] = "intel.vendorCamera.powerMode"; +constexpr uint8_t kIntelPowerModeLowPower = 0; +constexpr uint8_t kIntelPowerModeHighQuality = 1; + using AwbModeTemperatureMap = std::map<uint8_t, int32_t>; const AwbModeTemperatureMap& GetAwbModeTemperatureMap() { @@ -615,10 +619,9 @@ void CameraDeviceDelegate::ReconfigureStreams( DCHECK(ipc_task_runner_->BelongsToCurrentThread()); chrome_capture_params_ = params; if (request_manager_) { - // ReconfigureStreams is used for video recording. It does not require - // photo. - request_manager_->StopPreview(base::BindOnce( - &CameraDeviceDelegate::OnFlushed, GetWeakPtr(), false, absl::nullopt)); + request_manager_->StopPreview( + base::BindOnce(&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), + ShouldUseBlobVideoSnapshot(), absl::nullopt)); } } @@ -666,13 +669,27 @@ void CameraDeviceDelegate::TakePhotoImpl() { GetWeakPtr(), StreamType::kJpegOutput); if (request_manager_->HasStreamsConfiguredForTakePhoto()) { - camera_3a_controller_->Stabilize3AForStillCapture( - std::move(construct_request_cb)); + auto camera_app_device = + CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice( + device_descriptor_.device_id); + + // Skip 3A stabilization when taking video snapshot to avoid disrupting the + // video recording. + bool should_skip_3a = ShouldUseBlobVideoSnapshot() && camera_app_device && + camera_app_device->GetCaptureIntent() == + cros::mojom::CaptureIntent::VIDEO_RECORD; + if (should_skip_3a) { + std::move(construct_request_cb).Run(); + } else { + camera_3a_controller_->Stabilize3AForStillCapture( + std::move(construct_request_cb)); + } return; } - // Trigger the reconfigure process if it not yet triggered. - if (on_reconfigured_callbacks_.empty()) { + // Trigger the reconfigure process if it is required and is not yet triggered. + if (current_blob_resolution_.IsEmpty() && + on_reconfigured_callbacks_.empty()) { request_manager_->StopPreview(base::BindOnce( &CameraDeviceDelegate::OnFlushed, GetWeakPtr(), true, absl::nullopt)); } @@ -806,6 +823,20 @@ void CameraDeviceDelegate::Initialize() { std::move(callback_ops), base::BindOnce(&CameraDeviceDelegate::OnInitialized, GetWeakPtr())); request_manager_->AddResultMetadataObserver(this); + + // For Intel IPU6 platform, set power mode to high quality for CCA and low + // power mode for others. + const VendorTagInfo* info = + camera_hal_delegate_->GetVendorTagInfoByName(kIntelPowerMode); + if (info != nullptr) { + bool is_cca = + CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice( + device_descriptor_.device_id) != nullptr; + uint8_t power_mode = + is_cca ? kIntelPowerModeHighQuality : kIntelPowerModeLowPower; + request_manager_->SetRepeatingCaptureMetadata( + info->tag, info->type, 1, std::vector<uint8_t>{power_mode}); + } } void CameraDeviceDelegate::OnInitialized(int32_t result) { @@ -825,6 +856,7 @@ void CameraDeviceDelegate::OnInitialized(int32_t result) { base::safe_strerror(-result)); return; } + device_context_->SetState(CameraDeviceContext::State::kInitialized); bool require_photo = [&] { auto camera_app_device = @@ -840,7 +872,7 @@ void CameraDeviceDelegate::OnInitialized(int32_t result) { case cros::mojom::CaptureIntent::STILL_CAPTURE: return true; case cros::mojom::CaptureIntent::VIDEO_RECORD: - return false; + return ShouldUseBlobVideoSnapshot(); case cros::mojom::CaptureIntent::DOCUMENT: return true; default: @@ -1097,12 +1129,12 @@ void CameraDeviceDelegate::ConstructDefaultRequestSettings( CameraDeviceContext::State::kStreamConfigured || device_context_->GetState() == CameraDeviceContext::State::kCapturing); + auto camera_app_device = + CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice( + device_descriptor_.device_id); if (stream_type == StreamType::kPreviewOutput) { // CCA uses the same stream for preview and video recording. Choose proper // template here so the underlying camera HAL can set 3A tuning accordingly. - auto camera_app_device = - CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice( - device_descriptor_.device_id); auto request_template = camera_app_device && camera_app_device->GetCaptureIntent() == cros::mojom::CaptureIntent::VIDEO_RECORD @@ -1114,8 +1146,15 @@ void CameraDeviceDelegate::ConstructDefaultRequestSettings( &CameraDeviceDelegate::OnConstructedDefaultPreviewRequestSettings, GetWeakPtr())); } else if (stream_type == StreamType::kJpegOutput) { + auto request_template = + camera_app_device && camera_app_device->GetCaptureIntent() == + cros::mojom::CaptureIntent::VIDEO_RECORD + ? cros::mojom::Camera3RequestTemplate:: + CAMERA3_TEMPLATE_VIDEO_SNAPSHOT + : cros::mojom::Camera3RequestTemplate:: + CAMERA3_TEMPLATE_STILL_CAPTURE; device_ops_->ConstructDefaultRequestSettings( - cros::mojom::Camera3RequestTemplate::CAMERA3_TEMPLATE_STILL_CAPTURE, + request_template, base::BindOnce(&CameraDeviceDelegate:: OnConstructedDefaultStillCaptureRequestSettings, GetWeakPtr())); @@ -1355,6 +1394,16 @@ mojom::RangePtr CameraDeviceDelegate::GetControlRangeByVendorTagName( return range; } +bool CameraDeviceDelegate::ShouldUseBlobVideoSnapshot() { + auto level = GetMetadataEntryAsSpan<uint8_t>( + static_metadata_, + cros::mojom::CameraMetadataTag::ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL); + DCHECK_EQ(level.size(), 1u); + return level[0] == + static_cast<uint8_t>(cros::mojom::AndroidInfoSupportedHardwareLevel:: + ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL); +} + void CameraDeviceDelegate::OnResultMetadataAvailable( uint32_t frame_number, const cros::mojom::CameraMetadataPtr& result_metadata) { diff --git a/chromium/media/capture/video/chromeos/camera_device_delegate.h b/chromium/media/capture/video/chromeos/camera_device_delegate.h index 3f8c72cfb5e..4b1708d8737 100644 --- a/chromium/media/capture/video/chromeos/camera_device_delegate.h +++ b/chromium/media/capture/video/chromeos/camera_device_delegate.h @@ -9,9 +9,8 @@ #include <queue> #include "base/containers/flat_map.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "media/capture/video/chromeos/camera_device_context.h" #include "media/capture/video/chromeos/capture_metadata_dispatcher.h" #include "media/capture/video/chromeos/mojom/camera3.mojom.h" @@ -116,11 +115,16 @@ class CAPTURE_EXPORT StreamCaptureInterface { class CAPTURE_EXPORT CameraDeviceDelegate final : public CaptureMetadataDispatcher::ResultMetadataObserver { public: + CameraDeviceDelegate() = delete; + CameraDeviceDelegate( VideoCaptureDeviceDescriptor device_descriptor, scoped_refptr<CameraHalDelegate> camera_hal_delegate, scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner); + CameraDeviceDelegate(const CameraDeviceDelegate&) = delete; + CameraDeviceDelegate& operator=(const CameraDeviceDelegate&) = delete; + ~CameraDeviceDelegate() final; // Delegation methods for the VideoCaptureDevice interface. @@ -230,6 +234,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final const std::string& range_name, const absl::optional<int32_t>& current); + bool ShouldUseBlobVideoSnapshot(); + // CaptureMetadataDispatcher::ResultMetadataObserver implementation. void OnResultMetadataAvailable( uint32_t frame_number, @@ -301,8 +307,6 @@ class CAPTURE_EXPORT CameraDeviceDelegate final gfx::Rect active_array_size_; base::WeakPtrFactory<CameraDeviceDelegate> weak_ptr_factory_{this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(CameraDeviceDelegate); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/camera_device_delegate_unittest.cc b/chromium/media/capture/video/chromeos/camera_device_delegate_unittest.cc index 1c3b7a154c5..c481f80b01c 100644 --- a/chromium/media/capture/video/chromeos/camera_device_delegate_unittest.cc +++ b/chromium/media/capture/video/chromeos/camera_device_delegate_unittest.cc @@ -138,6 +138,9 @@ class CameraDeviceDelegateTest : public ::testing::Test { device_delegate_thread_("DeviceDelegateThread"), hal_delegate_thread_("HalDelegateThread") {} + CameraDeviceDelegateTest(const CameraDeviceDelegateTest&) = delete; + CameraDeviceDelegateTest& operator=(const CameraDeviceDelegateTest&) = delete; + void SetUp() override { VideoCaptureDeviceFactoryChromeOS::SetGpuBufferManager( &mock_gpu_memory_buffer_manager_); @@ -532,7 +535,6 @@ class CameraDeviceDelegateTest : public ::testing::Test { private: base::Thread hal_delegate_thread_; std::unique_ptr<base::RunLoop> run_loop_; - DISALLOW_COPY_AND_ASSIGN(CameraDeviceDelegateTest); }; // Test the complete capture flow: initialize, configure stream, capture one diff --git a/chromium/media/capture/video/chromeos/camera_hal_delegate.cc b/chromium/media/capture/video/chromeos/camera_hal_delegate.cc index c3b6a00f739..ef67081ebda 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_delegate.cc +++ b/chromium/media/capture/video/chromeos/camera_hal_delegate.cc @@ -40,6 +40,8 @@ constexpr base::TimeDelta kEventWaitTimeoutSecs = base::Seconds(1); class LocalCameraClientObserver : public CameraClientObserver { public: + LocalCameraClientObserver() = delete; + explicit LocalCameraClientObserver( scoped_refptr<CameraHalDelegate> camera_hal_delegate, cros::mojom::CameraClientType type, @@ -47,6 +49,10 @@ class LocalCameraClientObserver : public CameraClientObserver { : CameraClientObserver(type, std::move(auth_token)), camera_hal_delegate_(std::move(camera_hal_delegate)) {} + LocalCameraClientObserver(const LocalCameraClientObserver&) = delete; + LocalCameraClientObserver& operator=(const LocalCameraClientObserver&) = + delete; + void OnChannelCreated( mojo::PendingRemote<cros::mojom::CameraModule> camera_module) override { camera_hal_delegate_->SetCameraModule(std::move(camera_module)); @@ -54,7 +60,6 @@ class LocalCameraClientObserver : public CameraClientObserver { private: scoped_refptr<CameraHalDelegate> camera_hal_delegate_; - DISALLOW_IMPLICIT_CONSTRUCTORS(LocalCameraClientObserver); }; // chromeos::system::StatisticsProvider::IsRunningOnVM() is not available in diff --git a/chromium/media/capture/video/chromeos/camera_hal_delegate.h b/chromium/media/capture/video/chromeos/camera_hal_delegate.h index 0658c432fd9..58c7b0f0e39 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_delegate.h +++ b/chromium/media/capture/video/chromeos/camera_hal_delegate.h @@ -10,11 +10,10 @@ #include <unordered_map> #include "base/containers/flat_map.h" -#include "base/macros.h" #include "base/sequence_checker.h" -#include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread.h" #include "media/capture/video/chromeos/mojom/camera3.mojom.h" #include "media/capture/video/chromeos/mojom/camera_common.mojom.h" @@ -48,6 +47,9 @@ class CAPTURE_EXPORT CameraHalDelegate final explicit CameraHalDelegate( scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner); + CameraHalDelegate(const CameraHalDelegate&) = delete; + CameraHalDelegate& operator=(const CameraHalDelegate&) = delete; + // Registers the camera client observer to the CameraHalDispatcher instance. // Returns true if successful, false if failed (e.g., authentication failure). bool RegisterCameraClient(); @@ -222,8 +224,6 @@ class CAPTURE_EXPORT CameraHalDelegate final // A map from camera id to corresponding delegate instance. base::flat_map<int, std::unique_ptr<VideoCaptureDeviceChromeOSDelegate>> vcd_delegate_map_; - - DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/camera_hal_delegate_unittest.cc b/chromium/media/capture/video/chromeos/camera_hal_delegate_unittest.cc index a3cd9a46a27..e0a740f045c 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_delegate_unittest.cc +++ b/chromium/media/capture/video/chromeos/camera_hal_delegate_unittest.cc @@ -40,6 +40,9 @@ class CameraHalDelegateTest : public ::testing::Test { public: CameraHalDelegateTest() : hal_delegate_thread_("HalDelegateThread") {} + CameraHalDelegateTest(const CameraHalDelegateTest&) = delete; + CameraHalDelegateTest& operator=(const CameraHalDelegateTest&) = delete; + void SetUp() override { VideoCaptureDeviceFactoryChromeOS::SetGpuBufferManager( &mock_gpu_memory_buffer_manager_); @@ -70,7 +73,6 @@ class CameraHalDelegateTest : public ::testing::Test { private: base::Thread hal_delegate_thread_; std::unique_ptr<base::RunLoop> run_loop_; - DISALLOW_COPY_AND_ASSIGN(CameraHalDelegateTest); }; TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) { diff --git a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.cc b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.cc index 07ade5dbc04..aef8354f441 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.cc +++ b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.cc @@ -21,9 +21,9 @@ #include "base/notreached.h" #include "base/posix/eintr_wrapper.h" #include "base/rand_util.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/synchronization/waitable_event.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/sequenced_task_runner_handle.h" #include "base/trace_event/trace_event.h" #include "chromeos/components/sensors/sensor_util.h" @@ -53,6 +53,10 @@ const base::FilePath::CharType kForceEnableHdrNetPath[] = "/run/camera/force_enable_hdrnet"; const base::FilePath::CharType kForceDisableHdrNetPath[] = "/run/camera/force_disable_hdrnet"; +const base::FilePath::CharType kForceEnableAutoFramingPath[] = + "/run/camera/force_enable_auto_framing"; +const base::FilePath::CharType kForceDisableAutoFramingPath[] = + "/run/camera/force_disable_auto_framing"; std::string GenerateRandomToken() { char random_bytes[16]; @@ -94,6 +98,8 @@ bool HasCrosCameraTest() { class MojoCameraClientObserver : public CameraClientObserver { public: + MojoCameraClientObserver() = delete; + explicit MojoCameraClientObserver( mojo::PendingRemote<cros::mojom::CameraHalClient> client, cros::mojom::CameraClientType type, @@ -101,6 +107,9 @@ class MojoCameraClientObserver : public CameraClientObserver { : CameraClientObserver(type, std::move(auth_token)), client_(std::move(client)) {} + MojoCameraClientObserver(const MojoCameraClientObserver&) = delete; + MojoCameraClientObserver& operator=(const MojoCameraClientObserver&) = delete; + void OnChannelCreated( mojo::PendingRemote<cros::mojom::CameraModule> camera_module) override { client_->SetUpChannel(std::move(camera_module)); @@ -110,7 +119,6 @@ class MojoCameraClientObserver : public CameraClientObserver { private: mojo::Remote<cros::mojom::CameraHalClient> client_; - DISALLOW_IMPLICIT_CONSTRUCTORS(MojoCameraClientObserver); }; } // namespace @@ -192,10 +200,12 @@ bool CameraHalDispatcherImpl::Start( if (command_line->HasSwitch(media::switches::kForceControlFaceAe)) { if (command_line->GetSwitchValueASCII( media::switches::kForceControlFaceAe) == "enable") { - base::File file(enable_file_path, base::File::FLAG_CREATE_ALWAYS); + base::File file(enable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); file.Close(); } else { - base::File file(disable_file_path, base::File::FLAG_CREATE_ALWAYS); + base::File file(disable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); file.Close(); } } @@ -216,10 +226,38 @@ bool CameraHalDispatcherImpl::Start( std::string value = command_line->GetSwitchValueASCII(switches::kHdrNetOverride); if (value == switches::kHdrNetForceEnabled) { - base::File file(enable_file_path, base::File::FLAG_CREATE_ALWAYS); + base::File file(enable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); file.Close(); } else if (value == switches::kHdrNetForceDisabled) { - base::File file(disable_file_path, base::File::FLAG_CREATE_ALWAYS); + base::File file(disable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); + file.Close(); + } + } + } + + { + base::FilePath enable_file_path(kForceEnableAutoFramingPath); + base::FilePath disable_file_path(kForceDisableAutoFramingPath); + if (!base::DeleteFile(enable_file_path)) { + LOG(WARNING) << "Could not delete " << kForceEnableAutoFramingPath; + } + if (!base::DeleteFile(disable_file_path)) { + LOG(WARNING) << "Could not delete " << kForceDisableAutoFramingPath; + } + const base::CommandLine* command_line = + base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(media::switches::kAutoFramingOverride)) { + std::string value = + command_line->GetSwitchValueASCII(switches::kAutoFramingOverride); + if (value == switches::kAutoFramingForceEnabled) { + base::File file(enable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); + file.Close(); + } else if (value == switches::kAutoFramingForceDisabled) { + base::File file(disable_file_path, base::File::FLAG_CREATE_ALWAYS | + base::File::FLAG_WRITE); file.Close(); } } diff --git a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.h b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.h index fccc79e885d..f86e5239c11 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.h +++ b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl.h @@ -133,6 +133,9 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final public: static CameraHalDispatcherImpl* GetInstance(); + CameraHalDispatcherImpl(const CameraHalDispatcherImpl&) = delete; + CameraHalDispatcherImpl& operator=(const CameraHalDispatcherImpl&) = delete; + bool Start(MojoMjpegDecodeAcceleratorFactoryCB jda_factory, MojoJpegEncodeAcceleratorFactoryCB jea_factory); @@ -293,8 +296,6 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final privacy_switch_observers_; base::WeakPtrFactory<CameraHalDispatcherImpl> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(CameraHalDispatcherImpl); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl_unittest.cc b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl_unittest.cc index f8308a056aa..832bf6d4ca7 100644 --- a/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl_unittest.cc +++ b/chromium/media/capture/video/chromeos/camera_hal_dispatcher_impl_unittest.cc @@ -10,8 +10,8 @@ #include "base/bind.h" #include "base/posix/safe_strerror.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "media/capture/video/chromeos/mojom/camera_common.mojom.h" #include "media/capture/video/chromeos/mojom/cros_camera_client.mojom.h" diff --git a/chromium/media/capture/video/chromeos/display_rotation_observer.h b/chromium/media/capture/video/chromeos/display_rotation_observer.h index 9dfebe1573c..87716e299d4 100644 --- a/chromium/media/capture/video/chromeos/display_rotation_observer.h +++ b/chromium/media/capture/video/chromeos/display_rotation_observer.h @@ -6,7 +6,7 @@ #define MEDIA_CAPTURE_VIDEO_CHROMEOS_DISPLAY_ROTATION_OBSERVER_H_ #include "base/memory/ref_counted.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "ui/display/display.h" #include "ui/display/display_observer.h" #include "ui/display/screen.h" @@ -29,6 +29,10 @@ class ScreenObserverDelegate DisplayRotationObserver* observer, scoped_refptr<base::SingleThreadTaskRunner> display_task_runner); + ScreenObserverDelegate() = delete; + ScreenObserverDelegate(const ScreenObserverDelegate&) = delete; + ScreenObserverDelegate& operator=(const ScreenObserverDelegate&) = delete; + // The user must call RemoveObserver() to drop the reference to |observer_| in // ScreenObserverDelegate before deleting |observer_|. void RemoveObserver(); @@ -60,8 +64,6 @@ class ScreenObserverDelegate const scoped_refptr<base::SingleThreadTaskRunner> display_task_runner_; // The task runner on which the ScreenObserverDelegate is created. const scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/request_manager.h b/chromium/media/capture/video/chromeos/request_manager.h index a078343f508..c81b1f52817 100644 --- a/chromium/media/capture/video/chromeos/request_manager.h +++ b/chromium/media/capture/video/chromeos/request_manager.h @@ -99,6 +99,8 @@ class CAPTURE_EXPORT RequestManager final int32_t orientation; }; + RequestManager() = delete; + RequestManager(const std::string& device_id, mojo::PendingReceiver<cros::mojom::Camera3CallbackOps> callback_ops_receiver, @@ -109,6 +111,10 @@ class CAPTURE_EXPORT RequestManager final BlobifyCallback blobify_callback, scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner, uint32_t device_api_version); + + RequestManager(const RequestManager&) = delete; + RequestManager& operator=(const RequestManager&) = delete; + ~RequestManager() override; // Sets up the stream context and allocate buffers according to the @@ -382,8 +388,6 @@ class CAPTURE_EXPORT RequestManager final uint32_t device_api_version_; base::WeakPtrFactory<RequestManager> weak_ptr_factory_{this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(RequestManager); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/scoped_video_capture_jpeg_decoder.h b/chromium/media/capture/video/chromeos/scoped_video_capture_jpeg_decoder.h index a047ec729f6..a29892ecc73 100644 --- a/chromium/media/capture/video/chromeos/scoped_video_capture_jpeg_decoder.h +++ b/chromium/media/capture/video/chromeos/scoped_video_capture_jpeg_decoder.h @@ -7,7 +7,7 @@ #include <memory> -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "media/capture/capture_export.h" #include "media/capture/video/chromeos/video_capture_jpeg_decoder.h" diff --git a/chromium/media/capture/video/chromeos/stream_buffer_manager.cc b/chromium/media/capture/video/chromeos/stream_buffer_manager.cc index e9829b88c14..b2e52175d48 100644 --- a/chromium/media/capture/video/chromeos/stream_buffer_manager.cc +++ b/chromium/media/capture/video/chromeos/stream_buffer_manager.cc @@ -41,9 +41,7 @@ StreamBufferManager::~StreamBufferManager() { } void StreamBufferManager::ReserveBuffer(StreamType stream_type) { - // The YUV output buffer for reprocessing is not passed to client, so can be - // allocated by the local buffer factory without zero-copy concerns. - if (video_capture_use_gmb_ && stream_type != StreamType::kYUVOutput) { + if (CanReserveBufferFromPool(stream_type)) { ReserveBufferFromPool(stream_type); } else { ReserveBufferFromFactory(stream_type); @@ -415,6 +413,12 @@ int StreamBufferManager::GetBufferKey(uint64_t buffer_ipc_id) { return buffer_ipc_id & 0xFFFFFFFF; } +bool StreamBufferManager::CanReserveBufferFromPool(StreamType stream_type) { + // The YUV output buffer for reprocessing is not passed to client, so can be + // allocated by the local buffer factory without zero-copy concerns. + return video_capture_use_gmb_ && stream_type != StreamType::kYUVOutput; +} + void StreamBufferManager::ReserveBufferFromFactory(StreamType stream_type) { auto& stream_context = stream_context_[stream_type]; absl::optional<gfx::BufferFormat> gfx_format = @@ -484,7 +488,7 @@ void StreamBufferManager::ReserveBufferFromPool(StreamType stream_type) { void StreamBufferManager::DestroyCurrentStreamsAndBuffers() { for (const auto& iter : stream_context_) { if (iter.second) { - if (!video_capture_use_gmb_) { + if (!CanReserveBufferFromPool(iter.first)) { // The GMB is mapped by default only when it's allocated locally. for (auto& buf : iter.second->buffers) { auto& buf_pair = buf.second; diff --git a/chromium/media/capture/video/chromeos/stream_buffer_manager.h b/chromium/media/capture/video/chromeos/stream_buffer_manager.h index 8e336fd217e..20563f30f81 100644 --- a/chromium/media/capture/video/chromeos/stream_buffer_manager.h +++ b/chromium/media/capture/video/chromeos/stream_buffer_manager.h @@ -17,7 +17,7 @@ #include "base/containers/flat_map.h" #include "base/containers/queue.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "media/capture/video/chromeos/camera_device_context.h" #include "media/capture/video/chromeos/camera_device_delegate.h" #include "media/capture/video/chromeos/mojom/camera3.mojom.h" @@ -50,10 +50,16 @@ class CAPTURE_EXPORT StreamBufferManager final { public: using Buffer = VideoCaptureDevice::Client::Buffer; + StreamBufferManager() = delete; + StreamBufferManager( CameraDeviceContext* device_context, bool video_capture_use_gmb, std::unique_ptr<CameraBufferFactory> camera_buffer_factory); + + StreamBufferManager(const StreamBufferManager&) = delete; + StreamBufferManager& operator=(const StreamBufferManager&) = delete; + ~StreamBufferManager(); void ReserveBuffer(StreamType stream_type); @@ -155,6 +161,7 @@ class CAPTURE_EXPORT StreamBufferManager final { static int GetBufferKey(uint64_t buffer_ipc_id); + bool CanReserveBufferFromPool(StreamType stream_type); void ReserveBufferFromFactory(StreamType stream_type); void ReserveBufferFromPool(StreamType stream_type); // Destroy current streams and unmap mapped buffers. @@ -173,8 +180,6 @@ class CAPTURE_EXPORT StreamBufferManager final { std::unique_ptr<CameraBufferFactory> camera_buffer_factory_; base::WeakPtrFactory<StreamBufferManager> weak_ptr_factory_{this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(StreamBufferManager); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.cc b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.cc index 607a3a04949..137afb9f776 100644 --- a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.cc +++ b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.cc @@ -31,6 +31,9 @@ class VideoCaptureDeviceChromeOSDelegate::PowerManagerClientProxy public: PowerManagerClientProxy() = default; + PowerManagerClientProxy(const PowerManagerClientProxy&) = delete; + PowerManagerClientProxy& operator=(const PowerManagerClientProxy&) = delete; + void Init(base::WeakPtr<VideoCaptureDeviceChromeOSDelegate> device, scoped_refptr<base::SingleThreadTaskRunner> device_task_runner, scoped_refptr<base::SingleThreadTaskRunner> dbus_task_runner) { @@ -98,8 +101,6 @@ class VideoCaptureDeviceChromeOSDelegate::PowerManagerClientProxy base::WeakPtr<VideoCaptureDeviceChromeOSDelegate> device_; scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> dbus_task_runner_; - - DISALLOW_COPY_AND_ASSIGN(PowerManagerClientProxy); }; VideoCaptureDeviceChromeOSDelegate::VideoCaptureDeviceChromeOSDelegate( diff --git a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.h b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.h index 0f13ab818de..02d2c3d6f3b 100644 --- a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.h +++ b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_delegate.h @@ -8,10 +8,9 @@ #include <memory> #include "base/containers/flat_map.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread.h" #include "media/capture/video/chromeos/camera_device_context.h" #include "media/capture/video/chromeos/display_rotation_observer.h" @@ -34,13 +33,21 @@ class CameraDeviceDelegate; class CAPTURE_EXPORT VideoCaptureDeviceChromeOSDelegate final : public DisplayRotationObserver { public: + VideoCaptureDeviceChromeOSDelegate() = delete; + VideoCaptureDeviceChromeOSDelegate( scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, const VideoCaptureDeviceDescriptor& device_descriptor, scoped_refptr<CameraHalDelegate> camera_hal_delegate, base::OnceClosure cleanup_callback); + VideoCaptureDeviceChromeOSDelegate( + const VideoCaptureDeviceChromeOSDelegate&) = delete; + VideoCaptureDeviceChromeOSDelegate& operator=( + const VideoCaptureDeviceChromeOSDelegate&) = delete; + ~VideoCaptureDeviceChromeOSDelegate(); + void Shutdown(); bool HasDeviceClient(); @@ -109,8 +116,6 @@ class CAPTURE_EXPORT VideoCaptureDeviceChromeOSDelegate final base::WeakPtrFactory<VideoCaptureDeviceChromeOSDelegate> weak_ptr_factory_{ this}; - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOSDelegate); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_halv3.h b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_halv3.h index 5c5188a82e5..04ccfd07ea5 100644 --- a/chromium/media/capture/video/chromeos/video_capture_device_chromeos_halv3.h +++ b/chromium/media/capture/video/chromeos/video_capture_device_chromeos_halv3.h @@ -19,10 +19,17 @@ class VideoCaptureDeviceChromeOSDelegate; class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final : public VideoCaptureDevice { public: + VideoCaptureDeviceChromeOSHalv3() = delete; + VideoCaptureDeviceChromeOSHalv3( VideoCaptureDeviceChromeOSDelegate* delegate, const VideoCaptureDeviceDescriptor& vcd_descriptor); + VideoCaptureDeviceChromeOSHalv3(const VideoCaptureDeviceChromeOSHalv3&) = + delete; + VideoCaptureDeviceChromeOSHalv3& operator=( + const VideoCaptureDeviceChromeOSHalv3&) = delete; + ~VideoCaptureDeviceChromeOSHalv3() final; // VideoCaptureDevice implementation. @@ -38,8 +45,6 @@ class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final VideoCaptureDeviceChromeOSDelegate* vcd_delegate_; ClientType client_type_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOSHalv3); }; } // namespace media diff --git a/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc b/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc index 02d527b16ae..c340d374d82 100644 --- a/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc +++ b/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.cc @@ -36,15 +36,21 @@ VideoCaptureDeviceFactoryChromeOS::~VideoCaptureDeviceFactoryChromeOS() { camera_hal_ipc_thread_.Stop(); } -std::unique_ptr<VideoCaptureDevice> -VideoCaptureDeviceFactoryChromeOS::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryChromeOS::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); if (!initialized_) { - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kCrosHalV3DeviceDelegateFailedToInitializeCameraDevice); } - return camera_hal_delegate_->CreateDevice(task_runner_for_screen_observer_, - device_descriptor); + auto device = camera_hal_delegate_->CreateDevice( + task_runner_for_screen_observer_, device_descriptor); + return device + ? VideoCaptureErrorOrDevice(std::move(device)) + : VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); } void VideoCaptureDeviceFactoryChromeOS::GetDevicesInfo( diff --git a/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.h b/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.h index e72de356157..00e1543cd72 100644 --- a/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.h +++ b/chromium/media/capture/video/chromeos/video_capture_device_factory_chromeos.h @@ -7,8 +7,7 @@ #include <memory> -#include "base/macros.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "components/chromeos_camera/common/mjpeg_decode_accelerator.mojom.h" #include "media/capture/video/chromeos/camera_hal_delegate.h" #include "media/capture/video/video_capture_device_factory.h" @@ -34,7 +33,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryChromeOS final ~VideoCaptureDeviceFactoryChromeOS() override; // VideoCaptureDeviceFactory interface implementations. - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) final; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/chromeos/video_capture_features_chromeos.cc b/chromium/media/capture/video/chromeos/video_capture_features_chromeos.cc index a892c838d8c..82570b11a90 100644 --- a/chromium/media/capture/video/chromeos/video_capture_features_chromeos.cc +++ b/chromium/media/capture/video/chromeos/video_capture_features_chromeos.cc @@ -10,6 +10,7 @@ namespace switches { const char kForceControlFaceAe[] = "force-control-face-ae"; const char kHdrNetOverride[] = "hdrnet-override"; +const char kAutoFramingOverride[] = "auto-framing-override"; } // namespace switches diff --git a/chromium/media/capture/video/chromeos/video_capture_features_chromeos.h b/chromium/media/capture/video/chromeos/video_capture_features_chromeos.h index 4170ee32f6a..61edf0cecf5 100644 --- a/chromium/media/capture/video/chromeos/video_capture_features_chromeos.h +++ b/chromium/media/capture/video/chromeos/video_capture_features_chromeos.h @@ -18,6 +18,10 @@ CAPTURE_EXPORT extern const char kHdrNetOverride[]; constexpr char kHdrNetForceEnabled[] = "force-enabled"; constexpr char kHdrNetForceDisabled[] = "force-disabled"; +CAPTURE_EXPORT extern const char kAutoFramingOverride[]; +constexpr char kAutoFramingForceEnabled[] = "force-enabled"; +constexpr char kAutoFramingForceDisabled[] = "force-disabled"; + } // namespace switches namespace features { diff --git a/chromium/media/capture/video/chromeos/video_capture_jpeg_decoder_impl.h b/chromium/media/capture/video/chromeos/video_capture_jpeg_decoder_impl.h index 9f464ea1c30..700b3f0c6a9 100644 --- a/chromium/media/capture/video/chromeos/video_capture_jpeg_decoder_impl.h +++ b/chromium/media/capture/video/chromeos/video_capture_jpeg_decoder_impl.h @@ -12,7 +12,6 @@ #include <string> #include "base/callback.h" -#include "base/macros.h" #include "base/memory/unsafe_shared_memory_region.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" diff --git a/chromium/media/capture/video/create_video_capture_device_factory.cc b/chromium/media/capture/video/create_video_capture_device_factory.cc index fe803c89875..38028fd5abb 100644 --- a/chromium/media/capture/video/create_video_capture_device_factory.cc +++ b/chromium/media/capture/video/create_video_capture_device_factory.cc @@ -5,6 +5,7 @@ #include "media/capture/video/create_video_capture_device_factory.h" #include "base/command_line.h" +#include "base/system/sys_info.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "media/base/media_switches.h" @@ -16,6 +17,7 @@ #elif BUILDFLAG(IS_CHROMEOS_ASH) #include "media/capture/video/chromeos/public/cros_features.h" #include "media/capture/video/chromeos/video_capture_device_factory_chromeos.h" +#include "media/capture/video/linux/video_capture_device_factory_linux.h" #elif defined(OS_WIN) #include "media/capture/video/win/video_capture_device_factory_win.h" #elif defined(OS_MAC) @@ -56,7 +58,9 @@ CreatePlatformSpecificVideoCaptureDeviceFactory( #if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) return std::make_unique<VideoCaptureDeviceFactoryLinux>(ui_task_runner); #elif BUILDFLAG(IS_CHROMEOS_ASH) - return std::make_unique<VideoCaptureDeviceFactoryChromeOS>(ui_task_runner); + if (base::SysInfo::IsRunningOnChromeOS()) + return std::make_unique<VideoCaptureDeviceFactoryChromeOS>(ui_task_runner); + return std::make_unique<VideoCaptureDeviceFactoryLinux>(ui_task_runner); #elif defined(OS_WIN) return std::make_unique<VideoCaptureDeviceFactoryWin>(); #elif defined(OS_MAC) diff --git a/chromium/media/capture/video/create_video_capture_device_factory.h b/chromium/media/capture/video/create_video_capture_device_factory.h index a88b667c486..36872c17e44 100644 --- a/chromium/media/capture/video/create_video_capture_device_factory.h +++ b/chromium/media/capture/video/create_video_capture_device_factory.h @@ -7,7 +7,7 @@ #include <memory> -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "build/chromeos_buildflags.h" #include "media/capture/capture_export.h" #include "media/capture/video/video_capture_device_factory.h" diff --git a/chromium/media/capture/video/fake_video_capture_device.cc b/chromium/media/capture/video/fake_video_capture_device.cc index 608f28606e0..df02a71c7df 100644 --- a/chromium/media/capture/video/fake_video_capture_device.cc +++ b/chromium/media/capture/video/fake_video_capture_device.cc @@ -11,10 +11,10 @@ #include "base/bind.h" #include "base/cxx17_backports.h" #include "base/location.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" #include "base/strings/stringprintf.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_checker.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" @@ -200,7 +200,7 @@ class FrameDeliverer { private: const std::unique_ptr<PacmanFramePainter> frame_painter_; - const FakeDeviceState* device_state_ = nullptr; + raw_ptr<const FakeDeviceState> device_state_ = nullptr; std::unique_ptr<VideoCaptureDevice::Client> client_; base::TimeTicks first_ref_time_; }; @@ -258,7 +258,7 @@ class GpuMemoryBufferFrameDeliverer : public FrameDeliverer { void PaintAndDeliverNextFrame(base::TimeDelta timestamp_to_paint) override; private: - gpu::GpuMemoryBufferSupport* gmb_support_; + raw_ptr<gpu::GpuMemoryBufferSupport> gmb_support_; }; FrameDelivererFactory::FrameDelivererFactory( diff --git a/chromium/media/capture/video/fake_video_capture_device.h b/chromium/media/capture/video/fake_video_capture_device.h index 6de494f144f..f8daa30907a 100644 --- a/chromium/media/capture/video/fake_video_capture_device.h +++ b/chromium/media/capture/video/fake_video_capture_device.h @@ -10,6 +10,7 @@ #include <memory> #include <vector> +#include "base/memory/raw_ptr.h" #include "base/threading/thread_checker.h" #include "media/capture/video/video_capture_device.h" @@ -47,7 +48,7 @@ class PacmanFramePainter { int bytes_per_row); const Format pixel_format_; - const FakeDeviceState* fake_device_state_ = nullptr; + raw_ptr<const FakeDeviceState> fake_device_state_ = nullptr; }; // Implementation of VideoCaptureDevice that generates test frames. This is @@ -157,7 +158,7 @@ class FrameDelivererFactory { private: const FakeVideoCaptureDevice::DeliveryMode delivery_mode_; - const FakeDeviceState* device_state_ = nullptr; + raw_ptr<const FakeDeviceState> device_state_ = nullptr; std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support_; }; @@ -185,7 +186,7 @@ class FakePhotoDevice { private: const std::unique_ptr<PacmanFramePainter> sk_n32_painter_; - const FakeDeviceState* const fake_device_state_; + const raw_ptr<const FakeDeviceState> fake_device_state_; const FakePhotoDeviceConfig config_; }; diff --git a/chromium/media/capture/video/fake_video_capture_device_factory.cc b/chromium/media/capture/video/fake_video_capture_device_factory.cc index 222e0ab1582..34c4da22a47 100644 --- a/chromium/media/capture/video/fake_video_capture_device_factory.cc +++ b/chromium/media/capture/video/fake_video_capture_device_factory.cc @@ -187,16 +187,21 @@ void FakeVideoCaptureDeviceFactory::SetToCustomDevicesConfig( devices_config_ = config; } -std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( +VideoCaptureErrorOrDevice FakeVideoCaptureDeviceFactory::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); for (const auto& entry : devices_config_) { if (device_descriptor.device_id != entry.device_id) continue; - return CreateDeviceWithSettings(entry); + auto device = CreateDeviceWithSettings(entry); + return device ? VideoCaptureErrorOrDevice(std::move(device)) + : VideoCaptureErrorOrDevice( + VideoCaptureError:: + kErrorFakeDeviceIntentionallyEmittingErrorEvent); } - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError::kErrorFakeDeviceIntentionallyEmittingErrorEvent); } void FakeVideoCaptureDeviceFactory::GetDevicesInfo( diff --git a/chromium/media/capture/video/fake_video_capture_device_factory.h b/chromium/media/capture/video/fake_video_capture_device_factory.h index fd83b0977d8..95003bea1cf 100644 --- a/chromium/media/capture/video/fake_video_capture_device_factory.h +++ b/chromium/media/capture/video/fake_video_capture_device_factory.h @@ -80,7 +80,7 @@ class CAPTURE_EXPORT FakeVideoCaptureDeviceFactory const std::vector<FakeVideoCaptureDeviceSettings>& config); // VideoCaptureDeviceFactory implementation: - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/fake_video_capture_device_unittest.cc b/chromium/media/capture/video/fake_video_capture_device_unittest.cc index b75a4ad32cb..6c7c57a76db 100644 --- a/chromium/media/capture/video/fake_video_capture_device_unittest.cc +++ b/chromium/media/capture/video/fake_video_capture_device_unittest.cc @@ -436,9 +436,11 @@ TEST_F(FakeVideoCaptureDeviceFactoryTest, DeviceWithNoSupportedFormats) { EXPECT_EQ(1u, devices_info_.size()); VideoCaptureFormats& supported_formats = devices_info_[0].supported_formats; EXPECT_EQ(0u, supported_formats.size()); - auto device = + + VideoCaptureErrorOrDevice device_status = video_capture_device_factory_->CreateDevice(devices_info_[0].descriptor); - EXPECT_TRUE(device.get()); + ASSERT_TRUE(device_status.ok()); + auto device = device_status.ReleaseDevice(); auto client = CreateClient(); EXPECT_CALL(*client, OnError(_, _, _)); @@ -474,9 +476,10 @@ TEST_P(FakeVideoCaptureDeviceFactoryTest, supported_formats_entry.pixel_format); } - std::unique_ptr<VideoCaptureDevice> device = + VideoCaptureErrorOrDevice device_status = video_capture_device_factory_->CreateDevice(device_info.descriptor); - ASSERT_TRUE(device); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device = device_status.ReleaseDevice(); VideoCaptureParams capture_params; capture_params.requested_format.frame_size.SetSize(1280, 720); diff --git a/chromium/media/capture/video/file_video_capture_device.cc b/chromium/media/capture/video/file_video_capture_device.cc index f91e8517734..7308e9f188c 100644 --- a/chromium/media/capture/video/file_video_capture_device.cc +++ b/chromium/media/capture/video/file_video_capture_device.cc @@ -13,11 +13,10 @@ #include "base/cxx17_backports.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" #include "base/strings/string_util.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "media/base/video_frame.h" #include "media/capture/mojom/image_capture_types.h" diff --git a/chromium/media/capture/video/file_video_capture_device.h b/chromium/media/capture/video/file_video_capture_device.h index b66951725e7..c3dd666d06f 100644 --- a/chromium/media/capture/video/file_video_capture_device.h +++ b/chromium/media/capture/video/file_video_capture_device.h @@ -12,7 +12,6 @@ #include "base/containers/queue.h" #include "base/files/file.h" #include "base/files/memory_mapped_file.h" -#include "base/macros.h" #include "base/threading/thread.h" #include "base/threading/thread_checker.h" #include "gpu/ipc/common/gpu_memory_buffer_support.h" diff --git a/chromium/media/capture/video/file_video_capture_device_factory.cc b/chromium/media/capture/video/file_video_capture_device_factory.cc index 7c47a23f4f9..7ff8e8291be 100644 --- a/chromium/media/capture/video/file_video_capture_device_factory.cc +++ b/chromium/media/capture/video/file_video_capture_device_factory.cc @@ -26,16 +26,16 @@ base::FilePath GetFilePathFromCommandLine() { return command_line_file_path; } -std::unique_ptr<VideoCaptureDevice> FileVideoCaptureDeviceFactory::CreateDevice( +VideoCaptureErrorOrDevice FileVideoCaptureDeviceFactory::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::BlockingType::MAY_BLOCK); #if defined(OS_WIN) - return std::unique_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice( + return VideoCaptureErrorOrDevice(std::make_unique<FileVideoCaptureDevice>( base::FilePath(base::SysUTF8ToWide(device_descriptor.display_name())))); #else - return std::unique_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice( + return VideoCaptureErrorOrDevice(std::make_unique<FileVideoCaptureDevice>( base::FilePath(device_descriptor.display_name()))); #endif } diff --git a/chromium/media/capture/video/file_video_capture_device_factory.h b/chromium/media/capture/video/file_video_capture_device_factory.h index 5c8e0592e2e..503dc594270 100644 --- a/chromium/media/capture/video/file_video_capture_device_factory.h +++ b/chromium/media/capture/video/file_video_capture_device_factory.h @@ -21,7 +21,7 @@ class CAPTURE_EXPORT FileVideoCaptureDeviceFactory FileVideoCaptureDeviceFactory() {} ~FileVideoCaptureDeviceFactory() override {} - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; }; diff --git a/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.cc b/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.cc index ab3f4feea41..958e54d0f52 100644 --- a/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.cc +++ b/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.cc @@ -113,8 +113,7 @@ VideoCaptureDeviceFactoryFuchsia::~VideoCaptureDeviceFactoryFuchsia() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); } -std::unique_ptr<VideoCaptureDevice> -VideoCaptureDeviceFactoryFuchsia::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryFuchsia::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); uint64_t device_id; @@ -123,7 +122,9 @@ VideoCaptureDeviceFactoryFuchsia::CreateDevice( // Test may call CreateDevice() with an invalid |device_id|. if (!converted) - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); // CreateDevice() may be called before GetDeviceDescriptors(). Make sure // |device_watcher_| is initialized. @@ -132,7 +133,8 @@ VideoCaptureDeviceFactoryFuchsia::CreateDevice( fidl::InterfaceHandle<fuchsia::camera3::Device> device; device_watcher_->ConnectToDevice(device_id, device.NewRequest()); - return std::make_unique<VideoCaptureDeviceFuchsia>(std::move(device)); + return VideoCaptureErrorOrDevice( + std::make_unique<VideoCaptureDeviceFuchsia>(std::move(device))); } void VideoCaptureDeviceFactoryFuchsia::GetDevicesInfo( diff --git a/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.h b/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.h index eeafa468882..49ea546bef5 100644 --- a/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.h +++ b/chromium/media/capture/video/fuchsia/video_capture_device_factory_fuchsia.h @@ -27,7 +27,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryFuchsia const VideoCaptureDeviceFactoryFuchsia&) = delete; // VideoCaptureDeviceFactory implementation. - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia.cc b/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia.cc index 33159564011..faba35d96aa 100644 --- a/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia.cc +++ b/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia.cc @@ -370,7 +370,7 @@ void VideoCaptureDeviceFuchsia::ProcessNewFrame( ++frames_received_; float frame_rate = - (timestamp > base::TimeDelta()) + (timestamp.is_positive()) ? static_cast<float>(frames_received_) / timestamp.InSecondsF() : 0.0; VideoCaptureFormat capture_format(output_size, frame_rate, PIXEL_FORMAT_I420); diff --git a/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia_test.cc b/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia_test.cc index 63484483d97..aa8e473dbd0 100644 --- a/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia_test.cc +++ b/chromium/media/capture/video/fuchsia/video_capture_device_fuchsia_test.cc @@ -222,7 +222,8 @@ class VideoCaptureDeviceFuchsiaTest : public testing::Test { void CreateDevice() { auto devices_info = GetDevicesInfo(); ASSERT_EQ(devices_info.size(), 1U); - device_ = device_factory_.CreateDevice(devices_info[0].descriptor); + device_ = device_factory_.CreateDevice(devices_info[0].descriptor) + .ReleaseDevice(); } FakeCameraStream* GetDefaultCameraStream() { @@ -404,7 +405,8 @@ TEST_F(VideoCaptureDeviceFuchsiaTest, base::RunLoop().RunUntilIdle(); // The factory is expected to reconnect DeviceWatcher. - device_ = device_factory_.CreateDevice(devices_info[0].descriptor); + device_ = + device_factory_.CreateDevice(devices_info[0].descriptor).ReleaseDevice(); StartCapturer(); diff --git a/chromium/media/capture/video/linux/v4l2_capture_delegate.h b/chromium/media/capture/video/linux/v4l2_capture_delegate.h index 1fceb61e8e2..e867210a79f 100644 --- a/chromium/media/capture/video/linux/v4l2_capture_delegate.h +++ b/chromium/media/capture/video/linux/v4l2_capture_delegate.h @@ -14,7 +14,6 @@ #include "base/containers/queue.h" #include "base/files/scoped_file.h" -#include "base/macros.h" #include "build/build_config.h" #include "media/capture/video/linux/scoped_v4l2_device_fd.h" #include "media/capture/video/linux/v4l2_capture_device_impl.h" diff --git a/chromium/media/capture/video/linux/video_capture_device_factory_linux.cc b/chromium/media/capture/video/linux/video_capture_device_factory_linux.cc index 6724957d80a..c544563f3c8 100644 --- a/chromium/media/capture/video/linux/video_capture_device_factory_linux.cc +++ b/chromium/media/capture/video/linux/video_capture_device_factory_linux.cc @@ -130,8 +130,7 @@ void VideoCaptureDeviceFactoryLinux::SetV4L2EnvironmentForTesting( device_provider_ = std::move(device_provider); } -std::unique_ptr<VideoCaptureDevice> -VideoCaptureDeviceFactoryLinux::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryLinux::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); auto self = @@ -145,10 +144,11 @@ VideoCaptureDeviceFactoryLinux::CreateDevice( HANDLE_EINTR(v4l2_->open(device_descriptor.device_id.c_str(), O_RDONLY))); if (!fd.is_valid()) { DLOG(ERROR) << "Cannot open device"; - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError::kV4L2FailedToOpenV4L2DeviceDriverFile); } - return self; + return VideoCaptureErrorOrDevice(std::move(self)); } void VideoCaptureDeviceFactoryLinux::GetDevicesInfo( diff --git a/chromium/media/capture/video/linux/video_capture_device_factory_linux.h b/chromium/media/capture/video/linux/video_capture_device_factory_linux.h index 82a4275e359..c80fae457c2 100644 --- a/chromium/media/capture/video/linux/video_capture_device_factory_linux.h +++ b/chromium/media/capture/video/linux/video_capture_device_factory_linux.h @@ -13,8 +13,7 @@ #include <string> #include <vector> -#include "base/macros.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "media/capture/video/linux/v4l2_capture_device.h" #include "media/capture/video_capture_types.h" @@ -47,7 +46,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryLinux scoped_refptr<V4L2CaptureDevice> v4l2, std::unique_ptr<DeviceProvider> device_provider); - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/linux/video_capture_device_factory_linux_unittest.cc b/chromium/media/capture/video/linux/video_capture_device_factory_linux_unittest.cc index a98b8c0eb78..8fe25871bac 100644 --- a/chromium/media/capture/video/linux/video_capture_device_factory_linux_unittest.cc +++ b/chromium/media/capture/video/linux/video_capture_device_factory_linux_unittest.cc @@ -100,7 +100,7 @@ TEST_F(VideoCaptureDeviceFactoryLinuxTest, fake_v4l2_->AddDevice(stub_device_id, FakeV4L2DeviceConfig(descriptor)); // Exercise - auto device = factory_->CreateDevice(descriptor); + auto device = factory_->CreateDevice(descriptor).ReleaseDevice(); VideoCaptureParams arbitrary_params; arbitrary_params.requested_format.frame_size = gfx::Size(1280, 720); arbitrary_params.requested_format.frame_rate = 30.0f; diff --git a/chromium/media/capture/video/linux/video_capture_device_linux.cc b/chromium/media/capture/video/linux/video_capture_device_linux.cc index 123c0f51eec..ee98b83992c 100644 --- a/chromium/media/capture/video/linux/video_capture_device_linux.cc +++ b/chromium/media/capture/video/linux/video_capture_device_linux.cc @@ -9,7 +9,7 @@ #include <utility> #include "base/bind.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "build/build_config.h" #include "media/capture/video/linux/v4l2_capture_delegate.h" diff --git a/chromium/media/capture/video/linux/video_capture_device_linux.h b/chromium/media/capture/video/linux/video_capture_device_linux.h index 88e9263fb4a..08de3f0d477 100644 --- a/chromium/media/capture/video/linux/video_capture_device_linux.h +++ b/chromium/media/capture/video/linux/video_capture_device_linux.h @@ -17,7 +17,6 @@ #include "base/files/file_util.h" #include "base/files/scoped_file.h" -#include "base/macros.h" #include "base/threading/thread.h" #include "media/capture/video/linux/v4l2_capture_device_impl.h" #include "media/capture/video/video_capture_device.h" @@ -33,9 +32,15 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice { static VideoPixelFormat V4l2FourCcToChromiumPixelFormat(uint32_t v4l2_fourcc); static std::vector<uint32_t> GetListOfUsableFourCCs(bool favour_mjpeg); + VideoCaptureDeviceLinux() = delete; + explicit VideoCaptureDeviceLinux( scoped_refptr<V4L2CaptureDevice> v4l2, const VideoCaptureDeviceDescriptor& device_descriptor); + + VideoCaptureDeviceLinux(const VideoCaptureDeviceLinux&) = delete; + VideoCaptureDeviceLinux& operator=(const VideoCaptureDeviceLinux&) = delete; + ~VideoCaptureDeviceLinux() override; // VideoCaptureDevice implementation. @@ -72,8 +77,6 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice { int rotation_; SEQUENCE_CHECKER(sequence_checker_); - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux); }; } // namespace media diff --git a/chromium/media/capture/video/mac/sample_buffer_transformer_mac_unittest.mm b/chromium/media/capture/video/mac/sample_buffer_transformer_mac_unittest.mm index 3c83dd24d4c..0d454048036 100644 --- a/chromium/media/capture/video/mac/sample_buffer_transformer_mac_unittest.mm +++ b/chromium/media/capture/video/mac/sample_buffer_transformer_mac_unittest.mm @@ -187,7 +187,6 @@ base::ScopedCFTypeRef<CVPixelBufferRef> AddPadding( int height, int padding) { size_t num_planes = CVPixelBufferGetPlaneCount(pixel_buffer); - size_t padded_size = 0; std::vector<size_t> plane_widths; std::vector<size_t> plane_heights; std::vector<size_t> plane_strides; @@ -201,7 +200,6 @@ base::ScopedCFTypeRef<CVPixelBufferRef> AddPadding( plane_heights.push_back(h); plane_widths.push_back(w); plane_strides.push_back(padded_stride); - padded_size += h * padded_stride; } } else { // CVPixelBufferGetPlaneCount returns 0 for non-planar buffers. @@ -209,7 +207,6 @@ base::ScopedCFTypeRef<CVPixelBufferRef> AddPadding( size_t plane_stride = CVPixelBufferGetBytesPerRow(pixel_buffer); size_t padded_stride = plane_stride + padding; size_t h = CVPixelBufferGetHeight(pixel_buffer); - padded_size += h * padded_stride; plane_heights.push_back(h); plane_strides.push_back(padded_stride); } diff --git a/chromium/media/capture/video/mac/video_capture_device_avfoundation_mac.mm b/chromium/media/capture/video/mac/video_capture_device_avfoundation_mac.mm index 7a0e5068827..73d35e2452c 100644 --- a/chromium/media/capture/video/mac/video_capture_device_avfoundation_mac.mm +++ b/chromium/media/capture/video/mac/video_capture_device_avfoundation_mac.mm @@ -15,10 +15,10 @@ #include "base/location.h" #include "base/mac/foundation_util.h" #include "base/metrics/histogram_macros.h" -#include "base/sequenced_task_runner.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" +#include "base/task/sequenced_task_runner.h" #include "components/crash/core/common/crash_key.h" #include "media/base/mac/color_space_util_mac.h" #include "media/base/media_switches.h" diff --git a/chromium/media/capture/video/mac/video_capture_device_decklink_mac.h b/chromium/media/capture/video/mac/video_capture_device_decklink_mac.h index 7c473c2a7e2..9fe6f842e12 100644 --- a/chromium/media/capture/video/mac/video_capture_device_decklink_mac.h +++ b/chromium/media/capture/video/mac/video_capture_device_decklink_mac.h @@ -14,7 +14,6 @@ #include <stddef.h> #include <stdint.h> -#include "base/macros.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" diff --git a/chromium/media/capture/video/mac/video_capture_device_decklink_mac.mm b/chromium/media/capture/video/mac/video_capture_device_decklink_mac.mm index 8354e8b8a8a..fb403b2553d 100644 --- a/chromium/media/capture/video/mac/video_capture_device_decklink_mac.mm +++ b/chromium/media/capture/video/mac/video_capture_device_decklink_mac.mm @@ -6,8 +6,8 @@ #include <utility> +#include "base/compiler_specific.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/strings/sys_string_conversions.h" #include "base/synchronization/lock.h" @@ -52,6 +52,9 @@ class DeckLinkCaptureDelegate const media::VideoCaptureDeviceDescriptor& device_descriptor, media::VideoCaptureDeviceDeckLinkMac* frame_receiver); + DeckLinkCaptureDelegate(const DeckLinkCaptureDelegate&) = delete; + DeckLinkCaptureDelegate& operator=(const DeckLinkCaptureDelegate&) = delete; + void AllocateAndStart(const media::VideoCaptureParams& params); void StopAndDeAllocate(); @@ -104,8 +107,6 @@ class DeckLinkCaptureDelegate friend class base::RefCountedThreadSafe<DeckLinkCaptureDelegate>; ~DeckLinkCaptureDelegate() override; - - DISALLOW_COPY_AND_ASSIGN(DeckLinkCaptureDelegate); }; static float GetDisplayModeFrameRate( @@ -385,6 +386,7 @@ void VideoCaptureDeviceDeckLinkMac::EnumerateDevices( DVLOG_IF(1, hr != S_OK) << "Error reading Blackmagic device display name"; DVLOG_IF(1, hr == S_OK) << "Blackmagic device found with name: " << base::SysCFStringRefToUTF8(device_display_name); + ALLOW_UNUSED_LOCAL(hr); if (!device_model_name && !device_display_name) continue; diff --git a/chromium/media/capture/video/mac/video_capture_device_factory_mac.h b/chromium/media/capture/video/mac/video_capture_device_factory_mac.h index 54dd57db1cf..1f6dda8cd3c 100644 --- a/chromium/media/capture/video/mac/video_capture_device_factory_mac.h +++ b/chromium/media/capture/video/mac/video_capture_device_factory_mac.h @@ -7,7 +7,6 @@ #ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_FACTORY_MAC_H_ #define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_FACTORY_MAC_H_ -#include "base/macros.h" #include "media/capture/video/video_capture_device_factory.h" namespace media { @@ -27,7 +26,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryMac static void SetGetDevicesInfoRetryCount(int count); static int GetGetDevicesInfoRetryCount(); - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; }; diff --git a/chromium/media/capture/video/mac/video_capture_device_factory_mac.mm b/chromium/media/capture/video/mac/video_capture_device_factory_mac.mm index 28b6f40b74a..b4755522aab 100644 --- a/chromium/media/capture/video/mac/video_capture_device_factory_mac.mm +++ b/chromium/media/capture/video/mac/video_capture_device_factory_mac.mm @@ -13,10 +13,10 @@ #include "base/bind.h" #include "base/cxx17_backports.h" #include "base/location.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_util.h" #include "base/strings/sys_string_conversions.h" -#include "base/task_runner_util.h" +#include "base/task/single_thread_task_runner.h" +#include "base/task/task_runner_util.h" #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" #import "media/capture/video/mac/video_capture_device_avfoundation_utils_mac.h" #import "media/capture/video/mac/video_capture_device_decklink_mac.h" @@ -112,7 +112,7 @@ int VideoCaptureDeviceFactoryMac::GetGetDevicesInfoRetryCount() { return get_device_descriptors_retry_count; } -std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryMac::CreateDevice( const VideoCaptureDeviceDescriptor& descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_NE(descriptor.capture_api, VideoCaptureApi::UNKNOWN); @@ -130,7 +130,9 @@ std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::CreateDevice( capture_device.reset(); } } - return std::unique_ptr<VideoCaptureDevice>(std::move(capture_device)); + return capture_device ? VideoCaptureErrorOrDevice(std::move(capture_device)) + : VideoCaptureErrorOrDevice( + VideoCaptureError::kMacSetCaptureDeviceFailed); } void VideoCaptureDeviceFactoryMac::GetDevicesInfo( diff --git a/chromium/media/capture/video/mac/video_capture_device_mac.h b/chromium/media/capture/video/mac/video_capture_device_mac.h index 5cb40e8e86d..590b2eabcd6 100644 --- a/chromium/media/capture/video/mac/video_capture_device_mac.h +++ b/chromium/media/capture/video/mac/video_capture_device_mac.h @@ -16,7 +16,6 @@ #include "base/compiler_specific.h" #include "base/mac/scoped_nsobject.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" diff --git a/chromium/media/capture/video/mac/video_capture_device_mac.mm b/chromium/media/capture/video/mac/video_capture_device_mac.mm index 83d4d0a18d1..29f56a28144 100644 --- a/chromium/media/capture/video/mac/video_capture_device_mac.mm +++ b/chromium/media/capture/video/mac/video_capture_device_mac.mm @@ -20,10 +20,9 @@ #include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_ioobject.h" #include "base/mac/scoped_ioplugininterface.h" -#include "base/macros.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/strings/sys_string_conversions.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "media/base/timestamp_constants.h" diff --git a/chromium/media/capture/video/mock_device_factory.cc b/chromium/media/capture/video/mock_device_factory.cc index 3eef341887e..dad140b8ef4 100644 --- a/chromium/media/capture/video/mock_device_factory.cc +++ b/chromium/media/capture/video/mock_device_factory.cc @@ -6,6 +6,8 @@ #include <utility> +#include "base/memory/raw_ptr.h" + namespace { // Report a single hard-coded supported format to clients. @@ -43,7 +45,7 @@ class RawPointerVideoCaptureDevice : public media::VideoCaptureDevice { } private: - media::VideoCaptureDevice* device_; + raw_ptr<media::VideoCaptureDevice> device_; }; } // anonymous namespace @@ -64,12 +66,15 @@ void MockDeviceFactory::RemoveAllDevices() { devices_.clear(); } -std::unique_ptr<media::VideoCaptureDevice> MockDeviceFactory::CreateDevice( +VideoCaptureErrorOrDevice MockDeviceFactory::CreateDevice( const media::VideoCaptureDeviceDescriptor& device_descriptor) { if (devices_.find(device_descriptor) == devices_.end()) - return nullptr; - return std::make_unique<RawPointerVideoCaptureDevice>( - devices_[device_descriptor]); + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); + return VideoCaptureErrorOrDevice( + std::make_unique<RawPointerVideoCaptureDevice>( + devices_[device_descriptor])); } void MockDeviceFactory::GetDevicesInfo(GetDevicesInfoCallback callback) { diff --git a/chromium/media/capture/video/mock_device_factory.h b/chromium/media/capture/video/mock_device_factory.h index 2a87dd1d0d7..2cacc0e4fa8 100644 --- a/chromium/media/capture/video/mock_device_factory.h +++ b/chromium/media/capture/video/mock_device_factory.h @@ -23,7 +23,7 @@ class MockDeviceFactory : public media::VideoCaptureDeviceFactory { void RemoveAllDevices(); // media::VideoCaptureDeviceFactory implementation. - std::unique_ptr<media::VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const media::VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; diff --git a/chromium/media/capture/video/mock_video_capture_device_client.cc b/chromium/media/capture/video/mock_video_capture_device_client.cc index 95e4351dd0d..78e122d8bf5 100644 --- a/chromium/media/capture/video/mock_video_capture_device_client.cc +++ b/chromium/media/capture/video/mock_video_capture_device_client.cc @@ -4,6 +4,7 @@ #include "media/capture/video/mock_video_capture_device_client.h" +#include "base/memory/raw_ptr.h" #include "media/base/video_frame.h" using testing::_; @@ -24,7 +25,7 @@ class StubBufferHandle : public VideoCaptureBufferHandle { private: const size_t mapped_size_; - uint8_t* const data_; + const raw_ptr<uint8_t> data_; }; class StubBufferHandleProvider @@ -56,7 +57,7 @@ class StubBufferHandleProvider private: const size_t mapped_size_; - uint8_t* const data_; + const raw_ptr<uint8_t> data_; }; class StubReadWritePermission @@ -66,7 +67,7 @@ class StubReadWritePermission ~StubReadWritePermission() override { delete[] data_; } private: - uint8_t* const data_; + const raw_ptr<uint8_t> data_; }; VideoCaptureDevice::Client::Buffer CreateStubBuffer(int buffer_id, diff --git a/chromium/media/capture/video/shared_memory_buffer_tracker.cc b/chromium/media/capture/video/shared_memory_buffer_tracker.cc index 6d899b508f6..8609ed16184 100644 --- a/chromium/media/capture/video/shared_memory_buffer_tracker.cc +++ b/chromium/media/capture/video/shared_memory_buffer_tracker.cc @@ -5,6 +5,7 @@ #include "media/capture/video/shared_memory_buffer_tracker.h" #include "base/check.h" +#include "base/memory/raw_ptr.h" #include "base/notreached.h" #include "media/base/video_frame.h" #include "mojo/public/cpp/system/platform_handle.h" @@ -28,7 +29,7 @@ class SharedMemoryBufferTrackerHandle : public media::VideoCaptureBufferHandle { private: const size_t mapped_size_; - uint8_t* data_; + raw_ptr<uint8_t> data_; }; size_t CalculateRequiredBufferSize( diff --git a/chromium/media/capture/video/video_capture_buffer_pool_impl.cc b/chromium/media/capture/video/video_capture_buffer_pool_impl.cc index dae889e5dc2..e567a777f38 100644 --- a/chromium/media/capture/video/video_capture_buffer_pool_impl.cc +++ b/chromium/media/capture/video/video_capture_buffer_pool_impl.cc @@ -279,8 +279,17 @@ VideoCaptureBufferPoolImpl::ReserveForProducerInternal( // Create the new tracker. const int new_buffer_id = next_buffer_id_++; + VideoCaptureBufferType buffer_type = buffer_type_; +#if defined(OS_WIN) + // If the MediaFoundationD3D11VideoCapture path fails, a shared memory buffer + // is sent instead. + if (buffer_type == VideoCaptureBufferType::kGpuMemoryBuffer && + pixel_format != PIXEL_FORMAT_NV12) { + buffer_type = VideoCaptureBufferType::kSharedMemory; + } +#endif std::unique_ptr<VideoCaptureBufferTracker> tracker = - buffer_tracker_factory_->CreateTracker(buffer_type_); + buffer_tracker_factory_->CreateTracker(buffer_type); if (!tracker || !tracker->Init(dimensions, pixel_format, strides)) { DLOG(ERROR) << "Error initializing VideoCaptureBufferTracker"; *buffer_id = kInvalidId; diff --git a/chromium/media/capture/video/video_capture_buffer_pool_impl.h b/chromium/media/capture/video/video_capture_buffer_pool_impl.h index 533f92d8f72..cbfbfcb4581 100644 --- a/chromium/media/capture/video/video_capture_buffer_pool_impl.h +++ b/chromium/media/capture/video/video_capture_buffer_pool_impl.h @@ -10,7 +10,6 @@ #include <map> #include "base/files/file.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/process/process.h" #include "base/synchronization/lock.h" @@ -29,11 +28,17 @@ namespace media { class CAPTURE_EXPORT VideoCaptureBufferPoolImpl : public VideoCaptureBufferPool { public: + VideoCaptureBufferPoolImpl() = delete; + explicit VideoCaptureBufferPoolImpl(VideoCaptureBufferType buffer_type); explicit VideoCaptureBufferPoolImpl( VideoCaptureBufferType buffer_type, int count); + VideoCaptureBufferPoolImpl(const VideoCaptureBufferPoolImpl&) = delete; + VideoCaptureBufferPoolImpl& operator=(const VideoCaptureBufferPoolImpl&) = + delete; + // VideoCaptureBufferPool implementation. base::UnsafeSharedMemoryRegion DuplicateAsUnsafeRegion( int buffer_id) override; @@ -90,8 +95,6 @@ class CAPTURE_EXPORT VideoCaptureBufferPoolImpl const std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory_ GUARDED_BY(lock_); - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl); }; } // namespace media diff --git a/chromium/media/capture/video/video_capture_device.cc b/chromium/media/capture/video/video_capture_device.cc index 9d8d5c5a690..64eb8b37c3f 100644 --- a/chromium/media/capture/video/video_capture_device.cc +++ b/chromium/media/capture/video/video_capture_device.cc @@ -4,12 +4,15 @@ #include "media/capture/video/video_capture_device.h" +#include "base/callback.h" #include "base/command_line.h" #include "base/cxx17_backports.h" #include "base/i18n/timezone.h" #include "base/strings/string_util.h" +#include "base/token.h" #include "build/build_config.h" #include "media/base/media_switches.h" +#include "media/capture/mojom/video_capture_types.mojom.h" namespace media { @@ -59,6 +62,13 @@ operator=(VideoCaptureDevice::Client::Buffer&& other) = default; VideoCaptureDevice::~VideoCaptureDevice() = default; +void VideoCaptureDevice::Crop( + const base::Token& crop_id, + base::OnceCallback<void(media::mojom::CropRequestResult)> callback) { + std::move(callback).Run( + media::mojom::CropRequestResult::kUnsupportedCaptureDevice); +} + void VideoCaptureDevice::GetPhotoState(GetPhotoStateCallback callback) {} void VideoCaptureDevice::SetPhotoOptions(mojom::PhotoSettingsPtr settings, diff --git a/chromium/media/capture/video/video_capture_device.h b/chromium/media/capture/video/video_capture_device.h index 0ee1782bb83..f1b9ebd5af7 100644 --- a/chromium/media/capture/video/video_capture_device.h +++ b/chromium/media/capture/video/video_capture_device.h @@ -23,12 +23,14 @@ #include "base/files/file.h" #include "base/memory/ref_counted.h" #include "base/memory/unsafe_shared_memory_region.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/time/time.h" +#include "base/token.h" #include "build/build_config.h" #include "media/base/video_frame.h" #include "media/capture/capture_export.h" #include "media/capture/mojom/image_capture.mojom.h" +#include "media/capture/mojom/video_capture_types.mojom.h" #include "media/capture/video/video_capture_buffer_handle.h" #include "media/capture/video/video_capture_device_descriptor.h" #include "media/capture/video/video_capture_feedback.h" @@ -317,6 +319,14 @@ class CAPTURE_EXPORT VideoCaptureDevice // StopAndDeAllocate(). Otherwise, its behavior is undefined. virtual void Resume() {} + // Start/stop cropping. + // Non-empty |crop_id| sets (or changes) the crop-target. + // Empty |crop_id| reverts the capture to its original, uncropped state. + // The callback reports success/failure. + virtual void Crop( + const base::Token& crop_id, + base::OnceCallback<void(media::mojom::CropRequestResult)> callback); + // Deallocates the video capturer, possibly asynchronously. // // This call requires the device to do the following things, eventually: put diff --git a/chromium/media/capture/video/video_capture_device_client.cc b/chromium/media/capture/video/video_capture_device_client.cc index a6771881497..91b170df398 100644 --- a/chromium/media/capture/video/video_capture_device_client.cc +++ b/chromium/media/capture/video/video_capture_device_client.cc @@ -571,7 +571,16 @@ VideoCaptureDeviceClient::ReserveOutputBuffer(const gfx::Size& frame_size, if (!base::Contains(buffer_ids_known_by_receiver_, buffer_id)) { media::mojom::VideoBufferHandlePtr buffer_handle = media::mojom::VideoBufferHandle::New(); - switch (target_buffer_type_) { + VideoCaptureBufferType target_buffer_type = target_buffer_type_; +#if defined(OS_WIN) + // If MediaFoundationD3D11VideoCapture fails, a shared memory buffer may be + // sent instead. + if (target_buffer_type == VideoCaptureBufferType::kGpuMemoryBuffer && + pixel_format != PIXEL_FORMAT_NV12) { + target_buffer_type = VideoCaptureBufferType::kSharedMemory; + } +#endif + switch (target_buffer_type) { case VideoCaptureBufferType::kSharedMemory: buffer_handle->set_shared_buffer_handle( buffer_pool_->DuplicateAsMojoBuffer(buffer_id)); diff --git a/chromium/media/capture/video/video_capture_device_client.h b/chromium/media/capture/video/video_capture_device_client.h index f57f2d139f8..26f299d0486 100644 --- a/chromium/media/capture/video/video_capture_device_client.h +++ b/chromium/media/capture/video/video_capture_device_client.h @@ -11,7 +11,6 @@ #include <memory> #include <vector> -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/threading/thread_collision_warner.h" #include "build/chromeos_buildflags.h" diff --git a/chromium/media/capture/video/video_capture_device_client_unittest.cc b/chromium/media/capture/video/video_capture_device_client_unittest.cc index 2c7d97f2870..6387e1409d4 100644 --- a/chromium/media/capture/video/video_capture_device_client_unittest.cc +++ b/chromium/media/capture/video/video_capture_device_client_unittest.cc @@ -10,7 +10,7 @@ #include "base/bind.h" #include "base/check.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "media/base/limits.h" @@ -80,7 +80,7 @@ class VideoCaptureDeviceClientTest : public ::testing::Test { ~VideoCaptureDeviceClientTest() override = default; protected: - NiceMock<MockVideoFrameReceiver>* receiver_; + raw_ptr<NiceMock<MockVideoFrameReceiver>> receiver_; std::unique_ptr<unittest_internal::MockGpuMemoryBufferManager> gpu_memory_buffer_manager_; std::unique_ptr<VideoCaptureDeviceClient> device_client_; diff --git a/chromium/media/capture/video/video_capture_device_factory.cc b/chromium/media/capture/video/video_capture_device_factory.cc index dc668051cf7..963bcdd64c3 100644 --- a/chromium/media/capture/video/video_capture_device_factory.cc +++ b/chromium/media/capture/video/video_capture_device_factory.cc @@ -15,6 +15,29 @@ namespace media { +VideoCaptureErrorOrDevice::VideoCaptureErrorOrDevice( + std::unique_ptr<VideoCaptureDevice> video_device) + : device_(std::move(video_device)), error_code_(VideoCaptureError::kNone) {} + +VideoCaptureErrorOrDevice::VideoCaptureErrorOrDevice(VideoCaptureError err_code) + : error_code_(err_code) { + DCHECK_NE(error_code_, VideoCaptureError::kNone); +} + +VideoCaptureErrorOrDevice::~VideoCaptureErrorOrDevice() = default; + +VideoCaptureErrorOrDevice::VideoCaptureErrorOrDevice( + VideoCaptureErrorOrDevice&& other) + : device_(std::move(other.device_)), error_code_(other.error_code_) {} + +std::unique_ptr<VideoCaptureDevice> VideoCaptureErrorOrDevice::ReleaseDevice() { + DCHECK_EQ(error_code_, VideoCaptureError::kNone); + + error_code_ = VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested; + return std::move(device_); +} + VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() { thread_checker_.DetachFromThread(); } diff --git a/chromium/media/capture/video/video_capture_device_factory.h b/chromium/media/capture/video/video_capture_device_factory.h index a682f7f07ab..210b41f8834 100644 --- a/chromium/media/capture/video/video_capture_device_factory.h +++ b/chromium/media/capture/video/video_capture_device_factory.h @@ -5,8 +5,7 @@ #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_FACTORY_H_ #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_FACTORY_H_ -#include "base/macros.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_checker.h" #include "build/chromeos_buildflags.h" #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" @@ -15,6 +14,29 @@ namespace media { +// VideoCaptureErrorOrDevice stores the result of CreateDevice function. This is +// designed to pass information such that when device creation fails, instead of +// returning a null_ptr, this would store an error_code explaining why the +// creation failed. +class CAPTURE_EXPORT VideoCaptureErrorOrDevice { + public: + explicit VideoCaptureErrorOrDevice( + std::unique_ptr<VideoCaptureDevice> video_device); + explicit VideoCaptureErrorOrDevice(VideoCaptureError err_code); + ~VideoCaptureErrorOrDevice(); + + VideoCaptureErrorOrDevice(VideoCaptureErrorOrDevice&& other); + + bool ok() const { return error_code_ == VideoCaptureError::kNone; } + VideoCaptureError error() const { return error_code_; } + + std::unique_ptr<VideoCaptureDevice> ReleaseDevice(); + + private: + std::unique_ptr<VideoCaptureDevice> device_; + VideoCaptureError error_code_; +}; + // VideoCaptureDeviceFactory is the base class for creation of video capture // devices in the different platforms. VCDFs are created by MediaStreamManager // on UI thread and plugged into VideoCaptureManager, who owns and operates them @@ -36,8 +58,10 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactory { virtual ~VideoCaptureDeviceFactory(); - // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong. - virtual std::unique_ptr<VideoCaptureDevice> CreateDevice( + // Return type is VideoCaptureErrorOrDevice which can be used to access a + // VideoCaptureDevice, if device creation is successful, or a + // VideoCaptureError, if something goes wrong. + virtual VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) = 0; // Enumerates video capture devices and passes the results to the supplied diff --git a/chromium/media/capture/video/video_capture_device_unittest.cc b/chromium/media/capture/video/video_capture_device_unittest.cc index 1e6d5082695..5fdd3412f18 100644 --- a/chromium/media/capture/video/video_capture_device_unittest.cc +++ b/chromium/media/capture/video/video_capture_device_unittest.cc @@ -14,7 +14,7 @@ #include "base/callback_helpers.h" #include "base/memory/ref_counted.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/bind.h" #include "base/test/gmock_callback_support.h" #include "base/test/task_environment.h" @@ -497,12 +497,14 @@ void VideoCaptureDeviceTest::RunOpenInvalidDeviceTestCase() { #elif defined(OS_MAC) invalid_descriptor.capture_api = VideoCaptureApi::MACOSX_AVFOUNDATION; #endif - std::unique_ptr<VideoCaptureDevice> device = + VideoCaptureErrorOrDevice device_status = video_capture_device_factory_->CreateDevice(invalid_descriptor); #if !defined(OS_MAC) - EXPECT_FALSE(device); + EXPECT_FALSE(device_status.ok()); #else + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device = device_status.ReleaseDevice(); // The presence of the actual device is only checked on AllocateAndStart() // and not on creation. EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(1); @@ -539,9 +541,10 @@ void VideoCaptureDeviceTest::RunCaptureWithSizeTestCase() { const int width = size.width(); const int height = size.height(); - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()); @@ -586,9 +589,10 @@ void VideoCaptureDeviceTest::RunAllocateBadSizeTestCase() { const auto device_info = FindUsableDevice(); ASSERT_TRUE(device_info); - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()); @@ -621,8 +625,10 @@ void VideoCaptureDeviceTest::RunReAllocateCameraTestCase() { // First, do a number of very fast device start/stops. for (int i = 0; i <= 5; i++) { video_capture_client_ = CreateDeviceClient(); - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); gfx::Size resolution; if (i % 2) resolution = gfx::Size(640, 480); @@ -644,8 +650,10 @@ void VideoCaptureDeviceTest::RunReAllocateCameraTestCase() { capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; video_capture_client_ = CreateDeviceClient(); - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); device->AllocateAndStart(capture_params, std::move(video_capture_client_)); WaitForCapturedFrame(); @@ -679,9 +687,10 @@ void VideoCaptureDeviceTest::RunCaptureMjpegTestCase() { return; } #endif - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()); @@ -735,17 +744,10 @@ void VideoCaptureDeviceTest::RunTakePhotoTestCase() { const gfx::Size frame_size = device_info->supported_formats.front().frame_size; -#if defined(OS_ANDROID) - // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 - if (base::android::BuildInfo::GetInstance()->sdk_int() < - base::android::SDK_VERSION_MARSHMALLOW) { - return; - } -#endif - - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()).Times(testing::AtLeast(1)); @@ -786,17 +788,10 @@ void VideoCaptureDeviceTest::RunGetPhotoStateTestCase() { const gfx::Size frame_size = device_info->supported_formats.front().frame_size; -#if defined(OS_ANDROID) - // TODO(mcasas): fails on Lollipop devices, reconnect https://crbug.com/646840 - if (base::android::BuildInfo::GetInstance()->sdk_int() < - base::android::SDK_VERSION_MARSHMALLOW) { - return; - } -#endif - - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()); @@ -842,9 +837,10 @@ WRAPPED_TEST_P(VideoCaptureDeviceTest, EXPECT_CALL(*video_capture_client_, OnError(_, _, _)).Times(0); EXPECT_CALL(*video_capture_client_, OnStarted()); - std::unique_ptr<VideoCaptureDevice> device( - video_capture_device_factory_->CreateDevice(device_info->descriptor)); - ASSERT_TRUE(device); + VideoCaptureErrorOrDevice device_status = + video_capture_device_factory_->CreateDevice(device_info->descriptor); + ASSERT_TRUE(device_status.ok()); + std::unique_ptr<VideoCaptureDevice> device(device_status.ReleaseDevice()); VideoCaptureParams capture_params; capture_params.requested_format.frame_size.SetSize(320, 240); diff --git a/chromium/media/capture/video/video_capture_system.h b/chromium/media/capture/video/video_capture_system.h index 016b8e2e517..5e5704d8411 100644 --- a/chromium/media/capture/video/video_capture_system.h +++ b/chromium/media/capture/video/video_capture_system.h @@ -25,9 +25,9 @@ class CAPTURE_EXPORT VideoCaptureSystem { // that calls GetDeviceInfosAsync() virtual void GetDeviceInfosAsync(DeviceInfoCallback result_callback) = 0; - // Creates a VideoCaptureDevice object. Returns nullptr if something goes - // wrong. - virtual std::unique_ptr<VideoCaptureDevice> CreateDevice( + // Creates a VideoCaptureErrorOrDevice object. Contains an error code if + // something goes wrong. + virtual VideoCaptureErrorOrDevice CreateDevice( const std::string& device_id) = 0; }; diff --git a/chromium/media/capture/video/video_capture_system_impl.cc b/chromium/media/capture/video/video_capture_system_impl.cc index 5ff37450c12..c4b413823f9 100644 --- a/chromium/media/capture/video/video_capture_system_impl.cc +++ b/chromium/media/capture/video/video_capture_system_impl.cc @@ -10,6 +10,7 @@ #include "base/callback_helpers.h" #include "build/build_config.h" #include "media/base/bind_to_current_loop.h" +#include "media/capture/video/video_capture_device_factory.h" #include "media/capture/video/video_capture_metrics.h" namespace { @@ -85,12 +86,15 @@ void VideoCaptureSystemImpl::GetDeviceInfosAsync( } } -std::unique_ptr<VideoCaptureDevice> VideoCaptureSystemImpl::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureSystemImpl::CreateDevice( const std::string& device_id) { DCHECK(thread_checker_.CalledOnValidThread()); const VideoCaptureDeviceInfo* device_info = LookupDeviceInfoFromId(device_id); - if (!device_info) - return nullptr; + if (!device_info) { + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); + } return factory_->CreateDevice(device_info->descriptor); } diff --git a/chromium/media/capture/video/video_capture_system_impl.h b/chromium/media/capture/video/video_capture_system_impl.h index 9e0beca5f19..01f93721fa3 100644 --- a/chromium/media/capture/video/video_capture_system_impl.h +++ b/chromium/media/capture/video/video_capture_system_impl.h @@ -19,8 +19,7 @@ class CAPTURE_EXPORT VideoCaptureSystemImpl : public VideoCaptureSystem { ~VideoCaptureSystemImpl() override; void GetDeviceInfosAsync(DeviceInfoCallback result_callback) override; - std::unique_ptr<VideoCaptureDevice> CreateDevice( - const std::string& device_id) override; + VideoCaptureErrorOrDevice CreateDevice(const std::string& device_id) override; private: using DeviceEnumQueue = std::list<DeviceInfoCallback>; diff --git a/chromium/media/capture/video/video_frame_receiver_on_task_runner.cc b/chromium/media/capture/video/video_frame_receiver_on_task_runner.cc index db8990cf1c7..3cb8b9c13f2 100644 --- a/chromium/media/capture/video/video_frame_receiver_on_task_runner.cc +++ b/chromium/media/capture/video/video_frame_receiver_on_task_runner.cc @@ -7,7 +7,7 @@ #include <utility> #include "base/bind.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" namespace media { diff --git a/chromium/media/capture/video/win/filter_base_win.h b/chromium/media/capture/video/win/filter_base_win.h index 89b433d69c7..70f783013b6 100644 --- a/chromium/media/capture/video/win/filter_base_win.h +++ b/chromium/media/capture/video/win/filter_base_win.h @@ -14,7 +14,6 @@ #include <stddef.h> #include <wrl/client.h> -#include "base/macros.h" #include "base/memory/ref_counted.h" namespace media { @@ -23,6 +22,9 @@ class FilterBase : public IBaseFilter, public base::RefCounted<FilterBase> { public: FilterBase(); + FilterBase(const FilterBase&) = delete; + FilterBase& operator=(const FilterBase&) = delete; + // Number of pins connected to this filter. virtual size_t NoOfPins() = 0; // Returns the IPin interface pin no index. @@ -67,8 +69,6 @@ class FilterBase : public IBaseFilter, public base::RefCounted<FilterBase> { private: FILTER_STATE state_; Microsoft::WRL::ComPtr<IFilterGraph> owning_graph_; - - DISALLOW_COPY_AND_ASSIGN(FilterBase); }; } // namespace media diff --git a/chromium/media/capture/video/win/gpu_memory_buffer_tracker.cc b/chromium/media/capture/video/win/gpu_memory_buffer_tracker.cc index fd76f9ea486..ef6caa1c1ba 100644 --- a/chromium/media/capture/video/win/gpu_memory_buffer_tracker.cc +++ b/chromium/media/capture/video/win/gpu_memory_buffer_tracker.cc @@ -5,7 +5,10 @@ #include "media/capture/video/win/gpu_memory_buffer_tracker.h" #include "base/check.h" +#include "base/logging.h" +#include "base/metrics/histogram_functions.h" #include "base/notreached.h" +#include "base/unguessable_token.h" #include "base/win/scoped_handle.h" #include "gpu/ipc/common/dxgi_helpers.h" #include "media/base/win/mf_helpers.h" @@ -92,6 +95,12 @@ bool GpuMemoryBufferTracker::CreateBufferInternal() { gfx::GpuMemoryBufferHandle buffer_handle; buffer_handle.dxgi_handle = CreateNV12Texture(d3d_device_.Get(), buffer_size_); + buffer_handle.dxgi_token = gfx::DXGIHandleToken(); + + if (!buffer_handle.dxgi_handle.IsValid()) { + LOG(ERROR) << "Failed to create NV12 texture"; + return false; + } buffer_ = gpu::GpuMemoryBufferImplDXGI::CreateFromHandle( std::move(buffer_handle), buffer_size_, @@ -107,26 +116,26 @@ bool GpuMemoryBufferTracker::CreateBufferInternal() { return true; } -bool GpuMemoryBufferTracker::EnsureD3DDevice() { +bool GpuMemoryBufferTracker::IsD3DDeviceChanged() { // Check for and handle device loss by recreating the texture - if (FAILED(d3d_device_->GetDeviceRemovedReason())) { - DVLOG(1) << "Detected device loss."; - dxgi_device_manager_->ResetDevice(); - d3d_device_ = dxgi_device_manager_->GetDevice(); - if (!d3d_device_) { - return false; - } - - return CreateBufferInternal(); + Microsoft::WRL::ComPtr<ID3D11Device> recreated_d3d_device; + HRESULT hr = dxgi_device_manager_->CheckDeviceRemovedAndGetDevice( + &recreated_d3d_device); + if (FAILED(hr)) { + LOG(ERROR) << "Detected device loss: " + << logging::SystemErrorCodeToString(hr); + base::UmaHistogramSparse("Media.VideoCapture.Win.D3DDeviceRemovedReason", + hr); } - return true; + return recreated_d3d_device != d3d_device_; } bool GpuMemoryBufferTracker::IsReusableForFormat( const gfx::Size& dimensions, VideoPixelFormat format, const mojom::PlaneStridesPtr& strides) { - return (format == PIXEL_FORMAT_NV12) && (dimensions == buffer_->GetSize()); + return !IsD3DDeviceChanged() && (format == PIXEL_FORMAT_NV12) && + (dimensions == buffer_->GetSize()); } std::unique_ptr<VideoCaptureBufferHandle> @@ -158,7 +167,7 @@ mojo::ScopedSharedBufferHandle GpuMemoryBufferTracker::DuplicateAsMojoBuffer() { } gfx::GpuMemoryBufferHandle GpuMemoryBufferTracker::GetGpuMemoryBufferHandle() { - if (!EnsureD3DDevice()) { + if (IsD3DDeviceChanged()) { return gfx::GpuMemoryBufferHandle(); } auto handle = buffer_->CloneHandle(); diff --git a/chromium/media/capture/video/win/gpu_memory_buffer_tracker.h b/chromium/media/capture/video/win/gpu_memory_buffer_tracker.h index 5fe262b9db9..d788e92a035 100644 --- a/chromium/media/capture/video/win/gpu_memory_buffer_tracker.h +++ b/chromium/media/capture/video/win/gpu_memory_buffer_tracker.h @@ -51,7 +51,7 @@ class CAPTURE_EXPORT GpuMemoryBufferTracker final Microsoft::WRL::ComPtr<ID3D11Texture2D> staging_texture_; gfx::Size buffer_size_; bool CreateBufferInternal(); - bool EnsureD3DDevice(); + bool IsD3DDeviceChanged(); }; } // namespace media diff --git a/chromium/media/capture/video/win/gpu_memory_buffer_tracker_unittest.cc b/chromium/media/capture/video/win/gpu_memory_buffer_tracker_unittest.cc index 3cae8586962..84e28609ec0 100644 --- a/chromium/media/capture/video/win/gpu_memory_buffer_tracker_unittest.cc +++ b/chromium/media/capture/video/win/gpu_memory_buffer_tracker_unittest.cc @@ -37,7 +37,13 @@ class MockDXGIDeviceManager : public DXGIDeviceManager { mock_d3d_device_(new MockD3D11Device()) {} // Associates a new D3D device with the DXGI Device Manager - HRESULT ResetDevice() override { return S_OK; } + // returns it in the parameter, which can't be nullptr. + HRESULT ResetDevice( + Microsoft::WRL::ComPtr<ID3D11Device>& d3d_device) override { + mock_d3d_device_ = new MockD3D11Device(); + d3d_device = mock_d3d_device_; + return S_OK; + } // Directly access D3D device stored in DXGI device manager Microsoft::WRL::ComPtr<ID3D11Device> GetDevice() override { @@ -116,7 +122,7 @@ TEST_F(GpuMemoryBufferTrackerTest, TextureCreation) { true); } -TEST_F(GpuMemoryBufferTrackerTest, TextureRecreationOnDeviceLoss) { +TEST_F(GpuMemoryBufferTrackerTest, InvalidateOnDeviceLoss) { // Verify that GpuMemoryBufferTracker recreates a D3D11 texture with the // correct properties when there is a device loss const gfx::Size expected_buffer_size = {1920, 1080}; @@ -135,8 +141,8 @@ TEST_F(GpuMemoryBufferTrackerTest, TextureRecreationOnDeviceLoss) { static_cast<const unsigned int>( expected_buffer_size.height())))), _, _)) - .Times(2); - // Mock device loss + .Times(1); + // Mock device loss. EXPECT_CALL(*(dxgi_device_manager_->GetMockDevice().Get()), OnGetDeviceRemovedReason()) .WillOnce(Invoke([]() { return DXGI_ERROR_DEVICE_REMOVED; })); @@ -145,8 +151,11 @@ TEST_F(GpuMemoryBufferTrackerTest, TextureRecreationOnDeviceLoss) { std::make_unique<GpuMemoryBufferTracker>(dxgi_device_manager_); EXPECT_EQ(tracker->Init(expected_buffer_size, PIXEL_FORMAT_NV12, nullptr), true); - // Get GpuMemoryBufferHandle (should trigger device/texture recreation) + // The tracker now should be invalid. + EXPECT_FALSE(tracker->IsReusableForFormat(expected_buffer_size, + PIXEL_FORMAT_NV12, nullptr)); gfx::GpuMemoryBufferHandle gmb = tracker->GetGpuMemoryBufferHandle(); + EXPECT_FALSE(gmb.dxgi_handle.IsValid()); } TEST_F(GpuMemoryBufferTrackerTest, GetMemorySizeInBytes) { diff --git a/chromium/media/capture/video/win/pin_base_win.h b/chromium/media/capture/video/win/pin_base_win.h index 9338f3c658c..1a6b2ff6069 100644 --- a/chromium/media/capture/video/win/pin_base_win.h +++ b/chromium/media/capture/video/win/pin_base_win.h @@ -8,6 +8,8 @@ #ifndef MEDIA_CAPTURE_VIDEO_WIN_PIN_BASE_WIN_H_ #define MEDIA_CAPTURE_VIDEO_WIN_PIN_BASE_WIN_H_ +#include "base/memory/raw_ptr.h" + // Avoid including strsafe.h via dshow as it will cause build warnings. #define NO_DSHOW_STRSAFE #include <dshow.h> @@ -104,7 +106,7 @@ class PinBase : public IPin, Microsoft::WRL::ComPtr<IPin> connected_pin_; // owner_ is the filter owning this pin. We don't reference count it since // that would create a circular reference count. - IBaseFilter* owner_; + raw_ptr<IBaseFilter> owner_; }; } // namespace media diff --git a/chromium/media/capture/video/win/sink_filter_win.h b/chromium/media/capture/video/win/sink_filter_win.h index 6e5f9979bc8..88373bd705d 100644 --- a/chromium/media/capture/video/win/sink_filter_win.h +++ b/chromium/media/capture/video/win/sink_filter_win.h @@ -11,7 +11,6 @@ #include <windows.h> #include <stddef.h> -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "media/capture/video/video_capture_device.h" #include "media/capture/video/win/filter_base_win.h" @@ -61,8 +60,13 @@ class SinkInputPin; class __declspec(uuid("88cdbbdc-a73b-4afa-acbf-15d5e2ce12c3")) SinkFilter : public FilterBase { public: + SinkFilter() = delete; + explicit SinkFilter(SinkFilterObserver* observer); + SinkFilter(const SinkFilter&) = delete; + SinkFilter& operator=(const SinkFilter&) = delete; + void SetRequestedMediaFormat(VideoPixelFormat pixel_format, float frame_rate, const BITMAPINFOHEADER& info_header); @@ -77,8 +81,6 @@ class __declspec(uuid("88cdbbdc-a73b-4afa-acbf-15d5e2ce12c3")) SinkFilter ~SinkFilter() override; scoped_refptr<SinkInputPin> input_pin_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(SinkFilter); }; } // namespace media diff --git a/chromium/media/capture/video/win/sink_input_pin_win.h b/chromium/media/capture/video/win/sink_input_pin_win.h index e4e0a4eb9f9..7df06bb33ce 100644 --- a/chromium/media/capture/video/win/sink_input_pin_win.h +++ b/chromium/media/capture/video/win/sink_input_pin_win.h @@ -8,7 +8,7 @@ #ifndef MEDIA_CAPTURE_VIDEO_WIN_SINK_INPUT_PIN_WIN_H_ #define MEDIA_CAPTURE_VIDEO_WIN_SINK_INPUT_PIN_WIN_H_ -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "media/capture/video/video_capture_device.h" #include "media/capture/video/win/pin_base_win.h" #include "media/capture/video/win/sink_filter_win.h" @@ -22,8 +22,13 @@ extern const REFERENCE_TIME kSecondsToReferenceTime; // Input pin of the SinkFilter. class SinkInputPin : public PinBase { public: + SinkInputPin() = delete; + SinkInputPin(IBaseFilter* filter, SinkFilterObserver* observer); + SinkInputPin(const SinkInputPin&) = delete; + SinkInputPin& operator=(const SinkInputPin&) = delete; + void SetRequestedMediaFormat(VideoPixelFormat pixel_format, float frame_rate, const BITMAPINFOHEADER& info_header); @@ -42,9 +47,7 @@ class SinkInputPin : public PinBase { BITMAPINFOHEADER requested_info_header_; VideoCaptureFormat resulting_format_; bool flip_y_; - SinkFilterObserver* observer_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(SinkInputPin); + raw_ptr<SinkFilterObserver> observer_; }; } // namespace media diff --git a/chromium/media/capture/video/win/video_capture_device_factory_win.cc b/chromium/media/capture/video/win/video_capture_device_factory_win.cc index c63a835fbc7..260b65170a5 100644 --- a/chromium/media/capture/video/win/video_capture_device_factory_win.cc +++ b/chromium/media/capture/video/win/video_capture_device_factory_win.cc @@ -22,9 +22,9 @@ #include "base/feature_list.h" #include "base/metrics/histogram_macros.h" #include "base/no_destructor.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_util.h" #include "base/strings/sys_string_conversions.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/scoped_thread_priority.h" #include "base/win/core_winrt_util.h" #include "base/win/scoped_co_mem.h" @@ -353,7 +353,7 @@ VideoCaptureDeviceFactoryWin::~VideoCaptureDeviceFactoryWin() { } } -std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryWin::CreateDevice( +VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryWin::CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) { DCHECK(thread_checker_.CalledOnValidThread()); switch (device_descriptor.capture_api) { @@ -362,17 +362,20 @@ std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryWin::CreateDevice( case VideoCaptureApi::WIN_MEDIA_FOUNDATION_SENSOR: { DCHECK(PlatformSupportsMediaFoundation()); ComPtr<IMFMediaSource> source; - if (!CreateDeviceSourceMediaFoundation(device_descriptor.device_id, - device_descriptor.capture_api, - &source)) { - break; + MFSourceOutcome outcome = CreateDeviceSourceMediaFoundation( + device_descriptor.device_id, device_descriptor.capture_api, &source); + if (outcome == MFSourceOutcome::kFailedSystemPermissions) { + return VideoCaptureErrorOrDevice( + VideoCaptureError::kWinMediaFoundationSystemPermissionDenied); + } + if (outcome == MFSourceOutcome::kSuccess) { + auto device = std::make_unique<VideoCaptureDeviceMFWin>( + device_descriptor, std::move(source), dxgi_device_manager_); + DVLOG(1) << " MediaFoundation Device: " + << device_descriptor.display_name(); + if (device->Init()) + return VideoCaptureErrorOrDevice(std::move(device)); } - auto device = std::make_unique<VideoCaptureDeviceMFWin>( - device_descriptor, std::move(source), dxgi_device_manager_); - DVLOG(1) << " MediaFoundation Device: " - << device_descriptor.display_name(); - if (device->Init()) - return device; break; } case VideoCaptureApi::WIN_DIRECT_SHOW: { @@ -385,14 +388,16 @@ std::unique_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryWin::CreateDevice( device_descriptor, std::move(capture_filter)); DVLOG(1) << " DirectShow Device: " << device_descriptor.display_name(); if (device->Init()) - return device; + return VideoCaptureErrorOrDevice(std::move(device)); break; } default: NOTREACHED(); break; } - return nullptr; + return VideoCaptureErrorOrDevice( + VideoCaptureError:: + kVideoCaptureControllerInvalidOrUnsupportedVideoCaptureParametersRequested); } bool VideoCaptureDeviceFactoryWin::CreateDeviceEnumMonikerDirectShow( @@ -488,7 +493,7 @@ bool VideoCaptureDeviceFactoryWin::CreateDeviceFilterDirectShow( return true; } -bool VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( +MFSourceOutcome VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( const std::string& device_id, VideoCaptureApi capture_api, IMFMediaSource** source) { @@ -505,7 +510,7 @@ bool VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( // in attributes store. if (!PrepareVideoCaptureAttributesMediaFoundation( attributes_data, attributes_data.size() + 1, &attributes)) { - return false; + return MFSourceOutcome::kFailed; } attributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, @@ -514,19 +519,22 @@ bool VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( return CreateDeviceSourceMediaFoundation(std::move(attributes), source); } -bool VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( +MFSourceOutcome VideoCaptureDeviceFactoryWin::CreateDeviceSourceMediaFoundation( ComPtr<IMFAttributes> attributes, IMFMediaSource** source_out) { ComPtr<IMFMediaSource> source; HRESULT hr = MFCreateDeviceSource(attributes.Get(), &source); DLOG_IF(ERROR, FAILED(hr)) << "MFCreateDeviceSource failed: " << logging::SystemErrorCodeToString(hr); + if (hr == E_ACCESSDENIED) + return MFSourceOutcome::kFailedSystemPermissions; + if (SUCCEEDED(hr) && use_d3d11_with_media_foundation_ && dxgi_device_manager_) { dxgi_device_manager_->RegisterWithMediaSource(source); } *source_out = source.Detach(); - return SUCCEEDED(hr); + return SUCCEEDED(hr) ? MFSourceOutcome::kSuccess : MFSourceOutcome::kFailed; } bool VideoCaptureDeviceFactoryWin::EnumerateDeviceSourcesMediaFoundation( @@ -584,18 +592,17 @@ void VideoCaptureDeviceFactoryWin::EnumerateDevicesUWP( &VideoCaptureDeviceFactoryWin::FoundAllDevicesUWP, base::Unretained(factory), base::Passed(&devices_info), base::Passed(&result_callback)); - auto callback = - Microsoft::WRL::Callback< - ABI::Windows::Foundation::IAsyncOperationCompletedHandler< - DeviceInformationCollection*>>( - [com_thread_runner, device_info_callback]( - IAsyncOperation<DeviceInformationCollection*>* operation, - AsyncStatus status) -> HRESULT { - com_thread_runner->PostTask( - FROM_HERE, base::BindOnce(device_info_callback, - base::Unretained(operation))); - return S_OK; - }); + auto callback = Microsoft::WRL::Callback< + ABI::Windows::Foundation::IAsyncOperationCompletedHandler< + DeviceInformationCollection*>>( + [com_thread_runner, device_info_callback]( + IAsyncOperation<DeviceInformationCollection*>* operation, + AsyncStatus status) -> HRESULT { + com_thread_runner->PostTask( + FROM_HERE, + base::BindOnce(device_info_callback, base::Unretained(operation))); + return S_OK; + }); ComPtr<ABI::Windows::Devices::Enumeration::IDeviceInformationStatics> dev_info_statics; @@ -773,7 +780,8 @@ DevicesInfo VideoCaptureDeviceFactoryWin::GetDevicesInfoMediaFoundation() { VideoCaptureControlSupport control_support; VideoCaptureFormats supported_formats; if (CreateDeviceSourceMediaFoundation( - device_id, api_attributes.first, &source)) { + device_id, api_attributes.first, &source) == + MFSourceOutcome::kSuccess) { control_support = VideoCaptureDeviceMFWin::GetControlSupport(source); supported_formats = diff --git a/chromium/media/capture/video/win/video_capture_device_factory_win.h b/chromium/media/capture/video/win/video_capture_device_factory_win.h index f62dfdb5c95..6dab62d5831 100644 --- a/chromium/media/capture/video/win/video_capture_device_factory_win.h +++ b/chromium/media/capture/video/win/video_capture_device_factory_win.h @@ -15,7 +15,6 @@ #include <windows.devices.enumeration.h> #include <wrl.h> -#include "base/macros.h" #include "base/threading/thread.h" #include "media/base/win/dxgi_device_manager.h" #include "media/capture/video/video_capture_device_factory.h" @@ -25,6 +24,14 @@ namespace media { using ABI::Windows::Foundation::IAsyncOperation; using ABI::Windows::Devices::Enumeration::DeviceInformationCollection; +enum class MFSourceOutcome { + kSuccess = 0, + // Failed due to an unknown or unspecified reason. + kFailed, + // Failed to open due to OS-level system permissions. + kFailedSystemPermissions, +}; + // Extension of VideoCaptureDeviceFactory to create and manipulate Windows // devices, via either DirectShow or MediaFoundation APIs. class CAPTURE_EXPORT VideoCaptureDeviceFactoryWin @@ -40,7 +47,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryWin ~VideoCaptureDeviceFactoryWin() override; - std::unique_ptr<VideoCaptureDevice> CreateDevice( + VideoCaptureErrorOrDevice CreateDevice( const VideoCaptureDeviceDescriptor& device_descriptor) override; void GetDevicesInfo(GetDevicesInfoCallback callback) override; @@ -60,10 +67,11 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryWin virtual bool CreateDeviceFilterDirectShow( Microsoft::WRL::ComPtr<IMoniker> moniker, IBaseFilter** capture_filter); - virtual bool CreateDeviceSourceMediaFoundation(const std::string& device_id, - VideoCaptureApi capture_api, - IMFMediaSource** source_out); - virtual bool CreateDeviceSourceMediaFoundation( + virtual MFSourceOutcome CreateDeviceSourceMediaFoundation( + const std::string& device_id, + VideoCaptureApi capture_api, + IMFMediaSource** source_out); + virtual MFSourceOutcome CreateDeviceSourceMediaFoundation( Microsoft::WRL::ComPtr<IMFAttributes> attributes, IMFMediaSource** source); virtual bool EnumerateDeviceSourcesMediaFoundation( diff --git a/chromium/media/capture/video/win/video_capture_device_factory_win_unittest.cc b/chromium/media/capture/video/win/video_capture_device_factory_win_unittest.cc index 15bda062bd3..b95d7e2e029 100644 --- a/chromium/media/capture/video/win/video_capture_device_factory_win_unittest.cc +++ b/chromium/media/capture/video/win/video_capture_device_factory_win_unittest.cc @@ -1223,31 +1223,31 @@ class FakeVideoCaptureDeviceFactoryWin : public VideoCaptureDeviceFactoryWin { kDirectShowDeviceName6)})); return true; } - bool CreateDeviceSourceMediaFoundation( + MFSourceOutcome CreateDeviceSourceMediaFoundation( Microsoft::WRL::ComPtr<IMFAttributes> attributes, IMFMediaSource** source) override { UINT32 length; if (FAILED(attributes->GetStringLength( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &length))) { - return false; + return MFSourceOutcome::kFailed; } std::wstring symbolic_link(length, wchar_t()); if (FAILED(attributes->GetString( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &symbolic_link[0], length + 1, &length))) { - return false; + return MFSourceOutcome::kFailed; } const bool has_dxgi_device_manager = static_cast<bool>(dxgi_device_manager_for_testing()); if (use_d3d11_with_media_foundation_for_testing() != has_dxgi_device_manager) { - return false; + return MFSourceOutcome::kFailed; } *source = AddReference( new StubMFMediaSource(base::SysWideToUTF8(symbolic_link), device_source_native_formats_[symbolic_link])); - return true; + return MFSourceOutcome::kSuccess; } bool EnumerateDeviceSourcesMediaFoundation( Microsoft::WRL::ComPtr<IMFAttributes> attributes, diff --git a/chromium/media/capture/video/win/video_capture_device_mf_win.cc b/chromium/media/capture/video/win/video_capture_device_mf_win.cc index e279aded010..7fdb06f6551 100644 --- a/chromium/media/capture/video/win/video_capture_device_mf_win.cc +++ b/chromium/media/capture/video/win/video_capture_device_mf_win.cc @@ -5,6 +5,7 @@ #include "media/capture/video/win/video_capture_device_mf_win.h" #include <d3d11_4.h> +#include <ks.h> #include <mfapi.h> #include <mferror.h> #include <stddef.h> @@ -15,7 +16,10 @@ #include <utility> #include "base/bind.h" +#include "base/compiler_specific.h" #include "base/location.h" +#include "base/logging.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/metrics/histogram_functions.h" #include "base/strings/stringprintf.h" @@ -48,6 +52,9 @@ namespace media { namespace { +// How many times we try to restart D3D11 path. +constexpr int kMaxD3DRestarts = 2; + class MFPhotoCallback final : public base::RefCountedThreadSafe<MFPhotoCallback>, public IMFCaptureEngineOnSampleCallback { @@ -56,6 +63,9 @@ class MFPhotoCallback final VideoCaptureFormat format) : callback_(std::move(callback)), format_(format) {} + MFPhotoCallback(const MFPhotoCallback&) = delete; + MFPhotoCallback& operator=(const MFPhotoCallback&) = delete; + IFACEMETHODIMP QueryInterface(REFIID riid, void** object) override { if (riid == IID_IUnknown || riid == IID_IMFCaptureEngineOnSampleCallback) { AddRef(); @@ -124,8 +134,6 @@ class MFPhotoCallback final VideoCaptureDevice::TakePhotoCallback callback_; const VideoCaptureFormat format_; - - DISALLOW_COPY_AND_ASSIGN(MFPhotoCallback); }; // Locks the given buffer using the fastest supported method when constructed, @@ -205,8 +213,8 @@ scoped_refptr<IMFCaptureEngineOnSampleCallback> CreateMFPhotoCallback( } void LogError(const Location& from_here, HRESULT hr) { - DPLOG(ERROR) << from_here.ToString() - << " hr = " << logging::SystemErrorCodeToString(hr); + LOG(ERROR) << from_here.ToString() + << " hr = " << logging::SystemErrorCodeToString(hr); } bool GetFrameSizeFromMediaType(IMFMediaType* type, gfx::Size* frame_size) { @@ -689,7 +697,7 @@ class MFVideoCallback final // Protects access to |observer_|. base::Lock lock_; - VideoCaptureDeviceMFWin* observer_ GUARDED_BY(lock_); + raw_ptr<VideoCaptureDeviceMFWin> observer_ GUARDED_BY(lock_); }; // static @@ -719,6 +727,7 @@ VideoCaptureControlSupport VideoCaptureDeviceMFWin::GetControlSupport( ComPtr<IAMVideoProcAmp> video_control; hr = source.As(&video_control); DLOG_IF_FAILED_WITH_HRESULT("Failed to retrieve IAMVideoProcAmp", hr); + ALLOW_UNUSED_LOCAL(hr); // On Windows platform, some Image Capture video constraints and settings are // get or set using IAMCameraControl interface while the rest are get or set @@ -875,7 +884,7 @@ VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin( ComPtr<IMFMediaSource> source, scoped_refptr<DXGIDeviceManager> dxgi_device_manager, ComPtr<IMFCaptureEngine> engine) - : facing_mode_(device_descriptor.facing), + : device_descriptor_(device_descriptor), create_mf_photo_callback_(base::BindRepeating(&CreateMFPhotoCallback)), is_initialized_(false), max_retry_count_(200), @@ -914,7 +923,6 @@ VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { } bool VideoCaptureDeviceMFWin::Init() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!is_initialized_); HRESULT hr; @@ -931,7 +939,6 @@ bool VideoCaptureDeviceMFWin::Init() { return false; } } - ComPtr<IMFAttributes> attributes; hr = MFCreateAttributes(&attributes, 1); if (FAILED(hr)) { @@ -973,7 +980,13 @@ void VideoCaptureDeviceMFWin::AllocateAndStart( DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); base::AutoLock lock(lock_); + return AllocateAndStartLocked(params, std::move(client)); +} +void VideoCaptureDeviceMFWin::AllocateAndStartLocked( + const VideoCaptureParams& params, + std::unique_ptr<VideoCaptureDevice::Client> client) { + params_ = params; client_ = std::move(client); DCHECK_EQ(false, is_started_); @@ -1538,8 +1551,14 @@ HRESULT VideoCaptureDeviceMFWin::DeliverTextureToClient( HRESULT hr = texture_device->GetDeviceRemovedReason(); if (FAILED(hr)) { - DLOG(ERROR) << "Camera texture device lost."; - DCHECK(dxgi_device_manager_->ResetDevice()); + // Make sure the main device is reset. + hr = dxgi_device_manager_->CheckDeviceRemovedAndGetDevice(nullptr); + LOG(ERROR) << "Camera texture device lost: " + << logging::SystemErrorCodeToString(hr); + base::UmaHistogramSparse("Media.VideoCapture.Win.D3DDeviceRemovedReason", + hr); + // Even if device was reset successfully, we can't continue + // because the texture is tied to the old device. return hr; } @@ -1556,13 +1575,24 @@ HRESULT VideoCaptureDeviceMFWin::DeliverTextureToClient( auto result = client_->ReserveOutputBuffer( texture_size, pixel_format, kDummyFrameFeedbackId, &capture_buffer); if (result != VideoCaptureDevice::Client::ReserveResult::kSucceeded) { - DLOG(ERROR) << "Failed to reserve output capture buffer: " << (int)result; + LOG(ERROR) << "Failed to reserve output capture buffer: " << (int)result; return MF_E_UNEXPECTED; } auto gmb_handle = capture_buffer.handle_provider->GetGpuMemoryBufferHandle(); + if (!gmb_handle.dxgi_handle.IsValid()) { + // If the device is removed and GMB tracker fails to recreate it, + // an empty gmb handle may be returned here. + return MF_E_UNEXPECTED; + } hr = CopyTextureToGpuMemoryBuffer(texture, gmb_handle.dxgi_handle.Get()); + if (FAILED(hr)) { + LOG(ERROR) << "Failed to copy camera device texture to output texture: " + << logging::SystemErrorCodeToString(hr); + return hr; + } + capture_buffer.is_premapped = false; if (last_feedback_.require_mapped_frame) { // Only a flag on the Buffer is set here; the region itself isn't passed @@ -1574,12 +1604,6 @@ HRESULT VideoCaptureDeviceMFWin::DeliverTextureToClient( } } - if (FAILED(hr)) { - DLOG(ERROR) << "Failed to copy camera device texture to output texture: " - << logging::SystemErrorCodeToString(hr); - return hr; - } - VideoRotation frame_rotation = VIDEO_ROTATION_0; DCHECK(camera_rotation_.has_value()); switch (camera_rotation_.value()) { @@ -1633,7 +1657,7 @@ void VideoCaptureDeviceMFWin::OnIncomingCapturedDataInternal( // We always calculate camera rotation for the first frame. We also cache // the latest value to use when AutoRotation is turned off. if (!camera_rotation_.has_value() || IsAutoRotationEnabled()) - camera_rotation_ = GetCameraRotation(facing_mode_); + camera_rotation_ = GetCameraRotation(device_descriptor_.facing); Microsoft::WRL::ComPtr<ID3D11Texture2D> texture; // Use the hardware path only if it is enabled and the selected pixel format @@ -1656,7 +1680,7 @@ void VideoCaptureDeviceMFWin::OnIncomingCapturedDataInternal( ScopedBufferLock locked_buffer(buffer); if (!locked_buffer.data()) { - DLOG(ERROR) << "Locked buffer delivered nullptr"; + LOG(ERROR) << "Locked buffer delivered nullptr"; frame_drop_reason = VideoCaptureFrameDropReason:: kWinMediaFoundationLockingBufferDelieveredNullptr; return; @@ -1709,13 +1733,12 @@ void VideoCaptureDeviceMFWin::OnFrameDropped( } void VideoCaptureDeviceMFWin::OnEvent(IMFMediaEvent* media_event) { - base::AutoLock lock(lock_); - HRESULT hr; GUID capture_event_guid = GUID_NULL; media_event->GetStatus(&hr); media_event->GetExtendedType(&capture_event_guid); + // TODO(http://crbug.com/1093521): Add cases for Start // MF_CAPTURE_ENGINE_PREVIEW_STARTED and MF_CAPTURE_ENGINE_PREVIEW_STOPPED // When MF_CAPTURE_ENGINE_ERROR is returned the captureengine object is no @@ -1728,6 +1751,46 @@ void VideoCaptureDeviceMFWin::OnEvent(IMFMediaEvent* media_event) { capture_initialize_.Signal(); } + // Lock is taken after events are signalled, because if the capture + // is being restarted, lock is currently owned by another thread running + // OnEvent(). + base::AutoLock lock(lock_); + + if (hr == DXGI_ERROR_DEVICE_REMOVED) { + // Removed device can happen for external reasons. + // We should restart capture. + Microsoft::WRL::ComPtr<ID3D11Device> recreated_d3d_device; + const bool try_d3d_path = num_restarts_ < kMaxD3DRestarts; + if (try_d3d_path) { + HRESULT removed_hr = dxgi_device_manager_->CheckDeviceRemovedAndGetDevice( + &recreated_d3d_device); + LOG(ERROR) << "OnEvent: Device was Removed. Reason: " + << logging::SystemErrorCodeToString(removed_hr); + } else { + // Too many restarts. Fallback to the software path. + dxgi_device_manager_ = nullptr; + } + + engine_ = nullptr; + is_initialized_ = false; + is_started_ = false; + source_ = nullptr; + capture_error_.Reset(); + capture_initialize_.Reset(); + + if ((!try_d3d_path || recreated_d3d_device) && RecreateMFSource() && + Init()) { + AllocateAndStartLocked(params_, std::move(client_)); + // If AllocateAndStart fails somehow, OnError() will be called + // internally. Therefore, it's safe to always override |hr| here. + hr = S_OK; + ++num_restarts_; + } else { + LOG(ERROR) << "Failed to re-initialize."; + hr = MF_E_UNEXPECTED; + } + } + if (FAILED(hr)) { base::UmaHistogramSparse("Media.VideoCapture.Win.ErrorEvent", hr); OnError(VideoCaptureError::kWinMediaFoundationGetMediaEventStatusFailed, @@ -1789,4 +1852,36 @@ HRESULT VideoCaptureDeviceMFWin::WaitOnCaptureEvent(GUID capture_event_guid) { } return hr; } + +bool VideoCaptureDeviceMFWin::RecreateMFSource() { + const bool is_sensor_api = device_descriptor_.capture_api == + VideoCaptureApi::WIN_MEDIA_FOUNDATION_SENSOR; + ComPtr<IMFAttributes> attributes; + HRESULT hr = MFCreateAttributes(&attributes, is_sensor_api ? 3 : 2); + if (FAILED(hr)) { + LOG(ERROR) << "Failed to create attributes: " + << logging::SystemErrorCodeToString(hr); + return false; + } + attributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, + MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID); + if (is_sensor_api) { + attributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_CATEGORY, + KSCATEGORY_SENSOR_CAMERA); + } + attributes->SetString( + MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, + base::SysUTF8ToWide(device_descriptor_.device_id).c_str()); + hr = MFCreateDeviceSource(attributes.Get(), &source_); + if (FAILED(hr)) { + LOG(ERROR) << "MFCreateDeviceSource failed: " + << logging::SystemErrorCodeToString(hr); + return false; + } + + if (dxgi_device_manager_) { + dxgi_device_manager_->RegisterWithMediaSource(source_); + } + return true; +} } // namespace media diff --git a/chromium/media/capture/video/win/video_capture_device_mf_win.h b/chromium/media/capture/video/win/video_capture_device_mf_win.h index 196ab92d0e2..b788812d895 100644 --- a/chromium/media/capture/video/win/video_capture_device_mf_win.h +++ b/chromium/media/capture/video/win/video_capture_device_mf_win.h @@ -20,7 +20,6 @@ #include "base/callback_forward.h" #include "base/containers/queue.h" -#include "base/macros.h" #include "base/sequence_checker.h" #include "media/base/win/dxgi_device_manager.h" #include "media/capture/capture_export.h" @@ -47,6 +46,8 @@ class CAPTURE_EXPORT VideoCaptureDeviceMFWin : public VideoCaptureDevice { static VideoCaptureControlSupport GetControlSupport( Microsoft::WRL::ComPtr<IMFMediaSource> source); + VideoCaptureDeviceMFWin() = delete; + explicit VideoCaptureDeviceMFWin( const VideoCaptureDeviceDescriptor& device_descriptor, Microsoft::WRL::ComPtr<IMFMediaSource> source, @@ -57,6 +58,9 @@ class CAPTURE_EXPORT VideoCaptureDeviceMFWin : public VideoCaptureDevice { scoped_refptr<DXGIDeviceManager> dxgi_device_manager, Microsoft::WRL::ComPtr<IMFCaptureEngine> engine); + VideoCaptureDeviceMFWin(const VideoCaptureDeviceMFWin&) = delete; + VideoCaptureDeviceMFWin& operator=(const VideoCaptureDeviceMFWin&) = delete; + ~VideoCaptureDeviceMFWin() override; // Opens the device driver for this device. @@ -143,8 +147,12 @@ class CAPTURE_EXPORT VideoCaptureDeviceMFWin : public VideoCaptureDevice { base::TimeTicks reference_time, base::TimeDelta timestamp, VideoCaptureFrameDropReason& frame_drop_reason); + bool RecreateMFSource(); + void AllocateAndStartLocked( + const VideoCaptureParams& params, + std::unique_ptr<VideoCaptureDevice::Client> client); - VideoFacingMode facing_mode_; + VideoCaptureDeviceDescriptor device_descriptor_; CreateMFPhotoCallbackCB create_mf_photo_callback_; scoped_refptr<MFVideoCallback> video_callback_; bool is_initialized_; @@ -157,7 +165,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceMFWin : public VideoCaptureDevice { base::Lock lock_; std::unique_ptr<VideoCaptureDevice::Client> client_; - const Microsoft::WRL::ComPtr<IMFMediaSource> source_; + Microsoft::WRL::ComPtr<IMFMediaSource> source_; Microsoft::WRL::ComPtr<IAMCameraControl> camera_control_; Microsoft::WRL::ComPtr<IAMVideoProcAmp> video_control_; Microsoft::WRL::ComPtr<IMFCaptureEngine> engine_; @@ -175,12 +183,12 @@ class CAPTURE_EXPORT VideoCaptureDeviceMFWin : public VideoCaptureDevice { base::WaitableEvent capture_error_; scoped_refptr<DXGIDeviceManager> dxgi_device_manager_; absl::optional<int> camera_rotation_; + VideoCaptureParams params_; + int num_restarts_ = 0; media::VideoCaptureFeedback last_feedback_; SEQUENCE_CHECKER(sequence_checker_); - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin); }; } // namespace media diff --git a/chromium/media/capture/video/win/video_capture_device_win.h b/chromium/media/capture/video/win/video_capture_device_win.h index 54bf57ed64a..2f2942855af 100644 --- a/chromium/media/capture/video/win/video_capture_device_win.h +++ b/chromium/media/capture/video/win/video_capture_device_win.h @@ -19,7 +19,6 @@ #include <string> #include "base/containers/queue.h" -#include "base/macros.h" #include "base/threading/thread_checker.h" #include "media/capture/video/video_capture_device.h" #include "media/capture/video/win/capability_list_win.h" @@ -77,9 +76,16 @@ class VideoCaptureDeviceWin : public VideoCaptureDevice, static VideoPixelFormat TranslateMediaSubtypeToPixelFormat( const GUID& sub_type); + VideoCaptureDeviceWin() = delete; + VideoCaptureDeviceWin(const VideoCaptureDeviceDescriptor& device_descriptor, Microsoft::WRL::ComPtr<IBaseFilter> capture_filter); + + VideoCaptureDeviceWin(const VideoCaptureDeviceWin&) = delete; + VideoCaptureDeviceWin& operator=(const VideoCaptureDeviceWin&) = delete; + ~VideoCaptureDeviceWin() override; + // Opens the device driver for this device. bool Init(); @@ -157,8 +163,6 @@ class VideoCaptureDeviceWin : public VideoCaptureDevice, bool enable_get_photo_state_; absl::optional<int> camera_rotation_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin); }; } // namespace media diff --git a/chromium/media/capture/video_capture_types.h b/chromium/media/capture/video_capture_types.h index 5cbc77670c3..c3ca9403df4 100644 --- a/chromium/media/capture/video_capture_types.h +++ b/chromium/media/capture/video_capture_types.h @@ -192,7 +192,9 @@ enum class VideoCaptureError { kDesktopCaptureDeviceMacFailedStreamCreate = 124, kDesktopCaptureDeviceMacFailedStreamStart = 125, kCrosHalV3BufferManagerFailedToReserveBuffers = 126, - kMaxValue = 126 + kWinMediaFoundationSystemPermissionDenied = 127, + kVideoCaptureImplTimedOutOnStart = 128, + kMaxValue = 128 }; // WARNING: Do not change the values assigned to the entries. They are used for diff --git a/chromium/media/capture/video_capturer_source.cc b/chromium/media/capture/video_capturer_source.cc deleted file mode 100644 index 143506b8f8a..00000000000 --- a/chromium/media/capture/video_capturer_source.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/capture/video_capturer_source.h" -#include "base/callback_helpers.h" - -namespace media { - -// TODO(mcasas): VideoCapturerSource is implemented in other .dll(s) (e.g. -// content) in Windows component build. The current compiler fails to generate -// object files for this destructor if it's defined in the header file and that -// breaks linking. Consider removing this file when the compiler+linker is able -// to generate symbols across linking units. -VideoCapturerSource::~VideoCapturerSource() = default; - -media::VideoCaptureFeedbackCB VideoCapturerSource::GetFeedbackCallback() const { - return base::DoNothing(); -} - -} // namespace media diff --git a/chromium/media/capture/video_capturer_source.h b/chromium/media/capture/video_capturer_source.h deleted file mode 100644 index 9c46503617c..00000000000 --- a/chromium/media/capture/video_capturer_source.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAPTURE_VIDEO_CAPTURER_SOURCE_H_ -#define MEDIA_CAPTURE_VIDEO_CAPTURER_SOURCE_H_ - -#include <string> -#include <vector> - -#include "base/callback.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" -#include "media/capture/capture_export.h" -#include "media/capture/video/video_capture_feedback.h" -#include "media/capture/video_capture_types.h" - -namespace media { - -class VideoFrame; - -// VideoCapturerSource is an interface representing the source for captured -// video. An implementation will periodically call the frame callback with new -// video frames. -class CAPTURE_EXPORT VideoCapturerSource { - public: - virtual ~VideoCapturerSource(); - - // This callback is used to deliver video frames. - // - // |estimated_capture_time| - The capture time of the delivered video - // frame. This field represents the local time at which either: 1) the frame - // was generated, if it was done so locally; or 2) the targeted play-out time - // of the frame, if it was generated from a remote source. Either way, an - // implementation should not present the frame before this point-in-time. This - // value is NOT a high-resolution timestamp, and so it should not be used as a - // presentation time; but, instead, it should be used for buffering playback - // and for A/V synchronization purposes. NOTE: It is possible for this value - // to be null if the current implementation lacks this timing information. - // - // |video_frame->timestamp()| gives the presentation timestamp of the video - // frame relative to the first frame generated by the corresponding source. - // Because a source can start generating frames before a subscriber is added, - // the first video frame delivered may not have timestamp equal to 0. - // - // |scaled_video_frames| are alternative representations of |video_frame| - // where scaling has already been applied. Scaled frames may be produced by - // some capturers that listen to media::VideoCaptureFeedback. However, because - // not all capturers support in-capturer scaling or due to delays in the - // pipeline, listeners have to be prepared for scaled video frames not being - // present or being present with other sizes than most recently requested. - using VideoCaptureDeliverFrameCB = base::RepeatingCallback<void( - scoped_refptr<media::VideoFrame> video_frame, - std::vector<scoped_refptr<media::VideoFrame>> scaled_video_frames, - base::TimeTicks estimated_capture_time)>; - - using VideoCaptureDeviceFormatsCB = - base::OnceCallback<void(const media::VideoCaptureFormats&)>; - - using RunningCallback = base::RepeatingCallback<void(bool)>; - - // Returns formats that are preferred and can currently be used. May be empty - // if no formats are available or known. - virtual VideoCaptureFormats GetPreferredFormats() = 0; - - // Starts capturing frames using the capture |params|. |new_frame_callback| is - // triggered when a new video frame is available. - // If capturing is started successfully then |running_callback| will be - // called with a parameter of true. Note that some implementations may - // simply reject StartCapture (by calling running_callback with a false - // argument) if called with the wrong task runner. - // If capturing fails to start or stopped due to an external event then - // |running_callback| will be called with a parameter of false. - // |running_callback| will always be called on the same thread as the - // StartCapture. - virtual void StartCapture( - const media::VideoCaptureParams& params, - const VideoCaptureDeliverFrameCB& new_frame_callback, - const RunningCallback& running_callback) = 0; - - // Returns a callback for providing the feedback from the consumer. - // The callback can be called on any thread. - virtual media::VideoCaptureFeedbackCB GetFeedbackCallback() const; - - // Asks source to send a refresh frame. In cases where source does not provide - // a continuous rate of new frames (e.g. canvas capture, screen capture where - // the screen's content has not changed in a while), consumers may request a - // "refresh frame" to be delivered. For instance, this would be needed when - // a new sink is added to a MediaStreamTrack. - // - // The default implementation is a no-op and implementations are not required - // to honor this request. If they decide to and capturing is started - // successfully, then |new_frame_callback| should be called with a frame. - // - // Note: This should only be called after StartCapture() and before - // StopCapture(). Otherwise, its behavior is undefined. - virtual void RequestRefreshFrame() {} - - // Optionally suspends frame delivery. The source may or may not honor this - // request. Thus, the caller cannot assume frame delivery will actually - // stop. Even if frame delivery is suspended, this might not take effect - // immediately. - // - // The purpose of this is to allow minimizing resource usage while - // there are no frame consumers present. - // - // Note: This should only be called after StartCapture() and before - // StopCapture(). Otherwise, its behavior is undefined. - virtual void MaybeSuspend() {} - - // Resumes frame delivery, if it was suspended. If frame delivery was not - // suspended, this is a no-op, and frame delivery will continue. - // - // Note: This should only be called after StartCapture() and before - // StopCapture(). Otherwise, its behavior is undefined. - virtual void Resume() {} - - // Stops capturing frames and clears all callbacks including the - // SupportedFormatsCallback callback. Note that queued frame callbacks - // may still occur after this call, so the caller must take care to - // use refcounted or weak references in |new_frame_callback|. - virtual void StopCapture() = 0; - - // Indicates to the source that a frame has been dropped. - virtual void OnFrameDropped(media::VideoCaptureFrameDropReason reason) {} - - // Hints to the source that if it has an alpha channel, that alpha channel - // will be ignored and can be discarded. - virtual void SetCanDiscardAlpha(bool can_discard_alpha) {} - - // Sends a log message to the source. - virtual void OnLog(const std::string& message) {} -}; - -} // namespace media - -#endif // MEDIA_CAPTURE_VIDEO_CAPTURER_SOURCE_H_ |