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 "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "media/base/video_capturer_source.h" | 13 #include "media/base/video_capturer_source.h" |
14 #include "media/base/video_frame_pool.h" | 14 #include "media/base/video_frame_pool.h" |
15 #include "third_party/WebKit/public/platform/WebCanvasCaptureHandler.h" | 15 #include "third_party/WebKit/public/platform/WebCanvasCaptureHandler.h" |
16 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
17 #include "third_party/WebKit/public/platform/WebSize.h" | 17 #include "third_party/WebKit/public/platform/WebSize.h" |
18 #include "third_party/WebKit/public/platform/WebSkImage.h" | 18 #include "third_party/WebKit/public/platform/WebSkImage.h" |
19 #include "third_party/skia/include/core/SkImage.h" | 19 #include "third_party/skia/include/core/SkImage.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
| 23 // CanvasCaptureHandler acts as the link between blink side HTMLCanvasElement |
| 24 // and Chrome side VideoCapturerSource. It is responsible for handling |
| 25 // WebSkImage instances sent from the blink side, convert them to |
| 26 // media::VideoFrame and plug them to the MediaStreamTrack. |
| 27 // CanvasCaptureHandler instance is owned by a blink::CanvasDrawListener which |
| 28 // is owned by a CanvasCaptureMediaStreamTrack. |
| 29 // All methods are called on the same thread as construction and destruction, |
| 30 // i.e. the Main Render thread. Note that a CanvasCaptureHandlerDelegate is |
| 31 // used to send back frames on the IO thread. |
23 class CONTENT_EXPORT CanvasCaptureHandler final | 32 class CONTENT_EXPORT CanvasCaptureHandler final |
24 : public NON_EXPORTED_BASE(blink::WebCanvasCaptureHandler) { | 33 : public NON_EXPORTED_BASE(blink::WebCanvasCaptureHandler) { |
25 public: | 34 public: |
| 35 // A VideoCapturerSource instance is created, which is responsible for handing |
| 36 // stop&start callbacks back to CanvasCaptureHandler. That VideoCapturerSource |
| 37 // is then plugged into a MediaStreamTrack passed as |track|, and it is owned |
| 38 // by the blink side MediaStreamSource. |
26 CanvasCaptureHandler(const blink::WebSize& size, | 39 CanvasCaptureHandler(const blink::WebSize& size, |
27 double frame_rate, | 40 double frame_rate, |
28 blink::WebMediaStream* stream); | 41 blink::WebMediaStreamTrack* track); |
| 42 ~CanvasCaptureHandler() override; |
29 | 43 |
30 // blink::WebCanvasCaptureHandler Implementation. | 44 // blink::WebCanvasCaptureHandler Implementation. |
31 void sendNewFrame(const blink::WebSkImage& image) override; | 45 void sendNewFrame(const blink::WebSkImage& image) override; |
32 bool needsNewFrame() const override; | 46 bool needsNewFrame() const override; |
33 | 47 |
34 // Functions called by media::VideoCapturerSource implementation. | 48 // Functions called by media::VideoCapturerSource implementation. |
35 void StartVideoCapture( | 49 void StartVideoCapture( |
36 const media::VideoCaptureParams& params, | 50 const media::VideoCaptureParams& params, |
37 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB& | 51 const media::VideoCapturerSource::VideoCaptureDeliverFrameCB& |
38 new_frame_callback, | 52 new_frame_callback, |
39 const media::VideoCapturerSource::RunningCallback& running_callback); | 53 const media::VideoCapturerSource::RunningCallback& running_callback); |
40 void StopVideoCapture(); | 54 void StopVideoCapture(); |
41 blink::WebSize GetSourceSize() const { return size_; } | 55 blink::WebSize GetSourceSize() const { return size_; } |
42 | 56 |
43 private: | 57 private: |
44 ~CanvasCaptureHandler() override; | |
45 | |
46 void CreateNewFrame(const blink::WebSkImage& image); | 58 void CreateNewFrame(const blink::WebSkImage& image); |
| 59 void AddVideoCapturerSourceToVideoTrack( |
| 60 scoped_ptr<media::VideoCapturerSource> source, |
| 61 blink::WebMediaStreamTrack* web_track); |
47 | 62 |
48 // Implementation VideoCapturerSource that is owned by blink and delegates | 63 // Implementation VideoCapturerSource that is owned by blink and delegates |
49 // the Start/Stop calls to CanvasCaptureHandler. | 64 // the Start/Stop calls to CanvasCaptureHandler. |
50 class VideoCapturerSource; | 65 class VideoCapturerSource; |
| 66 |
51 // Object that does all the work of running |new_frame_callback_|. | 67 // Object that does all the work of running |new_frame_callback_|. |
52 // Destroyed on |io_task_runner_| after the class is destroyed. | 68 // Destroyed on |io_task_runner_| after the class is destroyed. |
53 class CanvasCaptureHandlerDelegate; | 69 class CanvasCaptureHandlerDelegate; |
54 | 70 |
55 media::VideoCaptureFormat capture_format_; | 71 media::VideoCaptureFormat capture_format_; |
56 bool ask_for_new_frame_; | 72 bool ask_for_new_frame_; |
57 | 73 |
58 const blink::WebSize size_; | 74 const blink::WebSize size_; |
59 gfx::Size last_size; | 75 gfx::Size last_size; |
60 std::vector<uint8> temp_data_; | 76 std::vector<uint8> temp_data_; |
61 size_t row_bytes_; | 77 size_t row_bytes_; |
62 SkImageInfo image_info_; | 78 SkImageInfo image_info_; |
63 media::VideoFramePool frame_pool_; | 79 media::VideoFramePool frame_pool_; |
64 | 80 |
65 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 81 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
66 scoped_ptr<CanvasCaptureHandlerDelegate> delegate_; | 82 scoped_ptr<CanvasCaptureHandlerDelegate> delegate_; |
67 // Bound to the main render thread. | 83 // Bound to the main render thread. |
68 base::ThreadChecker thread_checker_; | 84 base::ThreadChecker thread_checker_; |
69 base::WeakPtrFactory<CanvasCaptureHandler> weak_ptr_factory_; | 85 base::WeakPtrFactory<CanvasCaptureHandler> weak_ptr_factory_; |
70 | 86 |
71 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler); | 87 DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler); |
72 }; | 88 }; |
73 | 89 |
74 } // namespace content | 90 } // namespace content |
75 | 91 |
76 #endif // CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ | 92 #endif // CONTENT_RENDERER_MEDIA_CANVAS_CAPTURE_HANDLER_H_ |
OLD | NEW |