- add sources.
[platform/framework/web/crosswalk.git] / src / remoting / codec / video_decoder_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_decoder_vpx.h"
6
7 #include "media/base/video_frame.h"
8 #include "remoting/codec/codec_test.h"
9 #include "remoting/codec/video_encoder_vpx.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
12
13 namespace remoting {
14
15 class VideoDecoderVpxTest : public testing::Test {
16  protected:
17   scoped_ptr<VideoEncoderVpx> encoder_;
18   scoped_ptr<VideoDecoderVpx> decoder_;
19
20   VideoDecoderVpxTest() : encoder_(VideoEncoderVpx::CreateForVP8()),
21                           decoder_(VideoDecoderVpx::CreateForVP8()) {
22   }
23
24   void TestGradient(int screen_width, int screen_height,
25                     int view_width, int view_height,
26                     double max_error_limit, double mean_error_limit) {
27     TestVideoEncoderDecoderGradient(
28         encoder_.get(), decoder_.get(),
29         webrtc::DesktopSize(screen_width, screen_height),
30         webrtc::DesktopSize(view_width, view_height),
31         max_error_limit, mean_error_limit);
32   }
33 };
34
35 TEST_F(VideoDecoderVpxTest, VideoEncodeAndDecode) {
36   TestVideoEncoderDecoder(encoder_.get(), decoder_.get(), false);
37 }
38
39 // Check that encoding and decoding a particular frame doesn't change the
40 // frame too much. The frame used is a gradient, which does not contain sharp
41 // transitions, so encoding lossiness should not be too high.
42 TEST_F(VideoDecoderVpxTest, Gradient) {
43   TestGradient(320, 240, 320, 240, 0.04, 0.02);
44 }
45
46 TEST_F(VideoDecoderVpxTest, GradientScaleUpEvenToEven) {
47   TestGradient(320, 240, 640, 480, 0.04, 0.02);
48 }
49
50 TEST_F(VideoDecoderVpxTest, GradientScaleUpEvenToOdd) {
51   TestGradient(320, 240, 641, 481, 0.04, 0.02);
52 }
53
54 TEST_F(VideoDecoderVpxTest, GradientScaleUpOddToEven) {
55   TestGradient(321, 241, 640, 480, 0.04, 0.02);
56 }
57
58 TEST_F(VideoDecoderVpxTest, GradientScaleUpOddToOdd) {
59   TestGradient(321, 241, 641, 481, 0.04, 0.02);
60 }
61
62 TEST_F(VideoDecoderVpxTest, GradientScaleDownEvenToEven) {
63   TestGradient(320, 240, 160, 120, 0.04, 0.02);
64 }
65
66 TEST_F(VideoDecoderVpxTest, GradientScaleDownEvenToOdd) {
67   // The maximum error is non-deterministic. The mean error is not too high,
68   // which suggests that the problem is restricted to a small area of the output
69   // image. See crbug.com/139437 and crbug.com/139633.
70   TestGradient(320, 240, 161, 121, 1.0, 0.02);
71 }
72
73 TEST_F(VideoDecoderVpxTest, GradientScaleDownOddToEven) {
74   TestGradient(321, 241, 160, 120, 0.04, 0.02);
75 }
76
77 TEST_F(VideoDecoderVpxTest, GradientScaleDownOddToOdd) {
78   TestGradient(321, 241, 161, 121, 0.04, 0.02);
79 }
80
81 }  // namespace remoting