Skip to content

Commit

Permalink
[nplb] Enable SbMediaSetAudioWriteDurationTests
Browse files Browse the repository at this point in the history
b/268744146
  • Loading branch information
jasonzhangxx committed Jun 15, 2023
1 parent ea69d45 commit 9f91472
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions starboard/nplb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ target(gtest_target_type, "nplb") {
"media_buffer_test.cc",
"media_can_play_mime_and_key_system_test.cc",
"media_configuration_test.cc",
"media_set_audio_write_duration_test.cc",
"memory_allocate_aligned_test.cc",
"memory_allocate_test.cc",
"memory_deallocate_aligned_test.cc",
Expand Down
54 changes: 27 additions & 27 deletions starboard/nplb/media_set_audio_write_duration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
#include "starboard/testing/fake_graphics_context_provider.h"
#include "testing/gtest/include/gtest/gtest.h"

#if SB_API_VERSION < 15

namespace starboard {
namespace nplb {
namespace {

using ::shared::starboard::player::video_dmp::VideoDmpReader;
using shared::starboard::player::video_dmp::VideoDmpReader;
using ::starboard::testing::FakeGraphicsContextProvider;
using ::testing::ValuesIn;

Expand All @@ -42,8 +40,7 @@ const SbTime kSmallWaitInterval = 10 * kSbTimeMillisecond;
class SbMediaSetAudioWriteDurationTest
: public ::testing::TestWithParam<const char*> {
public:
SbMediaSetAudioWriteDurationTest()
: dmp_reader_(ResolveTestFileName(GetParam()).c_str()) {}
SbMediaSetAudioWriteDurationTest() : dmp_reader_(GetParam()) {}

void TryToWritePendingSample() {
{
Expand Down Expand Up @@ -79,11 +76,11 @@ class SbMediaSetAudioWriteDurationTest
pending_decoder_status_ = nullopt;
}

CallSbPlayerWriteSamples(player, kSbMediaTypeAudio, dmp_reader_.get(),
index_, 1);
CallSbPlayerWriteSamples(player, kSbMediaTypeAudio, &dmp_reader_, index_,
1);
last_input_timestamp_ =
dmp_reader_.GetPlayerSampleInfo(kSbMediaTypeAudio, index_).timestamp;
++index_;

last_input_timestamp_ = player_sample_info.timestamp;
}

void PlayerStatus(SbPlayer player, SbPlayerState state, int ticket) {
Expand All @@ -103,27 +100,30 @@ class SbMediaSetAudioWriteDurationTest
}

SbPlayer CreatePlayer() {
SbMediaAudioSampleInfo audio_sample_info = dmp_reader_.audio_sample_info();
SbMediaAudioCodec kAudioCodec = dmp_reader_.audio_codec();
SbDrmSystem kDrmSystem = kSbDrmSystemInvalid;
SbMediaAudioCodec audio_codec = dmp_reader_.audio_codec();

last_input_timestamp_ =
dmp_reader_.GetPlayerSampleInfo(kSbMediaTypeAudio, 0).timestamp;
first_input_timestamp_ = last_input_timestamp_;
PlayerCreationParam creation_param = CreatePlayerCreationParam(
audio_codec, kSbMediaVideoCodecNone, kSbPlayerOutputModeInvalid);

SbPlayerCreationParam param = {};
creation_param.ConvertTo(&param);

SbPlayerCreationParam creation_param = CreatePlayerCreationParam(
audio_sample_info.codec, kSbMediaVideoCodecNone,
SbPlayerGetPreferredOutputMode(&creation_param));
creation_param.audio_sample_info = audio_sample_info;
creation_param.output_mode = SbPlayerGetPreferredOutputMode(&param);
EXPECT_NE(creation_param.output_mode, kSbPlayerOutputModeInvalid);

SbPlayer player = SbPlayerCreate(
fake_graphics_context_provider_.window(), &creation_param,
SbPlayer player = CallSbPlayerCreate(
fake_graphics_context_provider_.window(), kSbMediaVideoCodecNone,
audio_codec, kSbDrmSystemInvalid, &dmp_reader_.audio_stream_info(), "",
DummyDeallocateSampleFunc, DecoderStatusFunc, PlayerStatusFunc,
DummyErrorFunc, this /* context */,
DummyErrorFunc, this /* context */, creation_param.output_mode,
fake_graphics_context_provider_.decoder_target_provider());

EXPECT_TRUE(SbPlayerIsValid(player));

last_input_timestamp_ =
dmp_reader_.GetPlayerSampleInfo(kSbMediaTypeAudio, 0).timestamp;
first_input_timestamp_ = last_input_timestamp_;

return player;
}

Expand Down Expand Up @@ -183,7 +183,9 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteLimitedInput) {
ASSERT_NE(dmp_reader_.audio_codec(), kSbMediaAudioCodecNone);
ASSERT_GT(dmp_reader_.number_of_audio_buffers(), 0);

#if SB_API_VERSION < 15
SbMediaSetAudioWriteDuration(kDuration);
#endif // SB_API_VERSION < 15

SbPlayer player = CreatePlayer();
WaitForPlayerState(kSbPlayerStateInitialized);
Expand Down Expand Up @@ -224,7 +226,9 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteContinuedLimitedInput) {
ASSERT_NE(dmp_reader_.audio_codec(), kSbMediaAudioCodecNone);
ASSERT_GT(dmp_reader_.number_of_audio_buffers(), 0);

#if SB_API_VERSION < 15
SbMediaSetAudioWriteDuration(kDuration);
#endif // SB_API_VERSION < 15

// This directly impacts the runtime of the test.
total_duration_ = 15 * kSbTimeSecond;
Expand Down Expand Up @@ -277,11 +281,9 @@ std::vector<const char*> GetSupportedTests() {
}

for (auto filename : kFilenames) {
VideoDmpReader dmp_reader(ResolveTestFileName(filename).c_str());
VideoDmpReader dmp_reader(filename);
SB_DCHECK(dmp_reader.number_of_audio_buffers() > 0);

const SbMediaAudioSampleInfo* audio_sample_info =
&dmp_reader.audio_sample_info();
if (SbMediaIsAudioSupported(dmp_reader.audio_codec(), nullptr,
dmp_reader.audio_bitrate())) {
test_params.push_back(filename);
Expand All @@ -297,5 +299,3 @@ INSTANTIATE_TEST_CASE_P(SbMediaSetAudioWriteDurationTests,
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION < 15

0 comments on commit 9f91472

Please sign in to comment.