| 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/gtest_prod_util.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "content/common/media/video_capture.h" | 13 #include "content/common/media/video_capture.h" |
| 14 #include "content/renderer/media/media_stream_video_source.h" | 14 #include "content/renderer/media/media_stream_video_source.h" |
| 15 #include "media/video/capture/video_capturer_source.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource | 19 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource |
| 19 // for local video capturer. It uses VideoCaptureImplManager to start / stop | 20 // for local video capturer. It uses VideoCaptureImplManager to start / stop |
| 20 // and receive I420 frames from Chrome's video capture implementation. | 21 // and receive I420 frames from Chrome's video capture implementation. |
| 21 // | 22 // |
| 22 // This is a render thread only object. | 23 // This is a render thread only object. |
| 23 class CONTENT_EXPORT VideoCapturerDelegate { | 24 |
| 25 class CONTENT_EXPORT VideoCapturerDelegate : public media::VideoCapturerSource { |
| 24 public: | 26 public: |
| 25 typedef base::Callback<void(MediaStreamRequestResult result)> RunningCallback; | 27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info); |
| 26 | 28 |
| 27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info); | 29 // VideoCaptureDelegate Implementation. |
| 28 virtual ~VideoCapturerDelegate(); | 30 void GetCurrentSupportedFormats( |
| 29 | |
| 30 // Collects the formats that can currently be used. | |
| 31 // |max_requested_height|, |max_requested_width|, and | |
| 32 // |max_requested_frame_rate| is used by Tab and Screen capture to decide what | |
| 33 // resolution/framerate to generate. |callback| is triggered when the formats | |
| 34 // have been collected. | |
| 35 virtual void GetCurrentSupportedFormats( | |
| 36 int max_requested_width, | 31 int max_requested_width, |
| 37 int max_requested_height, | 32 int max_requested_height, |
| 38 double max_requested_frame_rate, | 33 double max_requested_frame_rate, |
| 39 const VideoCaptureDeviceFormatsCB& callback); | 34 const VideoCaptureDeviceFormatsCB& callback) override; |
| 40 | 35 |
| 41 // Starts capturing frames using the resolution in |params|. | 36 void StartCapture( |
| 42 // |new_frame_callback| is triggered when a new video frame is available. | |
| 43 // If capturing is started successfully then |running_callback| will be | |
| 44 // called with a parameter of true. | |
| 45 // If capturing fails to start or stopped due to an external event then | |
| 46 // |running_callback| will be called with a parameter of false. | |
| 47 virtual void StartCapture( | |
| 48 const media::VideoCaptureParams& params, | 37 const media::VideoCaptureParams& params, |
| 49 const VideoCaptureDeliverFrameCB& new_frame_callback, | 38 const VideoCaptureDeliverFrameCB& new_frame_callback, |
| 50 const RunningCallback& running_callback); | 39 const RunningCallback& running_callback) override; |
| 51 | 40 |
| 52 // Stops capturing frames and clears all callbacks including the | 41 void StopCapture() override; |
| 53 // SupportedFormatsCallback callback. | |
| 54 virtual void StopCapture(); | |
| 55 | 42 |
| 56 private: | 43 private: |
| 44 ~VideoCapturerDelegate() override; |
| 57 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended); | 45 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended); |
| 58 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; | 46 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; |
| 59 friend class MockVideoCapturerDelegate; | 47 friend class MockVideoCapturerDelegate; |
| 60 | 48 |
| 61 void OnStateUpdateOnRenderThread(VideoCaptureState state); | 49 void OnStateUpdateOnRenderThread(VideoCaptureState state); |
| 62 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 50 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
| 63 void OnDeviceSupportedFormatsEnumerated( | 51 void OnDeviceSupportedFormatsEnumerated( |
| 64 const media::VideoCaptureFormats& formats); | 52 const media::VideoCaptureFormats& formats); |
| 65 | 53 |
| 66 // The id identifies which video capture device is used for this video | 54 // The id identifies which video capture device is used for this video |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 // Owned by WebMediaStreamSource in Blink as a representation of a video | 76 // Owned by WebMediaStreamSource in Blink as a representation of a video |
| 89 // stream coming from a camera. | 77 // stream coming from a camera. |
| 90 // This is a render thread only object. All methods must be called on the | 78 // This is a render thread only object. All methods must be called on the |
| 91 // render thread. | 79 // render thread. |
| 92 class CONTENT_EXPORT MediaStreamVideoCapturerSource | 80 class CONTENT_EXPORT MediaStreamVideoCapturerSource |
| 93 : public MediaStreamVideoSource { | 81 : public MediaStreamVideoSource { |
| 94 public: | 82 public: |
| 95 MediaStreamVideoCapturerSource( | 83 MediaStreamVideoCapturerSource( |
| 96 const StreamDeviceInfo& device_info, | 84 const StreamDeviceInfo& device_info, |
| 97 const SourceStoppedCallback& stop_callback, | 85 const SourceStoppedCallback& stop_callback, |
| 98 scoped_ptr<VideoCapturerDelegate> delegate); | 86 scoped_refptr<media::VideoCapturerSource> delegate); |
| 99 | 87 |
| 100 virtual ~MediaStreamVideoCapturerSource(); | 88 virtual ~MediaStreamVideoCapturerSource(); |
| 101 | 89 |
| 102 protected: | 90 protected: |
| 103 // Implements MediaStreamVideoSource. | 91 // Implements MediaStreamVideoSource. |
| 104 void GetCurrentSupportedFormats( | 92 void GetCurrentSupportedFormats( |
| 105 int max_requested_width, | 93 int max_requested_width, |
| 106 int max_requested_height, | 94 int max_requested_height, |
| 107 double max_requested_frame_rate, | 95 double max_requested_frame_rate, |
| 108 const VideoCaptureDeviceFormatsCB& callback) override; | 96 const VideoCaptureDeviceFormatsCB& callback) override; |
| 109 | 97 |
| 110 void StartSourceImpl( | 98 void StartSourceImpl( |
| 111 const media::VideoCaptureFormat& format, | 99 const media::VideoCaptureFormat& format, |
| 112 const VideoCaptureDeliverFrameCB& frame_callback) override; | 100 const VideoCaptureDeliverFrameCB& frame_callback) override; |
| 113 | 101 |
| 114 void StopSourceImpl() override; | 102 void StopSourceImpl() override; |
| 115 | 103 |
| 116 private: | 104 private: |
| 105 void OnStarted(bool result); |
| 117 // The delegate that provides video frames. | 106 // The delegate that provides video frames. |
| 118 scoped_ptr<VideoCapturerDelegate> delegate_; | 107 scoped_refptr<media::VideoCapturerSource> delegate_; |
| 119 | 108 |
| 120 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); | 109 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); |
| 121 }; | 110 }; |
| 122 | 111 |
| 123 } // namespace content | 112 } // namespace content |
| 124 | 113 |
| 125 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ | 114 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ |
| OLD | NEW |