-
Notifications
You must be signed in to change notification settings - Fork 207
media: Wire URL player duration and buffered ranges for tvOS #11548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
|
|
||
| #include "base/task/bind_post_task.h" | ||
| #include "base/time/time.h" | ||
| #include "build/build_config.h" | ||
| #include "cobalt/media/service/mojom/platform_window_provider.mojom.h" | ||
| #include "cobalt/renderer/cobalt_render_frame_observer.h" | ||
| #include "cobalt/shell/common/url_constants.h" | ||
|
|
@@ -33,6 +34,7 @@ | |
| #include "media/base/media_switches.h" | ||
| #include "media/base/renderer_factory.h" | ||
| #include "media/base/starboard/experimental_features.h" | ||
| #include "media/media_buildflags.h" | ||
| #include "media/mojo/clients/starboard/starboard_renderer_client_factory.h" | ||
| #include "media/starboard/starboard_media_external_memory_allocator.h" | ||
| #include "mojo/public/cpp/bindings/generic_pending_receiver.h" | ||
|
|
@@ -46,6 +48,10 @@ | |
| #include "third_party/blink/public/web/web_view.h" | ||
| #include "ui/gfx/geometry/size_conversions.h" | ||
|
|
||
| #if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. USE_STARBOARD_MEDIA is true for Cobalt build anyway, so this is not necessary. |
||
| #include "media/starboard/url_player_demuxer.h" | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
|
||
| namespace cobalt { | ||
|
|
||
| namespace { | ||
|
|
@@ -368,4 +374,18 @@ void CobaltContentRendererClient::PostSandboxInitialized() { | |
| } | ||
| } | ||
|
|
||
| std::unique_ptr<::media::Demuxer> | ||
| CobaltContentRendererClient::OverrideDemuxerForUrl( | ||
| content::RenderFrame* render_frame, | ||
| const GURL& url, | ||
| scoped_refptr<base::SequencedTaskRunner> task_runner) { | ||
| #if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| if (::media::IsHlsUrl(url)) { | ||
| return std::make_unique<::media::UrlPlayerDemuxer>(std::move(task_runner), | ||
| url); | ||
| } | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| return nullptr; | ||
| } | ||
|
|
||
| } // namespace cobalt | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ enum class DemuxerType { | |
| kFrameInjectingDemuxer = 5, | ||
| kStreamProviderDemuxer = 6, | ||
| kManifestDemuxer = 7, | ||
| kUrlPlayerDemuxer = 8, // URL player placeholder demuxer. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: gate it by |
||
| }; | ||
|
|
||
| class MEDIA_EXPORT DemuxerHost { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| #include "media/base/media_resource.h" | ||
|
|
||
| #include "base/no_destructor.h" | ||
| #include "media/media_buildflags.h" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not necessary, please check it. |
||
| #include "net/cookies/site_for_cookies.h" | ||
| #include "net/storage_access_api/status.h" | ||
| #include "url/gurl.h" | ||
|
|
@@ -25,4 +26,17 @@ DemuxerStream* MediaResource::GetFirstStream(DemuxerStream::Type type) { | |
| return nullptr; | ||
| } | ||
|
|
||
| #if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| GURL MediaResource::GetMediaUrl() const { | ||
| return GURL(); | ||
| } | ||
|
|
||
| void MediaResource::ForwardDurationChangeToDemuxerHost( | ||
| base::TimeDelta duration) {} | ||
|
|
||
| void MediaResource::ForwardBufferedTimeRangesToDemuxerHost( | ||
| base::TimeDelta start, | ||
| base::TimeDelta length) {} | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
|
||
| } // namespace media | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,11 @@ | |
| #include "base/time/time.h" | ||
| #include "media/base/demuxer_stream.h" | ||
| #include "media/base/media_export.h" | ||
| #include "build/build_config.h" | ||
| #include "media/media_buildflags.h" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for all |
||
| #if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| #include "url/gurl.h" | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
|
||
| namespace media { | ||
|
|
||
|
|
@@ -41,6 +46,18 @@ class MEDIA_EXPORT MediaResource { | |
| // A helper function that return the first stream of the given `type` if one | ||
| // exists or a null pointer if there is no streams of that type. | ||
| DemuxerStream* GetFirstStream(DemuxerStream::Type type); | ||
|
|
||
| #if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| // Returns the media URL for URL player. | ||
| virtual GURL GetMediaUrl() const; | ||
|
|
||
| // Forwards duration change to DemuxerHost. | ||
| virtual void ForwardDurationChangeToDemuxerHost(base::TimeDelta duration); | ||
|
|
||
| // Forwards buffered ranges to DemuxerHost. | ||
| virtual void ForwardBufferedTimeRangesToDemuxerHost(base::TimeDelta start, | ||
| base::TimeDelta length); | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA) | ||
| }; | ||
|
|
||
| } // namespace media | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| #include "base/functional/bind.h" | ||
| #include "base/time/time.h" | ||
| #include "base/unguessable_token.h" | ||
| #include "build/build_config.h" | ||
| #include "media/base/media_log.h" | ||
| #include "media/base/media_resource.h" | ||
| #include "media/base/media_switches.h" | ||
|
|
@@ -30,6 +31,10 @@ | |
| #include "mojo/public/cpp/bindings/callback_helpers.h" | ||
| #include "mojo/public/cpp/bindings/pending_receiver.h" | ||
|
|
||
| #if BUILDFLAG(IS_IOS_TVOS) | ||
| #include "url/gurl.h" | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) | ||
|
abhijeetk marked this conversation as resolved.
|
||
|
|
||
| #if BUILDFLAG(IS_ANDROID) | ||
| #include "base/task/bind_post_task.h" | ||
| #endif // BUILDFLAG(IS_ANDROID) | ||
|
|
@@ -102,6 +107,7 @@ void StarboardRendererClient::Initialize(MediaResource* media_resource, | |
| DCHECK(!init_cb_); | ||
|
|
||
| client_ = client; | ||
| media_resource_ = media_resource; | ||
| init_cb_ = std::move(init_cb); | ||
|
|
||
| DCHECK(!AreMojoPipesConnected()); | ||
|
|
@@ -280,6 +286,26 @@ void StarboardRendererClient::GetSbWindowHandle() { | |
| renderer_extension_->OnSbWindowHandleReady(sb_window_handle); | ||
| } | ||
|
|
||
| void StarboardRendererClient::OnDurationChange(base::TimeDelta duration) { | ||
| DCHECK(media_task_runner_->RunsTasksInCurrentSequence()); | ||
| #if BUILDFLAG(IS_IOS_TVOS) | ||
| if (media_resource_) { | ||
| media_resource_->ForwardDurationChangeToDemuxerHost(duration); | ||
| } | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) | ||
|
abhijeetk marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void StarboardRendererClient::OnBufferedTimeRangesChange( | ||
| base::TimeDelta start, | ||
| base::TimeDelta length) { | ||
| DCHECK(media_task_runner_->RunsTasksInCurrentSequence()); | ||
| #if BUILDFLAG(IS_IOS_TVOS) | ||
| if (media_resource_) { | ||
| media_resource_->ForwardBufferedTimeRangesToDemuxerHost(start, length); | ||
| } | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) | ||
|
abhijeetk marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #if BUILDFLAG(IS_ANDROID) | ||
| void StarboardRendererClient::RequestOverlayInfo(bool restart_for_transitions) { | ||
| DCHECK(media_task_runner_->RunsTasksInCurrentSequence()); | ||
|
|
@@ -351,8 +377,18 @@ void StarboardRendererClient::InitializeMojoRenderer( | |
| DCHECK(media_task_runner_->RunsTasksInCurrentSequence()); | ||
| DCHECK(AreMojoPipesConnected()); | ||
|
|
||
| if (base::FeatureList::IsEnabled(kCobaltBypassMojoForMedia) || | ||
| bypass_mojo_for_media_) { | ||
| // URL player is incompatible with the bypass bridge because the bypass | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just gate the code by
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion! Gating the bypass bridge block with Let me know if you'd prefer a different approach here. |
||
| // bridge proxies demuxer streams, while the URL player delegates playback | ||
| // entirely to the native platform player. | ||
| bool is_url_player = false; | ||
| #if BUILDFLAG(IS_IOS_TVOS) | ||
| GURL url = media_resource->GetMediaUrl(); | ||
| is_url_player = url.is_valid(); | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) | ||
|
abhijeetk marked this conversation as resolved.
|
||
|
|
||
| if (!is_url_player && | ||
| (base::FeatureList::IsEnabled(kCobaltBypassMojoForMedia) || | ||
| bypass_mojo_for_media_)) { | ||
| bypass_bridge_ = base::MakeRefCounted<MojoRendererBypassBridge>( | ||
| media_task_runner_, | ||
| base::BindRepeating(&StarboardRendererClient::OnTimeUpdateFromBridge, | ||
|
|
@@ -378,6 +414,12 @@ void StarboardRendererClient::InitializeMojoRenderer( | |
| return; | ||
| } | ||
|
|
||
| #if BUILDFLAG(IS_IOS_TVOS) | ||
| if (is_url_player) { | ||
| renderer_extension_->SetSourceUrl(url.spec()); | ||
| } | ||
| #endif // BUILDFLAG(IS_IOS_TVOS) | ||
|
abhijeetk marked this conversation as resolved.
|
||
|
|
||
| MojoRendererWrapper::Initialize(media_resource, client, std::move(init_cb)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| #include "base/memory/weak_ptr.h" | ||
| #include "base/synchronization/lock.h" | ||
| #include "base/task/sequenced_task_runner.h" | ||
| #include "build/build_config.h" | ||
| #include "media/base/pipeline_status.h" | ||
| #include "media/base/renderer_client.h" | ||
| #include "media/base/starboard/starboard_rendering_mode.h" | ||
|
|
@@ -110,6 +111,9 @@ class MEDIA_EXPORT StarboardRendererClient | |
| void PaintVideoHoleFrame(const gfx::Size& size) override; | ||
| void UpdateStarboardRenderingMode(const StarboardRenderingMode mode) override; | ||
| void GetSbWindowHandle() override; | ||
| void OnDurationChange(base::TimeDelta duration) override; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is only used on tvOS, consider to gate them by |
||
| void OnBufferedTimeRangesChange(base::TimeDelta start, | ||
| base::TimeDelta length) override; | ||
| #if BUILDFLAG(IS_ANDROID) | ||
| void RequestOverlayInfo(bool restart_for_transitions) override; | ||
| #endif // BUILDFLAG(IS_ANDROID) | ||
|
|
@@ -169,6 +173,7 @@ class MEDIA_EXPORT StarboardRendererClient | |
| mojo::Remote<RendererExtension> renderer_extension_; | ||
|
|
||
| raw_ptr<RendererClient> client_ = nullptr; | ||
| raw_ptr<MediaResource> media_resource_ = nullptr; | ||
| PipelineStatusCallback init_cb_; | ||
|
|
||
| // Rendering mode the Starboard Renderer will use. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -662,6 +662,7 @@ enum DemuxerType { | |
| kFrameInjectingDemuxer = 5, | ||
| kStreamProviderDemuxer = 6, | ||
| kManifestDemuxer = 7, | ||
| kUrlPlayerDemuxer = 8, // URL player placeholder demuxer. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please gate it.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Currently at GN level, we identify tvos code using Please see our previous notes here regarding this constraint. Aslo, As per your suggestion on |
||
| }; | ||
|
|
||
| // See media::CreateCdmStatus | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,11 @@ interface StarboardRendererClientExtension { | |
| // Get SbWindow from StarboardRendererClient. | ||
| GetSbWindowHandle(); | ||
|
|
||
| // URL player duration and buffered ranges forwarding. | ||
| OnDurationChange(mojo_base.mojom.TimeDelta duration); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please gate it both by use_starboard_media and is_ios_tvos
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed above on |
||
| OnBufferedTimeRangesChange(mojo_base.mojom.TimeDelta start, | ||
| mojo_base.mojom.TimeDelta length); | ||
|
|
||
| [EnableIf=is_android] | ||
| // Request OverlayInfo from StarboardRendererClient. | ||
| RequestOverlayInfo(bool restart_for_transitions); | ||
|
|
@@ -151,6 +156,9 @@ interface StarboardRendererExtension { | |
| // Initialize media bypass bridge in single-process mode. | ||
| InitializeWithBypassBridge(uint32 bypass_bridge_id) => (bool success); | ||
|
|
||
| // Pass source URL for URL player. | ||
| SetSourceUrl(string source_url); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed above on |
||
|
|
||
| [EnableIf=is_android] | ||
| // Notify StarboardRendererWrapper when the current OverlayInfo changes. | ||
| OnOverlayInfoChanged(OverlayInfo overlay_info); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think including this is necessary.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments of this PR should be applied to #10698.