Skip to content

Commit

Permalink
[xb1] Implement closed captioning system settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekLuxoft committed Dec 12, 2024
1 parent 5d0bf09 commit 95f3874
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 0 deletions.
2 changes: 2 additions & 0 deletions starboard/xb1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ static_library("starboard_platform") {
"//starboard/shared/win32/win32_audio_decoder.h",
"//starboard/shared/win32/wrm_header.cc",
"//starboard/shared/win32/wrm_header.h",
"//starboard/xb1/shared/accessibility_extension.cc",
"//starboard/xb1/shared/accessibility_get_caption_settings.cc",
"//starboard/xb1/shared/gpu_base_video_decoder.cc",
"//starboard/xb1/shared/gpu_base_video_decoder.h",
"//starboard/xb1/shared/internal_shims.h",
Expand Down
53 changes: 53 additions & 0 deletions starboard/xb1/shared/accessibility_extension.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.

#include "starboard/xb1/shared/accessibility_extension.h"
#include "starboard/extension/accessibility.h"

namespace starboard {
namespace xb1 {
namespace shared {

namespace accessibility {

// The rest of the accessibility extension is not implemented on XB1
bool GetTextToSpeechSettings(SbAccessibilityTextToSpeechSettings* out_setting) {
return false;
}

bool GetDisplaySettings(SbAccessibilityDisplaySettings* out_setting) {
return false;
}

bool SetCaptionsEnabled(bool enabled) {
return false;
}

} // namespace accessibility

const StarboardExtensionAccessibilityApi kAccessibilityAPI = {
kStarboardExtensionAccessibilityName,
1,
&accessibility::GetTextToSpeechSettings,
&accessibility::GetDisplaySettings,
&accessibility::GetCaptionSettings,
&accessibility::SetCaptionsEnabled};

const void* GetAccessibilityApi() {
return &kAccessibilityAPI;
}

} // namespace shared
} // namespace xb1
} // namespace starboard
36 changes: 36 additions & 0 deletions starboard/xb1/shared/accessibility_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_
#define STARBOARD_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_

#include "starboard/extension/accessibility.h"

namespace starboard {
namespace xb1 {
namespace shared {

namespace accessibility {
bool GetTextToSpeechSettings(SbAccessibilityTextToSpeechSettings* out_setting);
bool GetDisplaySettings(SbAccessibilityDisplaySettings* out_setting);
bool GetCaptionSettings(SbAccessibilityCaptionSettings* caption_settings);
bool SetCaptionsEnabled(bool enabled);
} // namespace accessibility

const void* GetAccessibilityApi();
} // namespace shared
} // namespace xb1
} // namespace starboard

#endif // STARBOARD_XB1_SHARED_ACCESSIBILITY_EXTENSION_H_
194 changes: 194 additions & 0 deletions starboard/xb1/shared/accessibility_get_caption_settings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// 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.

#include <Windows.h>

#include "starboard/common/memory.h"
#include "starboard/shared/starboard/accessibility_internal.h"
#include "starboard/xb1/shared/accessibility_extension.h"

namespace starboard {
namespace xb1 {
namespace shared {
namespace accessibility {

namespace {

using namespace Windows::Media::ClosedCaptioning;

SbAccessibilityCaptionCharacterEdgeStyle
ClosedCaptionEdgeEffectToSbAccessibilityCaptionCharacterEdgeStyle(
ClosedCaptionEdgeEffect edgeStyle) {
switch (edgeStyle) {
case ClosedCaptionEdgeEffect::Default:
return kSbAccessibilityCaptionCharacterEdgeStyleNone;
case ClosedCaptionEdgeEffect::None:
return kSbAccessibilityCaptionCharacterEdgeStyleNone;
case ClosedCaptionEdgeEffect::Raised:
return kSbAccessibilityCaptionCharacterEdgeStyleRaised;
case ClosedCaptionEdgeEffect::Depressed:
return kSbAccessibilityCaptionCharacterEdgeStyleDepressed;
case ClosedCaptionEdgeEffect::Uniform:
return kSbAccessibilityCaptionCharacterEdgeStyleUniform;
case ClosedCaptionEdgeEffect::DropShadow:
return kSbAccessibilityCaptionCharacterEdgeStyleDropShadow;
}
}

SbAccessibilityCaptionColor ClosedCaptionColorToSbAccessibilityCaptionColor(
ClosedCaptionColor color) {
switch (color) {
case ClosedCaptionColor::Default:
return kSbAccessibilityCaptionColorWhite;
case ClosedCaptionColor::White:
return kSbAccessibilityCaptionColorWhite;
case ClosedCaptionColor::Black:
return kSbAccessibilityCaptionColorBlack;
case ClosedCaptionColor::Red:
return kSbAccessibilityCaptionColorRed;
case ClosedCaptionColor::Green:
return kSbAccessibilityCaptionColorGreen;
case ClosedCaptionColor::Blue:
return kSbAccessibilityCaptionColorBlue;
case ClosedCaptionColor::Yellow:
return kSbAccessibilityCaptionColorYellow;
case ClosedCaptionColor::Magenta:
return kSbAccessibilityCaptionColorMagenta;
case ClosedCaptionColor::Cyan:
return kSbAccessibilityCaptionColorCyan;
}
}

SbAccessibilityCaptionFontFamily
ClosedCaptionStyleToSbAccessibilityCaptionFontFamily(ClosedCaptionStyle style) {
switch (style) {
case ClosedCaptionStyle::Default:
return kSbAccessibilityCaptionFontFamilyCasual;
case ClosedCaptionStyle::MonospacedWithSerifs:
return kSbAccessibilityCaptionFontFamilyMonospaceSerif;
case ClosedCaptionStyle::ProportionalWithSerifs:
return kSbAccessibilityCaptionFontFamilyProportionalSerif;
case ClosedCaptionStyle::MonospacedWithoutSerifs:
return kSbAccessibilityCaptionFontFamilyMonospaceSansSerif;
case ClosedCaptionStyle::ProportionalWithoutSerifs:
return kSbAccessibilityCaptionFontFamilyProportionalSansSerif;
case ClosedCaptionStyle::Casual:
return kSbAccessibilityCaptionFontFamilyCasual;
case ClosedCaptionStyle::Cursive:
return kSbAccessibilityCaptionFontFamilyCursive;
case ClosedCaptionStyle::SmallCapitals:
return kSbAccessibilityCaptionFontFamilySmallCapitals;
}
}

SbAccessibilityCaptionFontSizePercentage
ClosedCaptionSizeToSbAccessibilityCaptionFontSizePercentage(
ClosedCaptionSize opacity) {
switch (opacity) {
case ClosedCaptionSize::Default:
return kSbAccessibilityCaptionFontSizePercentage100;
case ClosedCaptionSize::FiftyPercent:
return kSbAccessibilityCaptionFontSizePercentage50;
case ClosedCaptionSize::OneHundredPercent:
return kSbAccessibilityCaptionFontSizePercentage100;
case ClosedCaptionSize::OneHundredFiftyPercent:
return kSbAccessibilityCaptionFontSizePercentage150;
case ClosedCaptionSize::TwoHundredPercent:
return kSbAccessibilityCaptionFontSizePercentage200;
}
}

SbAccessibilityCaptionOpacityPercentage
ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage(
ClosedCaptionOpacity opacity) {
switch (opacity) {
case ClosedCaptionOpacity::Default:
return kSbAccessibilityCaptionOpacityPercentage100;
case ClosedCaptionOpacity::OneHundredPercent:
return kSbAccessibilityCaptionOpacityPercentage100;
case ClosedCaptionOpacity::SeventyFivePercent:
return kSbAccessibilityCaptionOpacityPercentage75;
case ClosedCaptionOpacity::TwentyFivePercent:
return kSbAccessibilityCaptionOpacityPercentage25;
case ClosedCaptionOpacity::ZeroPercent:
return kSbAccessibilityCaptionOpacityPercentage0;
}
}

} // namespace.

bool GetCaptionSettings(SbAccessibilityCaptionSettings* caption_settings) {
if (!caption_settings ||
!starboard::common::MemoryIsZero(
caption_settings, sizeof(SbAccessibilityCaptionSettings))) {
return false;
}

caption_settings->background_color =
ClosedCaptionColorToSbAccessibilityCaptionColor(
ClosedCaptionProperties::BackgroundColor);
caption_settings->background_color_state = kSbAccessibilityCaptionStateSet;

caption_settings->background_opacity =
ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage(
ClosedCaptionProperties::BackgroundOpacity);
caption_settings->background_opacity_state = kSbAccessibilityCaptionStateSet;

caption_settings->character_edge_style =
ClosedCaptionEdgeEffectToSbAccessibilityCaptionCharacterEdgeStyle(
ClosedCaptionProperties::FontEffect);
caption_settings->character_edge_style_state =
kSbAccessibilityCaptionStateSet;

caption_settings->font_color =
ClosedCaptionColorToSbAccessibilityCaptionColor(
ClosedCaptionProperties::FontColor);
caption_settings->font_color_state = kSbAccessibilityCaptionStateSet;

caption_settings->font_family =
ClosedCaptionStyleToSbAccessibilityCaptionFontFamily(
ClosedCaptionProperties::FontStyle);
caption_settings->font_family_state = kSbAccessibilityCaptionStateSet;

caption_settings->font_opacity =
ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage(
ClosedCaptionProperties::FontOpacity);
caption_settings->font_opacity_state = kSbAccessibilityCaptionStateSet;

caption_settings->font_size =
ClosedCaptionSizeToSbAccessibilityCaptionFontSizePercentage(
ClosedCaptionProperties::FontSize);
caption_settings->font_size_state = kSbAccessibilityCaptionStateSet;

caption_settings->window_color =
ClosedCaptionColorToSbAccessibilityCaptionColor(
ClosedCaptionProperties::RegionColor);
caption_settings->window_color_state = kSbAccessibilityCaptionStateSet;

caption_settings->window_opacity =
ClosedCaptionOpacityToSbAccessibilityCaptionOpacityPercentage(
ClosedCaptionProperties::RegionOpacity);
caption_settings->window_opacity_state = kSbAccessibilityCaptionStateSet;

caption_settings->is_enabled = true; // TODO: check it
caption_settings->supports_is_enabled = true;
caption_settings->supports_set_enabled = false;
caption_settings->supports_override = true;
return true;
}

} // namespace accessibility
} // namespace shared
} // namespace xb1
} // namespace starboard
4 changes: 4 additions & 0 deletions starboard/xb1/shared/system_get_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "starboard/extension/media_session.h"
#include "starboard/shared/uwp/xb1_media_session_client.h"
#include "starboard/shared/win32/graphics.h"
#include "starboard/xb1/shared/accessibility_extension.h"
#include "starboard/xb1/shared/configuration.h"

const void* SbSystemGetExtension(const char* name) {
Expand All @@ -32,5 +33,8 @@ const void* SbSystemGetExtension(const char* name) {
if (strcmp(name, kCobaltExtensionMediaSessionName) == 0) {
return starboard::shared::uwp::GetMediaSessionApi();
}
if (strcmp(name, kStarboardExtensionAccessibilityName) == 0) {
return starboard::xb1::shared::GetAccessibilityApi();
}
return NULL;
}

0 comments on commit 95f3874

Please sign in to comment.