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> | 8 #include <list> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "remoting/codec/video_decoder.h" | 13 #include "remoting/codec/video_decoder.h" |
14 #include "remoting/client/chromoting_stats.h" | 14 #include "remoting/client/chromoting_stats.h" |
15 #include "remoting/client/frame_consumer_proxy.h" | 15 #include "remoting/client/frame_consumer_proxy.h" |
16 #include "remoting/client/frame_producer.h" | 16 #include "remoting/client/frame_producer.h" |
17 #include "remoting/protocol/video_stub.h" | 17 #include "remoting/protocol/video_stub.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
21 } // namespace base | 21 } // namespace base |
22 | 22 |
23 namespace pp { | 23 namespace pp { |
24 class ImageData; | 24 class ImageData; |
25 }; | 25 } // namespace pp |
26 | 26 |
27 namespace remoting { | 27 namespace remoting { |
28 | 28 |
29 class ChromotingStats; | 29 class ChromotingStats; |
30 class VideoPacket; | |
31 | 30 |
32 namespace protocol { | 31 namespace protocol { |
33 class SessionConfig; | 32 class SessionConfig; |
34 } // namespace protocol | 33 } // namespace protocol |
35 | 34 |
36 // TODO(ajwong): Re-examine this API, especially with regards to how error | 35 // TODO(ajwong): Re-examine this API, especially with regards to how error |
37 // conditions on each step are reported. Should they be CHECKs? Logs? Other? | 36 // conditions on each step are reported. Should they be CHECKs? Logs? Other? |
38 // TODO(sergeyu): Rename this class. | 37 // TODO(sergeyu): Rename this class. |
39 class RectangleUpdateDecoder | 38 class RectangleUpdateDecoder |
40 : public base::RefCountedThreadSafe<RectangleUpdateDecoder>, | 39 : public base::RefCountedThreadSafe<RectangleUpdateDecoder>, |
41 public FrameProducer, | 40 public FrameProducer, |
42 public protocol::VideoStub { | 41 public protocol::VideoStub { |
43 public: | 42 public: |
44 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, | 43 // Creates an update decoder on |main_task_runner_| and |decode_task_runner_|, |
45 // outputting to |consumer|. The |main_task_runner_| is responsible for | 44 // outputting to |consumer|. The |main_task_runner_| is responsible for |
46 // receiving and queueing packets. The |decode_task_runner_| is responsible | 45 // receiving and queueing packets. The |decode_task_runner_| is responsible |
47 // for decoding the video packets. | 46 // for decoding the video packets. |
48 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. | 47 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. |
49 RectangleUpdateDecoder( | 48 RectangleUpdateDecoder( |
50 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 49 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
51 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 50 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
52 scoped_refptr<FrameConsumerProxy> consumer); | 51 scoped_refptr<FrameConsumerProxy> consumer); |
53 | 52 |
54 // Initializes decoder with the information from the protocol config. | 53 // Initializes decoder with the information from the protocol config. |
55 void Initialize(const protocol::SessionConfig& config); | 54 void Initialize(const protocol::SessionConfig& config); |
56 | 55 |
57 // Removes all video packets in the queue. | |
58 void DropAllPackets(); | |
59 | |
60 // FrameProducer implementation. These methods may be called before we are | 56 // FrameProducer implementation. These methods may be called before we are |
61 // Initialize()d, or we know the source screen size. | 57 // Initialize()d, or we know the source screen size. |
62 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; | 58 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; |
63 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; | 59 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; |
64 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; | 60 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; |
65 virtual void SetOutputSizeAndClip(const SkISize& view_size, | 61 virtual void SetOutputSizeAndClip(const SkISize& view_size, |
66 const SkIRect& clip_area) OVERRIDE; | 62 const SkIRect& clip_area) OVERRIDE; |
67 | 63 |
68 // VideoStub implementation. | 64 // VideoStub implementation. |
69 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 65 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
70 const base::Closure& done) OVERRIDE; | 66 const base::Closure& done) OVERRIDE; |
71 virtual int GetPendingVideoPackets() OVERRIDE; | |
72 | 67 |
73 // Return the stats recorded by this client. | 68 // Return the stats recorded by this client. |
74 ChromotingStats* GetStats(); | 69 ChromotingStats* GetStats(); |
75 | 70 |
76 private: | 71 private: |
77 struct QueuedVideoPacket { | |
78 QueuedVideoPacket(scoped_ptr<VideoPacket> packet, | |
79 const base::Closure& done); | |
80 ~QueuedVideoPacket(); | |
81 VideoPacket* packet; | |
82 base::Closure done; | |
83 }; | |
84 | |
85 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; | 72 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; |
86 virtual ~RectangleUpdateDecoder(); | 73 virtual ~RectangleUpdateDecoder(); |
87 | 74 |
88 // Paints the invalidated region to the next available buffer and returns it | 75 // Paints the invalidated region to the next available buffer and returns it |
89 // to the consumer. | 76 // to the consumer. |
90 void SchedulePaint(); | 77 void SchedulePaint(); |
91 void DoPaint(); | 78 void DoPaint(); |
92 | 79 |
93 // If a packet is not being processed, dispatches a single message from the | |
94 // |received_packets_| queue. | |
95 void ProcessNextPacket(); | |
96 | |
97 // Decodes the contents of |packet|. DecodePacket may keep a reference to | 80 // Decodes the contents of |packet|. DecodePacket may keep a reference to |
98 // |packet| so the |packet| must remain alive and valid until |done| is | 81 // |packet| so the |packet| must remain alive and valid until |done| is |
99 // executed. | 82 // executed. |
100 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); | 83 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); |
101 | 84 |
102 // Callback method when a VideoPacket is processed. | 85 // Callback method when a VideoPacket is processed. |
103 // If |last_packet| is true then |decode_start| contains the timestamp when | 86 // If |last_packet| is true then |decode_start| contains the timestamp when |
104 // the packet will start to be processed. | 87 // the packet will start to be processed. |
105 void OnPacketDone(bool last_packet, base::Time decode_start); | 88 void OnPacketDone(bool last_packet, |
| 89 base::Time decode_start, |
| 90 const base::Closure& done); |
106 | 91 |
107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 92 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
108 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; |
109 scoped_refptr<FrameConsumerProxy> consumer_; | 94 scoped_refptr<FrameConsumerProxy> consumer_; |
110 scoped_ptr<VideoDecoder> decoder_; | 95 scoped_ptr<VideoDecoder> decoder_; |
111 | 96 |
112 // Remote screen size in pixels. | 97 // Remote screen size in pixels. |
113 SkISize source_size_; | 98 SkISize source_size_; |
114 | 99 |
115 // Vertical and horizontal DPI of the remote screen. | 100 // Vertical and horizontal DPI of the remote screen. |
116 SkIPoint source_dpi_; | 101 SkIPoint source_dpi_; |
117 | 102 |
118 // The current dimensions of the frame consumer view. | 103 // The current dimensions of the frame consumer view. |
119 SkISize view_size_; | 104 SkISize view_size_; |
120 SkIRect clip_area_; | 105 SkIRect clip_area_; |
121 | 106 |
122 // The drawing buffers supplied by the frame consumer. | 107 // The drawing buffers supplied by the frame consumer. |
123 std::list<pp::ImageData*> buffers_; | 108 std::list<pp::ImageData*> buffers_; |
124 | 109 |
125 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). | 110 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). |
126 bool paint_scheduled_; | 111 bool paint_scheduled_; |
127 | 112 |
128 // Contains all video packets that have been received, but have not yet been | |
129 // processed. | |
130 // | |
131 // Used to serialize sending of messages to the client. | |
132 // TODO(sergeyu): Simplify this code and remove this list. | |
133 std::list<QueuedVideoPacket> received_packets_; | |
134 | |
135 // True if a message is being processed. Can be used to determine if it is | |
136 // safe to dispatch another message. | |
137 bool packet_being_processed_; | |
138 | |
139 ChromotingStats stats_; | 113 ChromotingStats stats_; |
140 | 114 |
141 // Keep track of the most recent sequence number bounced back from the host. | 115 // Keep track of the most recent sequence number bounced back from the host. |
142 int64 latest_sequence_number_; | 116 int64 latest_sequence_number_; |
143 }; | 117 }; |
144 | 118 |
145 } // namespace remoting | 119 } // namespace remoting |
146 | 120 |
147 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ | 121 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
OLD | NEW |