| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CANVAS_CAPTURE_HANDLER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ | 6 #define CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // All methods are called on the same thread as construction and destruction, | 34 // All methods are called on the same thread as construction and destruction, |
| 35 // i.e. the Main Render thread. Note that a CanvasCaptureHandlerDelegate is | 35 // i.e. the Main Render thread. Note that a CanvasCaptureHandlerDelegate is |
| 36 // used to send back frames to |io_task_runner_|, i.e. IO thread. | 36 // used to send back frames to |io_task_runner_|, i.e. IO thread. |
| 37 class CONTENT_EXPORT CanvasCaptureHandler final | 37 class CONTENT_EXPORT CanvasCaptureHandler final |
| 38 : public NON_EXPORTED_BASE(blink::WebCanvasCaptureHandler) { | 38 : public NON_EXPORTED_BASE(blink::WebCanvasCaptureHandler) { |
| 39 public: | 39 public: |
| 40 ~CanvasCaptureHandler() override; | 40 ~CanvasCaptureHandler() override; |
| 41 | 41 |
| 42 // Creates a CanvasCaptureHandler instance and updates UMA histogram. | 42 // Creates a CanvasCaptureHandler instance and updates UMA histogram. |
| 43 static CanvasCaptureHandler* CreateCanvasCaptureHandler( | 43 static CanvasCaptureHandler* CreateCanvasCaptureHandler( |
| 44 const blink::WebSize& size, | 44 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 45 double frame_rate, | |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | |
| 47 blink::WebMediaStreamTrack* track); | |
| 48 | 45 |
| 49 // blink::WebCanvasCaptureHandler Implementation. | 46 // blink::WebCanvasCaptureHandler Implementation. |
| 47 // A VideoCapturerSource instance is created, which is responsible for handing |
| 48 // stop&start callbacks back to CanvasCaptureHandler. That VideoCapturerSource |
| 49 // is then plugged into a MediaStreamTrack passed as |track|, and it is owned |
| 50 // by the Blink side MediaStreamSource. |
| 51 blink::WebMediaStreamTrack createTrack(const blink::WebSize& size, |
| 52 double frame_rate) override; |
| 50 void sendNewFrame(const SkImage* image) override; | 53 void sendNewFrame(const SkImage* image) override; |
| 51 bool needsNewFrame() const override; | 54 bool needsNewFrame() const override; |
| 52 | 55 |
| 53 // Functions called by media::VideoCapturerSource implementation. | 56 // Functions called by media::VideoCapturerSource implementation. |
| 54 void StartVideoCapture( | 57 void StartVideoCapture( |
| 55 const media::VideoCaptureParams& params, | 58 const media::VideoCaptureParams& params, |
| 56 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB& | 59 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB& |
| 57 new_frame_callback, | 60 new_frame_callback, |
| 58 const media::VideoCapturerSource::RunningCallback& running_callback); | 61 const media::VideoCapturerSource::RunningCallback& running_callback); |
| 59 void RequestRefreshFrame(); | 62 void RequestRefreshFrame(); |
| 60 void StopVideoCapture(); | 63 void StopVideoCapture(); |
| 61 blink::WebSize GetSourceSize() const { return size_; } | 64 blink::WebSize GetSourceSize() const { return size_; } |
| 62 | 65 |
| 63 private: | 66 private: |
| 64 // A VideoCapturerSource instance is created, which is responsible for handing | 67 explicit CanvasCaptureHandler( |
| 65 // stop&start callbacks back to CanvasCaptureHandler. That VideoCapturerSource | 68 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 66 // is then plugged into a MediaStreamTrack passed as |track|, and it is owned | |
| 67 // by the Blink side MediaStreamSource. | |
| 68 CanvasCaptureHandler( | |
| 69 const blink::WebSize& size, | |
| 70 double frame_rate, | |
| 71 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | |
| 72 blink::WebMediaStreamTrack* track); | |
| 73 | 69 |
| 74 void CreateNewFrame(const SkImage* image); | 70 void CreateNewFrame(const SkImage* image); |
| 75 void AddVideoCapturerSourceToVideoTrack( | |
| 76 std::unique_ptr<media::VideoCapturerSource> source, | |
| 77 blink::WebMediaStreamTrack* web_track); | |
| 78 | 71 |
| 79 // Object that does all the work of running |new_frame_callback_|. | 72 // Object that does all the work of running |new_frame_callback_|. |
| 80 // Destroyed on |frame_callback_task_runner_| after the class is destroyed. | 73 // Destroyed on |frame_callback_task_runner_| after the class is destroyed. |
| 81 class CanvasCaptureHandlerDelegate; | 74 class CanvasCaptureHandlerDelegate; |
| 82 | 75 |
| 83 media::VideoCaptureFormat capture_format_; | 76 media::VideoCaptureFormat capture_format_; |
| 84 bool ask_for_new_frame_; | 77 bool ask_for_new_frame_; |
| 85 | 78 |
| 86 const blink::WebSize size_; | 79 blink::WebSize size_; |
| 87 gfx::Size last_size; | 80 gfx::Size last_size; |
| 88 std::vector<uint8_t> temp_data_; | 81 std::vector<uint8_t> temp_data_; |
| 89 size_t temp_data_stride_; | 82 size_t temp_data_stride_; |
| 90 SkImageInfo image_info_; | 83 SkImageInfo image_info_; |
| 91 media::VideoFramePool frame_pool_; | 84 media::VideoFramePool frame_pool_; |
| 92 | 85 |
| 93 scoped_refptr<media::VideoFrame> last_frame_; | 86 scoped_refptr<media::VideoFrame> last_frame_; |
| 94 | 87 |
| 95 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 88 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 96 std::unique_ptr<CanvasCaptureHandlerDelegate> delegate_; | 89 std::unique_ptr<CanvasCaptureHandlerDelegate> delegate_; |
| 97 | 90 |
| 98 // Bound to Main Render thread. | 91 // Bound to Main Render thread. |
| 99 base::ThreadChecker main_render_thread_checker_; | 92 base::ThreadChecker main_render_thread_checker_; |
| 100 base::WeakPtrFactory<CanvasCaptureHandler> weak_ptr_factory_; | 93 base::WeakPtrFactory<CanvasCaptureHandler> weak_ptr_factory_; |
| 101 | 94 |
| 102 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler); | 95 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler); |
| 103 }; | 96 }; |
| 104 | 97 |
| 105 } // namespace content | 98 } // namespace content |
| 106 | 99 |
| 107 #endif // CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ | 100 #endif // CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ |
| OLD | NEW |