OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BASE_DECODER_H_ | 5 #ifndef REMOTING_BASE_DECODER_H_ |
6 #define REMOTING_BASE_DECODER_H_ | 6 #define REMOTING_BASE_DECODER_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
10 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
11 #include "third_party/skia/include/core/SkRegion.h" | 13 #include "third_party/skia/include/core/SkRect.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 | 16 |
| 17 typedef std::vector<SkIRect> RectVector; |
| 18 |
15 // Interface for a decoder that takes a stream of bytes from the network and | 19 // Interface for a decoder that takes a stream of bytes from the network and |
16 // outputs frames of data. | 20 // outputs frames of data. |
17 // | 21 // |
18 // TODO(ajwong): Beef up this documentation once the API stablizes. | 22 // TODO(ajwong): Beef up this documentation once the API stablizes. |
19 class Decoder { | 23 class Decoder { |
20 public: | 24 public: |
21 // DecodeResult is returned from DecodePacket() and indicates current state | 25 // DecodeResult is returned from DecodePacket() and indicates current state |
22 // of the decoder. DECODE_DONE means that last packet for the frame was | 26 // of the decoder. DECODE_DONE means that last packet for the frame was |
23 // processed, and the frame can be displayed now. DECODE_IN_PROGRESS | 27 // processed, and the frame can be displayed now. DECODE_IN_PROGRESS |
24 // indicates that the decoder must receive more data before the frame can be | 28 // indicates that the decoder must receive more data before the frame can be |
25 // displayed. DECODE_ERROR is returned if there was an error in the stream. | 29 // displayed. DECODE_ERROR is returned if there was an error in the stream. |
26 enum DecodeResult { | 30 enum DecodeResult { |
27 DECODE_ERROR = -1, | 31 DECODE_ERROR = -1, |
28 DECODE_IN_PROGRESS, | 32 DECODE_IN_PROGRESS, |
29 DECODE_DONE, | 33 DECODE_DONE, |
30 }; | 34 }; |
31 | 35 |
32 Decoder() {} | 36 Decoder() {} |
33 virtual ~Decoder() {} | 37 virtual ~Decoder() {} |
34 | 38 |
35 // Initializes the decoder to draw into the given |frame|. | 39 // Initializes the decoder to draw into the given |frame|. |
36 virtual void Initialize(scoped_refptr<media::VideoFrame> frame) = 0; | 40 virtual void Initialize(scoped_refptr<media::VideoFrame> frame) = 0; |
37 | 41 |
38 // Feeds more data into the decoder. | 42 // Feeds more data into the decoder. |
39 virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; | 43 virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; |
40 | 44 |
41 // Returns the region affected by the most recent frame. Can be called only | 45 // Returns rects that were updated in the last frame. Can be called only |
42 // after DecodePacket returned DECODE_DONE. Caller keeps ownership of | 46 // after DecodePacket returned DECODE_DONE. Caller keeps ownership of |
43 // |region|. | 47 // |rects|. |rects| is kept empty if whole screen needs to be updated. |
44 virtual void GetUpdatedRegion(SkRegion* region) = 0; | 48 virtual void GetUpdatedRects(RectVector* rects) = 0; |
45 | 49 |
46 // Reset the decoder to an uninitialized state. Release all references to | 50 // Reset the decoder to an uninitialized state. Release all references to |
47 // the initialized |frame|. Initialize() must be called before the decoder | 51 // the initialized |frame|. Initialize() must be called before the decoder |
48 // is used again. | 52 // is used again. |
49 virtual void Reset() = 0; | 53 virtual void Reset() = 0; |
50 | 54 |
51 // Returns true if decoder is ready to accept data via DecodePacket. | 55 // Returns true if decoder is ready to accept data via DecodePacket. |
52 virtual bool IsReadyForData() = 0; | 56 virtual bool IsReadyForData() = 0; |
53 | 57 |
54 virtual VideoPacketFormat::Encoding Encoding() = 0; | 58 virtual VideoPacketFormat::Encoding Encoding() = 0; |
55 | 59 |
56 // Set the output dimensions for the decoder. If the dimensions are empty | 60 // Set the output dimensions for the decoder. If the dimensions are empty |
57 // then the source is rendered without scaling. | 61 // then the source is rendered without scaling. |
58 // Output dimensions are ignored if the decoder doesn't support scaling. | 62 // Output dimensions are ignored if the decoder doesn't support scaling. |
59 virtual void SetOutputSize(const SkISize& size) {} | 63 virtual void SetOutputSize(const SkISize& size) {} |
60 | 64 |
61 // Set the clipping rectangle to the decoder. Decoder should respect this and | 65 // Set the clipping rectangle to the decoder. Decoder should respect this and |
62 // only output changes in this rectangle. The new clipping rectangle will be | 66 // only output changes in this rectangle. The new clipping rectangle will be |
63 // effective on the next decoded video frame. | 67 // effective on the next decoded video frame. |
| 68 // |
| 69 // When scaling is enabled clipping rectangles are ignored. |
64 virtual void SetClipRect(const SkIRect& clip_rect) {} | 70 virtual void SetClipRect(const SkIRect& clip_rect) {} |
65 | 71 |
66 // Force decoder to output a frame based on the specified |region| of the | 72 // Force decoder to output a video frame with content in |rects| using the |
67 // most recently decoded video frame. |region| is expressed in video frame | 73 // last decoded video frame. |rects| are expressed in video frame rather |
68 // rather than output coordinates. | 74 // than output coordinates. |
69 virtual void RefreshRegion(const SkRegion& region) {} | 75 virtual void RefreshRects(const RectVector& rects) {} |
70 }; | 76 }; |
71 | 77 |
72 } // namespace remoting | 78 } // namespace remoting |
73 | 79 |
74 #endif // REMOTING_BASE_DECODER_H_ | 80 #endif // REMOTING_BASE_DECODER_H_ |
OLD | NEW |