[Chromecast] Remove |audio_device_id_| from CastRenderer

1. The |audio_device_id| in CastRenderer is always
::media::AudioDeviceDescription::kDefaultDeviceId, so it's
not needed.

2. Add CastMojoMediaClient::CreateCastRenderer() method, so when
CastRendererFactory in the upstream is implemented and used, the
CastRenderer can be created and used without breaking chromecast.

No behavior change is expected.

Bug: crbug.com/925450
Test: 1. Manually Cast. 2. Internal CQ.

Change-Id: Ia2234f721ba6b636ea87a67198894aeeba173bde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626389
Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
Commit-Queue: Guohui Deng <guohuideng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663282}
diff --git a/chromecast/media/service/cast_mojo_media_client.cc b/chromecast/media/service/cast_mojo_media_client.cc
index 65cd3f1..ee25146 100644
--- a/chromecast/media/service/cast_mojo_media_client.cc
+++ b/chromecast/media/service/cast_mojo_media_client.cc
@@ -37,13 +37,31 @@
   connector_ = connector;
 }
 
+#if BUILDFLAG(ENABLE_CAST_RENDERER)
+std::unique_ptr<::media::Renderer> CastMojoMediaClient::CreateCastRenderer(
+    service_manager::mojom::InterfaceProvider* host_interfaces,
+    scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+    ::media::MediaLog* /* media_log */,
+    const base::UnguessableToken& /* overlay_plane_id */) {
+  // TODO(crbug.com/925450): 1) Make a VideoGeometrySetter within
+  // CastMojoMediaClient. 2) Before return the created CastRenderer, pass the
+  // CastRenderer and the |overlay_plane_id| to VideoGeometrySetter so it can
+  // maintain a map between the CastRenderers and their associated
+  // |overlay_plane_id|s.
+  return std::make_unique<CastRenderer>(
+      backend_factory_, task_runner, video_mode_switcher_,
+      video_resolution_policy_, media_resource_tracker_, connector_,
+      host_interfaces);
+}
+#endif
+
 std::unique_ptr<::media::Renderer> CastMojoMediaClient::CreateRenderer(
     service_manager::mojom::InterfaceProvider* host_interfaces,
     scoped_refptr<base::SingleThreadTaskRunner> task_runner,
     ::media::MediaLog* /* media_log */,
     const std::string& audio_device_id) {
   return std::make_unique<CastRenderer>(
-      backend_factory_, task_runner, audio_device_id, video_mode_switcher_,
+      backend_factory_, task_runner, video_mode_switcher_,
       video_resolution_policy_, media_resource_tracker_, connector_,
       host_interfaces);
 }
diff --git a/chromecast/media/service/cast_mojo_media_client.h b/chromecast/media/service/cast_mojo_media_client.h
index 2b74e1a..355b1b5 100644
--- a/chromecast/media/service/cast_mojo_media_client.h
+++ b/chromecast/media/service/cast_mojo_media_client.h
@@ -8,6 +8,7 @@
 #include <memory>
 #include <string>
 
+#include "media/mojo/buildflags.h"
 #include "media/mojo/services/mojo_media_client.h"
 
 namespace chromecast {
@@ -31,8 +32,15 @@
                       MediaResourceTracker* media_resource_tracker);
   ~CastMojoMediaClient() override;
 
-  // MojoMediaClient overrides.
+  // MojoMediaClient implementation:
   void Initialize(service_manager::Connector* connector) override;
