Skip to content

Commit

Permalink
Cherry pick PR #3011: Add decode to texture preferred option (#3039)
Browse files Browse the repository at this point in the history
Refer to the original PR: #3011

b/311035005

---------

Co-authored-by: Jason <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and jasonzhangxx committed Apr 23, 2024
1 parent 638ef66 commit 160902e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 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 @@ -92,6 +92,8 @@ class SbPlayerInterface {
cval_stats_.Enable(should_enable);
}
CValStats cval_stats_;

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_;
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
24 changes: 24 additions & 0 deletions starboard/extension/extension_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "starboard/extension/memory_mapped_file.h"
#include "starboard/extension/platform_info.h"
#include "starboard/extension/platform_service.h"
#include "starboard/extension/player_configuration.h"
#include "starboard/extension/player_set_max_video_input_size.h"
#include "starboard/extension/time_zone.h"
#include "starboard/extension/updater_notification.h"
Expand Down Expand Up @@ -503,5 +504,28 @@ TEST(ExtensionTest, PlayerSetMaxVideoInputSize) {
<< "Extension struct should be a singleton";
}

TEST(ExtensionTest, PlayerConfiguration) {
typedef StarboardExtensionPlayerConfigurationApi ExtensionApi;
const char* kExtensionName = kStarboardExtensionPlayerConfigurationName;

const ExtensionApi* extension_api =
static_cast<const ExtensionApi*>(SbSystemGetExtension(kExtensionName));
if (!extension_api) {
return;
}

EXPECT_STREQ(extension_api->name, kExtensionName);
EXPECT_EQ(extension_api->version, 1u);

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

} // namespace extension
} // namespace starboard
51 changes: 51 additions & 0 deletions starboard/extension/player_configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef STARBOARD_EXTENSION_PLAYER_CONFIGURATION_H_
#define STARBOARD_EXTENSION_PLAYER_CONFIGURATION_H_

#ifdef __cplusplus
extern "C" {
#endif

#define kStarboardExtensionPlayerConfigurationName \
"dev.starboard.extension.PlayerConfiguration"

typedef struct StarboardExtensionPlayerConfigurationApi {
// Name should be the string kStarboardExtensionPlayerConfigurationName.
// This helps to validate that the extension API is correct.
const char* name;

// This specifies the version of the API that is implemented.
uint32_t version;

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

// 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 (*SetDecodeToTexturePreferred)(bool preferred);

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

} StarboardExtensionPlayerConfigurationApi;

#ifdef __cplusplus
} // extern "C"
#endif

#endif // STARBOARD_EXTENSION_PLAYER_CONFIGURATION_H_

0 comments on commit 160902e

Please sign in to comment.