Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_capturer_source.h
blob0cf52ee7a28f25be511faf24b5cbfb90d6d0fe74
1 // Copyright 2014 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.
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/common/media/video_capture.h"
13 #include "content/renderer/media/media_stream_video_source.h"
14 #include "media/base/video_capturer_source.h"
16 namespace content {
18 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource
19 // for local video capturer. It uses VideoCaptureImplManager to start / stop
20 // and receive I420 frames from Chrome's video capture implementation.
22 // This is a render thread only object.
24 class CONTENT_EXPORT VideoCapturerDelegate : public media::VideoCapturerSource {
25 public:
26 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info);
27 ~VideoCapturerDelegate() override;
29 // VideoCaptureDelegate Implementation.
30 void GetCurrentSupportedFormats(
31 int max_requested_width,
32 int max_requested_height,
33 double max_requested_frame_rate,
34 const VideoCaptureDeviceFormatsCB& callback) override;
36 void StartCapture(
37 const media::VideoCaptureParams& params,
38 const VideoCaptureDeliverFrameCB& new_frame_callback,
39 scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner,
40 const RunningCallback& running_callback) override;
42 void StopCapture() override;
44 private:
45 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended);
46 friend class MockVideoCapturerDelegate;
48 void OnStateUpdate(VideoCaptureState state);
49 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats);
50 void OnDeviceSupportedFormatsEnumerated(
51 const media::VideoCaptureFormats& formats);
53 // The id identifies which video capture device is used for this video
54 // capture session.
55 const media::VideoCaptureSessionId session_id_;
56 base::Closure release_device_cb_;
57 base::Closure stop_capture_cb_;
59 const bool is_screen_cast_;
61 // |running_callback| is provided to this class in StartCapture and must be
62 // valid until StopCapture is called.
63 RunningCallback running_callback_;
65 VideoCaptureDeviceFormatsCB source_formats_callback_;
67 // Bound to the render thread.
68 base::ThreadChecker thread_checker_;
70 base::WeakPtrFactory<VideoCapturerDelegate> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate);
75 // Owned by WebMediaStreamSource in Blink as a representation of a video
76 // stream coming from a camera.
77 // This is a render thread only object. All methods must be called on the
78 // render thread.
79 class CONTENT_EXPORT MediaStreamVideoCapturerSource
80 : public MediaStreamVideoSource {
81 public:
82 MediaStreamVideoCapturerSource(
83 const SourceStoppedCallback& stop_callback,
84 scoped_ptr<media::VideoCapturerSource> delegate);
85 virtual ~MediaStreamVideoCapturerSource();
87 void SetDeviceInfo(const StreamDeviceInfo& device_info);
89 protected:
90 // Implements MediaStreamVideoSource.
91 void GetCurrentSupportedFormats(
92 int max_requested_width,
93 int max_requested_height,
94 double max_requested_frame_rate,
95 const VideoCaptureDeviceFormatsCB& callback) override;
97 void StartSourceImpl(
98 const media::VideoCaptureFormat& format,
99 const blink::WebMediaConstraints& constraints,
100 const VideoCaptureDeliverFrameCB& frame_callback) override;
102 void StopSourceImpl() override;
104 private:
105 void OnStarted(bool result);
106 // The delegate that provides video frames.
107 const scoped_ptr<media::VideoCapturerSource> delegate_;
109 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource);
112 } // namespace content
114 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_