diff --git a/cobalt/media/base/sbplayer_bridge.cc b/cobalt/media/base/sbplayer_bridge.cc index b806e21541b1..4c6831837fb7 100644 --- a/cobalt/media/base/sbplayer_bridge.cc +++ b/cobalt/media/base/sbplayer_bridge.cc @@ -526,7 +526,11 @@ void SbPlayerBridge::GetVideoResolution(int* frame_width, int* frame_height) { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo out_player_info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 out_player_info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &out_player_info); video_stream_info_.frame_width = out_player_info.frame_width; @@ -545,7 +549,11 @@ TimeDelta SbPlayerBridge::GetDuration() { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); if (info.duration == SB_PLAYER_NO_DURATION) { // URL-based player may not have loaded asset yet, so map no duration to 0. @@ -563,7 +571,11 @@ TimeDelta SbPlayerBridge::GetStartDate() { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); return TimeDelta::FromMicroseconds(info.start_date); } @@ -977,7 +989,11 @@ void SbPlayerBridge::GetInfo_Locked(uint32* video_frames_decoded, DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); if (media_time) { diff --git a/cobalt/media/base/sbplayer_interface.cc b/cobalt/media/base/sbplayer_interface.cc index 3f6059160ba8..217441f5e596 100644 --- a/cobalt/media/base/sbplayer_interface.cc +++ b/cobalt/media/base/sbplayer_interface.cc @@ -91,7 +91,11 @@ void DefaultSbPlayerInterface::Destroy(SbPlayer player) { void DefaultSbPlayerInterface::Seek(SbPlayer player, base::TimeDelta seek_to_timestamp, int ticket) { +#if SB_API_VERSION >= 15 SbPlayerSeek(player, seek_to_timestamp.InMicroseconds(), ticket); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, seek_to_timestamp.InMicroseconds(), ticket); +#endif // SB_API_VERSION >= 15 } bool DefaultSbPlayerInterface::IsEnhancedAudioExtensionEnabled() const { @@ -102,8 +106,13 @@ void DefaultSbPlayerInterface::WriteSamples( SbPlayer player, SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos) { DCHECK(!IsEnhancedAudioExtensionEnabled()); +#if SB_API_VERSION >= 15 SbPlayerWriteSamples(player, sample_type, sample_infos, number_of_sample_infos); +#else // SB_API_VERSION >= 15 + SbPlayerWriteSample2(player, sample_type, sample_infos, + number_of_sample_infos); +#endif // SB_API_VERSION >= 15 } void DefaultSbPlayerInterface::WriteSamples( @@ -140,8 +149,13 @@ void DefaultSbPlayerInterface::SetVolume(SbPlayer player, double volume) { } void DefaultSbPlayerInterface::GetInfo(SbPlayer player, +#if SB_API_VERSION >= 15 SbPlayerInfo* out_player_info) { SbPlayerGetInfo(player, out_player_info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2* out_player_info2) { + SbPlayerGetInfo2(player, out_player_info2); +#endif // SB_API_VERSION >= 15 } SbDecodeTarget DefaultSbPlayerInterface::GetCurrentFrame(SbPlayer player) { diff --git a/cobalt/media/base/sbplayer_interface.h b/cobalt/media/base/sbplayer_interface.h index 54b3de18d50c..cef271c5c53d 100644 --- a/cobalt/media/base/sbplayer_interface.h +++ b/cobalt/media/base/sbplayer_interface.h @@ -62,7 +62,11 @@ class SbPlayerInterface { virtual bool SetPlaybackRate(SbPlayer player, double playback_rate) = 0; virtual void SetVolume(SbPlayer player, double volume) = 0; +#if SB_API_VERSION >= 15 virtual void GetInfo(SbPlayer player, SbPlayerInfo* out_player_info) = 0; +#else // SB_API_VERSION >= 15 + virtual void GetInfo(SbPlayer player, SbPlayerInfo2* out_player_info2) = 0; +#endif // SB_API_VERSION >= 15 virtual SbDecodeTarget GetCurrentFrame(SbPlayer player) = 0; #if SB_HAS(PLAYER_WITH_URL) @@ -125,7 +129,11 @@ class DefaultSbPlayerInterface final : public SbPlayerInterface { int height) override; bool SetPlaybackRate(SbPlayer player, double playback_rate) override; void SetVolume(SbPlayer player, double volume) override; +#if SB_API_VERSION >= 15 void GetInfo(SbPlayer player, SbPlayerInfo* out_player_info) override; +#else // SB_API_VERSION >= 15 + void GetInfo(SbPlayer player, SbPlayerInfo2* out_player_info2) override; +#endif // SB_API_VERSION >= 15 SbDecodeTarget GetCurrentFrame(SbPlayer player) override; #if SB_HAS(PLAYER_WITH_URL) diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index 97d5d3d39482..ff3bacaa8fce 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -261,17 +261,31 @@ ExportedSymbols::ExportedSymbols() { #endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbPlayerCreate); REGISTER_SYMBOL(SbPlayerDestroy); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetAudioConfiguration); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetCurrentFrame); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetInfo); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerGetInfo2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetMaximumNumberOfSamplesPerWrite); REGISTER_SYMBOL(SbPlayerGetPreferredOutputMode); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerSeek); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerSeek2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerSetBounds); REGISTER_SYMBOL(SbPlayerSetPlaybackRate); REGISTER_SYMBOL(SbPlayerSetVolume); REGISTER_SYMBOL(SbPlayerWriteEndOfStream); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerWriteSamples); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerWriteSample2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbSocketAccept); REGISTER_SYMBOL(SbSocketBind); REGISTER_SYMBOL(SbSocketClearLastError); diff --git a/starboard/linux/shared/BUILD.gn b/starboard/linux/shared/BUILD.gn index 53838e95b4d2..f2669a4e70fe 100644 --- a/starboard/linux/shared/BUILD.gn +++ b/starboard/linux/shared/BUILD.gn @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//starboard/shared/enhanced_audio/enhanced_audio.gni") import("//starboard/shared/starboard/media/media_tests.gni") import("//starboard/shared/starboard/player/buildfiles.gni") import("//starboard/shared/starboard/player/player_tests.gni") diff --git a/starboard/linux/shared/system_get_extensions.cc b/starboard/linux/shared/system_get_extensions.cc index 1dad8044a8e8..454bf3abe3f8 100644 --- a/starboard/linux/shared/system_get_extensions.cc +++ b/starboard/linux/shared/system_get_extensions.cc @@ -34,6 +34,7 @@ #include "starboard/linux/shared/ifa.h" #include "starboard/linux/shared/platform_service.h" #include "starboard/linux/shared/time_zone.h" +#include "starboard/shared/enhanced_audio/enhanced_audio.h" #include "starboard/shared/ffmpeg/ffmpeg_demuxer.h" #include "starboard/shared/posix/free_space.h" #include "starboard/shared/posix/memory_mapped_file.h" @@ -70,6 +71,11 @@ const void* SbSystemGetExtension(const char* name) { if (strcmp(name, kCobaltExtensionFreeSpaceName) == 0) { return starboard::shared::posix::GetFreeSpaceApi(); } +#if SB_API_VERSION < 15 + if (strcmp(name, kCobaltExtensionEnhancedAudioName) == 0) { + return starboard::shared::enhanced_audio::GetEnhancedAudioApi(); + } +#endif // SB_API_VERSION < 15 if (strcmp(name, kCobaltExtensionDemuxerApi) == 0) { auto command_line = starboard::shared::starboard::Application::Get()->GetCommandLine(); diff --git a/starboard/nplb/media_set_audio_write_duration_test.cc b/starboard/nplb/media_set_audio_write_duration_test.cc index 6674d4c84212..5c9d67ecc1fb 100644 --- a/starboard/nplb/media_set_audio_write_duration_test.cc +++ b/starboard/nplb/media_set_audio_write_duration_test.cc @@ -59,8 +59,13 @@ class SbMediaSetAudioWriteDurationTest } // Check if we're about to input too far beyond the current playback time. +#if SB_API_VERSION >= 15 SbPlayerInfo info; SbPlayerGetInfo(pending_decoder_status_->player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; + SbPlayerGetInfo2(pending_decoder_status_->player, &info); +#endif // SB_API_VERSION >= 15 if ((last_input_timestamp_ - info.current_media_timestamp) > kDuration) { // Postpone writing samples. return; @@ -185,18 +190,30 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteLimitedInput) { WaitForPlayerState(kSbPlayerStateInitialized); // Seek to preroll. +#if SB_API_VERSION >= 15 SbPlayerSeek(player, first_input_timestamp_, /* ticket */ 1); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, first_input_timestamp_, /* ticket */ 1); +#endif // SB_API_VERSION >= 15 WaitForPlayerState(kSbPlayerStatePresenting); // Wait until the playback time is > 0. const int64_t kMaxWaitTime = 5'000'000; // 5 seconds int64_t start_of_wait = CurrentMonotonicTime(); +#if SB_API_VERSION >= 15 SbPlayerInfo info = {}; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info = {}; +#endif // SB_API_VERSION >= 15 while (CurrentMonotonicTime() - start_of_wait < kMaxWaitTime && info.current_media_timestamp == 0) { usleep(500'000); +#if SB_API_VERSION >= 15 SbPlayerGetInfo(player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 } EXPECT_GT(info.current_media_timestamp, 0); @@ -215,7 +232,11 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteContinuedLimitedInput) { WaitForPlayerState(kSbPlayerStateInitialized); // Seek to preroll. +#if SB_API_VERSION >= 15 SbPlayerSeek(player, first_input_timestamp_, /* ticket */ 1); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, first_input_timestamp_, /* ticket */ 1); +#endif // SB_API_VERSION >= 15 WaitForPlayerState(kSbPlayerStatePresenting); // Wait for the player to play far enough. It may not play all the way to @@ -223,12 +244,20 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteContinuedLimitedInput) { int64_t min_ending_playback_time = total_duration_ - kDuration; int64_t start_of_wait = CurrentMonotonicTime(); const int64_t kMaxWaitTime = total_duration_ + 5'000'000LL; +#if SB_API_VERSION >= 15 SbPlayerInfo info; SbPlayerGetInfo(player, &info); - +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 while (info.current_media_timestamp < min_ending_playback_time && (CurrentMonotonicTime() - start_of_wait) < kMaxWaitTime) { +#if SB_API_VERSION >= 15 SbPlayerGetInfo(player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 usleep(kSmallWaitInterval); TryToWritePendingSample(); } diff --git a/starboard/nplb/player_test_fixture.cc b/starboard/nplb/player_test_fixture.cc index 30700e23cf45..6aaf93a8b958 100644 --- a/starboard/nplb/player_test_fixture.cc +++ b/starboard/nplb/player_test_fixture.cc @@ -250,7 +250,11 @@ void SbPlayerTestFixture::Seek(const int64_t time) { audio_end_of_stream_written_ = false; video_end_of_stream_written_ = false; +#if SB_API_VERSION >= 15 SbPlayerSeek(player_, time, ++ticket_); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player_, time, ++ticket_); +#endif // SB_API_VERSION >= 15 } void SbPlayerTestFixture::Write(const GroupedSamples& grouped_samples) { @@ -345,8 +349,13 @@ void SbPlayerTestFixture::WaitForPlayerEndOfStream() { } int64_t SbPlayerTestFixture::GetCurrentMediaTime() const { +#if SB_API_VERSION >= 15 SbPlayerInfo info = {}; SbPlayerGetInfo(player_, &info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info = {}; + SbPlayerGetInfo2(player_, &info); +#endif // SB_API_VERSION >= 15 return info.current_media_timestamp; } diff --git a/starboard/nplb/player_test_util.cc b/starboard/nplb/player_test_util.cc index 7fa84d067dca..a1e6e5d65db8 100644 --- a/starboard/nplb/player_test_util.cc +++ b/starboard/nplb/player_test_util.cc @@ -356,8 +356,13 @@ void CallSbPlayerWriteSamples( discarded_durations_from_back[i]; } } +#if SB_API_VERSION >= 15 SbPlayerWriteSamples(player, sample_type, sample_infos.data(), number_of_samples_to_write); +#else // SB_API_VERSION >= 15 + SbPlayerWriteSample2(player, sample_type, sample_infos.data(), + number_of_samples_to_write); +#endif // SB_API_VERSION >= 15 } bool IsOutputModeSupported(SbPlayerOutputMode output_mode, diff --git a/starboard/player.h b/starboard/player.h index b1afa9d5710e..835e0580e403 100644 --- a/starboard/player.h +++ b/starboard/player.h @@ -177,7 +177,11 @@ typedef struct SbPlayerSampleInfo { } SbPlayerSampleInfo; // Information about the current media playback state. +#if SB_API_VERSION >= 15 typedef struct SbPlayerInfo { +#else // SB_API_VERSION >= 15 +typedef struct SbPlayerInfo2 { +#endif // SB_API_VERSION >= 15 // The position of the playback head, as precisely as possible, in // microseconds. int64_t current_media_timestamp; @@ -222,7 +226,11 @@ typedef struct SbPlayerInfo { // is played in a slower than normal speed. Negative speeds are not // supported. double playback_rate; +#if SB_API_VERSION >= 15 } SbPlayerInfo; +#else // SB_API_VERSION >= 15 +} SbPlayerInfo2; +#endif // SB_API_VERSION >= 15 // An opaque handle to an implementation-private structure representing a // player. @@ -466,9 +474,15 @@ SB_EXPORT void SbPlayerDestroy(SbPlayer player); // when SbPlayerSeek was called. To be very specific, once SbPlayerSeek has // been called with ticket X, a client should ignore all // |SbPlayerDecoderStatusFunc| calls that do not pass in ticket X. +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket); +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerSeek2(SbPlayer player, + int64_t seek_to_timestamp, + int ticket); +#endif // SB_API_VERSION >= 15 // Writes samples of the given media type to |player|'s input stream. The // lifetime of |sample_infos|, and the members of its elements like |buffer|, @@ -496,7 +510,11 @@ SB_EXPORT void SbPlayerSeek(SbPlayer player, // |number_of_sample_infos|: Specify the number of samples contained inside // |sample_infos|. It has to be at least one, and at most the return value // of SbPlayerGetMaximumNumberOfSamplesPerWrite(). +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos); @@ -592,7 +610,12 @@ SB_EXPORT void SbPlayerSetVolume(SbPlayer player, double volume); // |kSbPlayerInvalid|. // // |out_player_info|: The information retrieved for the player. +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info); +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerGetInfo2(SbPlayer player, + SbPlayerInfo2* out_player_info2); +#endif // SB_API_VERSION >= 15 // Given a player created with the kSbPlayerOutputModeDecodeToTexture // output mode, it will return a SbDecodeTarget representing the current frame diff --git a/starboard/shared/enhanced_audio/enhanced_audio.cc b/starboard/shared/enhanced_audio/enhanced_audio.cc new file mode 100644 index 000000000000..e12190872583 --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.cc @@ -0,0 +1,46 @@ +// Copyright 2023 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 "starboard/shared/enhanced_audio/enhanced_audio.h" + +#include "starboard/common/log.h" +#include "starboard/extension/enhanced_audio.h" +#include "starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h" + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +#if SB_API_VERSION < 15 + +namespace { + +const CobaltExtensionEnhancedAudioApi kEnhancedAudioApi = { + kCobaltExtensionEnhancedAudioName, + 1, + &EnhancedAudioPlayerWriteSamples, +}; + +} // namespace + +const void* GetEnhancedAudioApi() { + SB_LOG(INFO) << "EnhancedAudio extension enabled."; + return &kEnhancedAudioApi; +} + +#endif // SB_API_VERSION < 15 + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard diff --git a/starboard/shared/enhanced_audio/enhanced_audio.gni b/starboard/shared/enhanced_audio/enhanced_audio.gni new file mode 100644 index 000000000000..03588b8ce57b --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.gni @@ -0,0 +1,21 @@ +# Copyright 2023 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. + +enhanced_audio_sources = [ + "//starboard/shared/enhanced_audio/enhanced_audio.cc", + "//starboard/shared/enhanced_audio/enhanced_audio.h", + "//starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc", + "//starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h", + "//starboard/shared/enhanced_audio/player_write_samples_checked.cc", +] diff --git a/starboard/shared/enhanced_audio/enhanced_audio.h b/starboard/shared/enhanced_audio/enhanced_audio.h new file mode 100644 index 000000000000..19f0729a3b2f --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.h @@ -0,0 +1,28 @@ +// Copyright 2023 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 STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ +#define STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +const void* GetEnhancedAudioApi(); + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ diff --git a/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc new file mode 100644 index 000000000000..351e19e3489e --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc @@ -0,0 +1,59 @@ +// Copyright 2023 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 "starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h" + +#include "starboard/common/log.h" +#include "starboard/shared/starboard/player/player_internal.h" + +#if SB_API_VERSION < 15 + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +void EnhancedAudioPlayerWriteSamples( + SbPlayer player, + SbMediaType sample_type, + const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos, + int number_of_sample_infos) { + if (!SbPlayerIsValid(player)) { + SB_LOG(WARNING) << "player is invalid."; + return; + } + if (!sample_infos) { + SB_LOG(WARNING) << "sample_infos is null."; + return; + } + if (number_of_sample_infos < 1) { + SB_LOG(WARNING) << "number_of_sample_infos is " << number_of_sample_infos + << ", which should be greater than or equal to 1"; + return; + } + auto max_samples_per_write = + SbPlayerGetMaximumNumberOfSamplesPerWrite(player, sample_type); + if (number_of_sample_infos > max_samples_per_write) { + SB_LOG(WARNING) << "number_of_sample_infos is " << number_of_sample_infos + << ", which should be less than or equal to " + << max_samples_per_write; + } + + player->WriteSamples(sample_infos, number_of_sample_infos); +} + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // SB_API_VERSION < 15 diff --git a/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h new file mode 100644 index 000000000000..2f9e8e324aa2 --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h @@ -0,0 +1,41 @@ +// Copyright 2023 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 STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ +#define STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ + +#include "starboard/extension/enhanced_audio.h" + +#include "starboard/media.h" +#include "starboard/player.h" + +#if SB_API_VERSION < 15 + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +void EnhancedAudioPlayerWriteSamples( + SbPlayer player, + SbMediaType sample_type, + const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos, + int number_of_sample_infos); + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // SB_API_VERSION < 15 + +#endif // STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ diff --git a/starboard/shared/enhanced_audio/player_write_samples_checked.cc b/starboard/shared/enhanced_audio/player_write_samples_checked.cc new file mode 100644 index 000000000000..275c0b05ceac --- /dev/null +++ b/starboard/shared/enhanced_audio/player_write_samples_checked.cc @@ -0,0 +1,31 @@ +// Copyright 2023 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 "starboard/player.h" + +#include "starboard/common/log.h" + +// Special implementation of `SbPlayerWriteSample2()` for EnhancedAudio, where +// all sample writes should use the `PlayerWriteSamples()` function provided by +// the EnhancedAudio extension. +#if SB_API_VERSION < 15 + +void SbPlayerWriteSample2(SbPlayer player, + SbMediaType sample_type, + const SbPlayerSampleInfo* sample_infos, + int number_of_sample_infos) { + SB_NOTREACHED(); +} + +#endif // SB_API_VERSION < 15 diff --git a/starboard/shared/starboard/player/player_get_info.cc b/starboard/shared/starboard/player/player_get_info.cc index c16baa73ccca..7c1659d97161 100644 --- a/starboard/shared/starboard/player/player_get_info.cc +++ b/starboard/shared/starboard/player/player_get_info.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info) { +#else // SB_API_VERSION >= 15 +void SbPlayerGetInfo2(SbPlayer player, SbPlayerInfo2* out_player_info) { +#endif // SB_API_VERSION >= 15 if (!SbPlayerIsValid(player)) { SB_DLOG(WARNING) << "player is invalid."; return; diff --git a/starboard/shared/starboard/player/player_internal.cc b/starboard/shared/starboard/player/player_internal.cc index be054943a366..225d4a8d96ae 100644 --- a/starboard/shared/starboard/player/player_internal.cc +++ b/starboard/shared/starboard/player/player_internal.cc @@ -116,7 +116,11 @@ void SbPlayerPrivate::SetBounds(int z_index, // TODO: Wait until a frame is rendered with the updated bounds. } +#if SB_API_VERSION >= 15 void SbPlayerPrivate::GetInfo(SbPlayerInfo* out_player_info) { +#else // SB_API_VERSION >= 15 +void SbPlayerPrivate::GetInfo(SbPlayerInfo2* out_player_info) { +#endif // SB_API_VERSION >= 15 SB_DCHECK(out_player_info != NULL); starboard::ScopedLock lock(mutex_); diff --git a/starboard/shared/starboard/player/player_internal.h b/starboard/shared/starboard/player/player_internal.h index 1aa6026fd583..05d64a11886a 100644 --- a/starboard/shared/starboard/player/player_internal.h +++ b/starboard/shared/starboard/player/player_internal.h @@ -54,7 +54,11 @@ struct SbPlayerPrivate { void WriteEndOfStream(SbMediaType stream_type); void SetBounds(int z_index, int x, int y, int width, int height); +#if SB_API_VERSION >= 15 void GetInfo(SbPlayerInfo* out_player_info); +#else // SB_API_VERSION >= 15 + void GetInfo(SbPlayerInfo2* out_player_info); +#endif // SB_API_VERSION >= 15 void SetPause(bool pause); void SetPlaybackRate(double playback_rate); void SetVolume(double volume); diff --git a/starboard/shared/starboard/player/player_seek.cc b/starboard/shared/starboard/player/player_seek.cc index 694fcd80476d..9b1281488bbc 100644 --- a/starboard/shared/starboard/player/player_seek.cc +++ b/starboard/shared/starboard/player/player_seek.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket) { +#else // SB_API_VERSION >= 15 +void SbPlayerSeek2(SbPlayer player, int64_t seek_to_timestamp, int ticket) { +#endif // SB_API_VERSION >= 15 if (!SbPlayerIsValid(player)) { SB_DLOG(WARNING) << "player is invalid."; return; diff --git a/starboard/shared/starboard/player/player_write_samples.cc b/starboard/shared/starboard/player/player_write_samples.cc index 73dfeb2fd0f5..37c66692e443 100644 --- a/starboard/shared/starboard/player/player_write_samples.cc +++ b/starboard/shared/starboard/player/player_write_samples.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos) { diff --git a/starboard/shared/stub/player_get_info.cc b/starboard/shared/stub/player_get_info.cc index 04c38acde0ca..f368ccbd9412 100644 --- a/starboard/shared/stub/player_get_info.cc +++ b/starboard/shared/stub/player_get_info.cc @@ -14,4 +14,8 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info) {} +#else // SB_API_VERSION >= 15 +void SbPlayerGetInfo2(SbPlayer player, SbPlayerInfo2* out_player_info) {} +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/stub/player_seek.cc b/starboard/shared/stub/player_seek.cc index ad5c70435951..43acbe2b842b 100644 --- a/starboard/shared/stub/player_seek.cc +++ b/starboard/shared/stub/player_seek.cc @@ -14,4 +14,8 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket) {} +#else // SB_API_VERSION >= 15 +void SbPlayerSeek2(SbPlayer player, int64_t seek_to_timestamp, int ticket) {} +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/stub/player_write_samples.cc b/starboard/shared/stub/player_write_samples.cc index a732cf7ca557..ef08d173b896 100644 --- a/starboard/shared/stub/player_write_samples.cc +++ b/starboard/shared/stub/player_write_samples.cc @@ -14,7 +14,12 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, - int number_of_sample_infos) {} + int number_of_sample_infos) { +}