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" | |
|
Sergey Ulanov
2012/08/24 18:44:12
Don't need this include - you already have callbac
kxing
2012/08/24 19:35:51
Done.
| |
| 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 |main_task_runner_| and |decode_task_runner_|, |
| 46 // outputting to |consumer|. The |main_task_runner_| is responsible for | |
| 47 // receiving and queueing packets. The |decode_task_runner_| is responsible | |
| 48 // for decoding the video packets. | |
| 41 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. | 49 // TODO(wez): Replace the ref-counted proxy with an owned FrameConsumer. |
| 42 RectangleUpdateDecoder( | 50 RectangleUpdateDecoder( |
| 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 51 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 52 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | |
| 44 scoped_refptr<FrameConsumerProxy> consumer); | 53 scoped_refptr<FrameConsumerProxy> consumer); |
| 45 | 54 |
| 46 // Initializes decoder with the information from the protocol config. | 55 // Initializes decoder with the information from the protocol config. |
| 47 void Initialize(const protocol::SessionConfig& config); | 56 void Initialize(const protocol::SessionConfig& config); |
| 48 | 57 |
| 49 // Decodes the contents of |packet|. DecodePacket may keep a reference to | 58 // Removes all video packets in the queue. |
| 50 // |packet| so the |packet| must remain alive and valid until |done| is | 59 void DropAllPackets(); |
| 51 // executed. | |
| 52 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); | |
| 53 | 60 |
| 54 // FrameProducer implementation. These methods may be called before we are | 61 // FrameProducer implementation. These methods may be called before we are |
| 55 // Initialize()d, or we know the source screen size. | 62 // Initialize()d, or we know the source screen size. |
| 56 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; | 63 virtual void DrawBuffer(pp::ImageData* buffer) OVERRIDE; |
| 57 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; | 64 virtual void InvalidateRegion(const SkRegion& region) OVERRIDE; |
| 58 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; | 65 virtual void RequestReturnBuffers(const base::Closure& done) OVERRIDE; |
| 59 virtual void SetOutputSizeAndClip(const SkISize& view_size, | 66 virtual void SetOutputSizeAndClip(const SkISize& view_size, |
| 60 const SkIRect& clip_area) OVERRIDE; | 67 const SkIRect& clip_area) OVERRIDE; |
| 61 | 68 |
| 69 // VideoStub implementation. | |
| 70 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | |
| 71 const base::Closure& done) OVERRIDE; | |
| 72 virtual int GetPendingVideoPackets() OVERRIDE; | |
| 73 | |
| 74 // Return the stats recorded by this client. | |
| 75 ChromotingStats* GetStats(); | |
| 76 | |
| 62 private: | 77 private: |
| 78 struct QueuedVideoPacket { | |
| 79 QueuedVideoPacket(scoped_ptr<VideoPacket> packet, | |
| 80 const base::Closure& done); | |
| 81 ~QueuedVideoPacket(); | |
| 82 VideoPacket* packet; | |
| 83 base::Closure done; | |
| 84 }; | |
| 85 | |
| 63 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; | 86 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; |
| 64 virtual ~RectangleUpdateDecoder(); | 87 virtual ~RectangleUpdateDecoder(); |
| 65 | 88 |
| 66 // Paints the invalidated region to the next available buffer and returns it | 89 // Paints the invalidated region to the next available buffer and returns it |
| 67 // to the consumer. | 90 // to the consumer. |
| 68 void SchedulePaint(); | 91 void SchedulePaint(); |
| 69 void DoPaint(); | 92 void DoPaint(); |
| 70 | 93 |
| 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 94 // If a packet is not being processed, dispatches a single message from the |
| 95 // |received_packets_| queue. | |
| 96 void ProcessNextPacket(); | |
| 97 | |
| 98 // Decodes the contents of |packet|. DecodePacket may keep a reference to | |
| 99 // |packet| so the |packet| must remain alive and valid until |done| is | |
| 100 // executed. | |
| 101 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); | |
| 102 | |
| 103 // Callback method when a VideoPacket is processed. | |
| 104 // If |last_packet| is true then |decode_start| contains the timestamp when | |
| 105 // the packet will start to be processed. | |
| 106 void OnPacketDone(bool last_packet, base::Time decode_start); | |
| 107 | |
| 108 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 109 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | |
| 72 scoped_refptr<FrameConsumerProxy> consumer_; | 110 scoped_refptr<FrameConsumerProxy> consumer_; |
| 73 scoped_ptr<VideoDecoder> decoder_; | 111 scoped_ptr<VideoDecoder> decoder_; |
| 74 | 112 |
| 75 // Remote screen size in pixels. | 113 // Remote screen size in pixels. |
| 76 SkISize source_size_; | 114 SkISize source_size_; |
| 77 | 115 |
| 78 // Vertical and horizontal DPI of the remote screen. | 116 // Vertical and horizontal DPI of the remote screen. |
| 79 SkIPoint source_dpi_; | 117 SkIPoint source_dpi_; |
| 80 | 118 |
| 81 // The current dimentions of the frame consumer view. | 119 // The current dimensions of the frame consumer view. |
| 82 SkISize view_size_; | 120 SkISize view_size_; |
| 83 SkIRect clip_area_; | 121 SkIRect clip_area_; |
| 84 | 122 |
| 85 // The drawing buffers supplied by the frame consumer. | 123 // The drawing buffers supplied by the frame consumer. |
| 86 std::list<pp::ImageData*> buffers_; | 124 std::list<pp::ImageData*> buffers_; |
| 87 | 125 |
| 88 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). | 126 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). |
| 89 bool paint_scheduled_; | 127 bool paint_scheduled_; |
| 128 | |
| 129 // Contains all video packets that have been received, but have not yet been | |
| 130 // processed. | |
|
Sergey Ulanov
2012/08/24 18:45:40
Please add TODO(sergeyu) to simplify this code and
kxing
2012/08/24 19:35:51
Done.
| |
| 131 // | |
| 132 // Used to serialize sending of messages to the client. | |
| 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_; | |
| 140 | |
| 141 // Keep track of the most recent sequence number bounced back from the host. | |
| 142 int64 last_sequence_number_; | |
| 90 }; | 143 }; |
| 91 | 144 |
| 92 } // namespace remoting | 145 } // namespace remoting |
| 93 | 146 |
| 94 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ | 147 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
| OLD | NEW |