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