OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "media/base/data_buffer.h" | 5 #include "remoting/base/codec_test.h" |
6 #include "remoting/base/pixel_format.h" | 6 #include "remoting/base/encoder_vp8.h" |
7 #include "remoting/host/encoder_vp8.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | |
9 | 8 |
10 namespace remoting { | 9 namespace remoting { |
11 | 10 |
12 static const int kWidth = 1024; | 11 TEST(EncoderVp8Test, TestEncoder) { |
13 static const int kHeight = 768; | |
14 static const PixelFormat kPixelFormat = kPixelFormat_YV12; | |
15 | |
16 static void GenerateData(uint8* data, int size) { | |
17 for (int i = 0; i < size; ++i) { | |
18 data[i] = i; | |
19 } | |
20 } | |
21 | |
22 class EncodeDoneHandler | |
23 : public base::RefCountedThreadSafe<EncodeDoneHandler> { | |
24 public: | |
25 MOCK_METHOD0(EncodeDone, void()); | |
26 }; | |
27 | |
28 TEST(EncoderVp8Test, SimpleEncode) { | |
29 EncoderVp8 encoder; | 12 EncoderVp8 encoder; |
30 encoder.SetSize(kWidth, kHeight); | 13 TestEncoder(&encoder, false); |
31 encoder.SetPixelFormat(kPixelFormat); | |
32 | |
33 DirtyRects rects; | |
34 rects.push_back(gfx::Rect(kWidth, kHeight)); | |
35 | |
36 // Prepare memory for encoding. | |
37 int strides[3]; | |
38 strides[0] = kWidth; | |
39 strides[1] = strides[2] = kWidth / 2; | |
40 | |
41 uint8* planes[3]; | |
42 planes[0] = new uint8[kWidth * kHeight]; | |
43 planes[1] = new uint8[kWidth * kHeight / 4]; | |
44 planes[2] = new uint8[kWidth * kHeight / 4]; | |
45 GenerateData(planes[0], kWidth * kHeight); | |
46 GenerateData(planes[1], kWidth * kHeight / 4); | |
47 GenerateData(planes[2], kWidth * kHeight / 4); | |
48 | |
49 scoped_refptr<EncodeDoneHandler> handler = new EncodeDoneHandler(); | |
50 UpdateStreamPacketHeader* header = new UpdateStreamPacketHeader(); | |
51 scoped_refptr<media::DataBuffer> encoded_data; | |
52 bool encode_done = false; | |
53 EXPECT_CALL(*handler, EncodeDone()); | |
54 encoder.Encode(rects, const_cast<const uint8**>(planes), | |
55 strides, true, header, &encoded_data, &encode_done, | |
56 NewRunnableMethod(handler.get(), | |
57 &EncodeDoneHandler::EncodeDone)); | |
58 | |
59 EXPECT_TRUE(encode_done); | |
60 ASSERT_TRUE(encoded_data.get()); | |
61 EXPECT_NE(0u, encoded_data->GetBufferSize()); | |
62 | |
63 delete [] planes[0]; | |
64 delete [] planes[1]; | |
65 delete [] planes[2]; | |
66 } | 14 } |
67 | 15 |
68 } // namespace remoting | 16 } // namespace remoting |
OLD | NEW |