Skip to content

Commit

Permalink
[media] Create SbPlayerState utility function
Browse files Browse the repository at this point in the history
Creates GetPlayerStateName(), which will return the name of the passed
SbPlayerState as a const char*.

b/376316272
  • Loading branch information
osagie98 committed Jan 8, 2025
1 parent f1505ad commit 8546f3e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
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 "
<< 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

0 comments on commit 8546f3e

Please sign in to comment.