Delete VCMEncodedFrame::VerifyAndAllocate

And mark EncodedImage::Allocate as deprecated.

Bug: webrtc:9378
Change-Id: I03ce907fa6b87803ddb72f548f60a9bf1b7c317d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/155163
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29383}
This commit is contained in:
Niels Möller
2019-10-03 08:43:53 +02:00
committed by Commit Bot
parent 7536bc5395
commit b9bfe655d4
7 changed files with 19 additions and 33 deletions

View File

@ -114,6 +114,7 @@ rtc_source_set("encoded_image") {
"..:scoped_refptr",
"../..:webrtc_common",
"../../rtc_base:checks",
"../../rtc_base:deprecation",
"../../rtc_base:rtc_base_approved",
"../../rtc_base/system:rtc_export",
"//third_party/abseil-cpp/absl/types:optional",

View File

@ -28,6 +28,7 @@
#include "api/video/video_timing.h"
#include "common_types.h" // NOLINT(build/include)
#include "rtc_base/checks.h"
#include "rtc_base/deprecation.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/system/rtc_export.h"
@ -55,6 +56,7 @@ class EncodedImageBufferInterface : public rtc::RefCountInterface {
// Basic implementation of EncodedImageBufferInterface.
class EncodedImageBuffer : public EncodedImageBufferInterface {
public:
static rtc::scoped_refptr<EncodedImageBuffer> Create() { return Create(0); }
static rtc::scoped_refptr<EncodedImageBuffer> Create(size_t size);
static rtc::scoped_refptr<EncodedImageBuffer> Create(const uint8_t* data,
size_t size);
@ -146,6 +148,7 @@ class RTC_EXPORT EncodedImage {
// TODO(bugs.webrtc.org/9378): Delete; this method implies realloc, which
// should not be generally supported by the EncodedImageBufferInterface.
RTC_DEPRECATED
void Allocate(size_t capacity);
void SetEncodedData(

View File

@ -521,14 +521,13 @@ TEST(RtpVideoSenderTest, EarlyRetransmits) {
kPayloadType, {});
test.router()->SetActive(true);
constexpr uint8_t kPayload = 'a';
const uint8_t kPayload[1] = {'a'};
EncodedImage encoded_image;
encoded_image.SetTimestamp(1);
encoded_image.capture_time_ms_ = 2;
encoded_image._frameType = VideoFrameType::kVideoFrameKey;
encoded_image.Allocate(1);
encoded_image.data()[0] = kPayload;
encoded_image.set_size(1);
encoded_image.SetEncodedData(
EncodedImageBuffer::Create(kPayload, sizeof(kPayload)));
encoded_image.SetSpatialIndex(0);
CodecSpecificInfo codec_specific;

View File

@ -1136,16 +1136,20 @@ int LibvpxVp8Encoder::GetEncodedPartitions(const VideoFrame& input_image,
encoded_images_[encoder_idx]._frameType = VideoFrameType::kVideoFrameDelta;
CodecSpecificInfo codec_specific;
const vpx_codec_cx_pkt_t* pkt = NULL;
// TODO(nisse): Introduce some buffer cache or buffer pool, to reduce
// allocations and/or copy operations.
auto buffer = EncodedImageBuffer::Create();
while ((pkt = libvpx_->codec_get_cx_data(&encoders_[encoder_idx], &iter)) !=
NULL) {
switch (pkt->kind) {
case VPX_CODEC_CX_FRAME_PKT: {
const size_t size = encoded_images_[encoder_idx].size();
const size_t size = buffer->size();
const size_t new_size = pkt->data.frame.sz + size;
encoded_images_[encoder_idx].Allocate(new_size);
memcpy(&encoded_images_[encoder_idx].data()[size],
pkt->data.frame.buf, pkt->data.frame.sz);
encoded_images_[encoder_idx].set_size(new_size);
buffer->Realloc(new_size);
memcpy(&buffer->data()[size], pkt->data.frame.buf,
pkt->data.frame.sz);
break;
}
default:
@ -1158,6 +1162,7 @@ int LibvpxVp8Encoder::GetEncodedPartitions(const VideoFrame& input_image,
encoded_images_[encoder_idx]._frameType =
VideoFrameType::kVideoFrameKey;
}
encoded_images_[encoder_idx].SetEncodedData(buffer);
encoded_images_[encoder_idx].SetSpatialIndex(stream_idx);
PopulateCodecSpecific(&codec_specific, *pkt, stream_idx, encoder_idx,
input_image.timestamp());

View File

@ -159,14 +159,4 @@ void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) {
}
}
void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) {
size_t old_capacity = capacity();
if (minimumSize > old_capacity) {
// TODO(nisse): EncodedImage::Allocate is implemented as a realloc
// operation, and is deprecated. Refactor to use EncodedImageBuffer::Realloc
// instead.
Allocate(minimumSize);
}
}
} // namespace webrtc

View File

@ -110,16 +110,6 @@ class VCMEncodedFrame : protected EncodedImage {
_codecSpecificInfo = *codec_specific;
}
/**
* Verifies that current allocated buffer size is larger than or equal to the
* input size.
* If the current buffer size is smaller, a new allocation is made and the old
* buffer data
* is copied to the new buffer.
* Buffer size is updated to minimumSize.
*/
void VerifyAndAllocate(size_t minimumSize);
protected:
void Reset();

View File

@ -171,8 +171,7 @@ class TestFrameBuffer2 : public ::testing::Test {
frame->inter_layer_predicted = inter_layer_predicted;
frame->is_last_spatial_layer = last_spatial_layer;
// Add some data to buffer.
frame->VerifyAndAllocate(frame_size_bytes);
frame->set_size(frame_size_bytes);
frame->SetEncodedData(EncodedImageBuffer::Create(frame_size_bytes));
for (size_t r = 0; r < references.size(); ++r)
frame->references[r] = references[r];
return frame;
@ -585,8 +584,7 @@ TEST_F(TestFrameBuffer2, StatsCallback) {
{
std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
frame->VerifyAndAllocate(kFrameSize);
frame->set_size(kFrameSize);
frame->SetEncodedData(EncodedImageBuffer::Create(kFrameSize));
frame->id.picture_id = pid;
frame->id.spatial_layer = 0;
frame->SetTimestamp(ts);