18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "remoting/codec/video_decoder_vpx.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/video_frame.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/codec/codec_test.h" 98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "remoting/codec/video_encoder_vpx.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochnamespace { 16e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class VideoDecoderVpxTest : public testing::Test { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<VideoEncoderVpx> encoder_; 208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<VideoDecoderVpx> decoder_; 218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) VideoDecoderVpxTest() : encoder_(VideoEncoderVpx::CreateForVP8()), 238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) decoder_(VideoDecoderVpx::CreateForVP8()) { 248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void TestGradient(int screen_width, int screen_height, 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int view_width, int view_height, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) double max_error_limit, double mean_error_limit) { 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TestVideoEncoderDecoderGradient( 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) encoder_.get(), decoder_.get(), 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) webrtc::DesktopSize(screen_width, screen_height), 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) webrtc::DesktopSize(view_width, view_height), 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) max_error_limit, mean_error_limit); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 37e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass VideoDecoderVp8Test : public VideoDecoderVpxTest { 38e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch protected: 39e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch VideoDecoderVp8Test() { 40e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch encoder_ = VideoEncoderVpx::CreateForVP8(); 41e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch decoder_ = VideoDecoderVpx::CreateForVP8(); 42e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 43e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}; 44e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 45e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass VideoDecoderVp9Test : public VideoDecoderVpxTest { 46e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch protected: 47e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch VideoDecoderVp9Test() { 48e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch encoder_ = VideoEncoderVpx::CreateForVP9(); 49e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch decoder_ = VideoDecoderVpx::CreateForVP9(); 50e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch } 51e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}; 52e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 53e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} // namespace 54e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 55e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// 56e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// Test the VP8 codec. 57e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// 58e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 59e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, VideoEncodeAndDecode) { 60e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestVideoEncoderDecoder(encoder_.get(), decoder_.get(), false); 61e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 62e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 63e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// Check that encoding and decoding a particular frame doesn't change the 64e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// frame too much. The frame used is a gradient, which does not contain sharp 65e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// transitions, so encoding lossiness should not be too high. 66e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, Gradient) { 67e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(320, 240, 320, 240, 0.04, 0.02); 68e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 69e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 70e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleUpEvenToEven) { 71e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(320, 240, 640, 480, 0.04, 0.02); 72e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 73e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 74e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleUpEvenToOdd) { 75e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(320, 240, 641, 481, 0.04, 0.02); 76e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 77e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 78e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleUpOddToEven) { 79e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(321, 241, 640, 480, 0.04, 0.02); 80e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 81e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 82e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleUpOddToOdd) { 83e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(321, 241, 641, 481, 0.04, 0.02); 84e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 85e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 86e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleDownEvenToEven) { 87e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(320, 240, 160, 120, 0.04, 0.02); 88e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 89e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 90e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleDownEvenToOdd) { 91e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // The maximum error is non-deterministic. The mean error is not too high, 92e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // which suggests that the problem is restricted to a small area of the output 93e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch // image. See crbug.com/139437 and crbug.com/139633. 94e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(320, 240, 161, 121, 1.0, 0.02); 95e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 96e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 97e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleDownOddToEven) { 98e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(321, 241, 160, 120, 0.04, 0.02); 99e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 100e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 101e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp8Test, GradientScaleDownOddToOdd) { 102e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch TestGradient(321, 241, 161, 121, 0.04, 0.02); 103e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch} 104e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 105e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// 106e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// Test the VP9 codec. 107e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// 108e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 109e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, VideoEncodeAndDecode) { 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) TestVideoEncoderDecoder(encoder_.get(), decoder_.get(), false); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that encoding and decoding a particular frame doesn't change the 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// frame too much. The frame used is a gradient, which does not contain sharp 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// transitions, so encoding lossiness should not be too high. 116e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, Gradient) { 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestGradient(320, 240, 320, 240, 0.04, 0.02); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 120e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleUpEvenToEven) { 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(320, 240, 640, 480, 0.04, 0.02); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 124e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleUpEvenToOdd) { 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(320, 240, 641, 481, 0.04, 0.02); 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 128e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleUpOddToEven) { 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(321, 241, 640, 480, 0.04, 0.02); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 132e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleUpOddToOdd) { 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(321, 241, 641, 481, 0.04, 0.02); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 136e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleDownEvenToEven) { 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(320, 240, 160, 120, 0.04, 0.02); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 140e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleDownEvenToOdd) { 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The maximum error is non-deterministic. The mean error is not too high, 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which suggests that the problem is restricted to a small area of the output 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // image. See crbug.com/139437 and crbug.com/139633. 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(320, 240, 161, 121, 1.0, 0.02); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 147e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleDownOddToEven) { 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(321, 241, 160, 120, 0.04, 0.02); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 151e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen MurdochTEST_F(VideoDecoderVp9Test, GradientScaleDownOddToOdd) { 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestGradient(321, 241, 161, 121, 0.04, 0.02); 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace remoting 156