Home | History | Annotate | Download | only in codec
      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.
      4 
      5 #include "remoting/codec/video_encoder_vp8.h"
      6 
      7 #include <limits>
      8 #include <vector>
      9 
     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"
     17 
     18 namespace {
     19 
     20 const int kIntMax = std::numeric_limits<int>::max();
     21 
     22 }  // namespace
     23 
     24 namespace remoting {
     25 
     26 TEST(VideoEncoderVp8Test, TestVideoEncoder) {
     27   VideoEncoderVp8 encoder;
     28   TestVideoEncoder(&encoder, false);
     29 }
     30 
     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
     38 // does not leak memory.
     39 TEST(VideoEncoderVp8Test, TestSizeChangeNoLeak) {
     40   int height = 1000;
     41   int width = 1000;
     42 
     43   VideoEncoderVp8 encoder;
     44   VideoEncoderCallback callback;
     45 
     46   scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(
     47       webrtc::DesktopSize(width, height)));
     48 
     49   encoder.Encode(frame.get(), base::Bind(&VideoEncoderCallback::DataAvailable,
     50                                          base::Unretained(&callback)));
     51 
     52   height /= 2;
     53   frame.reset(new webrtc::BasicDesktopFrame(
     54       webrtc::DesktopSize(width, height)));
     55   encoder.Encode(frame.get(), base::Bind(&VideoEncoderCallback::DataAvailable,
     56                                          base::Unretained(&callback)));
     57 }
     58 
     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
     68 // media::ScreenCaptureData to the VideoPacket.
     69 TEST(VideoEncoderVp8Test, TestDpiPropagation) {
     70   int height = 32;
     71   int width = 32;
     72 
     73   VideoEncoderVp8 encoder;
     74   VideoEncoderDpiCallback callback;
     75 
     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)));
     82 }
     83 
     84 }  // namespace remoting
     85