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

Unified Diff: media/remoting/remoting_controller.cc

Issue 2389473002: Media Remoting: Add RemotingController. (Closed)
Patch Set: Created 4 years, 3 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_controller.cc
diff --git a/media/remoting/remoting_controller.cc b/media/remoting/remoting_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31c02898c523e4c3e7778ff1f06b2d16c78ab556
--- /dev/null
+++ b/media/remoting/remoting_controller.cc
@@ -0,0 +1,181 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// 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 "base/bind.h"
+#include "base/logging.h"
+#include "media/base/bind_to_current_loop.h"
+
+namespace media {
+
+RemotingController::RemotingController(mojom::RemoterFactory* remoter_factory)
+ : is_fullscreen_(false),
+ is_sink_available_(false),
+ is_remoting_(false),
+ binding_(this),
+ task_runner_(base::ThreadTaskRunnerHandle::Get()) {
+ remoter_factory->Create(binding_.CreateInterfacePtrAndBind(),
+ mojo::GetProxy(&remoter_));
+}
+
+RemotingController::~RemotingController() {}
+
+void RemotingController::OnSinkAvailable() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ is_sink_available_ = true;
+ Update();
+}
+
+void RemotingController::OnSinkGone() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ is_sink_available_ = false;
+ Update();
+}
+
+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);
+}
+
+void RemotingController::OnStartFailed(mojom::RemotingStartFailReason reason) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ VLOG(1) << "Failed to start remoting:" << reason;
+ is_remoting_ = false;
+}
+
+void RemotingController::OnMessageFromSink(
+ const std::vector<uint8_t>& message) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ // TODO(xjz): Merge with Eric's CL to handle the RPC messages here.
+ NOTIMPLEMENTED();
+}
+
+void RemotingController::OnStopped(mojom::RemotingStopReason reason) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ VLOG(1) << "Remoting stopped: " << reason;
+ is_remoting_ = false;
+}
+
+void RemotingController::OnEnteredFullscreen() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ is_fullscreen_ = true;
+ Update();
+}
+
+void RemotingController::OnExitedFullscreen() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ is_fullscreen_ = false;
+ Update();
+}
+
+void RemotingController::OnSetCdm(CdmContext* cdm_context) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ // TODO(xjz): Not implemented. Will add in up-coming change.
+ NOTIMPLEMENTED();
+}
+
+void RemotingController::SetSwitchRenderCallback(
+ const SwitchRendererCallback& cb) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(!cb.is_null());
+
+ switch_renderer_cb_ = cb;
+}
+
+void RemotingController::OnDecoderConfigChanged(
+ const AudioDecoderConfig& audio_config,
+ const VideoDecoderConfig& video_config) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ audio_decoder_config_ = audio_config;
+ video_decoder_config_ = video_config;
+ Update();
+}
+
+bool RemotingController::isVideoConfigSupported() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (!video_decoder_config_.IsValidConfig())
+ return false;
xhwang 2016/10/01 07:12:15 You should be able to DCHECK in OnDecoderConfigCha
xjz 2016/10/03 22:31:08 Done.
+
+ switch (video_decoder_config_.codec()) {
+ case VideoCodec::kCodecH264:
+ case VideoCodec::kCodecVP8:
xhwang 2016/10/01 07:12:15 Just OCC, VP9 is not supported?
xjz 2016/10/03 22:31:08 For now, assume receiver only supports H264 and VP
+ return true;
+ default:
+ VLOG(2) << "Remoting does not support video codec: "
+ << video_decoder_config_.codec();
+ return false;
+ }
+}
+
+bool RemotingController::isAudioConfigSupported() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (!audio_decoder_config_.IsValidConfig())
+ return false;
xhwang 2016/10/01 07:12:15 ditto
xjz 2016/10/03 22:31:08 Done.
+
+ switch (audio_decoder_config_.codec()) {
+ case AudioCodec::kCodecAAC:
+ case AudioCodec::kCodecMP3:
+ case AudioCodec::kCodecPCM:
+ case AudioCodec::kCodecVorbis:
+ case AudioCodec::kCodecFLAC:
+ case AudioCodec::kCodecAMR_NB:
+ case AudioCodec::kCodecAMR_WB:
+ case AudioCodec::kCodecPCM_MULAW:
+ case AudioCodec::kCodecGSM_MS:
+ case AudioCodec::kCodecPCM_S16BE:
+ case AudioCodec::kCodecPCM_S24BE:
+ case AudioCodec::kCodecOpus:
+ case AudioCodec::kCodecEAC3:
+ case AudioCodec::kCodecPCM_ALAW:
+ case AudioCodec::kCodecALAC:
+ case AudioCodec::kCodecAC3:
+ return true;
+ default:
+ VLOG(2) << "Remoting does not support audio codec: "
+ << audio_decoder_config_.codec();
+ return false;
+ }
+}
+
+void RemotingController::Update() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ // TODO(xjz): The switching logic for encrypted content will be added in a
+ // later CL.
+
+ bool should_be_remoting =
+ is_sink_available_ && is_fullscreen_ && isVideoConfigSupported() &&
+ isAudioConfigSupported() && !video_decoder_config_.is_encrypted() &&
+ !switch_renderer_cb_.is_null();
+ if (is_remoting_ == should_be_remoting)
+ return;
+
+ // Switch between local and remoting.
+ is_remoting_ = should_be_remoting;
+ if (is_remoting_) {
+ remoter_->Start();
+ } else {
+ switch_renderer_cb_.Run();
+ remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK);
+ }
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698