diff --git a/api/video/encoded_image.cc b/api/video/encoded_image.cc index d2cc751317..55970fcd00 100644 --- a/api/video/encoded_image.cc +++ b/api/video/encoded_image.cc @@ -77,7 +77,7 @@ void EncodedImage::Retain() { } void EncodedImage::Allocate(size_t capacity) { - if (encoded_data_) { + if (encoded_data_ && encoded_data_->HasOneRef()) { encoded_data_->Realloc(capacity); } else { encoded_data_ = EncodedImageBuffer::Create(capacity); diff --git a/api/video/encoded_image.h b/api/video/encoded_image.h index 9aa5046a3e..a980ef7ee1 100644 --- a/api/video/encoded_image.h +++ b/api/video/encoded_image.h @@ -47,6 +47,9 @@ class EncodedImageBufferInterface : public rtc::RefCountInterface { // EncodedImage::Allocate. Implemented properly only by the below concrete // class virtual void Realloc(size_t size) { RTC_NOTREACHED(); } + // Will be implemented by RefCountedObject, which also implements + // |rtc::RefCountInterface|. + virtual bool HasOneRef() const = 0; }; // Basic implementation of EncodedImageBufferInterface.