Skip to content

Commit

Permalink
Allow DecodedAudio ctor to accept a Buffer object
Browse files Browse the repository at this point in the history
b/275199195
  • Loading branch information
borongc committed Sep 5, 2023
1 parent efcc55c commit df60499
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions starboard/shared/starboard/player/decoded_audio_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions starboard/shared/starboard/player/decoded_audio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class DecodedAudio : public RefCountedThreadSafe<DecodedAudio> {
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_; }
Expand Down
18 changes: 18 additions & 0 deletions starboard/shared/starboard/player/decoded_audio_test_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecodedAudio> 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) {
Expand Down

0 comments on commit df60499

Please sign in to comment.