| 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 21 matching lines...) Expand all Loading... |
| 32 (x * webrtc::DesktopFrame::kBytesPerPixel); | 32 (x * webrtc::DesktopFrame::kBytesPerPixel); |
| 33 *(reinterpret_cast<uint32*>(pixel_u8)) = | 33 *(reinterpret_cast<uint32*>(pixel_u8)) = |
| 34 ((x + y) & 1) ? kGreenColor : kBlueColor; | 34 ((x + y) & 1) ? kGreenColor : kBlueColor; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 frame->mutable_updated_region()->SetRect( | 37 frame->mutable_updated_region()->SetRect( |
| 38 webrtc::DesktopRect::MakeSize(frame_size)); | 38 webrtc::DesktopRect::MakeSize(frame_size)); |
| 39 return frame.Pass(); | 39 return frame.Pass(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST(VideoEncoderVpxTest, TestVp8VideoEncoder) { | 42 TEST(VideoEncoderVpxTest, Vp8) { |
| 43 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); | 43 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); |
| 44 TestVideoEncoder(encoder.get(), false); | 44 TestVideoEncoder(encoder.get(), false); |
| 45 } | 45 } |
| 46 | 46 |
| 47 TEST(VideoEncoderVpxTest, TestVp9VideoEncoder) { | 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, TestVp9VideoEncoderLossyEncode) { | 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(1024, 768); |
| 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, TestVp9VideoEncoderLossyColor) { | 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(1024, 768); |
| 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, TestVp8VideoEncoderIgnoreLossy) { | 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(1024, 768); |
| 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, TestVp8SizeChangeNoCrash) { | 115 TEST(VideoEncoderVpxTest, Vp8SizeChangeNoCrash) { |
| 116 webrtc::DesktopSize frame_size(1000, 1000); | 116 webrtc::DesktopSize frame_size(1000, 1000); |
| 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, TestVp9SizeChangeNoCrash) { | 134 TEST(VideoEncoderVpxTest, Vp9SizeChangeNoCrash) { |
| 135 webrtc::DesktopSize frame_size(1000, 1000); | 135 webrtc::DesktopSize frame_size(1000, 1000); |
| 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); |
| 146 frame = CreateTestFrame(frame_size); | 146 frame = CreateTestFrame(frame_size); |
| 147 packet = encoder->Encode(*frame); | 147 packet = encoder->Encode(*frame); |
| 148 EXPECT_TRUE(packet); | 148 EXPECT_TRUE(packet); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Test that the DPI information is correctly propagated from the | 151 // Test that the DPI information is correctly propagated from the |
| 152 // media::ScreenCaptureData to the VideoPacket. | 152 // media::ScreenCaptureData to the VideoPacket. |
| 153 TEST(VideoEncoderVpxTest, TestDpiPropagation) { | 153 TEST(VideoEncoderVpxTest, DpiPropagation) { |
| 154 webrtc::DesktopSize frame_size(32, 32); | 154 webrtc::DesktopSize frame_size(32, 32); |
| 155 | 155 |
| 156 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); | 156 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); |
| 157 | 157 |
| 158 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); | 158 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size)); |
| 159 frame->set_dpi(webrtc::DesktopVector(96, 97)); | 159 frame->set_dpi(webrtc::DesktopVector(96, 97)); |
| 160 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); | 160 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); |
| 161 EXPECT_EQ(packet->format().x_dpi(), 96); | 161 EXPECT_EQ(packet->format().x_dpi(), 96); |
| 162 EXPECT_EQ(packet->format().y_dpi(), 97); | 162 EXPECT_EQ(packet->format().y_dpi(), 97); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST(VideoEncoderVerbatimTest, Vp8EncodeUnchangedFrame) { |
| 166 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); |
| 167 TestVideoEncoderEmptyFrames(encoder.get(), 0); |
| 168 } |
| 169 |
| 170 TEST(VideoEncoderVerbatimTest, Vp9LosslessUnchangedFrame) { |
| 171 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 172 encoder->SetLosslessEncode(true); |
| 173 TestVideoEncoderEmptyFrames(encoder.get(), 0); |
| 174 } |
| 175 |
| 176 TEST(VideoEncoderVerbatimTest, Vp9LossyUnchangedFrame) { |
| 177 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9()); |
| 178 encoder->SetLosslessEncode(false); |
| 179 TestVideoEncoderEmptyFrames(encoder.get(), 2); |
| 180 } |
| 181 |
| 165 } // namespace remoting | 182 } // namespace remoting |
| OLD | NEW |