blob: 2cc0f215e077ced7ce3a6314693deb1b2c879b27 [file] [log] [blame]
// Copyright 2017 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.
#include "starboard/decode_target.h"
#include "starboard/player.h"
#if SB_HAS(PLAYER_WITH_URL)
#include "starboard/shared/uikit/url_player.h"
#endif // SB_HAS(PLAYER_WITH_URL)
#include "starboard/window.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace starboard {
namespace nplb {
namespace {
#if SB_HAS(PLAYER_WITH_URL)
const char kPlayerUrl[] = "about:blank";
void DummyPlayerStatusFunc(SbPlayer player,
void* context,
SbPlayerState state,
int ticket) {}
void DummyEncryptedMediaInitaDataEncounteredFunc(
SbPlayer player,
void* context,
const char* init_data_type,
const unsigned char* init_data,
unsigned int init_data_length) {}
void DummyPlayerErrorFunc(SbPlayer player,
void* context,
SbPlayerError error,
const char* message) {}
TEST(SbPlayerUrlTest, SunnyDay) {
SbWindowOptions window_options;
SbWindowSetDefaultOptions(&window_options);
SbWindow window = SbWindowCreate(&window_options);
EXPECT_TRUE(SbWindowIsValid(window));
SbPlayerOutputMode output_modes[] = {kSbPlayerOutputModeDecodeToTexture,
kSbPlayerOutputModePunchOut};
for (int i = 0; i < SB_ARRAY_SIZE_INT(output_modes); ++i) {
SbPlayerOutputMode output_mode = output_modes[i];
if (!SbUrlPlayerOutputModeSupported(output_mode)) {
continue;
}
SbPlayer player =
SbUrlPlayerCreate(kPlayerUrl, window, DummyPlayerStatusFunc,
DummyEncryptedMediaInitaDataEncounteredFunc,
DummyPlayerErrorFunc, NULL);
EXPECT_TRUE(SbPlayerIsValid(player));
if (output_mode == kSbPlayerOutputModeDecodeToTexture) {
SbDecodeTarget current_frame = SbPlayerGetCurrentFrame(player);
}
SbPlayerDestroy(player);
}
SbWindowDestroy(window);
}
TEST(SbPlayerUrlTest, NullCallbacks) {
SbWindowOptions window_options;
SbWindowSetDefaultOptions(&window_options);
SbWindow window = SbWindowCreate(&window_options);
EXPECT_TRUE(SbWindowIsValid(window));
SbMediaVideoCodec kVideoCodec = kSbMediaVideoCodecH264;
SbDrmSystem kDrmSystem = kSbDrmSystemInvalid;
SbPlayerOutputMode output_modes[] = {kSbPlayerOutputModeDecodeToTexture,
kSbPlayerOutputModePunchOut};
for (int i = 0; i < SB_ARRAY_SIZE_INT(output_modes); ++i) {
SbPlayerOutputMode output_mode = output_modes[i];
if (!SbUrlPlayerOutputModeSupported(output_mode)) {
continue;
}
{
SbPlayer player =
SbUrlPlayerCreate(kPlayerUrl, window, NULL /* player_status_func */,
DummyEncryptedMediaInitaDataEncounteredFunc,
DummyPlayerErrorFunc, NULL /* context */);
EXPECT_FALSE(SbPlayerIsValid(player));
SbPlayerDestroy(player);
}
{
SbPlayer player = SbUrlPlayerCreate(
kPlayerUrl, window, DummyPlayerStatusFunc,
NULL /* encrypted_media_inita_data_encountered_func */,
DummyPlayerErrorFunc, NULL /* context */);
EXPECT_FALSE(SbPlayerIsValid(player));
SbPlayerDestroy(player);
}
{
SbPlayer player =
SbUrlPlayerCreate(kPlayerUrl, window, DummyPlayerStatusFunc,
DummyEncryptedMediaInitaDataEncounteredFunc,
NULL /* player_error_func */, NULL /* context */);
EXPECT_FALSE(SbPlayerIsValid(player));
SbPlayerDestroy(player);
}
}
}
TEST(SbPlayerUrlTest, MultiPlayer) {
SbWindowOptions window_options;
SbWindowSetDefaultOptions(&window_options);
SbWindow window = SbWindowCreate(&window_options);
EXPECT_TRUE(SbWindowIsValid(window));
SbPlayerOutputMode output_modes[] = {kSbPlayerOutputModeDecodeToTexture,
kSbPlayerOutputModePunchOut};
for (int i = 0; i < SB_ARRAY_SIZE_INT(output_modes); ++i) {
SbPlayerOutputMode output_mode = output_modes[i];
if (!SbUrlPlayerOutputModeSupported(output_mode)) {
continue;
}
const int kMaxPlayers = 16;
std::vector<SbPlayer> created_players;
for (int j = 0; j < kMaxPlayers; ++j) {
created_players.push_back(
SbUrlPlayerCreate(kPlayerUrl, window, NULL, NULL, NULL, NULL));
if (!SbPlayerIsValid(created_players[j])) {
created_players.pop_back();
break;
}
}
SB_DLOG(INFO) << "Created " << created_players.size()
<< " valid players for output mode " << output_mode;
for (auto player : created_players) {
SbPlayerDestroy(player);
}
}
SbWindowDestroy(window);
}
#endif // SB_HAS(PLAYER_WITH_URL)
} // namespace
} // namespace nplb
} // namespace starboard