OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/base/data_buffer.h" |
| 6 #include "remoting/base/pixel_format.h" |
| 7 #include "remoting/host/encoder_vp8.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 |
| 10 namespace remoting { |
| 11 |
| 12 static const int kWidth = 1024; |
| 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; |
| 30 encoder.SetSize(kWidth, kHeight); |
| 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 chromotocol_pb::UpdateStreamPacketHeader* header |
| 51 = new chromotocol_pb::UpdateStreamPacketHeader(); |
| 52 scoped_refptr<media::DataBuffer> encoded_data; |
| 53 bool encode_done = false; |
| 54 EXPECT_CALL(*handler, EncodeDone()); |
| 55 encoder.Encode(rects, const_cast<const uint8**>(planes), |
| 56 strides, true, header, &encoded_data, &encode_done, |
| 57 NewRunnableMethod(handler.get(), |
| 58 &EncodeDoneHandler::EncodeDone)); |
| 59 |
| 60 EXPECT_TRUE(encode_done); |
| 61 ASSERT_TRUE(encoded_data.get()); |
| 62 EXPECT_NE(0u, encoded_data->GetBufferSize()); |
| 63 |
| 64 delete [] planes[0]; |
| 65 delete [] planes[1]; |
| 66 delete [] planes[2]; |
| 67 } |
| 68 |
| 69 } // namespace remoting |
OLD | NEW |