| 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/gtest_prod_util.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 11 #include "content/common/media/video_capture.h" | 12 #include "content/common/media/video_capture.h" |
| 12 #include "content/renderer/media/media_stream_video_source.h" | 13 #include "content/renderer/media/media_stream_video_source.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource | 17 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource |
| 17 // for local video capturer. It uses VideoCaptureImplManager to start / stop | 18 // for local video capturer. It uses VideoCaptureImplManager to start / stop |
| 18 // and receive I420 frames from Chrome's video capture implementation. | 19 // and receive I420 frames from Chrome's video capture implementation. |
| 19 // | 20 // |
| 20 // This is a render thread only object. | 21 // This is a render thread only object. |
| 21 class CONTENT_EXPORT VideoCapturerDelegate | 22 class CONTENT_EXPORT VideoCapturerDelegate |
| 22 : public base::RefCountedThreadSafe<VideoCapturerDelegate> { | 23 : public base::RefCountedThreadSafe<VideoCapturerDelegate> { |
| 23 public: | 24 public: |
| 24 typedef base::Callback<void(bool running)> StartedCallback; | 25 typedef base::Callback<void(bool running)> RunningCallback; |
| 25 | 26 |
| 26 explicit VideoCapturerDelegate( | 27 explicit VideoCapturerDelegate( |
| 27 const StreamDeviceInfo& device_info); | 28 const StreamDeviceInfo& device_info); |
| 28 | 29 |
| 29 // Collects the formats that can currently be used. | 30 // Collects the formats that can currently be used. |
| 30 // |max_requested_height| and |max_requested_width| is used by Tab and Screen | 31 // |max_requested_height| and |max_requested_width| is used by Tab and Screen |
| 31 // capture to decide what resolution to generate. | 32 // capture to decide what resolution to generate. |
| 32 // |callback| is triggered when the formats have been collected. | 33 // |callback| is triggered when the formats have been collected. |
| 33 virtual void GetCurrentSupportedFormats( | 34 virtual void GetCurrentSupportedFormats( |
| 34 int max_requested_width, | 35 int max_requested_width, |
| 35 int max_requested_height, | 36 int max_requested_height, |
| 36 const VideoCaptureDeviceFormatsCB& callback); | 37 const VideoCaptureDeviceFormatsCB& callback); |
| 37 | 38 |
| 38 // Starts capturing frames using the resolution in |params|. | 39 // Starts capturing frames using the resolution in |params|. |
| 39 // |new_frame_callback| is triggered when a new video frame is available. | 40 // |new_frame_callback| is triggered when a new video frame is available. |
| 40 // |started_callback| is triggered before the first video frame is received | 41 // If capturing is started successfully then |running_callback| will be |
| 41 // or if the underlying video capturer fails to start. | 42 // called with a parameter of true. |
| 43 // If capturing fails to start or stopped due to an external event then |
| 44 // |running_callback| will be called with a parameter of false. |
| 42 virtual void StartCapture( | 45 virtual void StartCapture( |
| 43 const media::VideoCaptureParams& params, | 46 const media::VideoCaptureParams& params, |
| 44 const VideoCaptureDeliverFrameCB& new_frame_callback, | 47 const VideoCaptureDeliverFrameCB& new_frame_callback, |
| 45 const StartedCallback& started_callback); | 48 const RunningCallback& running_callback); |
| 46 | 49 |
| 47 // Stops capturing frames and clears all callbacks including the | 50 // Stops capturing frames and clears all callbacks including the |
| 48 // SupportedFormatsCallback callback. | 51 // SupportedFormatsCallback callback. |
| 49 virtual void StopCapture(); | 52 virtual void StopCapture(); |
| 50 | 53 |
| 51 private: | 54 private: |
| 55 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended); |
| 52 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; | 56 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; |
| 53 friend class MockVideoCapturerDelegate; | 57 friend class MockVideoCapturerDelegate; |
| 54 | 58 |
| 55 virtual ~VideoCapturerDelegate(); | 59 virtual ~VideoCapturerDelegate(); |
| 56 | 60 |
| 57 void OnStateUpdateOnRenderThread(VideoCaptureState state); | 61 void OnStateUpdateOnRenderThread(VideoCaptureState state); |
| 58 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 62 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
| 59 void OnDeviceSupportedFormatsEnumerated( | 63 void OnDeviceSupportedFormatsEnumerated( |
| 60 const media::VideoCaptureFormats& formats); | 64 const media::VideoCaptureFormats& formats); |
| 61 | 65 |
| 62 // The id identifies which video capture device is used for this video | 66 // The id identifies which video capture device is used for this video |
| 63 // capture session. | 67 // capture session. |
| 64 media::VideoCaptureSessionId session_id_; | 68 media::VideoCaptureSessionId session_id_; |
| 65 base::Closure release_device_cb_; | 69 base::Closure release_device_cb_; |
| 66 base::Closure stop_capture_cb_; | 70 base::Closure stop_capture_cb_; |
| 67 | 71 |
| 68 bool is_screen_cast_; | 72 bool is_screen_cast_; |
| 69 bool got_first_frame_; | 73 bool got_first_frame_; |
| 70 | 74 |
| 71 // |started_callback| is provided to this class in StartCapture and must be | 75 // |running_callback| is provided to this class in StartCapture and must be |
| 72 // valid until StopCapture is called. | 76 // valid until StopCapture is called. |
| 73 StartedCallback started_callback_; | 77 RunningCallback running_callback_; |
| 74 | 78 |
| 75 VideoCaptureDeviceFormatsCB source_formats_callback_; | 79 VideoCaptureDeviceFormatsCB source_formats_callback_; |
| 76 | 80 |
| 77 // Bound to the render thread. | 81 // Bound to the render thread. |
| 78 base::ThreadChecker thread_checker_; | 82 base::ThreadChecker thread_checker_; |
| 79 | 83 |
| 80 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); | 84 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 // Owned by WebMediaStreamSource in Blink as a representation of a video | 87 // Owned by WebMediaStreamSource in Blink as a representation of a video |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 private: | 114 private: |
| 111 // The delegate that provides video frames. | 115 // The delegate that provides video frames. |
| 112 scoped_refptr<VideoCapturerDelegate> delegate_; | 116 scoped_refptr<VideoCapturerDelegate> delegate_; |
| 113 | 117 |
| 114 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); | 118 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); |
| 115 }; | 119 }; |
| 116 | 120 |
| 117 } // namespace content | 121 } // namespace content |
| 118 | 122 |
| 119 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ | 123 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ |
| OLD | NEW |