device_proxy_lacros.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "services/video_capture/lacros/device_proxy_lacros.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "media/capture/mojom/image_capture.mojom.h"
  8. #include "services/video_capture/lacros/video_frame_handler_proxy_lacros.h"
  9. namespace video_capture {
  10. DeviceProxyLacros::DeviceProxyLacros(
  11. mojo::PendingReceiver<mojom::Device> device_receiver,
  12. mojo::PendingRemote<crosapi::mojom::VideoCaptureDevice> proxy_remote,
  13. base::OnceClosure cleanup_callback)
  14. : device_(std::move(proxy_remote)) {
  15. receiver_.Bind(std::move(device_receiver));
  16. receiver_.set_disconnect_handler(std::move(cleanup_callback));
  17. // Note that currently all versioned calls that we need to make are
  18. // best effort, and can just be dropped if we haven't gotten an updated
  19. // version yet. If that changes, we'll need to track that we have an
  20. // outstanding query and respond accordingly.
  21. device_.QueryVersion(base::DoNothing());
  22. }
  23. DeviceProxyLacros::~DeviceProxyLacros() = default;
  24. void DeviceProxyLacros::Start(
  25. const media::VideoCaptureParams& requested_settings,
  26. mojo::PendingRemote<mojom::VideoFrameHandler> handler) {
  27. mojo::PendingRemote<crosapi::mojom::VideoFrameHandler> proxy_handler_remote;
  28. handler_ = std::make_unique<VideoFrameHandlerProxyLacros>(
  29. proxy_handler_remote.InitWithNewPipeAndPassReceiver(),
  30. std::move(handler));
  31. device_->Start(std::move(requested_settings),
  32. std::move(proxy_handler_remote));
  33. }
  34. void DeviceProxyLacros::MaybeSuspend() {
  35. device_->MaybeSuspend();
  36. }
  37. void DeviceProxyLacros::Resume() {
  38. device_->Resume();
  39. }
  40. void DeviceProxyLacros::GetPhotoState(GetPhotoStateCallback callback) {
  41. device_->GetPhotoState(std::move(callback));
  42. }
  43. void DeviceProxyLacros::SetPhotoOptions(media::mojom::PhotoSettingsPtr settings,
  44. SetPhotoOptionsCallback callback) {
  45. device_->SetPhotoOptions(std::move(settings), std::move(callback));
  46. }
  47. void DeviceProxyLacros::TakePhoto(TakePhotoCallback callback) {
  48. device_->TakePhoto(std::move(callback));
  49. }
  50. void DeviceProxyLacros::ProcessFeedback(
  51. const media::VideoCaptureFeedback& feedback) {
  52. device_->ProcessFeedback(std::move(feedback));
  53. }
  54. void DeviceProxyLacros::RequestRefreshFrame() {
  55. if (device_.version() >=
  56. int{crosapi::mojom::VideoCaptureDevice::MethodMinVersions::
  57. kRequestRefreshFrameMinVersion}) {
  58. device_->RequestRefreshFrame();
  59. }
  60. }
  61. } // namespace video_capture