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_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 "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "media/base/video_frame.h" | |
10 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
| 11 #include "third_party/skia/include/core/SkRect.h" |
11 #include "third_party/skia/include/core/SkRegion.h" | 12 #include "third_party/skia/include/core/SkRegion.h" |
| 13 #include "third_party/skia/include/core/SkSize.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 | 16 |
15 // Interface for a decoder that takes a stream of bytes from the network and | 17 // Interface for a decoder that takes a stream of bytes from the network and |
16 // outputs frames of data. | 18 // outputs frames of data. |
17 // | 19 // |
18 // TODO(ajwong): Beef up this documentation once the API stablizes. | 20 // TODO(ajwong): Beef up this documentation once the API stablizes. |
19 class Decoder { | 21 class Decoder { |
20 public: | 22 public: |
21 // DecodeResult is returned from DecodePacket() and indicates current state | 23 // DecodeResult is returned from DecodePacket() and indicates current state |
22 // of the decoder. DECODE_DONE means that last packet for the frame was | 24 // 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 | 25 // 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 | 26 // 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. | 27 // displayed. DECODE_ERROR is returned if there was an error in the stream. |
26 enum DecodeResult { | 28 enum DecodeResult { |
27 DECODE_ERROR = -1, | 29 DECODE_ERROR = -1, |
28 DECODE_IN_PROGRESS, | 30 DECODE_IN_PROGRESS, |
29 DECODE_DONE, | 31 DECODE_DONE, |
30 }; | 32 }; |
31 | 33 |
32 Decoder() {} | 34 Decoder() {} |
33 virtual ~Decoder() {} | 35 virtual ~Decoder() {} |
34 | 36 |
35 // Initializes the decoder to draw into the given |frame|. | 37 // Initializes the decoder and sets the output dimensions. |
36 virtual void Initialize(scoped_refptr<media::VideoFrame> frame) = 0; | 38 virtual void Initialize(const SkISize& screen_size) = 0; |
37 | 39 |
38 // Feeds more data into the decoder. | 40 // Feeds more data into the decoder. |
39 virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; | 41 virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; |
40 | 42 |
41 // Returns the region affected by the most recent frame. Can be called only | |
42 // after DecodePacket returned DECODE_DONE. Caller keeps ownership of | |
43 // |region|. | |
44 virtual void GetUpdatedRegion(SkRegion* region) = 0; | |
45 | |
46 // Reset the decoder to an uninitialized state. Release all references to | |
47 // the initialized |frame|. Initialize() must be called before the decoder | |
48 // is used again. | |
49 virtual void Reset() = 0; | |
50 | |
51 // Returns true if decoder is ready to accept data via DecodePacket. | 43 // Returns true if decoder is ready to accept data via DecodePacket. |
52 virtual bool IsReadyForData() = 0; | 44 virtual bool IsReadyForData() = 0; |
53 | 45 |
54 virtual VideoPacketFormat::Encoding Encoding() = 0; | 46 virtual VideoPacketFormat::Encoding Encoding() = 0; |
55 | 47 |
56 // Set the output dimensions for the decoder. If the dimensions are empty | 48 // Forces the decoder to include the specified |region| the next time |
57 // then the source is rendered without scaling. | 49 // RenderFrame() is called. |region| is expressed in output coordinates. |
58 // Output dimensions are ignored if the decoder doesn't support scaling. | 50 virtual void Invalidate(const SkISize& view_size, |
59 virtual void SetOutputSize(const SkISize& size) {} | 51 const SkRegion& region) = 0; |
60 | 52 |
61 // Set the clipping rectangle to the decoder. Decoder should respect this and | 53 // Copies invalidated pixels of the video frame to |image_buffer|. Both |
62 // only output changes in this rectangle. The new clipping rectangle will be | 54 // decoding a packet or Invalidate() call can result in parts of the frame |
63 // effective on the next decoded video frame. | 55 // to be invalidated. Only the pixels within |clip_area| are copied. |
64 virtual void SetClipRect(const SkIRect& clip_rect) {} | 56 // Invalidated pixels outside of |clip_area| remain invalidated. |
65 | 57 // |
66 // Force decoder to output a frame based on the specified |region| of the | 58 // The routine sets |output_region| to indicate the updated areas of |
67 // most recently decoded video frame. |region| is expressed in video frame | 59 // |image_buffer|. |output_region| is in output buffer coordinates. |
68 // rather than output coordinates. | 60 // |
69 virtual void RefreshRegion(const SkRegion& region) {} | 61 // |image_buffer| is assumed to be large enough to hold entire |clip_area| |
| 62 // (RGBA32). The top left corner of the buffer corresponds to the top left |
| 63 // corner of |clip_area|. |image_stride| specifies the size of a single row |
| 64 // of the buffer in bytes. |
| 65 // |
| 66 // Both |clip_area| and |output_region| are expressed in output coordinates. |
| 67 virtual void RenderFrame(const SkISize& view_size, |
| 68 const SkIRect& clip_area, |
| 69 uint8* image_buffer, |
| 70 int image_stride, |
| 71 SkRegion* output_region) = 0; |
70 }; | 72 }; |
71 | 73 |
72 } // namespace remoting | 74 } // namespace remoting |
73 | 75 |
74 #endif // REMOTING_BASE_DECODER_H_ | 76 #endif // REMOTING_BASE_DECODER_H_ |
OLD | NEW |