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}
diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
index d4f18e0..ee5fd43 100644
--- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
+++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
@@ -1136,16 +1136,20 @@
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 @@
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());
diff --git a/modules/video_coding/encoded_frame.cc b/modules/video_coding/encoded_frame.cc
index bbbd9bc..1e9e374 100644
--- a/modules/video_coding/encoded_frame.cc
+++ b/modules/video_coding/encoded_frame.cc
@@ -159,14 +159,4 @@
}
}
-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
diff --git a/modules/video_coding/encoded_frame.h b/modules/video_coding/encoded_frame.h
index 27ad107..b29ff63 100644
--- a/modules/video_coding/encoded_frame.h
+++ b/modules/video_coding/encoded_frame.h
@@ -110,16 +110,6 @@
_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();
diff --git a/modules/video_coding/frame_buffer2_unittest.cc b/modules/video_coding/frame_buffer2_unittest.cc
index d96960e..09300fb 100644
--- a/modules/video_coding/frame_buffer2_unittest.cc
+++ b/modules/video_coding/frame_buffer2_unittest.cc
@@ -171,8 +171,7 @@
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 @@
{
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);