summaryrefslogtreecommitdiffstats
path: root/remoting/base/encoder_vp8_unittest.cc
blob: 9435cd1504d494142b744dda4e466a9adad28566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <limits>
#include <vector>

#include "base/callback.h"
#include "base/scoped_ptr.h"
#include "remoting/base/capture_data.h"
#include "remoting/base/codec_test.h"
#include "remoting/base/encoder_vp8.h"
#include "remoting/proto/video.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const int kIntMax = std::numeric_limits<int>::max();

}  // namespace

namespace remoting {

TEST(EncoderVp8Test, TestEncoder) {
  EncoderVp8 encoder;
  TestEncoder(&encoder, false);
}

class EncoderCallback {
 public:
  void DataAvailable(VideoPacket *packet) {
    delete packet;
  }
};

// Test that calling Encode with a differently-sized CaptureData does not
// leak memory.
TEST(EncoderVp8Test, TestSizeChangeNoLeak) {
  int height = 1000;
  int width = 1000;
  const int kBytesPerPixel = 4;

  EncoderVp8 encoder;
  EncoderCallback callback;

  std::vector<uint8> buffer(width * height * kBytesPerPixel);
  DataPlanes planes;
  planes.data[0] = &buffer.front();
  planes.strides[0] = width;

  scoped_refptr<CaptureData> capture_data(new CaptureData(
      planes, gfx::Size(width, height), media::VideoFrame::RGB32));
  encoder.Encode(capture_data, false,
                 NewCallback(&callback, &EncoderCallback::DataAvailable));

  height /= 2;
  capture_data = new CaptureData(planes, gfx::Size(width, height),
                                 media::VideoFrame::RGB32);
  encoder.Encode(capture_data, false,
                 NewCallback(&callback, &EncoderCallback::DataAvailable));
}

TEST(EncoderVp8Test, AlignAndClipRect) {
  // Simple test case (no clipping).
  gfx::Rect r1(100, 200, 300, 400);
  EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1);

  // Should expand outward to r1.
  gfx::Rect r2(101, 201, 298, 398);
  EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1);

  // Test clipping to screen size.
  EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220),
            gfx::Rect(100, 200, 10, 20));

  // Rectangle completely off-screen.
  EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).IsEmpty());

  // Clipping to odd-sized screen.  An unlikely case, and we might not deal
  // with it cleanly in the encoder (we possibly lose 1px at right & bottom
  // of screen).
  EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299),
            gfx::Rect(100, 200, 98, 98));
}

}  // namespace remoting