Reland "Update VP9EncoderImpl to use EncodedImage::Allocate"

This is a reland of e12778cb3a7c35b4d3b9d25104841dccd67dc59b
Performance regressions should be addressed by
cl https://webrtc-review.googlesource.com/c/123442

Original change's description:
> Update VP9EncoderImpl to use EncodedImage::Allocate
>
> Bug: webrtc:9378
> Change-Id: I009138b4dc50c4ceb8f94fee6a958bbfa4d7e326
> Reviewed-on: https://webrtc-review.googlesource.com/c/121771
> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> Reviewed-by: Philip Eliasson <philipel@webrtc.org>
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#26593}

Bug: webrtc:9378
Change-Id: I37a28574741fd50d03a80a01a8f9fe7596e31d6f
Reviewed-on: https://webrtc-review.googlesource.com/c/123484
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26768}
This commit is contained in:
Niels Möller
2019-02-07 18:52:50 +01:00
committed by Commit Bot
parent 109b5fb5f5
commit dd1cc982e4

View File

@ -185,10 +185,7 @@ VP9EncoderImpl::~VP9EncoderImpl() {
int VP9EncoderImpl::Release() {
int ret_val = WEBRTC_VIDEO_CODEC_OK;
if (encoded_image_.buffer() != nullptr) {
delete[] encoded_image_.buffer();
encoded_image_.set_buffer(nullptr, 0);
}
encoded_image_.Allocate(0);
if (encoder_ != nullptr) {
if (inited_) {
if (vpx_codec_destroy(encoder_)) {
@ -390,12 +387,9 @@ int VP9EncoderImpl::InitEncode(const VideoCodec* inst,
is_svc_ = (num_spatial_layers_ > 1 || num_temporal_layers_ > 1);
// Allocate memory for encoded image
if (encoded_image_.data() != nullptr) {
delete[] encoded_image_.data();
}
size_t frame_capacity =
CalcBufferSize(VideoType::kI420, codec_.width, codec_.height);
encoded_image_.set_buffer(new uint8_t[frame_capacity], frame_capacity);
encoded_image_.Allocate(frame_capacity);
encoded_image_._completeFrame = true;
// Populate encoder configuration with default values.
if (vpx_codec_enc_config_default(vpx_codec_vp9_cx(), config_, 0)) {
@ -1267,9 +1261,7 @@ int VP9EncoderImpl::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) {
}
if (pkt->data.frame.sz > encoded_image_.capacity()) {
delete[] encoded_image_.buffer();
encoded_image_.set_buffer(new uint8_t[pkt->data.frame.sz],
pkt->data.frame.sz);
encoded_image_.Allocate(pkt->data.frame.sz);
}
memcpy(encoded_image_.data(), pkt->data.frame.buf, pkt->data.frame.sz);
encoded_image_.set_size(pkt->data.frame.sz);