From df60499730fb80c33ad81d6e9ee54b07ce6e19c2 Mon Sep 17 00:00:00 2001 From: Bo-Rong Chen Date: Tue, 5 Sep 2023 22:25:04 +0000 Subject: [PATCH] Allow DecodedAudio ctor to accept a Buffer object b/275199195 --- .../player/decoded_audio_internal.cc | 20 +++++++++++++++++++ .../starboard/player/decoded_audio_internal.h | 7 +++++++ .../player/decoded_audio_test_internal.cc | 18 +++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/starboard/shared/starboard/player/decoded_audio_internal.cc b/starboard/shared/starboard/player/decoded_audio_internal.cc index 2834bc225e53..18a525f558fe 100644 --- a/starboard/shared/starboard/player/decoded_audio_internal.cc +++ b/starboard/shared/starboard/player/decoded_audio_internal.cc @@ -73,6 +73,26 @@ DecodedAudio::DecodedAudio(int channels, // 0); } +DecodedAudio::DecodedAudio(int channels, + SbMediaAudioSampleType sample_type, + SbMediaAudioFrameStorageType storage_type, + SbTime timestamp, + int size_in_bytes, + Buffer&& storage) + : channels_(channels), + sample_type_(sample_type), + storage_type_(storage_type), + timestamp_(timestamp), + storage_(std::move(storage)), + offset_in_bytes_(0), + size_in_bytes_(size_in_bytes) { + SB_DCHECK(channels_ > 0); + SB_DCHECK(size_in_bytes_ >= 0); + // TODO(b/275199195): Enable the SB_DCHECK below. + SB_DCHECK(size_in_bytes_ % (GetBytesPerSample(sample_type_) * channels_) == + 0); +} + int DecodedAudio::frames() const { int bytes_per_sample = GetBytesPerSample(sample_type_); SB_DCHECK(size_in_bytes_ % (bytes_per_sample * channels_) == 0); diff --git a/starboard/shared/starboard/player/decoded_audio_internal.h b/starboard/shared/starboard/player/decoded_audio_internal.h index 8aff07173ac2..0e9d20de625c 100644 --- a/starboard/shared/starboard/player/decoded_audio_internal.h +++ b/starboard/shared/starboard/player/decoded_audio_internal.h @@ -42,6 +42,13 @@ class DecodedAudio : public RefCountedThreadSafe { SbTime timestamp, int size_in_bytes); + DecodedAudio(int channels, + SbMediaAudioSampleType sample_type, + SbMediaAudioFrameStorageType storage_type, + SbTime timestamp, + int size_in_bytes, + Buffer&& storage); + int channels() const { return channels_; } SbMediaAudioSampleType sample_type() const { return sample_type_; } SbMediaAudioFrameStorageType storage_type() const { return storage_type_; } diff --git a/starboard/shared/starboard/player/decoded_audio_test_internal.cc b/starboard/shared/starboard/player/decoded_audio_test_internal.cc index a1e2cd20b37f..302927d68589 100644 --- a/starboard/shared/starboard/player/decoded_audio_test_internal.cc +++ b/starboard/shared/starboard/player/decoded_audio_test_internal.cc @@ -207,6 +207,24 @@ TEST(DecodedAudioTest, CtorWithSize) { } } +TEST(DecodedAudioTest, CtorWithMoveCtor) { + Buffer original(128); + memset(original.data(), 'x', 128); + + const uint8_t* original_data_pointer = original.data(); + + scoped_refptr decoded_audio( + new DecodedAudio(kChannels, kSampleTypes[0], kStorageTypes[0], kTimestamp, + 128, std::move(original))); + ASSERT_EQ(decoded_audio->size_in_bytes(), 128); + ASSERT_NE(decoded_audio->data(), nullptr); + ASSERT_EQ(decoded_audio->data(), original_data_pointer); + + for (int i = 0; i < decoded_audio->size_in_bytes(); ++i) { + ASSERT_EQ(decoded_audio->data()[i], 'x'); + } +} + TEST(DecodedAudioTest, AdjustForSeekTime) { for (int channels = 1; channels <= 6; ++channels) { for (auto sample_type : kSampleTypes) {