Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: remoting/client/rectangle_update_decoder.h

Issue 10879085: Cleanup RectangleUpdateDecoder and VideoStub (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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. 56 // Stop decoding of any pending video packets.
58 void DropAllPackets(); 57 void Stop();
59 58
60 // FrameProducer implementation. These methods may be called before we are 59 // FrameProducer implementation. These methods may be called before we are
61 // Initialize()d, or we know the source screen size. 60 // Initialize()d, or we know the source screen size.
62 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; 61 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE;
63 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; 62 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE;
64 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; 63 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE;
65 virtual void SetOutputSizeAndClip(const SkISize& view_size, 64 virtual void SetOutputSizeAndClip(const SkISize& view_size,
66 const SkIRect& clip_area) OVERRIDE; 65 const SkIRect& clip_area) OVERRIDE;
67 66
68 // VideoStub implementation. 67 // VideoStub implementation.
69 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, 68 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
70 const base::Closure& done) OVERRIDE; 69 const base::Closure& done) OVERRIDE;
71 virtual int GetPendingVideoPackets() OVERRIDE;
72 70
73 // Return the stats recorded by this client. 71 // Return the stats recorded by this client.
74 ChromotingStats* GetStats(); 72 ChromotingStats* GetStats();
75 73
76 private: 74 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>; 75 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>;
86 virtual ~RectangleUpdateDecoder(); 76 virtual ~RectangleUpdateDecoder();
87 77
88 // Paints the invalidated region to the next available buffer and returns it 78 // Paints the invalidated region to the next available buffer and returns it
89 // to the consumer. 79 // to the consumer.
90 void SchedulePaint(); 80 void SchedulePaint();
91 void DoPaint(); 81 void DoPaint();
92 82
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 83 // Decodes the contents of |packet|. DecodePacket may keep a reference to
98 // |packet| so the |packet| must remain alive and valid until |done| is 84 // |packet| so the |packet| must remain alive and valid until |done| is
99 // executed. 85 // executed.
100 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); 86 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done);
101 87
102 // Callback method when a VideoPacket is processed. 88 // Callback method when a VideoPacket is processed.
103 // If |last_packet| is true then |decode_start| contains the timestamp when 89 // If |last_packet| is true then |decode_start| contains the timestamp when
104 // the packet will start to be processed. 90 // the packet will start to be processed.
105 void OnPacketDone(bool last_packet, base::Time decode_start); 91 void OnPacketDone(bool last_packet,
92 base::Time decode_start,
93 const base::Closure& done);
106 94
107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 95 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
108 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; 96 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_;
109 scoped_refptr<FrameConsumerProxy> consumer_; 97 scoped_refptr<FrameConsumerProxy> consumer_;
110 scoped_ptr<VideoDecoder> decoder_; 98 scoped_ptr<VideoDecoder> decoder_;
111 99
112 // Remote screen size in pixels. 100 // Remote screen size in pixels.
113 SkISize source_size_; 101 SkISize source_size_;
114 102
115 // Vertical and horizontal DPI of the remote screen. 103 // Vertical and horizontal DPI of the remote screen.
116 SkIPoint source_dpi_; 104 SkIPoint source_dpi_;
117 105
118 // The current dimensions of the frame consumer view. 106 // The current dimensions of the frame consumer view.
119 SkISize view_size_; 107 SkISize view_size_;
120 SkIRect clip_area_; 108 SkIRect clip_area_;
121 109
122 // The drawing buffers supplied by the frame consumer. 110 // The drawing buffers supplied by the frame consumer.
123 std::list<pp::ImageData*> buffers_; 111 std::list<pp::ImageData*> buffers_;
124 112
125 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). 113 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint().
126 bool paint_scheduled_; 114 bool paint_scheduled_;
127 115
128 // Contains all video packets that have been received, but have not yet been 116 // Set to true after Stop() has been called.
Wez 2012/08/28 16:42:27 nit: True after Stop() has been called. The curren
Sergey Ulanov 2012/08/28 18:30:27 Done.
129 // processed. 117 bool stopped_;
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 118
139 ChromotingStats stats_; 119 ChromotingStats stats_;
140 120
141 // Keep track of the most recent sequence number bounced back from the host. 121 // Keep track of the most recent sequence number bounced back from the host.
142 int64 latest_sequence_number_; 122 int64 latest_sequence_number_;
143 }; 123 };
144 124
145 } // namespace remoting 125 } // namespace remoting
146 126
147 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ 127 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698