Skip to content

Commit

Permalink
tvOS TV mode switch implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Oct 11, 2024
1 parent def2b95 commit 372b7a5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ endif()

if (APPLE)
set(XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC OFF)
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework CoreMedia" "-framework VideoToolbox")
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework CoreMedia" "-framework VideoToolbox" "-framework AVKit")
elseif (PLATFORM_PSV)
target_link_libraries(${PROJECT_NAME} PRIVATE mp3lame libGLESv2_stub)
endif ()
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,21 @@ make -C build/pc -j$(nproc)

Also, please note that the `resources` folder must be available in the working directory, otherwise the program will fail to find the shaders.

### iOS:
### iOS / tvOS:

```shell
# build libromfs generator
./build_libromfs_generator.sh

# prepare vcpkg
./extern/vcpkg/bootstrap-vcpkg.sh

# install packages
./extern/vcpkg/vcpkg install --triplet arm64-ios mbedtls
./extern/vcpkg/vcpkg install --triplet arm64-ios jansson
./extern/vcpkg/vcpkg install --triplet arm64-ios ffmpeg
./extern/vcpkg/vcpkg install --triplet arm64-ios "curl[mbedtls]"
./extern/vcpkg/vcpkg install --triplet arm64-ios libpng
./extern/vcpkg/vcpkg install --triplet arm64-ios opus
```

#### 1. Build for arm64 iphoneOS
#### 1. Build for arm64 iphoneOS / tvOS

```shell
# 1. Generate a Xcode project
# IOS_CODE_SIGN_IDENTITY: code is not signed when IOS_CODE_SIGN_IDENTITY is empty
# IOS_GUI_IDENTIFIER: optional, default is com.borealis.demo
# Replace `PLATFORM_IOS` with `PLATFORM_TVOS` to build for tvOS platform
cmake -B build/ios -G Xcode -DPLATFORM_IOS=ON

# 2. open project in Xcode
Expand Down
41 changes: 41 additions & 0 deletions app/platforms/ios/apple_display.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifdef PLATFORM_TVOS

#import <UIKit/UIKit.h>
#import <AVFoundation/AVDisplayCriteria.h>
#import <AVKit/AVDisplayManager.h>
#import <AVKit/UIWindow.h>
#include "Limelight.h"
#include "Settings.hpp"

@interface AVDisplayCriteria()
@property(readonly) int videoDynamicRange;
@property(readonly, nonatomic) float refreshRate;
- (id)initWithRefreshRate:(float)arg1 videoDynamicRange:(int)arg2;
@end

void updatePreferredDisplayMode(bool streamActive) {
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
AVDisplayManager* displayManager = [window avDisplayManager];

// This logic comes from Kodi and MrMC
if (streamActive) {
int dynamicRange;

if (LiGetCurrentHostDisplayHdrMode()) {
dynamicRange = 2; // HDR10
}
else {
dynamicRange = 0; // SDR
}

AVDisplayCriteria* displayCriteria = [[AVDisplayCriteria alloc] initWithRefreshRate:Settings::instance().fps()
videoDynamicRange:dynamicRange];
displayManager.preferredDisplayCriteria = displayCriteria;
}
else {
// Switch back to the default display mode
displayManager.preferredDisplayCriteria = nil;
}
}

#endif
12 changes: 12 additions & 0 deletions app/src/streaming_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@

using namespace brls;

#ifdef PLATFORM_TVOS
extern void updatePreferredDisplayMode(bool streamActive);
#endif

StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host), app(app) {
Application::getPlatform()->disableScreenDimming(true);

#ifdef PLATFORM_TVOS
updatePreferredDisplayMode(true);
#endif

setFocusable(true);
setHideHighlight(true);
loader = new LoadingOverlay(this);
Expand Down Expand Up @@ -439,6 +447,10 @@ void StreamingView::onLayout() {
}

StreamingView::~StreamingView() {
#ifdef PLATFORM_TVOS
updatePreferredDisplayMode(false);
#endif

Application::getPlatform()->disableScreenDimming(false);
Application::getPlatform()
->getInputManager()
Expand Down

0 comments on commit 372b7a5

Please sign in to comment.