Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: remoting/codec/video_encoder_vpx_unittest.cc

Issue 304653002: Extend VideoControl to allow clients to request lossless modes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/codec/video_encoder_vpx.cc ('k') | remoting/host/client_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "remoting/codec/codec_test.h" 11 #include "remoting/codec/codec_test.h"
12 #include "remoting/proto/video.pb.h" 12 #include "remoting/proto/video.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
15 15
16 namespace {
17
18 const int kIntMax = std::numeric_limits<int>::max();
19
20 } // namespace
21
22 namespace remoting { 16 namespace remoting {
23 17
24 TEST(VideoEncoderVp8Test, TestVideoEncoder) { 18 // xRGB pixel colors for use by tests.
19 const uint32 kBlueColor = 0x0000ff;
20 const uint32 kGreenColor = 0x00ff00;
21
22 // Creates a frame stippled between blue and red pixels, which is useful for
23 // lossy/lossless encode and color tests.
24 static scoped_ptr<webrtc::DesktopFrame> CreateTestFrame(
25 const webrtc::DesktopSize& frame_size) {
26 scoped_ptr<webrtc::DesktopFrame> frame(
27 new webrtc::BasicDesktopFrame(frame_size));
28 for (int x = 0; x < frame_size.width(); ++x) {
29 for (int y = 0; y < frame_size.height(); ++y) {
30 uint8* pixel_u8 = frame->data() + (y * frame->stride()) +
31 (x * webrtc::DesktopFrame::kBytesPerPixel);
32 *(reinterpret_cast<uint32*>(pixel_u8)) =
33 ((x + y) & 1) ? kGreenColor : kBlueColor;
34 }
35 }
36 return frame.Pass();
37 }
38
39 TEST(VideoEncoderVpxTest, TestVp8VideoEncoder) {
25 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); 40 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
26 TestVideoEncoder(encoder.get(), false); 41 TestVideoEncoder(encoder.get(), false);
27 } 42 }
28 43
44 TEST(VideoEncoderVpxTest, TestVp9VideoEncoder) {
45 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9());
46 // VP9 encoder defaults to lossless encode and lossy (I420) color.
47 TestVideoEncoder(encoder.get(), false);
48 }
49
50 // Test that the VP9 encoder can switch between lossy & lossless encode.
51 TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyEncode) {
52 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9());
53
54 webrtc::DesktopSize frame_size(1024, 768);
55 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
56 frame->mutable_updated_region()->SetRect(
57 webrtc::DesktopRect::MakeSize(frame_size));
58
59 // Lossy encode the first frame.
60 encoder->SetLosslessEncode(false);
61 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame);
62
63 // Lossless encode the second frame.
64 encoder->SetLosslessEncode(true);
65 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame);
66 EXPECT_GT(lossless_packet->data().size(), lossy_packet->data().size());
67
68 // Lossy encode one more frame.
69 encoder->SetLosslessEncode(false);
70 lossy_packet = encoder->Encode(*frame);
71 EXPECT_LT(lossy_packet->data().size(), lossless_packet->data().size());
72 }
73
74 // Test that the VP9 encoder can switch between lossy & lossless color.
75 TEST(VideoEncoderVpxTest, TestVp9VideoEncoderLossyColor) {
76 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9());
77
78 webrtc::DesktopSize frame_size(1024, 768);
79 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
80 frame->mutable_updated_region()->SetRect(
81 webrtc::DesktopRect::MakeSize(frame_size));
82
83 // Lossy encode the first frame.
84 encoder->SetLosslessColor(false);
85 scoped_ptr<VideoPacket> lossy_packet = encoder->Encode(*frame);
86
87 // Lossless encode the second frame.
88 encoder->SetLosslessColor(true);
89 scoped_ptr<VideoPacket> lossless_packet = encoder->Encode(*frame);
90 EXPECT_GT(lossless_packet->data().size(), lossy_packet->data().size());
91
92 // Lossy encode one more frame.
93 encoder->SetLosslessColor(false);
94 lossy_packet = encoder->Encode(*frame);
95 EXPECT_LT(lossy_packet->data().size(), lossless_packet->data().size());
96 }
97
98 // Test that the VP8 encoder ignores lossless modes without crashing.
99 TEST(VideoEncoderVpxTest, TestVp8VideoEncoderIgnoreLossy) {
100 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
101
102 webrtc::DesktopSize frame_size(1024, 768);
103 scoped_ptr<webrtc::DesktopFrame> frame(CreateTestFrame(frame_size));
104 frame->mutable_updated_region()->SetRect(
105 webrtc::DesktopRect::MakeSize(frame_size));
106
107 // Encode a frame, to give the encoder a chance to crash if misconfigured.
108 encoder->SetLosslessEncode(true);
109 encoder->SetLosslessColor(true);
110 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
111 EXPECT_TRUE(packet);
112 }
113
29 // Test that calling Encode with a differently-sized media::ScreenCaptureData 114 // Test that calling Encode with a differently-sized media::ScreenCaptureData
30 // does not leak memory. 115 // does not leak memory.
31 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { 116 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) {
32 int height = 1000; 117 int height = 1000;
33 int width = 1000; 118 int width = 1000;
34 119
35 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8()); 120 scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
36 121
37 scoped_ptr<webrtc::DesktopFrame> frame( 122 scoped_ptr<webrtc::DesktopFrame> frame(
38 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height))); 123 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)));
(...skipping 18 matching lines...) Expand all
57 142
58 scoped_ptr<webrtc::DesktopFrame> frame( 143 scoped_ptr<webrtc::DesktopFrame> frame(
59 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height))); 144 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(width, height)));
60 frame->set_dpi(webrtc::DesktopVector(96, 97)); 145 frame->set_dpi(webrtc::DesktopVector(96, 97));
61 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); 146 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
62 EXPECT_EQ(packet->format().x_dpi(), 96); 147 EXPECT_EQ(packet->format().x_dpi(), 96);
63 EXPECT_EQ(packet->format().y_dpi(), 97); 148 EXPECT_EQ(packet->format().y_dpi(), 97);
64 } 149 }
65 150
66 } // namespace remoting 151 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/codec/video_encoder_vpx.cc ('k') | remoting/host/client_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698