| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/codec/video_encoder_vpx.h" | 5 #include "remoting/codec/video_encoder_vpx.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 TEST(VideoEncoderVpxTest, Vp9) { | 47 TEST(VideoEncoderVpxTest, Vp9) { |
| 48 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); | 48 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 49 // VP9 encoder defaults to lossless encode and lossy (I420) color. | 49 // VP9 encoder defaults to lossless encode and lossy (I420) color. |
| 50 TestVideoEncoder(encoder.get(), false); | 50 TestVideoEncoder(encoder.get(), false); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Test that the VP9 encoder can switch between lossy & lossless encode. | 53 // Test that the VP9 encoder can switch between lossy & lossless encode. |
| 54 TEST(VideoEncoderVpxTest, Vp9LossyEncodeSwitching) { | 54 TEST(VideoEncoderVpxTest, Vp9LossyEncodeSwitching) { |
| 55 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); | 55 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 56 | 56 |
| 57 webrtc::DesktopSize frame_size(1024, 768); | 57 webrtc::DesktopSize frame_size(100, 100); |
| 58 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 58 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 59 | 59 |
| 60 // Lossy encode the first frame. | 60 // Lossy encode the first frame. |
| 61 encoder->SetLosslessEncode(false); | 61 encoder->SetLosslessEncode(false); |
| 62 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame); | 62 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame); |
| 63 | 63 |
| 64 // Lossless encode the second frame. | 64 // Lossless encode the second frame. |
| 65 encoder->SetLosslessEncode(true); | 65 encoder->SetLosslessEncode(true); |
| 66 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame); | 66 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame); |
| 67 // Lossless encode is so good that the frames are smaller than the lossy | 67 // Lossless encode is so good that the frames are smaller than the lossy |
| 68 // encodes. This comparison needs to be revisited. | 68 // encodes. This comparison needs to be revisited. |
| 69 // http://crbug.com/439166 | 69 // http://crbug.com/439166 |
| 70 // EXPECT_GT(lossless_packet->data().size(), lossy_packet->data().size()); | 70 // EXPECT_GT(lossless_packet->data().size(), lossy_packet->data().size()); |
| 71 | 71 |
| 72 // Lossy encode one more frame. | 72 // Lossy encode one more frame. |
| 73 encoder->SetLosslessEncode(false); | 73 encoder->SetLosslessEncode(false); |
| 74 lossy_packet = encoder->Encode(*frame); | 74 lossy_packet = encoder->Encode(*frame); |
| 75 // Same bug as above. | 75 // Same bug as above. |
| 76 // EXPECT_LT(lossy_packet->data().size(), lossless_packet->data().size()); | 76 // EXPECT_LT(lossy_packet->data().size(), lossless_packet->data().size()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Test that the VP9 encoder can switch between lossy & lossless color. | 79 // Test that the VP9 encoder can switch between lossy & lossless color. |
| 80 TEST(VideoEncoderVpxTest, Vp9LossyColorSwitching) { | 80 TEST(VideoEncoderVpxTest, Vp9LossyColorSwitching) { |
| 81 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); | 81 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 82 | 82 |
| 83 webrtc::DesktopSize frame_size(1024, 768); | 83 webrtc::DesktopSize frame_size(100, 100); |
| 84 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 84 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 85 | 85 |
| 86 // Lossy encode the first frame. | 86 // Lossy encode the first frame. |
| 87 encoder->SetLosslessColor(false); | 87 encoder->SetLosslessColor(false); |
| 88 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame); | 88 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame); |
| 89 | 89 |
| 90 // Lossless encode the second frame. | 90 // Lossless encode the second frame. |
| 91 encoder->SetLosslessColor(true); | 91 encoder->SetLosslessColor(true); |
| 92 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame); | 92 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame); |
| 93 | 93 |
| 94 // Lossy encode one more frame. | 94 // Lossy encode one more frame. |
| 95 encoder->SetLosslessColor(false); | 95 encoder->SetLosslessColor(false); |
| 96 lossy_packet = encoder->Encode(*frame); | 96 lossy_packet = encoder->Encode(*frame); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Test that the VP8 encoder ignores lossless modes without crashing. | 99 // Test that the VP8 encoder ignores lossless modes without crashing. |
| 100 TEST(VideoEncoderVpxTest, Vp8IgnoreLossy) { | 100 TEST(VideoEncoderVpxTest, Vp8IgnoreLossy) { |
| 101 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); | 101 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); |
| 102 | 102 |
| 103 webrtc::DesktopSize frame_size(1024, 768); | 103 webrtc::DesktopSize frame_size(100, 100); |
| 104 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 104 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 105 | 105 |
| 106 // Encode a frame, to give the encoder a chance to crash if misconfigured. | 106 // Encode a frame, to give the encoder a chance to crash if misconfigured. |
| 107 encoder->SetLosslessEncode(true); | 107 encoder->SetLosslessEncode(true); |
| 108 encoder->SetLosslessColor(true); | 108 encoder->SetLosslessColor(true); |
| 109 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); | 109 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); |
| 110 EXPECT_TRUE(packet); | 110 EXPECT_TRUE(packet); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Test that calling Encode with a larger frame size than the initial one | 113 // Test that calling Encode with a larger frame size than the initial one |
| 114 // does not cause VP8 to crash. | 114 // does not cause VP8 to crash. |
| 115 TEST(VideoEncoderVpxTest, Vp8SizeChangeNoCrash) { | 115 TEST(VideoEncoderVpxTest, Vp8SizeChangeNoCrash) { |
| 116 webrtc::DesktopSize frame_size(1000, 1000); | 116 webrtc::DesktopSize frame_size(100, 100); |
| 117 | 117 |
| 118 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); | 118 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); |
| 119 | 119 |
| 120 // Create first frame & encode it. | 120 // Create first frame & encode it. |
| 121 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 121 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 122 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); | 122 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); |
| 123 EXPECT_TRUE(packet); | 123 EXPECT_TRUE(packet); |
| 124 | 124 |
| 125 // Double the size of the frame, and updated region, and encode again. | 125 // Double the size of the frame, and updated region, and encode again. |
| 126 frame_size.set(frame_size.width() * 2, frame_size.height() * 2); | 126 frame_size.set(frame_size.width() * 2, frame_size.height() * 2); |
| 127 frame = CreateTestFrame(frame_size); | 127 frame = CreateTestFrame(frame_size); |
| 128 packet = encoder->Encode(*frame); | 128 packet = encoder->Encode(*frame); |
| 129 EXPECT_TRUE(packet); | 129 EXPECT_TRUE(packet); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Test that calling Encode with a larger frame size than the initial one | 132 // Test that calling Encode with a larger frame size than the initial one |
| 133 // does not cause VP9 to crash. | 133 // does not cause VP9 to crash. |
| 134 TEST(VideoEncoderVpxTest, Vp9SizeChangeNoCrash) { | 134 TEST(VideoEncoderVpxTest, Vp9SizeChangeNoCrash) { |
| 135 webrtc::DesktopSize frame_size(1000, 1000); | 135 webrtc::DesktopSize frame_size(100, 100); |
| 136 | 136 |
| 137 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); | 137 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 138 | 138 |
| 139 // Create first frame & encode it. | 139 // Create first frame & encode it. |
| 140 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 140 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 141 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); | 141 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); |
| 142 EXPECT_TRUE(packet); | 142 EXPECT_TRUE(packet); |
| 143 | 143 |
| 144 // Double the size of the frame, and updated region, and encode again. | 144 // Double the size of the frame, and updated region, and encode again. |
| 145 frame_size.set(frame_size.width() * 2, frame_size.height() * 2); | 145 frame_size.set(frame_size.width() * 2, frame_size.height() * 2); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 175 | 175 |
| 176 TEST(VideoEncoderVpxTest, Vp9LossyUnchangedFrame) { | 176 TEST(VideoEncoderVpxTest, Vp9LossyUnchangedFrame) { |
| 177 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); | 177 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 178 encoder->SetLosslessEncode(false); | 178 encoder->SetLosslessEncode(false); |
| 179 // Expect that VP9+CR should generate no more than 10 top-off frames | 179 // Expect that VP9+CR should generate no more than 10 top-off frames |
| 180 // per cycle, and take no more than 2 cycles to top-off. | 180 // per cycle, and take no more than 2 cycles to top-off. |
| 181 TestVideoEncoderEmptyFrames(encoder.get(), 20); | 181 TestVideoEncoderEmptyFrames(encoder.get(), 20); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace remoting | 184 } // namespace remoting |
| OLD | NEW |