OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/threading/thread_checker.h" |
10 #include "content/common/media/video_capture.h" | 11 #include "content/common/media/video_capture.h" |
11 #include "content/renderer/media/media_stream_video_source.h" | 12 #include "content/renderer/media/media_stream_video_source.h" |
12 #include "media/video/capture/video_capture.h" | |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 class VideoCaptureHandle; | |
17 | |
18 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource | 16 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource |
19 // for local video capturer. It uses VideoCaptureImplManager to start / stop | 17 // for local video capturer. It uses VideoCaptureImplManager to start / stop |
20 // and receive I420 frames from Chrome's video capture implementation. | 18 // and receive I420 frames from Chrome's video capture implementation. |
| 19 // |
| 20 // This is a render thread only object. |
21 class CONTENT_EXPORT VideoCapturerDelegate | 21 class CONTENT_EXPORT VideoCapturerDelegate |
22 : public media::VideoCapture::EventHandler, | 22 : public base::RefCountedThreadSafe<VideoCapturerDelegate> { |
23 public base::RefCountedThreadSafe<VideoCapturerDelegate> { | |
24 public: | 23 public: |
25 typedef base::Callback<void(const scoped_refptr<media::VideoFrame>&)> | |
26 NewFrameCallback; | |
27 typedef base::Callback<void(bool running)> StartedCallback; | 24 typedef base::Callback<void(bool running)> StartedCallback; |
28 typedef base::Callback<void(const media::VideoCaptureFormats& formats)> | |
29 SupportedFormatsCallback; | |
30 | 25 |
31 explicit VideoCapturerDelegate( | 26 explicit VideoCapturerDelegate( |
32 const StreamDeviceInfo& device_info); | 27 const StreamDeviceInfo& device_info); |
33 | 28 |
34 // Collects the formats that can currently be used. | 29 // Collects the formats that can currently be used. |
35 // |max_requested_height| and |max_requested_width| is used by Tab and Screen | 30 // |max_requested_height| and |max_requested_width| is used by Tab and Screen |
36 // capture to decide what resolution to generate. | 31 // capture to decide what resolution to generate. |
37 // |callback| is triggered when the formats have been collected. | 32 // |callback| is triggered when the formats have been collected. |
38 virtual void GetCurrentSupportedFormats( | 33 virtual void GetCurrentSupportedFormats( |
39 int max_requested_width, | 34 int max_requested_width, |
40 int max_requested_height, | 35 int max_requested_height, |
41 const SupportedFormatsCallback& callback); | 36 const VideoCaptureDeviceFormatsCB& callback); |
42 | 37 |
43 // Starts deliver frames using the resolution in |params|. | 38 // Starts capturing frames using the resolution in |params|. |
44 // |new_frame_callback| is triggered when a new video frame is available. | 39 // |new_frame_callback| is triggered when a new video frame is available. |
45 // |started_callback| is triggered before the first video frame is received | 40 // |started_callback| is triggered before the first video frame is received |
46 // or if the underlying video capturer fails to start. | 41 // or if the underlying video capturer fails to start. |
47 virtual void StartDeliver( | 42 virtual void StartCapture( |
48 const media::VideoCaptureParams& params, | 43 const media::VideoCaptureParams& params, |
49 const NewFrameCallback& new_frame_callback, | 44 const VideoCaptureDeliverFrameCB& new_frame_callback, |
50 const StartedCallback& started_callback); | 45 const StartedCallback& started_callback); |
51 | 46 |
52 // Stops deliver frames and clears all callbacks including the | 47 // Stops capturing frames and clears all callbacks including the |
53 // SupportedFormatsCallback callback. | 48 // SupportedFormatsCallback callback. |
54 virtual void StopDeliver(); | 49 virtual void StopCapture(); |
55 | |
56 protected: | |
57 // media::VideoCapture::EventHandler implementation. | |
58 // These functions are called on the IO thread (same as where | |
59 // |capture_engine_| runs). | |
60 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE; | |
61 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE; | |
62 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE; | |
63 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE; | |
64 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE; | |
65 virtual void OnFrameReady( | |
66 media::VideoCapture* capture, | |
67 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; | |
68 | 50 |
69 private: | 51 private: |
70 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; | 52 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; |
71 friend class MockVideoCapturerDelegate; | 53 friend class MockVideoCapturerDelegate; |
72 | 54 |
73 virtual ~VideoCapturerDelegate(); | 55 virtual ~VideoCapturerDelegate(); |
74 | 56 |
75 void OnFrameReadyOnRenderThread( | 57 void OnFrameReadyOnRenderThread( |
76 media::VideoCapture* capture, | 58 const scoped_refptr<media::VideoFrame>& frame, |
77 const scoped_refptr<media::VideoFrame>& frame); | 59 const media::VideoCaptureFormat& format); |
78 void OnErrorOnRenderThread(media::VideoCapture* capture); | 60 void OnStateUpdateOnRenderThread(VideoCaptureState state); |
79 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 61 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
80 void OnDeviceSupportedFormatsEnumerated( | 62 void OnDeviceSupportedFormatsEnumerated( |
81 const media::VideoCaptureFormats& formats); | 63 const media::VideoCaptureFormats& formats); |
82 | 64 |
83 // The id identifies which video capture device is used for this video | 65 // The id identifies which video capture device is used for this video |
84 // capture session. | 66 // capture session. |
85 media::VideoCaptureSessionId session_id_; | 67 media::VideoCaptureSessionId session_id_; |
86 scoped_ptr<VideoCaptureHandle> capture_engine_; | 68 base::Closure release_device_cb_; |
| 69 base::Closure stop_capture_cb_; |
87 | 70 |
88 bool is_screen_cast_; | 71 bool is_screen_cast_; |
89 | |
90 // Accessed on the thread where StartDeliver is called. | |
91 bool got_first_frame_; | 72 bool got_first_frame_; |
92 | 73 |
93 // |new_frame_callback_| is provided to this class in StartDeliver and must be | 74 // |new_frame_callback_| is provided to this class in StartToDeliver and must |
94 // valid until StopDeliver is called. | 75 // be valid until StopDeliver is called. |
95 NewFrameCallback new_frame_callback_; | 76 VideoCaptureDeliverFrameCB new_frame_callback_; |
96 // |started_callback| is provided to this class in StartDeliver and must be | 77 // |started_callback| is provided to this class in StartToDeliver and must be |
97 // valid until StopDeliver is called. | 78 // valid until StopDeliver is called. |
98 StartedCallback started_callback_; | 79 StartedCallback started_callback_; |
99 // Message loop of the caller of StartDeliver. | |
100 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
101 | 80 |
102 SupportedFormatsCallback source_formats_callback_; | 81 VideoCaptureDeviceFormatsCB source_formats_callback_; |
| 82 |
| 83 // Bound to the render thread. |
| 84 base::ThreadChecker thread_checker_; |
103 | 85 |
104 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); |
105 }; | 87 }; |
106 | 88 |
| 89 // Owned by WebMediaStreamSource in Blink as a representation of a video |
| 90 // stream coming from a camera. |
| 91 // This is a render thread only object. All methods must be called on the |
| 92 // render thread. |
107 class CONTENT_EXPORT MediaStreamVideoCapturerSource | 93 class CONTENT_EXPORT MediaStreamVideoCapturerSource |
108 : public MediaStreamVideoSource { | 94 : public MediaStreamVideoSource { |
109 public: | 95 public: |
110 MediaStreamVideoCapturerSource( | 96 MediaStreamVideoCapturerSource( |
111 const StreamDeviceInfo& device_info, | 97 const StreamDeviceInfo& device_info, |
112 const SourceStoppedCallback& stop_callback, | 98 const SourceStoppedCallback& stop_callback, |
113 const scoped_refptr<VideoCapturerDelegate>& delegate); | 99 const scoped_refptr<VideoCapturerDelegate>& delegate); |
114 | 100 |
115 virtual ~MediaStreamVideoCapturerSource(); | 101 virtual ~MediaStreamVideoCapturerSource(); |
116 | 102 |
(...skipping 11 matching lines...) Expand all Loading... |
128 private: | 114 private: |
129 // The delegate that provides video frames. | 115 // The delegate that provides video frames. |
130 scoped_refptr<VideoCapturerDelegate> delegate_; | 116 scoped_refptr<VideoCapturerDelegate> delegate_; |
131 | 117 |
132 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); | 118 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); |
133 }; | 119 }; |
134 | 120 |
135 } // namespace content | 121 } // namespace content |
136 | 122 |
137 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ | 123 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ |
OLD | NEW |