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/base/capture_data.h" | 13 #include "remoting/base/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(EncoderVp8Test, TestEncoder) { | 26 TEST(VideoEncoderVp8Test, TestVideoEncoder) { |
27 EncoderVp8 encoder; | 27 VideoEncoderVp8 encoder; |
28 TestEncoder(&encoder, false); | 28 TestVideoEncoder(&encoder, false); |
29 } | 29 } |
30 | 30 |
31 class EncoderCallback { | 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 CaptureData does not |
38 // leak memory. | 38 // leak memory. |
39 TEST(EncoderVp8Test, 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 EncoderVp8 encoder; | 44 VideoEncoderVp8 encoder; |
45 EncoderCallback callback; | 45 VideoEncoderCallback callback; |
46 | 46 |
47 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 47 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
48 DataPlanes planes; | 48 DataPlanes planes; |
49 planes.data[0] = &buffer.front(); | 49 planes.data[0] = &buffer.front(); |
50 planes.strides[0] = width; | 50 planes.strides[0] = width; |
51 | 51 |
52 scoped_refptr<CaptureData> capture_data(new CaptureData( | 52 scoped_refptr<CaptureData> capture_data(new CaptureData( |
53 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); | 53 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); |
54 encoder.Encode(capture_data, false, | 54 encoder.Encode(capture_data, false, |
55 base::Bind(&EncoderCallback::DataAvailable, | 55 base::Bind(&VideoEncoderCallback::DataAvailable, |
56 base::Unretained(&callback))); | 56 base::Unretained(&callback))); |
57 | 57 |
58 height /= 2; | 58 height /= 2; |
59 capture_data = new CaptureData(planes, SkISize::Make(width, height), | 59 capture_data = new CaptureData(planes, SkISize::Make(width, height), |
60 media::VideoFrame::RGB32); | 60 media::VideoFrame::RGB32); |
61 encoder.Encode(capture_data, false, | 61 encoder.Encode(capture_data, false, |
62 base::Bind(&EncoderCallback::DataAvailable, | 62 base::Bind(&VideoEncoderCallback::DataAvailable, |
63 base::Unretained(&callback))); | 63 base::Unretained(&callback))); |
64 } | 64 } |
65 | 65 |
66 class EncoderDpiCallback { | 66 class VideoEncoderDpiCallback { |
67 public: | 67 public: |
68 void DataAvailable(scoped_ptr<VideoPacket> packet) { | 68 void DataAvailable(scoped_ptr<VideoPacket> packet) { |
69 EXPECT_EQ(packet->format().x_dpi(), 96); | 69 EXPECT_EQ(packet->format().x_dpi(), 96); |
70 EXPECT_EQ(packet->format().y_dpi(), 97); | 70 EXPECT_EQ(packet->format().y_dpi(), 97); |
71 } | 71 } |
72 }; | 72 }; |
73 | 73 |
74 // Test that the DPI information is correctly propagated from the CaptureData | 74 // Test that the DPI information is correctly propagated from the CaptureData |
75 // to the VideoPacket. | 75 // to the VideoPacket. |
76 TEST(EncoderVp8Test, TestDpiPropagation) { | 76 TEST(VideoEncoderVp8Test, TestDpiPropagation) { |
77 int height = 32; | 77 int height = 32; |
78 int width = 32; | 78 int width = 32; |
79 const int kBytesPerPixel = 4; | 79 const int kBytesPerPixel = 4; |
80 | 80 |
81 EncoderVp8 encoder; | 81 VideoEncoderVp8 encoder; |
82 EncoderDpiCallback callback; | 82 VideoEncoderDpiCallback callback; |
83 | 83 |
84 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 84 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
85 DataPlanes planes; | 85 DataPlanes planes; |
86 planes.data[0] = &buffer.front(); | 86 planes.data[0] = &buffer.front(); |
87 planes.strides[0] = width; | 87 planes.strides[0] = width; |
88 | 88 |
89 scoped_refptr<CaptureData> capture_data(new CaptureData( | 89 scoped_refptr<CaptureData> capture_data(new CaptureData( |
90 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); | 90 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); |
91 capture_data->set_dpi(SkIPoint::Make(96, 97)); | 91 capture_data->set_dpi(SkIPoint::Make(96, 97)); |
92 encoder.Encode(capture_data, false, | 92 encoder.Encode(capture_data, false, |
93 base::Bind(&EncoderDpiCallback::DataAvailable, | 93 base::Bind(&VideoEncoderDpiCallback::DataAvailable, |
94 base::Unretained(&callback))); | 94 base::Unretained(&callback))); |
95 } | 95 } |
96 | 96 |
97 } // namespace remoting | 97 } // namespace remoting |
OLD | NEW |