Skip to content

Commit

Permalink
Cherry pick PR #3568: [android] Refactor AudioBatchedSampleWrite to M…
Browse files Browse the repository at this point in the history
…axAudioSamplesPerWrite (#3585)

Refer to the original PR: #3568

Rename AudioBatchedSampleWrite to MaxAudioSamplesPerWrite followed by PR
(#3325).

b/227837774

Co-authored-by: Bo-Rong Chen <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and borongc authored Jun 17, 2024
1 parent 7974b5d commit b357a65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions cobalt/media/base/sbplayer_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ SbPlayerPipeline::SbPlayerPipeline(
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const GetDecodeTargetGraphicsContextProviderFunc&
get_decode_target_graphics_context_provider_func,
bool allow_resume_after_suspend, int audio_batched_sample_write,
bool allow_resume_after_suspend, int max_audio_samples_per_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
TimeDelta audio_write_duration_local, TimeDelta audio_write_duration_remote,
Expand All @@ -146,7 +146,7 @@ SbPlayerPipeline::SbPlayerPipeline(
sbplayer_interface_(interface),
task_runner_(task_runner),
allow_resume_after_suspend_(allow_resume_after_suspend),
audio_batched_sample_write_(audio_batched_sample_write),
max_audio_samples_per_write_(max_audio_samples_per_write),
window_(window),
get_decode_target_graphics_context_provider_func_(
get_decode_target_graphics_context_provider_func),
Expand Down Expand Up @@ -1111,9 +1111,9 @@ void SbPlayerPipeline::OnNeedData(DemuxerStream::Type type,
return;
}

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

if (GetReadInProgress(type)) return;
Expand Down Expand Up @@ -1166,13 +1166,13 @@ void SbPlayerPipeline::OnNeedData(DemuxerStream::Type type,
audio_read_delayed_ = true;
return;
}
if (audio_batched_sample_write_ > 1 &&
if (max_audio_samples_per_write_ > 1 &&
!time_ahead_of_playback.is_negative()) {
estimated_max_buffers = GetEstimatedMaxBuffers(adjusted_write_duration,
time_ahead_of_playback,
false /* is_preroll */);
}
} else if (audio_batched_sample_write_ > 1) {
} else if (max_audio_samples_per_write_ > 1) {
if (!time_ahead_of_playback_for_preroll.is_negative()) {
estimated_max_buffers = GetEstimatedMaxBuffers(
adjusted_write_duration_for_preroll,
Expand Down Expand Up @@ -1228,7 +1228,7 @@ int SbPlayerPipeline::GetEstimatedMaxBuffers(TimeDelta write_duration,
DCHECK_GE(time_ahead_of_playback.InMicroseconds(), 0);

int estimated_max_buffers = 1;
if (!(audio_batched_sample_write_ > 1) ||
if (!(max_audio_samples_per_write_ > 1) ||
write_duration <= time_ahead_of_playback) {
return estimated_max_buffers;
}
Expand Down
8 changes: 4 additions & 4 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,
int audio_batched_sample_write,
int max_audio_samples_per_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
TimeDelta audio_write_duration_local,
Expand Down Expand Up @@ -222,11 +222,11 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline,
// Whether we should save DecoderBuffers for resume after suspend.
const bool allow_resume_after_suspend_;

// The number of samples per write that is allowed at once.
// The minimum number of |audio_batched_sample_write_| and
// The number of audio samples per write that is allowed at once.
// The minimum number of |max_audio_samples_per_write_| and
// SbPlayerGetMaximumNumberOfSamplesPerWrite() specifies
// the maximum number of samples SbPlayerWriteSamples() can accept.
const int audio_batched_sample_write_;
const int max_audio_samples_per_write_;

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

bool MediaModule::SetConfiguration(const std::string& name, int32 value) {
if (name == "AudioBatchedSampleWrite" && value > 0) {
audio_batched_sample_write_ = value;
LOG(INFO) << "Set MaximumNumberOfSamplesPerWrite to " << value;
if (name == "MaxAudioSamplesPerWrite" && value > 0) {
max_audio_samples_per_write_ = value;
LOG(INFO) << "Set MaxAudioSamplesPerWrite to " << value;
return true;
} else if (name == "ForcePunchOutByDefault") {
force_punch_out_by_default_ = value;
Expand Down Expand Up @@ -248,7 +248,7 @@ std::unique_ptr<WebMediaPlayer> MediaModule::CreateWebMediaPlayer(
base::Bind(&MediaModule::GetSbDecodeTargetGraphicsContextProvider,
base::Unretained(this)),
client, this, options_.allow_resume_after_suspend,
audio_batched_sample_write_, force_punch_out_by_default_,
max_audio_samples_per_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;

int audio_batched_sample_write_ = 1;
int max_audio_samples_per_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, int audio_batched_sample_write,
bool allow_resume_after_suspend, int max_audio_samples_per_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),
audio_batched_sample_write_(audio_batched_sample_write),
max_audio_samples_per_write_(max_audio_samples_per_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_, audio_batched_sample_write_,
allow_resume_after_suspend_, max_audio_samples_per_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,
int audio_batched_sample_write,
int max_audio_samples_per_write,
bool force_punch_out_by_default,
#if SB_API_VERSION >= 15
base::TimeDelta audio_write_duration_local,
Expand Down Expand Up @@ -304,7 +304,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
WebMediaPlayerClient* const client_;
WebMediaPlayerDelegate* const delegate_;
const bool allow_resume_after_suspend_;
const int audio_batched_sample_write_;
const int max_audio_samples_per_write_;
const bool force_punch_out_by_default_;
scoped_refptr<DecodeTargetProvider> decode_target_provider_;

Expand Down

0 comments on commit b357a65

Please sign in to comment.