| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_vp8.h" | 5 #include "remoting/codec/video_encoder_vp8.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 13 #include "remoting/codec/codec_test.h" | 11 #include "remoting/codec/codec_test.h" |
| 14 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 17 | 15 |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 const int kIntMax = std::numeric_limits<int>::max(); | 18 const int kIntMax = std::numeric_limits<int>::max(); |
| 21 | 19 |
| 22 } // namespace | 20 } // namespace |
| 23 | 21 |
| 24 namespace remoting { | 22 namespace remoting { |
| 25 | 23 |
| 26 TEST(VideoEncoderVp8Test, TestVideoEncoder) { | 24 TEST(VideoEncoderVp8Test, TestVideoEncoder) { |
| 27 VideoEncoderVp8 encoder; | 25 VideoEncoderVp8 encoder; |
| 28 TestVideoEncoder(&encoder, false); | 26 TestVideoEncoder(&encoder, false); |
| 29 } | 27 } |
| 30 | 28 |
| 31 class VideoEncoderCallback { | |
| 32 public: | |
| 33 void DataAvailable(scoped_ptr<VideoPacket> packet) { | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // Test that calling Encode with a differently-sized media::ScreenCaptureData | 29 // Test that calling Encode with a differently-sized media::ScreenCaptureData |
| 38 // does not leak memory. | 30 // does not leak memory. |
| 39 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { | 31 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) { |
| 40 int height = 1000; | 32 int height = 1000; |
| 41 int width = 1000; | 33 int width = 1000; |
| 42 | 34 |
| 43 VideoEncoderVp8 encoder; | 35 VideoEncoderVp8 encoder; |
| 44 VideoEncoderCallback callback; | |
| 45 | 36 |
| 46 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( | 37 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( |
| 47 webrtc::DesktopSize(width, height))); | 38 webrtc::DesktopSize(width, height))); |
| 48 | 39 |
| 49 encoder.Encode(frame.get(), base::Bind(&VideoEncoderCallback::DataAvailable, | 40 scoped_ptr<VideoPacket> packet = encoder.Encode(*frame); |
| 50 base::Unretained(&callback))); | 41 EXPECT_TRUE(packet); |
| 51 | 42 |
| 52 height /= 2; | 43 height /= 2; |
| 53 frame.reset(new webrtc::BasicDesktopFrame( | 44 frame.reset(new webrtc::BasicDesktopFrame( |
| 54 webrtc::DesktopSize(width, height))); | 45 webrtc::DesktopSize(width, height))); |
| 55 encoder.Encode(frame.get(), base::Bind(&VideoEncoderCallback::DataAvailable, | 46 packet = encoder.Encode(*frame); |
| 56 base::Unretained(&callback))); | 47 EXPECT_TRUE(packet); |
| 57 } | 48 } |
| 58 | 49 |
| 59 class VideoEncoderDpiCallback { | |
| 60 public: | |
| 61 void DataAvailable(scoped_ptr<VideoPacket> packet) { | |
| 62 EXPECT_EQ(packet->format().x_dpi(), 96); | |
| 63 EXPECT_EQ(packet->format().y_dpi(), 97); | |
| 64 } | |
| 65 }; | |
| 66 | |
| 67 // Test that the DPI information is correctly propagated from the | 50 // Test that the DPI information is correctly propagated from the |
| 68 // media::ScreenCaptureData to the VideoPacket. | 51 // media::ScreenCaptureData to the VideoPacket. |
| 69 TEST(VideoEncoderVp8Test, TestDpiPropagation) { | 52 TEST(VideoEncoderVp8Test, TestDpiPropagation) { |
| 70 int height = 32; | 53 int height = 32; |
| 71 int width = 32; | 54 int width = 32; |
| 72 | 55 |
| 73 VideoEncoderVp8 encoder; | 56 VideoEncoderVp8 encoder; |
| 74 VideoEncoderDpiCallback callback; | |
| 75 | 57 |
| 76 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( | 58 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( |
| 77 webrtc::DesktopSize(width, height))); | 59 webrtc::DesktopSize(width, height))); |
| 78 frame->set_dpi(webrtc::DesktopVector(96, 97)); | 60 frame->set_dpi(webrtc::DesktopVector(96, 97)); |
| 79 encoder.Encode(frame.get(), | 61 scoped_ptr<VideoPacket> packet = encoder.Encode(*frame); |
| 80 base::Bind(&VideoEncoderDpiCallback::DataAvailable, | 62 EXPECT_EQ(packet->format().x_dpi(), 96); |
| 81 base::Unretained(&callback))); | 63 EXPECT_EQ(packet->format().y_dpi(), 97); |
| 82 } | 64 } |
| 83 | 65 |
| 84 } // namespace remoting | 66 } // namespace remoting |
| OLD | NEW |