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:
@ -6,6 +6,11 @@ specific_include_rules = {
|
|||||||
"+modules/video_coding/encoded_frame.h",
|
"+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": [
|
"i010_buffer\.h": [
|
||||||
"+rtc_base/memory/aligned_malloc.h",
|
"+rtc_base/memory/aligned_malloc.h",
|
||||||
],
|
],
|
||||||
|
@ -42,8 +42,7 @@ EncodedImage& EncodedImage::operator=(const EncodedImage&) = default;
|
|||||||
|
|
||||||
void EncodedImage::Retain() {
|
void EncodedImage::Retain() {
|
||||||
if (buffer_) {
|
if (buffer_) {
|
||||||
encoded_data_ = std::vector<uint8_t>(size_);
|
encoded_data_.SetData(buffer_, size_);
|
||||||
memcpy(encoded_data_.data(), buffer_, size_);
|
|
||||||
buffer_ = nullptr;
|
buffer_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#define API_VIDEO_ENCODED_IMAGE_H_
|
#define API_VIDEO_ENCODED_IMAGE_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "api/video/color_space.h"
|
#include "api/video/color_space.h"
|
||||||
@ -23,6 +22,7 @@
|
|||||||
#include "api/video/video_timing.h"
|
#include "api/video/video_timing.h"
|
||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/copy_on_write_buffer.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -88,13 +88,13 @@ class RTC_EXPORT EncodedImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Allocate(size_t capacity) {
|
void Allocate(size_t capacity) {
|
||||||
encoded_data_.resize(capacity);
|
encoded_data_.SetSize(capacity);
|
||||||
buffer_ = nullptr;
|
buffer_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* data() { return buffer_ ? buffer_ : encoded_data_.data(); }
|
uint8_t* data() { return buffer_ ? buffer_ : encoded_data_.data(); }
|
||||||
const uint8_t* data() const {
|
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
|
// 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.
|
// still writes to it, to clear padding at the end of the encoded data.
|
||||||
@ -141,7 +141,7 @@ class RTC_EXPORT EncodedImage {
|
|||||||
private:
|
private:
|
||||||
// TODO(bugs.webrtc.org/9378): We're transitioning to always owning the
|
// TODO(bugs.webrtc.org/9378): We're transitioning to always owning the
|
||||||
// encoded data.
|
// encoded data.
|
||||||
std::vector<uint8_t> encoded_data_;
|
rtc::CopyOnWriteBuffer encoded_data_;
|
||||||
size_t size_; // Size of encoded frame data.
|
size_t size_; // Size of encoded frame data.
|
||||||
// Non-null when used with an un-owned buffer.
|
// Non-null when used with an un-owned buffer.
|
||||||
uint8_t* buffer_;
|
uint8_t* buffer_;
|
||||||
|
Reference in New Issue
Block a user