+#if BUILDFLAG(ENABLE_CAST_RENDERER)
+  std::unique_ptr<::media::Renderer> CreateCastRenderer(
+      service_manager::mojom::InterfaceProvider* host_interfaces,
+      scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+      ::media::MediaLog* media_log,
+      const base::UnguessableToken& overlay_plane_id) override;
+#endif
   std::unique_ptr<::media::Renderer> CreateRenderer(
       service_manager::mojom::InterfaceProvider* host_interfaces,
       scoped_refptr<base::SingleThreadTaskRunner> task_runner,
diff --git a/chromecast/media/service/cast_renderer.cc b/chromecast/media/service/cast_renderer.cc
index f439a86..225b2b0 100644
--- a/chromecast/media/service/cast_renderer.cc
+++ b/chromecast/media/service/cast_renderer.cc
@@ -58,7 +58,6 @@
 CastRenderer::CastRenderer(
     CmaBackendFactory* backend_factory,
     const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
-    const std::string& audio_device_id,
     VideoModeSwitcher* video_mode_switcher,
     VideoResolutionPolicy* video_resolution_policy,
     MediaResourceTracker* media_resource_tracker,
@@ -66,9 +65,6 @@
     service_manager::mojom::InterfaceProvider* host_interfaces)
     : backend_factory_(backend_factory),
       task_runner_(task_runner),
-      audio_device_id_(audio_device_id.empty()
-                           ? ::media::AudioDeviceDescription::kDefaultDeviceId
-                           : audio_device_id),
       video_mode_switcher_(video_mode_switcher),
       video_resolution_policy_(video_resolution_policy),
       media_resource_tracker_(media_resource_tracker),
@@ -178,18 +174,9 @@
           ? MediaPipelineDeviceParams::kModeIgnorePts
           : MediaPipelineDeviceParams::kModeSyncPts;
 
-  AudioContentType content_type;
-  if (audio_device_id_ == kAlarmAudioDeviceId) {
-    content_type = AudioContentType::kAlarm;
-  } else if (audio_device_id_ == kTtsAudioDeviceId ||
-             audio_device_id_ ==
-                 ::media::AudioDeviceDescription::kCommunicationsDeviceId) {
-    content_type = AudioContentType::kCommunication;
-  } else {
-    content_type = AudioContentType::kMedia;
-  }
-  MediaPipelineDeviceParams params(sync_type, backend_task_runner_.get(),
-                                   content_type, audio_device_id_);
+  MediaPipelineDeviceParams params(
+      sync_type, backend_task_runner_.get(), AudioContentType::kMedia,
+      ::media::AudioDeviceDescription::kDefaultDeviceId);
   params.connector = connector_;
   params.session_id = application_media_info->application_session_id;
   params.multiroom = multiroom_info->multiroom;
@@ -198,14 +185,6 @@
   params.pass_through_audio_support_desired =
       !application_media_info->mixer_audio_enabled;
 
-  if (audio_device_id_ == kTtsAudioDeviceId ||
-      audio_device_id_ ==
-          ::media::AudioDeviceDescription::kCommunicationsDeviceId) {
-    load_type = kLoadTypeCommunication;
-  } else if (audio_device_id_ == kPlatformAudioDeviceId) {
-    load_type = kLoadTypeMediaStream;
-  }
-
   auto backend = backend_factory_->CreateBackend(params);
 
   // Create pipeline.
diff --git a/chromecast/media/service/cast_renderer.h b/chromecast/media/service/cast_renderer.h
index a9fef18..1c78799 100644
--- a/chromecast/media/service/cast_renderer.h
+++ b/chromecast/media/service/cast_renderer.h
@@ -45,7 +45,6 @@
   // |host_interfaces| provides interfaces tied to RenderFrameHost.
   CastRenderer(CmaBackendFactory* backend_factory,
                const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
-               const std::string& audio_device_id,
                VideoModeSwitcher* video_mode_switcher,
                VideoResolutionPolicy* video_resolution_policy,
                MediaResourceTracker* media_resource_tracker,
@@ -95,7 +94,6 @@
 
   CmaBackendFactory* const backend_factory_;
   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-  const std::string audio_device_id_;
   VideoModeSwitcher* video_mode_switcher_;
   VideoResolutionPolicy* video_resolution_policy_;
   MediaResourceTracker* media_resource_tracker_;