Skip to content

Commit

Permalink
[media] Add StarboardRendererFactory
Browse files Browse the repository at this point in the history
1. Add StarboardRendererFactory for MediaFactory to select StarboardRenderer when `use_starboard_media=true`.
2. Remove hard code StarboardRenderer in WebMediaPlayerImpl.

Note RendererType::kStarboard cannot be gated due to mojom files.

b/375278384
  • Loading branch information
borongc committed Nov 9, 2024
1 parent 819f56c commit 201c312
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 17 deletions.
14 changes: 14 additions & 0 deletions content/renderer/media/media_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#endif // BUILDFLAG(IS_WIN)

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "media/starboard/starboard_renderer_factory.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace {

// This limit is much higher than it needs to be right now, because the logic
Expand Down Expand Up @@ -740,6 +744,16 @@ MediaFactory::CreateRendererFactorySelector(
}
#endif // BUILDFLAG(IS_CASTOS) || BUILDFLAG(IS_CAST_ANDROID)

#if BUILDFLAG(USE_STARBOARD_MEDIA)
if (!is_base_renderer_factory_set) {
is_base_renderer_factory_set = true;
factory_selector->AddFactory(
RendererType::kStarboard,
std::make_unique<media::StarboardRendererFactory>());
factory_selector->SetBaseRendererType(RendererType::kStarboard);
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

if (!is_base_renderer_factory_set) {
// TODO(crbug.com/1265448): These sorts of checks shouldn't be necessary if
// this method were significantly refactored to split things up by
Expand Down
4 changes: 4 additions & 0 deletions media/base/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ std::string GetRendererName(RendererType renderer_type) {
return "CastStreamingRenderer";
case RendererType::kContentEmbedderDefined:
return "EmbedderDefined";
// TODO(b/375278384): RendererType::kStarboard cannot
// be gated due to media_types.mojom
case RendererType::kStarboard:
return "StarboardRenderer";
case RendererType::kTest:
return "Media Renderer Implementation For Testing";
}
Expand Down
5 changes: 4 additions & 1 deletion media/base/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ enum class RendererType {
kRemoting = 8, // RemotingRendererFactory for remoting::Receiver
kCastStreaming = 9, // PlaybackCommandForwardingRendererFactory
kContentEmbedderDefined = 10, // Defined by the content embedder
kTest = 11, // Renderer implementations used in tests
// TODO(b/375278384): RendererType::kStarboard cannot
// be gated due to media_types.mojom
kStarboard = 11, // StarboardRendererFactory
kTest = 12, // Renderer implementations used in tests
kMaxValue = kTest,
};

Expand Down
3 changes: 2 additions & 1 deletion media/mojo/mojom/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,6 @@ enum RendererType {
kRemoting = 8, // RemotingRendererFactory for remoting::Receiver
kCastStreaming = 9, // CastStreamingRendererFactory
kContentEmbedderDefined = 10, // Defined by the content embedder
kTest= 11, // Renderer implementations used in tests
kStarboard = 11, // StarboardRendererFactory
kTest = 12, // Renderer implementations used in tests
};
5 changes: 5 additions & 0 deletions media/mojo/mojom/media_types_enum_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
return media::mojom::RendererType::kCastStreaming;
case ::media::RendererType::kContentEmbedderDefined:
return media::mojom::RendererType::kContentEmbedderDefined;
case ::media::RendererType::kStarboard:
return media::mojom::RendererType::kStarboard;
case ::media::RendererType::kTest:
return media::mojom::RendererType::kTest;
}
Expand Down Expand Up @@ -356,6 +358,9 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
case media::mojom::RendererType::kContentEmbedderDefined:
*output = ::media::RendererType::kContentEmbedderDefined;
return true;
case media::mojom::RendererType::kStarboard:
*output = ::media::RendererType::kStarboard;
return true;
case media::mojom::RendererType::kTest:
*output = ::media::RendererType::kTest;
return true;
Expand Down
2 changes: 2 additions & 0 deletions media/starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ source_set("starboard") {
"starboard_memory_allocator.h",
"starboard_renderer.cc",
"starboard_renderer.h",
"starboard_renderer_factory.cc",
"starboard_renderer_factory.h",
"starboard_utils.cc",
"starboard_utils.h",
]
Expand Down
42 changes: 42 additions & 0 deletions media/starboard/starboard_renderer_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "media/starboard/starboard_renderer_factory.h"

#include <memory>

#include "base/check.h"
#include "base/logging.h"
#include "base/task/sequenced_task_runner.h"
#include "media/starboard/starboard_renderer.h"

namespace media {

StarboardRendererFactory::StarboardRendererFactory() {}

StarboardRendererFactory::~StarboardRendererFactory() = default;

std::unique_ptr<Renderer> StarboardRendererFactory::CreateRenderer(
const scoped_refptr<base::SequencedTaskRunner>& media_task_runner,
const scoped_refptr<base::TaskRunner>& worker_task_runner,
AudioRendererSink* audio_renderer_sink,
VideoRendererSink* video_renderer_sink,
RequestOverlayInfoCB request_overlay_info_cb,
const gfx::ColorSpace& target_color_space) {
DCHECK(video_renderer_sink);
return std::make_unique<media::StarboardRenderer>(media_task_runner,
video_renderer_sink);
}

} // namespace media
44 changes: 44 additions & 0 deletions media/starboard/starboard_renderer_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_
#define MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_

#include "base/task/sequenced_task_runner.h"
#include "media/base/renderer_factory.h"

namespace media {

// Creates Renderers using Starboard.
class MEDIA_EXPORT StarboardRendererFactory final : public RendererFactory {
public:
StarboardRendererFactory();

StarboardRendererFactory(const StarboardRendererFactory&) = delete;
StarboardRendererFactory& operator=(const StarboardRendererFactory&) = delete;

~StarboardRendererFactory() final;

std::unique_ptr<Renderer> CreateRenderer(
const scoped_refptr<base::SequencedTaskRunner>& media_task_runner,
const scoped_refptr<base::TaskRunner>& worker_task_runner,
AudioRendererSink* audio_renderer_sink,
VideoRendererSink* video_renderer_sink,
RequestOverlayInfoCB request_overlay_info_cb,
const gfx::ColorSpace& target_color_space) final;
};

} // namespace media

#endif // MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_
23 changes: 8 additions & 15 deletions third_party/blink/renderer/platform/media/web_media_player_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2800,21 +2800,6 @@ std::unique_ptr<media::Renderer> WebMediaPlayerImpl::CreateRenderer(
&WebMediaPlayerImpl::OnOverlayInfoRequested, weak_this_));
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
// TODO(b/375278384): Select the StarboardRenderer properly instead of
// hard coding.

