Skip to content

Commit

Permalink
Add decode to texture preferred option (#3011)
Browse files Browse the repository at this point in the history
b/311035005
  • Loading branch information
jasonzhangxx authored Apr 22, 2024
1 parent b8835a8 commit aada42d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
22 changes: 22 additions & 0 deletions cobalt/media/base/sbplayer_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@
#include <string>

#include "base/logging.h"
#include "starboard/extension/player_configuration.h"
#include "starboard/system.h"

namespace cobalt {
namespace media {

void SbPlayerInterface::SetDecodeToTexturePreferred(bool preferred) {
const StarboardExtensionPlayerConfigurationApi* extension_api =
static_cast<const StarboardExtensionPlayerConfigurationApi*>(
SbSystemGetExtension(kStarboardExtensionPlayerConfigurationName));
if (!extension_api) {
return;
}

DCHECK_EQ(extension_api->name,
// Avoid comparing raw string pointers for equal.
std::string(kStarboardExtensionPlayerConfigurationName));
DCHECK_EQ(extension_api->version, 1u);

// SetDecodeToTexturePreferred api could be NULL.
if (extension_api->SetDecodeToTexturePreferred) {
extension_api->SetDecodeToTexturePreferred(preferred);
} else {
LOG(INFO) << "DecodeToTextureModePreferred is not supported.";
}
}

DefaultSbPlayerInterface::DefaultSbPlayerInterface() {
const CobaltExtensionEnhancedAudioApi* extension_api =
static_cast<const CobaltExtensionEnhancedAudioApi*>(
Expand Down
2 changes: 2 additions & 0 deletions cobalt/media/base/sbplayer_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class SbPlayerInterface {
}
CValStats cval_stats_;
MediaMetricsProvider media_metrics_provider_;

void SetDecodeToTexturePreferred(bool preferred);
};

class DefaultSbPlayerInterface final : public SbPlayerInterface {
Expand Down
5 changes: 5 additions & 0 deletions cobalt/media/media_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ bool MediaModule::SetConfiguration(const std::string& name, int32 value) {
<< audio_write_duration_remote_.InMicroseconds();
return true;
#endif // SB_API_VERSION >= 15
} else if (name == "PlayerConfiguration.DecodeToTexturePreferred") {
sbplayer_interface_->SetDecodeToTexturePreferred(value);
LOG(INFO) << "Set DecodeToTexturePreferred to "
<< (value ? "true" : "false");
return true;
}

return false;
Expand Down
12 changes: 6 additions & 6 deletions starboard/extension/extension_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,13 @@ TEST(ExtensionTest, PlayerConfiguration) {
EXPECT_STREQ(extension_api->name, kExtensionName);
EXPECT_EQ(extension_api->version, 1u);

if (extension_api->SetEnforceDecodeToTextureMode) {
extension_api->SetEnforceDecodeToTextureMode(true);
extension_api->SetEnforceDecodeToTextureMode(false);
if (extension_api->SetDecodeToTexturePreferred) {
extension_api->SetDecodeToTexturePreferred(true);
extension_api->SetDecodeToTexturePreferred(false);
}
if (extension_api->SetEnforceTunnelMode) {
extension_api->SetEnforceTunnelMode(true);
extension_api->SetEnforceTunnelMode(false);
if (extension_api->SetTunnelModePreferred) {
extension_api->SetTunnelModePreferred(true);
extension_api->SetTunnelModePreferred(false);
}
}

Expand Down
8 changes: 4 additions & 4 deletions starboard/extension/player_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ typedef struct StarboardExtensionPlayerConfigurationApi {

// The fields below this point were added in version 1 or later.

// This is used to enforce the underlying starboard player using decode
// This is used to ask the underlying starboard player using decode
// to texture mode to render video frames when it's available, no matter
// what output mode is passed in SbPlayerCreate(). This function can be
// null.
void (*SetEnforceDecodeToTextureMode)(bool enforced);
void (*SetDecodeToTexturePreferred)(bool preferred);

// This is used to enforce the underlying starboard player using tunnel mode
// This is used to ask the underlying starboard player using tunnel mode
// when it's available. This function can be null.
void (*SetEnforceTunnelMode)(bool enforced);
void (*SetTunnelModePreferred)(bool preferred);

} StarboardExtensionPlayerConfigurationApi;

Expand Down

0 comments on commit aada42d

Please sign in to comment.