Skip to content

Commit

Permalink
[android] Support configuring maximum number of samples per write to …
Browse files Browse the repository at this point in the history
…SbPlayer from webapp

1. Support maximum number of samples per write configuration from the h5vcc setting.
2. Enable this feature by the h5vcc settings of "EnableBatchedSampleWrite" and a positive value for "PlayerConfiguration.SetMaximumNumberOfSamplesPerWrite".

b/227837774
  • Loading branch information
borongc committed Jun 11, 2024
1 parent 939ed4f commit 2f3f9fd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
10 changes: 6 additions & 4 deletions cobalt/media/base/sbplayer_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SbPlayerPipeline::SbPlayerPipeline(
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const GetDecodeTargetGraphicsContextProviderFunc&
get_decode_target_graphics_context_provider_func,
bool allow_resume_after_suspend, bool allow_batched_sample_write,
bool allow_resume_after_suspend, int audio_batched_sample_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
TimeDelta audio_write_duration_local, TimeDelta audio_write_duration_remote,
Expand All @@ -116,7 +116,7 @@ SbPlayerPipeline::SbPlayerPipeline(
sbplayer_interface_(interface),
task_runner_(task_runner),
allow_resume_after_suspend_(allow_resume_after_suspend),
allow_batched_sample_write_(allow_batched_sample_write),
audio_batched_sample_write_(audio_batched_sample_write),
window_(window),
get_decode_target_graphics_context_provider_func_(
get_decode_target_graphics_context_provider_func),
Expand Down Expand Up @@ -1079,8 +1079,10 @@ void SbPlayerPipeline::OnNeedData(DemuxerStream::Type type,
return;
}

int max_buffers =
allow_batched_sample_write_ ? max_number_of_buffers_to_write : 1;
int max_buffers = audio_batched_sample_write_ > 1
? std::min(max_number_of_buffers_to_write,
audio_batched_sample_write_)
: 1;

if (GetReadInProgress(type)) return;

Expand Down
6 changes: 3 additions & 3 deletions cobalt/media/base/sbplayer_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline,
const GetDecodeTargetGraphicsContextProviderFunc&
get_decode_target_graphics_context_provider_func,
bool allow_resume_after_suspend,
bool allow_batched_sample_write,
int audio_batched_sample_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
TimeDelta audio_write_duration_local,
Expand Down Expand Up @@ -217,8 +217,8 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline,
// Whether we should save DecoderBuffers for resume after suspend.
const bool allow_resume_after_suspend_;

// Whether we enable batched sample write functionality.
const bool allow_batched_sample_write_;
// Whether we allow batched sample write functionality.
const int audio_batched_sample_write_;

// The default output mode passed to `SbPlayerGetPreferredOutputMode()`.
SbPlayerOutputMode default_output_mode_ = kSbPlayerOutputModeInvalid;
Expand Down
9 changes: 4 additions & 5 deletions cobalt/media/media_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,9 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler {
} // namespace

bool MediaModule::SetConfiguration(const std::string& name, int32 value) {
if (name == "EnableBatchedSampleWrite") {
allow_batched_sample_write_ = value;
LOG(INFO) << (allow_batched_sample_write_ ? "Enabling" : "Disabling")
<< " batched sample write.";
if (name == "AudioBatchedSampleWrite") {
audio_batched_sample_write_ = value;
LOG(INFO) << "Set MaximumNumberOfSamplesPerWrite to " << value;
return true;
} else if (name == "ForcePunchOutByDefault") {
force_punch_out_by_default_ = value;
Expand Down Expand Up @@ -235,7 +234,7 @@ std::unique_ptr<WebMediaPlayer> MediaModule::CreateWebMediaPlayer(
base::Bind(&MediaModule::GetSbDecodeTargetGraphicsContextProvider,
base::Unretained(this)),
client, this, options_.allow_resume_after_suspend,
allow_batched_sample_write_, force_punch_out_by_default_,
audio_batched_sample_write_, force_punch_out_by_default_,
#if SB_API_VERSION >= 15
audio_write_duration_local_, audio_write_duration_remote_,
#endif // SB_API_VERSION >= 15
Expand Down
2 changes: 1 addition & 1 deletion cobalt/media/media_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MediaModule : public WebMediaPlayerFactory,
Players players_;
bool suspended_ = false;

bool allow_batched_sample_write_ = false;
int audio_batched_sample_write_ = 1;
// When set to `false` (the default value), Cobalt calls
// `SbPlayerGetPreferredOutputMode()` with `kSbPlayerOutputModeInvalid` when
// there is no preference on output mode.
Expand Down
6 changes: 3 additions & 3 deletions cobalt/media/player/web_media_player_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
const Pipeline::GetDecodeTargetGraphicsContextProviderFunc&
get_decode_target_graphics_context_provider_func,
WebMediaPlayerClient* client, WebMediaPlayerDelegate* delegate,
bool allow_resume_after_suspend, bool allow_batched_sample_write,
bool allow_resume_after_suspend, int audio_batched_sample_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
base::TimeDelta audio_write_duration_local,
Expand All @@ -123,7 +123,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
client_(client),
delegate_(delegate),
allow_resume_after_suspend_(allow_resume_after_suspend),
allow_batched_sample_write_(allow_batched_sample_write),
audio_batched_sample_write_(audio_batched_sample_write),
force_punch_out_by_default_(force_punch_out_by_default),
proxy_(new WebMediaPlayerProxy(task_runner_, this)),
media_log_(media_log),
Expand All @@ -143,7 +143,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
pipeline_ = new SbPlayerPipeline(
interface, window, pipeline_thread_.task_runner(),
get_decode_target_graphics_context_provider_func,
allow_resume_after_suspend_, allow_batched_sample_write_,
allow_resume_after_suspend_, audio_batched_sample_write_,
force_punch_out_by_default_,
#if SB_API_VERSION >= 15
audio_write_duration_local, audio_write_duration_remote,
Expand Down
4 changes: 2 additions & 2 deletions cobalt/media/player/web_media_player_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
WebMediaPlayerClient* client,
WebMediaPlayerDelegate* delegate,
bool allow_resume_after_suspend,
bool allow_batched_sample_write,
int audio_batched_sample_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
base::TimeDelta audio_write_duration_local,
Expand Down Expand Up @@ -300,7 +300,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
WebMediaPlayerClient* const client_;
WebMediaPlayerDelegate* const delegate_;
const bool allow_resume_after_suspend_;
const bool allow_batched_sample_write_;
const int audio_batched_sample_write_;
const bool force_punch_out_by_default_;
scoped_refptr<DecodeTargetProvider> decode_target_provider_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

int SbPlayerGetMaximumNumberOfSamplesPerWrite(SbPlayer player,
SbMediaType sample_type) {
return 1;
return 256;
}

0 comments on commit 2f3f9fd

Please sign in to comment.