Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: webrtc/media/engine/simulcast_encoder_adapter.cc

Issue 3007643002: Clean up ownership of webrtc::VideoEncoder (Closed)
Patch Set: Fix Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/engine/simulcast_encoder_adapter.h ('k') | webrtc/media/engine/webrtcvideoengine.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/media/engine/simulcast_encoder_adapter.cc
diff --git a/webrtc/media/engine/simulcast_encoder_adapter.cc b/webrtc/media/engine/simulcast_encoder_adapter.cc
index c33dfdd7703a373e1ac48f4a08cdcac38e2d51be..af84b8526e06e4987738001442e9837ac19e6974 100644
--- a/webrtc/media/engine/simulcast_encoder_adapter.cc
+++ b/webrtc/media/engine/simulcast_encoder_adapter.cc
@@ -16,6 +16,7 @@
#include "libyuv/scale.h" // NOLINT
#include "webrtc/api/video/i420_buffer.h"
+#include "webrtc/media/engine/scopedvideoencoder.h"
#include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h"
#include "webrtc/modules/video_coding/codecs/vp8/simulcast_rate_allocator.h"
#include "webrtc/rtc_base/checks.h"
@@ -148,14 +149,15 @@ int SimulcastEncoderAdapter::Release() {
RTC_DCHECK_CALLED_SEQUENTIALLY(&encoder_queue_);
while (!streaminfos_.empty()) {
- VideoEncoder* encoder = streaminfos_.back().encoder;
+ std::unique_ptr<VideoEncoder> encoder =
+ std::move(streaminfos_.back().encoder);
encoder->Release();
// Even though it seems very unlikely, there are no guarantees that the
// encoder will not call back after being Release()'d. Therefore, we disable
// the callbacks here.
encoder->RegisterEncodeCompleteCallback(nullptr);
streaminfos_.pop_back(); // Deletes callback adapter.
- stored_encoders_.push(encoder);
+ stored_encoders_.push(std::move(encoder));
}
// It's legal to move the encoder to another queue now.
@@ -232,27 +234,28 @@ int SimulcastEncoderAdapter::InitEncode(const VideoCodec* inst,
// If an existing encoder instance exists, reuse it.
// TODO(brandtr): Set initial RTP state (e.g., picture_id/tl0_pic_idx) here,
// when we start storing that state outside the encoder wrappers.
- VideoEncoder* encoder;
+ std::unique_ptr<VideoEncoder> encoder;
if (!stored_encoders_.empty()) {
- encoder = stored_encoders_.top();
+ encoder = std::move(stored_encoders_.top());
stored_encoders_.pop();
} else {
- encoder = factory_->CreateVideoEncoder(cricket::VideoCodec("VP8"));
+ encoder = CreateScopedVideoEncoder(factory_, cricket::VideoCodec("VP8"));
}
ret = encoder->InitEncode(&stream_codec, number_of_cores, max_payload_size);
if (ret < 0) {
// Explicitly destroy the current encoder; because we haven't registered a
// StreamInfo for it yet, Release won't do anything about it.
- factory_->DestroyVideoEncoder(encoder);
+ encoder.reset();
Release();
return ret;
}
std::unique_ptr<EncodedImageCallback> callback(
new AdapterEncodedImageCallback(this, i));
encoder->RegisterEncodeCompleteCallback(callback.get());
- streaminfos_.emplace_back(encoder, std::move(callback), stream_codec.width,
- stream_codec.height, start_bitrate_kbps > 0);
+ streaminfos_.emplace_back(std::move(encoder), std::move(callback),
+ stream_codec.width, stream_codec.height,
+ start_bitrate_kbps > 0);
if (i != 0) {
implementation_name += ", ";
@@ -500,8 +503,6 @@ bool SimulcastEncoderAdapter::Initialized() const {
void SimulcastEncoderAdapter::DestroyStoredEncoders() {
while (!stored_encoders_.empty()) {
- VideoEncoder* encoder = stored_encoders_.top();
- factory_->DestroyVideoEncoder(encoder);
stored_encoders_.pop();
}
}
« no previous file with comments | « webrtc/media/engine/simulcast_encoder_adapter.h ('k') | webrtc/media/engine/webrtcvideoengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698