Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_capturer_source.h
blobf95dd594b2206949ae62678bb4df91b0df2459f6
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/message_loop/message_loop_proxy.h"
12 #include "base/threading/thread_checker.h"
13 #include "content/common/media/video_capture.h"
14 #include "content/renderer/media/media_stream_video_source.h"
15 #include "media/base/video_capturer_source.h"
17 namespace content {
19 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource
20 // for local video capturer. It uses VideoCaptureImplManager to start / stop
21 // and receive I420 frames from Chrome's video capture implementation.
23 // This is a render thread only object.
25 class CONTENT_EXPORT VideoCapturerDelegate : public media::VideoCapturerSource {
26 public:
27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info);
28 ~VideoCapturerDelegate() override;
30 // VideoCaptureDelegate Implementation.
31 void GetCurrentSupportedFormats(
32 int max_requested_width,
33 int max_requested_height,
34 double max_requested_frame_rate,
35 const VideoCaptureDeviceFormatsCB& callback) override;
37 void StartCapture(
38 const media::VideoCaptureParams& params,
39 const VideoCaptureDeliverFrameCB& new_frame_callback,
40 scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner,
41 const RunningCallback& running_callback) override;
43 void StopCapture() override;
45 private:
46 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended);
47 friend class MockVideoCapturerDelegate;
49 void OnStateUpdate(VideoCaptureState state);
50 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats);
51 void OnDeviceSupportedFormatsEnumerated(
52 const media::VideoCaptureFormats& formats);
54 // The id identifies which video capture device is used for this video
55 // capture session.
56 const media::VideoCaptureSessionId session_id_;
57 base::Closure release_device_cb_;
58 base::Closure stop_capture_cb_;
60 const bool is_screen_cast_;
62 // |running_callback| is provided to this class in StartCapture and must be
63 // valid until StopCapture is called.
64 RunningCallback running_callback_;
66 VideoCaptureDeviceFormatsCB source_formats_callback_;
68 // Bound to the render thread.
69 base::ThreadChecker thread_checker_;
71 base::WeakPtrFactory<VideoCapturerDelegate> weak_factory_;
73 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate);
76 // Owned by WebMediaStreamSource in Blink as a representation of a video
77 // stream coming from a camera.
78 // This is a render thread only object. All methods must be called on the
79 // render thread.
80 class CONTENT_EXPORT MediaStreamVideoCapturerSource
81 : public MediaStreamVideoSource {
82 public:
83 MediaStreamVideoCapturerSource(
84 const SourceStoppedCallback& stop_callback,
85 scoped_ptr<media::VideoCapturerSource> delegate);
86 virtual ~MediaStreamVideoCapturerSource();
88 void SetDeviceInfo(const StreamDeviceInfo& device_info);
90 protected:
91 // Implements MediaStreamVideoSource.
92 void GetCurrentSupportedFormats(
93 int max_requested_width,
94 int max_requested_height,
95 double max_requested_frame_rate,
96 const VideoCaptureDeviceFormatsCB& callback) override;
98 void StartSourceImpl(
99 const media::VideoCaptureFormat& format,
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_