Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / remoting / codec / video_encoder_vpx_unittest.cc
1 // Copyright 2013 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 "remoting/codec/video_encoder_vpx.h"
6
7 #include <limits>
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "remoting/codec/codec_test.h"
12 #include "remoting/proto/video.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
15
16 namespace {
17
18 const int kIntMax = std::numeric_limits<int>::max();
19
20 }  // namespace
21
22 namespace remoting {
23
24 TEST(VideoEncoderVp8Test, TestVideoEncoder) {
25   scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
26   TestVideoEncoder(encoder.get(), false);
27 }
28
29 // Test that calling Encode with a differently-sized media::ScreenCaptureData
30 // does not leak memory.
31 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) {
32   int height = 1000;
33   int width = 1000;
34
35   scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
36
37   scoped_ptr<webrtc::DesktopFrame> frame(
38       new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)));
39
40   scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
41   EXPECT_TRUE(packet);
42
43   height /= 2;
44   frame.reset(
45       new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)));
46   packet = encoder->Encode(*frame);
47   EXPECT_TRUE(packet);
48 }
49
50 // Test that the DPI information is correctly propagated from the
51 // media::ScreenCaptureData to the VideoPacket.
52 TEST(VideoEncoderVp8Test, TestDpiPropagation) {
53   int height = 32;
54   int width = 32;
55
56   scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
57
58   scoped_ptr<webrtc::DesktopFrame> frame(
59       new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)));
60   frame->set_dpi(webrtc::DesktopVector(96, 97));
61   scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
62   EXPECT_EQ(packet->format().x_dpi(), 96);
63   EXPECT_EQ(packet->format().y_dpi(), 97);
64 }
65
66 }  // namespace remoting