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 #include "remoting/codec/video_encoder_vp8.h" | 5 #include "remoting/codec/video_encoder_vp8.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "remoting/capturer/capture_data.h" | 13 #include "media/video/capture/screen/screen_capture_data.h" |
14 #include "remoting/codec/codec_test.h" | 14 #include "remoting/codec/codec_test.h" |
15 #include "remoting/proto/video.pb.h" | 15 #include "remoting/proto/video.pb.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int kIntMax = std::numeric_limits<int>::max(); | 20 const int kIntMax = std::numeric_limits<int>::max(); |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace remoting { | 24 namespace remoting { |
25 | 25 |
26 TEST(VideoEncoderVp8Test, TestVideoEncoder) { | 26 TEST(VideoEncoderVp8Test, TestVideoEncoder) { |
27 VideoEncoderVp8 encoder; | 27 VideoEncoderVp8 encoder; |
28 TestVideoEncoder(&encoder, false); | 28 TestVideoEncoder(&encoder, false); |
29 } | 29 } |
30 | 30 |
31 class VideoEncoderCallback { | 31 class VideoEncoderCallback { |
32 public: | 32 public: |
33 void DataAvailable(scoped_ptr<VideoPacket> packet) { | 33 void DataAvailable(scoped_ptr<VideoPacket> packet) { |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
37 // Test that calling Encode with a differently-sized CaptureData does not | 37 // Test that calling Encode with a differently-sized media::ScreenCaptureData |
38 // leak memory. | 38 // does not leak memory. |
39 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { | 39 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { |
40 int height = 1000; | 40 int height = 1000; |
41 int width = 1000; | 41 int width = 1000; |
42 const int kBytesPerPixel = 4; | 42 const int kBytesPerPixel = 4; |
43 | 43 |
44 VideoEncoderVp8 encoder; | 44 VideoEncoderVp8 encoder; |
45 VideoEncoderCallback callback; | 45 VideoEncoderCallback callback; |
46 | 46 |
47 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 47 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
48 scoped_refptr<CaptureData> capture_data(new CaptureData( | 48 scoped_refptr<media::ScreenCaptureData> capture_data( |
49 &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height))); | 49 new media::ScreenCaptureData(&buffer.front(), width * kBytesPerPixel, |
| 50 SkISize::Make(width, height))); |
50 encoder.Encode(capture_data, false, | 51 encoder.Encode(capture_data, false, |
51 base::Bind(&VideoEncoderCallback::DataAvailable, | 52 base::Bind(&VideoEncoderCallback::DataAvailable, |
52 base::Unretained(&callback))); | 53 base::Unretained(&callback))); |
53 | 54 |
54 height /= 2; | 55 height /= 2; |
55 capture_data = new CaptureData( | 56 capture_data = new media::ScreenCaptureData( |
56 &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height)); | 57 &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height)); |
57 encoder.Encode(capture_data, false, | 58 encoder.Encode(capture_data, false, |
58 base::Bind(&VideoEncoderCallback::DataAvailable, | 59 base::Bind(&VideoEncoderCallback::DataAvailable, |
59 base::Unretained(&callback))); | 60 base::Unretained(&callback))); |
60 } | 61 } |
61 | 62 |
62 class VideoEncoderDpiCallback { | 63 class VideoEncoderDpiCallback { |
63 public: | 64 public: |
64 void DataAvailable(scoped_ptr<VideoPacket> packet) { | 65 void DataAvailable(scoped_ptr<VideoPacket> packet) { |
65 EXPECT_EQ(packet->format().x_dpi(), 96); | 66 EXPECT_EQ(packet->format().x_dpi(), 96); |
66 EXPECT_EQ(packet->format().y_dpi(), 97); | 67 EXPECT_EQ(packet->format().y_dpi(), 97); |
67 } | 68 } |
68 }; | 69 }; |
69 | 70 |
70 // Test that the DPI information is correctly propagated from the CaptureData | 71 // Test that the DPI information is correctly propagated from the |
71 // to the VideoPacket. | 72 // media::ScreenCaptureData to the VideoPacket. |
72 TEST(VideoEncoderVp8Test, TestDpiPropagation) { | 73 TEST(VideoEncoderVp8Test, TestDpiPropagation) { |
73 int height = 32; | 74 int height = 32; |
74 int width = 32; | 75 int width = 32; |
75 const int kBytesPerPixel = 4; | 76 const int kBytesPerPixel = 4; |
76 | 77 |
77 VideoEncoderVp8 encoder; | 78 VideoEncoderVp8 encoder; |
78 VideoEncoderDpiCallback callback; | 79 VideoEncoderDpiCallback callback; |
79 | 80 |
80 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 81 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
81 scoped_refptr<CaptureData> capture_data(new CaptureData( | 82 scoped_refptr<media::ScreenCaptureData> capture_data( |
82 &buffer.front(), width * kBytesPerPixel, SkISize::Make(width, height))); | 83 new media::ScreenCaptureData(&buffer.front(), width * kBytesPerPixel, |
| 84 SkISize::Make(width, height))); |
83 capture_data->set_dpi(SkIPoint::Make(96, 97)); | 85 capture_data->set_dpi(SkIPoint::Make(96, 97)); |
84 encoder.Encode(capture_data, false, | 86 encoder.Encode(capture_data, false, |
85 base::Bind(&VideoEncoderDpiCallback::DataAvailable, | 87 base::Bind(&VideoEncoderDpiCallback::DataAvailable, |
86 base::Unretained(&callback))); | 88 base::Unretained(&callback))); |
87 } | 89 } |
88 | 90 |
89 } // namespace remoting | 91 } // namespace remoting |
OLD | NEW |