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

Unified Diff: media/remoting/remoting_renderer_controller.cc

Issue 2457563002: Media Remoting: Add remoting control logic for encrypted contents. (Closed)
Patch Set: Rebase Only. Created 4 years, 2 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
Index: media/remoting/remoting_renderer_controller.cc
diff --git a/media/remoting/remoting_controller.cc b/media/remoting/remoting_renderer_controller.cc
similarity index 35%
rename from media/remoting/remoting_controller.cc
rename to media/remoting/remoting_renderer_controller.cc
index dd38d70ff78f4760dd6b49a91de4aa2ca8c67d67..4ff655e1ce0dad83c0477fdef301145fc8af8d0c 100644
--- a/media/remoting/remoting_controller.cc
+++ b/media/remoting/remoting_renderer_controller.cc
@@ -2,110 +2,109 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/remoting/remoting_controller.h"
+#include "media/remoting/remoting_renderer_controller.h"
#include "base/bind.h"
#include "base/logging.h"
-#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_checker.h"
+#include "media/remoting/remoting_cdm.h"
namespace media {
-RemotingController::RemotingController(
- mojom::RemotingSourceRequest source_request,
- mojom::RemoterPtr remoter)
- : binding_(this, std::move(source_request)),
- remoter_(std::move(remoter)),
- task_runner_(base::ThreadTaskRunnerHandle::Get()),
- weak_factory_(this) {}
-
-RemotingController::~RemotingController() {}
-
-void RemotingController::OnSinkAvailable() {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- is_sink_available_ = true;
- UpdateAndMaybeSwitch();
-}
-
-void RemotingController::OnSinkGone() {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- is_sink_available_ = false;
- UpdateAndMaybeSwitch();
-}
-
-void RemotingController::OnStarted() {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- VLOG(1) << "Remoting started successively.";
- if (is_remoting_)
- switch_renderer_cb_.Run();
- else
- remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK);
+RemotingRendererController::RemotingRendererController(
+ scoped_refptr<RemotingSourceImpl> remoting_source)
+ : remoting_source_(remoting_source), weak_factory_(this) {
+ remoting_source_->AddClient(this);
}
-void RemotingController::OnStartFailed(mojom::RemotingStartFailReason reason) {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- VLOG(1) << "Failed to start remoting:" << reason;
- is_remoting_ = false;
+RemotingRendererController::~RemotingRendererController() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ remoting_source_->RemoveClient(this);
}
-void RemotingController::OnMessageFromSink(
- const std::vector<uint8_t>& message) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::OnStarted(bool success) {
+ DCHECK(thread_checker_.CalledOnValidThread());
- // TODO(xjz): Merge with Eric's CL to handle the RPC messages here.
- NOTIMPLEMENTED();
+ DCHECK(!switch_renderer_cb_.is_null());
xjz 2016/10/27 22:45:58 Done.
+ if (success) {
+ VLOG(1) << "Remoting started successively.";
+ if (remote_rendering_started_)
+ switch_renderer_cb_.Run();
+ else
+ remoting_source_->StopRemoting(this);
+ } else {
+ VLOG(1) << "Failed to start remoting.";
+ remote_rendering_started_ = false;
+ }
}
-void RemotingController::OnStopped(mojom::RemotingStopReason reason) {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- VLOG(1) << "Remoting stopped: " << reason;
- is_remoting_ = false;
+void RemotingRendererController::OnSessionStateChanged() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ VLOG(1) << "OnSessionStateChanged: " << remoting_source_->state();
+ bool session_could_remote = session_can_remote_;
+ switch (remoting_source_->state()) {
+ case SESSION_CAN_START:
+ case SESSION_STARTING:
+ case SESSION_STARTED:
+ session_can_remote_ = true;
+ break;
+ case SESSION_STOPPING:
+ case SESSION_UNAVAILABLE:
+ case SESSION_PERMANENTLY_STOPPED:
+ session_can_remote_ = false;
+ break;
+ }
+ if (session_can_remote_ != session_could_remote)
+ UpdateAndMaybeSwitch();
}
-void RemotingController::OnEnteredFullscreen() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::OnEnteredFullscreen() {
+ DCHECK(thread_checker_.CalledOnValidThread());
is_fullscreen_ = true;
UpdateAndMaybeSwitch();
}
-void RemotingController::OnExitedFullscreen() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::OnExitedFullscreen() {
+ DCHECK(thread_checker_.CalledOnValidThread());
is_fullscreen_ = false;
UpdateAndMaybeSwitch();
}
-void RemotingController::OnSetCdm(CdmContext* cdm_context) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ auto* cdm = RemotingCdm::From(cdm_context);
+ if (!cdm)
+ return;
- // TODO(xjz): Not implemented. Will add in up-coming change.
- NOTIMPLEMENTED();
+ remoting_source_->RemoveClient(this);
+ remoting_source_ = cdm->GetRemotingSource();
+ remoting_source_->AddClient(this); // Calls OnSessionStateChanged().
+ UpdateAndMaybeSwitch();
}
-void RemotingController::SetSwitchRendererCallback(
- const SwitchRendererCallback& cb) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::SetSwitchRendererCallback(
+ const base::Closure& cb) {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!cb.is_null());
switch_renderer_cb_ = cb;
+ UpdateAndMaybeSwitch();
}
-void RemotingController::OnMetadataChanged(const PipelineMetadata& metadata) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::OnMetadataChanged(
+ const PipelineMetadata& metadata) {
+ DCHECK(thread_checker_.CalledOnValidThread());
- has_video_ = metadata.has_video;
- has_audio_ = metadata.has_audio;
- if (!has_video_ && !has_audio_)
- return;
+ has_video_ =
+ metadata.has_video && metadata.video_decoder_config.IsValidConfig();
+ has_audio_ =
+ metadata.has_audio && metadata.audio_decoder_config.IsValidConfig();
- // On Android, when using the MediaPlayerRenderer, |has_video_| and
- // |has_audio_| will be true, but the respective configs will be empty.
- // We cannot make any assumptions on the validity of configs.
+ is_encrypted_ = false;
if (has_video_) {
video_decoder_config_ = metadata.video_decoder_config;
is_encrypted_ |= video_decoder_config_.is_encrypted();
@@ -117,8 +116,8 @@ void RemotingController::OnMetadataChanged(const PipelineMetadata& metadata) {
UpdateAndMaybeSwitch();
}
-bool RemotingController::IsVideoCodecSupported() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+bool RemotingRendererController::IsVideoCodecSupported() {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(has_video_);
switch (video_decoder_config_.codec()) {
@@ -132,8 +131,8 @@ bool RemotingController::IsVideoCodecSupported() {
}
}
-bool RemotingController::IsAudioCodecSupported() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+bool RemotingRendererController::IsAudioCodecSupported() {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(has_audio_);
switch (audio_decoder_config_.codec()) {
@@ -161,50 +160,71 @@ bool RemotingController::IsAudioCodecSupported() {
}
}
-bool RemotingController::ShouldBeRemoting() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+bool RemotingRendererController::ShouldBeRemoting() {
+ DCHECK(thread_checker_.CalledOnValidThread());
- // TODO(xjz): The control logic for EME will be added in a later CL.
- if (is_encrypted_)
+ if (!session_can_remote_)
return false;
-
- if (!is_sink_available_)
+ if (switch_renderer_cb_.is_null())
return false;
- if (!is_fullscreen_)
+ if (!has_audio_ && !has_video_)
return false;
if (has_video_ && !IsVideoCodecSupported())
return false;
if (has_audio_ && !IsAudioCodecSupported())
return false;
- return true;
+
+ // Explicitly ignoring |is_fullscreen_| since all EME content should trigger
+ // the start of remoting immediately, and not later after switching into
+ // fullscreen. This is required by current technical limitations.
+ if (is_encrypted_)
+ return remoting_source_->state() == RemotingSessionState::SESSION_STARTED;
+
+ return is_fullscreen_;
}
-void RemotingController::UpdateAndMaybeSwitch() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+void RemotingRendererController::UpdateAndMaybeSwitch() {
+ DCHECK(thread_checker_.CalledOnValidThread());
- // TODO(xjz): The switching logic for encrypted content will be added in a
- // later CL.
+ bool should_be_remoting = ShouldBeRemoting();
- // Demuxer is not initialized yet.
- if (!has_audio_ && !has_video_)
+ // When OnSetCdm() is called, if the session that creates CDM remotely was
+ // permanently terminated, we need to render the failure page.
+ if (!remote_rendering_started_ && IsTerminated() &&
xjz 2016/10/27 22:45:58 As discussed, modified the logic so that we can sw
+ !session_permanently_terminated_) {
+ session_permanently_terminated_ = IsTerminated();
+ DCHECK(!switch_renderer_cb_.is_null());
+ switch_renderer_cb_.Run();
return;
+ }
- DCHECK(!switch_renderer_cb_.is_null());
-
- bool should_be_remoting = ShouldBeRemoting();
- if (is_remoting_ == should_be_remoting)
+ if (remote_rendering_started_ == should_be_remoting)
return;
- // Switch between local and remoting.
- is_remoting_ = should_be_remoting;
- if (is_remoting_) {
- // |swithc_renderer_cb_.Run()| will be called after remoting is started
+ // Switch between local renderer and remoting renderer.
+ remote_rendering_started_ = should_be_remoting;
+
+ if (remote_rendering_started_) {
+ // |switch_renderer_cb_.Run()| will be called after remoting is started
// successfully.
- remoter_->Start();
+ remoting_source_->StartRemoting(this);
} else {
switch_renderer_cb_.Run();
xjz 2016/10/27 22:45:58 As discussed, modified the logic and will let Remo
miu 2016/10/29 02:22:16 Seems now like we were discussing two different th
- remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK);
+ remoting_source_->StopRemoting(this);
}
}
+bool RemotingRendererController::IsRenderingRemotely() const {
xjz 2016/10/27 22:45:58 Done.
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return remote_rendering_started_;
+}
+
+bool RemotingRendererController::IsTerminated() const {
xjz 2016/10/27 22:45:58 Done.
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return remoting_source_->state() ==
+ RemotingSessionState::SESSION_PERMANENTLY_STOPPED;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698