Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@
#define BUILDFLAG_INTERNAL_USE_STARBOARD_MEDIA() (0)
#endif

#if defined(ENABLE_BUILDFLAG_USE_STARBOARD_URL_PLAYER)
#define BUILDFLAG_INTERNAL_USE_STARBOARD_URL_PLAYER() (1)
#else
#define BUILDFLAG_INTERNAL_USE_STARBOARD_URL_PLAYER() (0)
#endif

#if defined(ENABLE_BUILDFLAG_USE_EVERGREEN)
#define BUILDFLAG_INTERNAL_USE_EVERGREEN() (1)
#else
Expand Down
8 changes: 8 additions & 0 deletions cobalt/build/configs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ config("buildflag_defines") {
defines += [ "ENABLE_BUILDFLAG_USE_STARBOARD_MEDIA" ]
}

# use_starboard_url_player and BUILDFLAG(USE_STARBOARD_URL_PLAYER) should be
# used to wrap URL-based player functionality (e.g., HLS via AVPlayer on
# tvOS). This is a derived capability that is true only for tvOS builds with
# Starboard media enabled.
if (use_starboard_url_player) {
defines += [ "ENABLE_BUILDFLAG_USE_STARBOARD_URL_PLAYER" ]
}

# use_evergreen and BUILDFLAG(USE_EVERGREEN) should be used for
# Evergreen-specific functionality, i.e. the Evergreen loader_app. Do not use
# this flag for hermetic build functionality, instead use
Expand Down
8 changes: 7 additions & 1 deletion media/base/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// found in the LICENSE file.

#include "media/base/renderer.h"

#include "base/logging.h"
#include "build/build_config.h"

namespace media {

Expand Down Expand Up @@ -34,7 +36,11 @@ std::string GetRendererName(RendererType renderer_type) {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
case RendererType::kStarboard:
return "StarboardRenderer";
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
case RendererType::kUrlPlayer:
return "UrlPlayerRenderer";
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
}
}

Expand Down
10 changes: 8 additions & 2 deletions media/base/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/functional/callback.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "media/base/buffering_state.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
Expand Down Expand Up @@ -39,10 +40,15 @@ enum class RendererType {
kTest = 11, // Renderer implementations used in tests
#if BUILDFLAG(USE_STARBOARD_MEDIA)
kStarboard = 12, // StarboardRendererFactory
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
kUrlPlayer = 13, // UrlPlayerRendererClientFactory
kMaxValue = kUrlPlayer,
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
kMaxValue = kStarboard,
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
#else
kMaxValue = kTest,
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
};

// Get the name of the Renderer for `renderer_type`. The returned name could be
Expand Down
25 changes: 25 additions & 0 deletions media/mojo/clients/mojo_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ void MojoRenderer::Initialize(MediaResource* media_resource,
base::Unretained(this), client));
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void MojoRenderer::InitializeWithUrl(media::RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb) {
DVLOG(1) << __func__;
DCHECK(task_runner_->RunsTasksInCurrentSequence());

if (!source_url.is_valid() || encountered_error_) {
task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(init_cb),
PIPELINE_ERROR_INITIALIZATION_FAILED));
return;
}

init_cb_ = std::move(init_cb);

BindRemoteRendererIfNeeded();

remote_renderer_->InitializeWithUrl(
client_receiver_.BindNewEndpointAndPassRemote(), source_url,
base::BindOnce(&MojoRenderer::OnInitialized, base::Unretained(this),
client));
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

