blob: 94be428c794281c26f2321be1e88ef34b558af7f [file] [log] [blame]
[email protected]770284a2011-05-09 17:13:521// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]cb3b1f9312010-06-07 19:58:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f7524002011-03-17 14:22:145#include <limits>
[email protected]770284a2011-05-09 17:13:526#include <vector>
[email protected]f7524002011-03-17 14:22:147
[email protected]1e1cb3b2011-11-10 02:07:418#include "base/bind.h"
[email protected]770284a2011-05-09 17:13:529#include "base/callback.h"
[email protected]e57a7162011-06-15 04:14:2310#include "base/memory/scoped_ptr.h"
[email protected]770284a2011-05-09 17:13:5211#include "remoting/base/capture_data.h"
[email protected]df10bf172010-09-28 22:19:4812#include "remoting/base/codec_test.h"
13#include "remoting/base/encoder_vp8.h"
[email protected]770284a2011-05-09 17:13:5214#include "remoting/proto/video.pb.h"
[email protected]df10bf172010-09-28 22:19:4815#include "testing/gtest/include/gtest/gtest.h"
[email protected]cb3b1f9312010-06-07 19:58:2316
[email protected]f7524002011-03-17 14:22:1417namespace {
18
19const int kIntMax = std::numeric_limits<int>::max();
20
21} // namespace
22
[email protected]cb3b1f9312010-06-07 19:58:2323namespace remoting {
24
[email protected]df10bf172010-09-28 22:19:4825TEST(EncoderVp8Test, TestEncoder) {
[email protected]cb3b1f9312010-06-07 19:58:2326 EncoderVp8 encoder;
[email protected]df10bf172010-09-28 22:19:4827 TestEncoder(&encoder, false);
[email protected]cb3b1f9312010-06-07 19:58:2328}
29
[email protected]770284a2011-05-09 17:13:5230class EncoderCallback {
31 public:
32 void DataAvailable(VideoPacket *packet) {
33 delete packet;
34 }
35};
36
37// Test that calling Encode with a differently-sized CaptureData does not
38// leak memory.
39TEST(EncoderVp8Test, TestSizeChangeNoLeak) {
40 int height = 1000;
41 int width = 1000;
42 const int kBytesPerPixel = 4;
43
44 EncoderVp8 encoder;
45 EncoderCallback callback;
46
47 std::vector<uint8> buffer(width * height * kBytesPerPixel);
48 DataPlanes planes;
49 planes.data[0] = &buffer.front();
50 planes.strides[0] = width;
51
52 scoped_refptr<CaptureData> capture_data(new CaptureData(
[email protected]bcad2682011-09-30 20:35:2653 planes, SkISize::Make(width, height), media::VideoFrame::RGB32));
[email protected]770284a2011-05-09 17:13:5254 encoder.Encode(capture_data, false,
[email protected]1e1cb3b2011-11-10 02:07:4155 base::Bind(&EncoderCallback::DataAvailable,
56 base::Unretained(&callback)));
[email protected]770284a2011-05-09 17:13:5257
58 height /= 2;
[email protected]bcad2682011-09-30 20:35:2659 capture_data = new CaptureData(planes, SkISize::Make(width, height),
[email protected]770284a2011-05-09 17:13:5260 media::VideoFrame::RGB32);
61 encoder.Encode(capture_data, false,
[email protected]1e1cb3b2011-11-10 02:07:4162 base::Bind(&EncoderCallback::DataAvailable,
63 base::Unretained(&callback)));
[email protected]770284a2011-05-09 17:13:5264}
65
[email protected]f7524002011-03-17 14:22:1466TEST(EncoderVp8Test, AlignAndClipRect) {
67 // Simple test case (no clipping).
[email protected]bcad2682011-09-30 20:35:2668 SkIRect r1(SkIRect::MakeXYWH(100, 200, 300, 400));
[email protected]f7524002011-03-17 14:22:1469 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1);
70
71 // Should expand outward to r1.
[email protected]bcad2682011-09-30 20:35:2672 SkIRect r2(SkIRect::MakeXYWH(101, 201, 298, 398));
[email protected]f7524002011-03-17 14:22:1473 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1);
74
75 // Test clipping to screen size.
76 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220),
[email protected]bcad2682011-09-30 20:35:2677 SkIRect::MakeXYWH(100, 200, 10, 20));
[email protected]f7524002011-03-17 14:22:1478
79 // Rectangle completely off-screen.
[email protected]bcad2682011-09-30 20:35:2680 EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).isEmpty());
[email protected]f7524002011-03-17 14:22:1481
82 // Clipping to odd-sized screen. An unlikely case, and we might not deal
83 // with it cleanly in the encoder (we possibly lose 1px at right & bottom
84 // of screen).
85 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299),
[email protected]bcad2682011-09-30 20:35:2686 SkIRect::MakeXYWH(100, 200, 98, 98));
[email protected]f7524002011-03-17 14:22:1487}
88
[email protected]cb3b1f9312010-06-07 19:58:2389} // namespace remoting