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