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 <queue> |
| 9 |
8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "media/base/video_frame.h" | |
12 #include "remoting/base/decoder.h" | 13 #include "remoting/base/decoder.h" |
| 14 #include "remoting/client/frame_producer.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 class MessageLoopProxy; | 17 class MessageLoopProxy; |
16 } // namespace base | 18 } // namespace base |
17 | 19 |
| 20 namespace pp { |
| 21 class ImageData; |
| 22 }; |
| 23 |
18 namespace remoting { | 24 namespace remoting { |
19 | 25 |
20 class FrameConsumer; | 26 class FrameConsumer; |
21 class VideoPacket; | 27 class VideoPacket; |
22 | 28 |
23 namespace protocol { | 29 namespace protocol { |
24 class SessionConfig; | 30 class SessionConfig; |
25 } // namespace protocol | 31 } // namespace protocol |
26 | 32 |
27 // TODO(ajwong): Re-examine this API, especially with regards to how error | 33 // TODO(ajwong): Re-examine this API, especially with regards to how error |
28 // conditions on each step are reported. Should they be CHECKs? Logs? Other? | 34 // conditions on each step are reported. Should they be CHECKs? Logs? Other? |
29 // TODO(sergeyu): Rename this class. | 35 // TODO(sergeyu): Rename this class. |
30 class RectangleUpdateDecoder : | 36 class RectangleUpdateDecoder : |
31 public base::RefCountedThreadSafe<RectangleUpdateDecoder> { | 37 public base::RefCountedThreadSafe<RectangleUpdateDecoder>, |
| 38 public FrameProducer { |
32 public: | 39 public: |
33 RectangleUpdateDecoder(base::MessageLoopProxy* message_loop, | 40 RectangleUpdateDecoder(base::MessageLoopProxy* message_loop, |
34 FrameConsumer* consumer); | 41 FrameConsumer* consumer); |
35 | 42 |
36 // Initializes decoder with the infromation from the protocol config. | 43 // Initializes decoder with the infromation from the protocol config. |
37 void Initialize(const protocol::SessionConfig& config); | 44 void Initialize(const protocol::SessionConfig& config); |
38 | 45 |
39 // Decodes the contents of |packet| calling OnPartialFrameOutput() in the | 46 // Decodes the contents of |packet|. DecodePacket may keep a reference to |
40 // regsitered as data is avaialable. DecodePacket may keep a reference to | |
41 // |packet| so the |packet| must remain alive and valid until |done| is | 47 // |packet| so the |packet| must remain alive and valid until |done| is |
42 // executed. | 48 // executed. |
43 void DecodePacket(const VideoPacket* packet, const base::Closure& done); | 49 void DecodePacket(const VideoPacket* packet, const base::Closure& done); |
44 | 50 |
45 // Set the output dimensions to scale video output to. | 51 // FrameProducer implementation. |
46 void SetOutputSize(const SkISize& size); | 52 virtual void DrainQueue(const base::Closure& done) OVERRIDE; |
47 | 53 virtual void EnqueueBuffer(pp::ImageData* buffer) OVERRIDE; |
48 // Set a new clipping rectangle for the decoder. Decoder should respect | 54 virtual void Invalidate(const SkRegion& region) OVERRIDE; |
49 // this clipping rectangle and only decode content in this rectangle and | 55 virtual void SetView(const SkISize& view_size, |
50 // report dirty rectangles accordingly to enhance performance. | 56 const SkIRect& clip_area) OVERRIDE; |
51 void UpdateClipRect(const SkIRect& clip_rect); | |
52 | |
53 // Force the decoder to output the last decoded video frame without any | |
54 // clipping. | |
55 void RefreshFullFrame(); | |
56 | 57 |
57 private: | 58 private: |
58 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; | 59 friend class base::RefCountedThreadSafe<RectangleUpdateDecoder>; |
59 friend class PartialFrameCleanup; | |
60 | 60 |
61 ~RectangleUpdateDecoder(); | 61 ~RectangleUpdateDecoder(); |
62 | 62 |
63 void AllocateFrame(const VideoPacket* packet, const base::Closure& done); | 63 // Paint the invalidated region to the next available buffer and return it |
64 void ProcessPacketData(const VideoPacket* packet, const base::Closure& done); | 64 // to the consumer. |
65 | 65 void DoPaint(); |
66 // Obtain updated rectangles from decoder and submit it to the consumer. | |
67 void SubmitToConsumer(); | |
68 | |
69 // Use |refresh_rects_| to do a refresh to the backing video frame. | |
70 // When done the affected rectangles are submitted to the consumer. | |
71 void DoRefresh(); | |
72 | |
73 // Callback for FrameConsumer::OnPartialFrameOutput() | |
74 void OnFrameConsumed(SkRegion* region); | |
75 | 66 |
76 scoped_refptr<base::MessageLoopProxy> message_loop_; | 67 scoped_refptr<base::MessageLoopProxy> message_loop_; |
77 FrameConsumer* consumer_; | 68 FrameConsumer* consumer_; |
78 | 69 |
| 70 scoped_ptr<Decoder> decoder_; |
| 71 |
| 72 // Remote screen size in pixels. |
79 SkISize screen_size_; | 73 SkISize screen_size_; |
80 SkIRect clip_rect_; | |
81 SkRegion refresh_region_; | |
82 | 74 |
83 scoped_ptr<Decoder> decoder_; | 75 // The current dimentions of the frame consumer view. |
84 bool decoder_needs_reset_; | 76 SkISize view_size_; |
| 77 SkIRect clip_area_; |
85 | 78 |
86 // The video frame that the decoder writes to. | 79 // The drawing buffers supplied by the frame consumer. |
87 scoped_refptr<media::VideoFrame> frame_; | 80 std::queue<pp::ImageData*> buffers_; |
88 }; | 81 }; |
89 | 82 |
90 } // namespace remoting | 83 } // namespace remoting |
91 | 84 |
92 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ | 85 #endif // REMOTING_CLIENT_RECTANGLE_UPDATE_DECODER_H_ |
OLD | NEW |