mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 08:37:54 +01:00
Refactor legacy FrameBuffer to use EncodedImageBuffer::Realloc
Preparation for deleting VCMEncodedFrame::VerifyAndAllocate and EncodedImage::Allocate. Bug: webrtc:9378 Change-Id: If7c16061962bbd58c3e7d5720189854e00a3d7bf Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/154570 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29339}
This commit is contained in:
parent
fbf75a7891
commit
2449d7aa78
4 changed files with 18 additions and 3 deletions
|
@ -52,6 +52,11 @@ size_t EncodedImageBuffer::size() const {
|
|||
}
|
||||
|
||||
void EncodedImageBuffer::Realloc(size_t size) {
|
||||
// Calling realloc with size == 0 is equivalent to free, and returns nullptr.
|
||||
// Which is confusing on systems where malloc(0) doesn't return a nullptr.
|
||||
// More specifically, it breaks expectations of
|
||||
// VCMSessionInfo::UpdateDataPointers.
|
||||
RTC_DCHECK(size > 0);
|
||||
buffer_ = static_cast<uint8_t*>(realloc(buffer_, size));
|
||||
size_ = size;
|
||||
}
|
||||
|
|
|
@ -266,7 +266,6 @@ void VP9EncoderImpl::SetFecControllerOverride(
|
|||
int VP9EncoderImpl::Release() {
|
||||
int ret_val = WEBRTC_VIDEO_CODEC_OK;
|
||||
|
||||
encoded_image_.Allocate(0);
|
||||
if (encoder_ != nullptr) {
|
||||
if (inited_) {
|
||||
if (vpx_codec_destroy(encoder_)) {
|
||||
|
|
|
@ -101,7 +101,7 @@ VCMFrameBufferEnum VCMFrameBuffer::InsertPacket(const VCMPacket& packet,
|
|||
uint32_t requiredSizeBytes =
|
||||
size() + packet.sizeBytes +
|
||||
(packet.insertStartCode ? kH264StartCodeLengthBytes : 0);
|
||||
if (requiredSizeBytes >= capacity()) {
|
||||
if (requiredSizeBytes > capacity()) {
|
||||
const uint8_t* prevBuffer = data();
|
||||
const uint32_t increments =
|
||||
requiredSizeBytes / kBufferIncStepSizeBytes +
|
||||
|
@ -112,7 +112,15 @@ VCMFrameBufferEnum VCMFrameBuffer::InsertPacket(const VCMPacket& packet,
|
|||
"big.";
|
||||
return kSizeError;
|
||||
}
|
||||
VerifyAndAllocate(newSize);
|
||||
if (data() == nullptr) {
|
||||
encoded_image_buffer_ = EncodedImageBuffer::Create(newSize);
|
||||
SetEncodedData(encoded_image_buffer_);
|
||||
set_size(0);
|
||||
} else {
|
||||
RTC_CHECK(encoded_image_buffer_ != nullptr);
|
||||
RTC_DCHECK_EQ(encoded_image_buffer_->data(), data());
|
||||
encoded_image_buffer_->Realloc(newSize);
|
||||
}
|
||||
_sessionInfo.UpdateDataPointers(prevBuffer, data());
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,9 @@ class VCMFrameBuffer : public VCMEncodedFrame {
|
|||
void SetState(VCMFrameBufferStateEnum state); // Set state of frame
|
||||
|
||||
VCMFrameBufferStateEnum _state; // Current state of the frame
|
||||
// Set with SetEncodedData, but keep pointer to the concrete class here, to
|
||||
// enable reallocation and mutation.
|
||||
rtc::scoped_refptr<EncodedImageBuffer> encoded_image_buffer_;
|
||||
VCMSessionInfo _sessionInfo;
|
||||
uint16_t _nackCount;
|
||||
int64_t _latestPacketTimeMs;
|
||||
|
|
Loading…
Reference in a new issue