| 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 REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 5 #ifndef REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
| 6 #define REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 6 #define REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" |
| 10 #include "remoting/client/chromoting_stats.h" | 12 #include "remoting/client/chromoting_stats.h" |
| 11 #include "remoting/client/frame_consumer_proxy.h" | |
| 12 #include "remoting/client/frame_producer.h" | |
| 13 #include "remoting/client/video_renderer.h" | 13 #include "remoting/client/video_renderer.h" |
| 14 #include "remoting/protocol/video_stub.h" | 14 #include "remoting/protocol/video_stub.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
| 19 } // namespace base | 19 } // namespace base |
| 20 | 20 |
| 21 namespace webrtc { |
| 22 class DesktopFrame; |
| 23 } // namespace webrtc; |
| 24 |
| 21 namespace remoting { | 25 namespace remoting { |
| 22 | 26 |
| 23 class ChromotingStats; | 27 class ChromotingStats; |
| 28 class FrameConsumer; |
| 29 class VideoDecoder; |
| 24 | 30 |
| 25 // Implementation of VideoRenderer interface that decodes frame on CPU (on a | 31 // Implementation of VideoRenderer interface that decodes frame on CPU (on a |
| 26 // decode thread) and then passes decoded frames to a FrameConsumer. | 32 // decode thread) and then passes decoded frames to a FrameConsumer. |
| 27 // FrameProducer methods can be called on any thread. All other methods must be | |
| 28 // called on the main thread. Owned must ensure that this class outlives | |
| 29 // FrameConsumer (which calls FrameProducer interface). | |
| 30 class SoftwareVideoRenderer : public VideoRenderer, | 33 class SoftwareVideoRenderer : public VideoRenderer, |
| 31 public protocol::VideoStub, | 34 public protocol::VideoStub { |
| 32 public FrameProducer, | |
| 33 public base::NonThreadSafe { | |
| 34 public: | 35 public: |
| 35 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, | 36 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, |
| 36 // outputting to |consumer|. The |main_task_runner_| is responsible for | 37 // outputting to |consumer|. The |main_task_runner_| is responsible for |
| 37 // receiving and queueing packets. The |decode_task_runner_| is responsible | 38 // receiving and queueing packets. The |decode_task_runner_| is responsible |
| 38 // for decoding the video packets. | 39 // for decoding the video packets. |
| 39 SoftwareVideoRenderer( | 40 SoftwareVideoRenderer( |
| 40 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 41 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 41 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
| 42 scoped_ptr<FrameConsumerProxy> consumer); | 42 FrameConsumer* consumer); |
| 43 ~SoftwareVideoRenderer() override; | 43 ~SoftwareVideoRenderer() override; |
| 44 | 44 |
| 45 // VideoRenderer interface. | 45 // VideoRenderer interface. |
| 46 void OnSessionConfig(const protocol::SessionConfig& config) override; | 46 void OnSessionConfig(const protocol::SessionConfig& config) override; |
| 47 ChromotingStats* GetStats() override; | 47 ChromotingStats* GetStats() override; |
| 48 protocol::VideoStub* GetVideoStub() override; | 48 protocol::VideoStub* GetVideoStub() override; |
| 49 | 49 |
| 50 // protocol::VideoStub interface. | 50 // protocol::VideoStub interface. |
| 51 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 51 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
| 52 const base::Closure& done) override; | 52 const base::Closure& done) override; |
| 53 | 53 |
| 54 // FrameProducer implementation. These methods may be called before we are | |
| 55 // Initialize()d, or we know the source screen size. These methods may be | |
| 56 // called on any thread. | |
| 57 // | |
| 58 // TODO(sergeyu): On Android a separate display thread is used for drawing. | |
| 59 // FrameConsumer calls FrameProducer on that thread. Can we avoid having a | |
| 60 // separate display thread? E.g. can we do everything on the decode thread? | |
| 61 void DrawBuffer(webrtc::DesktopFrame* buffer) override; | |
| 62 void InvalidateRegion(const webrtc::DesktopRegion& region) override; | |
| 63 void RequestReturnBuffers(const base::Closure& done) override; | |
| 64 void SetOutputSizeAndClip(const webrtc::DesktopSize& view_size, | |
| 65 const webrtc::DesktopRect& clip_area) override; | |
| 66 | |
| 67 private: | 54 private: |
| 68 class Core; | 55 void RenderFrame(base::TimeTicks decode_start_time, |
| 69 | 56 const base::Closure& done, |
| 70 // Callback method when a VideoPacket is processed. |decode_start| contains | 57 scoped_ptr<webrtc::DesktopFrame> frame); |
| 71 // the timestamp when the packet will start to be processed. | 58 void OnFrameRendered(base::TimeTicks paint_start_time, |
| 72 void OnPacketDone(base::Time decode_start, const base::Closure& done); | 59 const base::Closure& done); |
| 73 | 60 |
| 74 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | 61 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; |
| 75 scoped_ptr<Core> core_; | 62 FrameConsumer* consumer_; |
| 63 |
| 64 scoped_ptr<VideoDecoder> decoder_; |
| 65 |
| 66 webrtc::DesktopSize source_size_; |
| 67 webrtc::DesktopVector source_dpi_; |
| 76 | 68 |
| 77 ChromotingStats stats_; | 69 ChromotingStats stats_; |
| 78 | 70 |
| 71 base::ThreadChecker thread_checker_; |
| 72 |
| 79 base::WeakPtrFactory<SoftwareVideoRenderer> weak_factory_; | 73 base::WeakPtrFactory<SoftwareVideoRenderer> weak_factory_; |
| 80 | 74 |
| 81 DISALLOW_COPY_AND_ASSIGN(SoftwareVideoRenderer); | 75 DISALLOW_COPY_AND_ASSIGN(SoftwareVideoRenderer); |
| 82 }; | 76 }; |
| 83 | 77 |
| 84 } // namespace remoting | 78 } // namespace remoting |
| 85 | 79 |
| 86 #endif // REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ | 80 #endif // REMOTING_CLIENT_SOFTWARE_VIDEO_RENDERER_H_ |
| OLD | NEW |