OLD | NEW |
1 // Copyright (c) 2011 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_ENCODER_VP8_H_ | 5 #ifndef REMOTING_BASE_ENCODER_VP8_H_ |
6 #define REMOTING_BASE_ENCODER_VP8_H_ | 6 #define REMOTING_BASE_ENCODER_VP8_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "remoting/base/encoder.h" | 11 #include "remoting/base/encoder.h" |
12 #include "ui/gfx/rect.h" | 12 #include "third_party/skia/include/core/SkRect.h" |
13 | 13 |
14 typedef struct vpx_codec_ctx vpx_codec_ctx_t; | 14 typedef struct vpx_codec_ctx vpx_codec_ctx_t; |
15 typedef struct vpx_image vpx_image_t; | 15 typedef struct vpx_image vpx_image_t; |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 | 18 |
19 // A class that uses VP8 to perform encoding. | 19 // A class that uses VP8 to perform encoding. |
20 class EncoderVp8 : public Encoder { | 20 class EncoderVp8 : public Encoder { |
21 public: | 21 public: |
22 EncoderVp8(); | 22 EncoderVp8(); |
23 virtual ~EncoderVp8(); | 23 virtual ~EncoderVp8(); |
24 | 24 |
25 virtual void Encode(scoped_refptr<CaptureData> capture_data, | 25 virtual void Encode(scoped_refptr<CaptureData> capture_data, |
26 bool key_frame, | 26 bool key_frame, |
27 DataAvailableCallback* data_available_callback); | 27 DataAvailableCallback* data_available_callback); |
28 | 28 |
29 private: | 29 private: |
| 30 typedef std::vector<SkIRect> RectVector; |
| 31 |
30 FRIEND_TEST_ALL_PREFIXES(EncoderVp8Test, AlignAndClipRect); | 32 FRIEND_TEST_ALL_PREFIXES(EncoderVp8Test, AlignAndClipRect); |
31 | 33 |
32 // Initialize the encoder. Returns true if successful. | 34 // Initialize the encoder. Returns true if successful. |
33 bool Init(const gfx::Size& size); | 35 bool Init(const SkISize& size); |
34 | 36 |
35 // Destroy the encoder. | 37 // Destroy the encoder. |
36 void Destroy(); | 38 void Destroy(); |
37 | 39 |
38 // Prepare |image_| for encoding. Write updated rectangles into | 40 // Prepare |image_| for encoding. Write updated rectangles into |
39 // |updated_rects|. Returns true if successful. | 41 // |updated_rects|. Returns true if successful. |
40 bool PrepareImage(scoped_refptr<CaptureData> capture_data, | 42 bool PrepareImage(scoped_refptr<CaptureData> capture_data, |
41 std::vector<gfx::Rect>* updated_rects); | 43 RectVector* updated_rects); |
42 | 44 |
43 // Update the active map according to |updated_rects|. Active map is then | 45 // Update the active map according to |updated_rects|. Active map is then |
44 // given to the encoder to speed up encoding. | 46 // given to the encoder to speed up encoding. |
45 void PrepareActiveMap(const std::vector<gfx::Rect>& updated_rects); | 47 void PrepareActiveMap(const RectVector& updated_rects); |
46 | 48 |
47 // Align the sides of the rectangle to multiples of 2 (expanding outwards), | 49 // Align the sides of the rectangle to multiples of 2 (expanding outwards), |
48 // but ensuring the result stays within the screen area (width, height). | 50 // but ensuring the result stays within the screen area (width, height). |
49 // If |rect| falls outside the screen area, return an empty rect. | 51 // If |rect| falls outside the screen area, return an empty rect. |
50 // | 52 // |
51 // TODO(lambroslambrou): Pull this out if it's useful for other things than | 53 // TODO(lambroslambrou): Pull this out if it's useful for other things than |
52 // VP8-encoding? | 54 // VP8-encoding? |
53 static gfx::Rect AlignAndClipRect(const gfx::Rect& rect, | 55 static SkIRect AlignAndClipRect(const SkIRect& rect, int width, int height); |
54 int width, int height); | |
55 | 56 |
56 // True if the encoder is initialized. | 57 // True if the encoder is initialized. |
57 bool initialized_; | 58 bool initialized_; |
58 | 59 |
59 scoped_ptr<vpx_codec_ctx_t> codec_; | 60 scoped_ptr<vpx_codec_ctx_t> codec_; |
60 scoped_ptr<vpx_image_t> image_; | 61 scoped_ptr<vpx_image_t> image_; |
61 scoped_array<uint8> active_map_; | 62 scoped_array<uint8> active_map_; |
62 int active_map_width_; | 63 int active_map_width_; |
63 int active_map_height_; | 64 int active_map_height_; |
64 int last_timestamp_; | 65 int last_timestamp_; |
65 | 66 |
66 // Buffer for storing the yuv image. | 67 // Buffer for storing the yuv image. |
67 scoped_array<uint8> yuv_image_; | 68 scoped_array<uint8> yuv_image_; |
68 | 69 |
69 // The current frame size. | 70 // The current frame size. |
70 gfx::Size size_; | 71 SkISize size_; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(EncoderVp8); | 73 DISALLOW_COPY_AND_ASSIGN(EncoderVp8); |
73 }; | 74 }; |
74 | 75 |
75 } // namespace remoting | 76 } // namespace remoting |
76 | 77 |
77 #endif // REMOTING_BASE_ENCODER_VP8_H_ | 78 #endif // REMOTING_BASE_ENCODER_VP8_H_ |
OLD | NEW |