Delete unowned buffer in EncodedImage.

Bug: webrtc:9378
Change-Id: Ice48020c0f14905cbc185b52c88bbb9ac3bb4c93
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128575
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33510}
This commit is contained in:
Niels Möller
2021-03-19 13:06:23 +01:00
committed by Commit Bot
parent 2b250734da
commit 490c1503d9
7 changed files with 7 additions and 38 deletions

View File

@ -66,21 +66,11 @@ EncodedImage::EncodedImage() = default;
EncodedImage::EncodedImage(EncodedImage&&) = default;
EncodedImage::EncodedImage(const EncodedImage&) = default;
EncodedImage::EncodedImage(uint8_t* buffer, size_t size, size_t capacity)
: size_(size), buffer_(buffer), capacity_(capacity) {}
EncodedImage::~EncodedImage() = default;
EncodedImage& EncodedImage::operator=(EncodedImage&&) = default;
EncodedImage& EncodedImage::operator=(const EncodedImage&) = default;
void EncodedImage::Retain() {
if (buffer_) {
encoded_data_ = EncodedImageBuffer::Create(buffer_, size_);
buffer_ = nullptr;
}
}
void EncodedImage::SetEncodeTime(int64_t encode_start_ms,
int64_t encode_finish_ms) {
timing_.encode_start_ms = encode_start_ms;

View File

@ -73,13 +73,10 @@ class RTC_EXPORT EncodedImage {
EncodedImage();
EncodedImage(EncodedImage&&);
EncodedImage(const EncodedImage&);
ABSL_DEPRECATED("")
EncodedImage(uint8_t* buffer, size_t length, size_t capacity);
~EncodedImage();
EncodedImage& operator=(EncodedImage&&);
// Discouraged: potentially expensive.
EncodedImage& operator=(const EncodedImage&);
// TODO(nisse): Change style to timestamp(), set_timestamp(), for consistency
@ -129,33 +126,30 @@ class RTC_EXPORT EncodedImage {
RTC_DCHECK_LE(new_size, new_size == 0 ? 0 : capacity());
size_ = new_size;
}
void SetEncodedData(
rtc::scoped_refptr<EncodedImageBufferInterface> encoded_data) {
encoded_data_ = encoded_data;
size_ = encoded_data->size();
buffer_ = nullptr;
}
void ClearEncodedData() {
encoded_data_ = nullptr;
size_ = 0;
buffer_ = nullptr;
capacity_ = 0;
}
rtc::scoped_refptr<EncodedImageBufferInterface> GetEncodedData() const {
RTC_DCHECK(buffer_ == nullptr);
return encoded_data_;
}
const uint8_t* data() const {
return buffer_ ? buffer_
: (encoded_data_ ? encoded_data_->data() : nullptr);
return encoded_data_ ? encoded_data_->data() : nullptr;
}
// Hack to workaround lack of ownership of the encoded data. If we don't
// already own the underlying data, make an owned copy.
void Retain();
// TODO(bugs.webrtc.org/9378): Obsolete, delete as soon as downstream calls
// are fixed.
ABSL_DEPRECATED("")
void Retain() {}
uint32_t _encodedWidth = 0;
uint32_t _encodedHeight = 0;
@ -186,18 +180,10 @@ class RTC_EXPORT EncodedImage {
} timing_;
private:
size_t capacity() const {
return buffer_ ? capacity_ : (encoded_data_ ? encoded_data_->size() : 0);
}
size_t capacity() const { return encoded_data_ ? encoded_data_->size() : 0; }
// TODO(bugs.webrtc.org/9378): We're transitioning to always owning the
// encoded data.
rtc::scoped_refptr<EncodedImageBufferInterface> encoded_data_;
size_t size_ = 0; // Size of encoded frame data.
// Non-null when used with an un-owned buffer.
uint8_t* buffer_ = nullptr;
// Allocated size of _buffer; relevant only if it's non-null.
size_t capacity_ = 0;
uint32_t timestamp_rtp_ = 0;
absl::optional<int> spatial_index_;
std::map<int, size_t> spatial_layer_frame_size_bytes_;

View File

@ -298,9 +298,6 @@ EncodedImageCallback::Result MultiplexEncoderAdapter::OnEncodedImage(
PayloadStringToCodecType(associated_format_.name);
image_component.encoded_image = encodedImage;
// If we don't already own the buffer, make a copy.
image_component.encoded_image.Retain();
MutexLock lock(&mutex_);
const auto& stashed_image_itr =
stashed_images_.find(encodedImage.Timestamp());

View File

@ -121,7 +121,6 @@ class VideoProcessor {
: video_processor_(video_processor),
encoded_image_(encoded_image),
codec_specific_info_(*codec_specific_info) {
encoded_image_.Retain();
}
bool Run() override {

View File

@ -52,7 +52,6 @@ class RTC_EXPORT VCMEncodedFrame : public EncodedImage {
using EncodedImage::GetEncodedData;
using EncodedImage::NtpTimeMs;
using EncodedImage::PacketInfos;
using EncodedImage::Retain;
using EncodedImage::set_size;
using EncodedImage::SetColorSpace;
using EncodedImage::SetEncodedData;

View File

@ -683,7 +683,6 @@ void VideoReceiveStream::HandleEncodedFrame(
}
if (encoded_frame_buffer_function_) {
frame->Retain();
encoded_frame_buffer_function_(WebRtcRecordableEncodedFrame(*frame));
}
}

View File

@ -725,7 +725,6 @@ void VideoReceiveStream2::HandleEncodedFrame(
}));
if (encoded_frame_buffer_function_) {
frame->Retain();
encoded_frame_buffer_function_(WebRtcRecordableEncodedFrame(*frame));
}
}