Commit 585ed401 authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

media: StreamProvider/MediaStream using OnceClosure for init_cb.

The "initialization done" callbacks for both
media::remoting::StreamProvider and media::remoting::MediaStream
both used implicitly repeating closures, but only ever ran the
callbacks once. Switching to base::OnceClosure.

Bug: 1007810
Change-Id: I9431a6cca138e3e095b98d625bc94fcf97f7ce19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881985Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/master@{#710068}
parent 9cabda14
......@@ -106,7 +106,8 @@ void Receiver::Initialize(std::unique_ptr<pb::RpcMessage> message) {
stream_provider_->Initialize(
message->renderer_initialize_rpc().audio_demuxer_handle(),
message->renderer_initialize_rpc().video_demuxer_handle(),
base::Bind(&Receiver::OnStreamInitialized, weak_factory_.GetWeakPtr()));
base::BindOnce(&Receiver::OnStreamInitialized,
weak_factory_.GetWeakPtr()));
}
void Receiver::OnStreamInitialized() {
......
......@@ -42,7 +42,7 @@ class MediaStream final : public DemuxerStream {
Liveness liveness() const override;
bool SupportsConfigChanges() override;
void Initialize(const base::Closure& init_done_cb);
void Initialize(base::OnceClosure init_done_cb);
void FlushUntil(int count);
void AppendBuffer(scoped_refptr<DecoderBuffer> buffer);
......@@ -73,9 +73,9 @@ class MediaStream final : public DemuxerStream {
const int remote_handle_;
const int rpc_handle_;
// Set when Initialize() is called, and will be run only once after
// initialization is done.
base::Closure init_done_callback_;
// Set when Initialize() is called, and will be run after initialization is
// done.
base::OnceClosure init_done_callback_;
// The read until count in the last ReadUntil RPC message.
int last_read_until_count_ = 0;
......@@ -128,13 +128,13 @@ MediaStream::~MediaStream() {
rpc_broker_->UnregisterMessageReceiverCallback(rpc_handle_);
}
void MediaStream::Initialize(const base::Closure& init_done_cb) {
void MediaStream::Initialize(base::OnceClosure init_done_cb) {
DCHECK(init_done_cb);
if (!init_done_callback_.is_null()) {
OnError("Duplicate initialization");
return;
}
init_done_callback_ = init_done_cb;
init_done_callback_ = std::move(init_done_cb);
DVLOG(3) << __func__ << "Issues RpcMessage::RPC_DS_INITIALIZE with "
<< "remote_handle=" << remote_handle_
......@@ -398,7 +398,7 @@ StreamProvider::~StreamProvider() = default;
void StreamProvider::Initialize(int remote_audio_handle,
int remote_video_handle,
const base::Closure& callback) {
base::OnceClosure callback) {
DVLOG(3) << __func__ << ": remote_audio_handle=" << remote_audio_handle
<< " remote_video_handle=" << remote_video_handle;
if (!init_done_callback_.is_null()) {
......@@ -411,13 +411,13 @@ void StreamProvider::Initialize(int remote_audio_handle,
return;
}
init_done_callback_ = callback;
init_done_callback_ = std::move(callback);
if (remote_audio_handle != RpcBroker::kInvalidHandle) {
audio_stream_.reset(new MediaStream(
rpc_broker_, DemuxerStream::AUDIO, remote_audio_handle,
base::BindOnce(&StreamProvider::OnError, weak_factory_.GetWeakPtr(),
"Media stream error")));
audio_stream_->Initialize(base::Bind(
audio_stream_->Initialize(base::BindOnce(
&StreamProvider::AudioStreamInitialized, weak_factory_.GetWeakPtr()));
}
if (remote_video_handle != RpcBroker::kInvalidHandle) {
......@@ -425,7 +425,7 @@ void StreamProvider::Initialize(int remote_audio_handle,
rpc_broker_, DemuxerStream::VIDEO, remote_video_handle,
base::BindOnce(&StreamProvider::OnError, weak_factory_.GetWeakPtr(),
"Media stream error")));
video_stream_->Initialize(base::Bind(
video_stream_->Initialize(base::BindOnce(
&StreamProvider::VideoStreamInitialized, weak_factory_.GetWeakPtr()));
}
}
......
......@@ -29,7 +29,7 @@ class StreamProvider final : public MediaResource {
void Initialize(int remote_audio_handle,
int remote_video_handle,
const base::Closure& callback);
base::OnceClosure callback);
void AppendBuffer(DemuxerStream::Type type,
scoped_refptr<DecoderBuffer> buffer);
void FlushUntil(DemuxerStream::Type type, int count);
......@@ -48,9 +48,9 @@ class StreamProvider final : public MediaResource {
bool audio_stream_initialized_ = false;
bool video_stream_initialized_ = false;
// Set when Initialize() is called, and will run only once when both video
// and audio streams are initialized or error occurs.
base::Closure init_done_callback_;
// Set when Initialize() is called, and will run when both video and audio
// streams are initialized or error occurs.
base::OnceClosure init_done_callback_;
// Run when first error occurs;
base::OnceClosure error_callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment