Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / media / media_stream_video_capturer_source.h
bloba0dd791529c39110966e0a60cd369ba3001124dc
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/message_loop/message_loop_proxy.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"
15 namespace content {
17 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource
18 // for local video capturer. It uses VideoCaptureImplManager to start / stop
19 // and receive I420 frames from Chrome's video capture implementation.
21 // This is a render thread only object.
22 class CONTENT_EXPORT VideoCapturerDelegate
23 : public base::RefCountedThreadSafe<VideoCapturerDelegate> {
24 public:
25 typedef base::Callback<void(MediaStreamRequestResult result)> RunningCallback;
27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info);
29 // Collects the formats that can currently be used.
30 // |max_requested_height|, |max_requested_width|, and
31 // |max_requested_frame_rate| is used by Tab and Screen capture to decide what
32 // resolution/framerate to generate. |callback| is triggered when the formats
33 // have been collected.
34 virtual void GetCurrentSupportedFormats(
35 int max_requested_width,
36 int max_requested_height,
37 double max_requested_frame_rate,
38 const VideoCaptureDeviceFormatsCB& callback);
40 // Starts capturing frames using the resolution in |params|.
41 // |new_frame_callback| is triggered when a new video frame is available.
42 // If capturing is started successfully then |running_callback| will be
43 // called with a parameter of true.
44 // If capturing fails to start or stopped due to an external event then
45 // |running_callback| will be called with a parameter of false.
46 virtual void StartCapture(
47 const media::VideoCaptureParams& params,
48 const VideoCaptureDeliverFrameCB& new_frame_callback,
49 const RunningCallback& running_callback);
51 // Stops capturing frames and clears all callbacks including the
52 // SupportedFormatsCallback callback.
53 virtual void StopCapture();
55 private:
56 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended);
57 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>;
58 friend class MockVideoCapturerDelegate;
60 virtual ~VideoCapturerDelegate();
62 void OnStateUpdateOnRenderThread(VideoCaptureState state);
63 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats);
64 void OnDeviceSupportedFormatsEnumerated(
65 const media::VideoCaptureFormats& formats);
67 // The id identifies which video capture device is used for this video
68 // capture session.
69 media::VideoCaptureSessionId session_id_;
70 base::Closure release_device_cb_;
71 base::Closure stop_capture_cb_;
73 bool is_screen_cast_;
75 // |running_callback| is provided to this class in StartCapture and must be
76 // valid until StopCapture is called.
77 RunningCallback running_callback_;
79 VideoCaptureDeviceFormatsCB source_formats_callback_;
81 // Bound to the render thread.
82 base::ThreadChecker thread_checker_;
84 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate);
87 // Owned by WebMediaStreamSource in Blink as a representation of a video
88 // stream coming from a camera.
89 // This is a render thread only object. All methods must be called on the
90 // render thread.
91 class CONTENT_EXPORT MediaStreamVideoCapturerSource
92 : public MediaStreamVideoSource {
93 public:
94 MediaStreamVideoCapturerSource(
95 const StreamDeviceInfo& device_info,
96 const SourceStoppedCallback& stop_callback,
97 const scoped_refptr<VideoCapturerDelegate>& delegate);
99 virtual ~MediaStreamVideoCapturerSource();
101 protected:
102 // Implements MediaStreamVideoSource.
103 virtual void GetCurrentSupportedFormats(
104 int max_requested_width,
105 int max_requested_height,
106 double max_requested_frame_rate,
107 const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
109 virtual void StartSourceImpl(
110 const media::VideoCaptureParams& params,
111 const VideoCaptureDeliverFrameCB& frame_callback) OVERRIDE;
113 virtual void StopSourceImpl() OVERRIDE;
115 private:
116 // The delegate that provides video frames.
117 scoped_refptr<VideoCapturerDelegate> delegate_;
119 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource);
122 } // namespace content
124 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_