// StarboardRenderer always uses full screen with overlay video mode.
overlay_info_.is_fullscreen = true;

// `media_task_runner_` is always true, use an if statement to avoid
// potential build warning on unreachable code.
if (media_task_runner_) {
return std::make_unique<media::StarboardRenderer>(media_task_runner_,
compositor_.get());
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

if (renderer_type) {
DVLOG(1) << __func__
<< ": renderer_type=" << static_cast<int>(renderer_type.value());
Expand All @@ -2831,6 +2816,14 @@ std::unique_ptr<media::Renderer> WebMediaPlayerImpl::CreateRenderer(
media_metrics_provider_->SetRendererType(renderer_type_);
media_log_->SetProperty<MediaLogProperty::kRendererName>(renderer_type_);

#if BUILDFLAG(USE_STARBOARD_MEDIA)
LOG(INFO) << "Renderer Type is " << GetRendererName(renderer_type_) << ".";
if (renderer_type_ == media::RendererType::kStarboard) {
// StarboardRenderer always uses full screen with overlay video mode.
overlay_info_.is_fullscreen = true;
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

return renderer_factory_selector_->GetCurrentFactory()->CreateRenderer(
media_task_runner_, worker_task_runner_, audio_source_provider_.get(),
compositor_.get(), std::move(request_overlay_info_cb),
Expand Down

0 comments on commit 201c312

Please sign in to comment.