aboutsummaryrefslogtreecommitdiff
path: root/webrtc/common_video/plane.cc
diff options
context:
space:
mode:
authorChih-hung Hsieh <chh@google.com>2015-12-01 17:07:48 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-12-01 17:07:48 +0000
commita4acd9d6bc9b3b033d7d274316e75ee067df8d20 (patch)
tree672a185b294789cf991f385c3e395dd63bea9063 /webrtc/common_video/plane.cc
parent3681b90ba4fe7a27232dd3e27897d5d7ed9d651c (diff)
parentfe8b4a657979b49e1701bd92f6d5814a99e0b2be (diff)
downloadwebrtc-a4acd9d6bc9b3b033d7d274316e75ee067df8d20.tar.gz
Merge changes I7bbf776e,I1b827825
am: fe8b4a6579 * commit 'fe8b4a657979b49e1701bd92f6d5814a99e0b2be': (7237 commits) WIP: Changes after merge commit 'cb3f9bd' Make the nonlinear beamformer steerable Utilize bitrate above codec max to protect video. Enable VP9 internal resize by default. Filter overlapping RTP header extensions. Make VCMEncodedFrameCallback const. MediaCodecVideoEncoder: Add number of quality resolution downscales to Encoded callback. Remove redudant encoder rate calls. Create isolate files for nonparallel tests. Register header extensions in RtpRtcpObserver to avoid log spam. Make an enum class out of NetEqDecoder, and hide the neteq_decoders_ table ACM: Move NACK functionality inside NetEq Fix chromium-style warnings in webrtc/sound/. Create a 'webrtc_nonparallel_tests' target. Update scalability structure data according to updates in the RTP payload profile. audio_coding: rename interface -> include Rewrote perform_action_on_all_files to be parallell. Update reference indices according to updates in the RTP payload profile. Disable P2PTransport...TestFailoverControlledSide on Memcheck pass clangcl compile options to ignore warnings in gflags.cc ...
Diffstat (limited to 'webrtc/common_video/plane.cc')
-rw-r--r--webrtc/common_video/plane.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/webrtc/common_video/plane.cc b/webrtc/common_video/plane.cc
new file mode 100644
index 0000000000..e0bbba10ba
--- /dev/null
+++ b/webrtc/common_video/plane.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/common_video/plane.h"
+
+#include <string.h> // memcpy
+
+#include <algorithm> // swap
+
+namespace webrtc {
+
+// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
+static const int kBufferAlignment = 64;
+
+Plane::Plane()
+ : allocated_size_(0),
+ plane_size_(0),
+ stride_(0) {}
+
+Plane::~Plane() {}
+
+int Plane::CreateEmptyPlane(int allocated_size, int stride, int plane_size) {
+ if (allocated_size < 1 || stride < 1 || plane_size < 1)
+ return -1;
+ stride_ = stride;
+ if (MaybeResize(allocated_size) < 0)
+ return -1;
+ plane_size_ = plane_size;
+ return 0;
+}
+
+int Plane::MaybeResize(int new_size) {
+ if (new_size <= 0)
+ return -1;
+ if (new_size <= allocated_size_)
+ return 0;
+ rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> new_buffer(
+ static_cast<uint8_t*>(AlignedMalloc(new_size, kBufferAlignment)));
+ if (buffer_.get()) {
+ memcpy(new_buffer.get(), buffer_.get(), plane_size_);
+ }
+ buffer_.reset(new_buffer.release());
+ allocated_size_ = new_size;
+ return 0;
+}
+
+int Plane::Copy(const Plane& plane) {
+ if (MaybeResize(plane.allocated_size_) < 0)
+ return -1;
+ if (plane.buffer_.get())
+ memcpy(buffer_.get(), plane.buffer_.get(), plane.plane_size_);
+ stride_ = plane.stride_;
+ plane_size_ = plane.plane_size_;
+ return 0;
+}
+
+int Plane::Copy(int size, int stride, const uint8_t* buffer) {
+ if (MaybeResize(size) < 0)
+ return -1;
+ memcpy(buffer_.get(), buffer, size);
+ plane_size_ = size;
+ stride_ = stride;
+ return 0;
+}
+
+void Plane::Swap(Plane& plane) {
+ std::swap(stride_, plane.stride_);
+ std::swap(allocated_size_, plane.allocated_size_);
+ std::swap(plane_size_, plane.plane_size_);
+ buffer_.swap(plane.buffer_);
+}
+
+} // namespace webrtc