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 namespace { 16 17 class VideoDecoderVpxTest : public testing::Test { 18 protected: 19 scoped_ptr<VideoEncoderVpx> encoder_; 20 scoped_ptr<VideoDecoderVpx> decoder_; 21 22 VideoDecoderVpxTest() : encoder_(VideoEncoderVpx::CreateForVP8()), 23 decoder_(VideoDecoderVpx::CreateForVP8()) { 24 } 25 26 void TestGradient(int screen_width, int screen_height, 27 int view_width, int view_height, 28 double max_error_limit, double mean_error_limit) { 29 TestVideoEncoderDecoderGradient( 30 encoder_.get(), decoder_.get(), 31 webrtc::DesktopSize(screen_width, screen_height), 32 webrtc::DesktopSize(view_width, view_height), 33 max_error_limit, mean_error_limit); 34 } 35 }; 36 37 class VideoDecoderVp8Test : public VideoDecoderVpxTest { 38 protected: 39 VideoDecoderVp8Test() { 40 encoder_ = VideoEncoderVpx::CreateForVP8(); 41 decoder_ = VideoDecoderVpx::CreateForVP8(); 42 } 43 }; 44 45 class VideoDecoderVp9Test : public VideoDecoderVpxTest { 46 protected: 47 VideoDecoderVp9Test() { 48 encoder_ = VideoEncoderVpx::CreateForVP9(); 49 decoder_ = VideoDecoderVpx::CreateForVP9(); 50 } 51 }; 52 53 } // namespace 54 55 // 56 // Test the VP8 codec. 57 // 58 59 TEST_F(VideoDecoderVp8Test, VideoEncodeAndDecode) { 60 TestVideoEncoderDecoder(encoder_.get(), decoder_.get(), false); 61 } 62 63 // Check that encoding and decoding a particular frame doesn't change the 64 // frame too much. The frame used is a gradient, which does not contain sharp 65 // transitions, so encoding lossiness should not be too high. 66 TEST_F(VideoDecoderVp8Test, Gradient) { 67 TestGradient(320, 240, 320, 240, 0.04, 0.02); 68 } 69 70 TEST_F(VideoDecoderVp8Test, GradientScaleUpEvenToEven) { 71 TestGradient(320, 240, 640, 480, 0.04, 0.02); 72 } 73 74 TEST_F(VideoDecoderVp8Test, GradientScaleUpEvenToOdd) { 75 TestGradient(320, 240, 641, 481, 0.04, 0.02); 76 } 77 78 TEST_F(VideoDecoderVp8Test, GradientScaleUpOddToEven) { 79 TestGradient(321, 241, 640, 480, 0.04, 0.02); 80 } 81 82 TEST_F(VideoDecoderVp8Test, GradientScaleUpOddToOdd) { 83 TestGradient(321, 241, 641, 481, 0.04, 0.02); 84 } 85 86 TEST_F(VideoDecoderVp8Test, GradientScaleDownEvenToEven) { 87 TestGradient(320, 240, 160, 120, 0.04, 0.02); 88 } 89 90 TEST_F(VideoDecoderVp8Test, GradientScaleDownEvenToOdd) { 91 // The maximum error is non-deterministic. The mean error is not too high, 92 // which suggests that the problem is restricted to a small area of the output 93 // image. See crbug.com/139437 and crbug.com/139633. 94 TestGradient(320, 240, 161, 121, 1.0, 0.02); 95 } 96 97 TEST_F(VideoDecoderVp8Test, GradientScaleDownOddToEven) { 98 TestGradient(321, 241, 160, 120, 0.04, 0.02); 99 } 100 101 TEST_F(VideoDecoderVp8Test, GradientScaleDownOddToOdd) { 102 TestGradient(321, 241, 161, 121, 0.04, 0.02); 103 } 104 105 // 106 // Test the VP9 codec. 107 // 108 109 TEST_F(VideoDecoderVp9Test, VideoEncodeAndDecode) { 110 TestVideoEncoderDecoder(encoder_.get(), decoder_.get(), false); 111 } 112 113 // Check that encoding and decoding a particular frame doesn't change the 114 // frame too much. The frame used is a gradient, which does not contain sharp 115 // transitions, so encoding lossiness should not be too high. 116 TEST_F(VideoDecoderVp9Test, Gradient) { 117 TestGradient(320, 240, 320, 240, 0.04, 0.02); 118 } 119 120 TEST_F(VideoDecoderVp9Test, GradientScaleUpEvenToEven) { 121 TestGradient(320, 240, 640, 480, 0.04, 0.02); 122 } 123 124 TEST_F(VideoDecoderVp9Test, GradientScaleUpEvenToOdd) { 125 TestGradient(320, 240, 641, 481, 0.04, 0.02); 126 } 127 128 TEST_F(VideoDecoderVp9Test, GradientScaleUpOddToEven) { 129 TestGradient(321, 241, 640, 480, 0.04, 0.02); 130 } 131 132 TEST_F(VideoDecoderVp9Test, GradientScaleUpOddToOdd) { 133 TestGradient(321, 241, 641, 481, 0.04, 0.02); 134 } 135 136 TEST_F(VideoDecoderVp9Test, GradientScaleDownEvenToEven) { 137 TestGradient(320, 240, 160, 120, 0.04, 0.02); 138 } 139 140 TEST_F(VideoDecoderVp9Test, GradientScaleDownEvenToOdd) { 141 // The maximum error is non-deterministic. The mean error is not too high, 142 // which suggests that the problem is restricted to a small area of the output 143 // image. See crbug.com/139437 and crbug.com/139633. 144 TestGradient(320, 240, 161, 121, 1.0, 0.02); 145 } 146 147 TEST_F(VideoDecoderVp9Test, GradientScaleDownOddToEven) { 148 TestGradient(321, 241, 160, 120, 0.04, 0.02); 149 } 150 151 TEST_F(VideoDecoderVp9Test, GradientScaleDownOddToOdd) { 152 TestGradient(321, 241, 161, 121, 0.04, 0.02); 153 } 154 155 } // namespace remoting 156