Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[media] Create SbPlayerState utility function #4668

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions media/starboard/starboard_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include "media/base/audio_codecs.h"
#include "media/base/video_codecs.h"
#include "starboard/common/media.h"
#include "starboard/common/player.h"

namespace media {

namespace {

using ::starboard::GetMediaAudioConnectorName;
using ::starboard::GetPlayerStateName;

// In the OnNeedData(), it attempts to write one more audio access
// unit than the audio write duration. Specifically, the check
Expand Down Expand Up @@ -762,19 +764,21 @@ void StarboardRenderer::OnNeedData(DemuxerStream::Type type,
void StarboardRenderer::OnPlayerStatus(SbPlayerState state) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());

static auto log_player_state = [](SbPlayerState state) {
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with "
osagie98 marked this conversation as resolved.
Show resolved Hide resolved
<< GetPlayerStateName(state);
};

// In case if state is changed when creation of the `player_bridge_` fails.
// We may also need this for suspend/resume support.
if (!player_bridge_) {
// TODO(b/376316272): Turn `state` into its string form and consolidate all
// player state loggings below.
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with " << state;
log_player_state(state);
return;
}

switch (state) {
case kSbPlayerStateInitialized:
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with "
"kSbPlayerStateInitialized.";
log_player_state(state);
DCHECK(!player_bridge_initialized_);
player_bridge_initialized_ = true;

Expand All @@ -783,8 +787,7 @@ void StarboardRenderer::OnPlayerStatus(SbPlayerState state) {
}
break;
case kSbPlayerStatePrerolling:
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with "
"kSbPlayerStatePrerolling.";
log_player_state(state);
DCHECK(player_bridge_initialized_);
break;
case kSbPlayerStatePresenting:
Expand All @@ -794,19 +797,17 @@ void StarboardRenderer::OnPlayerStatus(SbPlayerState state) {
HasRemoteAudioOutputs(player_bridge_->GetAudioConfigurations())
? audio_write_duration_remote_
: audio_write_duration_local_;
LOG(INFO) << "SbPlayerBridge reaches kSbPlayerStatePresenting, with audio"
<< " write duration at " << audio_write_duration_;
LOG(INFO) << "SbPlayerBridge reaches " << GetPlayerStateName(state)
<< ", with audio write duration at " << audio_write_duration_;
DCHECK(player_bridge_initialized_);
break;
case kSbPlayerStateEndOfStream:
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with "
"kSbPlayerStateEndOfStream.";
log_player_state(state);
DCHECK(player_bridge_initialized_);
client_->OnEnded();
break;
case kSbPlayerStateDestroyed:
LOG(INFO) << "StarboardRenderer::OnPlayerStatus() called with "
"kSbPlayerStateDestroyed.";
log_player_state(state);
break;
}
}
Expand Down
18 changes: 18 additions & 0 deletions starboard/common/player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ const char* GetPlayerOutputModeName(SbPlayerOutputMode output_mode) {
return "invalid";
}

const char* GetPlayerStateName(SbPlayerState state) {
switch (state) {
case kSbPlayerStateInitialized:
return "kSbPlayerStateInitialized";
case kSbPlayerStatePrerolling:
return "kSbPlayerStatePrerolling";
case kSbPlayerStatePresenting:
return "kSbPlayerStatePresenting";
case kSbPlayerStateEndOfStream:
return "kSbPlayerStateEndOfStream";
case kSbPlayerStateDestroyed:
return "kSbPlayerStateDestroyed";
}

SB_NOTREACHED();
return "invalid";
}

} // namespace starboard
2 changes: 2 additions & 0 deletions starboard/common/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace starboard {

const char* GetPlayerOutputModeName(SbPlayerOutputMode output_mode);

const char* GetPlayerStateName(SbPlayerState state);

} // namespace starboard

#endif // STARBOARD_COMMON_PLAYER_H_
13 changes: 13 additions & 0 deletions starboard/common/player_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,18 @@ TEST(PlayerTest, GetPlayerOutputModeName) {
ASSERT_STREQ(GetPlayerOutputModeName(kSbPlayerOutputModeInvalid), "invalid");
}

TEST(PlayerTest, GetPlayerStateName) {
ASSERT_STREQ(GetPlayerStateName(kSbPlayerStateInitialized),
"kSbPlayerStateInitialized");
ASSERT_STREQ(GetPlayerStateName(kSbPlayerStatePrerolling),
"kSbPlayerStatePrerolling");
ASSERT_STREQ(GetPlayerStateName(kSbPlayerStatePresenting),
"kSbPlayerStatePresenting");
ASSERT_STREQ(GetPlayerStateName(kSbPlayerStateEndOfStream),
"kSbPlayerStateEndOfStream");
ASSERT_STREQ(GetPlayerStateName(kSbPlayerStateDestroyed),
"kSbPlayerStateDestroyed");
}

} // namespace
} // namespace starboard
Loading