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 
5 #ifndef CONTENT_PUBLIC_BROWSER_VIDEO_CAPTURE_DEVICE_LAUNCHER_H_
6 #define CONTENT_PUBLIC_BROWSER_VIDEO_CAPTURE_DEVICE_LAUNCHER_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "content/common/content_export.h"
12 #include "media/capture/video/video_capture_device.h"
13 #include "media/capture/video/video_capture_device_info.h"
14 #include "media/capture/video/video_frame_receiver.h"
15 #include "media/capture/video_capture_types.h"
16 #include "third_party/blink/public/common/mediastream/media_stream_request.h"
17 #include "ui/gfx/native_widget_types.h"
18 
19 namespace content {
20 
21 class LaunchedVideoCaptureDevice;
22 
23 // Asynchronously launches video capture devices. After a call to
24 // LaunchDeviceAsync() it is illegal to call LaunchDeviceAsync() again until
25 // |callbacks| has been notified about the outcome of the asynchronous launch.
26 class CONTENT_EXPORT VideoCaptureDeviceLauncher {
27  public:
28   class CONTENT_EXPORT Callbacks {
29    public:
~Callbacks()30     virtual ~Callbacks() {}
31     virtual void OnDeviceLaunched(
32         std::unique_ptr<LaunchedVideoCaptureDevice> device) = 0;
33     virtual void OnDeviceLaunchFailed(media::VideoCaptureError error) = 0;
34     virtual void OnDeviceLaunchAborted() = 0;
35   };
36 
~VideoCaptureDeviceLauncher()37   virtual ~VideoCaptureDeviceLauncher() {}
38 
39   // Creates an InProcessVideoCaptureDeviceLauncher.
40   static std::unique_ptr<VideoCaptureDeviceLauncher>
41   CreateInProcessVideoCaptureDeviceLauncher(
42       scoped_refptr<base::SingleThreadTaskRunner> device_task_runner);
43 
44   // The passed-in |done_cb| must guarantee that the context relevant
45   // during the asynchronous processing stays alive.
46   virtual void LaunchDeviceAsync(
47       const std::string& device_id,
48       blink::mojom::MediaStreamType stream_type,
49       const media::VideoCaptureParams& params,
50       base::WeakPtr<media::VideoFrameReceiver> receiver,
51       base::OnceClosure connection_lost_cb,
52       Callbacks* callbacks,
53       base::OnceClosure done_cb) = 0;
54 
55   virtual void AbortLaunch() = 0;
56 };
57 
58 class CONTENT_EXPORT LaunchedVideoCaptureDevice
59     : public media::VideoFrameConsumerFeedbackObserver {
60  public:
61   // Device operation methods.
62   virtual void GetPhotoState(
63       media::VideoCaptureDevice::GetPhotoStateCallback callback) = 0;
64   virtual void SetPhotoOptions(
65       media::mojom::PhotoSettingsPtr settings,
66       media::VideoCaptureDevice::SetPhotoOptionsCallback callback) = 0;
67   virtual void TakePhoto(
68       media::VideoCaptureDevice::TakePhotoCallback callback) = 0;
69   virtual void MaybeSuspendDevice() = 0;
70   virtual void ResumeDevice() = 0;
71   virtual void RequestRefreshFrame() = 0;
72 
73   // Methods for specific types of devices.
74   virtual void SetDesktopCaptureWindowIdAsync(gfx::NativeViewId window_id,
75                                               base::OnceClosure done_cb) = 0;
76 };
77 
78 }  // namespace content
79 
80 #endif  // CONTENT_PUBLIC_BROWSER_VIDEO_CAPTURE_DEVICE_LAUNCHER_H_
81