diff options
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/base/encoder_vp8.cc | 6 | ||||
-rw-r--r-- | remoting/base/encoder_vp8.h | 3 | ||||
-rw-r--r-- | remoting/base/encoder_vp8_unittest.cc | 41 |
3 files changed, 49 insertions, 1 deletions
diff --git a/remoting/base/encoder_vp8.cc b/remoting/base/encoder_vp8.cc index 84a0bc6..0bba179 100644 --- a/remoting/base/encoder_vp8.cc +++ b/remoting/base/encoder_vp8.cc @@ -37,13 +37,19 @@ EncoderVp8::EncoderVp8() } EncoderVp8::~EncoderVp8() { + Destroy(); +} + +void EncoderVp8::Destroy() { if (initialized_) { vpx_codec_err_t ret = vpx_codec_destroy(codec_.get()); DCHECK(ret == VPX_CODEC_OK) << "Failed to destroy codec"; + initialized_ = false; } } bool EncoderVp8::Init(const gfx::Size& size) { + Destroy(); size_ = size; codec_.reset(new vpx_codec_ctx_t()); image_.reset(new vpx_image_t()); diff --git a/remoting/base/encoder_vp8.h b/remoting/base/encoder_vp8.h index 6ded488..a74d9f9 100644 --- a/remoting/base/encoder_vp8.h +++ b/remoting/base/encoder_vp8.h @@ -32,6 +32,9 @@ class EncoderVp8 : public Encoder { // Initialize the encoder. Returns true if successful. bool Init(const gfx::Size& size); + // Destroy the encoder. + void Destroy(); + // Prepare |image_| for encoding. Write updated rectangles into // |updated_rects|. Returns true if successful. bool PrepareImage(scoped_refptr<CaptureData> capture_data, diff --git a/remoting/base/encoder_vp8_unittest.cc b/remoting/base/encoder_vp8_unittest.cc index 370fd08..9435cd1 100644 --- a/remoting/base/encoder_vp8_unittest.cc +++ b/remoting/base/encoder_vp8_unittest.cc @@ -1,11 +1,16 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <limits> +#include <vector> +#include "base/callback.h" +#include "base/scoped_ptr.h" +#include "remoting/base/capture_data.h" #include "remoting/base/codec_test.h" #include "remoting/base/encoder_vp8.h" +#include "remoting/proto/video.pb.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -21,6 +26,40 @@ TEST(EncoderVp8Test, TestEncoder) { TestEncoder(&encoder, false); } +class EncoderCallback { + public: + void DataAvailable(VideoPacket *packet) { + delete packet; + } +}; + +// Test that calling Encode with a differently-sized CaptureData does not +// leak memory. +TEST(EncoderVp8Test, TestSizeChangeNoLeak) { + int height = 1000; + int width = 1000; + const int kBytesPerPixel = 4; + + EncoderVp8 encoder; + EncoderCallback callback; + + std::vector<uint8> buffer(width * height * kBytesPerPixel); + DataPlanes planes; + planes.data[0] = &buffer.front(); + planes.strides[0] = width; + + scoped_refptr<CaptureData> capture_data(new CaptureData( + planes, gfx::Size(width, height), media::VideoFrame::RGB32)); + encoder.Encode(capture_data, false, + NewCallback(&callback, &EncoderCallback::DataAvailable)); + + height /= 2; + capture_data = new CaptureData(planes, gfx::Size(width, height), + media::VideoFrame::RGB32); + encoder.Encode(capture_data, false, + NewCallback(&callback, &EncoderCallback::DataAvailable)); +} + TEST(EncoderVp8Test, AlignAndClipRect) { // Simple test case (no clipping). gfx::Rect r1(100, 200, 300, 400); |