push_video_stream_subscription_impl.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2018 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. #ifndef SERVICES_VIDEO_CAPTURE_PUSH_VIDEO_STREAM_SUBSCRIPTION_IMPL_H_
  5. #define SERVICES_VIDEO_CAPTURE_PUSH_VIDEO_STREAM_SUBSCRIPTION_IMPL_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "mojo/public/cpp/bindings/pending_remote.h"
  8. #include "mojo/public/cpp/bindings/receiver.h"
  9. #include "mojo/public/cpp/bindings/remote.h"
  10. #include "services/video_capture/public/mojom/device.mojom.h"
  11. #include "services/video_capture/public/mojom/video_frame_handler.mojom.h"
  12. #include "services/video_capture/public/mojom/video_source.mojom.h"
  13. namespace video_capture {
  14. class BroadcastingReceiver;
  15. class PushVideoStreamSubscriptionImpl
  16. : public mojom::PushVideoStreamSubscription {
  17. public:
  18. PushVideoStreamSubscriptionImpl(
  19. mojo::PendingReceiver<mojom::PushVideoStreamSubscription>
  20. subscription_receiver,
  21. mojo::PendingRemote<mojom::VideoFrameHandler> subscriber,
  22. const media::VideoCaptureParams& requested_settings,
  23. mojom::VideoSource::CreatePushSubscriptionCallback creation_callback,
  24. BroadcastingReceiver* broadcaster,
  25. mojo::Remote<mojom::Device>* device);
  26. PushVideoStreamSubscriptionImpl(const PushVideoStreamSubscriptionImpl&) =
  27. delete;
  28. PushVideoStreamSubscriptionImpl& operator=(
  29. const PushVideoStreamSubscriptionImpl&) = delete;
  30. ~PushVideoStreamSubscriptionImpl() override;
  31. void SetOnClosedHandler(
  32. base::OnceCallback<void(base::OnceClosure done_cb)> handler);
  33. void OnDeviceStartSucceededWithSettings(
  34. const media::VideoCaptureParams& settings);
  35. void OnDeviceStartFailed(media::VideoCaptureError error);
  36. // mojom::PushVideoStreamSubscription implementation.
  37. void Activate() override;
  38. void Suspend(SuspendCallback callback) override;
  39. void Resume() override;
  40. void GetPhotoState(GetPhotoStateCallback callback) override;
  41. void SetPhotoOptions(media::mojom::PhotoSettingsPtr settings,
  42. SetPhotoOptionsCallback callback) override;
  43. void TakePhoto(TakePhotoCallback callback) override;
  44. void Close(CloseCallback callback) override;
  45. void ProcessFeedback(const media::VideoCaptureFeedback& feedback) override;
  46. private:
  47. enum class Status {
  48. kCreationCallbackNotYetRun,
  49. kNotYetActivated,
  50. kActive,
  51. kSuspended,
  52. kClosed
  53. };
  54. void OnConnectionLost();
  55. mojo::Receiver<mojom::PushVideoStreamSubscription> receiver_;
  56. mojo::PendingRemote<mojom::VideoFrameHandler> subscriber_;
  57. const media::VideoCaptureParams requested_settings_;
  58. mojom::VideoSource::CreatePushSubscriptionCallback creation_callback_;
  59. const raw_ptr<BroadcastingReceiver> broadcaster_;
  60. const raw_ptr<mojo::Remote<mojom::Device>> device_;
  61. Status status_;
  62. // Client id handed out by |broadcaster_| when registering |this| as its
  63. // client.
  64. int32_t broadcaster_client_id_;
  65. // A callback that we invoke when this instance changes |status_| to
  66. // kClosed via a call to Close().
  67. base::OnceCallback<void(base::OnceClosure done_cb)> on_closed_handler_;
  68. base::WeakPtrFactory<PushVideoStreamSubscriptionImpl> weak_factory_{this};
  69. };
  70. } // namespace video_capture
  71. #endif // SERVICES_VIDEO_CAPTURE_PUSH_VIDEO_STREAM_SUBSCRIPTION_IMPL_H_