Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / remoting / codec / video_encoder_vp8_unittest.cc
blob57d5f7a2c94d527321b80c51d0c7ecf08545ab78
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
3 // found in the LICENSE file.
5 #include "remoting/codec/video_encoder_vp8.h"
7 #include <limits>
8 #include <vector>
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/capture_data.h"
14 #include "remoting/codec/codec_test.h"
15 #include "remoting/proto/video.pb.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace {
20 const int kIntMax = std::numeric_limits<int>::max();
22 } // namespace
24 namespace remoting {
26 TEST(VideoEncoderVp8Test, TestVideoEncoder) {
27 VideoEncoderVp8 encoder;
28 TestVideoEncoder(&encoder, false);
31 class VideoEncoderCallback {
32 public:
33 void DataAvailable(scoped_ptr<VideoPacket> packet) {
37 // Test that calling Encode with a differently-sized CaptureData does not
38 // leak memory.
39 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) {
40 int height = 1000;
41 int width = 1000;
42 const int kBytesPerPixel = 4;
44 VideoEncoderVp8 encoder;
45 VideoEncoderCallback callback;
47 std::vector<uint8> buffer(width * height * kBytesPerPixel);
48 DataPlanes planes;
49 planes.data[0] = &buffer.front();
50 planes.strides[0] = width;
52 scoped_refptr<CaptureData> capture_data(new CaptureData(
53 planes, SkISize::Make(width, height), media::VideoFrame::RGB32));
54 encoder.Encode(capture_data, false,
55 base::Bind(&VideoEncoderCallback::DataAvailable,
56 base::Unretained(&callback)));
58 height /= 2;
59 capture_data = new CaptureData(planes, SkISize::Make(width, height),
60 media::VideoFrame::RGB32);
61 encoder.Encode(capture_data, false,
62 base::Bind(&VideoEncoderCallback::DataAvailable,
63 base::Unretained(&callback)));
66 class VideoEncoderDpiCallback {
67 public:
68 void DataAvailable(scoped_ptr<VideoPacket> packet) {
69 EXPECT_EQ(packet->format().x_dpi(), 96);
70 EXPECT_EQ(packet->format().y_dpi(), 97);
74 // Test that the DPI information is correctly propagated from the CaptureData
75 // to the VideoPacket.
76 TEST(VideoEncoderVp8Test, TestDpiPropagation) {
77 int height = 32;
78 int width = 32;
79 const int kBytesPerPixel = 4;
81 VideoEncoderVp8 encoder;
82 VideoEncoderDpiCallback callback;
84 std::vector<uint8> buffer(width * height * kBytesPerPixel);
85 DataPlanes planes;
86 planes.data[0] = &buffer.front();
87 planes.strides[0] = width;
89 scoped_refptr<CaptureData> capture_data(new CaptureData(
90 planes, SkISize::Make(width, height), media::VideoFrame::RGB32));
91 capture_data->set_dpi(SkIPoint::Make(96, 97));
92 encoder.Encode(capture_data, false,
93 base::Bind(&VideoEncoderDpiCallback::DataAvailable,
94 base::Unretained(&callback)));
97 } // namespace remoting