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
3 // found in the LICENSE file.
5 #include "remoting/codec/video_encoder_vp8.h"
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/codec/codec_test.h"
14 #include "remoting/proto/video.pb.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
20 const int kIntMax
= std::numeric_limits
<int>::max();
26 TEST(VideoEncoderVp8Test
, TestVideoEncoder
) {
27 VideoEncoderVp8 encoder
;
28 TestVideoEncoder(&encoder
, false);
31 class VideoEncoderCallback
{
33 void DataAvailable(scoped_ptr
<VideoPacket
> packet
) {
37 // Test that calling Encode with a differently-sized media::ScreenCaptureData
38 // does not leak memory.
39 TEST(VideoEncoderVp8Test
, TestSizeChangeNoLeak
) {
43 VideoEncoderVp8 encoder
;
44 VideoEncoderCallback callback
;
46 scoped_ptr
<webrtc::DesktopFrame
> frame(new webrtc::BasicDesktopFrame(
47 webrtc::DesktopSize(width
, height
)));
49 encoder
.Encode(frame
.get(), base::Bind(&VideoEncoderCallback::DataAvailable
,
50 base::Unretained(&callback
)));
53 frame
.reset(new webrtc::BasicDesktopFrame(
54 webrtc::DesktopSize(width
, height
)));
55 encoder
.Encode(frame
.get(), base::Bind(&VideoEncoderCallback::DataAvailable
,
56 base::Unretained(&callback
)));
59 class VideoEncoderDpiCallback
{
61 void DataAvailable(scoped_ptr
<VideoPacket
> packet
) {
62 EXPECT_EQ(packet
->format().x_dpi(), 96);
63 EXPECT_EQ(packet
->format().y_dpi(), 97);
67 // Test that the DPI information is correctly propagated from the
68 // media::ScreenCaptureData to the VideoPacket.
69 TEST(VideoEncoderVp8Test
, TestDpiPropagation
) {
73 VideoEncoderVp8 encoder
;
74 VideoEncoderDpiCallback callback
;
76 scoped_ptr
<webrtc::DesktopFrame
> frame(new webrtc::BasicDesktopFrame(
77 webrtc::DesktopSize(width
, height
)));
78 frame
->set_dpi(webrtc::DesktopVector(96, 97));
79 encoder
.Encode(frame
.get(),
80 base::Bind(&VideoEncoderDpiCallback::DataAvailable
,
81 base::Unretained(&callback
)));
84 } // namespace remoting