void MojoRenderer::SetCdm(CdmContext* cdm_context,
CdmAttachedCB cdm_attached_cb) {
DVLOG(1) << __func__;
Expand Down
7 changes: 7 additions & 0 deletions media/mojo/clients/mojo_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#include "base/task/sequenced_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "media/base/demuxer_stream.h"
#include "media/base/renderer.h"
#include "media/base/time_delta_interpolator.h"
#include "media/mojo/mojom/renderer.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "url/gurl.h"

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "media/mojo/common/starboard/mojo_renderer_bypass_bridge.h"
Expand Down Expand Up @@ -65,6 +67,11 @@ class MojoRenderer : public Renderer, public mojom::RendererClient {
void Initialize(MediaResource* media_resource,
media::RendererClient* client,
PipelineStatusCallback init_cb) override;
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(media::RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb);
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb) override;
void SetLatencyHint(std::optional<base::TimeDelta> latency_hint) override;
void Flush(base::OnceClosure flush_cb) override;
Expand Down
11 changes: 11 additions & 0 deletions media/mojo/clients/mojo_renderer_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <utility>

#include "base/logging.h"

namespace media {

MojoRendererWrapper::MojoRendererWrapper(
Expand All @@ -20,6 +22,15 @@ void MojoRendererWrapper::Initialize(MediaResource* media_resource,
mojo_renderer_->Initialize(media_resource, client, std::move(init_cb));
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void MojoRendererWrapper::InitializeWithUrl(RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb) {
DVLOG(1) << __func__;
mojo_renderer_->InitializeWithUrl(client, source_url, std::move(init_cb));
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

void MojoRendererWrapper::Flush(base::OnceClosure flush_cb) {
mojo_renderer_->Flush(std::move(flush_cb));
}
Expand Down
7 changes: 7 additions & 0 deletions media/mojo/clients/mojo_renderer_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#include <memory>

#include "build/build_config.h"
#include "media/base/renderer.h"
#include "media/mojo/clients/mojo_renderer.h"
#include "url/gurl.h"

namespace media {

Expand All @@ -30,6 +32,11 @@ class MojoRendererWrapper : public Renderer {
void Initialize(MediaResource* media_resource,
RendererClient* client,
PipelineStatusCallback init_cb) override;
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb);
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb) override;
void SetLatencyHint(std::optional<base::TimeDelta> latency_hint) override;
void Flush(base::OnceClosure flush_cb) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "media/base/mock_media_log.h"
#include "media/base/test_helpers.h"
#include "media/base/video_renderer_sink.h"
#include "media/media_buildflags.h"
#include "media/mojo/mojom/renderer.mojom.h"
#include "media/mojo/mojom/renderer_extensions.mojom.h"
#include "media/renderers/video_overlay_factory.h"
Expand Down Expand Up @@ -61,6 +62,13 @@ class FakeMojomRenderer : public mojom::Renderer {
InitializeWithBypassBridgeCallback cb) override {
std::move(cb).Run(true);
}
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(mojo::PendingAssociatedRemote<mojom::RendererClient>,
const GURL& source_url,
InitializeWithUrlCallback cb) override {
std::move(cb).Run(true);
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
MOCK_METHOD1(Flush, void(FlushCallback));
void StartPlayingFrom(base::TimeDelta time) override {}
MOCK_METHOD1(SetPlaybackRate, void(double));
Expand Down
4 changes: 4 additions & 0 deletions media/mojo/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ mojom("mojom") {
enabled_features += [ "use_starboard_media" ]
}

if (is_cobalt && use_starboard_url_player) {
enabled_features += [ "use_starboard_url_player" ]
}

shared_typemaps = [
{
types = [
Expand Down
2 changes: 2 additions & 0 deletions media/mojo/mojom/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ enum RendererType {
kTest= 11, // Renderer implementations used in tests
[EnableIf=use_starboard_media]
kStarboard = 12, // StarboardRendererFactory
[EnableIf=use_starboard_url_player]
kUrlPlayer = 13, // UrlPlayerRendererClientFactory
};

// See media/base/demuxer.h for description.
Expand Down
13 changes: 11 additions & 2 deletions media/mojo/mojom/media_types_enum_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
case ::media::RendererType::kStarboard:
return media::mojom::RendererType::kStarboard;
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
case ::media::RendererType::kUrlPlayer:
return media::mojom::RendererType::kUrlPlayer;
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
}

NOTREACHED();
Expand Down Expand Up @@ -436,7 +440,12 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
case media::mojom::RendererType::kStarboard:
*output = ::media::RendererType::kStarboard;
return true;
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
case media::mojom::RendererType::kUrlPlayer:
*output = ::media::RendererType::kUrlPlayer;
return true;
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
}

NOTREACHED();
Expand Down
8 changes: 8 additions & 0 deletions media/mojo/mojom/renderer.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ interface Renderer {
Initialize(pending_associated_remote<RendererClient> client,
array<pending_remote<DemuxerStream>>? streams) => (bool success);

// Initializes the tvOS URL player with a `source_url` delivered on the
// renderer pipe. No demuxer streams are needed - the platform handles
// demuxing. Sending the URL on the renderer pipe keeps URL delivery
// and initialization ordered on the same Mojo pipe.
[EnableIf=use_starboard_url_player]
InitializeWithUrl(pending_associated_remote<RendererClient> client,
url.mojom.Url source_url) => (bool success);

// Supported only in single-process mode with the feature enabled.
[EnableIf=use_starboard_media]
InitializeWithBypassBridge(pending_associated_remote<RendererClient> client,
Expand Down
10 changes: 10 additions & 0 deletions media/mojo/services/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ component("services") {
sources += [ "gpu_mojo_media_client_stubs.cc" ]
}

if (is_cobalt && use_starboard_url_player) {
sources += [
"starboard/url_player_renderer_wrapper.cc",
"starboard/url_player_renderer_wrapper.h",
]
}

if (is_chromeos) {
deps +=
[ "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu" ]
Expand Down Expand Up @@ -366,6 +373,9 @@ source_set("unit_tests") {
"//starboard/common",
]
}
if (is_cobalt && use_starboard_url_player) {
sources += [ "starboard/url_player_renderer_wrapper_unittest.cc" ]
}
}

mojolpm_fuzzer_test("webrtc_video_perf_mojolpm_fuzzer") {
Expand Down
37 changes: 37 additions & 0 deletions media/mojo/services/mojo_renderer_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "media/mojo/common/starboard/mojo_renderer_bypass_bridge.h"
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
#include "media/mojo/services/starboard/url_player_renderer_wrapper.h"
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

namespace media {

// Time interval to update media time.
Expand Down Expand Up @@ -135,6 +139,39 @@ void MojoRendererService::Initialize(
std::move(callback)));
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void MojoRendererService::InitializeWithUrl(
mojo::PendingAssociatedRemote<mojom::RendererClient> client,
const GURL& source_url,
InitializeWithUrlCallback callback) {
DVLOG(1) << __func__ << ": " << source_url;

if (state_ != STATE_UNINITIALIZED) {
std::move(callback).Run(false);
return;
}

if (renderer_->GetRendererType() != RendererType::kUrlPlayer) {
mojo::ReportBadMessage("InitializeWithUrl requires URL player renderer");
return;
}

if (!source_url.is_valid()) {
mojo::ReportBadMessage("InitializeWithUrl requires a valid source URL");
return;
}

client_.Bind(std::move(client));
state_ = STATE_INITIALIZING;

static_cast<UrlPlayerRendererWrapper*>(renderer_.get())
->InitializeWithUrl(
this, source_url,
base::BindOnce(&MojoRendererService::OnRendererInitializeDone,
weak_this_, std::move(callback)));
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

#if BUILDFLAG(USE_STARBOARD_MEDIA)
void MojoRendererService::InitializeWithBypassBridge(
mojo::PendingAssociatedRemote<mojom::RendererClient> client,
Expand Down
8 changes: 8 additions & 0 deletions media/mojo/services/mojo_renderer_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "media/base/buffering_state.h"
#include "media/base/media_resource.h"
#include "media/base/pipeline_status.h"
Expand All @@ -28,6 +29,7 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "url/gurl.h"

namespace media {

Expand Down Expand Up @@ -67,6 +69,12 @@ class MEDIA_MOJO_EXPORT MojoRendererService final : public mojom::Renderer,
std::optional<std::vector<mojo::PendingRemote<mojom::DemuxerStream>>>
streams,
InitializeCallback callback) final;
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(
mojo::PendingAssociatedRemote<mojom::RendererClient> client,
const GURL& source_url,
InitializeWithUrlCallback callback) final;
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
#if BUILDFLAG(USE_STARBOARD_MEDIA)
void InitializeWithBypassBridge(
mojo::PendingAssociatedRemote<mojom::RendererClient> client,
Expand Down
Loading
Loading