mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-20 00:57:49 +01:00
Use a CopyOnWriteBuffer to back EncodedImage data
Intended to make copy construction and assignment of EncodedImage cheaper, but otherwise not have any effect on users of the class. Bug: webrtc:9378, chromium:931692 Change-Id: I22cf8c05f6ef7b7b5cf7ef08fd0dfc5c61211196 Reviewed-on: https://webrtc-review.googlesource.com/c/123442 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26760}
This commit is contained in:
parent
0d4869c2b9
commit
cc26fef5b2
3 changed files with 10 additions and 6 deletions
|
@ -6,6 +6,11 @@ specific_include_rules = {
|
|||
"+modules/video_coding/encoded_frame.h",
|
||||
],
|
||||
|
||||
# Used for a private member variable.
|
||||
"encoded_image\.h": [
|
||||
"+rtc_base/copy_on_write_buffer.h",
|
||||
],
|
||||
|
||||
"i010_buffer\.h": [
|
||||
"+rtc_base/memory/aligned_malloc.h",
|
||||
],
|
||||
|
|
|
@ -42,8 +42,7 @@ EncodedImage& EncodedImage::operator=(const EncodedImage&) = default;
|
|||
|
||||
void EncodedImage::Retain() {
|
||||
if (buffer_) {
|
||||
encoded_data_ = std::vector<uint8_t>(size_);
|
||||
memcpy(encoded_data_.data(), buffer_, size_);
|
||||
encoded_data_.SetData(buffer_, size_);
|
||||
buffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#define API_VIDEO_ENCODED_IMAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/video/color_space.h"
|
||||
|
@ -23,6 +22,7 @@
|
|||
#include "api/video/video_timing.h"
|
||||
#include "common_types.h" // NOLINT(build/include)
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/copy_on_write_buffer.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
@ -88,13 +88,13 @@ class RTC_EXPORT EncodedImage {
|
|||
}
|
||||
|
||||
void Allocate(size_t capacity) {
|
||||
encoded_data_.resize(capacity);
|
||||
encoded_data_.SetSize(capacity);
|
||||
buffer_ = nullptr;
|
||||
}
|
||||
|
||||
uint8_t* data() { return buffer_ ? buffer_ : encoded_data_.data(); }
|
||||
const uint8_t* data() const {
|
||||
return buffer_ ? buffer_ : encoded_data_.data();
|
||||
return buffer_ ? buffer_ : encoded_data_.cdata();
|
||||
}
|
||||
// TODO(nisse): At some places, code accepts a const ref EncodedImage, but
|
||||
// still writes to it, to clear padding at the end of the encoded data.
|
||||
|
@ -141,7 +141,7 @@ class RTC_EXPORT EncodedImage {
|
|||
private:
|
||||
// TODO(bugs.webrtc.org/9378): We're transitioning to always owning the
|
||||
// encoded data.
|
||||
std::vector<uint8_t> encoded_data_;
|
||||
rtc::CopyOnWriteBuffer encoded_data_;
|
||||
size_t size_; // Size of encoded frame data.
|
||||
// Non-null when used with an un-owned buffer.
|
||||
uint8_t* buffer_;
|
||||
|
|
Loading…
Reference in a new issue