OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RECTANGLE_UPDATE_DECODER_H_ | 5 #ifndef REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
6 #define REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ | 6 #define REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
7 | 7 |
8 #include <list> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
13 #include "remoting/codec/video_decoder.h" | 10 #include "remoting/codec/video_decoder.h" |
14 #include "remoting/client/chromoting_stats.h" | 11 #include "remoting/client/chromoting_stats.h" |
15 #include "remoting/client/frame_consumer_proxy.h" | 12 #include "remoting/client/frame_consumer_proxy.h" |
16 #include "remoting/client/frame_producer.h" | 13 #include "remoting/client/frame_producer.h" |
17 #include "remoting/protocol/video_stub.h" | 14 #include "remoting/client/video_processor.h" |
18 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
19 | 16 |
20 namespace base { | 17 namespace base { |
21 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
22 } // namespace base | 19 } // namespace base |
23 | 20 |
24 namespace remoting { | 21 namespace remoting { |
25 | 22 |
26 class ChromotingStats; | 23 class ChromotingStats; |
27 | 24 |
28 namespace protocol { | 25 // Implementation of VideoProcessor interface that decodes frame on a separate |
29 class SessionConfig; | 26 // thread and then passes decoded frames to a FrameConsumer./ |
Wez
2014/01/14 16:23:14
nit: Lose the trailing /
Sergey Ulanov
2014/01/15 00:58:17
Done.
| |
30 } // namespace protocol | 27 // |
31 | |
32 // TODO(ajwong): Re-examine this API, especially with regards to how error | |
33 // conditions on each step are reported. Should they be CHECKs? Logs? Other? | |
34 // TODO(sergeyu): Rename this class. | 28 // TODO(sergeyu): Rename this class. |
Wez
2014/01/14 16:23:14
e.g. SoftwareVideoRenderer, since it's what we use
Sergey Ulanov
2014/01/15 00:58:17
Done.
| |
35 class RectangleUpdateDecoder | 29 class RectangleUpdateDecoder : public VideoProcessor, public FrameProducer { |
36 : public base::RefCountedThreadSafe<RectangleUpdateDecoder>, | |
37 public FrameProducer, | |
38 public protocol::VideoStub { | |
39 public: | 30 public: |
40 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, | 31 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, |
41 // outputting to |consumer|. The |main_task_runner_| is responsible for | 32 // outputting to |consumer|. The |main_task_runner_| is responsible for |
42 // receiving and queueing packets. The |decode_task_runner_| is responsible | 33 // receiving and queueing packets. The |decode_task_runner_| is responsible |
43 // for decoding the video packets. | 34 // for decoding the video packets. |
44 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. | 35 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. |
45 RectangleUpdateDecoder( | 36 RectangleUpdateDecoder( |
46 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 37 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
47 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 38 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
48 scoped_refptr<FrameConsumerProxy> consumer); | 39 scoped_refptr<FrameConsumerProxy> consumer); |
49 | 40 |
50 // Initializes decoder with the information from the protocol config. | 41 // VideoProcessor implementation. |
51 void Initialize(const protocol::SessionConfig& config); | 42 virtual void Initialize(const protocol::SessionConfig& config) OVERRIDE; |
43 virtual ChromotingStats* GetStats() OVERRIDE; | |
44 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | |
45 const base::Closure& done) OVERRIDE; | |
52 | 46 |
53 // FrameProducer implementation. These methods may be called before we are | 47 // FrameProducer implementation. These methods may be called before we are |
54 // Initialize()d, or we know the source screen size. | 48 // Initialize()d, or we know the source screen size. |
55 virtual void DrawBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; | 49 virtual void DrawBuffer(webrtc::DesktopFrame* buffer) OVERRIDE; |
56 virtual void InvalidateRegion(const webrtc::DesktopRegion& region) OVERRIDE; | 50 virtual void InvalidateRegion(const webrtc::DesktopRegion& region) OVERRIDE; |
57 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; | 51 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; |
58 virtual void SetOutputSizeAndClip( | 52 virtual void SetOutputSizeAndClip( |
59 const webrtc::DesktopSize& view_size, | 53 const webrtc::DesktopSize& view_size, |
60 const webrtc::DesktopRect& clip_area) OVERRIDE; | 54 const webrtc::DesktopRect& clip_area) OVERRIDE; |
61 virtual const webrtc::DesktopRegion* GetBufferShape() OVERRIDE; | 55 virtual const webrtc::DesktopRegion* GetBufferShape() OVERRIDE; |
62 | 56 |
63 // VideoStub implementation. | 57 private: |
64 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 58 class Core; |
65 const base::Closure& done) OVERRIDE; | 59 scoped_refptr<Core> core_; |
Wez
2014/01/14 16:23:14
refptr makes kitteh sad... !^.^
Can't Core be an
Sergey Ulanov
2014/01/15 00:58:17
Done.
| |
66 | 60 |
67 // Return the stats recorded by this client. | 61 DISALLOW_COPY_AND_ASSIGN(RectangleUpdateDecoder); |
68 ChromotingStats* GetStats(); | |
69 | |
70 private: | |
71 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; | |
72 virtual ~RectangleUpdateDecoder(); | |
73 | |
74 // Paints the invalidated region to the next available buffer and returns it | |
75 // to the consumer. | |
76 void SchedulePaint(); | |
77 void DoPaint(); | |
78 | |
79 // Decodes the contents of |packet|. DecodePacket may keep a reference to | |
80 // |packet| so the |packet| must remain alive and valid until |done| is | |
81 // executed. | |
82 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); | |
83 | |
84 // Callback method when a VideoPacket is processed. |decode_start| contains | |
85 // the timestamp when the packet will start to be processed. | |
86 void OnPacketDone(base::Time decode_start, const base::Closure& done); | |
87 | |
88 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
89 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | |
90 scoped_refptr<FrameConsumerProxy> consumer_; | |
91 scoped_ptr<VideoDecoder> decoder_; | |
92 | |
93 // Remote screen size in pixels. | |
94 webrtc::DesktopSize source_size_; | |
95 | |
96 // Vertical and horizontal DPI of the remote screen. | |
97 webrtc::DesktopVector source_dpi_; | |
98 | |
99 // The current dimensions of the frame consumer view. | |
100 webrtc::DesktopSize view_size_; | |
101 webrtc::DesktopRect clip_area_; | |
102 | |
103 // The drawing buffers supplied by the frame consumer. | |
104 std::list<webrtc::DesktopFrame*> buffers_; | |
105 | |
106 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). | |
107 bool paint_scheduled_; | |
108 | |
109 ChromotingStats stats_; | |
110 | |
111 // Keep track of the most recent sequence number bounced back from the host. | |
112 int64 latest_sequence_number_; | |
113 }; | 62 }; |
114 | 63 |
115 } // namespace remoting | 64 } // namespace remoting |
116 | 65 |
117 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ | 66 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
OLD | NEW |