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:
@ -114,6 +114,7 @@ rtc_source_set("encoded_image") {
|
|||||||
"..:scoped_refptr",
|
"..:scoped_refptr",
|
||||||
"../..:webrtc_common",
|
"../..:webrtc_common",
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
|
"../../rtc_base:deprecation",
|
||||||
"../../rtc_base:rtc_base_approved",
|
"../../rtc_base:rtc_base_approved",
|
||||||
"../../rtc_base/system:rtc_export",
|
"../../rtc_base/system:rtc_export",
|
||||||
"//third_party/abseil-cpp/absl/types:optional",
|
"//third_party/abseil-cpp/absl/types:optional",
|
||||||
|
@ -28,6 +28,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/deprecation.h"
|
||||||
#include "rtc_base/ref_count.h"
|
#include "rtc_base/ref_count.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ class EncodedImageBufferInterface : public rtc::RefCountInterface {
|
|||||||
// Basic implementation of EncodedImageBufferInterface.
|
// Basic implementation of EncodedImageBufferInterface.
|
||||||
class EncodedImageBuffer : public EncodedImageBufferInterface {
|
class EncodedImageBuffer : public EncodedImageBufferInterface {
|
||||||
public:
|
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(size_t size);
|
||||||
static rtc::scoped_refptr<EncodedImageBuffer> Create(const uint8_t* data,
|
static rtc::scoped_refptr<EncodedImageBuffer> Create(const uint8_t* data,
|
||||||
size_t size);
|
size_t size);
|
||||||
@ -146,6 +148,7 @@ class RTC_EXPORT EncodedImage {
|
|||||||
|
|
||||||
// TODO(bugs.webrtc.org/9378): Delete; this method implies realloc, which
|
// TODO(bugs.webrtc.org/9378): Delete; this method implies realloc, which
|
||||||
// should not be generally supported by the EncodedImageBufferInterface.
|
// should not be generally supported by the EncodedImageBufferInterface.
|
||||||
|
RTC_DEPRECATED
|
||||||
void Allocate(size_t capacity);
|
void Allocate(size_t capacity);
|
||||||
|
|
||||||
void SetEncodedData(
|
void SetEncodedData(
|
||||||
|
@ -521,14 +521,13 @@ TEST(RtpVideoSenderTest, EarlyRetransmits) {
|
|||||||
kPayloadType, {});
|
kPayloadType, {});
|
||||||
test.router()->SetActive(true);
|
test.router()->SetActive(true);
|
||||||
|
|
||||||
constexpr uint8_t kPayload = 'a';
|
const uint8_t kPayload[1] = {'a'};
|
||||||
EncodedImage encoded_image;
|
EncodedImage encoded_image;
|
||||||
encoded_image.SetTimestamp(1);
|
encoded_image.SetTimestamp(1);
|
||||||
encoded_image.capture_time_ms_ = 2;
|
encoded_image.capture_time_ms_ = 2;
|
||||||
encoded_image._frameType = VideoFrameType::kVideoFrameKey;
|
encoded_image._frameType = VideoFrameType::kVideoFrameKey;
|
||||||
encoded_image.Allocate(1);
|
encoded_image.SetEncodedData(
|
||||||
encoded_image.data()[0] = kPayload;
|
EncodedImageBuffer::Create(kPayload, sizeof(kPayload)));
|
||||||
encoded_image.set_size(1);
|
|
||||||
encoded_image.SetSpatialIndex(0);
|
encoded_image.SetSpatialIndex(0);
|
||||||
|
|
||||||
CodecSpecificInfo codec_specific;
|
CodecSpecificInfo codec_specific;
|
||||||
|
@ -1136,16 +1136,20 @@ int LibvpxVp8Encoder::GetEncodedPartitions(const VideoFrame& input_image,
|
|||||||
encoded_images_[encoder_idx]._frameType = VideoFrameType::kVideoFrameDelta;
|
encoded_images_[encoder_idx]._frameType = VideoFrameType::kVideoFrameDelta;
|
||||||
CodecSpecificInfo codec_specific;
|
CodecSpecificInfo codec_specific;
|
||||||
const vpx_codec_cx_pkt_t* pkt = NULL;
|
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)) !=
|
while ((pkt = libvpx_->codec_get_cx_data(&encoders_[encoder_idx], &iter)) !=
|
||||||
NULL) {
|
NULL) {
|
||||||
switch (pkt->kind) {
|
switch (pkt->kind) {
|
||||||
case VPX_CODEC_CX_FRAME_PKT: {
|
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;
|
const size_t new_size = pkt->data.frame.sz + size;
|
||||||
encoded_images_[encoder_idx].Allocate(new_size);
|
buffer->Realloc(new_size);
|
||||||
memcpy(&encoded_images_[encoder_idx].data()[size],
|
memcpy(&buffer->data()[size], pkt->data.frame.buf,
|
||||||
pkt->data.frame.buf, pkt->data.frame.sz);
|
pkt->data.frame.sz);
|
||||||
encoded_images_[encoder_idx].set_size(new_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -1158,6 +1162,7 @@ int LibvpxVp8Encoder::GetEncodedPartitions(const VideoFrame& input_image,
|
|||||||
encoded_images_[encoder_idx]._frameType =
|
encoded_images_[encoder_idx]._frameType =
|
||||||
VideoFrameType::kVideoFrameKey;
|
VideoFrameType::kVideoFrameKey;
|
||||||
}
|
}
|
||||||
|
encoded_images_[encoder_idx].SetEncodedData(buffer);
|
||||||
encoded_images_[encoder_idx].SetSpatialIndex(stream_idx);
|
encoded_images_[encoder_idx].SetSpatialIndex(stream_idx);
|
||||||
PopulateCodecSpecific(&codec_specific, *pkt, stream_idx, encoder_idx,
|
PopulateCodecSpecific(&codec_specific, *pkt, stream_idx, encoder_idx,
|
||||||
input_image.timestamp());
|
input_image.timestamp());
|
||||||
|
@ -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
|
} // namespace webrtc
|
||||||
|
@ -110,16 +110,6 @@ class VCMEncodedFrame : protected EncodedImage {
|
|||||||
_codecSpecificInfo = *codec_specific;
|
_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:
|
protected:
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
@ -171,8 +171,7 @@ class TestFrameBuffer2 : public ::testing::Test {
|
|||||||
frame->inter_layer_predicted = inter_layer_predicted;
|
frame->inter_layer_predicted = inter_layer_predicted;
|
||||||
frame->is_last_spatial_layer = last_spatial_layer;
|
frame->is_last_spatial_layer = last_spatial_layer;
|
||||||
// Add some data to buffer.
|
// Add some data to buffer.
|
||||||
frame->VerifyAndAllocate(frame_size_bytes);
|
frame->SetEncodedData(EncodedImageBuffer::Create(frame_size_bytes));
|
||||||
frame->set_size(frame_size_bytes);
|
|
||||||
for (size_t r = 0; r < references.size(); ++r)
|
for (size_t r = 0; r < references.size(); ++r)
|
||||||
frame->references[r] = references[r];
|
frame->references[r] = references[r];
|
||||||
return frame;
|
return frame;
|
||||||
@ -585,8 +584,7 @@ TEST_F(TestFrameBuffer2, StatsCallback) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
|
std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
|
||||||
frame->VerifyAndAllocate(kFrameSize);
|
frame->SetEncodedData(EncodedImageBuffer::Create(kFrameSize));
|
||||||
frame->set_size(kFrameSize);
|
|
||||||
frame->id.picture_id = pid;
|
frame->id.picture_id = pid;
|
||||||
frame->id.spatial_layer = 0;
|
frame->id.spatial_layer = 0;
|
||||||
frame->SetTimestamp(ts);
|
frame->SetTimestamp(ts);
|
||||||
|
Reference in New Issue
Block a user