mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 13:09:39 -07:00
Compare commits
No commits in common. "master" and "v1.0.4" have entirely different histories.
394 changed files with 5589 additions and 23501 deletions
|
@ -1,51 +1,34 @@
|
|||
image:
|
||||
- macOS
|
||||
- 'Visual Studio 2019'
|
||||
image: 'Visual Studio 2017'
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /^v\d.*$/
|
||||
- /^deploy-test(-.*)?$/
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
|
||||
for:
|
||||
- matrix:
|
||||
only:
|
||||
- image: 'Visual Studio 2019'
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
build_script:
|
||||
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
- C:\msys64\usr\bin\bash -lc "cd \"%APPVEYOR_BUILD_FOLDER%\" && scripts/appveyor.sh"
|
||||
|
||||
build_script:
|
||||
- call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
- C:\msys64\usr\bin\bash -lc "cd \"%APPVEYOR_BUILD_FOLDER%\" && scripts/appveyor-win.sh"
|
||||
artifacts:
|
||||
- path: Chiaki
|
||||
name: Chiaki
|
||||
- path: Chiaki-PDB
|
||||
name: Chiaki-PDB
|
||||
|
||||
artifacts:
|
||||
- path: Chiaki
|
||||
name: Chiaki
|
||||
- path: Chiaki-PDB
|
||||
name: Chiaki-PDB
|
||||
deploy:
|
||||
description: 'Chiaki Binaries'
|
||||
provider: GitHub
|
||||
draft: true
|
||||
auth_token:
|
||||
secure: Amvzm3PMM5nv+iFsqaU7TZ9fgyYt/YIrOLV0QMiCyOoUlLRIaiYxWiJ7maTpxhZ9
|
||||
artifact: "Chiaki"
|
||||
on:
|
||||
appveyor_repo_tag: true
|
||||
|
||||
- matrix:
|
||||
only:
|
||||
- image: macOS
|
||||
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
- sudo pip3 install protobuf
|
||||
- HOMEBREW_NO_AUTO_UPDATE=1 brew install qt@5 opus openssl@1.1 nasm sdl2 protobuf
|
||||
- scripts/build-ffmpeg.sh
|
||||
|
||||
build_script:
|
||||
- export CMAKE_PREFIX_PATH="`pwd`/ffmpeg-prefix;/usr/local/opt/openssl@1.1;/usr/local/opt/qt@5"
|
||||
- scripts/build-common.sh
|
||||
- cp -a build/gui/chiaki.app Chiaki.app
|
||||
- /usr/local/opt/qt@5/bin/macdeployqt Chiaki.app -dmg
|
||||
|
||||
artifacts:
|
||||
- path: Chiaki.dmg
|
||||
name: Chiaki
|
||||
|
|
25
.builds/alpine.yml
Normal file
25
.builds/alpine.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
image: alpine/edge
|
||||
|
||||
sources:
|
||||
- https://github.com/thestr4ng3r/chiaki.git
|
||||
|
||||
packages:
|
||||
- cmake
|
||||
- protoc
|
||||
- py3-protobuf
|
||||
- opus-dev
|
||||
- qt5-qtbase-dev
|
||||
- qt5-qtsvg-dev
|
||||
- qt5-qtmultimedia-dev
|
||||
- ffmpeg-dev
|
||||
- sdl2-dev
|
||||
|
||||
tasks:
|
||||
- build: |
|
||||
cd chiaki
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
make -j4
|
||||
test/chiaki-unit
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
image: alpine/latest
|
||||
|
||||
packages:
|
||||
- docker
|
||||
|
||||
sources:
|
||||
- https://git.sr.ht/~thestr4ng3r/chiaki
|
||||
|
||||
artifacts:
|
||||
- Chiaki.apk
|
||||
- Chiaki.aab
|
||||
|
||||
secrets:
|
||||
- 163950ff-2ac4-423d-a280-d2d9edbef000
|
||||
- f4bce41f-f96b-4633-80d8-0ff5dd74dc2a
|
||||
|
||||
tasks:
|
||||
- build: |
|
||||
cp -v ~/chiaki-local.properties chiaki/android/local.properties || echo "Secrets not available"
|
||||
sudo service docker start
|
||||
timeout 15 sh -c "until sudo docker info; do sleep 0.5; done"
|
||||
sudo docker run \
|
||||
-v /home/build:/home/build \
|
||||
-u $(id -u):$(id -g) \
|
||||
thestr4ng3r/android:90d826e \
|
||||
/bin/bash -c "cd /home/build/chiaki/android && ./gradlew assembleRelease bundleRelease"
|
||||
cp chiaki/android/app/build/outputs/apk/release/app-release*.apk Chiaki.apk
|
||||
cp chiaki/android/app/build/outputs/bundle/release/app-release*.aab Chiaki.aab
|
|
@ -1,55 +0,0 @@
|
|||
|
||||
image: alpine/latest
|
||||
|
||||
sources:
|
||||
- https://git.sr.ht/~thestr4ng3r/chiaki
|
||||
|
||||
packages:
|
||||
- cmake
|
||||
- ninja
|
||||
- protoc
|
||||
- py3-protobuf
|
||||
- py3-setuptools
|
||||
- opus-dev
|
||||
- qt5-qtbase-dev
|
||||
- qt5-qtsvg-dev
|
||||
- qt5-qtmultimedia-dev
|
||||
- ffmpeg-dev
|
||||
- sdl2-dev
|
||||
- podman
|
||||
- fuse
|
||||
- udev
|
||||
- argp-standalone
|
||||
|
||||
artifacts:
|
||||
- chiaki.nro
|
||||
- Chiaki.AppImage
|
||||
|
||||
tasks:
|
||||
- setup_podman: |
|
||||
sudo rc-service udev start
|
||||
sudo rc-service cgroups start
|
||||
sudo rc-service fuse start # Fuse for AppImages
|
||||
echo build:100000:65536 | sudo tee /etc/subuid
|
||||
echo build:100000:65536 | sudo tee /etc/subgid
|
||||
# https://www.kernel.org/doc/Documentation/networking/tuntap.txt
|
||||
# for slirp4netns
|
||||
sudo mkdir -p /dev/net
|
||||
sudo mknod /dev/net/tun c 10 200
|
||||
sudo chmod 0666 /dev/net/tun
|
||||
- local_build_and_test: |
|
||||
cd chiaki
|
||||
cmake -Bbuild -GNinja -DCHIAKI_ENABLE_CLI=ON -DCHIAKI_ENABLE_GUI=ON -DCHIAKI_CLI_ARGP_STANDALONE=ON
|
||||
ninja -C build
|
||||
build/test/chiaki-unit
|
||||
- appimage: |
|
||||
cd chiaki
|
||||
scripts/run-podman-build-appimage.sh
|
||||
cp appimage/Chiaki.AppImage ../Chiaki.AppImage
|
||||
- switch: |
|
||||
cd chiaki
|
||||
scripts/switch/run-podman-build-chiaki.sh
|
||||
cp build_switch/switch/chiaki.nro ../chiaki.nro
|
||||
- bullseye: |
|
||||
cd chiaki
|
||||
scripts/run-podman-build-bullseye.sh
|
|
@ -1,21 +1,19 @@
|
|||
|
||||
image: freebsd/14.x
|
||||
image: freebsd/latest
|
||||
|
||||
sources:
|
||||
- https://git.sr.ht/~thestr4ng3r/chiaki
|
||||
- https://github.com/thestr4ng3r/chiaki
|
||||
|
||||
packages:
|
||||
- cmake
|
||||
- protobuf
|
||||
- py311-setuptools # should not be needed with nanopb >= 0.4.9
|
||||
- py311-protobuf
|
||||
- py36-protobuf
|
||||
- opus
|
||||
- qt5-core
|
||||
- qt5-qmake
|
||||
- qt5-buildtools
|
||||
- qt5-gui
|
||||
- qt5-widgets
|
||||
- qt5-concurrent
|
||||
- qt5-svg
|
||||
- qt5-opengl
|
||||
- qt5-multimedia
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
image: openbsd/latest
|
||||
|
||||
sources:
|
||||
- https://git.sr.ht/~thestr4ng3r/chiaki
|
||||
|
||||
packages:
|
||||
- cmake
|
||||
- protobuf
|
||||
- py3-setuptools # should not be needed with nanopb >= 0.4.9
|
||||
- py3-protobuf
|
||||
- opus
|
||||
- qtbase
|
||||
- qtsvg
|
||||
- qtmultimedia
|
||||
- ffmpeg
|
||||
- sdl2
|
||||
|
||||
tasks:
|
||||
- build: |
|
||||
cd chiaki
|
||||
mkdir build && cd build
|
||||
cmake -DCMAKE_PREFIX_PATH="/usr/local/lib;/usr/local/lib/qt5/cmake" ..
|
||||
make -j4
|
||||
test/chiaki-unit
|
||||
|
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1,2 +0,0 @@
|
|||
/test/*.inl linguist-generated=true
|
||||
/lib/*.h linguist-language=C
|
14
.gitignore
vendored
14
.gitignore
vendored
|
@ -3,8 +3,6 @@
|
|||
.idea
|
||||
build
|
||||
cmake-build-*
|
||||
/build_*
|
||||
/build-*
|
||||
.DS_store
|
||||
*.AppImage
|
||||
appdir
|
||||
|
@ -19,15 +17,3 @@ appdir
|
|||
.vs
|
||||
CMakeSettings.json
|
||||
chiaki.rb
|
||||
*.jks
|
||||
secret.tar
|
||||
keystore-env.sh
|
||||
compile_commands.json
|
||||
.ccls-cache
|
||||
.cache/
|
||||
.gdb_history
|
||||
chiaki.conf
|
||||
/appimage
|
||||
.cache/
|
||||
/*.app
|
||||
/*.dmg
|
||||
|
|
7
.gitmodules
vendored
7
.gitmodules
vendored
|
@ -6,13 +6,10 @@
|
|||
url = https://github.com/nanopb/nanopb.git
|
||||
[submodule "third-party/jerasure"]
|
||||
path = third-party/jerasure
|
||||
url = https://git.sr.ht/~thestr4ng3r/jerasure
|
||||
url = https://github.com/thestr4ng3r/jerasure.git
|
||||
[submodule "third-party/gf-complete"]
|
||||
path = third-party/gf-complete
|
||||
url = https://git.sr.ht/~thestr4ng3r/gf-complete
|
||||
url = https://github.com/thestr4ng3r/gf-complete.git
|
||||
[submodule "android/app/src/main/cpp/oboe"]
|
||||
path = android/app/src/main/cpp/oboe
|
||||
url = https://github.com/google/oboe
|
||||
[submodule "switch/borealis"]
|
||||
path = switch/borealis
|
||||
url = https://git.sr.ht/~thestr4ng3r/borealis
|
||||
|
|
148
.travis.yml
Normal file
148
.travis.yml
Normal file
|
@ -0,0 +1,148 @@
|
|||
|
||||
language: cpp
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- /^v\d.*$/
|
||||
- /^deploy-test(-.*)?$/
|
||||
|
||||
before_script:
|
||||
- export CHIAKI_VERSION="$TRAVIS_TAG"
|
||||
- if [ -z "$CHIAKI_VERSION" ]; then export CHIAKI_VERSION="$TRAVIS_COMMIT"; fi
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- name: Linux (Bionic)
|
||||
os: linux
|
||||
dist: bionic
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: "ppa:beineri/opt-qt-5.12.0-bionic"
|
||||
packages:
|
||||
- protobuf-compiler
|
||||
- python3-protobuf
|
||||
- libopus-dev
|
||||
- qt512base
|
||||
- qt512multimedia
|
||||
- qt512gamepad
|
||||
- qt512svg
|
||||
- libgl1-mesa-dev
|
||||
- nasm
|
||||
- libsdl2-dev
|
||||
env:
|
||||
- CMAKE_PREFIX_PATH="$TRAVIS_BUILD_DIR/ffmpeg-prefix;/opt/qt512"
|
||||
- CMAKE_EXTRA_ARGS="-DCMAKE_INSTALL_PREFIX=/usr"
|
||||
- DEPLOY=0
|
||||
install:
|
||||
- scripts/build-ffmpeg.sh
|
||||
script:
|
||||
- scripts/travis-build.sh || exit 1
|
||||
- source scripts/travis-appimage.sh
|
||||
|
||||
- name: Linux (Xenial, Deploy)
|
||||
os: linux
|
||||
dist: xenial
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: "ppa:beineri/opt-qt-5.12.3-xenial"
|
||||
packages:
|
||||
- python3-pip
|
||||
- libopus-dev
|
||||
- qt512base
|
||||
- qt512multimedia
|
||||
- qt512svg
|
||||
- libgl1-mesa-dev
|
||||
- nasm
|
||||
env:
|
||||
- CMAKE_PREFIX_PATH="$TRAVIS_BUILD_DIR/ffmpeg-prefix;$TRAVIS_BUILD_DIR/sdl2-prefix;/opt/qt512"
|
||||
- CMAKE_EXTRA_ARGS="-DCMAKE_INSTALL_PREFIX=/usr"
|
||||
- SDL2_FROM_SRC=1
|
||||
- DEPLOY=1
|
||||
install:
|
||||
- sudo pip3 install protobuf
|
||||
- scripts/fetch-protoc.sh
|
||||
- export PATH="$TRAVIS_BUILD_DIR/protoc/bin:$PATH"
|
||||
- scripts/build-ffmpeg.sh
|
||||
- scripts/build-sdl2.sh
|
||||
script:
|
||||
- scripts/travis-build.sh || exit 1
|
||||
- source scripts/travis-appimage.sh
|
||||
|
||||
- name: macOS
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
addons:
|
||||
homebrew:
|
||||
packages:
|
||||
- qt
|
||||
- opus
|
||||
- openssl@1.1
|
||||
- nasm
|
||||
- sdl2
|
||||
env:
|
||||
- CMAKE_PREFIX_PATH="$TRAVIS_BUILD_DIR/ffmpeg-prefix;/usr/local/opt/openssl@1.1;/usr/local/opt/qt"
|
||||
- CMAKE_EXTRA_ARGS=""
|
||||
- DEPLOY=1
|
||||
install:
|
||||
- scripts/build-ffmpeg.sh
|
||||
script:
|
||||
- scripts/travis-build.sh
|
||||
- cp -a build/gui/chiaki.app Chiaki.app
|
||||
- /usr/local/opt/qt/bin/macdeployqt Chiaki.app -dmg
|
||||
- export DEPLOY_FILE="Chiaki-${CHIAKI_VERSION}-macOS-x86_64.dmg"
|
||||
- mv Chiaki.dmg "$DEPLOY_FILE"
|
||||
- cmake -DCHIAKI_VERSION="${CHIAKI_VERSION}" -DCHIAKI_DMG="${DEPLOY_FILE}" -DCHIAKI_CASK_OUT=chiaki.rb -P scripts/configure-cask.cmake
|
||||
- echo "------------------- chiaki.rb cask -------------------"
|
||||
- cat chiaki.rb
|
||||
- echo "------------------------------------------------------"
|
||||
|
||||
- name: Android
|
||||
language: android
|
||||
os: linux
|
||||
dist: trusty
|
||||
android:
|
||||
components:
|
||||
- build-tools-29.0.2
|
||||
- android-29
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- python3-pip
|
||||
install:
|
||||
- echo y | sdkmanager "ndk-bundle"
|
||||
- echo y | sdkmanager "cmake;3.10.2.4988404"
|
||||
- sudo pip3 install protobuf
|
||||
- scripts/fetch-protoc.sh
|
||||
- export PATH="$TRAVIS_BUILD_DIR/protoc/bin:$PATH"
|
||||
script:
|
||||
- cd android
|
||||
- ./gradlew assembleRelease
|
||||
|
||||
- name: "Source Package"
|
||||
os: linux
|
||||
dist: bionic
|
||||
env:
|
||||
- DEPLOY=1
|
||||
install: ~
|
||||
script:
|
||||
- find . -name ".git*" | xargs rm -rfv
|
||||
- mkdir chiaki && shopt -s extglob && mv !(chiaki) chiaki
|
||||
- export DEPLOY_FILE="chiaki-$CHIAKI_VERSION-src.tar.gz"
|
||||
- tar -czvf "$DEPLOY_FILE" chiaki
|
||||
|
||||
after_success:
|
||||
- if [ ! -z "$DEPLOY_FILE" ]; then curl --upload-file "$DEPLOY_FILE" "https://transfer.sh/$DEPLOY_FILE"; echo; fi
|
||||
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
provider: releases
|
||||
draft: true
|
||||
api_key:
|
||||
secure: R7RjLOuGFda05EJeNX2lNG135xKU2w9IQn7p1H1P2zw4zlQMgSBpNRaW8hE408x5KJUjptJTF6QaYYmPWbHlf9VEPFVIcVzSp8YSd2Cdr+GKhmFgWF+fJPBj5y9NNqohwxvK3Nrugh0v6yVQiEYEGF7WArU6dvymSNNTw/EqXtfrOvwUgSf1bDAzQAsXn3E6Ptzf9DrQU8+mOgMSqT/3Wy5207KLmWTtwBWDgkskKwS9OEXk3tDd6U4uT7NFHHmcw+ZjQXRD+yHSHUWYs1oKR4IfgPFxQfEK0Txhkxdf3yj1aNweuk7GGC3cfRaarUfRQpoYqYYCxhTfGZ2b4rVgX3XpssMY7ZmSZHRi/SX08ETXF/c7PZGzr0RPFXZLgAGjgN6O2Dbb9agc3tOUGDUuqKEWX9sALm82WS0FRAFrFLENgMFsj5hu+DKIIkAU2yEsadYKjjhC+q+mTAEkxKKknvM50Xpx3tE1TlP/31Z53v4/NydHIHXPJ72V3mnuoTacwhG2SkGtjMbLCnEZDCtu9C4556oa7Z29cqafv90ZD7lTQMV+ijKvjxgOC9u1GeemmZLofRGDFyYSqKxOpYxxxXGOhs+7FMAdKP00h++MTLwRwIebKQs0fW0XiNKmwushWOUU8sXI1jxTbwe9dPQsspxHRv/mVo6l2vUcBjC19K0=
|
||||
file: $DEPLOY_FILE
|
||||
on:
|
||||
tags: true
|
||||
condition: $DEPLOY = 1
|
163
CMakeLists.txt
163
CMakeLists.txt
|
@ -3,82 +3,22 @@ cmake_minimum_required(VERSION 3.2)
|
|||
|
||||
project(chiaki)
|
||||
|
||||
# Like option(), but the value can also be AUTO
|
||||
macro(tri_option name desc default)
|
||||
set("${name}" "${default}" CACHE STRING "${desc}")
|
||||
set_property(CACHE "${name}" PROPERTY STRINGS AUTO ON OFF)
|
||||
endmacro()
|
||||
|
||||
option(CHIAKI_ENABLE_TESTS "Enable tests for Chiaki" ON)
|
||||
option(CHIAKI_ENABLE_CLI "Enable CLI for Chiaki" OFF)
|
||||
option(CHIAKI_ENABLE_GUI "Enable Qt GUI" ON)
|
||||
option(CHIAKI_ENABLE_ANDROID "Enable Android (Use only as part of the Gradle Project)" OFF)
|
||||
option(CHIAKI_ENABLE_BOREALIS "Enable Borealis GUI (For Nintendo Switch or PC)" OFF)
|
||||
tri_option(CHIAKI_ENABLE_SETSU "Enable libsetsu for touchpad input from controller" AUTO)
|
||||
option(CHIAKI_LIB_ENABLE_OPUS "Use Opus as part of Chiaki Lib" ON)
|
||||
if(CHIAKI_ENABLE_GUI OR CHIAKI_ENABLE_BOREALIS)
|
||||
set(CHIAKI_FFMPEG_DEFAULT ON)
|
||||
else()
|
||||
set(CHIAKI_FFMPEG_DEFAULT AUTO)
|
||||
endif()
|
||||
tri_option(CHIAKI_ENABLE_FFMPEG_DECODER "Enable FFMPEG video decoder" ${CHIAKI_FFMPEG_DEFAULT})
|
||||
tri_option(CHIAKI_ENABLE_PI_DECODER "Enable Raspberry Pi-specific video decoder (requires libraspberrypi0 and libraspberrypi-doc)" AUTO)
|
||||
option(CHIAKI_LIB_ENABLE_MBEDTLS "Use mbedtls instead of OpenSSL as part of Chiaki Lib" OFF)
|
||||
option(CHIAKI_LIB_MBEDTLS_EXTERNAL_PROJECT "Fetch Mbed TLS instead of using system-provided libs" OFF)
|
||||
option(CHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT "Use OpenSSL as CMake external project" OFF)
|
||||
option(CHIAKI_GUI_ENABLE_QT_GAMEPAD "Use QtGamepad for Input" OFF)
|
||||
option(CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER "Use SDL Gamecontroller for Input" ON)
|
||||
option(CHIAKI_CLI_ARGP_STANDALONE "Search for standalone argp lib for CLI" OFF)
|
||||
tri_option(CHIAKI_USE_SYSTEM_JERASURE "Use system-provided jerasure instead of submodule" AUTO)
|
||||
tri_option(CHIAKI_USE_SYSTEM_NANOPB "Use system-provided nanopb instead of submodule" AUTO)
|
||||
|
||||
set(CHIAKI_VERSION_MAJOR 2)
|
||||
set(CHIAKI_VERSION_MINOR 2)
|
||||
set(CHIAKI_VERSION_PATCH 0)
|
||||
set(CHIAKI_VERSION_MAJOR 1)
|
||||
set(CHIAKI_VERSION_MINOR 0)
|
||||
set(CHIAKI_VERSION_PATCH 4)
|
||||
set(CHIAKI_VERSION ${CHIAKI_VERSION_MAJOR}.${CHIAKI_VERSION_MINOR}.${CHIAKI_VERSION_PATCH})
|
||||
|
||||
set(CPACK_PACKAGE_NAME "chiaki")
|
||||
set(CPACK_PACKAGE_DESCRIPTION "Open Source PS4 remote play client")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${CHIAKI_VERSION_MAJOR})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${CHIAKI_VERSION_MINOR})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${CHIAKI_VERSION_PATCH})
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
|
||||
include(CPack)
|
||||
|
||||
set(CHIAKI_IS_SWITCH ${NSWITCH})
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_CURRENT_SOURCE_DIR}/setsu/cmake")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
if(CHIAKI_IS_SWITCH)
|
||||
# force mbedtls as crypto lib
|
||||
set(CHIAKI_LIB_ENABLE_MBEDTLS ON)
|
||||
add_definitions(-D__SWITCH__)
|
||||
endif()
|
||||
|
||||
if(CHIAKI_USE_SYSTEM_JERASURE)
|
||||
if(CHIAKI_USE_SYSTEM_JERASURE STREQUAL AUTO)
|
||||
find_package(Jerasure QUIET)
|
||||
set(CHIAKI_USE_SYSTEM_JERASURE ${Jerasure_FOUND})
|
||||
else()
|
||||
find_package(Jerasure REQUIRED)
|
||||
set(CHIAKI_USE_SYSTEM_JERASURE ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(PythonInterp 3 REQUIRED) # Make sure nanopb doesn't find Python 2.7 because Python 2 should just die.
|
||||
|
||||
if(CHIAKI_USE_SYSTEM_NANOPB)
|
||||
if(CHIAKI_USE_SYSTEM_NANOPB STREQUAL AUTO)
|
||||
find_package(Nanopb QUIET)
|
||||
set(CHIAKI_USE_SYSTEM_NANOPB ${Nanopb_FOUND})
|
||||
else()
|
||||
find_package(Nanopb REQUIRED)
|
||||
set(CHIAKI_USE_SYSTEM_NANOPB ON)
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
add_subdirectory(third-party)
|
||||
|
||||
|
@ -88,101 +28,12 @@ if(CHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT)
|
|||
include(OpenSSLExternalProject)
|
||||
endif()
|
||||
|
||||
if(CHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
add_definitions(-DCHIAKI_LIB_ENABLE_MBEDTLS)
|
||||
if(CHIAKI_LIB_MBEDTLS_EXTERNAL_PROJECT)
|
||||
set(FETCHCONTENT_QUIET CACHE BOOL FALSE)
|
||||
include(FetchContent)
|
||||
set(ENABLE_TESTING CACHE INTERNAL OFF)
|
||||
set(ENABLE_PROGRAMS CACHE INTERNAL OFF)
|
||||
set(USE_SHARED_MBEDTLS_LIBRARY CACHE INTERNAL OFF)
|
||||
FetchContent_Declare(
|
||||
mbedtls
|
||||
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls.git
|
||||
GIT_TAG 8b3f26a5ac38d4fdccbc5c5366229f3e01dafcc0 # v2.28.0
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
FetchContent_MakeAvailable(mbedtls)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_FFMPEG_DECODER)
|
||||
find_package(FFMPEG COMPONENTS avcodec avutil)
|
||||
if(FFMPEG_FOUND)
|
||||
set(CHIAKI_ENABLE_FFMPEG_DECODER ON)
|
||||
else()
|
||||
if(NOT CHIAKI_ENABLE_FFMPEG_DECODER STREQUAL AUTO)
|
||||
message(FATAL_ERROR "CHIAKI_ENABLE_FFMPEG_DECODER is set to ON, but ffmpeg could not be found.")
|
||||
endif()
|
||||
set(CHIAKI_ENABLE_FFMPEG_DECODER OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_FFMPEG_DECODER)
|
||||
message(STATUS "FFMPEG Decoder enabled")
|
||||
else()
|
||||
message(STATUS "FFMPEG Decoder disabled")
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_PI_DECODER)
|
||||
find_package(ILClient)
|
||||
if(ILClient_FOUND)
|
||||
set(CHIAKI_ENABLE_PI_DECODER ON)
|
||||
else()
|
||||
if(NOT CHIAKI_ENABLE_PI_DECODER STREQUAL AUTO)
|
||||
message(FATAL_ERROR "
|
||||
CHIAKI_ENABLE_PI_DECODER is set to ON, but its dependencies (ilclient source and libs) could not be resolved.
|
||||
The Raspberry Pi Decoder is only supported on Raspberry Pi OS and requires libraspberrypi0 and libraspberrypi-doc.")
|
||||
endif()
|
||||
set(CHIAKI_ENABLE_PI_DECODER OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_PI_DECODER)
|
||||
message(STATUS "Pi Decoder enabled")
|
||||
else()
|
||||
message(STATUS "Pi Decoder disabled")
|
||||
endif()
|
||||
|
||||
add_subdirectory(lib)
|
||||
|
||||
if(CHIAKI_ENABLE_CLI)
|
||||
add_subdirectory(cli)
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_GUI AND CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER)
|
||||
find_package(SDL2 MODULE REQUIRED)
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_SETSU)
|
||||
if(CHIAKI_ENABLE_SETSU STREQUAL AUTO AND SDL2_FOUND AND (SDL2_VERSION_MINOR GREATER 0 OR SDL2_VERSION_PATCH GREATER_EQUAL 14))
|
||||
message(STATUS "SDL version ${SDL2_VERSION} is >= 2.0.14, disabling Setsu")
|
||||
set(CHIAKI_ENABLE_SETSU OFF)
|
||||
else()
|
||||
find_package(Udev QUIET)
|
||||
find_package(Evdev QUIET)
|
||||
if(Udev_FOUND AND Evdev_FOUND)
|
||||
set(CHIAKI_ENABLE_SETSU ON)
|
||||
else()
|
||||
if(NOT CHIAKI_ENABLE_SETSU STREQUAL AUTO)
|
||||
message(FATAL_ERROR "
|
||||
CHIAKI_ENABLE_SETSU is set to ON, but its dependencies (udev and evdev) could not be resolved.
|
||||
Keep in mind that setsu is only supported on Linux!")
|
||||
endif()
|
||||
set(CHIAKI_ENABLE_SETSU OFF)
|
||||
endif()
|
||||
if(CHIAKI_ENABLE_SETSU)
|
||||
add_subdirectory(setsu)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_SETSU)
|
||||
message(STATUS "Setsu enabled")
|
||||
else()
|
||||
message(STATUS "Setsu disabled")
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_GUI)
|
||||
add_subdirectory(gui)
|
||||
endif()
|
||||
|
@ -195,7 +46,3 @@ endif()
|
|||
if(CHIAKI_ENABLE_ANDROID)
|
||||
add_subdirectory(android/app)
|
||||
endif()
|
||||
|
||||
if(CHIAKI_ENABLE_BOREALIS)
|
||||
add_subdirectory(switch)
|
||||
endif()
|
||||
|
|
150
COPYING
150
COPYING
|
@ -1,5 +1,5 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
|
@ -7,15 +7,17 @@
|
|||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
|
@ -24,34 +26,44 @@ them if you wish), that you receive source code or can get it if you
|
|||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
@ -60,7 +72,7 @@ modification follow.
|
|||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
@ -537,45 +549,35 @@ to collect a royalty for further conveying from those to whom you convey
|
|||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
|
@ -633,40 +635,40 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU AGPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work.
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
|
|
@ -1,672 +0,0 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU AGPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work.
|
91
README.md
91
README.md
|
@ -5,43 +5,37 @@
|
|||
|
||||
**Disclaimer:** This project is not endorsed or certified by Sony Interactive Entertainment LLC.
|
||||
|
||||
[](https://ci.appveyor.com/project/thestr4ng3r/chiaki) [](https://builds.sr.ht/~thestr4ng3r/chiaki?)
|
||||
[](https://travis-ci.com/thestr4ng3r/chiaki) [](https://ci.appveyor.com/project/thestr4ng3r/chiaki) [](https://builds.sr.ht/~thestr4ng3r/chiaki?)
|
||||
|
||||
Chiaki is a Free and Open Source Software Client for PlayStation 4 and PlayStation 5 Remote Play
|
||||
for Linux, FreeBSD, OpenBSD, NetBSD, Android, macOS, Windows, Nintendo Switch and potentially even more platforms.
|
||||
|
||||
## Project Status and Contributing
|
||||
|
||||
As all relevant features are implemented, this project is considered to be finished and in maintenance mode only.
|
||||
No major updates are planned and contributions are only accepted in special cases such as security issues.
|
||||
The objective is to keep a stable base and not break existing support for less mainstream platforms such as BSDs.
|
||||
|
||||
**For a more active, fast moving and community-oriented project, refer
|
||||
to [chiaki-ng](https://streetpea.github.io/chiaki-ng/) ("next generation").
|
||||
If you would like to contribute, this will likely also be the best place to do so.**
|
||||
Chiaki is a Free and Open Source Software Client for PlayStation 4 Remote Play
|
||||
for Linux, macOS, Windows and potentially even more platforms.
|
||||
|
||||

|
||||
|
||||
## Installing
|
||||
## Features
|
||||
|
||||
You can either download a pre-built release or build Chiaki from source.
|
||||
Everything necessary for a full streaming session, including the initial
|
||||
registration and wakeup of the console, is supported.
|
||||
The following features however are yet to be implemented:
|
||||
* Congestion Control
|
||||
* H264 Error Concealment (FEC and active error recovery however are implemented)
|
||||
* Touchpad support (Triggering the Touchpad Button is currently possible by pressing `T` on the keyboard)
|
||||
* Rumble
|
||||
* Configurable Keybindings
|
||||
|
||||
### Downloading a Release
|
||||
## Downloading a Release
|
||||
|
||||
Builds are provided for Linux, Android, macOS, Nintendo Switch and Windows.
|
||||
|
||||
You can download them [here](https://git.sr.ht/~thestr4ng3r/chiaki/refs).
|
||||
Builds are provided for Linux, macOS and Windows. You can find them [here](https://github.com/thestr4ng3r/chiaki/releases).
|
||||
|
||||
* **Linux**: The provided file is an [AppImage](https://appimage.org/). Simply make it executable (`chmod +x <file>.AppImage`) and run it.
|
||||
* **Android**: Install from [F-Droid](https://f-droid.org/packages/com.metallic.chiaki/) or download the APK from Sourcehut.
|
||||
* **macOS**: Drag the application from the `.dmg` into your Applications folder.
|
||||
* **Windows**: Extract the `.zip` file and execute `chiaki.exe`.
|
||||
* **Switch**: Download the `.nro` file and copy it into the `switch/` directory on your SD card.
|
||||
|
||||
### Building from Source
|
||||
## Building from Source
|
||||
|
||||
Dependencies are CMake, Qt 5 with QtMultimedia, QtOpenGL and QtSvg, FFMPEG (libavcodec with H264 is enough), libopus, OpenSSL 1.1, SDL 2,
|
||||
protoc and the protobuf Python library (only used during compilation for Nanopb). Then, Chiaki builds just like any other CMake project:
|
||||
Dependencies are CMake, Qt 5 with QtMultimedia, QtOpenGL and QtSvg, FFMPEG (libavcodec with H264 is enough), libopus, OpenSSL 1.1,
|
||||
protoc and the protobuf Python library (only used during compilation for Nanopb).
|
||||
Then, Chiaki builds just like any other CMake project:
|
||||
```
|
||||
git submodule update --init
|
||||
mkdir build && cd build
|
||||
|
@ -49,37 +43,20 @@ cmake ..
|
|||
make
|
||||
```
|
||||
|
||||
For more detailed platform-specific instructions, see [doc/platform-build.md](doc/platform-build.md) or [switch/](./switch/README.md) for Nintendo Switch.
|
||||
|
||||
## Usage
|
||||
|
||||
If your Console is on your local network, is turned on or in standby mode and does not have Discovery explicitly disabled, Chiaki should find it.
|
||||
Otherwise, you can add it manually.
|
||||
To do so, click the "+" icon in the top right, and enter your Console's IP address.
|
||||
|
||||
You will then need to register your Console with Chiaki. You will need two more pieces of information to do this.
|
||||
|
||||
### Obtaining your PSN AccountID
|
||||
## Obtaining your PSN AccountID
|
||||
|
||||
Starting with PS4 7.0, it is necessary to use a so-called "AccountID" as opposed to the "Online-ID" for registration (streaming itself did not change).
|
||||
This ID seems to be a unique identifier for a PSN Account and it can be obtained from the PSN after logging in using OAuth.
|
||||
A Python 3 script which does this is provided in [scripts/psn-account-id.py](scripts/psn-account-id.py).
|
||||
Simply run it in a terminal and follow the instructions. Once you know your ID, write it down. You will likely never have to do this process again.
|
||||
|
||||
### Obtaining a Registration PIN
|
||||
|
||||
To register a Console with a PIN, it must be put into registration mode. To do this on a PS4, simply go to:
|
||||
Settings -> Remote Play -> Add Device, or on a PS5: Settings -> System -> Remote Play -> Link Device.
|
||||
|
||||
You can now double-click your Console in Chiaki's main window to start Remote Play.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This project has only been made possible because of the following Open Source projects:
|
||||
[Rizin](https://rizin.re),
|
||||
[Cutter](https://cutter.re),
|
||||
[Frida](https://www.frida.re) and
|
||||
[x64dbg](https://x64dbg.com).
|
||||
[radare2](https://github.com/radare/radare2),
|
||||
[Cutter](https://cutter.re/),
|
||||
[Frida](https://www.frida.re/) and
|
||||
[x64dbg](https://x64dbg.com/).
|
||||
|
||||
Also thanks to [delroth](https://github.com/delroth) for analyzing the registration and wakeup protocol,
|
||||
[grill2010](https://github.com/grill2010) for analyzing the PSN's OAuth Login,
|
||||
|
@ -88,27 +65,17 @@ extremely helpful information about FEC and error correction.
|
|||
|
||||
## About
|
||||
|
||||
Created by Florian Märkl
|
||||
Created by Florian Märkl.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU AGPL version 3 section 7
|
||||
|
||||
If you modify this program, or any covered work, by linking or
|
||||
combining it with the OpenSSL project's OpenSSL library (or a
|
||||
modified version of that library), containing parts covered by the
|
||||
terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
|
||||
grants you additional permission to convey the resulting work.
|
||||
Corresponding Source for a non-source form of such a combination
|
||||
shall include the source code for the parts of OpenSSL used as well
|
||||
as that of the covered work.
|
||||
|
|
2
android/.gitignore
vendored
2
android/.gitignore
vendored
|
@ -12,5 +12,3 @@
|
|||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
/app/release
|
||||
keystore.jks
|
||||
|
|
|
@ -5,8 +5,6 @@ set(CMAKE_CXX_STANDARD 14)
|
|||
|
||||
add_library(chiaki-jni SHARED
|
||||
src/main/cpp/chiaki-jni.c
|
||||
src/main/cpp/log.h
|
||||
src/main/cpp/log.c
|
||||
src/main/cpp/video-decoder.h
|
||||
src/main/cpp/video-decoder.c
|
||||
src/main/cpp/audio-decoder.h
|
||||
|
|
|
@ -1,88 +1,40 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
def rootCMakeLists = "../../CMakeLists.txt"
|
||||
def rootCMakeListsContent = file(rootCMakeLists).text
|
||||
static def grepVersionComponent(content, varname) {
|
||||
def match = content =~ /set\($varname ([0-9]+)\)/
|
||||
if(!match.find())
|
||||
throw new GradleException("Failed to find $varname in CMakeLists.txt")
|
||||
return match.group(1)
|
||||
}
|
||||
def chiakiVersionMajor = grepVersionComponent(rootCMakeListsContent, "CHIAKI_VERSION_MAJOR")
|
||||
def chiakiVersionMinor = grepVersionComponent(rootCMakeListsContent, "CHIAKI_VERSION_MINOR")
|
||||
def chiakiVersionPatch = grepVersionComponent(rootCMakeListsContent, "CHIAKI_VERSION_PATCH")
|
||||
def chiakiVersion = "$chiakiVersionMajor.$chiakiVersionMinor.$chiakiVersionPatch"
|
||||
println("Determined Chiaki Version: $chiakiVersion")
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.metallic.chiaki"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
versionCode 12
|
||||
versionName chiakiVersion
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DCHIAKI_ENABLE_TESTS=OFF",
|
||||
"-DCHIAKI_ENABLE_CLI=OFF",
|
||||
"-DCHIAKI_ENABLE_GUI=OFF",
|
||||
"-DCHIAKI_ENABLE_SETSU=OFF",
|
||||
"-DCHIAKI_ENABLE_ANDROID=ON",
|
||||
"-DCHIAKI_ENABLE_FFMPEG_DECODER=OFF",
|
||||
"-DCHIAKI_ENABLE_PI_DECODER=OFF",
|
||||
"-DCHIAKI_LIB_ENABLE_OPUS=OFF",
|
||||
"-DCHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT=ON"
|
||||
}
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
version "3.22.1"
|
||||
path rootCMakeLists
|
||||
version "3.10.2+"
|
||||
path "../../CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
signingConfigs {
|
||||
release
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Properties properties = new Properties()
|
||||
def propertiesFile = file("../local.properties")
|
||||
if (propertiesFile.exists()) {
|
||||
properties.load(propertiesFile.newDataInputStream())
|
||||
}
|
||||
|
||||
if(properties.containsKey("chiakiKeystore")) {
|
||||
println("Enabling Local Signing")
|
||||
buildTypes.release.signingConfig = signingConfigs.release
|
||||
buildTypes.debug.signingConfig = signingConfigs.release
|
||||
signingConfigs.release.storeFile = file(properties.get("chiakiKeystore"))
|
||||
signingConfigs.release.storePassword = properties.get("chiakiKeystorePW")
|
||||
signingConfigs.release.keyAlias = properties.get("chiakiKeyAlias")
|
||||
signingConfigs.release.keyPassword = properties.get("chiakiKeyPW")
|
||||
} else {
|
||||
println("Signing not enabled")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
|
@ -91,26 +43,30 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
|||
}
|
||||
}
|
||||
|
||||
androidExtensions {
|
||||
// for @Parcelize
|
||||
experimental = true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
||||
implementation 'androidx.core:core-ktx:1.9.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
implementation 'androidx.preference:preference:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.5.1'
|
||||
implementation "io.reactivex.rxjava2:rxjava:2.2.20"
|
||||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha10'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.1.0'
|
||||
implementation "io.reactivex.rxjava2:rxjava:2.2.12"
|
||||
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
|
||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||
def room_version = "2.5.0"
|
||||
def room_version = "2.2.0-rc01"
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
implementation "androidx.room:room-ktx:$room_version"
|
||||
implementation "androidx.room:room-rxjava2:$room_version"
|
||||
implementation "com.squareup.moshi:moshi:1.14.0"
|
||||
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.14.0"
|
||||
|
||||
}
|
||||
|
|
70
android/app/proguard-rules.pro
vendored
70
android/app/proguard-rules.pro
vendored
|
@ -19,73 +19,3 @@
|
|||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-dontobfuscate
|
||||
-keep class com.metallic.chiaki.** { *; }
|
||||
|
||||
|
||||
##########################################
|
||||
# Moshi
|
||||
##########################################
|
||||
|
||||
# JSR 305 annotations are for embedding nullability information.
|
||||
-dontwarn javax.annotation.**
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
@com.squareup.moshi.* <methods>;
|
||||
}
|
||||
|
||||
-keep @com.squareup.moshi.JsonQualifier interface *
|
||||
|
||||
# Enum field names are used by the integrated EnumJsonAdapter.
|
||||
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
|
||||
# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.
|
||||
-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
|
||||
<fields>;
|
||||
**[] values();
|
||||
}
|
||||
|
||||
# The name of @JsonClass types is used to look up the generated adapter.
|
||||
-keepnames @com.squareup.moshi.JsonClass class *
|
||||
|
||||
# Retain generated target class's synthetic defaults constructor and keep DefaultConstructorMarker's
|
||||
# name. We will look this up reflectively to invoke the type's constructor.
|
||||
#
|
||||
# We can't _just_ keep the defaults constructor because Proguard/R8's spec doesn't allow wildcard
|
||||
# matching preceding parameters.
|
||||
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
|
||||
-keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * {
|
||||
synthetic <init>(...);
|
||||
}
|
||||
|
||||
# Retain generated JsonAdapters if annotated type is retained.
|
||||
-if @com.squareup.moshi.JsonClass class *
|
||||
-keep class <1>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
-if @com.squareup.moshi.JsonClass class **$*
|
||||
-keep class <1>_<2>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
-if @com.squareup.moshi.JsonClass class **$*$*
|
||||
-keep class <1>_<2>_<3>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
-if @com.squareup.moshi.JsonClass class **$*$*$*
|
||||
-keep class <1>_<2>_<3>_<4>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
-if @com.squareup.moshi.JsonClass class **$*$*$*$*
|
||||
-keep class <1>_<2>_<3>_<4>_<5>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
-if @com.squareup.moshi.JsonClass class **$*$*$*$*$*
|
||||
-keep class <1>_<2>_<3>_<4>_<5>_<6>JsonAdapter {
|
||||
<init>(...);
|
||||
<fields>;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.metallic.chiaki">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -14,23 +11,10 @@
|
|||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
<provider
|
||||
android:authorities="com.metallic.chiaki.fileprovider"
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths"
|
||||
/>
|
||||
</provider>
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".main.MainActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:exported="true">
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -46,6 +30,11 @@
|
|||
<activity
|
||||
android:name=".settings.SettingsActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".TestStartActivity"
|
||||
android:theme="@style/MageTheme"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
|
||||
|
||||
<activity
|
||||
android:name=".regist.RegistActivity"
|
||||
android:theme="@style/MageTheme"
|
||||
|
@ -56,11 +45,6 @@
|
|||
android:name=".regist.RegistExecuteActivity"
|
||||
android:theme="@style/MageTheme"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
|
||||
|
||||
<activity
|
||||
android:name=".manualconsole.EditManualConsoleActivity"
|
||||
android:theme="@style/MageTheme"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "audio-decoder.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_JNI_AUDIO_DECODER_H
|
||||
#define CHIAKI_JNI_AUDIO_DECODER_H
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "audio-output.h"
|
||||
|
||||
|
@ -9,7 +24,7 @@
|
|||
|
||||
#include <oboe/Oboe.h>
|
||||
|
||||
#define BUFFER_CHUNK_SIZE 1024
|
||||
#define BUFFER_CHUNK_SIZE 512
|
||||
#define BUFFER_CHUNKS_COUNT 32
|
||||
|
||||
using AudioBuffer = CircularBuffer<BUFFER_CHUNKS_COUNT, BUFFER_CHUNK_SIZE>;
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_JNI_AUDIO_OUTPUT_H
|
||||
#define CHIAKI_JNI_AUDIO_OUTPUT_H
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
|
@ -18,8 +33,41 @@
|
|||
#include "video-decoder.h"
|
||||
#include "audio-decoder.h"
|
||||
#include "audio-output.h"
|
||||
#include "log.h"
|
||||
#include "chiaki-jni.h"
|
||||
|
||||
#define LOG_TAG "Chiaki"
|
||||
#define JNI_VERSION JNI_VERSION_1_6
|
||||
|
||||
#define BASE_PACKAGE "com/metallic/chiaki/lib"
|
||||
#define JNI_FCN(name) Java_com_metallic_chiaki_lib_ChiakiNative_##name
|
||||
|
||||
#define E (*env)
|
||||
|
||||
static void log_cb_android(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
int prio;
|
||||
switch(level)
|
||||
{
|
||||
case CHIAKI_LOG_DEBUG:
|
||||
prio = ANDROID_LOG_DEBUG;
|
||||
break;
|
||||
case CHIAKI_LOG_VERBOSE:
|
||||
prio = ANDROID_LOG_VERBOSE;
|
||||
break;
|
||||
case CHIAKI_LOG_INFO:
|
||||
prio = ANDROID_LOG_INFO;
|
||||
break;
|
||||
case CHIAKI_LOG_WARNING:
|
||||
prio = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
case CHIAKI_LOG_ERROR:
|
||||
prio = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
default:
|
||||
prio = ANDROID_LOG_INFO;
|
||||
break;
|
||||
}
|
||||
__android_log_write(prio, LOG_TAG, msg);
|
||||
}
|
||||
|
||||
static char *strdup_jni(const char *str)
|
||||
{
|
||||
|
@ -36,7 +84,7 @@ static char *strdup_jni(const char *str)
|
|||
return r;
|
||||
}
|
||||
|
||||
jobject jnistr_from_ascii(JNIEnv *env, const char *str)
|
||||
static jobject jnistr_from_ascii(JNIEnv *env, const char *str)
|
||||
{
|
||||
if(!str)
|
||||
return NULL;
|
||||
|
@ -48,45 +96,56 @@ jobject jnistr_from_ascii(JNIEnv *env, const char *str)
|
|||
return r;
|
||||
}
|
||||
|
||||
static jbyteArray jnibytearray_create(JNIEnv *env, const uint8_t *buf, size_t buf_size)
|
||||
{
|
||||
jbyteArray r = E->NewByteArray(env, buf_size);
|
||||
E->SetByteArrayRegion(env, r, 0, buf_size, (const jbyte *)buf);
|
||||
return r;
|
||||
}
|
||||
|
||||
static jobject get_kotlin_global_object(JNIEnv *env, const char *id)
|
||||
{
|
||||
size_t idlen = strlen(id);
|
||||
char *sig = malloc(idlen + 3);
|
||||
if(!sig)
|
||||
return NULL;
|
||||
sig[0] = 'L';
|
||||
memcpy(sig + 1, id, idlen);
|
||||
sig[1 + idlen] = ';';
|
||||
sig[1 + idlen + 1] = '\0';
|
||||
jclass cls = E->FindClass(env, id);
|
||||
jfieldID field_id = E->GetStaticFieldID(env, cls, "INSTANCE", sig);
|
||||
jobject r = E->GetStaticObjectField(env, cls, field_id);
|
||||
free(sig);
|
||||
return r;
|
||||
}
|
||||
|
||||
static ChiakiLog global_log;
|
||||
JavaVM *global_vm;
|
||||
static JavaVM *global_vm;
|
||||
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
global_vm = vm;
|
||||
|
||||
android_chiaki_file_log_init(&global_log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, NULL);
|
||||
chiaki_log_init(&global_log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, log_cb_android, NULL);
|
||||
CHIAKI_LOGI(&global_log, "Loading Chiaki Library");
|
||||
ChiakiErrorCode err = chiaki_lib_init();
|
||||
CHIAKI_LOGI(&global_log, "Chiaki Library Init Result: %s\n", chiaki_error_string(err));
|
||||
return JNI_VERSION;
|
||||
}
|
||||
|
||||
JNIEnv *attach_thread_jni()
|
||||
JNIEXPORT jstring JNICALL JNI_FCN(errorCodeToString)(JNIEnv *env, jobject obj, jint value)
|
||||
{
|
||||
return E->NewStringUTF(env, chiaki_error_string((ChiakiErrorCode)value));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL JNI_FCN(quitReasonToString)(JNIEnv *env, jobject obj, jint value)
|
||||
{
|
||||
return E->NewStringUTF(env, chiaki_quit_reason_string((ChiakiQuitReason)value));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL JNI_FCN(quitReasonIsStopped)(JNIEnv *env, jobject obj, jint value)
|
||||
{
|
||||
return value == CHIAKI_QUIT_REASON_STOPPED;
|
||||
}
|
||||
|
||||
typedef struct android_chiaki_session_t
|
||||
{
|
||||
ChiakiSession session;
|
||||
jobject java_session;
|
||||
jclass java_session_class;
|
||||
jmethodID java_session_event_connected_meth;
|
||||
jmethodID java_session_event_login_pin_request_meth;
|
||||
jmethodID java_session_event_quit_meth;
|
||||
jfieldID java_controller_state_buttons;
|
||||
jfieldID java_controller_state_l2_state;
|
||||
jfieldID java_controller_state_r2_state;
|
||||
jfieldID java_controller_state_left_x;
|
||||
jfieldID java_controller_state_left_y;
|
||||
jfieldID java_controller_state_right_x;
|
||||
jfieldID java_controller_state_right_y;
|
||||
|
||||
AndroidChiakiVideoDecoder video_decoder;
|
||||
AndroidChiakiAudioDecoder audio_decoder;
|
||||
void *audio_output;
|
||||
} AndroidChiakiSession;
|
||||
|
||||
static JNIEnv *attach_thread_jni()
|
||||
{
|
||||
JNIEnv *env;
|
||||
int r = (*global_vm)->GetEnv(global_vm, (void **)&env, JNI_VERSION);
|
||||
|
@ -100,67 +159,40 @@ JNIEnv *attach_thread_jni()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL JNI_FCN(errorCodeToString)(JNIEnv *env, jobject obj, jint value)
|
||||
typedef struct android_chiaki_log_t
|
||||
{
|
||||
return E->NewStringUTF(env, chiaki_error_string((ChiakiErrorCode)value));
|
||||
jobject java_log;
|
||||
jmethodID java_log_meth;
|
||||
ChiakiLog log;
|
||||
} AndroidChiakiLog;
|
||||
|
||||
static void android_chiaki_log_cb(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
log_cb_android(level, msg, NULL);
|
||||
|
||||
AndroidChiakiLog *log = user;
|
||||
JNIEnv *env = attach_thread_jni();
|
||||
if(!env)
|
||||
return;
|
||||
E->CallVoidMethod(env, log->java_log, log->java_log_meth, (jint)level, jnistr_from_ascii(env, msg));
|
||||
(*global_vm)->DetachCurrentThread(global_vm);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL JNI_FCN(quitReasonToString)(JNIEnv *env, jobject obj, jint value)
|
||||
static void android_chiaki_log_init(AndroidChiakiLog *log, JNIEnv *env, jobject java_log)
|
||||
{
|
||||
return E->NewStringUTF(env, chiaki_quit_reason_string((ChiakiQuitReason)value));
|
||||
log->java_log = E->NewGlobalRef(env, java_log);
|
||||
jclass log_class = E->GetObjectClass(env, log->java_log);
|
||||
log->java_log_meth = E->GetMethodID(env, log_class, "log", "(ILjava/lang/String;)V");
|
||||
log->log.level_mask = (uint32_t)E->GetIntField(env, log->java_log, E->GetFieldID(env, log_class, "levelMask", "I"));
|
||||
log->log.cb = android_chiaki_log_cb;
|
||||
log->log.user = log;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL JNI_FCN(quitReasonIsError)(JNIEnv *env, jobject obj, jint value)
|
||||
static void android_chiaki_log_fini(AndroidChiakiLog *log, JNIEnv *env)
|
||||
{
|
||||
return chiaki_quit_reason_is_error(value);
|
||||
E->DeleteGlobalRef(env, log->java_log);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL JNI_FCN(videoProfilePreset)(JNIEnv *env, jobject obj, jint resolution_preset, jint fps_preset, jobject codec)
|
||||
{
|
||||
ChiakiConnectVideoProfile profile = { 0 };
|
||||
chiaki_connect_video_profile_preset(&profile, (ChiakiVideoResolutionPreset)resolution_preset, (ChiakiVideoFPSPreset)fps_preset);
|
||||
jclass profile_class = E->FindClass(env, BASE_PACKAGE"/ConnectVideoProfile");
|
||||
jmethodID profile_ctor = E->GetMethodID(env, profile_class, "<init>", "(IIIIL"BASE_PACKAGE"/Codec;)V");
|
||||
return E->NewObject(env, profile_class, profile_ctor, profile.width, profile.height, profile.max_fps, profile.bitrate, codec);
|
||||
}
|
||||
|
||||
typedef struct android_chiaki_session_t
|
||||
{
|
||||
ChiakiSession session;
|
||||
ChiakiLog *log;
|
||||
jobject java_session;
|
||||
jclass java_session_class;
|
||||
jmethodID java_session_event_connected_meth;
|
||||
jmethodID java_session_event_login_pin_request_meth;
|
||||
jmethodID java_session_event_quit_meth;
|
||||
jmethodID java_session_event_rumble_meth;
|
||||
jfieldID java_controller_state_buttons;
|
||||
jfieldID java_controller_state_l2_state;
|
||||
jfieldID java_controller_state_r2_state;
|
||||
jfieldID java_controller_state_left_x;
|
||||
jfieldID java_controller_state_left_y;
|
||||
jfieldID java_controller_state_right_x;
|
||||
jfieldID java_controller_state_right_y;
|
||||
jfieldID java_controller_state_touches;
|
||||
jfieldID java_controller_state_gyro_x;
|
||||
jfieldID java_controller_state_gyro_y;
|
||||
jfieldID java_controller_state_gyro_z;
|
||||
jfieldID java_controller_state_accel_x;
|
||||
jfieldID java_controller_state_accel_y;
|
||||
jfieldID java_controller_state_accel_z;
|
||||
jfieldID java_controller_state_orient_x;
|
||||
jfieldID java_controller_state_orient_y;
|
||||
jfieldID java_controller_state_orient_z;
|
||||
jfieldID java_controller_state_orient_w;
|
||||
jfieldID java_controller_touch_x;
|
||||
jfieldID java_controller_touch_y;
|
||||
jfieldID java_controller_touch_id;
|
||||
|
||||
AndroidChiakiVideoDecoder video_decoder;
|
||||
AndroidChiakiAudioDecoder audio_decoder;
|
||||
void *audio_output;
|
||||
} AndroidChiakiSession;
|
||||
|
||||
static void android_chiaki_event_cb(ChiakiEvent *event, void *user)
|
||||
{
|
||||
AndroidChiakiSession *session = user;
|
||||
|
@ -193,44 +225,27 @@ static void android_chiaki_event_cb(ChiakiEvent *event, void *user)
|
|||
free(reason_str);
|
||||
break;
|
||||
}
|
||||
case CHIAKI_EVENT_RUMBLE:
|
||||
E->CallVoidMethod(env, session->java_session,
|
||||
session->java_session_event_rumble_meth,
|
||||
(jint)event->rumble.left,
|
||||
(jint)event->rumble.right);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
(*global_vm)->DetachCurrentThread(global_vm);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject result, jobject connect_info_obj, jstring log_file_str, jboolean log_verbose, jobject java_session)
|
||||
JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject result, jobject connect_info_obj, jobject java_session)
|
||||
{
|
||||
AndroidChiakiSession *session = NULL;
|
||||
ChiakiLog *log = malloc(sizeof(ChiakiLog));
|
||||
const char *log_file = log_file_str ? E->GetStringUTFChars(env, log_file_str, NULL) : NULL;
|
||||
android_chiaki_file_log_init(log, log_verbose ? CHIAKI_LOG_ALL : (CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE), log_file);
|
||||
if(log_file)
|
||||
E->ReleaseStringUTFChars(env, log_file_str, log_file);
|
||||
|
||||
ChiakiErrorCode err = CHIAKI_ERR_SUCCESS;
|
||||
char *host_str = NULL;
|
||||
|
||||
jclass result_class = E->GetObjectClass(env, result);
|
||||
|
||||
jclass connect_info_class = E->GetObjectClass(env, connect_info_obj);
|
||||
jboolean ps5 = E->GetBooleanField(env, connect_info_obj, E->GetFieldID(env, connect_info_class, "ps5", "Z"));
|
||||
jstring host_string = E->GetObjectField(env, connect_info_obj, E->GetFieldID(env, connect_info_class, "host", "Ljava/lang/String;"));
|
||||
jbyteArray regist_key_array = E->GetObjectField(env, connect_info_obj, E->GetFieldID(env, connect_info_class, "registKey", "[B"));
|
||||
jbyteArray morning_array = E->GetObjectField(env, connect_info_obj, E->GetFieldID(env, connect_info_class, "morning", "[B"));
|
||||
jobject connect_video_profile_obj = E->GetObjectField(env, connect_info_obj, E->GetFieldID(env, connect_info_class, "videoProfile", "L"BASE_PACKAGE"/ConnectVideoProfile;"));
|
||||
jclass connect_video_profile_class = E->GetObjectClass(env, connect_video_profile_obj);
|
||||
|
||||
ChiakiConnectInfo connect_info = { 0 };
|
||||
connect_info.ps5 = ps5;
|
||||
|
||||
ChiakiConnectInfo connect_info;
|
||||
const char *str_borrow = E->GetStringUTFChars(env, host_string, NULL);
|
||||
connect_info.host = host_str = strdup(str_borrow);
|
||||
E->ReleaseStringUTFChars(env, host_string, str_borrow);
|
||||
|
@ -242,7 +257,7 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
|
||||
if(E->GetArrayLength(env, regist_key_array) != sizeof(connect_info.regist_key))
|
||||
{
|
||||
CHIAKI_LOGE(log, "Regist Key passed from Java has invalid length");
|
||||
CHIAKI_LOGE(&global_log, "Regist Key passed from Java has invalid length");
|
||||
err = CHIAKI_ERR_INVALID_DATA;
|
||||
goto beach;
|
||||
}
|
||||
|
@ -252,7 +267,7 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
|
||||
if(E->GetArrayLength(env, morning_array) != sizeof(connect_info.morning))
|
||||
{
|
||||
CHIAKI_LOGE(log, "Morning passed from Java has invalid length");
|
||||
CHIAKI_LOGE(&global_log, "Morning passed from Java has invalid length");
|
||||
err = CHIAKI_ERR_INVALID_DATA;
|
||||
goto beach;
|
||||
}
|
||||
|
@ -265,13 +280,6 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
connect_info.video_profile.max_fps = (unsigned int)E->GetIntField(env, connect_video_profile_obj, E->GetFieldID(env, connect_video_profile_class, "maxFPS", "I"));
|
||||
connect_info.video_profile.bitrate = (unsigned int)E->GetIntField(env, connect_video_profile_obj, E->GetFieldID(env, connect_video_profile_class, "bitrate", "I"));
|
||||
|
||||
jobject codec_obj = E->GetObjectField(env, connect_video_profile_obj, E->GetFieldID(env, connect_video_profile_class, "codec", "L"BASE_PACKAGE"/Codec;"));
|
||||
jclass codec_class = E->GetObjectClass(env, codec_obj);
|
||||
jint target_value = E->GetIntField(env, codec_obj, E->GetFieldID(env, codec_class, "value", "I"));
|
||||
connect_info.video_profile.codec = (ChiakiCodec)target_value;
|
||||
|
||||
connect_info.video_profile_auto_downgrade = true;
|
||||
|
||||
session = CHIAKI_NEW(AndroidChiakiSession);
|
||||
if(!session)
|
||||
{
|
||||
|
@ -279,9 +287,7 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
goto beach;
|
||||
}
|
||||
memset(session, 0, sizeof(AndroidChiakiSession));
|
||||
session->log = log;
|
||||
err = android_chiaki_video_decoder_init(&session->video_decoder, log, connect_info.video_profile.width, connect_info.video_profile.height,
|
||||
connect_info.ps5 ? connect_info.video_profile.codec : CHIAKI_CODEC_H264);
|
||||
err = android_chiaki_video_decoder_init(&session->video_decoder, &global_log);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
free(session);
|
||||
|
@ -289,7 +295,7 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
goto beach;
|
||||
}
|
||||
|
||||
err = android_chiaki_audio_decoder_init(&session->audio_decoder, log);
|
||||
err = android_chiaki_audio_decoder_init(&session->audio_decoder, &global_log);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
android_chiaki_video_decoder_fini(&session->video_decoder);
|
||||
|
@ -298,14 +304,14 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
goto beach;
|
||||
}
|
||||
|
||||
session->audio_output = android_chiaki_audio_output_new(log);
|
||||
session->audio_output = android_chiaki_audio_output_new(&global_log);
|
||||
|
||||
android_chiaki_audio_decoder_set_cb(&session->audio_decoder, android_chiaki_audio_output_settings, android_chiaki_audio_output_frame, session->audio_output);
|
||||
|
||||
err = chiaki_session_init(&session->session, &connect_info, log);
|
||||
err = chiaki_session_init(&session->session, &connect_info, &global_log);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(log, "JNI ChiakiSession failed to init");
|
||||
CHIAKI_LOGE(&global_log, "JNI ChiakiSession failed to init");
|
||||
android_chiaki_video_decoder_fini(&session->video_decoder);
|
||||
android_chiaki_audio_decoder_fini(&session->audio_decoder);
|
||||
android_chiaki_audio_output_free(session->audio_output);
|
||||
|
@ -319,7 +325,6 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
session->java_session_event_connected_meth = E->GetMethodID(env, session->java_session_class, "eventConnected", "()V");
|
||||
session->java_session_event_login_pin_request_meth = E->GetMethodID(env, session->java_session_class, "eventLoginPinRequest", "(Z)V");
|
||||
session->java_session_event_quit_meth = E->GetMethodID(env, session->java_session_class, "eventQuit", "(ILjava/lang/String;)V");
|
||||
session->java_session_event_rumble_meth = E->GetMethodID(env, session->java_session_class, "eventRumble", "(II)V");
|
||||
|
||||
jclass controller_state_class = E->FindClass(env, BASE_PACKAGE"/ControllerState");
|
||||
session->java_controller_state_buttons = E->GetFieldID(env, controller_state_class, "buttons", "I");
|
||||
|
@ -329,22 +334,6 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
session->java_controller_state_left_y = E->GetFieldID(env, controller_state_class, "leftY", "S");
|
||||
session->java_controller_state_right_x = E->GetFieldID(env, controller_state_class, "rightX", "S");
|
||||
session->java_controller_state_right_y = E->GetFieldID(env, controller_state_class, "rightY", "S");
|
||||
session->java_controller_state_touches = E->GetFieldID(env, controller_state_class, "touches", "[L"BASE_PACKAGE"/ControllerTouch;");
|
||||
session->java_controller_state_gyro_x = E->GetFieldID(env, controller_state_class, "gyroX", "F");
|
||||
session->java_controller_state_gyro_y = E->GetFieldID(env, controller_state_class, "gyroY", "F");
|
||||
session->java_controller_state_gyro_z = E->GetFieldID(env, controller_state_class, "gyroZ", "F");
|
||||
session->java_controller_state_accel_x = E->GetFieldID(env, controller_state_class, "accelX", "F");
|
||||
session->java_controller_state_accel_y = E->GetFieldID(env, controller_state_class, "accelY", "F");
|
||||
session->java_controller_state_accel_z = E->GetFieldID(env, controller_state_class, "accelZ", "F");
|
||||
session->java_controller_state_orient_x = E->GetFieldID(env, controller_state_class, "orientX", "F");
|
||||
session->java_controller_state_orient_y = E->GetFieldID(env, controller_state_class, "orientY", "F");
|
||||
session->java_controller_state_orient_z = E->GetFieldID(env, controller_state_class, "orientZ", "F");
|
||||
session->java_controller_state_orient_w = E->GetFieldID(env, controller_state_class, "orientW", "F");
|
||||
|
||||
jclass controller_touch_class = E->FindClass(env, BASE_PACKAGE"/ControllerTouch");
|
||||
session->java_controller_touch_x = E->GetFieldID(env, controller_touch_class, "x", "S");
|
||||
session->java_controller_touch_y = E->GetFieldID(env, controller_touch_class, "y", "S");
|
||||
session->java_controller_touch_id = E->GetFieldID(env, controller_touch_class, "id", "B");
|
||||
|
||||
chiaki_session_set_event_cb(&session->session, android_chiaki_event_cb, session);
|
||||
chiaki_session_set_video_sample_cb(&session->session, android_chiaki_video_decoder_video_sample, &session->video_decoder);
|
||||
|
@ -354,12 +343,6 @@ JNIEXPORT void JNICALL JNI_FCN(sessionCreate)(JNIEnv *env, jobject obj, jobject
|
|||
chiaki_session_set_audio_sink(&session->session, &audio_sink);
|
||||
|
||||
beach:
|
||||
if(!session && log)
|
||||
{
|
||||
android_chiaki_file_log_fini(log);
|
||||
free(log);
|
||||
}
|
||||
|
||||
free(host_str);
|
||||
E->SetIntField(env, result, E->GetFieldID(env, result_class, "errorCode", "I"), (jint)err);
|
||||
E->SetLongField(env, result, E->GetFieldID(env, result_class, "ptr", "J"), (jlong)session);
|
||||
|
@ -368,39 +351,37 @@ beach:
|
|||
JNIEXPORT void JNICALL JNI_FCN(sessionFree)(JNIEnv *env, jobject obj, jlong ptr)
|
||||
{
|
||||
AndroidChiakiSession *session = (AndroidChiakiSession *)ptr;
|
||||
CHIAKI_LOGI(&global_log, "Shutting down JNI Session");
|
||||
if(!session)
|
||||
return;
|
||||
CHIAKI_LOGI(session->log, "Shutting down JNI Session");
|
||||
chiaki_session_fini(&session->session);
|
||||
free(session);
|
||||
android_chiaki_video_decoder_fini(&session->video_decoder);
|
||||
android_chiaki_audio_decoder_fini(&session->audio_decoder);
|
||||
android_chiaki_audio_output_free(session->audio_output);
|
||||
E->DeleteGlobalRef(env, session->java_session);
|
||||
E->DeleteGlobalRef(env, session->java_session_class);
|
||||
CHIAKI_LOGI(session->log, "JNI Session has quit");
|
||||
android_chiaki_file_log_fini(session->log);
|
||||
free(session->log);
|
||||
free(session);
|
||||
CHIAKI_LOGI(&global_log, "JNI Session has quit");
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_FCN(sessionStart)(JNIEnv *env, jobject obj, jlong ptr)
|
||||
{
|
||||
AndroidChiakiSession *session = (AndroidChiakiSession *)ptr;
|
||||
CHIAKI_LOGI(session->log, "Start JNI Session");
|
||||
CHIAKI_LOGI(&global_log, "Start JNI Session");
|
||||
return chiaki_session_start(&session->session);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_FCN(sessionStop)(JNIEnv *env, jobject obj, jlong ptr)
|
||||
{
|
||||
AndroidChiakiSession *session = (AndroidChiakiSession *)ptr;
|
||||
CHIAKI_LOGI(session->log, "Stop JNI Session");
|
||||
CHIAKI_LOGI(&global_log, "Stop JNI Session");
|
||||
return chiaki_session_stop(&session->session);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_FCN(sessionJoin)(JNIEnv *env, jobject obj, jlong ptr)
|
||||
{
|
||||
AndroidChiakiSession *session = (AndroidChiakiSession *)ptr;
|
||||
CHIAKI_LOGI(session->log, "Join JNI Session");
|
||||
CHIAKI_LOGI(&global_log, "Join JNI Session");
|
||||
return chiaki_session_join(&session->session);
|
||||
}
|
||||
|
||||
|
@ -413,8 +394,7 @@ JNIEXPORT void JNICALL JNI_FCN(sessionSetSurface)(JNIEnv *env, jobject obj, jlon
|
|||
JNIEXPORT void JNICALL JNI_FCN(sessionSetControllerState)(JNIEnv *env, jobject obj, jlong ptr, jobject controller_state_java)
|
||||
{
|
||||
AndroidChiakiSession *session = (AndroidChiakiSession *)ptr;
|
||||
ChiakiControllerState controller_state;
|
||||
chiaki_controller_state_set_idle(&controller_state);
|
||||
ChiakiControllerState controller_state = { 0 };
|
||||
controller_state.buttons = (uint32_t)E->GetIntField(env, controller_state_java, session->java_controller_state_buttons);
|
||||
controller_state.l2_state = (uint8_t)E->GetByteField(env, controller_state_java, session->java_controller_state_l2_state);
|
||||
controller_state.r2_state = (uint8_t)E->GetByteField(env, controller_state_java, session->java_controller_state_r2_state);
|
||||
|
@ -422,34 +402,6 @@ JNIEXPORT void JNICALL JNI_FCN(sessionSetControllerState)(JNIEnv *env, jobject o
|
|||
controller_state.left_y = (int16_t)E->GetShortField(env, controller_state_java, session->java_controller_state_left_y);
|
||||
controller_state.right_x = (int16_t)E->GetShortField(env, controller_state_java, session->java_controller_state_right_x);
|
||||
controller_state.right_y = (int16_t)E->GetShortField(env, controller_state_java, session->java_controller_state_right_y);
|
||||
jobjectArray touch_array = E->GetObjectField(env, controller_state_java, session->java_controller_state_touches);
|
||||
size_t touch_array_len = (size_t)E->GetArrayLength(env, touch_array);
|
||||
for(size_t i = 0; i < CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
if(i < touch_array_len)
|
||||
{
|
||||
jobject touch = E->GetObjectArrayElement(env, touch_array, i);
|
||||
controller_state.touches[i].x = (uint16_t)E->GetShortField(env, touch, session->java_controller_touch_x);
|
||||
controller_state.touches[i].y = (uint16_t)E->GetShortField(env, touch, session->java_controller_touch_y);
|
||||
controller_state.touches[i].id = (int8_t)E->GetByteField(env, touch, session->java_controller_touch_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
controller_state.touches[i].x = 0;
|
||||
controller_state.touches[i].y = 0;
|
||||
controller_state.touches[i].id = -1;
|
||||
}
|
||||
}
|
||||
controller_state.gyro_x = E->GetFloatField(env, controller_state_java, session->java_controller_state_gyro_x);
|
||||
controller_state.gyro_y = E->GetFloatField(env, controller_state_java, session->java_controller_state_gyro_y);
|
||||
controller_state.gyro_z = E->GetFloatField(env, controller_state_java, session->java_controller_state_gyro_z);
|
||||
controller_state.accel_x = E->GetFloatField(env, controller_state_java, session->java_controller_state_accel_x);
|
||||
controller_state.accel_y = E->GetFloatField(env, controller_state_java, session->java_controller_state_accel_y);
|
||||
controller_state.accel_z = E->GetFloatField(env, controller_state_java, session->java_controller_state_accel_z);
|
||||
controller_state.orient_x = E->GetFloatField(env, controller_state_java, session->java_controller_state_orient_x);
|
||||
controller_state.orient_y = E->GetFloatField(env, controller_state_java, session->java_controller_state_orient_y);
|
||||
controller_state.orient_z = E->GetFloatField(env, controller_state_java, session->java_controller_state_orient_z);
|
||||
controller_state.orient_w = E->GetFloatField(env, controller_state_java, session->java_controller_state_orient_w);
|
||||
chiaki_session_set_controller_state(&session->session, &controller_state);
|
||||
}
|
||||
|
||||
|
@ -654,92 +606,16 @@ JNIEXPORT void JNICALL JNI_FCN(discoveryServiceFree)(JNIEnv *env, jobject obj, j
|
|||
free(service);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_FCN(discoveryServiceWakeup)(JNIEnv *env, jobject obj, jlong ptr, jstring host_string, jlong user_credential, jboolean ps5)
|
||||
{
|
||||
AndroidDiscoveryService *service = (AndroidDiscoveryService *)ptr;
|
||||
const char *host = E->GetStringUTFChars(env, host_string, NULL);
|
||||
ChiakiErrorCode r = chiaki_discovery_wakeup(&global_log, service ? &service->service.discovery : NULL, host, (uint64_t)user_credential, ps5);
|
||||
E->ReleaseStringUTFChars(env, host_string, host);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
typedef struct android_chiaki_regist_t
|
||||
{
|
||||
AndroidChiakiJNILog log;
|
||||
ChiakiRegist regist;
|
||||
|
||||
AndroidChiakiLog log;
|
||||
jobject java_regist;
|
||||
jmethodID java_regist_event_meth;
|
||||
|
||||
jclass java_target_class;
|
||||
|
||||
jobject java_regist_event_canceled;
|
||||
jobject java_regist_event_failed;
|
||||
jclass java_regist_event_success_class;
|
||||
jmethodID java_regist_event_success_ctor;
|
||||
|
||||
jclass java_regist_host_class;
|
||||
jmethodID java_regist_host_ctor;
|
||||
ChiakiRegist regist;
|
||||
} AndroidChiakiRegist;
|
||||
|
||||
static jobject create_jni_target(JNIEnv *env, jclass target_class, ChiakiTarget target)
|
||||
{
|
||||
jmethodID meth = E->GetStaticMethodID(env, target_class, "fromValue", "(I)L"BASE_PACKAGE"/Target;");
|
||||
return E->CallStaticObjectMethod(env, target_class, meth, (jint)target);
|
||||
}
|
||||
|
||||
static void android_chiaki_regist_cb(ChiakiRegistEvent *event, void *user)
|
||||
{
|
||||
AndroidChiakiRegist *regist = user;
|
||||
|
||||
JNIEnv *env = attach_thread_jni();
|
||||
if(!env)
|
||||
return;
|
||||
|
||||
jobject java_event = NULL;
|
||||
switch(event->type)
|
||||
{
|
||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_CANCELED:
|
||||
java_event = regist->java_regist_event_canceled;
|
||||
break;
|
||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_FAILED:
|
||||
java_event = regist->java_regist_event_failed;
|
||||
break;
|
||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_SUCCESS:
|
||||
{
|
||||
ChiakiRegisteredHost *host = event->registered_host;
|
||||
jobject java_host = E->NewObject(env, regist->java_regist_host_class, regist->java_regist_host_ctor,
|
||||
create_jni_target(env, regist->java_target_class, host->target),
|
||||
jnistr_from_ascii(env, host->ap_ssid),
|
||||
jnistr_from_ascii(env, host->ap_bssid),
|
||||
jnistr_from_ascii(env, host->ap_key),
|
||||
jnistr_from_ascii(env, host->ap_name),
|
||||
jnibytearray_create(env, host->server_mac, sizeof(host->server_mac)),
|
||||
jnistr_from_ascii(env, host->server_nickname),
|
||||
jnibytearray_create(env, (const uint8_t *)host->rp_regist_key, sizeof(host->rp_regist_key)),
|
||||
(jint)host->rp_key_type,
|
||||
jnibytearray_create(env, host->rp_key, sizeof(host->rp_key)));
|
||||
java_event = E->NewObject(env, regist->java_regist_event_success_class, regist->java_regist_event_success_ctor, java_host);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(java_event)
|
||||
E->CallVoidMethod(env, regist->java_regist, regist->java_regist_event_meth, java_event);
|
||||
|
||||
(*global_vm)->DetachCurrentThread(global_vm);
|
||||
}
|
||||
|
||||
static void android_chiaki_regist_fini_partial(JNIEnv *env, AndroidChiakiRegist *regist)
|
||||
{
|
||||
android_chiaki_jni_log_fini(®ist->log, env);
|
||||
E->DeleteGlobalRef(env, regist->java_regist);
|
||||
E->DeleteGlobalRef(env, regist->java_target_class);
|
||||
E->DeleteGlobalRef(env, regist->java_regist_event_canceled);
|
||||
E->DeleteGlobalRef(env, regist->java_regist_event_failed);
|
||||
E->DeleteGlobalRef(env, regist->java_regist_event_success_class);
|
||||
E->DeleteGlobalRef(env, regist->java_regist_host_class);
|
||||
// TODO
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_FCN(registStart)(JNIEnv *env, jobject obj, jobject result, jobject regist_info_obj, jobject log_obj, jobject java_regist)
|
||||
|
@ -753,63 +629,31 @@ JNIEXPORT void JNICALL JNI_FCN(registStart)(JNIEnv *env, jobject obj, jobject re
|
|||
goto beach;
|
||||
}
|
||||
|
||||
android_chiaki_jni_log_init(®ist->log, env, log_obj);
|
||||
android_chiaki_log_init(®ist->log, env, log_obj);
|
||||
|
||||
regist->java_regist = E->NewGlobalRef(env, java_regist);
|
||||
regist->java_regist_event_meth = E->GetMethodID(env, E->GetObjectClass(env, regist->java_regist), "event", "(L"BASE_PACKAGE"/RegistEvent;)V");
|
||||
|
||||
regist->java_target_class = E->NewGlobalRef(env, E->FindClass(env, BASE_PACKAGE"/Target"));
|
||||
|
||||
regist->java_regist_event_canceled = E->NewGlobalRef(env, get_kotlin_global_object(env, BASE_PACKAGE"/RegistEventCanceled"));
|
||||
regist->java_regist_event_failed = E->NewGlobalRef(env, get_kotlin_global_object(env, BASE_PACKAGE"/RegistEventFailed"));
|
||||
regist->java_regist_event_success_class = E->NewGlobalRef(env, E->FindClass(env, BASE_PACKAGE"/RegistEventSuccess"));
|
||||
regist->java_regist_event_success_ctor = E->GetMethodID(env, regist->java_regist_event_success_class, "<init>", "(L"BASE_PACKAGE"/RegistHost;)V");
|
||||
|
||||
regist->java_regist_host_class = E->NewGlobalRef(env, E->FindClass(env, BASE_PACKAGE"/RegistHost"));
|
||||
regist->java_regist_host_ctor = E->GetMethodID(env, regist->java_regist_host_class, "<init>", "("
|
||||
"L"BASE_PACKAGE"/Target;" // target: Target
|
||||
"Ljava/lang/String;" // apSsid: String
|
||||
"Ljava/lang/String;" // apBssid: String
|
||||
"Ljava/lang/String;" // apKey: String
|
||||
"Ljava/lang/String;" // apName: String
|
||||
"[B" // serverMac: ByteArray
|
||||
"Ljava/lang/String;" // serverNickname: String
|
||||
"[B" // rpRegistKey: ByteArray
|
||||
"I" // rpKeyType: UInt
|
||||
"[B" // rpKey: ByteArray
|
||||
")V");
|
||||
|
||||
jclass regist_info_class = E->GetObjectClass(env, regist_info_obj);
|
||||
|
||||
jobject target_obj = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "target", "L"BASE_PACKAGE"/Target;"));
|
||||
jclass target_class = E->GetObjectClass(env, target_obj);
|
||||
jint target_value = E->GetIntField(env, target_obj, E->GetFieldID(env, target_class, "value", "I"));
|
||||
|
||||
jstring host_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "host", "Ljava/lang/String;"));
|
||||
jboolean broadcast = E->GetBooleanField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "broadcast", "Z"));
|
||||
jstring psn_online_id_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnOnlineId", "Ljava/lang/String;"));
|
||||
jbyteArray psn_account_id_array = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnAccountId", "[B"));
|
||||
jstring psn_id_string = E->GetObjectField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "psnId", "Ljava/lang/String;"));
|
||||
jint pin = E->GetIntField(env, regist_info_obj, E->GetFieldID(env, regist_info_class, "pin", "I"));
|
||||
|
||||
ChiakiRegistInfo regist_info = { 0 };
|
||||
regist_info.target = (ChiakiTarget)target_value;
|
||||
ChiakiRegistInfo regist_info;
|
||||
regist_info.host = E->GetStringUTFChars(env, host_string, NULL);
|
||||
regist_info.broadcast = broadcast;
|
||||
if(psn_online_id_string)
|
||||
regist_info.psn_online_id = E->GetStringUTFChars(env, psn_online_id_string, NULL);
|
||||
if(psn_account_id_array && E->GetArrayLength(env, psn_account_id_array) == sizeof(regist_info.psn_account_id))
|
||||
E->GetByteArrayRegion(env, psn_account_id_array, 0, sizeof(regist_info.psn_account_id), (jbyte *)regist_info.psn_account_id);
|
||||
// TODO regist_info.psn_id = E->GetStringUTFChars(env, psn_id_string, NULL);
|
||||
regist_info.pin = (uint32_t)pin;
|
||||
|
||||
err = chiaki_regist_start(®ist->regist, ®ist->log.log, ®ist_info, android_chiaki_regist_cb, regist);
|
||||
|
||||
E->ReleaseStringUTFChars(env, host_string, regist_info.host);
|
||||
if(regist_info.psn_online_id)
|
||||
E->ReleaseStringUTFChars(env, psn_online_id_string, regist_info.psn_online_id);
|
||||
// TODO E->ReleaseStringUTFChars(env, psn_id_string, regist_info.psn_id);
|
||||
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
android_chiaki_regist_fini_partial(env, regist);
|
||||
android_chiaki_log_fini(®ist->log, env);
|
||||
E->DeleteGlobalRef(env, regist->java_regist);
|
||||
free(regist);
|
||||
regist = NULL;
|
||||
}
|
||||
|
@ -829,6 +673,7 @@ JNIEXPORT void JNICALL JNI_FCN(registFree)(JNIEnv *env, jobject obj, jlong ptr)
|
|||
{
|
||||
AndroidChiakiRegist *regist = (AndroidChiakiRegist *)ptr;
|
||||
chiaki_regist_fini(®ist->regist);
|
||||
android_chiaki_regist_fini_partial(env, regist);
|
||||
android_chiaki_log_fini(®ist->log, env);
|
||||
E->DeleteGlobalRef(env, regist->java_regist);
|
||||
free(regist);
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
#ifndef CHIAKI_JNI_H
|
||||
#define CHIAKI_JNI_H
|
||||
|
||||
#define JNI_VERSION JNI_VERSION_1_6
|
||||
|
||||
#define BASE_PACKAGE "com/metallic/chiaki/lib"
|
||||
#define JNI_FCN(name) Java_com_metallic_chiaki_lib_ChiakiNative_##name
|
||||
|
||||
#define E (*env)
|
||||
|
||||
JNIEnv *attach_thread_jni();
|
||||
jobject jnistr_from_ascii(JNIEnv *env, const char *str);
|
||||
|
||||
extern JavaVM *global_vm;
|
||||
|
||||
#endif
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_JNI_CIRCULARBUF_HPP
|
||||
#define CHIAKI_JNI_CIRCULARBUF_HPP
|
||||
|
@ -13,8 +28,8 @@
|
|||
template<size_t ChunksCount, size_t ChunkSize>
|
||||
class CircularBuffer
|
||||
{
|
||||
static_assert(ChunksCount > 0, "ChunksCount > 0");
|
||||
static_assert(ChunkSize > 0, "ChunkSize > 0");
|
||||
static_assert(ChunksCount > 0);
|
||||
static_assert(ChunkSize > 0);
|
||||
|
||||
private:
|
||||
using Queue = memory_relaxed_aquire_release::CircularFifo<uint8_t *, ChunksCount>;
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "chiaki-jni.h"
|
||||
|
||||
#define LOG_TAG "Chiaki"
|
||||
|
||||
void log_cb_android(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
int prio;
|
||||
switch(level)
|
||||
{
|
||||
case CHIAKI_LOG_DEBUG:
|
||||
prio = ANDROID_LOG_DEBUG;
|
||||
break;
|
||||
case CHIAKI_LOG_VERBOSE:
|
||||
prio = ANDROID_LOG_VERBOSE;
|
||||
break;
|
||||
case CHIAKI_LOG_INFO:
|
||||
prio = ANDROID_LOG_INFO;
|
||||
break;
|
||||
case CHIAKI_LOG_WARNING:
|
||||
prio = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
case CHIAKI_LOG_ERROR:
|
||||
prio = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
default:
|
||||
prio = ANDROID_LOG_INFO;
|
||||
break;
|
||||
}
|
||||
__android_log_write(prio, LOG_TAG, msg);
|
||||
}
|
||||
|
||||
static void log_cb_android_file(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
log_cb_android(level, msg, user);
|
||||
FILE *f = user;
|
||||
if(!f)
|
||||
return;
|
||||
switch(level)
|
||||
{
|
||||
case CHIAKI_LOG_DEBUG:
|
||||
fwrite("[D] ", 4, 1, f);
|
||||
break;
|
||||
case CHIAKI_LOG_VERBOSE:
|
||||
fwrite("[V] ", 4, 1, f);
|
||||
break;
|
||||
case CHIAKI_LOG_INFO:
|
||||
fwrite("[I] ", 4, 1, f);
|
||||
break;
|
||||
case CHIAKI_LOG_WARNING:
|
||||
fwrite("[W] ", 4, 1, f);
|
||||
break;
|
||||
case CHIAKI_LOG_ERROR:
|
||||
fwrite("[E] ", 4, 1, f);
|
||||
break;
|
||||
default:
|
||||
fwrite("[?] ", 4, 1, f);
|
||||
break;
|
||||
}
|
||||
fwrite(msg, strlen(msg), 1, f);
|
||||
fwrite("\n", 1, 1, f);
|
||||
}
|
||||
|
||||
ChiakiErrorCode android_chiaki_file_log_init(ChiakiLog *log, uint32_t level, const char *file)
|
||||
{
|
||||
chiaki_log_init(log, level, log_cb_android, NULL);
|
||||
if(file)
|
||||
{
|
||||
FILE *f = fopen(file, "w+");
|
||||
if(!f)
|
||||
{
|
||||
CHIAKI_LOGE(log, "Failed to open log file %s for writing: %s", file, strerror(errno));
|
||||
return CHIAKI_ERR_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
log->user = f;
|
||||
log->cb = log_cb_android_file;
|
||||
CHIAKI_LOGI(log, "Logging to file %s", file);
|
||||
}
|
||||
}
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
void android_chiaki_file_log_fini(ChiakiLog *log)
|
||||
{
|
||||
if(log->user)
|
||||
{
|
||||
FILE *f = log->user;
|
||||
fclose(f);
|
||||
log->user = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void android_chiaki_log_cb(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
log_cb_android(level, msg, NULL);
|
||||
|
||||
AndroidChiakiJNILog *log = user;
|
||||
JNIEnv *env = attach_thread_jni();
|
||||
if(!env)
|
||||
return;
|
||||
E->CallVoidMethod(env, log->java_log, log->java_log_meth, (jint)level, jnistr_from_ascii(env, msg));
|
||||
(*global_vm)->DetachCurrentThread(global_vm);
|
||||
}
|
||||
|
||||
void android_chiaki_jni_log_init(AndroidChiakiJNILog *log, JNIEnv *env, jobject java_log)
|
||||
{
|
||||
log->java_log = E->NewGlobalRef(env, java_log);
|
||||
jclass log_class = E->GetObjectClass(env, log->java_log);
|
||||
log->java_log_meth = E->GetMethodID(env, log_class, "log", "(ILjava/lang/String;)V");
|
||||
log->log.level_mask = (uint32_t)E->GetIntField(env, log->java_log, E->GetFieldID(env, log_class, "levelMask", "I"));
|
||||
log->log.cb = android_chiaki_log_cb;
|
||||
log->log.user = log;
|
||||
}
|
||||
|
||||
void android_chiaki_jni_log_fini(AndroidChiakiJNILog *log, JNIEnv *env)
|
||||
{
|
||||
E->DeleteGlobalRef(env, log->java_log);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
#ifndef CHIAKI_JNI_LOG_H
|
||||
#define CHIAKI_JNI_LOG_H
|
||||
|
||||
#include <chiaki/log.h>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
typedef struct android_jni_chiaki_log_t
|
||||
{
|
||||
jobject java_log;
|
||||
jmethodID java_log_meth;
|
||||
ChiakiLog log;
|
||||
} AndroidChiakiJNILog;
|
||||
|
||||
ChiakiErrorCode android_chiaki_file_log_init(ChiakiLog *log, uint32_t level, const char *file);
|
||||
void android_chiaki_file_log_fini(ChiakiLog *log);
|
||||
|
||||
void android_chiaki_jni_log_init(AndroidChiakiJNILog *log, JNIEnv *env, jobject java_log);
|
||||
void android_chiaki_jni_log_fini(AndroidChiakiJNILog *log, JNIEnv *env);
|
||||
|
||||
#endif
|
|
@ -1 +1 @@
|
|||
Subproject commit 8740d0fc321a55489dbbf6067298201b7d2e106d
|
||||
Subproject commit 0ab5b12a5bc3630a3d6c83b20eed2a669ebf7a24
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "video-decoder.h"
|
||||
|
||||
|
@ -14,46 +29,31 @@
|
|||
|
||||
static void *android_chiaki_video_decoder_output_thread_func(void *user);
|
||||
|
||||
ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log, int32_t target_width, int32_t target_height, ChiakiCodec codec)
|
||||
ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log)
|
||||
{
|
||||
decoder->log = log;
|
||||
decoder->codec = NULL;
|
||||
decoder->timestamp_cur = 0;
|
||||
decoder->target_width = target_width;
|
||||
decoder->target_height = target_height;
|
||||
decoder->target_codec = codec;
|
||||
decoder->shutdown_output = false;
|
||||
return chiaki_mutex_init(&decoder->codec_mutex, false);
|
||||
}
|
||||
|
||||
static void kill_decoder(AndroidChiakiVideoDecoder *decoder)
|
||||
{
|
||||
chiaki_mutex_lock(&decoder->codec_mutex);
|
||||
decoder->shutdown_output = true;
|
||||
ssize_t codec_buf_index = AMediaCodec_dequeueInputBuffer(decoder->codec, 1000);
|
||||
if(codec_buf_index >= 0)
|
||||
{
|
||||
CHIAKI_LOGI(decoder->log, "Video Decoder sending EOS buffer");
|
||||
AMediaCodec_queueInputBuffer(decoder->codec, (size_t)codec_buf_index, 0, 0, decoder->timestamp_cur++, AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM);
|
||||
AMediaCodec_stop(decoder->codec);
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
chiaki_thread_join(&decoder->output_thread, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "Failed to get input buffer for shutting down Video Decoder!");
|
||||
AMediaCodec_stop(decoder->codec);
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
}
|
||||
AMediaCodec_delete(decoder->codec);
|
||||
decoder->codec = NULL;
|
||||
decoder->shutdown_output = false;
|
||||
}
|
||||
|
||||
void android_chiaki_video_decoder_fini(AndroidChiakiVideoDecoder *decoder)
|
||||
{
|
||||
if(decoder->codec)
|
||||
kill_decoder(decoder);
|
||||
{
|
||||
chiaki_mutex_lock(&decoder->codec_mutex);
|
||||
ssize_t codec_buf_index = AMediaCodec_dequeueInputBuffer(decoder->codec, -1);
|
||||
if(codec_buf_index >= 0)
|
||||
{
|
||||
CHIAKI_LOGI(decoder->log, "Video Decoder sending EOS buffer");
|
||||
AMediaCodec_queueInputBuffer(decoder->codec, (size_t)codec_buf_index, 0, 0, decoder->timestamp_cur++, AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM);
|
||||
}
|
||||
else
|
||||
CHIAKI_LOGE(decoder->log, "Failed to get input buffer for shutting down Video Decoder!");
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
chiaki_thread_join(&decoder->output_thread, NULL);
|
||||
AMediaCodec_delete(decoder->codec);
|
||||
}
|
||||
chiaki_mutex_fini(&decoder->codec_mutex);
|
||||
}
|
||||
|
||||
|
@ -61,87 +61,56 @@ void android_chiaki_video_decoder_set_surface(AndroidChiakiVideoDecoder *decoder
|
|||
{
|
||||
chiaki_mutex_lock(&decoder->codec_mutex);
|
||||
|
||||
if(!surface)
|
||||
{
|
||||
if(decoder->codec)
|
||||
{
|
||||
kill_decoder(decoder);
|
||||
CHIAKI_LOGI(decoder->log, "Decoder shut down after surface was removed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(decoder->codec)
|
||||
{
|
||||
#if __ANDROID_API__ >= 23
|
||||
//CHIAKI_LOGE(decoder->log, "Video Decoder already initialized");
|
||||
CHIAKI_LOGI(decoder->log, "Video decoder already initialized, swapping surface");
|
||||
ANativeWindow *new_window = surface ? ANativeWindow_fromSurface(env, surface) : NULL;
|
||||
AMediaCodec_setOutputSurface(decoder->codec, new_window);
|
||||
ANativeWindow_release(decoder->window);
|
||||
decoder->window = new_window;
|
||||
#else
|
||||
CHIAKI_LOGE(decoder->log, "Video Decoder already initialized");
|
||||
#endif
|
||||
goto beach;
|
||||
}
|
||||
|
||||
decoder->window = ANativeWindow_fromSurface(env, surface);
|
||||
|
||||
const char *mime = chiaki_codec_is_h265(decoder->target_codec) ? "video/hevc" : "video/avc";
|
||||
CHIAKI_LOGI(decoder->log, "Initializing decoder with mime %s", mime);
|
||||
const char *mime = "video/avc";
|
||||
|
||||
decoder->codec = AMediaCodec_createDecoderByType(mime);
|
||||
if(!decoder->codec)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "Failed to create AMediaCodec for mime type %s", mime);
|
||||
goto error_surface;
|
||||
ANativeWindow_release(decoder->window);
|
||||
decoder->window = NULL;
|
||||
goto beach;
|
||||
}
|
||||
|
||||
AMediaFormat *format = AMediaFormat_new();
|
||||
AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, mime);
|
||||
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, decoder->target_width);
|
||||
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, decoder->target_height);
|
||||
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, 1280); // TODO: correct values
|
||||
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, 720);
|
||||
|
||||
media_status_t r = AMediaCodec_configure(decoder->codec, format, decoder->window, NULL, 0);
|
||||
if(r != AMEDIA_OK)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "AMediaCodec_configure() failed: %d", (int)r);
|
||||
AMediaFormat_delete(format);
|
||||
goto error_codec;
|
||||
}
|
||||
AMediaCodec_configure(decoder->codec, format, decoder->window, NULL, 0); // TODO: check result
|
||||
AMediaCodec_start(decoder->codec); // TODO: check result
|
||||
|
||||
r = AMediaCodec_start(decoder->codec);
|
||||
AMediaFormat_delete(format);
|
||||
if(r != AMEDIA_OK)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "AMediaCodec_start() failed: %d", (int)r);
|
||||
goto error_codec;
|
||||
}
|
||||
|
||||
ChiakiErrorCode err = chiaki_thread_create(&decoder->output_thread, android_chiaki_video_decoder_output_thread_func, decoder);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "Failed to create output thread for AMediaCodec");
|
||||
goto error_codec;
|
||||
AMediaCodec_delete(decoder->codec);
|
||||
decoder->codec = NULL;
|
||||
ANativeWindow_release(decoder->window);
|
||||
decoder->window = NULL;
|
||||
}
|
||||
|
||||
goto beach;
|
||||
|
||||
error_codec:
|
||||
AMediaCodec_delete(decoder->codec);
|
||||
decoder->codec = NULL;
|
||||
|
||||
error_surface:
|
||||
ANativeWindow_release(decoder->window);
|
||||
decoder->window = NULL;
|
||||
|
||||
beach:
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
}
|
||||
|
||||
bool android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user)
|
||||
void android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user)
|
||||
{
|
||||
bool r = true;
|
||||
AndroidChiakiVideoDecoder *decoder = user;
|
||||
chiaki_mutex_lock(&decoder->codec_mutex);
|
||||
|
||||
|
@ -157,7 +126,7 @@ bool android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, vo
|
|||
if(codec_buf_index < 0)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "Failed to get input buffer");
|
||||
r = false;
|
||||
// TODO: report corrupt
|
||||
goto beach;
|
||||
}
|
||||
|
||||
|
@ -170,11 +139,7 @@ bool android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, vo
|
|||
codec_sample_size = codec_buf_size;
|
||||
}
|
||||
memcpy(codec_buf, buf, codec_sample_size);
|
||||
media_status_t r = AMediaCodec_queueInputBuffer(decoder->codec, (size_t)codec_buf_index, 0, codec_sample_size, decoder->timestamp_cur++, 0); // timestamp just raised by 1 for maximum realtime
|
||||
if(r != AMEDIA_OK)
|
||||
{
|
||||
CHIAKI_LOGE(decoder->log, "AMediaCodec_queueInputBuffer() failed: %d", (int)r);
|
||||
}
|
||||
AMediaCodec_queueInputBuffer(decoder->codec, (size_t)codec_buf_index, 0, codec_sample_size, decoder->timestamp_cur++, 0); // timestamp just raised by 1 for maximum realtime
|
||||
buf += codec_sample_size;
|
||||
buf_size -= codec_sample_size;
|
||||
|
||||
|
@ -182,7 +147,6 @@ bool android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, vo
|
|||
|
||||
beach:
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void *android_chiaki_video_decoder_output_thread_func(void *user)
|
||||
|
@ -202,17 +166,6 @@ static void *android_chiaki_video_decoder_output_thread_func(void *user)
|
|||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chiaki_mutex_lock(&decoder->codec_mutex);
|
||||
bool shutdown = decoder->shutdown_output;
|
||||
chiaki_mutex_unlock(&decoder->codec_mutex);
|
||||
if(shutdown)
|
||||
{
|
||||
CHIAKI_LOGI(decoder->log, "Video Decoder Output Thread detected shutdown after reported error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(decoder->log, "Video Decoder Output Thread exiting");
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_JNI_VIDEO_DECODER_H
|
||||
#define CHIAKI_JNI_VIDEO_DECODER_H
|
||||
|
@ -19,15 +34,11 @@ typedef struct android_chiaki_video_decoder_t
|
|||
ANativeWindow *window;
|
||||
uint64_t timestamp_cur;
|
||||
ChiakiThread output_thread;
|
||||
bool shutdown_output;
|
||||
int32_t target_width;
|
||||
int32_t target_height;
|
||||
ChiakiCodec target_codec;
|
||||
} AndroidChiakiVideoDecoder;
|
||||
|
||||
ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log, int32_t target_width, int32_t target_height, ChiakiCodec codec);
|
||||
ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log);
|
||||
void android_chiaki_video_decoder_fini(AndroidChiakiVideoDecoder *decoder);
|
||||
void android_chiaki_video_decoder_set_surface(AndroidChiakiVideoDecoder *decoder, JNIEnv *env, jobject surface);
|
||||
bool android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user);
|
||||
void android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user);
|
||||
|
||||
#endif
|
173
android/app/src/main/java/com/metallic/chiaki/StreamSession.kt
Normal file
173
android/app/src/main/java/com/metallic/chiaki/StreamSession.kt
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki
|
||||
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.Surface
|
||||
import android.view.TextureView
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.metallic.chiaki.lib.*
|
||||
|
||||
sealed class StreamState
|
||||
object StreamStateIdle: StreamState()
|
||||
object StreamStateConnecting: StreamState()
|
||||
object StreamStateConnected: StreamState()
|
||||
data class StreamStateCreateError(val error: CreateError): StreamState()
|
||||
data class StreamStateQuit(val reason: QuitReason, val reasonString: String?): StreamState()
|
||||
data class StreamStateLoginPinRequest(val pinIncorrect: Boolean): StreamState()
|
||||
|
||||
class StreamSession(val connectInfo: ConnectInfo)
|
||||
{
|
||||
var session: Session? = null
|
||||
private set
|
||||
|
||||
private val _state = MutableLiveData<StreamState>(StreamStateIdle)
|
||||
val state: LiveData<StreamState> get() = _state
|
||||
|
||||
private val controllerState = ControllerState()
|
||||
private var touchControllerState = ControllerState()
|
||||
|
||||
var surfaceTexture: SurfaceTexture? = null
|
||||
|
||||
fun shutdown()
|
||||
{
|
||||
session?.stop()
|
||||
session?.dispose()
|
||||
session = null
|
||||
_state.value = StreamStateIdle
|
||||
//surfaceTexture?.release()
|
||||
}
|
||||
|
||||
fun pause()
|
||||
{
|
||||
shutdown()
|
||||
}
|
||||
|
||||
fun resume()
|
||||
{
|
||||
if(session != null)
|
||||
return
|
||||
try
|
||||
{
|
||||
val session = Session(connectInfo)
|
||||
_state.value = StreamStateConnecting
|
||||
session.eventCallback = this::eventCallback
|
||||
session.start()
|
||||
val surfaceTexture = surfaceTexture
|
||||
if(surfaceTexture != null)
|
||||
session.setSurface(Surface(surfaceTexture))
|
||||
this.session = session
|
||||
}
|
||||
catch(e: CreateError)
|
||||
{
|
||||
_state.value = StreamStateCreateError(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun eventCallback(event: Event)
|
||||
{
|
||||
when(event)
|
||||
{
|
||||
is ConnectedEvent -> _state.postValue(StreamStateConnected)
|
||||
is QuitEvent -> _state.postValue(StreamStateQuit(event.reason, event.reasonString))
|
||||
is LoginPinRequestEvent -> _state.postValue(StreamStateLoginPinRequest(event.pinIncorrect))
|
||||
}
|
||||
}
|
||||
|
||||
fun attachToTextureView(textureView: TextureView)
|
||||
{
|
||||
textureView.surfaceTextureListener = object: TextureView.SurfaceTextureListener {
|
||||
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int)
|
||||
{
|
||||
if(surfaceTexture != null)
|
||||
return
|
||||
surfaceTexture = surface
|
||||
session?.setSurface(Surface(surface))
|
||||
}
|
||||
|
||||
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean
|
||||
{
|
||||
// return false if we want to keep the surface texture
|
||||
return surfaceTexture == null
|
||||
}
|
||||
|
||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) { }
|
||||
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {}
|
||||
}
|
||||
|
||||
val surfaceTexture = surfaceTexture
|
||||
if(surfaceTexture != null)
|
||||
textureView.surfaceTexture = surfaceTexture
|
||||
}
|
||||
|
||||
fun setLoginPin(pin: String)
|
||||
{
|
||||
session?.setLoginPin(pin)
|
||||
}
|
||||
|
||||
fun dispatchKeyEvent(event: KeyEvent): Boolean
|
||||
{
|
||||
Log.i("StreamSession", "key event $event")
|
||||
val buttonMask: UInt = when(event.keyCode)
|
||||
{
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> ControllerState.BUTTON_DPAD_LEFT
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> ControllerState.BUTTON_DPAD_RIGHT
|
||||
KeyEvent.KEYCODE_DPAD_UP -> ControllerState.BUTTON_DPAD_UP
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> ControllerState.BUTTON_DPAD_DOWN
|
||||
KeyEvent.KEYCODE_BUTTON_A -> ControllerState.BUTTON_CROSS
|
||||
KeyEvent.KEYCODE_BUTTON_B -> ControllerState.BUTTON_MOON
|
||||
KeyEvent.KEYCODE_BUTTON_X -> ControllerState.BUTTON_BOX
|
||||
KeyEvent.KEYCODE_BUTTON_Y -> ControllerState.BUTTON_PYRAMID
|
||||
KeyEvent.KEYCODE_BUTTON_L1 -> ControllerState.BUTTON_L1
|
||||
KeyEvent.KEYCODE_BUTTON_R1 -> ControllerState.BUTTON_R1
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBL -> ControllerState.BUTTON_L3
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBR -> ControllerState.BUTTON_R3
|
||||
KeyEvent.KEYCODE_BUTTON_SELECT -> ControllerState.BUTTON_SHARE
|
||||
KeyEvent.KEYCODE_BUTTON_START -> ControllerState.BUTTON_OPTIONS
|
||||
KeyEvent.KEYCODE_BUTTON_C -> ControllerState.BUTTON_PS
|
||||
KeyEvent.KEYCODE_BUTTON_MODE -> ControllerState.BUTTON_PS
|
||||
else -> return false
|
||||
}
|
||||
|
||||
controllerState.buttons = controllerState.buttons.run {
|
||||
when(event.action)
|
||||
{
|
||||
KeyEvent.ACTION_DOWN -> this or buttonMask
|
||||
KeyEvent.ACTION_UP -> this and buttonMask.inv()
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
|
||||
sendControllerState()
|
||||
return true
|
||||
}
|
||||
|
||||
fun updateTouchControllerState(controllerState: ControllerState)
|
||||
{
|
||||
touchControllerState = controllerState
|
||||
sendControllerState()
|
||||
}
|
||||
|
||||
private fun sendControllerState()
|
||||
{
|
||||
session?.setControllerState(controllerState or touchControllerState)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import com.metallic.chiaki.common.ext.RevealActivity
|
||||
import com.metallic.chiaki.lib.ConnectInfo
|
||||
import com.metallic.chiaki.lib.ConnectVideoProfile
|
||||
import com.metallic.chiaki.stream.StreamActivity
|
||||
import kotlinx.android.synthetic.main.activity_test_start.*
|
||||
|
||||
class TestStartActivity : AppCompatActivity(), RevealActivity
|
||||
{
|
||||
override val revealIntent: Intent get() = intent
|
||||
override val revealRootLayout: View get() = rootLayout
|
||||
override val revealWindow: Window get() = window
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_test_start)
|
||||
handleReveal()
|
||||
|
||||
val prefs = getPreferences(Context.MODE_PRIVATE)
|
||||
|
||||
hostEditText.setText(prefs.getString("debug_host", ""))
|
||||
registKeyEditText.setText(prefs.getString("debug_regist_key", ""))
|
||||
morningEditText.setText(prefs.getString("debug_morning", ""))
|
||||
|
||||
hostEditText.addTextChangedListener {
|
||||
prefs.edit {
|
||||
putString("debug_host", it?.toString())
|
||||
}
|
||||
}
|
||||
|
||||
registKeyEditText.addTextChangedListener {
|
||||
prefs.edit {
|
||||
putString("debug_regist_key", it?.toString())
|
||||
}
|
||||
}
|
||||
|
||||
morningEditText.addTextChangedListener {
|
||||
prefs.edit {
|
||||
putString("debug_morning", it?.toString())
|
||||
}
|
||||
}
|
||||
|
||||
startButton.setOnClickListener {
|
||||
val registKeyBase = registKeyEditText.text.toString().toByteArray(Charsets.US_ASCII)
|
||||
val registKey = registKeyBase + ByteArray(0x10 - registKeyBase.size) { 0 }
|
||||
val morning = Base64.decode(morningEditText.text.toString(), Base64.DEFAULT)
|
||||
val connectInfo = ConnectInfo(hostEditText.text.toString(),
|
||||
registKey,
|
||||
morning,
|
||||
ConnectVideoProfile(1280, 720, 60, 10000))
|
||||
|
||||
Intent(this, StreamActivity::class.java).let {
|
||||
it.putExtra(StreamActivity.EXTRA_CONNECT_INFO, connectInfo)
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +1,33 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.*
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.metallic.chiaki.lib.Target
|
||||
|
||||
@Database(
|
||||
version = 2,
|
||||
version = 1,
|
||||
entities = [RegisteredHost::class, ManualHost::class])
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AppDatabase: RoomDatabase()
|
||||
{
|
||||
abstract fun registeredHostDao(): RegisteredHostDao
|
||||
abstract fun manualHostDao(): ManualHostDao
|
||||
abstract fun importDao(): ImportDao
|
||||
}
|
||||
|
||||
val MIGRATION_1_2 = object : Migration(1, 2)
|
||||
{
|
||||
override fun migrate(database: SupportSQLiteDatabase)
|
||||
{
|
||||
database.execSQL("ALTER TABLE registered_host ADD target INTEGER NOT NULL DEFAULT 1000")
|
||||
database.execSQL("CREATE TABLE `new_registered_host` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `target` INTEGER NOT NULL, `ap_ssid` TEXT, `ap_bssid` TEXT, `ap_key` TEXT, `ap_name` TEXT, `server_mac` INTEGER NOT NULL, `server_nickname` TEXT, `rp_regist_key` BLOB NOT NULL, `rp_key_type` INTEGER NOT NULL, `rp_key` BLOB NOT NULL)");
|
||||
database.execSQL("INSERT INTO `new_registered_host` SELECT `id`, `target`, `ap_ssid`, `ap_bssid`, `ap_key`, `ap_name`, `ps4_mac`, `ps4_nickname`, `rp_regist_key`, `rp_key_type`, `rp_key` FROM `registered_host`")
|
||||
database.execSQL("DROP TABLE registered_host")
|
||||
database.execSQL("ALTER TABLE new_registered_host RENAME TO registered_host")
|
||||
}
|
||||
}
|
||||
|
||||
private var database: AppDatabase? = null
|
||||
|
@ -40,9 +39,7 @@ fun getDatabase(context: Context): AppDatabase
|
|||
val db = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
AppDatabase::class.java,
|
||||
"chiaki")
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.build()
|
||||
"chiaki").build()
|
||||
database = db
|
||||
return db
|
||||
}
|
||||
|
@ -54,10 +51,4 @@ private class Converters
|
|||
|
||||
@TypeConverter
|
||||
fun macToValue(addr: MacAddress) = addr.value
|
||||
|
||||
@TypeConverter
|
||||
fun targetFromValue(v: Int) = Target.fromValue(v)
|
||||
|
||||
@TypeConverter
|
||||
fun targetToValue(target: Target) = target.value
|
||||
}
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
|
@ -10,9 +25,6 @@ sealed class DisplayHost
|
|||
abstract val host: String
|
||||
abstract val name: String?
|
||||
abstract val id: String?
|
||||
abstract val isPS5: Boolean
|
||||
|
||||
val isRegistered get() = registeredHost != null
|
||||
}
|
||||
|
||||
class DiscoveredDisplayHost(
|
||||
|
@ -21,19 +33,8 @@ class DiscoveredDisplayHost(
|
|||
): DisplayHost()
|
||||
{
|
||||
override val host get() = discoveredHost.hostAddr ?: ""
|
||||
override val name get() = discoveredHost.hostName ?: registeredHost?.serverNickname
|
||||
override val id get() = discoveredHost.hostId ?: registeredHost?.serverMac?.toString()
|
||||
override val isPS5 get() = discoveredHost.isPS5
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
if(other !is DiscoveredDisplayHost)
|
||||
false
|
||||
else
|
||||
other.discoveredHost == discoveredHost && other.registeredHost == registeredHost
|
||||
|
||||
override fun hashCode() = 31 * (registeredHost?.hashCode() ?: 0) + discoveredHost.hashCode()
|
||||
|
||||
override fun toString() = "DiscoveredDisplayHost{${registeredHost}, ${discoveredHost}}"
|
||||
override val name get() = discoveredHost.hostName ?: registeredHost?.ps4Nickname
|
||||
override val id get() = discoveredHost.hostId ?: registeredHost?.ps4Mac?.toString()
|
||||
}
|
||||
|
||||
class ManualDisplayHost(
|
||||
|
@ -42,17 +43,6 @@ class ManualDisplayHost(
|
|||
): DisplayHost()
|
||||
{
|
||||
override val host get() = manualHost.host
|
||||
override val name get() = registeredHost?.serverNickname
|
||||
override val id get() = registeredHost?.serverMac?.toString()
|
||||
override val isPS5: Boolean get() = registeredHost?.target?.isPS5 ?: false
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
if(other !is ManualDisplayHost)
|
||||
false
|
||||
else
|
||||
other.manualHost == manualHost && other.registeredHost == registeredHost
|
||||
|
||||
override fun hashCode() = 31 * (registeredHost?.hashCode() ?: 0) + manualHost.hashCode()
|
||||
|
||||
override fun toString() = "ManualDisplayHost{${registeredHost}, ${manualHost}}"
|
||||
override val name get() = registeredHost?.ps4Nickname
|
||||
override val id get() = registeredHost?.ps4Mac?.toString()
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
val fileProviderAuthority = "com.metallic.chiaki.fileprovider"
|
||||
private const val baseDirName = "session_logs" // must be in sync with filepaths.xml
|
||||
private val dateFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS", Locale.US)
|
||||
private const val filePrefix = "chiaki_session_"
|
||||
private const val filePostfix = ".log"
|
||||
private val fileRegex = Regex("$filePrefix(.*)$filePostfix")
|
||||
private const val keepLogFilesCount = 5
|
||||
|
||||
class LogFile private constructor(val logManager: LogManager, val filename: String)
|
||||
{
|
||||
val date = fileRegex.matchEntire(filename)?.groupValues?.get(1)?.let {
|
||||
dateFormat.parse(it)
|
||||
} ?: throw IllegalArgumentException()
|
||||
|
||||
val file get() = File(logManager.baseDir, filename)
|
||||
|
||||
companion object
|
||||
{
|
||||
fun fromFilename(logManager: LogManager, filename: String) = try { LogFile(logManager, filename) } catch(e: IllegalArgumentException) { null }
|
||||
}
|
||||
}
|
||||
|
||||
class LogManager(context: Context)
|
||||
{
|
||||
val baseDir = File(context.filesDir, baseDirName).also {
|
||||
it.mkdirs()
|
||||
}
|
||||
|
||||
val files: List<LogFile> get() =
|
||||
(baseDir.list { _, s -> s.matches(fileRegex) }?.toList() ?: listOf()).mapNotNull {
|
||||
LogFile.fromFilename(this, it)
|
||||
}.sortedByDescending {
|
||||
it.date
|
||||
}
|
||||
|
||||
fun createNewFile(): LogFile
|
||||
{
|
||||
val currentFiles = files
|
||||
if(currentFiles.size > keepLogFilesCount)
|
||||
{
|
||||
currentFiles.subList(keepLogFilesCount, currentFiles.size).forEach {
|
||||
it.file.delete()
|
||||
}
|
||||
}
|
||||
|
||||
val date = Date()
|
||||
val filename = "$filePrefix${dateFormat.format(date)}$filePostfix"
|
||||
return LogFile.fromFilename(this, filename)!!
|
||||
}
|
||||
}
|
|
@ -1,39 +1,24 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonDataException
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
class MacAddress(v: Long)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
val LENGTH = 6
|
||||
}
|
||||
|
||||
constructor(data: ByteArray) : this(
|
||||
if(data.size != LENGTH)
|
||||
throw IllegalArgumentException("Data has invalid length for MAC")
|
||||
else
|
||||
data.let {
|
||||
val buf = ByteBuffer.allocate(8)
|
||||
buf.put(it, 0, LENGTH)
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN)
|
||||
buf.getLong(0)
|
||||
})
|
||||
|
||||
constructor(string: String) : this(
|
||||
(Regex("([0-9A-Fa-f]{2})[:-]([0-9A-Fa-f]{2})[:-]([0-9A-Fa-f]{2})[:-]([0-9A-Fa-f]{2})[:-]([0-9A-Fa-f]{2})[:-]([0-9A-Fa-f]{2})").matchEntire(string)
|
||||
?: throw IllegalArgumentException("Invalid MAC Address String"))
|
||||
.groupValues
|
||||
.subList(1, 7)
|
||||
.map { it.toUByte(16).toByte() }
|
||||
.toByteArray())
|
||||
|
||||
val value: Long = v and 0xffffffffffff
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
|
@ -43,19 +28,4 @@ class MacAddress(v: Long)
|
|||
super.equals(other)
|
||||
|
||||
override fun hashCode() = value.hashCode()
|
||||
|
||||
override fun toString(): String = "%02x:%02x:%02x:%02x:%02x:%02x".format(
|
||||
value and 0xff,
|
||||
(value shr 0x8) and 0xff,
|
||||
(value shr 0x10) and 0xff,
|
||||
(value shr 0x18) and 0xff,
|
||||
(value shr 0x20) and 0xff,
|
||||
(value shr 0x28) and 0xff
|
||||
)
|
||||
}
|
||||
|
||||
class MacAddressJsonAdapter
|
||||
{
|
||||
@ToJson fun toJson(macAddress: MacAddress) = macAddress.toString()
|
||||
@FromJson fun fromJson(string: String) = try { MacAddress(string) } catch(e: IllegalArgumentException) { throw JsonDataException(e.message) }
|
||||
}
|
|
@ -1,12 +1,26 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.ForeignKey.Companion.SET_NULL
|
||||
import androidx.room.ForeignKey.SET_NULL
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
|
||||
@Entity(tableName = "manual_host",
|
||||
foreignKeys = [
|
||||
|
@ -18,42 +32,17 @@ import io.reactivex.Single
|
|||
)
|
||||
])
|
||||
data class ManualHost(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
||||
val host: String,
|
||||
@ColumnInfo(name = "registered_host") val registeredHost: Long?
|
||||
)
|
||||
|
||||
data class ManualHostAndRegisteredHost(
|
||||
@Embedded(prefix = "manual_host_") val manualHost: ManualHost,
|
||||
@Embedded val registeredHost: RegisteredHost?
|
||||
@ColumnInfo(name = "registered_host") val registeredHost: Int?
|
||||
)
|
||||
|
||||
@Dao
|
||||
interface ManualHostDao
|
||||
{
|
||||
@Query("SELECT * FROM manual_host WHERE id = :id")
|
||||
fun getById(id: Long): Single<ManualHost>
|
||||
|
||||
@Query("""SELECT
|
||||
manual_host.id as manual_host_id,
|
||||
manual_host.host as manual_host_host,
|
||||
manual_host.registered_host as manual_host_registered_host,
|
||||
registered_host.*
|
||||
FROM manual_host LEFT OUTER JOIN registered_host ON manual_host.registered_host = registered_host.id WHERE manual_host.id = :id""")
|
||||
fun getByIdWithRegisteredHost(id: Long): Single<ManualHostAndRegisteredHost>
|
||||
|
||||
@Query("SELECT * FROM manual_host")
|
||||
fun getAll(): Flowable<List<ManualHost>>
|
||||
|
||||
@Query("UPDATE manual_host SET registered_host = :registeredHostId WHERE id = :manualHostId")
|
||||
fun assignRegisteredHost(manualHostId: Long, registeredHostId: Long?): Completable
|
||||
|
||||
@Insert
|
||||
fun insert(host: ManualHost): Completable
|
||||
|
||||
@Delete
|
||||
fun delete(host: ManualHost): Completable
|
||||
|
||||
@Update
|
||||
fun update(host: ManualHost): Completable
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.lib.Codec
|
||||
import com.metallic.chiaki.lib.ConnectVideoProfile
|
||||
import com.metallic.chiaki.lib.VideoFPSPreset
|
||||
import com.metallic.chiaki.lib.VideoResolutionPreset
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class Preferences(context: Context)
|
||||
{
|
||||
enum class Resolution(val value: String, @StringRes val title: Int, val preset: VideoResolutionPreset)
|
||||
{
|
||||
RES_360P("360p", R.string.preferences_resolution_title_360p, VideoResolutionPreset.RES_360P),
|
||||
RES_540P("540p", R.string.preferences_resolution_title_540p, VideoResolutionPreset.RES_540P),
|
||||
RES_720P("720p", R.string.preferences_resolution_title_720p, VideoResolutionPreset.RES_720P),
|
||||
RES_1080P("1080p", R.string.preferences_resolution_title_1080p, VideoResolutionPreset.RES_1080P),
|
||||
}
|
||||
|
||||
enum class FPS(val value: String, @StringRes val title: Int, val preset: VideoFPSPreset)
|
||||
{
|
||||
FPS_30("30", R.string.preferences_fps_title_30, VideoFPSPreset.FPS_30),
|
||||
FPS_60("60", R.string.preferences_fps_title_60, VideoFPSPreset.FPS_60)
|
||||
}
|
||||
|
||||
enum class Codec(val value: String, @StringRes val title: Int, val codec: com.metallic.chiaki.lib.Codec)
|
||||
{
|
||||
CODEC_H264("h264", R.string.preferences_codec_title_h264, com.metallic.chiaki.lib.Codec.CODEC_H264),
|
||||
CODEC_H265("h265", R.string.preferences_codec_title_h265, com.metallic.chiaki.lib.Codec.CODEC_H265)
|
||||
}
|
||||
|
||||
companion object
|
||||
{
|
||||
val resolutionDefault = Resolution.RES_720P
|
||||
val resolutionAll = Resolution.values()
|
||||
val fpsDefault = FPS.FPS_60
|
||||
val fpsAll = FPS.values()
|
||||
val codecDefault = Codec.CODEC_H265
|
||||
val codecAll = Codec.values()
|
||||
}
|
||||
|
||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
private val sharedPreferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
when(key)
|
||||
{
|
||||
resolutionKey -> bitrateAutoSubject.onNext(bitrateAuto)
|
||||
}
|
||||
}.also { sharedPreferences.registerOnSharedPreferenceChangeListener(it) }
|
||||
|
||||
private val resources = context.resources
|
||||
|
||||
val discoveryEnabledKey get() = resources.getString(R.string.preferences_discovery_enabled_key)
|
||||
var discoveryEnabled
|
||||
get() = sharedPreferences.getBoolean(discoveryEnabledKey, true)
|
||||
set(value) { sharedPreferences.edit().putBoolean(discoveryEnabledKey, value).apply() }
|
||||
|
||||
val onScreenControlsEnabledKey get() = resources.getString(R.string.preferences_on_screen_controls_enabled_key)
|
||||
var onScreenControlsEnabled
|
||||
get() = sharedPreferences.getBoolean(onScreenControlsEnabledKey, true)
|
||||
set(value) { sharedPreferences.edit().putBoolean(onScreenControlsEnabledKey, value).apply() }
|
||||
|
||||
val touchpadOnlyEnabledKey get() = resources.getString(R.string.preferences_touchpad_only_enabled_key)
|
||||
var touchpadOnlyEnabled
|
||||
get() = sharedPreferences.getBoolean(touchpadOnlyEnabledKey, false)
|
||||
set(value) { sharedPreferences.edit().putBoolean(touchpadOnlyEnabledKey, value).apply() }
|
||||
|
||||
val rumbleEnabledKey get() = resources.getString(R.string.preferences_rumble_enabled_key)
|
||||
var rumbleEnabled
|
||||
get() = sharedPreferences.getBoolean(rumbleEnabledKey, true)
|
||||
set(value) { sharedPreferences.edit().putBoolean(rumbleEnabledKey, value).apply() }
|
||||
|
||||
val motionEnabledKey get() = resources.getString(R.string.preferences_motion_enabled_key)
|
||||
var motionEnabled
|
||||
get() = sharedPreferences.getBoolean(motionEnabledKey, true)
|
||||
set(value) { sharedPreferences.edit().putBoolean(motionEnabledKey, value).apply() }
|
||||
|
||||
val buttonHapticEnabledKey get() = resources.getString(R.string.preferences_button_haptic_enabled_key)
|
||||
var buttonHapticEnabled
|
||||
get() = sharedPreferences.getBoolean(buttonHapticEnabledKey, true)
|
||||
set(value) { sharedPreferences.edit().putBoolean(buttonHapticEnabledKey, value).apply() }
|
||||
|
||||
val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
|
||||
var logVerbose
|
||||
get() = sharedPreferences.getBoolean(logVerboseKey, false)
|
||||
set(value) { sharedPreferences.edit().putBoolean(logVerboseKey, value).apply() }
|
||||
|
||||
val swapCrossMoonKey get() = resources.getString(R.string.preferences_swap_cross_moon_key)
|
||||
var swapCrossMoon
|
||||
get() = sharedPreferences.getBoolean(swapCrossMoonKey, false)
|
||||
set(value) { sharedPreferences.edit().putBoolean(swapCrossMoonKey, value).apply() }
|
||||
|
||||
val resolutionKey get() = resources.getString(R.string.preferences_resolution_key)
|
||||
var resolution
|
||||
get() = sharedPreferences.getString(resolutionKey, resolutionDefault.value)?.let { value ->
|
||||
Resolution.values().firstOrNull { it.value == value }
|
||||
} ?: resolutionDefault
|
||||
set(value) { sharedPreferences.edit().putString(resolutionKey, value.value).apply() }
|
||||
|
||||
val fpsKey get() = resources.getString(R.string.preferences_fps_key)
|
||||
var fps
|
||||
get() = sharedPreferences.getString(fpsKey, fpsDefault.value)?.let { value ->
|
||||
FPS.values().firstOrNull { it.value == value }
|
||||
} ?: fpsDefault
|
||||
set(value) { sharedPreferences.edit().putString(fpsKey, value.value).apply() }
|
||||
|
||||
fun validateBitrate(bitrate: Int) = max(2000, min(50000, bitrate))
|
||||
val bitrateKey get() = resources.getString(R.string.preferences_bitrate_key)
|
||||
var bitrate
|
||||
get() = sharedPreferences.getInt(bitrateKey, 0).let { if(it == 0) null else validateBitrate(it) }
|
||||
set(value) { sharedPreferences.edit().putInt(bitrateKey, if(value != null) validateBitrate(value) else 0).apply() }
|
||||
val bitrateAuto get() = videoProfileDefaultBitrate.bitrate
|
||||
private val bitrateAutoSubject by lazy { BehaviorSubject.createDefault(bitrateAuto) }
|
||||
val bitrateAutoObservable: Observable<Int> get() = bitrateAutoSubject
|
||||
|
||||
val codecKey get() = resources.getString(R.string.preferences_codec_key)
|
||||
var codec
|
||||
get() = sharedPreferences.getString(codecKey, codecDefault.value)?.let { value ->
|
||||
Codec.values().firstOrNull { it.value == value }
|
||||
} ?: codecDefault
|
||||
set(value) { sharedPreferences.edit().putString(codecKey, value.value).apply() }
|
||||
|
||||
private val videoProfileDefaultBitrate get() = ConnectVideoProfile.preset(resolution.preset, fps.preset, codec.codec)
|
||||
val videoProfile get() = videoProfileDefaultBitrate.let {
|
||||
val bitrate = bitrate
|
||||
if(bitrate == null)
|
||||
it
|
||||
else
|
||||
it.copy(bitrate = bitrate)
|
||||
}
|
||||
}
|
|
@ -1,101 +1,44 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.ColumnInfo.Companion.BLOB
|
||||
import com.metallic.chiaki.lib.RegistHost
|
||||
import com.metallic.chiaki.lib.Target
|
||||
import io.reactivex.Completable
|
||||
import androidx.room.ColumnInfo.BLOB
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Single
|
||||
|
||||
@Suppress("ArrayInDataClass")
|
||||
@Entity(tableName = "registered_host")
|
||||
data class RegisteredHost(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
@ColumnInfo(name = "target") val target: Target,
|
||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
||||
@ColumnInfo(name = "ap_ssid") val apSsid: String?,
|
||||
@ColumnInfo(name = "ap_bssid") val apBssid: String?,
|
||||
@ColumnInfo(name = "ap_key") val apKey: String?,
|
||||
@ColumnInfo(name = "ap_name") val apName: String?,
|
||||
@ColumnInfo(name = "server_mac") val serverMac: MacAddress,
|
||||
@ColumnInfo(name = "server_nickname") val serverNickname: String?,
|
||||
@ColumnInfo(name = "ps4_mac") val ps4Mac: MacAddress,
|
||||
@ColumnInfo(name = "ps4_nickname") val ps4Nickname: String?,
|
||||
@ColumnInfo(name = "rp_regist_key", typeAffinity = BLOB) val rpRegistKey: ByteArray, // CHIAKI_SESSION_AUTH_SIZE
|
||||
@ColumnInfo(name = "rp_key_type") val rpKeyType: Int,
|
||||
@ColumnInfo(name = "rp_key", typeAffinity = BLOB) val rpKey: ByteArray // 0x10
|
||||
)
|
||||
{
|
||||
constructor(registHost: RegistHost) : this(
|
||||
target = registHost.target,
|
||||
apSsid = registHost.apSsid,
|
||||
apBssid = registHost.apBssid,
|
||||
apKey = registHost.apKey,
|
||||
apName = registHost.apName,
|
||||
serverMac = MacAddress(registHost.serverMac),
|
||||
serverNickname = registHost.serverNickname,
|
||||
rpRegistKey = registHost.rpRegistKey,
|
||||
rpKeyType = registHost.rpKeyType.toInt(),
|
||||
rpKey = registHost.rpKey
|
||||
)
|
||||
|
||||
override fun equals(other: Any?): Boolean
|
||||
{
|
||||
if(this === other) return true
|
||||
if(javaClass != other?.javaClass) return false
|
||||
|
||||
other as RegisteredHost
|
||||
|
||||
if(id != other.id) return false
|
||||
if(target != other.target) return false
|
||||
if(apSsid != other.apSsid) return false
|
||||
if(apBssid != other.apBssid) return false
|
||||
if(apKey != other.apKey) return false
|
||||
if(apName != other.apName) return false
|
||||
if(serverMac != other.serverMac) return false
|
||||
if(serverNickname != other.serverNickname) return false
|
||||
if(!rpRegistKey.contentEquals(other.rpRegistKey)) return false
|
||||
if(rpKeyType != other.rpKeyType) return false
|
||||
if(!rpKey.contentEquals(other.rpKey)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int
|
||||
{
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + target.hashCode()
|
||||
result = 31 * result + (apSsid?.hashCode() ?: 0)
|
||||
result = 31 * result + (apBssid?.hashCode() ?: 0)
|
||||
result = 31 * result + (apKey?.hashCode() ?: 0)
|
||||
result = 31 * result + (apName?.hashCode() ?: 0)
|
||||
result = 31 * result + serverMac.hashCode()
|
||||
result = 31 * result + (serverNickname?.hashCode() ?: 0)
|
||||
result = 31 * result + rpRegistKey.contentHashCode()
|
||||
result = 31 * result + rpKeyType
|
||||
result = 31 * result + rpKey.contentHashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface RegisteredHostDao
|
||||
{
|
||||
@Query("SELECT * FROM registered_host")
|
||||
fun getAll(): Flowable<List<RegisteredHost>>
|
||||
|
||||
@Query("SELECT * FROM registered_host WHERE server_mac == :mac LIMIT 1")
|
||||
fun getByMac(mac: MacAddress): Maybe<RegisteredHost>
|
||||
|
||||
@Query("DELETE FROM registered_host WHERE server_mac == :mac")
|
||||
fun deleteByMac(mac: MacAddress): Completable
|
||||
|
||||
@Delete
|
||||
fun delete(host: RegisteredHost): Completable
|
||||
|
||||
@Query("SELECT COUNT(*) FROM registered_host")
|
||||
fun count(): Flowable<Int>
|
||||
|
||||
@Insert
|
||||
fun insert(host: RegisteredHost): Single<Long>
|
||||
}
|
|
@ -1,289 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.common
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.room.*
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.lib.Target
|
||||
import com.squareup.moshi.*
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.rxkotlin.Singles
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okio.Buffer
|
||||
import okio.Okio
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class SerializedRegisteredHost(
|
||||
@Json(name = "target") val target: Target,
|
||||
@Json(name = "ap_ssid") val apSsid: String?,
|
||||
@Json(name = "ap_bssid") val apBssid: String?,
|
||||
@Json(name = "ap_key") val apKey: String?,
|
||||
@Json(name = "ap_name") val apName: String?,
|
||||
@Json(name = "server_mac") val serverMac: MacAddress,
|
||||
@Json(name = "server_nickname") val serverNickname: String?,
|
||||
@Json(name = "rp_regist_key") val rpRegistKey: ByteArray,
|
||||
@Json(name = "rp_key_type") val rpKeyType: Int,
|
||||
@Json(name = "rp_key") val rpKey: ByteArray
|
||||
){
|
||||
constructor(registeredHost: RegisteredHost) : this(
|
||||
registeredHost.target,
|
||||
registeredHost.apSsid,
|
||||
registeredHost.apBssid,
|
||||
registeredHost.apKey,
|
||||
registeredHost.apName,
|
||||
registeredHost.serverMac,
|
||||
registeredHost.serverNickname,
|
||||
registeredHost.rpRegistKey,
|
||||
registeredHost.rpKeyType,
|
||||
registeredHost.rpKey
|
||||
)
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class SerializedManualHost(
|
||||
@Json(name = "host") val host: String,
|
||||
@Json(name = "server_mac") val serverMac: MacAddress?
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class SerializedSettings(
|
||||
@Json(name = "registered_hosts") val registeredHosts: List<SerializedRegisteredHost>,
|
||||
@Json(name = "manual_hosts") val manualHosts: List<SerializedManualHost>
|
||||
)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
fun fromDatabase(db: AppDatabase) = Singles.zip(
|
||||
db.registeredHostDao().getAll().firstOrError(),
|
||||
db.manualHostDao().getAll().firstOrError()
|
||||
) { registeredHosts, manualHosts ->
|
||||
SerializedSettings(
|
||||
registeredHosts.map { SerializedRegisteredHost(it) },
|
||||
manualHosts.map { manualHost ->
|
||||
SerializedManualHost(
|
||||
manualHost.host,
|
||||
manualHost.registeredHost?.let { registeredHostId ->
|
||||
registeredHosts.firstOrNull { it.id == registeredHostId }
|
||||
}?.serverMac
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ByteArrayJsonAdapter
|
||||
{
|
||||
@ToJson fun toJson(byteArray: ByteArray) = Base64.encodeToString(byteArray, Base64.NO_WRAP)
|
||||
@FromJson fun fromJson(string: String) = Base64.decode(string, Base64.DEFAULT)
|
||||
}
|
||||
|
||||
private fun moshi() =
|
||||
Moshi.Builder()
|
||||
.add(MacAddressJsonAdapter())
|
||||
.add(ByteArrayJsonAdapter())
|
||||
.build()
|
||||
|
||||
private fun Moshi.serializedSettingsAdapter() =
|
||||
adapter(SerializedSettings::class.java)
|
||||
.serializeNulls()
|
||||
|
||||
private const val KEY_FORMAT = "format"
|
||||
private const val FORMAT = "chiaki-settings"
|
||||
private const val KEY_VERSION = "version"
|
||||
private const val VERSION = 2
|
||||
private const val KEY_SETTINGS = "settings"
|
||||
|
||||
fun exportAllSettings(db: AppDatabase) = SerializedSettings.fromDatabase(db)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map {
|
||||
val buffer = Buffer()
|
||||
val writer = JsonWriter.of(buffer)
|
||||
val adapter = moshi().serializedSettingsAdapter()
|
||||
writer.indent = " "
|
||||
writer.
|
||||
beginObject()
|
||||
.name(KEY_FORMAT).value(FORMAT)
|
||||
.name(KEY_VERSION).value(VERSION)
|
||||
writer.name(KEY_SETTINGS)
|
||||
adapter.toJson(writer, it)
|
||||
writer.endObject()
|
||||
buffer.readUtf8()
|
||||
}
|
||||
|
||||
fun exportAndShareAllSettings(activity: Activity): Disposable
|
||||
{
|
||||
val db = getDatabase(activity)
|
||||
val dir = File(activity.cacheDir, "export_settings")
|
||||
dir.mkdirs()
|
||||
val file = File(dir, "chiaki-settings.json")
|
||||
return exportAllSettings(db)
|
||||
.map {
|
||||
file.writeText(it, Charsets.UTF_8)
|
||||
file
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { _ ->
|
||||
val uri = FileProvider.getUriForFile(activity, fileProviderAuthority, file)
|
||||
Intent(Intent.ACTION_SEND).also {
|
||||
it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
it.type = "application/json"
|
||||
it.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
it.clipData = ClipData.newRawUri("", uri)
|
||||
activity.startActivity(Intent.createChooser(it, activity.getString(R.string.action_share_log)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun importSettingsFromUri(activity: Activity, uri: Uri, disposable: CompositeDisposable)
|
||||
{
|
||||
fun loadFail(msg: String)
|
||||
{
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(activity.getString(R.string.alert_message_import_failed, msg))
|
||||
.setPositiveButton(R.string.action_import_failed_ack) { _, _ -> }
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
val inputStream = activity.contentResolver.openInputStream(uri) ?: throw IOException()
|
||||
val buffer = inputStream.source().buffer()
|
||||
val reader = JsonReader.of(buffer)
|
||||
val adapter = moshi().serializedSettingsAdapter()
|
||||
|
||||
var format: String? = null
|
||||
var version: Int? = null
|
||||
var settingsValue: Any? = null
|
||||
|
||||
reader.beginObject()
|
||||
while(reader.hasNext())
|
||||
{
|
||||
when(reader.nextName())
|
||||
{
|
||||
KEY_FORMAT -> format = reader.nextString()
|
||||
KEY_VERSION -> version = reader.nextInt()
|
||||
KEY_SETTINGS -> settingsValue = reader.readJsonValue()
|
||||
}
|
||||
}
|
||||
reader.endObject()
|
||||
|
||||
if(format == null || version == null || settingsValue == null)
|
||||
throw IOException("Missing format, version or settings from JSON")
|
||||
if(format != FORMAT)
|
||||
throw IOException("Value of format is invalid")
|
||||
if(version != VERSION) // Add migrations here when necessary
|
||||
throw IOException("Value of version is invalid")
|
||||
|
||||
val settings = adapter.fromJsonValue(settingsValue) ?: throw JsonDataException("Failed to parse Settings JSON")
|
||||
Log.i("SerializedSettings", "would import: $settings")
|
||||
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(activity.getString(R.string.alert_message_import,
|
||||
settings.registeredHosts.let {
|
||||
if(it.isEmpty())
|
||||
"-"
|
||||
else
|
||||
it.joinToString(separator = "") { host -> "\n - ${host.serverNickname ?: "?"} / ${host.serverMac}" }
|
||||
},
|
||||
settings.manualHosts.let {
|
||||
if(it.isEmpty())
|
||||
"-"
|
||||
else
|
||||
it.joinToString(separator = "") { host -> "\n - ${host.host} / ${host.serverMac ?: "unregistered"}" }
|
||||
}
|
||||
))
|
||||
.setTitle(R.string.alert_title_import)
|
||||
.setNegativeButton(R.string.action_import_cancel) { _, _ -> }
|
||||
.setPositiveButton(R.string.action_import_import) { _, _ ->
|
||||
getDatabase(activity).importDao()
|
||||
.importCompletable(settings)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe()
|
||||
.addTo(disposable)
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
catch(e: IOException)
|
||||
{
|
||||
e.printStackTrace()
|
||||
loadFail(e.message ?: "")
|
||||
}
|
||||
catch(e: JsonDataException)
|
||||
{
|
||||
e.printStackTrace()
|
||||
loadFail(e.message ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
@Dao
|
||||
abstract class ImportDao
|
||||
{
|
||||
@Insert
|
||||
abstract fun insertRegisteredHosts(hosts: List<RegisteredHost>)
|
||||
|
||||
@Insert
|
||||
abstract fun insertManualHosts(hosts: List<ManualHost>)
|
||||
|
||||
class IdWithMac(val id: Long, val mac: MacAddress)
|
||||
|
||||
@Query("SELECT id, server_mac AS mac FROM registered_host WHERE server_mac IN (:macs)")
|
||||
abstract fun registeredHostsByMac(macs: List<MacAddress>): List<IdWithMac>
|
||||
|
||||
@Transaction
|
||||
fun import(settings: SerializedSettings)
|
||||
{
|
||||
insertRegisteredHosts(
|
||||
settings.registeredHosts.map {
|
||||
RegisteredHost(
|
||||
target = it.target,
|
||||
apSsid = it.apSsid,
|
||||
apBssid = it.apBssid,
|
||||
apKey = it.apKey,
|
||||
apName = it.apName,
|
||||
serverMac = it.serverMac,
|
||||
serverNickname = it.serverNickname,
|
||||
rpRegistKey = it.rpRegistKey,
|
||||
rpKeyType = it.rpKeyType,
|
||||
rpKey = it.rpKey
|
||||
)
|
||||
})
|
||||
|
||||
val macs = settings.manualHosts.mapNotNull { it.serverMac }
|
||||
val idMacs =
|
||||
if(macs.isNotEmpty())
|
||||
registeredHostsByMac(macs)
|
||||
else
|
||||
listOf()
|
||||
|
||||
insertManualHosts(
|
||||
settings.manualHosts.map {
|
||||
ManualHost(
|
||||
host = it.host,
|
||||
registeredHost = idMacs.firstOrNull { regHost -> regHost.mac == it.serverMac }?.id
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun ImportDao.importCompletable(settings: SerializedSettings) = Completable.fromCallable { import(settings) }
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common.ext
|
||||
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common.ext
|
||||
|
||||
import androidx.lifecycle.LiveDataReactiveStreams
|
||||
import io.reactivex.BackpressureStrategy
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import org.reactivestreams.Publisher
|
||||
|
||||
fun <T> Publisher<T>.toLiveData() = LiveDataReactiveStreams.fromPublisher(this)
|
||||
fun <T> Observable<T>.toLiveData() = this.toFlowable(BackpressureStrategy.LATEST).toLiveData()
|
||||
fun <T> Single<T>.toLiveData() = this.toFlowable().toLiveData()
|
|
@ -1,7 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.common.ext
|
||||
|
||||
fun String.hexToByteArray(): ByteArray? = ByteArray(this.length / 2) {
|
||||
this.substring(it * 2, it * 2 + 2).toIntOrNull(16)?.toByte() ?: return null
|
||||
}
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.common.ext
|
||||
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.discovery
|
||||
|
||||
import android.util.Log
|
||||
import com.metallic.chiaki.common.MacAddress
|
||||
import com.metallic.chiaki.common.ext.hexToByteArray
|
||||
import com.metallic.chiaki.lib.CreateError
|
||||
import com.metallic.chiaki.lib.DiscoveryHost
|
||||
import com.metallic.chiaki.lib.DiscoveryService
|
||||
import com.metallic.chiaki.lib.DiscoveryServiceOptions
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import java.lang.NumberFormatException
|
||||
import java.net.InetSocketAddress
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
val DiscoveryHost.serverMac get() = this.hostId?.hexToByteArray()?.let {
|
||||
if(it.size == MacAddress.LENGTH)
|
||||
MacAddress(it)
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
class DiscoveryManager
|
||||
{
|
||||
|
@ -36,8 +35,6 @@ class DiscoveryManager
|
|||
const val DROP_PINGS: ULong = 3U
|
||||
const val PING_MS: ULong = 500U
|
||||
const val PORT = 987
|
||||
|
||||
const val DEBOUNCE_EMPTY_MS = 1000L
|
||||
}
|
||||
|
||||
private var discoveryService: DiscoveryService? = null
|
||||
|
@ -53,26 +50,10 @@ class DiscoveryManager
|
|||
}
|
||||
private var paused = false
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
private var discoveredHostsSubjectDebounced: Subject<List<DiscoveryHost>> = BehaviorSubject.create<List<DiscoveryHost>>().also {
|
||||
private var discoveredHostsSubject: Subject<List<DiscoveryHost>> = BehaviorSubject.create<List<DiscoveryHost>>().also {
|
||||
it.onNext(listOf())
|
||||
}.toSerialized()
|
||||
|
||||
private var discoveredHostsSubjectRaw: Subject<List<DiscoveryHost>> = BehaviorSubject.create<List<DiscoveryHost>>().also { subject ->
|
||||
subject.debounce { hosts ->
|
||||
if(hosts.isEmpty())
|
||||
Observable.timer(DEBOUNCE_EMPTY_MS, TimeUnit.MILLISECONDS)
|
||||
else
|
||||
Observable.empty()
|
||||
}
|
||||
.subscribe { hosts ->
|
||||
discoveredHostsSubjectDebounced.onNext(hosts)
|
||||
}
|
||||
.addTo(disposable)
|
||||
}
|
||||
|
||||
val discoveredHosts: Observable<List<DiscoveryHost>> get() = discoveredHostsSubjectDebounced
|
||||
val discoveredHosts: Observable<List<DiscoveryHost>> get() = discoveredHostsSubject
|
||||
|
||||
fun resume()
|
||||
{
|
||||
|
@ -89,29 +70,17 @@ class DiscoveryManager
|
|||
fun dispose()
|
||||
{
|
||||
active = false
|
||||
disposable.dispose()
|
||||
}
|
||||
|
||||
fun sendWakeup(host: String, registKey: ByteArray, ps5: Boolean)
|
||||
{
|
||||
val registKeyString = registKey.indexOfFirst { it == 0.toByte() }.let { end -> registKey.copyOfRange(0, if(end >= 0) end else registKey.size) }.toString(StandardCharsets.UTF_8)
|
||||
val credential = try { registKeyString.toULong(16) } catch(e: NumberFormatException) {
|
||||
Log.e("DiscoveryManager", "Failed to convert registKey to int", e)
|
||||
return
|
||||
}
|
||||
DiscoveryService.wakeup(discoveryService, host, credential, ps5)
|
||||
}
|
||||
|
||||
private fun updateService()
|
||||
{
|
||||
if(active && !paused && discoveryService == null)
|
||||
{
|
||||
discoveredHostsSubjectRaw.onNext(listOf())
|
||||
try
|
||||
{
|
||||
discoveryService = DiscoveryService(DiscoveryServiceOptions(
|
||||
HOSTS_MAX, DROP_PINGS, PING_MS, InetSocketAddress("255.255.255.255", PORT)
|
||||
), discoveredHostsSubjectRaw::onNext)
|
||||
), discoveredHostsSubject::onNext)
|
||||
}
|
||||
catch(e: CreateError)
|
||||
{
|
||||
|
@ -123,8 +92,7 @@ class DiscoveryManager
|
|||
val service = discoveryService ?: return
|
||||
service.dispose()
|
||||
discoveryService = null
|
||||
if(!active)
|
||||
discoveredHostsSubjectRaw.onNext(listOf())
|
||||
discoveredHostsSubject.onNext(listOf())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,69 +3,21 @@ package com.metallic.chiaki.lib
|
|||
import android.os.Parcelable
|
||||
import android.util.Log
|
||||
import android.view.Surface
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import java.lang.Exception
|
||||
import java.net.InetSocketAddress
|
||||
import kotlin.math.abs
|
||||
|
||||
enum class Target(val value: Int)
|
||||
{
|
||||
PS4_UNKNOWN(0),
|
||||
PS4_8(800),
|
||||
PS4_9(900),
|
||||
PS4_10(1000),
|
||||
PS5_UNKNOWN(1000000),
|
||||
PS5_1(1000100);
|
||||
|
||||
companion object
|
||||
{
|
||||
@JvmStatic
|
||||
fun fromValue(value: Int) = values().firstOrNull { it.value == value } ?: PS4_10
|
||||
}
|
||||
|
||||
val isPS5 get() = value >= PS5_UNKNOWN.value
|
||||
}
|
||||
|
||||
enum class VideoResolutionPreset(val value: Int)
|
||||
{
|
||||
RES_360P(1),
|
||||
RES_540P(2),
|
||||
RES_720P(3),
|
||||
RES_1080P(4)
|
||||
}
|
||||
|
||||
enum class VideoFPSPreset(val value: Int)
|
||||
{
|
||||
FPS_30(30),
|
||||
FPS_60(60)
|
||||
}
|
||||
|
||||
enum class Codec(val value: Int)
|
||||
{
|
||||
CODEC_H264(0),
|
||||
CODEC_H265(1),
|
||||
CODEC_H265_HDR(2)
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ConnectVideoProfile(
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val maxFPS: Int,
|
||||
val bitrate: Int,
|
||||
val codec: Codec
|
||||
val bitrate: Int
|
||||
): Parcelable
|
||||
{
|
||||
companion object
|
||||
{
|
||||
fun preset(resolutionPreset: VideoResolutionPreset, fpsPreset: VideoFPSPreset, codec: Codec)
|
||||
= ChiakiNative.videoProfilePreset(resolutionPreset.value, fpsPreset.value, codec)
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ConnectInfo(
|
||||
val ps5: Boolean,
|
||||
val host: String,
|
||||
val registKey: ByteArray,
|
||||
val morning: ByteArray,
|
||||
|
@ -83,19 +35,17 @@ private class ChiakiNative
|
|||
}
|
||||
@JvmStatic external fun errorCodeToString(value: Int): String
|
||||
@JvmStatic external fun quitReasonToString(value: Int): String
|
||||
@JvmStatic external fun quitReasonIsError(value: Int): Boolean
|
||||
@JvmStatic external fun videoProfilePreset(resolutionPreset: Int, fpsPreset: Int, codec: Codec): ConnectVideoProfile
|
||||
@JvmStatic external fun sessionCreate(result: CreateResult, connectInfo: ConnectInfo, logFile: String?, logVerbose: Boolean, javaSession: Session)
|
||||
@JvmStatic external fun quitReasonIsStopped(value: Int): Boolean
|
||||
@JvmStatic external fun sessionCreate(result: CreateResult, connectInfo: ConnectInfo, javaSession: Session)
|
||||
@JvmStatic external fun sessionFree(ptr: Long)
|
||||
@JvmStatic external fun sessionStart(ptr: Long): Int
|
||||
@JvmStatic external fun sessionStop(ptr: Long): Int
|
||||
@JvmStatic external fun sessionJoin(ptr: Long): Int
|
||||
@JvmStatic external fun sessionSetSurface(ptr: Long, surface: Surface?)
|
||||
@JvmStatic external fun sessionSetSurface(ptr: Long, surface: Surface)
|
||||
@JvmStatic external fun sessionSetControllerState(ptr: Long, controllerState: ControllerState)
|
||||
@JvmStatic external fun sessionSetLoginPin(ptr: Long, pin: String)
|
||||
@JvmStatic external fun discoveryServiceCreate(result: CreateResult, options: DiscoveryServiceOptions, javaService: DiscoveryService)
|
||||
@JvmStatic external fun discoveryServiceFree(ptr: Long)
|
||||
@JvmStatic external fun discoveryServiceWakeup(ptr: Long, host: String, userCredential: Long, ps5: Boolean)
|
||||
@JvmStatic external fun registStart(result: CreateResult, registInfo: RegistInfo, javaLog: ChiakiLog, javaRegist: Regist)
|
||||
@JvmStatic external fun registStop(ptr: Long)
|
||||
@JvmStatic external fun registFree(ptr: Long)
|
||||
|
@ -108,23 +58,8 @@ class ErrorCode(val value: Int)
|
|||
var isSuccess = value == 0
|
||||
}
|
||||
|
||||
class ChiakiLog(val levelMask: Int, val callback: (level: Int, text: String) -> Unit)
|
||||
class ChiakiLog(val levelMask: Int)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
fun formatLog(level: Int, text: String) =
|
||||
"[${when(level)
|
||||
{
|
||||
Level.DEBUG.value -> "D"
|
||||
Level.VERBOSE.value -> "V"
|
||||
Level.INFO.value -> "I"
|
||||
Level.WARNING.value -> "W"
|
||||
Level.ERROR.value -> "E"
|
||||
else -> "?"
|
||||
}
|
||||
}] $text"
|
||||
}
|
||||
|
||||
enum class Level(val value: Int)
|
||||
{
|
||||
DEBUG(1 shl 4),
|
||||
|
@ -137,26 +72,12 @@ class ChiakiLog(val levelMask: Int, val callback: (level: Int, text: String) ->
|
|||
|
||||
private fun log(level: Int, text: String)
|
||||
{
|
||||
callback(level, text)
|
||||
Log.i("ChiakiJavaLog", "level $level, text $text")
|
||||
}
|
||||
|
||||
fun d(text: String) = log(Level.DEBUG.value, text)
|
||||
fun v(text: String) = log(Level.VERBOSE.value, text)
|
||||
fun i(text: String) = log(Level.INFO.value, text)
|
||||
fun w(text: String) = log(Level.WARNING.value, text)
|
||||
fun e(text: String) = log(Level.ERROR.value, text)
|
||||
}
|
||||
|
||||
private fun maxAbs(a: Short, b: Short) = if(abs(a.toInt()) > abs(b.toInt())) a else b
|
||||
|
||||
private val CONTROLLER_TOUCHES_MAX = 2 // must be the same as CHIAKI_CONTROLLER_TOUCHES_MAX
|
||||
|
||||
data class ControllerTouch(
|
||||
var x: UShort = 0U,
|
||||
var y: UShort = 0U,
|
||||
var id: Byte = -1 // -1 = up
|
||||
)
|
||||
|
||||
data class ControllerState constructor(
|
||||
var buttons: UInt = 0U,
|
||||
var l2State: UByte = 0U,
|
||||
|
@ -164,40 +85,26 @@ data class ControllerState constructor(
|
|||
var leftX: Short = 0,
|
||||
var leftY: Short = 0,
|
||||
var rightX: Short = 0,
|
||||
var rightY: Short = 0,
|
||||
private var touchIdNext: UByte = 0U,
|
||||
var touches: Array<ControllerTouch> = arrayOf(ControllerTouch(), ControllerTouch()),
|
||||
var gyroX: Float = 0.0f,
|
||||
var gyroY: Float = 0.0f,
|
||||
var gyroZ: Float = 0.0f,
|
||||
var accelX: Float = 0.0f,
|
||||
var accelY: Float = 1.0f,
|
||||
var accelZ: Float = 0.0f,
|
||||
var orientX: Float = 0.0f,
|
||||
var orientY: Float = 0.0f,
|
||||
var orientZ: Float = 0.0f,
|
||||
var orientW: Float = 1.0f
|
||||
var rightY: Short = 0
|
||||
){
|
||||
companion object
|
||||
{
|
||||
val BUTTON_CROSS = (1 shl 0).toUInt()
|
||||
val BUTTON_MOON = (1 shl 1).toUInt()
|
||||
val BUTTON_BOX = (1 shl 2).toUInt()
|
||||
val BUTTON_PYRAMID = (1 shl 3).toUInt()
|
||||
val BUTTON_BOX = (1 shl 2).toUInt()
|
||||
val BUTTON_PYRAMID = (1 shl 3).toUInt()
|
||||
val BUTTON_DPAD_LEFT = (1 shl 4).toUInt()
|
||||
val BUTTON_DPAD_RIGHT = (1 shl 5).toUInt()
|
||||
val BUTTON_DPAD_UP = (1 shl 6).toUInt()
|
||||
val BUTTON_DPAD_UP = (1 shl 6).toUInt()
|
||||
val BUTTON_DPAD_DOWN = (1 shl 7).toUInt()
|
||||
val BUTTON_L1 = (1 shl 8).toUInt()
|
||||
val BUTTON_R1 = (1 shl 9).toUInt()
|
||||
val BUTTON_L1 = (1 shl 8).toUInt()
|
||||
val BUTTON_R1 = (1 shl 9).toUInt()
|
||||
val BUTTON_L3 = (1 shl 10).toUInt()
|
||||
val BUTTON_R3 = (1 shl 11).toUInt()
|
||||
val BUTTON_OPTIONS = (1 shl 12).toUInt()
|
||||
val BUTTON_OPTIONS = (1 shl 12).toUInt()
|
||||
val BUTTON_SHARE = (1 shl 13).toUInt()
|
||||
val BUTTON_TOUCHPAD = (1 shl 14).toUInt()
|
||||
val BUTTON_TOUCHPAD = (1 shl 14).toUInt()
|
||||
val BUTTON_PS = (1 shl 15).toUInt()
|
||||
val TOUCHPAD_WIDTH: UShort = 1920U
|
||||
val TOUCHPAD_HEIGHT: UShort = 942U
|
||||
}
|
||||
|
||||
infix fun or(o: ControllerState) = ControllerState(
|
||||
|
@ -207,120 +114,28 @@ data class ControllerState constructor(
|
|||
leftX = maxAbs(leftX, o.leftX),
|
||||
leftY = maxAbs(leftY, o.leftY),
|
||||
rightX = maxAbs(rightX, o.rightX),
|
||||
rightY = maxAbs(rightY, o.rightY),
|
||||
touches = touches.zip(o.touches) { a, b -> if(a.id >= 0) a else b }.toTypedArray(),
|
||||
gyroX = gyroX,
|
||||
gyroY = gyroY,
|
||||
gyroZ = gyroZ,
|
||||
accelX = accelX,
|
||||
accelY = accelY,
|
||||
accelZ = accelZ,
|
||||
orientX = orientX,
|
||||
orientY = orientY,
|
||||
orientZ = orientZ,
|
||||
orientW = orientW
|
||||
rightY = maxAbs(rightY, o.rightY)
|
||||
)
|
||||
|
||||
override fun equals(other: Any?): Boolean
|
||||
{
|
||||
if(this === other) return true
|
||||
if(javaClass != other?.javaClass) return false
|
||||
|
||||
other as ControllerState
|
||||
|
||||
if(buttons != other.buttons) return false
|
||||
if(l2State != other.l2State) return false
|
||||
if(r2State != other.r2State) return false
|
||||
if(leftX != other.leftX) return false
|
||||
if(leftY != other.leftY) return false
|
||||
if(rightX != other.rightX) return false
|
||||
if(rightY != other.rightY) return false
|
||||
if(touchIdNext != other.touchIdNext) return false
|
||||
if(!touches.contentEquals(other.touches)) return false
|
||||
if(gyroX != other.gyroX) return false
|
||||
if(gyroY != other.gyroY) return false
|
||||
if(gyroZ != other.gyroZ) return false
|
||||
if(accelX != other.accelX) return false
|
||||
if(accelY != other.accelY) return false
|
||||
if(accelZ != other.accelZ) return false
|
||||
if(orientX != other.orientX) return false
|
||||
if(orientY != other.orientY) return false
|
||||
if(orientZ != other.orientZ) return false
|
||||
if(orientW != other.orientW) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int
|
||||
{
|
||||
var result = buttons.hashCode()
|
||||
result = 31 * result + l2State.hashCode()
|
||||
result = 31 * result + r2State.hashCode()
|
||||
result = 31 * result + leftX
|
||||
result = 31 * result + leftY
|
||||
result = 31 * result + rightX
|
||||
result = 31 * result + rightY
|
||||
result = 31 * result + touchIdNext.hashCode()
|
||||
result = 31 * result + touches.contentHashCode()
|
||||
result = 31 * result + gyroX.hashCode()
|
||||
result = 31 * result + gyroY.hashCode()
|
||||
result = 31 * result + gyroZ.hashCode()
|
||||
result = 31 * result + accelX.hashCode()
|
||||
result = 31 * result + accelY.hashCode()
|
||||
result = 31 * result + accelZ.hashCode()
|
||||
result = 31 * result + orientX.hashCode()
|
||||
result = 31 * result + orientY.hashCode()
|
||||
result = 31 * result + orientZ.hashCode()
|
||||
result = 31 * result + orientW.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
fun startTouch(x: UShort, y: UShort): UByte? =
|
||||
touches
|
||||
.find { it.id < 0 }
|
||||
?.also {
|
||||
it.id = touchIdNext.toByte()
|
||||
it.x = x
|
||||
it.y = y
|
||||
touchIdNext = ((touchIdNext + 1U) and 0x7fU).toUByte()
|
||||
}?.id?.toUByte()
|
||||
|
||||
fun stopTouch(id: UByte)
|
||||
{
|
||||
touches.find {
|
||||
it.id >= 0 && it.id == id.toByte()
|
||||
}?.let {
|
||||
it.id = -1
|
||||
}
|
||||
}
|
||||
|
||||
fun setTouchPos(id: UByte, x: UShort, y: UShort): Boolean
|
||||
= touches.find {
|
||||
it.id >= 0 && it.id == id.toByte()
|
||||
}?.let {
|
||||
val r = it.x != x || it.y != y
|
||||
it.x = x
|
||||
it.y = y
|
||||
r
|
||||
} ?: false
|
||||
}
|
||||
|
||||
class QuitReason(val value: Int)
|
||||
{
|
||||
override fun toString() = ChiakiNative.quitReasonToString(value)
|
||||
|
||||
val isError = ChiakiNative.quitReasonIsError(value)
|
||||
/**
|
||||
* whether the reason is CHIAKI_QUIT_REASON_STOPPED
|
||||
*/
|
||||
val isStopped = ChiakiNative.quitReasonIsStopped(value)
|
||||
}
|
||||
|
||||
sealed class Event
|
||||
object ConnectedEvent: Event()
|
||||
data class LoginPinRequestEvent(val pinIncorrect: Boolean): Event()
|
||||
data class QuitEvent(val reason: QuitReason, val reasonString: String?): Event()
|
||||
data class RumbleEvent(val left: UByte, val right: UByte): Event()
|
||||
|
||||
class CreateError(val errorCode: ErrorCode): Exception("Failed to create a native object: $errorCode")
|
||||
|
||||
class Session(connectInfo: ConnectInfo, logFile: String?, logVerbose: Boolean)
|
||||
class Session(connectInfo: ConnectInfo)
|
||||
{
|
||||
interface EventCallback
|
||||
{
|
||||
|
@ -333,7 +148,7 @@ class Session(connectInfo: ConnectInfo, logFile: String?, logVerbose: Boolean)
|
|||
init
|
||||
{
|
||||
val result = ChiakiNative.CreateResult(0, 0)
|
||||
ChiakiNative.sessionCreate(result, connectInfo, logFile, logVerbose, this)
|
||||
ChiakiNative.sessionCreate(result, connectInfo, this)
|
||||
val errorCode = ErrorCode(result.errorCode)
|
||||
if(!errorCode.isSuccess)
|
||||
throw CreateError(errorCode)
|
||||
|
@ -372,12 +187,7 @@ class Session(connectInfo: ConnectInfo, logFile: String?, logVerbose: Boolean)
|
|||
event(QuitEvent(QuitReason(reasonValue), reasonString))
|
||||
}
|
||||
|
||||
private fun eventRumble(left: Int, right: Int)
|
||||
{
|
||||
event(RumbleEvent(left.toUByte(), right.toUByte()))
|
||||
}
|
||||
|
||||
fun setSurface(surface: Surface?)
|
||||
fun setSurface(surface: Surface)
|
||||
{
|
||||
ChiakiNative.sessionSetSurface(nativePtr, surface)
|
||||
}
|
||||
|
@ -411,8 +221,6 @@ data class DiscoveryHost(
|
|||
READY,
|
||||
STANDBY
|
||||
}
|
||||
|
||||
val isPS5 get() = deviceDiscoveryProtocolVersion == "00030010"
|
||||
}
|
||||
|
||||
|
||||
|
@ -427,12 +235,6 @@ class DiscoveryService(
|
|||
options: DiscoveryServiceOptions,
|
||||
val callback: ((hosts: List<DiscoveryHost>) -> Unit)?)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
fun wakeup(service: DiscoveryService?, host: String, userCredential: ULong, ps5: Boolean) =
|
||||
ChiakiNative.discoveryServiceWakeup(service?.nativePtr ?: 0, host, userCredential.toLong(), ps5)
|
||||
}
|
||||
|
||||
private var nativePtr: Long
|
||||
|
||||
init
|
||||
|
@ -462,30 +264,21 @@ class DiscoveryService(
|
|||
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
|
||||
data class RegistInfo(
|
||||
val target: Target,
|
||||
val host: String,
|
||||
val broadcast: Boolean,
|
||||
val psnOnlineId: String?,
|
||||
val psnAccountId: ByteArray?,
|
||||
val pin: Int
|
||||
): Parcelable
|
||||
{
|
||||
companion object
|
||||
{
|
||||
const val ACCOUNT_ID_SIZE = 8
|
||||
}
|
||||
}
|
||||
val psnId: String, // TODO: this is outdated now
|
||||
val pin: UInt
|
||||
)
|
||||
|
||||
data class RegistHost(
|
||||
val target: Target,
|
||||
val apSsid: String,
|
||||
val apBssid: String,
|
||||
val apKey: String,
|
||||
val apName: String,
|
||||
val serverMac: ByteArray,
|
||||
val serverNickname: String,
|
||||
val ps4Mac: ByteArray,
|
||||
val ps4Nickname: String,
|
||||
val rpRegistKey: ByteArray,
|
||||
val rpKeyType: UInt,
|
||||
val rpKey: ByteArray
|
||||
|
|
|
@ -1,52 +1,45 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.main
|
||||
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.PopupMenu
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.DiscoveredDisplayHost
|
||||
import com.metallic.chiaki.common.DisplayHost
|
||||
import com.metallic.chiaki.common.ManualDisplayHost
|
||||
import com.metallic.chiaki.common.ext.inflate
|
||||
import com.metallic.chiaki.databinding.ItemDisplayHostBinding
|
||||
import com.metallic.chiaki.lib.DiscoveryHost
|
||||
import kotlinx.android.synthetic.main.item_display_host.view.*
|
||||
|
||||
class DisplayHostDiffCallback(val old: List<DisplayHost>, val new: List<DisplayHost>): DiffUtil.Callback()
|
||||
{
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = (old[oldItemPosition] == new[newItemPosition])
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) = (old[oldItemPosition] == new[newItemPosition])
|
||||
override fun getOldListSize() = old.size
|
||||
override fun getNewListSize() = new.size
|
||||
}
|
||||
|
||||
class DisplayHostRecyclerViewAdapter(
|
||||
val clickCallback: (DisplayHost) -> Unit,
|
||||
val wakeupCallback: (DisplayHost) -> Unit,
|
||||
val editCallback: (DisplayHost) -> Unit,
|
||||
val deleteCallback: (DisplayHost) -> Unit
|
||||
): RecyclerView.Adapter<DisplayHostRecyclerViewAdapter.ViewHolder>()
|
||||
class DisplayHostRecyclerViewAdapter: RecyclerView.Adapter<DisplayHostRecyclerViewAdapter.ViewHolder>()
|
||||
{
|
||||
var hosts: List<DisplayHost> = listOf()
|
||||
set(value)
|
||||
{
|
||||
val diff = DiffUtil.calculateDiff(DisplayHostDiffCallback(field, value))
|
||||
field = value
|
||||
diff.dispatchUpdatesTo(this)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class ViewHolder(val binding: ItemDisplayHostBinding): RecyclerView.ViewHolder(binding.root)
|
||||
class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
|
||||
= ViewHolder(ItemDisplayHostBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
= ViewHolder(parent.inflate(R.layout.item_display_host))
|
||||
|
||||
override fun getItemCount() = hosts.count()
|
||||
|
||||
|
@ -54,71 +47,22 @@ class DisplayHostRecyclerViewAdapter(
|
|||
{
|
||||
val context = holder.itemView.context
|
||||
val host = hosts[position]
|
||||
holder.binding.also {
|
||||
holder.itemView.also {
|
||||
it.nameTextView.text = host.name
|
||||
it.hostTextView.text = context.getString(R.string.display_host_host, host.host)
|
||||
val id = host.id
|
||||
it.idTextView.text =
|
||||
if(id != null)
|
||||
context.getString(
|
||||
if(host.isRegistered)
|
||||
R.string.display_host_id_registered
|
||||
else
|
||||
R.string.display_host_id_unregistered,
|
||||
id)
|
||||
else
|
||||
""
|
||||
it.bottomInfoTextView.text = (host as? DiscoveredDisplayHost)?.discoveredHost?.let { discoveredHost ->
|
||||
if(discoveredHost.runningAppName != null || discoveredHost.runningAppTitleid != null)
|
||||
context.getString(R.string.display_host_app_title_id, discoveredHost.runningAppName ?: "", discoveredHost.runningAppTitleid ?: "")
|
||||
else
|
||||
""
|
||||
} ?: ""
|
||||
it.idTextView.text = if(id != null) context.getString(R.string.display_host_id, id) else ""
|
||||
it.discoveredIndicatorLayout.visibility = if(host is DiscoveredDisplayHost) View.VISIBLE else View.GONE
|
||||
it.stateIndicatorImageView.setImageResource(
|
||||
when
|
||||
{
|
||||
host is DiscoveredDisplayHost -> when(host.discoveredHost.state)
|
||||
if(host is DiscoveredDisplayHost)
|
||||
when(host.discoveredHost.state)
|
||||
{
|
||||
DiscoveryHost.State.STANDBY -> if(host.isPS5) R.drawable.ic_console_ps5_standby else R.drawable.ic_console_standby
|
||||
DiscoveryHost.State.READY -> if(host.isPS5) R.drawable.ic_console_ps5_ready else R.drawable.ic_console_ready
|
||||
else -> if(host.isPS5) R.drawable.ic_console_ps5 else R.drawable.ic_console
|
||||
DiscoveryHost.State.STANDBY -> R.drawable.ic_console_standby
|
||||
DiscoveryHost.State.READY -> R.drawable.ic_console_ready
|
||||
else -> R.drawable.ic_console
|
||||
}
|
||||
host.isPS5 -> R.drawable.ic_console_ps5
|
||||
else -> R.drawable.ic_console
|
||||
}
|
||||
)
|
||||
it.root.setOnClickListener { clickCallback(host) }
|
||||
|
||||
val canWakeup = host.registeredHost != null
|
||||
val canEditDelete = host is ManualDisplayHost
|
||||
if(canWakeup || canEditDelete)
|
||||
{
|
||||
it.menuButton.isVisible = true
|
||||
it.menuButton.setOnClickListener { _ ->
|
||||
val menu = PopupMenu(context, it.menuButton)
|
||||
menu.menuInflater.inflate(R.menu.display_host, menu.menu)
|
||||
menu.menu.findItem(R.id.action_wakeup).isVisible = canWakeup
|
||||
menu.menu.findItem(R.id.action_edit).isVisible = canEditDelete
|
||||
menu.menu.findItem(R.id.action_delete).isVisible = canEditDelete
|
||||
menu.setOnMenuItemClickListener { menuItem ->
|
||||
when(menuItem.itemId)
|
||||
{
|
||||
R.id.action_wakeup -> wakeupCallback(host)
|
||||
R.id.action_edit -> editCallback(host)
|
||||
R.id.action_delete -> deleteCallback(host)
|
||||
else -> return@setOnMenuItemClickListener false
|
||||
}
|
||||
true
|
||||
}
|
||||
menu.show()
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
it.menuButton.isGone = true
|
||||
it.menuButton.setOnClickListener(null)
|
||||
}
|
||||
else
|
||||
R.drawable.ic_console)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.main
|
||||
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.main
|
||||
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.main
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.*
|
||||
import com.metallic.chiaki.TestStartActivity
|
||||
import com.metallic.chiaki.common.ext.RevealActivity
|
||||
import com.metallic.chiaki.common.ext.putRevealExtra
|
||||
import com.metallic.chiaki.common.getDatabase
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.databinding.ActivityMainBinding
|
||||
import com.metallic.chiaki.lib.ConnectInfo
|
||||
import com.metallic.chiaki.lib.DiscoveryHost
|
||||
import com.metallic.chiaki.manualconsole.EditManualConsoleActivity
|
||||
import com.metallic.chiaki.regist.RegistActivity
|
||||
import com.metallic.chiaki.settings.SettingsActivity
|
||||
import com.metallic.chiaki.stream.StreamActivity
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
||||
class MainActivity : AppCompatActivity()
|
||||
{
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private var discoveryMenuItem: MenuItem? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
title = ""
|
||||
setSupportActionBar(binding.toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
binding.floatingActionButton.setOnClickListener {
|
||||
expandFloatingActionButton(!binding.floatingActionButton.isExpanded)
|
||||
floatingActionButton.setOnClickListener {
|
||||
expandFloatingActionButton(!floatingActionButton.isExpanded)
|
||||
}
|
||||
binding.floatingActionButtonDialBackground.setOnClickListener {
|
||||
floatingActionButtonDialBackground.setOnClickListener {
|
||||
expandFloatingActionButton(false)
|
||||
}
|
||||
|
||||
binding.addManualButton.setOnClickListener { addManualConsole() }
|
||||
binding.addManualLabelButton.setOnClickListener { addManualConsole() }
|
||||
addManualButton.setOnClickListener { addManualConsole() }
|
||||
addManualLabelButton.setOnClickListener { addManualConsole() }
|
||||
|
||||
binding.registerButton.setOnClickListener { showRegistration() }
|
||||
binding.registerLabelButton.setOnClickListener { showRegistration() }
|
||||
registerButton.setOnClickListener { showRegistration() }
|
||||
registerLabelButton.setOnClickListener { showRegistration() }
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory { MainViewModel(getDatabase(this), Preferences(this)) })
|
||||
viewModel = ViewModelProviders
|
||||
.of(this, viewModelFactory { MainViewModel(getDatabase(this)) })
|
||||
.get(MainViewModel::class.java)
|
||||
|
||||
val recyclerViewAdapter = DisplayHostRecyclerViewAdapter(this::hostTriggered, this::wakeupHost, this::editHost, this::deleteHost)
|
||||
binding.hostsRecyclerView.adapter = recyclerViewAdapter
|
||||
binding.hostsRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||
viewModel.displayHosts.observe(this, Observer {
|
||||
val top = binding.hostsRecyclerView.computeVerticalScrollOffset() == 0
|
||||
recyclerViewAdapter.hosts = it
|
||||
if(top)
|
||||
binding.hostsRecyclerView.scrollToPosition(0)
|
||||
updateEmptyInfo()
|
||||
})
|
||||
val recyclerViewAdapter = DisplayHostRecyclerViewAdapter()
|
||||
hostsRecyclerView.adapter = recyclerViewAdapter
|
||||
hostsRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||
viewModel.displayHosts.observe(this, Observer { recyclerViewAdapter.hosts = it })
|
||||
|
||||
viewModel.discoveryActive.observe(this, Observer { active ->
|
||||
discoveryMenuItem?.let { updateDiscoveryMenuItem(it, active) }
|
||||
updateEmptyInfo()
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateEmptyInfo()
|
||||
{
|
||||
if(viewModel.displayHosts.value?.isEmpty() ?: true)
|
||||
{
|
||||
binding.emptyInfoLayout.visibility = View.VISIBLE
|
||||
val discoveryActive = viewModel.discoveryActive.value ?: false
|
||||
binding.emptyInfoImageView.setImageResource(if(discoveryActive) R.drawable.ic_discover_on else R.drawable.ic_discover_off)
|
||||
binding.emptyInfoTextView.setText(if(discoveryActive) R.string.display_hosts_empty_discovery_on_info else R.string.display_hosts_empty_discovery_off_info)
|
||||
}
|
||||
else
|
||||
binding.emptyInfoLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun expandFloatingActionButton(expand: Boolean)
|
||||
{
|
||||
binding.floatingActionButton.isExpanded = expand
|
||||
binding.floatingActionButton.isActivated = binding.floatingActionButton.isExpanded
|
||||
floatingActionButton.isExpanded = expand
|
||||
floatingActionButton.isActivated = floatingActionButton.isExpanded
|
||||
}
|
||||
|
||||
override fun onDestroy()
|
||||
{
|
||||
super.onDestroy()
|
||||
disposable.dispose()
|
||||
}
|
||||
|
||||
override fun onStart()
|
||||
|
@ -107,7 +107,7 @@ class MainActivity : AppCompatActivity()
|
|||
|
||||
override fun onBackPressed()
|
||||
{
|
||||
if(binding.floatingActionButton.isExpanded)
|
||||
if(floatingActionButton.isExpanded)
|
||||
{
|
||||
expandFloatingActionButton(false)
|
||||
return
|
||||
|
@ -152,8 +152,8 @@ class MainActivity : AppCompatActivity()
|
|||
|
||||
private fun addManualConsole()
|
||||
{
|
||||
Intent(this, EditManualConsoleActivity::class.java).also {
|
||||
it.putRevealExtra(binding.addManualButton, binding.rootLayout)
|
||||
Intent(this, TestStartActivity::class.java).also {
|
||||
it.putRevealExtra(addManualButton, rootLayout)
|
||||
startActivity(it, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
|
||||
}
|
||||
}
|
||||
|
@ -161,80 +161,8 @@ class MainActivity : AppCompatActivity()
|
|||
private fun showRegistration()
|
||||
{
|
||||
Intent(this, RegistActivity::class.java).also {
|
||||
it.putRevealExtra(binding.registerButton, binding.rootLayout)
|
||||
it.putRevealExtra(registerButton, rootLayout)
|
||||
startActivity(it, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
|
||||
}
|
||||
}
|
||||
|
||||
private fun hostTriggered(host: DisplayHost)
|
||||
{
|
||||
val registeredHost = host.registeredHost
|
||||
if(registeredHost != null)
|
||||
{
|
||||
fun connect() {
|
||||
val connectInfo = ConnectInfo(host.isPS5, host.host, registeredHost.rpRegistKey, registeredHost.rpKey, Preferences(this).videoProfile)
|
||||
Intent(this, StreamActivity::class.java).let {
|
||||
it.putExtra(StreamActivity.EXTRA_CONNECT_INFO, connectInfo)
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
|
||||
if(host is DiscoveredDisplayHost && host.discoveredHost.state == DiscoveryHost.State.STANDBY)
|
||||
{
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.alert_message_standby_wakeup)
|
||||
.setPositiveButton(R.string.action_wakeup) { _, _ ->
|
||||
wakeupHost(host)
|
||||
}
|
||||
.setNeutralButton(R.string.action_connect_immediately) { _, _ ->
|
||||
connect()
|
||||
}
|
||||
.setNegativeButton(R.string.action_connect_cancel_connect) { _, _ -> }
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
else
|
||||
connect()
|
||||
}
|
||||
else
|
||||
{
|
||||
Intent(this, RegistActivity::class.java).let {
|
||||
it.putExtra(RegistActivity.EXTRA_HOST, host.host)
|
||||
it.putExtra(RegistActivity.EXTRA_BROADCAST, false)
|
||||
if(host is ManualDisplayHost)
|
||||
it.putExtra(RegistActivity.EXTRA_ASSIGN_MANUAL_HOST_ID, host.manualHost.id)
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun wakeupHost(host: DisplayHost)
|
||||
{
|
||||
val registeredHost = host.registeredHost ?: return
|
||||
viewModel.discoveryManager.sendWakeup(host.host, registeredHost.rpRegistKey, registeredHost.target.isPS5)
|
||||
}
|
||||
|
||||
private fun editHost(host: DisplayHost)
|
||||
{
|
||||
if(host !is ManualDisplayHost)
|
||||
return
|
||||
Intent(this, EditManualConsoleActivity::class.java).also {
|
||||
it.putExtra(EditManualConsoleActivity.EXTRA_MANUAL_HOST_ID, host.manualHost.id)
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteHost(host: DisplayHost)
|
||||
{
|
||||
if(host !is ManualDisplayHost)
|
||||
return
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(getString(R.string.alert_message_delete_manual_host, host.manualHost.host))
|
||||
.setPositiveButton(R.string.action_delete) { _, _ ->
|
||||
viewModel.deleteManualHost(host.manualHost)
|
||||
}
|
||||
.setNegativeButton(R.string.action_keep) { _, _ -> }
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +1,42 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.main
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.*
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.DiscoveredDisplayHost
|
||||
import com.metallic.chiaki.common.ManualDisplayHost
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
import com.metallic.chiaki.discovery.DiscoveryManager
|
||||
import com.metallic.chiaki.discovery.serverMac
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class MainViewModel(val database: AppDatabase, val preferences: Preferences): ViewModel()
|
||||
class MainViewModel(val database: AppDatabase): ViewModel()
|
||||
{
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
val discoveryManager = DiscoveryManager().also {
|
||||
it.active = preferences.discoveryEnabled
|
||||
it.discoveryActive
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { preferences.discoveryEnabled = it }
|
||||
.addTo(disposable)
|
||||
}
|
||||
val discoveryManager = DiscoveryManager().also { it.active = true /* TODO: from shared preferences */ }
|
||||
|
||||
val displayHosts by lazy {
|
||||
Observables.combineLatest(
|
||||
database.manualHostDao().getAll().toObservable(),
|
||||
database.registeredHostDao().getAll().toObservable(),
|
||||
discoveryManager.discoveredHosts)
|
||||
{ manualHosts, registeredHosts, discoveredHosts ->
|
||||
val macRegisteredHosts = registeredHosts.associateBy { it.serverMac }
|
||||
val idRegisteredHosts = registeredHosts.associateBy { it.id }
|
||||
Observables.combineLatest(database.manualHostDao().getAll().toObservable(), discoveryManager.discoveredHosts)
|
||||
{ manualHosts, discoveredHosts ->
|
||||
discoveredHosts.map {
|
||||
DiscoveredDisplayHost(it.serverMac?.let { mac -> macRegisteredHosts[mac] }, it)
|
||||
DiscoveredDisplayHost(null /* TODO */, it)
|
||||
} +
|
||||
manualHosts.map {
|
||||
ManualDisplayHost(it.registeredHost?.let { id -> idRegisteredHosts[id] }, it)
|
||||
ManualDisplayHost(null /* TODO */, it)
|
||||
}
|
||||
}
|
||||
.toLiveData()
|
||||
|
@ -47,20 +46,9 @@ class MainViewModel(val database: AppDatabase, val preferences: Preferences): Vi
|
|||
discoveryManager.discoveryActive.toLiveData()
|
||||
}
|
||||
|
||||
fun deleteManualHost(manualHost: ManualHost)
|
||||
{
|
||||
database.manualHostDao()
|
||||
.delete(manualHost)
|
||||
.onErrorComplete()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
.addTo(disposable)
|
||||
}
|
||||
|
||||
override fun onCleared()
|
||||
{
|
||||
super.onCleared()
|
||||
disposable.dispose()
|
||||
discoveryManager.dispose()
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.manualconsole
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.common.ext.RevealActivity
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.common.getDatabase
|
||||
import com.metallic.chiaki.databinding.ActivityEditManualBinding
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
|
||||
class EditManualConsoleActivity: AppCompatActivity(), RevealActivity
|
||||
{
|
||||
companion object
|
||||
{
|
||||
const val EXTRA_MANUAL_HOST_ID = "manual_host_id"
|
||||
}
|
||||
|
||||
private lateinit var viewModel: EditManualConsoleViewModel
|
||||
private lateinit var binding: ActivityEditManualBinding
|
||||
|
||||
override val revealIntent: Intent get() = intent
|
||||
override val revealRootLayout: View get() = binding.rootLayout
|
||||
override val revealWindow: Window get() = window
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityEditManualBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
handleReveal()
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory {
|
||||
EditManualConsoleViewModel(getDatabase(this),
|
||||
if(intent.hasExtra(EXTRA_MANUAL_HOST_ID))
|
||||
intent.getLongExtra(EXTRA_MANUAL_HOST_ID, 0)
|
||||
else
|
||||
null)
|
||||
})
|
||||
.get(EditManualConsoleViewModel::class.java)
|
||||
|
||||
viewModel.existingHost?.observe(this, Observer {
|
||||
binding.hostEditText.setText(it.host)
|
||||
})
|
||||
|
||||
viewModel.selectedRegisteredHost.observe(this, Observer {
|
||||
binding.registeredHostTextView.setText(titleForRegisteredHost(it))
|
||||
})
|
||||
|
||||
viewModel.registeredHosts.observe(this, Observer { hosts ->
|
||||
binding.registeredHostTextView.setAdapter(ArrayAdapter<String>(this, R.layout.dropdown_menu_popup_item,
|
||||
hosts.map { titleForRegisteredHost(it) }))
|
||||
binding.registeredHostTextView.onItemClickListener = object: AdapterView.OnItemClickListener {
|
||||
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long)
|
||||
{
|
||||
if(position >= hosts.size)
|
||||
return
|
||||
val host = hosts[position]
|
||||
viewModel.selectedRegisteredHost.value = host
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.saveButton.setOnClickListener { saveHost() }
|
||||
}
|
||||
|
||||
private fun titleForRegisteredHost(registeredHost: RegisteredHost?) =
|
||||
if(registeredHost == null)
|
||||
getString(R.string.add_manual_regist_on_connect)
|
||||
else
|
||||
"${registeredHost.serverNickname ?: ""} (${registeredHost.serverMac})"
|
||||
|
||||
private fun saveHost()
|
||||
{
|
||||
val host = binding.hostEditText.text.toString().trim()
|
||||
if(host.isEmpty())
|
||||
{
|
||||
binding.hostEditText.error = getString(R.string.entered_host_invalid)
|
||||
return
|
||||
}
|
||||
|
||||
binding.saveButton.isEnabled = false
|
||||
viewModel.saveHost(host)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
finish()
|
||||
}
|
||||
.addTo(disposable)
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.manualconsole
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.ManualHost
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class EditManualConsoleViewModel(val database: AppDatabase, manualHostId: Long?): ViewModel()
|
||||
{
|
||||
val registeredHosts by lazy {
|
||||
database.registeredHostDao().getAll().observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { hosts ->
|
||||
val selectedHost = selectedRegisteredHost.value
|
||||
if(selectedHost != null)
|
||||
selectedRegisteredHost.value = hosts.firstOrNull { it.id == selectedHost.id }
|
||||
}
|
||||
.map { listOf(null) + it }
|
||||
.toLiveData()
|
||||
}
|
||||
|
||||
val existingHost: LiveData<ManualHost>? =
|
||||
if(manualHostId != null)
|
||||
database.manualHostDao()
|
||||
.getByIdWithRegisteredHost(manualHostId)
|
||||
.toFlowable()
|
||||
.doOnError {
|
||||
Log.e("EditManualConsole", "Failed to fetch existing manual host", it)
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { hosts ->
|
||||
selectedRegisteredHost.value = hosts.registeredHost
|
||||
}
|
||||
.map { hosts -> hosts.manualHost }
|
||||
.toLiveData()
|
||||
else
|
||||
null
|
||||
|
||||
var selectedRegisteredHost = MutableLiveData<RegisteredHost?>(null)
|
||||
|
||||
fun saveHost(host: String) =
|
||||
database.manualHostDao()
|
||||
.let {
|
||||
val registeredHost = selectedRegisteredHost.value?.id
|
||||
val existingHost = existingHost?.value
|
||||
if(existingHost != null)
|
||||
it.update(ManualHost(id = existingHost.id, host = host, registeredHost = registeredHost))
|
||||
else
|
||||
it.insert(ManualHost(host = host, registeredHost = registeredHost))
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import com.metallic.chiaki.lib.ChiakiLog
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
class ChiakiRxLog(levelMask: Int)
|
||||
{
|
||||
private val accSubject: BehaviorSubject<String> = BehaviorSubject.create<String>().also {
|
||||
it.onNext("")
|
||||
}
|
||||
private val accMutex = ReentrantLock()
|
||||
val logText: Observable<String> get() = accSubject
|
||||
|
||||
val log = ChiakiLog(levelMask, callback = { level, text ->
|
||||
accMutex.withLock {
|
||||
val cur = accSubject.value ?: ""
|
||||
accSubject.onNext(cur + (if(cur.isEmpty()) "" else "\n") + ChiakiLog.formatLog(level, text))
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,21 +1,30 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.ext.RevealActivity
|
||||
import com.metallic.chiaki.databinding.ActivityRegistBinding
|
||||
import com.metallic.chiaki.lib.RegistInfo
|
||||
import com.metallic.chiaki.lib.Target
|
||||
import java.lang.IllegalArgumentException
|
||||
import kotlinx.android.synthetic.main.activity_regist.*
|
||||
|
||||
class RegistActivity: AppCompatActivity(), RevealActivity
|
||||
{
|
||||
|
@ -23,126 +32,49 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
|||
{
|
||||
const val EXTRA_HOST = "regist_host"
|
||||
const val EXTRA_BROADCAST = "regist_broadcast"
|
||||
const val EXTRA_ASSIGN_MANUAL_HOST_ID = "assign_manual_host_id"
|
||||
|
||||
private const val PIN_LENGTH = 8
|
||||
|
||||
private const val REQUEST_REGIST = 1
|
||||
}
|
||||
|
||||
private lateinit var viewModel: RegistViewModel
|
||||
private lateinit var binding: ActivityRegistBinding
|
||||
|
||||
override val revealWindow: Window get() = window
|
||||
override val revealIntent: Intent get() = intent
|
||||
override val revealRootLayout: View get() = binding.rootLayout
|
||||
override val revealRootLayout: View get() = rootLayout
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityRegistBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setContentView(R.layout.activity_regist)
|
||||
handleReveal()
|
||||
|
||||
viewModel = ViewModelProvider(this).get(RegistViewModel::class.java)
|
||||
hostEditText.setText(intent.getStringExtra(EXTRA_HOST) ?: "255.255.255.255")
|
||||
broadcastCheckBox.isChecked = intent.getBooleanExtra(EXTRA_BROADCAST, true)
|
||||
|
||||
binding.hostEditText.setText(intent.getStringExtra(EXTRA_HOST) ?: "255.255.255.255")
|
||||
binding.broadcastCheckBox.isChecked = intent.getBooleanExtra(EXTRA_BROADCAST, true)
|
||||
|
||||
binding.registButton.setOnClickListener { doRegist() }
|
||||
|
||||
binding.ps4VersionRadioGroup.check(when(viewModel.ps4Version.value ?: RegistViewModel.ConsoleVersion.PS5) {
|
||||
RegistViewModel.ConsoleVersion.PS5 -> R.id.ps5RadioButton
|
||||
RegistViewModel.ConsoleVersion.PS4_GE_8 -> R.id.ps4VersionGE8RadioButton
|
||||
RegistViewModel.ConsoleVersion.PS4_GE_7 -> R.id.ps4VersionGE7RadioButton
|
||||
RegistViewModel.ConsoleVersion.PS4_LT_7 -> R.id.ps4VersionLT7RadioButton
|
||||
})
|
||||
|
||||
binding.ps4VersionRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
viewModel.ps4Version.value = when(checkedId)
|
||||
{
|
||||
R.id.ps5RadioButton -> RegistViewModel.ConsoleVersion.PS5
|
||||
R.id.ps4VersionGE8RadioButton -> RegistViewModel.ConsoleVersion.PS4_GE_8
|
||||
R.id.ps4VersionGE7RadioButton -> RegistViewModel.ConsoleVersion.PS4_GE_7
|
||||
R.id.ps4VersionLT7RadioButton -> RegistViewModel.ConsoleVersion.PS4_LT_7
|
||||
else -> RegistViewModel.ConsoleVersion.PS5
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.ps4Version.observe(this, Observer {
|
||||
binding.psnAccountIdHelpGroup.visibility = if(it == RegistViewModel.ConsoleVersion.PS4_LT_7) View.GONE else View.VISIBLE
|
||||
binding.psnIdTextInputLayout.hint = getString(when(it!!)
|
||||
{
|
||||
RegistViewModel.ConsoleVersion.PS4_LT_7 -> R.string.hint_regist_psn_online_id
|
||||
else -> R.string.hint_regist_psn_account_id
|
||||
})
|
||||
binding.pinHelpBeforeTextView.setText(if(it.isPS5) R.string.regist_pin_instructions_ps5_before else R.string.regist_pin_instructions_ps4_before)
|
||||
binding.pinHelpNavigationTextView.setText(if(it.isPS5) R.string.regist_pin_instructions_ps5_navigation else R.string.regist_pin_instructions_ps4_navigation)
|
||||
})
|
||||
registButton.setOnClickListener { doRegist() }
|
||||
}
|
||||
|
||||
private fun doRegist()
|
||||
{
|
||||
val ps4Version = viewModel.ps4Version.value ?: RegistViewModel.ConsoleVersion.PS5
|
||||
|
||||
val host = binding.hostEditText.text.toString().trim()
|
||||
val host = hostEditText.text.toString().trim()
|
||||
val hostValid = host.isNotEmpty()
|
||||
val broadcast = binding.broadcastCheckBox.isChecked
|
||||
|
||||
val psnId = binding.psnIdEditText.text.toString().trim()
|
||||
val psnOnlineId: String? = if(ps4Version == RegistViewModel.ConsoleVersion.PS4_LT_7) psnId else null
|
||||
val psnAccountId: ByteArray? =
|
||||
if(ps4Version != RegistViewModel.ConsoleVersion.PS4_LT_7)
|
||||
try { Base64.decode(psnId, Base64.DEFAULT) } catch(e: IllegalArgumentException) { null }
|
||||
else
|
||||
null
|
||||
val psnIdValid = when(ps4Version)
|
||||
{
|
||||
RegistViewModel.ConsoleVersion.PS4_LT_7 -> psnOnlineId?.isNotEmpty() ?: false
|
||||
else -> psnAccountId != null && psnAccountId.size == RegistInfo.ACCOUNT_ID_SIZE
|
||||
}
|
||||
|
||||
|
||||
val pin = binding.pinEditText.text.toString()
|
||||
val broadcast = broadcastCheckBox.isChecked
|
||||
val psnId = psnIdEditText.text.toString().trim()
|
||||
val psnIdValid = psnId.isNotEmpty()
|
||||
val pin = pinEditText.text.toString()
|
||||
val pinValid = pin.length == PIN_LENGTH
|
||||
|
||||
binding.hostEditText.error = if(!hostValid) getString(R.string.entered_host_invalid) else null
|
||||
binding.psnIdEditText.error =
|
||||
if(!psnIdValid)
|
||||
getString(when(ps4Version)
|
||||
{
|
||||
RegistViewModel.ConsoleVersion.PS4_LT_7 -> R.string.regist_psn_online_id_invalid
|
||||
else -> R.string.regist_psn_account_id_invalid
|
||||
})
|
||||
else
|
||||
null
|
||||
binding.pinEditText.error = if(!pinValid) getString(R.string.regist_pin_invalid, PIN_LENGTH) else null
|
||||
hostEditText.error = if(!hostValid) getString(R.string.regist_host_invalid) else null
|
||||
psnIdEditText.error = if(!psnIdValid) getString(R.string.regist_psn_id_invalid) else null
|
||||
pinEditText.error = if(!pinValid) getString(R.string.regist_pin_invalid, PIN_LENGTH) else null
|
||||
|
||||
if(!hostValid || !psnIdValid || !pinValid)
|
||||
return
|
||||
|
||||
val target = when(ps4Version)
|
||||
{
|
||||
RegistViewModel.ConsoleVersion.PS5 -> Target.PS5_1
|
||||
RegistViewModel.ConsoleVersion.PS4_GE_8 -> Target.PS4_10
|
||||
RegistViewModel.ConsoleVersion.PS4_GE_7 -> Target.PS4_9
|
||||
RegistViewModel.ConsoleVersion.PS4_LT_7 -> Target.PS4_8
|
||||
}
|
||||
|
||||
val registInfo = RegistInfo(target, host, broadcast, psnOnlineId, psnAccountId, pin.toInt())
|
||||
|
||||
Intent(this, RegistExecuteActivity::class.java).also {
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_REGIST_INFO, registInfo)
|
||||
if(intent.hasExtra(EXTRA_ASSIGN_MANUAL_HOST_ID))
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_ASSIGN_MANUAL_HOST_ID, intent.getLongExtra(EXTRA_ASSIGN_MANUAL_HOST_ID, 0L))
|
||||
startActivityForResult(it, REQUEST_REGIST)
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_HOST, host)
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_BROADCAST, broadcast)
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_PSN_ID, psnId)
|
||||
it.putExtra(RegistExecuteActivity.EXTRA_PIN, pin.toUInt().toInt())
|
||||
startActivity(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if(requestCode == REQUEST_REGIST && resultCode == RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
}
|
|
@ -1,106 +1,55 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.MacAddress
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.common.getDatabase
|
||||
import com.metallic.chiaki.databinding.ActivityRegistExecuteBinding
|
||||
import com.metallic.chiaki.lib.RegistInfo
|
||||
import kotlin.math.max
|
||||
|
||||
class RegistExecuteActivity: AppCompatActivity()
|
||||
{
|
||||
companion object
|
||||
{
|
||||
const val EXTRA_REGIST_INFO = "regist_info"
|
||||
const val EXTRA_ASSIGN_MANUAL_HOST_ID = "assign_manual_host_id"
|
||||
|
||||
const val RESULT_FAILED = Activity.RESULT_FIRST_USER
|
||||
const val EXTRA_HOST = "regist_host"
|
||||
const val EXTRA_BROADCAST = "regist_broadcast"
|
||||
const val EXTRA_PSN_ID = "regist_psn_id"
|
||||
const val EXTRA_PIN = "regist_pin"
|
||||
}
|
||||
|
||||
private lateinit var viewModel: RegistExecuteViewModel
|
||||
private lateinit var binding: ActivityRegistExecuteBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityRegistExecuteBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setContentView(R.layout.activity_regist_execute)
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory { RegistExecuteViewModel(getDatabase(this)) })
|
||||
.get(RegistExecuteViewModel::class.java)
|
||||
viewModel = ViewModelProviders.of(this).get(RegistExecuteViewModel::class.java)
|
||||
|
||||
binding.logTextView.setHorizontallyScrolling(true)
|
||||
binding.logTextView.movementMethod = ScrollingMovementMethod()
|
||||
viewModel.logText.observe(this, Observer {
|
||||
val textLayout = binding.logTextView.layout ?: return@Observer
|
||||
val lineCount = textLayout.lineCount
|
||||
if(lineCount < 1)
|
||||
return@Observer
|
||||
binding.logTextView.text = it
|
||||
val scrollY = textLayout.getLineBottom(lineCount - 1) - binding.logTextView.height + binding.logTextView.paddingTop + binding.logTextView.paddingBottom
|
||||
binding.logTextView.scrollTo(0, max(scrollY, 0))
|
||||
})
|
||||
val registInfo = RegistInfo(
|
||||
intent.getStringExtra(EXTRA_HOST) ?: return,
|
||||
intent.getBooleanExtra(EXTRA_BROADCAST, false) ?: return,
|
||||
intent.getStringExtra(EXTRA_PSN_ID) ?: return,
|
||||
intent.getIntExtra(EXTRA_PIN, 0).toUInt()
|
||||
)
|
||||
|
||||
viewModel.state.observe(this, Observer {
|
||||
binding.progressBar.visibility = if(it == RegistExecuteViewModel.State.RUNNING) View.VISIBLE else View.GONE
|
||||
when(it)
|
||||
{
|
||||
RegistExecuteViewModel.State.FAILED ->
|
||||
{
|
||||
binding.infoTextView.visibility = View.VISIBLE
|
||||
binding.infoTextView.setText(R.string.regist_info_failed)
|
||||
setResult(RESULT_FAILED)
|
||||
}
|
||||
RegistExecuteViewModel.State.SUCCESSFUL, RegistExecuteViewModel.State.SUCCESSFUL_DUPLICATE ->
|
||||
{
|
||||
binding.infoTextView.visibility = View.VISIBLE
|
||||
binding.infoTextView.setText(R.string.regist_info_success)
|
||||
setResult(RESULT_OK)
|
||||
if(it == RegistExecuteViewModel.State.SUCCESSFUL_DUPLICATE)
|
||||
showDuplicateDialog()
|
||||
}
|
||||
RegistExecuteViewModel.State.STOPPED ->
|
||||
{
|
||||
binding.infoTextView.visibility = View.GONE
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
}
|
||||
else -> binding.infoTextView.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
|
||||
binding.shareLogButton.setOnClickListener {
|
||||
val log = viewModel.logText.value ?: ""
|
||||
Intent(Intent.ACTION_SEND).also {
|
||||
it.type = "text/plain"
|
||||
it.putExtra(Intent.EXTRA_TEXT, log)
|
||||
startActivity(Intent.createChooser(it, resources.getString(R.string.action_share_log)))
|
||||
}
|
||||
}
|
||||
|
||||
val registInfo = intent.getParcelableExtra<RegistInfo>(EXTRA_REGIST_INFO)
|
||||
if(registInfo == null)
|
||||
{
|
||||
finish()
|
||||
return
|
||||
}
|
||||
viewModel.start(registInfo,
|
||||
if(intent.hasExtra(EXTRA_ASSIGN_MANUAL_HOST_ID))
|
||||
intent.getLongExtra(EXTRA_ASSIGN_MANUAL_HOST_ID, 0)
|
||||
else
|
||||
null)
|
||||
viewModel.start(registInfo)
|
||||
}
|
||||
|
||||
override fun onStop()
|
||||
|
@ -108,24 +57,4 @@ class RegistExecuteActivity: AppCompatActivity()
|
|||
super.onStop()
|
||||
viewModel.stop()
|
||||
}
|
||||
|
||||
private var dialog: AlertDialog? = null
|
||||
|
||||
private fun showDuplicateDialog()
|
||||
{
|
||||
if(dialog != null)
|
||||
return
|
||||
|
||||
val macStr = viewModel.host?.serverMac?.let { MacAddress(it).toString() } ?: ""
|
||||
|
||||
dialog = MaterialAlertDialogBuilder(this)
|
||||
.setMessage(getString(R.string.alert_regist_duplicate, macStr))
|
||||
.setNegativeButton(R.string.action_regist_discard) { _, _ -> }
|
||||
.setPositiveButton(R.string.action_regist_overwrite) { _, _ ->
|
||||
viewModel.saveHost()
|
||||
}
|
||||
.create()
|
||||
.also { it.show() }
|
||||
|
||||
}
|
||||
}
|
|
@ -1,22 +1,28 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.MacAddress
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
import com.metallic.chiaki.lib.*
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class RegistExecuteViewModel(val database: AppDatabase): ViewModel()
|
||||
class RegistExecuteViewModel: ViewModel()
|
||||
{
|
||||
enum class State
|
||||
{
|
||||
|
@ -24,38 +30,27 @@ class RegistExecuteViewModel(val database: AppDatabase): ViewModel()
|
|||
RUNNING,
|
||||
STOPPED,
|
||||
FAILED,
|
||||
SUCCESSFUL,
|
||||
SUCCESSFUL_DUPLICATE,
|
||||
SUCCESSFUL
|
||||
}
|
||||
|
||||
private val _state = MutableLiveData<State>(State.IDLE)
|
||||
val state: LiveData<State> get() = _state
|
||||
|
||||
private val log = ChiakiRxLog(ChiakiLog.Level.ALL.value/* and ChiakiLog.Level.VERBOSE.value.inv()*/)
|
||||
private val log = ChiakiLog(ChiakiLog.Level.ALL.value/* and ChiakiLog.Level.VERBOSE.value.inv()*/)
|
||||
private var regist: Regist? = null
|
||||
|
||||
val logText: LiveData<String> = log.logText.toLiveData()
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
var host: RegistHost? = null
|
||||
private set
|
||||
|
||||
private var assignManualHostId: Long? = null
|
||||
|
||||
fun start(info: RegistInfo, assignManualHostId: Long?)
|
||||
fun start(info: RegistInfo)
|
||||
{
|
||||
if(regist != null)
|
||||
return
|
||||
try
|
||||
{
|
||||
regist = Regist(info, log.log, this::registEvent)
|
||||
this.assignManualHostId = assignManualHostId
|
||||
regist = Regist(info, log, this::registEvent)
|
||||
_state.value = State.RUNNING
|
||||
}
|
||||
catch(error: CreateError)
|
||||
{
|
||||
log.log.e("Failed to create Regist: ${error.errorCode}")
|
||||
// TODO: log about error
|
||||
_state.value = State.FAILED
|
||||
}
|
||||
}
|
||||
|
@ -69,58 +64,22 @@ class RegistExecuteViewModel(val database: AppDatabase): ViewModel()
|
|||
{
|
||||
when(event)
|
||||
{
|
||||
is RegistEventCanceled -> _state.postValue(State.STOPPED)
|
||||
is RegistEventFailed -> _state.postValue(State.FAILED)
|
||||
is RegistEventSuccess -> registSuccess(event.host)
|
||||
is RegistEventCanceled -> {
|
||||
_state.postValue(State.STOPPED)
|
||||
}
|
||||
is RegistEventFailed -> {
|
||||
_state.postValue(State.FAILED)
|
||||
}
|
||||
is RegistEventSuccess -> {
|
||||
// TODO: save event.host into db
|
||||
_state.postValue(State.SUCCESSFUL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registSuccess(host: RegistHost)
|
||||
{
|
||||
this.host = host
|
||||
database.registeredHostDao().getByMac(MacAddress(host.serverMac))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnSuccess {
|
||||
_state.value = State.SUCCESSFUL_DUPLICATE
|
||||
}
|
||||
.doOnComplete {
|
||||
saveHost()
|
||||
}
|
||||
.subscribe()
|
||||
.addTo(disposable)
|
||||
}
|
||||
|
||||
fun saveHost()
|
||||
{
|
||||
val host = host ?: return
|
||||
val assignManualHostId = assignManualHostId
|
||||
val dao = database.registeredHostDao()
|
||||
val manualHostDao = database.manualHostDao()
|
||||
val registeredHost = RegisteredHost(host)
|
||||
dao.deleteByMac(registeredHost.serverMac)
|
||||
.andThen(dao.insert(registeredHost))
|
||||
.let {
|
||||
if(assignManualHostId != null)
|
||||
it.flatMapCompletable { registeredHostId ->
|
||||
manualHostDao.assignRegisteredHost(assignManualHostId, registeredHostId)
|
||||
}
|
||||
else
|
||||
it.ignoreElement()
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe {
|
||||
Log.i("RegistExecute", "Registered Host saved in db")
|
||||
_state.value = State.SUCCESSFUL
|
||||
}
|
||||
.addTo(disposable)
|
||||
}
|
||||
|
||||
override fun onCleared()
|
||||
{
|
||||
super.onCleared()
|
||||
regist?.dispose()
|
||||
disposable.dispose()
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.regist
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class RegistViewModel: ViewModel()
|
||||
{
|
||||
enum class ConsoleVersion {
|
||||
PS5,
|
||||
PS4_GE_8,
|
||||
PS4_GE_7,
|
||||
PS4_LT_7;
|
||||
|
||||
val isPS5 get() = this == PS5
|
||||
}
|
||||
|
||||
val ps4Version = MutableLiveData<ConsoleVersion>(ConsoleVersion.PS5)
|
||||
}
|
|
@ -1,206 +0,0 @@
|
|||
package com.metallic.chiaki.session
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.*
|
||||
import android.view.*
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
import com.metallic.chiaki.lib.ControllerState
|
||||
|
||||
class StreamInput(val context: Context, val preferences: Preferences)
|
||||
{
|
||||
var controllerStateChangedCallback: ((ControllerState) -> Unit)? = null
|
||||
|
||||
val controllerState: ControllerState get()
|
||||
{
|
||||
val controllerState = sensorControllerState or keyControllerState or motionControllerState
|
||||
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
@Suppress("DEPRECATION")
|
||||
when(windowManager.defaultDisplay.rotation)
|
||||
{
|
||||
Surface.ROTATION_90 -> {
|
||||
controllerState.accelX *= -1.0f
|
||||
controllerState.accelZ *= -1.0f
|
||||
controllerState.gyroX *= -1.0f
|
||||
controllerState.gyroZ *= -1.0f
|
||||
controllerState.orientX *= -1.0f
|
||||
controllerState.orientZ *= -1.0f
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
// prioritize motion controller's l2 and r2 over key
|
||||
// (some controllers send only key, others both but key earlier than full press)
|
||||
if(motionControllerState.l2State > 0U)
|
||||
controllerState.l2State = motionControllerState.l2State
|
||||
if(motionControllerState.r2State > 0U)
|
||||
controllerState.r2State = motionControllerState.r2State
|
||||
|
||||
return controllerState or touchControllerState
|
||||
}
|
||||
|
||||
private val sensorControllerState = ControllerState() // from Motion Sensors
|
||||
private val keyControllerState = ControllerState() // from KeyEvents
|
||||
private val motionControllerState = ControllerState() // from MotionEvents
|
||||
var touchControllerState = ControllerState()
|
||||
set(value)
|
||||
{
|
||||
field = value
|
||||
controllerStateUpdated()
|
||||
}
|
||||
|
||||
private val swapCrossMoon = preferences.swapCrossMoon
|
||||
|
||||
private val sensorEventListener = object: SensorEventListener {
|
||||
override fun onSensorChanged(event: SensorEvent)
|
||||
{
|
||||
when(event.sensor.type)
|
||||
{
|
||||
Sensor.TYPE_ACCELEROMETER -> {
|
||||
sensorControllerState.accelX = event.values[1] / SensorManager.GRAVITY_EARTH
|
||||
sensorControllerState.accelY = event.values[2] / SensorManager.GRAVITY_EARTH
|
||||
sensorControllerState.accelZ = event.values[0] / SensorManager.GRAVITY_EARTH
|
||||
}
|
||||
Sensor.TYPE_GYROSCOPE -> {
|
||||
sensorControllerState.gyroX = event.values[1]
|
||||
sensorControllerState.gyroY = event.values[2]
|
||||
sensorControllerState.gyroZ = event.values[0]
|
||||
}
|
||||
Sensor.TYPE_ROTATION_VECTOR -> {
|
||||
val q = floatArrayOf(0f, 0f, 0f, 0f)
|
||||
SensorManager.getQuaternionFromVector(q, event.values)
|
||||
sensorControllerState.orientX = q[2]
|
||||
sensorControllerState.orientY = q[3]
|
||||
sensorControllerState.orientZ = q[1]
|
||||
sensorControllerState.orientW = q[0]
|
||||
}
|
||||
else -> return
|
||||
}
|
||||
controllerStateUpdated()
|
||||
}
|
||||
|
||||
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {}
|
||||
}
|
||||
|
||||
private val motionLifecycleObserver = object: LifecycleObserver {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun onResume()
|
||||
{
|
||||
val samplingPeriodUs = 4000
|
||||
val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
listOfNotNull(
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)
|
||||
).forEach {
|
||||
sensorManager.registerListener(sensorEventListener, it, samplingPeriodUs)
|
||||
}
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
fun onPause()
|
||||
{
|
||||
val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
sensorManager.unregisterListener(sensorEventListener)
|
||||
}
|
||||
}
|
||||
|
||||
fun observe(lifecycleOwner: LifecycleOwner)
|
||||
{
|
||||
if(preferences.motionEnabled)
|
||||
lifecycleOwner.lifecycle.addObserver(motionLifecycleObserver)
|
||||
}
|
||||
|
||||
private fun controllerStateUpdated()
|
||||
{
|
||||
controllerStateChangedCallback?.let { it(controllerState) }
|
||||
}
|
||||
|
||||
fun dispatchKeyEvent(event: KeyEvent): Boolean
|
||||
{
|
||||
//Log.i("StreamSession", "key event $event")
|
||||
if(event.action != KeyEvent.ACTION_DOWN && event.action != KeyEvent.ACTION_UP)
|
||||
return false
|
||||
|
||||
when(event.keyCode)
|
||||
{
|
||||
KeyEvent.KEYCODE_BUTTON_L2 -> {
|
||||
keyControllerState.l2State = if(event.action == KeyEvent.ACTION_DOWN) UByte.MAX_VALUE else 0U
|
||||
return true
|
||||
}
|
||||
KeyEvent.KEYCODE_BUTTON_R2 -> {
|
||||
keyControllerState.r2State = if(event.action == KeyEvent.ACTION_DOWN) UByte.MAX_VALUE else 0U
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
val buttonMask: UInt = when(event.keyCode)
|
||||
{
|
||||
// dpad handled by MotionEvents
|
||||
//KeyEvent.KEYCODE_DPAD_LEFT -> ControllerState.BUTTON_DPAD_LEFT
|
||||
//KeyEvent.KEYCODE_DPAD_RIGHT -> ControllerState.BUTTON_DPAD_RIGHT
|
||||
//KeyEvent.KEYCODE_DPAD_UP -> ControllerState.BUTTON_DPAD_UP
|
||||
//KeyEvent.KEYCODE_DPAD_DOWN -> ControllerState.BUTTON_DPAD_DOWN
|
||||
KeyEvent.KEYCODE_BUTTON_A -> if(swapCrossMoon) ControllerState.BUTTON_MOON else ControllerState.BUTTON_CROSS
|
||||
KeyEvent.KEYCODE_BUTTON_B -> if(swapCrossMoon) ControllerState.BUTTON_CROSS else ControllerState.BUTTON_MOON
|
||||
KeyEvent.KEYCODE_BUTTON_X -> if(swapCrossMoon) ControllerState.BUTTON_PYRAMID else ControllerState.BUTTON_BOX
|
||||
KeyEvent.KEYCODE_BUTTON_Y -> if(swapCrossMoon) ControllerState.BUTTON_BOX else ControllerState.BUTTON_PYRAMID
|
||||
KeyEvent.KEYCODE_BUTTON_L1 -> ControllerState.BUTTON_L1
|
||||
KeyEvent.KEYCODE_BUTTON_R1 -> ControllerState.BUTTON_R1
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBL -> ControllerState.BUTTON_L3
|
||||
KeyEvent.KEYCODE_BUTTON_THUMBR -> ControllerState.BUTTON_R3
|
||||
KeyEvent.KEYCODE_BUTTON_SELECT -> ControllerState.BUTTON_SHARE
|
||||
KeyEvent.KEYCODE_BUTTON_START -> ControllerState.BUTTON_OPTIONS
|
||||
KeyEvent.KEYCODE_BUTTON_C -> ControllerState.BUTTON_PS
|
||||
KeyEvent.KEYCODE_BUTTON_MODE -> ControllerState.BUTTON_PS
|
||||
else -> return false
|
||||
}
|
||||
|
||||
keyControllerState.buttons = keyControllerState.buttons.run {
|
||||
when(event.action)
|
||||
{
|
||||
KeyEvent.ACTION_DOWN -> this or buttonMask
|
||||
KeyEvent.ACTION_UP -> this and buttonMask.inv()
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
|
||||
controllerStateUpdated()
|
||||
return true
|
||||
}
|
||||
|
||||
fun onGenericMotionEvent(event: MotionEvent): Boolean
|
||||
{
|
||||
if(event.source and InputDevice.SOURCE_CLASS_JOYSTICK != InputDevice.SOURCE_CLASS_JOYSTICK)
|
||||
return false
|
||||
fun Float.signedAxis() = (this * Short.MAX_VALUE).toInt().toShort()
|
||||
fun Float.unsignedAxis() = (this * UByte.MAX_VALUE.toFloat()).toUInt().toUByte()
|
||||
motionControllerState.leftX = event.getAxisValue(MotionEvent.AXIS_X).signedAxis()
|
||||
motionControllerState.leftY = event.getAxisValue(MotionEvent.AXIS_Y).signedAxis()
|
||||
motionControllerState.rightX = event.getAxisValue(MotionEvent.AXIS_Z).signedAxis()
|
||||
motionControllerState.rightY = event.getAxisValue(MotionEvent.AXIS_RZ).signedAxis()
|
||||
motionControllerState.l2State = event.getAxisValue(MotionEvent.AXIS_LTRIGGER).unsignedAxis()
|
||||
motionControllerState.r2State = event.getAxisValue(MotionEvent.AXIS_RTRIGGER).unsignedAxis()
|
||||
motionControllerState.buttons = motionControllerState.buttons.let {
|
||||
val dpadX = event.getAxisValue(MotionEvent.AXIS_HAT_X)
|
||||
val dpadY = event.getAxisValue(MotionEvent.AXIS_HAT_Y)
|
||||
val dpadButtons =
|
||||
(if(dpadX > 0.5f) ControllerState.BUTTON_DPAD_RIGHT else 0U) or
|
||||
(if(dpadX < -0.5f) ControllerState.BUTTON_DPAD_LEFT else 0U) or
|
||||
(if(dpadY > 0.5f) ControllerState.BUTTON_DPAD_DOWN else 0U) or
|
||||
(if(dpadY < -0.5f) ControllerState.BUTTON_DPAD_UP else 0U)
|
||||
it and (ControllerState.BUTTON_DPAD_RIGHT or
|
||||
ControllerState.BUTTON_DPAD_LEFT or
|
||||
ControllerState.BUTTON_DPAD_DOWN or
|
||||
ControllerState.BUTTON_DPAD_UP).inv() or
|
||||
dpadButtons
|
||||
}
|
||||
//Log.i("StreamSession", "motionEvent => $motionControllerState")
|
||||
controllerStateUpdated()
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.session
|
||||
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.metallic.chiaki.common.LogManager
|
||||
import com.metallic.chiaki.lib.*
|
||||
|
||||
sealed class StreamState
|
||||
object StreamStateIdle: StreamState()
|
||||
object StreamStateConnecting: StreamState()
|
||||
object StreamStateConnected: StreamState()
|
||||
data class StreamStateCreateError(val error: CreateError): StreamState()
|
||||
data class StreamStateQuit(val reason: QuitReason, val reasonString: String?): StreamState()
|
||||
data class StreamStateLoginPinRequest(val pinIncorrect: Boolean): StreamState()
|
||||
|
||||
class StreamSession(val connectInfo: ConnectInfo, val logManager: LogManager, val logVerbose: Boolean, val input: StreamInput)
|
||||
{
|
||||
var session: Session? = null
|
||||
private set
|
||||
|
||||
private val _state = MutableLiveData<StreamState>(StreamStateIdle)
|
||||
val state: LiveData<StreamState> get() = _state
|
||||
private val _rumbleState = MutableLiveData<RumbleEvent>(RumbleEvent(0U, 0U))
|
||||
val rumbleState: LiveData<RumbleEvent> get() = _rumbleState
|
||||
|
||||
private var surfaceTexture: SurfaceTexture? = null
|
||||
private var surface: Surface? = null
|
||||
|
||||
init
|
||||
{
|
||||
input.controllerStateChangedCallback = {
|
||||
session?.setControllerState(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun shutdown()
|
||||
{
|
||||
session?.stop()
|
||||
session?.dispose()
|
||||
session = null
|
||||
_state.value = StreamStateIdle
|
||||
//surfaceTexture?.release()
|
||||
}
|
||||
|
||||
fun pause()
|
||||
{
|
||||
shutdown()
|
||||
}
|
||||
|
||||
fun resume()
|
||||
{
|
||||
if(session != null)
|
||||
return
|
||||
try
|
||||
{
|
||||
val session = Session(connectInfo, logManager.createNewFile().file.absolutePath, logVerbose)
|
||||
_state.value = StreamStateConnecting
|
||||
session.eventCallback = this::eventCallback
|
||||
session.start()
|
||||
val surface = surface
|
||||
if(surface != null)
|
||||
session.setSurface(surface)
|
||||
this.session = session
|
||||
}
|
||||
catch(e: CreateError)
|
||||
{
|
||||
_state.value = StreamStateCreateError(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun eventCallback(event: Event)
|
||||
{
|
||||
when(event)
|
||||
{
|
||||
is ConnectedEvent -> _state.postValue(StreamStateConnected)
|
||||
is QuitEvent -> _state.postValue(
|
||||
StreamStateQuit(
|
||||
event.reason,
|
||||
event.reasonString
|
||||
)
|
||||
)
|
||||
is LoginPinRequestEvent -> _state.postValue(
|
||||
StreamStateLoginPinRequest(
|
||||
event.pinIncorrect
|
||||
)
|
||||
)
|
||||
is RumbleEvent -> _rumbleState.postValue(event)
|
||||
}
|
||||
}
|
||||
|
||||
fun attachToSurfaceView(surfaceView: SurfaceView)
|
||||
{
|
||||
surfaceView.holder.addCallback(object: SurfaceHolder.Callback {
|
||||
override fun surfaceCreated(holder: SurfaceHolder) { }
|
||||
|
||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int)
|
||||
{
|
||||
val surface = holder.surface
|
||||
this@StreamSession.surface = surface
|
||||
session?.setSurface(surface)
|
||||
}
|
||||
|
||||
override fun surfaceDestroyed(holder: SurfaceHolder)
|
||||
{
|
||||
this@StreamSession.surface = null
|
||||
session?.setSurface(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun attachToTextureView(textureView: TextureView)
|
||||
{
|
||||
textureView.surfaceTextureListener = object: TextureView.SurfaceTextureListener {
|
||||
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int)
|
||||
{
|
||||
if(surfaceTexture != null)
|
||||
return
|
||||
surfaceTexture = surface
|
||||
this@StreamSession.surface = Surface(surfaceTexture)
|
||||
session?.setSurface(Surface(surface))
|
||||
}
|
||||
|
||||
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean
|
||||
{
|
||||
// return false if we want to keep the surface texture
|
||||
return surfaceTexture == null
|
||||
}
|
||||
|
||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) { }
|
||||
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {}
|
||||
}
|
||||
|
||||
val surfaceTexture = surfaceTexture
|
||||
if(surfaceTexture != null)
|
||||
textureView.setSurfaceTexture(surfaceTexture)
|
||||
}
|
||||
|
||||
fun setLoginPin(pin: String)
|
||||
{
|
||||
session?.setLoginPin(pin)
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import androidx.core.graphics.withClip
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.metallic.chiaki.R
|
||||
|
||||
abstract class ItemTouchSwipeCallback(context: Context): ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT)
|
||||
{
|
||||
private val backgroundDrawable = context.getDrawable(R.color.item_delete_background)
|
||||
private val icon = context.getDrawable(R.drawable.ic_delete_row)
|
||||
|
||||
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder) = false
|
||||
|
||||
override fun onChildDraw(canvas: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean)
|
||||
{
|
||||
val itemView = viewHolder.itemView
|
||||
val itemHeight = itemView.bottom - itemView.top
|
||||
|
||||
val bounds = Rect(
|
||||
itemView.right + dX.toInt(),
|
||||
itemView.top,
|
||||
itemView.right,
|
||||
itemView.bottom
|
||||
)
|
||||
|
||||
backgroundDrawable?.bounds = bounds
|
||||
backgroundDrawable?.draw(canvas)
|
||||
|
||||
val icon = icon
|
||||
if(icon != null)
|
||||
{
|
||||
val iconMargin = (itemHeight - icon.intrinsicHeight) / 2
|
||||
val iconTop = itemView.top + iconMargin
|
||||
val iconLeft = itemView.right - iconMargin - icon.intrinsicWidth
|
||||
val iconRight = itemView.right - iconMargin
|
||||
val iconBottom = iconTop + icon.intrinsicHeight
|
||||
canvas.withClip(bounds) {
|
||||
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom)
|
||||
icon.draw(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
|
||||
}
|
||||
}
|
|
@ -1,60 +1,31 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.databinding.ActivitySettingsBinding
|
||||
|
||||
interface TitleFragment
|
||||
class SettingsActivity: AppCompatActivity()
|
||||
{
|
||||
fun getTitle(resources: Resources): String
|
||||
}
|
||||
|
||||
class SettingsActivity: AppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
|
||||
{
|
||||
private lateinit var binding: ActivitySettingsBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
title = ""
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
val rootFragment = SettingsFragment()
|
||||
replaceFragment(rootFragment, false)
|
||||
supportFragmentManager.addOnBackStackChangedListener {
|
||||
val titleFragment = supportFragmentManager.findFragmentById(R.id.settingsFragment) as? TitleFragment ?: return@addOnBackStackChangedListener
|
||||
binding.titleTextView.text = titleFragment.getTitle(resources)
|
||||
}
|
||||
binding.titleTextView.text = rootFragment.getTitle(resources)
|
||||
}
|
||||
|
||||
override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference) = when(pref.fragment)
|
||||
{
|
||||
SettingsRegisteredHostsFragment::class.java.canonicalName -> {
|
||||
replaceFragment(SettingsRegisteredHostsFragment(), true)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
private fun replaceFragment(fragment: Fragment, addToBackStack: Boolean)
|
||||
{
|
||||
supportFragmentManager.beginTransaction()
|
||||
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
.replace(R.id.settingsFragment, fragment)
|
||||
.also {
|
||||
if(addToBackStack)
|
||||
it.addToBackStack(null)
|
||||
}
|
||||
.commit()
|
||||
setContentView(R.layout.activity_settings)
|
||||
}
|
||||
}
|
|
@ -1,174 +1,30 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.preference.*
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
import com.metallic.chiaki.common.exportAndShareAllSettings
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.common.getDatabase
|
||||
import com.metallic.chiaki.common.importSettingsFromUri
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
|
||||
class DataStore(val preferences: Preferences): PreferenceDataStore()
|
||||
class SettingsFragment: PreferenceFragmentCompat()
|
||||
{
|
||||
override fun getBoolean(key: String?, defValue: Boolean) = when(key)
|
||||
{
|
||||
preferences.logVerboseKey -> preferences.logVerbose
|
||||
preferences.swapCrossMoonKey -> preferences.swapCrossMoon
|
||||
preferences.rumbleEnabledKey -> preferences.rumbleEnabled
|
||||
preferences.motionEnabledKey -> preferences.motionEnabled
|
||||
preferences.buttonHapticEnabledKey -> preferences.buttonHapticEnabled
|
||||
else -> defValue
|
||||
}
|
||||
|
||||
override fun putBoolean(key: String?, value: Boolean)
|
||||
{
|
||||
when(key)
|
||||
{
|
||||
preferences.logVerboseKey -> preferences.logVerbose = value
|
||||
preferences.swapCrossMoonKey -> preferences.swapCrossMoon = value
|
||||
preferences.rumbleEnabledKey -> preferences.rumbleEnabled = value
|
||||
preferences.motionEnabledKey -> preferences.motionEnabled = value
|
||||
preferences.buttonHapticEnabledKey -> preferences.buttonHapticEnabled = value
|
||||
}
|
||||
}
|
||||
|
||||
override fun getString(key: String, defValue: String?) = when(key)
|
||||
{
|
||||
preferences.resolutionKey -> preferences.resolution.value
|
||||
preferences.fpsKey -> preferences.fps.value
|
||||
preferences.bitrateKey -> preferences.bitrate?.toString() ?: ""
|
||||
preferences.codecKey -> preferences.codec.value
|
||||
else -> defValue
|
||||
}
|
||||
|
||||
override fun putString(key: String, value: String?)
|
||||
{
|
||||
when(key)
|
||||
{
|
||||
preferences.resolutionKey ->
|
||||
{
|
||||
val resolution = Preferences.Resolution.values().firstOrNull { it.value == value } ?: return
|
||||
preferences.resolution = resolution
|
||||
}
|
||||
preferences.fpsKey ->
|
||||
{
|
||||
val fps = Preferences.FPS.values().firstOrNull { it.value == value } ?: return
|
||||
preferences.fps = fps
|
||||
}
|
||||
preferences.bitrateKey -> preferences.bitrate = value?.toIntOrNull()
|
||||
preferences.codecKey ->
|
||||
{
|
||||
val codec = Preferences.Codec.values().firstOrNull { it.value == value } ?: return
|
||||
preferences.codec = codec
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsFragment: PreferenceFragmentCompat(), TitleFragment
|
||||
{
|
||||
companion object
|
||||
{
|
||||
private const val PICK_SETTINGS_JSON_REQUEST = 1
|
||||
}
|
||||
|
||||
private var disposable = CompositeDisposable()
|
||||
private var exportDisposable = CompositeDisposable().also { it.addTo(disposable) }
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?)
|
||||
{
|
||||
val context = context ?: return
|
||||
|
||||
val viewModel = ViewModelProvider(this, viewModelFactory { SettingsViewModel(getDatabase(context), Preferences(context)) })
|
||||
.get(SettingsViewModel::class.java)
|
||||
|
||||
val preferences = viewModel.preferences
|
||||
preferenceManager.preferenceDataStore = DataStore(preferences)
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey)
|
||||
|
||||
preferenceScreen.findPreference<ListPreference>(getString(R.string.preferences_resolution_key))?.let {
|
||||
it.entryValues = Preferences.resolutionAll.map { res -> res.value }.toTypedArray()
|
||||
it.entries = Preferences.resolutionAll.map { res -> getString(res.title) }.toTypedArray()
|
||||
}
|
||||
|
||||
preferenceScreen.findPreference<ListPreference>(getString(R.string.preferences_fps_key))?.let {
|
||||
it.entryValues = Preferences.fpsAll.map { fps -> fps.value }.toTypedArray()
|
||||
it.entries = Preferences.fpsAll.map { fps -> getString(fps.title) }.toTypedArray()
|
||||
}
|
||||
|
||||
val bitratePreference = preferenceScreen.findPreference<EditTextPreference>(getString(R.string.preferences_bitrate_key))
|
||||
val bitrateSummaryProvider = Preference.SummaryProvider<EditTextPreference> {
|
||||
preferences.bitrate?.toString() ?: getString(R.string.preferences_bitrate_auto, preferences.bitrateAuto)
|
||||
}
|
||||
bitratePreference?.let {
|
||||
it.summaryProvider = bitrateSummaryProvider
|
||||
it.setOnBindEditTextListener { editText ->
|
||||
editText.hint = getString(R.string.preferences_bitrate_auto, preferences.bitrateAuto)
|
||||
editText.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
editText.setText(preferences.bitrate?.toString() ?: "")
|
||||
}
|
||||
}
|
||||
viewModel.bitrateAuto.observe(this, Observer {
|
||||
bitratePreference?.summaryProvider = bitrateSummaryProvider
|
||||
})
|
||||
|
||||
preferenceScreen.findPreference<ListPreference>(getString(R.string.preferences_codec_key))?.let {
|
||||
it.entryValues = Preferences.codecAll.map { codec -> codec.value }.toTypedArray()
|
||||
it.entries = Preferences.codecAll.map { codec -> getString(codec.title) }.toTypedArray()
|
||||
}
|
||||
|
||||
val registeredHostsPreference = preferenceScreen.findPreference<Preference>("registered_hosts")
|
||||
viewModel.registeredHostsCount.observe(this, Observer {
|
||||
registeredHostsPreference?.summary = getString(R.string.preferences_registered_hosts_summary, it)
|
||||
})
|
||||
|
||||
preferenceScreen.findPreference<Preference>(getString(R.string.preferences_export_settings_key))?.setOnPreferenceClickListener { exportSettings(); true }
|
||||
preferenceScreen.findPreference<Preference>(getString(R.string.preferences_import_settings_key))?.setOnPreferenceClickListener { importSettings(); true }
|
||||
}
|
||||
|
||||
override fun onDestroy()
|
||||
{
|
||||
super.onDestroy()
|
||||
disposable.dispose()
|
||||
}
|
||||
|
||||
override fun getTitle(resources: Resources): String = resources.getString(R.string.title_settings)
|
||||
|
||||
private fun exportSettings()
|
||||
{
|
||||
val activity = activity ?: return
|
||||
exportDisposable.clear()
|
||||
exportAndShareAllSettings(activity).addTo(exportDisposable)
|
||||
}
|
||||
|
||||
private fun importSettings()
|
||||
{
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "application/json"
|
||||
}
|
||||
startActivityForResult(intent, PICK_SETTINGS_JSON_REQUEST)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
|
||||
{
|
||||
if(requestCode == PICK_SETTINGS_JSON_REQUEST && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
val activity = activity ?: return
|
||||
data?.data?.also {
|
||||
importSettingsFromUri(activity, it, disposable)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.LogFile
|
||||
import com.metallic.chiaki.common.ext.inflate
|
||||
import com.metallic.chiaki.databinding.ItemLogFileBinding
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class SettingsLogsAdapter: RecyclerView.Adapter<SettingsLogsAdapter.ViewHolder>()
|
||||
{
|
||||
var shareCallback: ((LogFile) -> Unit)? = null
|
||||
|
||||
private val dateFormat: DateFormat = DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
private val timeFormat = SimpleDateFormat("HH:mm:ss:SSS", Locale.getDefault())
|
||||
|
||||
class ViewHolder(val binding: ItemLogFileBinding): RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
var logFiles: List<LogFile> = listOf()
|
||||
set(value)
|
||||
{
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
ViewHolder(ItemLogFileBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
|
||||
override fun getItemCount() = logFiles.size
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int)
|
||||
{
|
||||
val logFile = logFiles[position]
|
||||
holder.binding.nameTextView.text = "${dateFormat.format(logFile.date)} ${timeFormat.format(logFile.date)}"
|
||||
holder.binding.summaryTextView.text = logFile.filename
|
||||
holder.binding.shareButton.setOnClickListener { shareCallback?.let { it(logFile) } }
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.LogFile
|
||||
import com.metallic.chiaki.common.LogManager
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.common.fileProviderAuthority
|
||||
import com.metallic.chiaki.databinding.FragmentSettingsLogsBinding
|
||||
|
||||
class SettingsLogsFragment: AppCompatDialogFragment(), TitleFragment
|
||||
{
|
||||
private lateinit var viewModel: SettingsLogsViewModel
|
||||
|
||||
private var _binding: FragmentSettingsLogsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
FragmentSettingsLogsBinding.inflate(inflater, container, false).let {
|
||||
_binding = it
|
||||
it.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
||||
{
|
||||
val context = requireContext()
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory { SettingsLogsViewModel(LogManager(context)) })
|
||||
.get(SettingsLogsViewModel::class.java)
|
||||
|
||||
val adapter = SettingsLogsAdapter()
|
||||
binding.logsRecyclerView.layoutManager = LinearLayoutManager(context)
|
||||
binding.logsRecyclerView.adapter = adapter
|
||||
adapter.shareCallback = this::shareLogFile
|
||||
viewModel.sessionLogs.observe(viewLifecycleOwner, Observer {
|
||||
adapter.logFiles = it
|
||||
binding.emptyInfoGroup.visibility = if(it.isEmpty()) View.VISIBLE else View.GONE
|
||||
})
|
||||
|
||||
val itemTouchSwipeCallback = object : ItemTouchSwipeCallback(context)
|
||||
{
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
|
||||
{
|
||||
val pos = viewHolder.adapterPosition
|
||||
val file = viewModel.sessionLogs.value?.getOrNull(pos) ?: return
|
||||
viewModel.deleteLog(file)
|
||||
}
|
||||
}
|
||||
ItemTouchHelper(itemTouchSwipeCallback).attachToRecyclerView(binding.logsRecyclerView)
|
||||
}
|
||||
|
||||
override fun getTitle(resources: Resources): String = resources.getString(R.string.preferences_logs_title)
|
||||
|
||||
private fun shareLogFile(file: LogFile)
|
||||
{
|
||||
val activity = activity ?: return
|
||||
val uri = FileProvider.getUriForFile(activity, fileProviderAuthority, file.file)
|
||||
Intent(Intent.ACTION_SEND).also {
|
||||
it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
it.type = "text/plain"
|
||||
it.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
it.clipData = ClipData.newRawUri("", uri)
|
||||
startActivity(Intent.createChooser(it, resources.getString(R.string.action_share_log)))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.LogFile
|
||||
import com.metallic.chiaki.common.LogManager
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class SettingsLogsViewModel(val logManager: LogManager): ViewModel()
|
||||
{
|
||||
private val _sessionLogs = MutableLiveData<List<LogFile>>(logManager.files)
|
||||
val sessionLogs: LiveData<List<LogFile>> get() = _sessionLogs
|
||||
|
||||
private fun updateLogs()
|
||||
{
|
||||
_sessionLogs.value = logManager.files
|
||||
}
|
||||
|
||||
fun deleteLog(file: LogFile)
|
||||
{
|
||||
file.file.delete()
|
||||
updateLogs()
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.databinding.ItemRegisteredHostBinding
|
||||
|
||||
class SettingsRegisteredHostsAdapter: RecyclerView.Adapter<SettingsRegisteredHostsAdapter.ViewHolder>()
|
||||
{
|
||||
class ViewHolder(val binding: ItemRegisteredHostBinding): RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
var hosts: List<RegisteredHost> = listOf()
|
||||
set(value)
|
||||
{
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
|
||||
= ViewHolder(ItemRegisteredHostBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
|
||||
override fun getItemCount() = hosts.size
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int)
|
||||
{
|
||||
val host = hosts[position]
|
||||
holder.binding.nameTextView.text = "${host.serverNickname} (${if(host.target.isPS5) "PS5" else "PS4"})"
|
||||
holder.binding.summaryTextView.text = host.serverMac.toString()
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.ext.putRevealExtra
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.common.getDatabase
|
||||
import com.metallic.chiaki.databinding.FragmentSettingsRegisteredHostsBinding
|
||||
import com.metallic.chiaki.regist.RegistActivity
|
||||
|
||||
class SettingsRegisteredHostsFragment: AppCompatDialogFragment(), TitleFragment
|
||||
{
|
||||
private lateinit var viewModel: SettingsRegisteredHostsViewModel
|
||||
|
||||
private var _binding: FragmentSettingsRegisteredHostsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
FragmentSettingsRegisteredHostsBinding.inflate(inflater, container, false).let {
|
||||
_binding = it
|
||||
it.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
||||
{
|
||||
val context = requireContext()
|
||||
viewModel = ViewModelProvider(this, viewModelFactory { SettingsRegisteredHostsViewModel(getDatabase(context)) })
|
||||
.get(SettingsRegisteredHostsViewModel::class.java)
|
||||
|
||||
val adapter = SettingsRegisteredHostsAdapter()
|
||||
binding.hostsRecyclerView.layoutManager = LinearLayoutManager(context)
|
||||
binding.hostsRecyclerView.adapter = adapter
|
||||
val itemTouchSwipeCallback = object : ItemTouchSwipeCallback(context)
|
||||
{
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
|
||||
{
|
||||
val pos = viewHolder.adapterPosition
|
||||
val host = viewModel.registeredHosts.value?.getOrNull(pos) ?: return
|
||||
MaterialAlertDialogBuilder(viewHolder.itemView.context)
|
||||
.setMessage(getString(R.string.alert_message_delete_registered_host, host.serverNickname, host.serverMac.toString()))
|
||||
.setPositiveButton(R.string.action_delete) { _, _ ->
|
||||
viewModel.deleteHost(host)
|
||||
}
|
||||
.setNegativeButton(R.string.action_keep) { _, _ ->
|
||||
adapter.notifyItemChanged(pos) // to reset the swipe
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
ItemTouchHelper(itemTouchSwipeCallback).attachToRecyclerView(binding.hostsRecyclerView)
|
||||
viewModel.registeredHosts.observe(this, Observer {
|
||||
adapter.hosts = it
|
||||
binding.emptyInfoGroup.visibility = if(it.isEmpty()) View.VISIBLE else View.GONE
|
||||
})
|
||||
|
||||
binding.floatingActionButton.setOnClickListener {
|
||||
Intent(context, RegistActivity::class.java).also {
|
||||
it.putRevealExtra(binding.floatingActionButton, binding.rootLayout)
|
||||
startActivity(it, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTitle(resources: Resources): String = resources.getString(R.string.preferences_registered_hosts_title)
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.RegisteredHost
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class SettingsRegisteredHostsViewModel(val database: AppDatabase): ViewModel()
|
||||
{
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
val registeredHosts by lazy {
|
||||
database.registeredHostDao().getAll().toLiveData()
|
||||
}
|
||||
|
||||
fun deleteHost(host: RegisteredHost)
|
||||
{
|
||||
database.registeredHostDao()
|
||||
.delete(host)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
.addTo(disposable)
|
||||
}
|
||||
|
||||
override fun onCleared()
|
||||
{
|
||||
super.onCleared()
|
||||
disposable.dispose()
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.settings
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.common.AppDatabase
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
import com.metallic.chiaki.common.ext.toLiveData
|
||||
|
||||
class SettingsViewModel(val database: AppDatabase, val preferences: Preferences): ViewModel()
|
||||
{
|
||||
val registeredHostsCount by lazy {
|
||||
database.registeredHostDao().count().toLiveData()
|
||||
}
|
||||
|
||||
val bitrateAuto by lazy {
|
||||
preferences.bitrateAutoObservable.toLiveData()
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.metallic.chiaki.stream
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
|
||||
// see ExoPlayer's AspectRatioFrameLayout
|
||||
class AspectRatioFrameLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null): FrameLayout(context, attrs)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
private const val MAX_ASPECT_RATIO_DEFORMATION_FRACTION = 0.01f
|
||||
}
|
||||
|
||||
var aspectRatio = 0f
|
||||
set(value)
|
||||
{
|
||||
if(field != value)
|
||||
{
|
||||
field = value
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
var mode: TransformMode = TransformMode.FIT
|
||||
set(value)
|
||||
{
|
||||
if(field != value)
|
||||
{
|
||||
field = value
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
|
||||
{
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
if(aspectRatio <= 0)
|
||||
{
|
||||
// Aspect ratio not set.
|
||||
return
|
||||
}
|
||||
var width = measuredWidth
|
||||
var height = measuredHeight
|
||||
val viewAspectRatio = width.toFloat() / height
|
||||
val aspectDeformation = aspectRatio / viewAspectRatio - 1
|
||||
if(Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION)
|
||||
return
|
||||
when(mode)
|
||||
{
|
||||
TransformMode.ZOOM ->
|
||||
if(aspectDeformation > 0)
|
||||
width = (height * aspectRatio).toInt()
|
||||
else
|
||||
height = (width / aspectRatio).toInt()
|
||||
TransformMode.FIT ->
|
||||
if(aspectDeformation > 0)
|
||||
height = (width / aspectRatio).toInt()
|
||||
else
|
||||
width = (height * aspectRatio).toInt()
|
||||
TransformMode.STRETCH -> {}
|
||||
}
|
||||
super.onMeasure(
|
||||
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,135 +1,88 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.stream
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.Matrix
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import android.os.Bundle
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.*
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.metallic.chiaki.*
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||
import com.metallic.chiaki.databinding.ActivityStreamBinding
|
||||
import com.metallic.chiaki.lib.ConnectInfo
|
||||
import com.metallic.chiaki.lib.ConnectVideoProfile
|
||||
import com.metallic.chiaki.session.*
|
||||
import com.metallic.chiaki.touchcontrols.DefaultTouchControlsFragment
|
||||
import com.metallic.chiaki.lib.LoginPinRequestEvent
|
||||
import com.metallic.chiaki.lib.QuitReason
|
||||
import com.metallic.chiaki.touchcontrols.TouchControlsFragment
|
||||
import com.metallic.chiaki.touchcontrols.TouchpadOnlyFragment
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import kotlin.math.min
|
||||
import kotlinx.android.synthetic.main.activity_stream.*
|
||||
|
||||
private sealed class DialogContents
|
||||
private object StreamQuitDialog: DialogContents()
|
||||
private object CreateErrorDialog: DialogContents()
|
||||
private object PinRequestDialog: DialogContents()
|
||||
|
||||
class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListener
|
||||
class StreamActivity : AppCompatActivity()
|
||||
{
|
||||
companion object
|
||||
{
|
||||
const val EXTRA_CONNECT_INFO = "connect_info"
|
||||
private const val HIDE_UI_TIMEOUT_MS = 2000L
|
||||
}
|
||||
|
||||
private lateinit var viewModel: StreamViewModel
|
||||
private lateinit var binding: ActivityStreamBinding
|
||||
|
||||
private val uiVisibilityHandler = Handler()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val connectInfo = intent.getParcelableExtra<ConnectInfo>(EXTRA_CONNECT_INFO)
|
||||
if(connectInfo == null)
|
||||
viewModel = ViewModelProviders.of(this)[StreamViewModel::class.java]
|
||||
if(!viewModel.isInitialized)
|
||||
{
|
||||
finish()
|
||||
return
|
||||
val connectInfo = intent.getParcelableExtra<ConnectInfo>(EXTRA_CONNECT_INFO)
|
||||
if(connectInfo == null)
|
||||
{
|
||||
finish()
|
||||
return
|
||||
}
|
||||
viewModel.init(connectInfo)
|
||||
}
|
||||
|
||||
viewModel = ViewModelProvider(this, viewModelFactory {
|
||||
StreamViewModel(application, connectInfo)
|
||||
})[StreamViewModel::class.java]
|
||||
setContentView(R.layout.activity_stream)
|
||||
|
||||
viewModel.input.observe(this)
|
||||
viewModel.session.attachToTextureView(textureView)
|
||||
|
||||
binding = ActivityStreamBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
window.decorView.setOnSystemUiVisibilityChangeListener(this)
|
||||
|
||||
viewModel.onScreenControlsEnabled.observe(this, Observer {
|
||||
if(binding.onScreenControlsSwitch.isChecked != it)
|
||||
binding.onScreenControlsSwitch.isChecked = it
|
||||
if(binding.onScreenControlsSwitch.isChecked)
|
||||
binding.touchpadOnlySwitch.isChecked = false
|
||||
})
|
||||
binding.onScreenControlsSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
viewModel.setOnScreenControlsEnabled(isChecked)
|
||||
showOverlay()
|
||||
}
|
||||
|
||||
viewModel.touchpadOnlyEnabled.observe(this, Observer {
|
||||
if(binding.touchpadOnlySwitch.isChecked != it)
|
||||
binding.touchpadOnlySwitch.isChecked = it
|
||||
if(binding.touchpadOnlySwitch.isChecked)
|
||||
binding.onScreenControlsSwitch.isChecked = false
|
||||
})
|
||||
binding.touchpadOnlySwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||
viewModel.setTouchpadOnlyEnabled(isChecked)
|
||||
showOverlay()
|
||||
}
|
||||
|
||||
binding.displayModeToggle.addOnButtonCheckedListener { _, _, _ ->
|
||||
adjustStreamViewAspect()
|
||||
showOverlay()
|
||||
}
|
||||
|
||||
//viewModel.session.attachToTextureView(textureView)
|
||||
viewModel.session.attachToSurfaceView(binding.surfaceView)
|
||||
viewModel.session.state.observe(this, Observer { this.stateChanged(it) })
|
||||
adjustStreamViewAspect()
|
||||
|
||||
if(Preferences(this).rumbleEnabled)
|
||||
{
|
||||
val vibrator = getSystemService(VIBRATOR_SERVICE) as Vibrator
|
||||
viewModel.session.rumbleState.observe(this, Observer {
|
||||
val amplitude = min(255, (it.left.toInt() + it.right.toInt()) / 2)
|
||||
vibrator.cancel()
|
||||
if(amplitude == 0)
|
||||
return@Observer
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(1000, amplitude))
|
||||
else
|
||||
vibrator.vibrate(1000)
|
||||
})
|
||||
textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
||||
adjustTextureViewAspect()
|
||||
}
|
||||
}
|
||||
|
||||
private val controlsDisposable = CompositeDisposable()
|
||||
|
||||
override fun onAttachFragment(fragment: Fragment)
|
||||
{
|
||||
super.onAttachFragment(fragment)
|
||||
if(fragment is TouchControlsFragment)
|
||||
{
|
||||
fragment.controllerState
|
||||
.subscribe { viewModel.input.touchControllerState = it }
|
||||
.addTo(controlsDisposable)
|
||||
fragment.onScreenControlsEnabled = viewModel.onScreenControlsEnabled
|
||||
if(fragment is TouchpadOnlyFragment)
|
||||
fragment.touchpadOnlyEnabled = viewModel.touchpadOnlyEnabled
|
||||
}
|
||||
(fragment as? TouchControlsFragment)?.controllerStateCallback = viewModel.session::updateTouchControllerState
|
||||
}
|
||||
|
||||
override fun onResume()
|
||||
|
@ -145,57 +98,12 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
viewModel.session.pause()
|
||||
}
|
||||
|
||||
override fun onDestroy()
|
||||
{
|
||||
super.onDestroy()
|
||||
controlsDisposable.dispose()
|
||||
}
|
||||
|
||||
private fun reconnect()
|
||||
{
|
||||
viewModel.session.shutdown()
|
||||
viewModel.session.resume()
|
||||
}
|
||||
|
||||
private val hideSystemUIRunnable = Runnable { hideSystemUI() }
|
||||
|
||||
override fun onSystemUiVisibilityChange(visibility: Int)
|
||||
{
|
||||
if(visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0)
|
||||
showOverlay()
|
||||
else
|
||||
hideOverlay()
|
||||
}
|
||||
|
||||
private fun showOverlay()
|
||||
{
|
||||
binding.overlay.isVisible = true
|
||||
binding.overlay.animate()
|
||||
.alpha(1.0f)
|
||||
.setListener(object: AnimatorListenerAdapter()
|
||||
{
|
||||
override fun onAnimationEnd(animation: Animator)
|
||||
{
|
||||
binding.overlay.alpha = 1.0f
|
||||
}
|
||||
})
|
||||
uiVisibilityHandler.removeCallbacks(hideSystemUIRunnable)
|
||||
uiVisibilityHandler.postDelayed(hideSystemUIRunnable, HIDE_UI_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
private fun hideOverlay()
|
||||
{
|
||||
binding.overlay.animate()
|
||||
.alpha(0.0f)
|
||||
.setListener(object: AnimatorListenerAdapter()
|
||||
{
|
||||
override fun onAnimationEnd(animation: Animator)
|
||||
{
|
||||
binding.overlay.isGone = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean)
|
||||
{
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
|
@ -205,7 +113,7 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
|
||||
private fun hideSystemUI()
|
||||
{
|
||||
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
|
@ -224,39 +132,34 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
|
||||
private fun stateChanged(state: StreamState)
|
||||
{
|
||||
binding.progressBar.visibility = if(state == StreamStateConnecting) View.VISIBLE else View.GONE
|
||||
progressBar.visibility = if(state == StreamStateConnecting) View.VISIBLE else View.GONE
|
||||
|
||||
when(state)
|
||||
{
|
||||
is StreamStateQuit ->
|
||||
{
|
||||
if(dialogContents != StreamQuitDialog)
|
||||
if(!state.reason.isStopped && dialogContents != StreamQuitDialog)
|
||||
{
|
||||
if(state.reason.isError)
|
||||
{
|
||||
dialog?.dismiss()
|
||||
val reasonStr = state.reasonString
|
||||
val dialog = MaterialAlertDialogBuilder(this)
|
||||
.setMessage(getString(R.string.alert_message_session_quit, state.reason.toString())
|
||||
+ (if(reasonStr != null) "\n$reasonStr" else ""))
|
||||
.setPositiveButton(R.string.action_reconnect) { _, _ ->
|
||||
dialog = null
|
||||
reconnect()
|
||||
}
|
||||
.setOnCancelListener {
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton(R.string.action_quit_session) { _, _ ->
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.create()
|
||||
dialogContents = StreamQuitDialog
|
||||
dialog.show()
|
||||
}
|
||||
else
|
||||
finish()
|
||||
dialog?.dismiss()
|
||||
val reasonStr = state.reasonString
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.alert_message_session_quit, state.reason.toString())
|
||||
+ (if(reasonStr != null) "\n$reasonStr" else ""))
|
||||
.setPositiveButton(R.string.action_reconnect) { _, _ ->
|
||||
dialog = null
|
||||
reconnect()
|
||||
}
|
||||
.setOnDismissListener {
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton(R.string.action_quit_session) { _, _ ->
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.create()
|
||||
dialogContents = StreamQuitDialog
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,13 +168,16 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
if(dialogContents != CreateErrorDialog)
|
||||
{
|
||||
dialog?.dismiss()
|
||||
val dialog = MaterialAlertDialogBuilder(this)
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.alert_message_session_create_error, state.error.errorCode.toString()))
|
||||
.setOnDismissListener {
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton(R.string.action_quit_session) { _, _ -> }
|
||||
.setNegativeButton(R.string.action_quit_session) { _, _ ->
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
.create()
|
||||
dialogContents = CreateErrorDialog
|
||||
dialog.show()
|
||||
|
@ -287,7 +193,7 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
val view = layoutInflater.inflate(R.layout.dialog_login_pin, null)
|
||||
val pinEditText = view.findViewById<EditText>(R.id.pinEditText)
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(this)
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setMessage(
|
||||
if(state.pinIncorrect)
|
||||
R.string.alert_message_login_pin_request_incorrect
|
||||
|
@ -298,7 +204,7 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
dialog = null
|
||||
viewModel.session.setLoginPin(pinEditText.text.toString())
|
||||
}
|
||||
.setOnCancelListener {
|
||||
.setOnDismissListener {
|
||||
dialog = null
|
||||
finish()
|
||||
}
|
||||
|
@ -311,90 +217,42 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
|||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun adjustTextureViewAspect(textureView: TextureView)
|
||||
private fun adjustTextureViewAspect()
|
||||
{
|
||||
val trans = TextureViewTransform(viewModel.session.connectInfo.videoProfile, textureView)
|
||||
val resolution = trans.resolutionFor(TransformMode.fromButton(binding.displayModeToggle.checkedButtonId))
|
||||
val contentWidth = viewModel.session.connectInfo.videoProfile.width.toFloat()
|
||||
val contentHeight = viewModel.session.connectInfo.videoProfile.height.toFloat()
|
||||
val viewWidth = textureView.width.toFloat()
|
||||
val viewHeight = textureView.height.toFloat()
|
||||
val contentAspect = contentHeight / contentWidth
|
||||
|
||||
val width: Float
|
||||
val height: Float
|
||||
if(viewHeight > viewWidth * contentAspect)
|
||||
{
|
||||
width = viewWidth
|
||||
height = viewWidth * contentAspect
|
||||
}
|
||||
else
|
||||
{
|
||||
width = viewHeight / contentAspect
|
||||
height = viewHeight
|
||||
}
|
||||
|
||||
Matrix().also {
|
||||
textureView.getTransform(it)
|
||||
it.setScale(resolution.width / trans.viewWidth, resolution.height / trans.viewHeight)
|
||||
it.postTranslate((trans.viewWidth - resolution.width) * 0.5f, (trans.viewHeight - resolution.height) * 0.5f)
|
||||
it.setScale(width / viewWidth, height / viewHeight)
|
||||
it.postTranslate((viewWidth - width) * 0.5f, (viewHeight - height) * 0.5f)
|
||||
textureView.setTransform(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun adjustSurfaceViewAspect()
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean
|
||||
{
|
||||
val videoProfile = viewModel.session.connectInfo.videoProfile
|
||||
binding.aspectRatioLayout.aspectRatio = videoProfile.width.toFloat() / videoProfile.height.toFloat()
|
||||
binding.aspectRatioLayout.mode = TransformMode.fromButton(binding.displayModeToggle.checkedButtonId)
|
||||
}
|
||||
|
||||
private fun adjustStreamViewAspect() = adjustSurfaceViewAspect()
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent) = viewModel.input.dispatchKeyEvent(event) || super.dispatchKeyEvent(event)
|
||||
override fun onGenericMotionEvent(event: MotionEvent) = viewModel.input.onGenericMotionEvent(event) || super.onGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
enum class TransformMode
|
||||
{
|
||||
FIT,
|
||||
STRETCH,
|
||||
ZOOM;
|
||||
|
||||
companion object
|
||||
{
|
||||
fun fromButton(displayModeButtonId: Int)
|
||||
= when (displayModeButtonId)
|
||||
{
|
||||
R.id.display_mode_stretch_button -> STRETCH
|
||||
R.id.display_mode_zoom_button -> ZOOM
|
||||
else -> FIT
|
||||
}
|
||||
if(viewModel.session.dispatchKeyEvent(event))
|
||||
return true
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
}
|
||||
|
||||
class TextureViewTransform(private val videoProfile: ConnectVideoProfile, private val textureView: TextureView)
|
||||
{
|
||||
private val contentWidth : Float get() = videoProfile.width.toFloat()
|
||||
private val contentHeight : Float get() = videoProfile.height.toFloat()
|
||||
val viewWidth : Float get() = textureView.width.toFloat()
|
||||
val viewHeight : Float get() = textureView.height.toFloat()
|
||||
private val contentAspect : Float get() = contentHeight / contentWidth
|
||||
|
||||
fun resolutionFor(mode: TransformMode): Resolution
|
||||
= when(mode)
|
||||
{
|
||||
TransformMode.STRETCH -> strechedResolution
|
||||
TransformMode.ZOOM -> zoomedResolution
|
||||
TransformMode.FIT -> normalResolution
|
||||
}
|
||||
|
||||
private val strechedResolution get() = Resolution(viewWidth, viewHeight)
|
||||
|
||||
private val zoomedResolution get() =
|
||||
if(viewHeight > viewWidth * contentAspect)
|
||||
{
|
||||
val zoomFactor = viewHeight / contentHeight
|
||||
Resolution(contentWidth * zoomFactor, viewHeight)
|
||||
}
|
||||
else
|
||||
{
|
||||
val zoomFactor = viewWidth / contentWidth
|
||||
Resolution(viewWidth, contentHeight * zoomFactor)
|
||||
}
|
||||
|
||||
private val normalResolution get() =
|
||||
if(viewHeight > viewWidth * contentAspect)
|
||||
Resolution(viewWidth, viewWidth * contentAspect)
|
||||
else
|
||||
Resolution(viewHeight / contentAspect, viewHeight)
|
||||
}
|
||||
|
||||
|
||||
data class Resolution(val width: Float, val height: Float)
|
||||
|
|
|
@ -1,46 +1,43 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.stream
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.*
|
||||
import com.metallic.chiaki.common.LogManager
|
||||
import com.metallic.chiaki.session.StreamSession
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.metallic.chiaki.StreamSession
|
||||
import com.metallic.chiaki.lib.*
|
||||
import com.metallic.chiaki.session.StreamInput
|
||||
|
||||
class StreamViewModel(val application: Application, val connectInfo: ConnectInfo): ViewModel()
|
||||
class StreamViewModel: ViewModel()
|
||||
{
|
||||
val preferences = Preferences(application)
|
||||
val logManager = LogManager(application)
|
||||
|
||||
private var connectInfo: ConnectInfo? = null
|
||||
private var _session: StreamSession? = null
|
||||
val input = StreamInput(application, preferences)
|
||||
val session = StreamSession(connectInfo, logManager, preferences.logVerbose, input)
|
||||
val session: StreamSession get() = _session ?: throw UninitializedPropertyAccessException("StreamViewModel not initialized")
|
||||
val isInitialized get() = connectInfo != null
|
||||
|
||||
private var _onScreenControlsEnabled = MutableLiveData<Boolean>(preferences.onScreenControlsEnabled)
|
||||
val onScreenControlsEnabled: LiveData<Boolean> get() = _onScreenControlsEnabled
|
||||
|
||||
private var _touchpadOnlyEnabled = MutableLiveData<Boolean>(preferences.touchpadOnlyEnabled)
|
||||
val touchpadOnlyEnabled: LiveData<Boolean> get() = _touchpadOnlyEnabled
|
||||
fun init(connectInfo: ConnectInfo)
|
||||
{
|
||||
if(isInitialized)
|
||||
return
|
||||
_session = StreamSession(connectInfo)
|
||||
}
|
||||
|
||||
override fun onCleared()
|
||||
{
|
||||
super.onCleared()
|
||||
_session?.shutdown()
|
||||
}
|
||||
|
||||
fun setOnScreenControlsEnabled(enabled: Boolean)
|
||||
{
|
||||
preferences.onScreenControlsEnabled = enabled
|
||||
_onScreenControlsEnabled.value = enabled
|
||||
}
|
||||
|
||||
fun setTouchpadOnlyEnabled(enabled: Boolean)
|
||||
{
|
||||
preferences.touchpadOnlyEnabled = enabled
|
||||
_touchpadOnlyEnabled.value = enabled
|
||||
}
|
||||
}
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
|
@ -63,8 +78,7 @@ class AnalogStickView @JvmOverloads constructor(
|
|||
val center = center
|
||||
if(center != null)
|
||||
{
|
||||
val circleRadius = radius + handleRadius
|
||||
drawableBase?.setBounds((center.x - circleRadius).toInt(), (center.y - circleRadius).toInt(), (center.x + circleRadius).toInt(), (center.y + circleRadius).toInt())
|
||||
drawableBase?.setBounds((center.x - radius).toInt(), (center.y - radius).toInt(), (center.x + radius).toInt(), (center.y + radius).toInt())
|
||||
drawableBase?.draw(canvas)
|
||||
|
||||
val handleX = center.x + handlePosition.x * radius
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.metallic.chiaki.common.Preferences
|
||||
|
||||
class ButtonHaptics(val context: Context)
|
||||
{
|
||||
private val enabled = Preferences(context).buttonHapticEnabled
|
||||
|
||||
fun trigger(harder: Boolean = false)
|
||||
{
|
||||
if(!enabled)
|
||||
return
|
||||
val vibrator = context.getSystemService(AppCompatActivity.VIBRATOR_SERVICE) as Vibrator
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
vibrator.vibrate(
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
VibrationEffect.createPredefined(if(harder) VibrationEffect.EFFECT_CLICK else VibrationEffect.EFFECT_TICK)
|
||||
else
|
||||
VibrationEffect.createOneShot(10, if(harder) 200 else 100)
|
||||
)
|
||||
else
|
||||
vibrator.vibrate(10)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
|
@ -6,19 +21,14 @@ import android.content.Context
|
|||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import com.metallic.chiaki.R
|
||||
|
||||
class ButtonView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr)
|
||||
{
|
||||
private val haptics = ButtonHaptics(context)
|
||||
|
||||
var buttonPressed = false
|
||||
private set(value)
|
||||
{
|
||||
|
@ -26,8 +36,6 @@ class ButtonView @JvmOverloads constructor(
|
|||
field = value
|
||||
if(diff)
|
||||
{
|
||||
if(value)
|
||||
haptics.trigger()
|
||||
invalidate()
|
||||
buttonPressedCallback?.let { it(field) }
|
||||
}
|
||||
|
@ -53,39 +61,16 @@ class ButtonView @JvmOverloads constructor(
|
|||
{
|
||||
super.onDraw(canvas)
|
||||
val drawable = if(buttonPressed) drawablePressed else drawableIdle
|
||||
drawable?.setBounds(paddingLeft, paddingTop, width - paddingRight, height - paddingBottom)
|
||||
drawable?.setBounds(0, 0, width, height)
|
||||
drawable?.draw(canvas)
|
||||
}
|
||||
|
||||
/**
|
||||
* If this button overlaps with others in the same layout,
|
||||
* let the one whose center is closest to the touch handle it.
|
||||
*/
|
||||
private fun bestFittingTouchView(x: Float, y: Float): View
|
||||
{
|
||||
val loc = locationOnScreen + Vector(x, y)
|
||||
return (parent as? ViewGroup)?.children?.filter {
|
||||
it is ButtonView
|
||||
}?.filter {
|
||||
val pos = it.locationOnScreen
|
||||
loc.x >= pos.x && loc.x < pos.x + it.width && loc.y >= pos.y && loc.y < pos.y + it.height
|
||||
}?.sortedBy {
|
||||
(loc - (it.locationOnScreen + Vector(it.width.toFloat(), it.height.toFloat()) * 0.5f)).lengthSq
|
||||
}?.firstOrNull() ?: this
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean
|
||||
{
|
||||
when(event.actionMasked)
|
||||
when(event.action)
|
||||
{
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
if(bestFittingTouchView(event.getX(event.actionIndex), event.getY(event.actionIndex)) != this)
|
||||
return false
|
||||
buttonPressed = true
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
|
||||
buttonPressed = false
|
||||
}
|
||||
MotionEvent.ACTION_DOWN -> buttonPressed = true
|
||||
MotionEvent.ACTION_UP -> buttonPressed = false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
|
@ -16,8 +31,6 @@ class DPadView @JvmOverloads constructor(
|
|||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr)
|
||||
{
|
||||
private val haptics = ButtonHaptics(context)
|
||||
|
||||
enum class Direction {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
|
@ -73,7 +86,7 @@ class DPadView @JvmOverloads constructor(
|
|||
else
|
||||
drawable = dpadIdleDrawable
|
||||
|
||||
drawable?.setBounds(paddingLeft, paddingTop, width - paddingRight, height - paddingBottom)
|
||||
drawable?.setBounds(0, 0, width, height)
|
||||
//drawable?.alpha = 127
|
||||
drawable?.draw(canvas)
|
||||
}
|
||||
|
@ -115,8 +128,6 @@ class DPadView @JvmOverloads constructor(
|
|||
|
||||
if(state != newState)
|
||||
{
|
||||
if(newState != null)
|
||||
haptics.trigger()
|
||||
state = newState
|
||||
invalidate()
|
||||
stateChangeCallback?.let { it(state) }
|
||||
|
|
|
@ -1,99 +1,84 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.metallic.chiaki.databinding.FragmentControlsBinding
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.lib.ControllerState
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.Observables.combineLatest
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.fragment_controls.*
|
||||
|
||||
abstract class TouchControlsFragment : Fragment()
|
||||
class TouchControlsFragment : Fragment()
|
||||
{
|
||||
protected var ownControllerState = ControllerState()
|
||||
set(value)
|
||||
var controllerState = ControllerState()
|
||||
private set(value)
|
||||
{
|
||||
val diff = field != value
|
||||
field = value
|
||||
if(diff)
|
||||
ownControllerStateSubject.onNext(ownControllerState)
|
||||
controllerStateCallback?.let { it(value) }
|
||||
}
|
||||
|
||||
protected val ownControllerStateSubject: Subject<ControllerState>
|
||||
= BehaviorSubject.create<ControllerState>().also { it.onNext(ownControllerState) }
|
||||
var controllerStateCallback: ((ControllerState) -> Unit)? = null
|
||||
|
||||
// to delay attaching to the touchpadView until it's available
|
||||
protected val controllerStateProxy: Subject<Observable<ControllerState>>
|
||||
= BehaviorSubject.create<Observable<ControllerState>>().also { it.onNext(ownControllerStateSubject) }
|
||||
val controllerState: Observable<ControllerState> get() =
|
||||
controllerStateProxy.flatMap { it }
|
||||
|
||||
var onScreenControlsEnabled: LiveData<Boolean>? = null
|
||||
}
|
||||
|
||||
class DefaultTouchControlsFragment : TouchControlsFragment()
|
||||
{
|
||||
private var _binding: FragmentControlsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
FragmentControlsBinding.inflate(inflater, container, false).let {
|
||||
_binding = it
|
||||
controllerStateProxy.onNext(
|
||||
combineLatest(ownControllerStateSubject, binding.touchpadView.controllerState) { a, b -> a or b }
|
||||
)
|
||||
it.root
|
||||
}
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View
|
||||
= inflater.inflate(R.layout.fragment_controls, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.dpadView.stateChangeCallback = this::dpadStateChanged
|
||||
binding.crossButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_CROSS)
|
||||
binding.moonButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_MOON)
|
||||
binding.pyramidButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PYRAMID)
|
||||
binding.boxButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_BOX)
|
||||
binding.l1ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_L1)
|
||||
binding.r1ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_R1)
|
||||
binding.l3ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_L3)
|
||||
binding.r3ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_R3)
|
||||
binding.optionsButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_OPTIONS)
|
||||
binding.shareButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_SHARE)
|
||||
binding.psButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PS)
|
||||
dpadView.stateChangeCallback = this::dpadStateChanged
|
||||
crossButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_CROSS)
|
||||
moonButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_MOON)
|
||||
pyramidButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PYRAMID)
|
||||
boxButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_BOX)
|
||||
l1ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_L1)
|
||||
r1ButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_R1)
|
||||
optionsButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_OPTIONS)
|
||||
shareButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_SHARE)
|
||||
psButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PS)
|
||||
touchpadButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_TOUCHPAD)
|
||||
|
||||
binding.l2ButtonView.buttonPressedCallback = { ownControllerState = ownControllerState.copy().apply { l2State = if(it) 255U else 0U } }
|
||||
binding.r2ButtonView.buttonPressedCallback = { ownControllerState = ownControllerState.copy().apply { r2State = if(it) 255U else 0U } }
|
||||
l2ButtonView.buttonPressedCallback = { controllerState = controllerState.copy().apply { l2State = if(it) 255U else 0U } }
|
||||
r2ButtonView.buttonPressedCallback = { controllerState = controllerState.copy().apply { r2State = if(it) 255U else 0U } }
|
||||
|
||||
val quantizeStick = { f: Float ->
|
||||
(Short.MAX_VALUE * f).toInt().toShort()
|
||||
(Short.MAX_VALUE * f).toShort()
|
||||
}
|
||||
|
||||
binding.leftAnalogStickView.stateChangedCallback = { ownControllerState = ownControllerState.copy().apply {
|
||||
leftAnalogStickView.stateChangedCallback = { controllerState = controllerState.copy().apply {
|
||||
leftX = quantizeStick(it.x)
|
||||
leftY = quantizeStick(it.y)
|
||||
}}
|
||||
|
||||
binding.rightAnalogStickView.stateChangedCallback = { ownControllerState = ownControllerState.copy().apply {
|
||||
rightAnalogStickView.stateChangedCallback = { controllerState = controllerState.copy().apply {
|
||||
rightX = quantizeStick(it.x)
|
||||
rightY = quantizeStick(it.y)
|
||||
}}
|
||||
|
||||
onScreenControlsEnabled?.observe(viewLifecycleOwner, Observer {
|
||||
view.visibility = if(it) View.VISIBLE else View.GONE
|
||||
})
|
||||
}
|
||||
|
||||
private fun dpadStateChanged(direction: DPadView.Direction?)
|
||||
{
|
||||
ownControllerState = ownControllerState.copy().apply {
|
||||
controllerState = controllerState.copy().apply {
|
||||
buttons = ((buttons
|
||||
and ControllerState.BUTTON_DPAD_LEFT.inv()
|
||||
and ControllerState.BUTTON_DPAD_RIGHT.inv()
|
||||
|
@ -115,7 +100,7 @@ class DefaultTouchControlsFragment : TouchControlsFragment()
|
|||
}
|
||||
|
||||
private fun buttonStateChanged(buttonMask: UInt) = { pressed: Boolean ->
|
||||
ownControllerState = ownControllerState.copy().apply {
|
||||
controllerState = controllerState.copy().apply {
|
||||
buttons =
|
||||
if(pressed)
|
||||
buttons or buttonMask
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
|
@ -26,7 +41,7 @@ class TouchTracker
|
|||
if(pointerId == null)
|
||||
{
|
||||
pointerId = event.getPointerId(event.actionIndex)
|
||||
currentPosition = Vector(event.getX(event.actionIndex), event.getY(event.actionIndex))
|
||||
currentPosition = Vector(event.x, event.y)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.metallic.chiaki.databinding.FragmentTouchpadOnlyBinding
|
||||
import io.reactivex.rxkotlin.Observables.combineLatest
|
||||
|
||||
class TouchpadOnlyFragment : TouchControlsFragment()
|
||||
{
|
||||
var touchpadOnlyEnabled: LiveData<Boolean>? = null
|
||||
|
||||
private var _binding: FragmentTouchpadOnlyBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
FragmentTouchpadOnlyBinding.inflate(inflater, container, false).let {
|
||||
_binding = it
|
||||
controllerStateProxy.onNext(
|
||||
combineLatest(ownControllerStateSubject, binding.touchpadView.controllerState) { a, b -> a or b }
|
||||
)
|
||||
it.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
touchpadOnlyEnabled?.observe(viewLifecycleOwner, Observer {
|
||||
view.visibility = if(it) View.VISIBLE else View.GONE
|
||||
})
|
||||
}
|
||||
|
||||
private fun buttonStateChanged(buttonMask: UInt) = { pressed: Boolean ->
|
||||
ownControllerState = ownControllerState.copy().apply {
|
||||
buttons =
|
||||
if(pressed)
|
||||
buttons or buttonMask
|
||||
else
|
||||
buttons and buttonMask.inv()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import com.metallic.chiaki.R
|
||||
import com.metallic.chiaki.lib.ControllerState
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlin.math.max
|
||||
|
||||
class TouchpadView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr)
|
||||
{
|
||||
companion object
|
||||
{
|
||||
private const val BUTTON_PRESS_MAX_MOVE_DIST_DP = 32.0f
|
||||
private const val SHORT_BUTTON_PRESS_DURATION_MS = 200L
|
||||
private const val BUTTON_HOLD_DELAY_MS = 500L
|
||||
}
|
||||
|
||||
private val haptics = ButtonHaptics(context)
|
||||
|
||||
private val drawableIdle: Drawable?
|
||||
private val drawablePressed: Drawable?
|
||||
|
||||
private val state: ControllerState = ControllerState()
|
||||
|
||||
inner class Touch(
|
||||
val stateId: UByte,
|
||||
private val startX: Float,
|
||||
private val startY: Float)
|
||||
{
|
||||
var lifted = false // will be true but touch still in list when only relevant for short touch
|
||||
private var maxDist: Float = 0.0f
|
||||
val moveInsignificant: Boolean get() = maxDist < BUTTON_PRESS_MAX_MOVE_DIST_DP
|
||||
|
||||
fun onMove(x: Float, y: Float)
|
||||
{
|
||||
val d = (Vector(x, y) - Vector(startX, startY)).length / resources.displayMetrics.density
|
||||
maxDist = max(d, maxDist)
|
||||
}
|
||||
|
||||
val startButtonHoldRunnable = Runnable {
|
||||
if(!moveInsignificant || buttonHeld)
|
||||
return@Runnable
|
||||
haptics.trigger(true)
|
||||
state.buttons = state.buttons or ControllerState.BUTTON_TOUCHPAD
|
||||
buttonHeld = true
|
||||
triggerStateChanged()
|
||||
}
|
||||
}
|
||||
private val pointerTouches = mutableMapOf<Int, Touch>()
|
||||
|
||||
private val stateSubject: Subject<ControllerState>
|
||||
= BehaviorSubject.create<ControllerState>().also { it.onNext(state) }
|
||||
val controllerState: Observable<ControllerState> get() = stateSubject
|
||||
|
||||
private var shortPressingTouches = listOf<Touch>()
|
||||
private val shortButtonPressLiftRunnable = Runnable {
|
||||
state.buttons = state.buttons and ControllerState.BUTTON_TOUCHPAD.inv()
|
||||
shortPressingTouches.forEach {
|
||||
state.stopTouch(it.stateId)
|
||||
}
|
||||
shortPressingTouches = listOf()
|
||||
triggerStateChanged()
|
||||
}
|
||||
|
||||
private var buttonHeld = false
|
||||
|
||||
init
|
||||
{
|
||||
context.theme.obtainStyledAttributes(attrs, R.styleable.TouchpadView, 0, 0).apply {
|
||||
drawableIdle = getDrawable(R.styleable.TouchpadView_drawableIdle)
|
||||
drawablePressed = getDrawable(R.styleable.TouchpadView_drawablePressed)
|
||||
recycle()
|
||||
}
|
||||
isClickable = true
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas)
|
||||
{
|
||||
super.onDraw(canvas)
|
||||
if(pointerTouches.values.find { !it.lifted } == null)
|
||||
return
|
||||
val drawable = if(state.buttons and ControllerState.BUTTON_TOUCHPAD != 0U) drawablePressed else drawableIdle
|
||||
drawable?.setBounds(paddingLeft, paddingTop, width - paddingRight, height - paddingBottom)
|
||||
drawable?.draw(canvas)
|
||||
}
|
||||
|
||||
private fun touchX(event: MotionEvent, index: Int): UShort =
|
||||
maxOf(0U.toUShort(), minOf((ControllerState.TOUCHPAD_WIDTH - 1u).toUShort(),
|
||||
(ControllerState.TOUCHPAD_WIDTH.toFloat() * event.getX(index) / width.toFloat()).toUInt().toUShort()))
|
||||
|
||||
private fun touchY(event: MotionEvent, index: Int): UShort =
|
||||
maxOf(0U.toUShort(), minOf((ControllerState.TOUCHPAD_HEIGHT - 1u).toUShort(),
|
||||
(ControllerState.TOUCHPAD_HEIGHT.toFloat() * event.getY(index) / height.toFloat()).toUInt().toUShort()))
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean
|
||||
{
|
||||
when(event.actionMasked)
|
||||
{
|
||||
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
state.startTouch(touchX(event, event.actionIndex), touchY(event, event.actionIndex))?.let {
|
||||
haptics.trigger()
|
||||
val touch = Touch(it, event.getX(event.actionIndex), event.getY(event.actionIndex))
|
||||
pointerTouches[event.getPointerId(event.actionIndex)] = touch
|
||||
if(!buttonHeld)
|
||||
postDelayed(touch.startButtonHoldRunnable, BUTTON_HOLD_DELAY_MS)
|
||||
triggerStateChanged()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
|
||||
pointerTouches.remove(event.getPointerId(event.actionIndex))?.let {
|
||||
removeCallbacks(it.startButtonHoldRunnable)
|
||||
when
|
||||
{
|
||||
buttonHeld ->
|
||||
{
|
||||
buttonHeld = false
|
||||
state.buttons = state.buttons and ControllerState.BUTTON_TOUCHPAD.inv()
|
||||
state.stopTouch(it.stateId)
|
||||
}
|
||||
it.moveInsignificant -> triggerShortButtonPress(it)
|
||||
else -> state.stopTouch(it.stateId)
|
||||
}
|
||||
triggerStateChanged()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val changed = pointerTouches.entries.fold(false) { acc, it ->
|
||||
val index = event.findPointerIndex(it.key)
|
||||
if(index < 0)
|
||||
acc
|
||||
else
|
||||
{
|
||||
it.value.onMove(event.getX(event.actionIndex), event.getY(event.actionIndex))
|
||||
acc || state.setTouchPos(it.value.stateId, touchX(event, index), touchY(event, index))
|
||||
}
|
||||
}
|
||||
if(changed)
|
||||
triggerStateChanged()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun triggerShortButtonPress(touch: Touch)
|
||||
{
|
||||
shortPressingTouches = shortPressingTouches + listOf(touch)
|
||||
removeCallbacks(shortButtonPressLiftRunnable)
|
||||
state.buttons = state.buttons or ControllerState.BUTTON_TOUCHPAD
|
||||
postDelayed(shortButtonPressLiftRunnable, SHORT_BUTTON_PRESS_DURATION_MS)
|
||||
}
|
||||
|
||||
private fun triggerStateChanged()
|
||||
{
|
||||
invalidate()
|
||||
stateSubject.onNext(state)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,22 @@
|
|||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.metallic.chiaki.touchcontrols
|
||||
|
||||
import android.view.View
|
||||
import kotlin.math.sqrt
|
||||
|
||||
data class Vector(val x: Float, val y: Float)
|
||||
|
@ -20,9 +34,3 @@ data class Vector(val x: Float, val y: Float)
|
|||
val length get() = sqrt(lengthSq)
|
||||
val normalized get() = this / length
|
||||
}
|
||||
|
||||
val View.locationOnScreen: Vector get() {
|
||||
val v = intArrayOf(0, 0)
|
||||
this.getLocationOnScreen(v)
|
||||
return Vector(v[0].toFloat(), v[1].toFloat())
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="?attr/colorAccent" android:state_checked="true"/>
|
||||
<item android:color="@android:color/white"/>
|
||||
</selector>
|
|
@ -1,10 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="512dp"
|
||||
android:height="512dp"
|
||||
android:viewportWidth="135.46666"
|
||||
android:viewportHeight="135.46667">
|
||||
<path
|
||||
android:pathData="M67.733,0A67.733,67.733 0,0 0,0 67.733,67.733 67.733,46.804 0,0 67.733,135.467 67.733,67.733 0,0 0,135.467 67.733,67.733 67.733,133.241 0,0 67.733,0ZM67.733,19.592 L121.224,67.733L105.177,67.733L105.177,110.526L78.431,110.526L78.431,78.431L57.035,78.431L57.035,110.526L30.29,110.526L30.29,67.733L14.243,67.733Z"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:fillAlpha="1"/>
|
||||
</vector>
|
|
@ -1,10 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="512dp"
|
||||
android:height="512dp"
|
||||
android:viewportWidth="135.46666"
|
||||
android:viewportHeight="135.46667">
|
||||
<path
|
||||
android:pathData="M67.733,0A67.733,67.733 0,0 0,0 67.733,67.733 67.733,46.804 0,0 67.733,135.467 67.733,67.733 0,0 0,135.467 67.733,67.733 67.733,133.241 0,0 67.733,0ZM67.733,19.592 L121.224,67.733L105.177,67.733L105.177,110.526L78.431,110.526L78.431,78.431L57.035,78.431L57.035,110.526L30.29,110.526L30.29,67.733L14.243,67.733Z"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:fillAlpha="1"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M39.2255,0 L0,39.2255 20.3838,59.6093a27.7366,27.7366 88.4859,0 0,39.2255 0,27.7366 27.7366,88.4859 0,0 0,-39.2255zM25.4129,29.4287l2.7735,0l0,18.1643l9.9818,0l0,2.3342L25.4129,49.9272ZM46.3098,29.4287l2.7735,0l0,18.1643l4.5305,0l0,2.3342l-11.8076,0l0,-2.3342l4.531,0l0,-15.6383l-4.9289,0.9886l0,-2.5259z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M39.2255,0 L0,39.2255 20.3838,59.6093a27.7366,27.7366 88.4859,0 0,39.2255 0,27.7366 27.7366,88.4859 0,0 0,-39.2255zM25.4129,29.4287l2.7735,0l0,18.1643l9.9818,0l0,2.3342L25.4129,49.9272ZM46.3098,29.4287l2.7735,0l0,18.1643l4.5305,0l0,2.3342l-11.8076,0l0,-2.3342l4.531,0l0,-15.6383l-4.9289,0.9886l0,-2.5259z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="m27.6526,0a27.7366,27.7366 88.4859,0 0,-19.5285 8.1241,27.7366 27.7366,88.4859 0,0 0,39.2255L28.5078,67.7333 67.7333,28.5078 47.3496,8.1241A27.7366,27.7366 88.4859,0 0,27.6526 0ZM34.9017,15.1846c2.1235,0 3.8172,0.5309 5.0803,1.5927 1.2631,1.0618 1.8945,2.4804 1.8945,4.2561 0,0.8421 -0.1602,1.6432 -0.4806,2.403 -0.3112,0.7506 -0.8832,1.6383 -1.7162,2.6634 -0.2288,0.2654 -0.9563,1.034 -2.1828,2.3063 -1.2265,1.2631 -2.9565,3.0342 -5.1899,5.3134l9.6795,0l0,2.3342l-13.0157,0l0,-2.3342c1.0526,-1.0892 2.4851,-2.549 4.2974,-4.3796 1.8215,-1.8398 2.9655,-3.025 3.4323,-3.5559 0.8879,-0.9977 1.5058,-1.84 1.8536,-2.5265 0.357,-0.6956 0.5354,-1.3777 0.5354,-2.0459 0,-1.0892 -0.3846,-1.9769 -1.1534,-2.6634 -0.7597,-0.6865 -1.7526,-1.0299 -2.9791,-1.0299 -0.8695,-0 -1.7898,0.1511 -2.76,0.4532 -0.9611,0.3021 -1.9908,0.7598 -3.0892,1.373L29.1078,16.5437c1.1167,-0.4485 2.1603,-0.7871 3.1306,-1.016 0.9702,-0.2288 1.8579,-0.3431 2.6634,-0.3431zM14.0053,15.5551l2.7735,0l0,18.1643l9.9813,0l0,2.3342L14.0053,36.0536Z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="m27.6526,0a27.7366,27.7366 88.4859,0 0,-19.5285 8.1241,27.7366 27.7366,88.4859 0,0 0,39.2255L28.5078,67.7333 67.7333,28.5078 47.3496,8.1241A27.7366,27.7366 88.4859,0 0,27.6526 0ZM34.9017,15.1846c2.1235,0 3.8172,0.5309 5.0803,1.5927 1.2631,1.0618 1.8945,2.4804 1.8945,4.2561 0,0.8421 -0.1602,1.6432 -0.4806,2.403 -0.3112,0.7506 -0.8832,1.6383 -1.7162,2.6634 -0.2288,0.2654 -0.9563,1.034 -2.1828,2.3063 -1.2265,1.2631 -2.9565,3.0342 -5.1899,5.3134l9.6795,0l0,2.3342l-13.0157,0l0,-2.3342c1.0526,-1.0892 2.4851,-2.549 4.2974,-4.3796 1.8215,-1.8398 2.9655,-3.025 3.4323,-3.5559 0.8879,-0.9977 1.5058,-1.84 1.8536,-2.5265 0.357,-0.6956 0.5354,-1.3777 0.5354,-2.0459 0,-1.0892 -0.3846,-1.9769 -1.1534,-2.6634 -0.7597,-0.6865 -1.7526,-1.0299 -2.9791,-1.0299 -0.8695,-0 -1.7898,0.1511 -2.76,0.4532 -0.9611,0.3021 -1.9908,0.7598 -3.0892,1.373L29.1078,16.5437c1.1167,-0.4485 2.1603,-0.7871 3.1306,-1.016 0.9702,-0.2288 1.8579,-0.3431 2.6634,-0.3431zM14.0053,15.5551l2.7735,0l0,18.1643l9.9813,0l0,2.3342L14.0053,36.0536Z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M0,0 L-41.939,102.093 67.7333,67.7333C67.7333,30.3253 37.4081,0 0,0ZM33.6093,31.3252c2.1052,0 3.7711,0.4807 4.9976,1.4418 1.2265,0.9519 1.8397,2.2423 1.8397,3.8716 0,1.135 -0.3253,2.0964 -0.9751,2.8835 -0.6499,0.778 -1.5739,1.318 -2.773,1.6201 1.3272,0.2837 2.3613,0.8739 3.1027,1.771 0.7506,0.897 1.126,2.0047 1.126,3.3228 0,2.0228 -0.6959,3.5878 -2.0872,4.6953 -1.3913,1.1075 -3.368,1.6614 -5.9309,1.6614 -0.8604,0 -1.7486,-0.0871 -2.6639,-0.261 -0.9062,-0.1648 -1.8441,-0.4163 -2.8143,-0.755l0,-2.6774c0.7689,0.4485 1.6106,0.7871 2.5259,1.016 0.9153,0.2288 1.8719,0.3431 2.8696,0.3431 1.7391,0 3.0621,-0.3434 3.9682,-1.0299 0.9153,-0.6865 1.3725,-1.6837 1.3725,-2.9926 0,-1.2082 -0.4252,-2.1514 -1.2764,-2.8288 -0.8421,-0.6865 -2.0187,-1.0294 -3.529,-1.0294l-2.3885,0l0,-2.2794l2.4986,0c1.3638,0 2.4075,-0.2697 3.1306,-0.8098 0.7231,-0.5492 1.0847,-1.3365 1.0847,-2.3616 0,-1.0526 -0.3755,-1.858 -1.126,-2.4164 -0.7414,-0.5675 -1.808,-0.8511 -3.1993,-0.8511 -0.7597,0 -1.5742,0.0823 -2.4438,0.247 -0.8695,0.1648 -1.8261,0.4211 -2.8696,0.7689l0,-2.4717c1.0526,-0.2929 2.037,-0.5124 2.9523,-0.6589 0.9245,-0.1464 1.794,-0.2196 2.6086,-0.2196zM12.3832,31.6957l2.7735,0l0,18.1648l9.9813,0l0,2.3337L12.3832,52.1942Z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="11.0688"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M0,0 L-41.939,102.093 67.7333,67.7333C67.7333,30.3253 37.4081,0 0,0ZM33.6093,31.3252c2.1052,0 3.7711,0.4807 4.9976,1.4418 1.2265,0.9519 1.8397,2.2423 1.8397,3.8716 0,1.135 -0.3253,2.0964 -0.9751,2.8835 -0.6499,0.778 -1.5739,1.318 -2.773,1.6201 1.3272,0.2837 2.3613,0.8739 3.1027,1.771 0.7506,0.897 1.126,2.0047 1.126,3.3228 0,2.0228 -0.6959,3.5878 -2.0872,4.6953 -1.3913,1.1075 -3.368,1.6614 -5.9309,1.6614 -0.8604,0 -1.7486,-0.0871 -2.6639,-0.261 -0.9062,-0.1648 -1.8441,-0.4163 -2.8143,-0.755l0,-2.6774c0.7689,0.4485 1.6106,0.7871 2.5259,1.016 0.9153,0.2288 1.8719,0.3431 2.8696,0.3431 1.7391,0 3.0621,-0.3434 3.9682,-1.0299 0.9153,-0.6865 1.3725,-1.6837 1.3725,-2.9926 0,-1.2082 -0.4252,-2.1514 -1.2764,-2.8288 -0.8421,-0.6865 -2.0187,-1.0294 -3.529,-1.0294l-2.3885,0l0,-2.2794l2.4986,0c1.3638,0 2.4075,-0.2697 3.1306,-0.8098 0.7231,-0.5492 1.0847,-1.3365 1.0847,-2.3616 0,-1.0526 -0.3755,-1.858 -1.126,-2.4164 -0.7414,-0.5675 -1.808,-0.8511 -3.1993,-0.8511 -0.7597,0 -1.5742,0.0823 -2.4438,0.247 -0.8695,0.1648 -1.8261,0.4211 -2.8696,0.7689l0,-2.4717c1.0526,-0.2929 2.037,-0.5124 2.9523,-0.6589 0.9245,-0.1464 1.794,-0.2196 2.6086,-0.2196zM12.3832,31.6957l2.7735,0l0,18.1648l9.9813,0l0,2.3337L12.3832,52.1942Z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="11.0688"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M33.8667,0C24.4856,0 16.9333,7.5523 16.9333,16.9333L16.9333,50.8C16.9333,60.1811 24.4856,67.7333 33.8667,67.7333C43.2477,67.7333 50.8,60.1811 50.8,50.8L50.8,16.9333C50.8,7.5523 43.2477,0 33.8667,0zM33.8832,20.5254C37.4891,20.5254 40.3718,21.7372 42.5307,24.1603C44.6897,26.5718 45.7688,29.8102 45.7688,33.8755C45.7688,37.9292 44.6897,41.1676 42.5307,43.5906C40.3718,46.0022 37.4891,47.208 33.8832,47.208C30.2659,47.208 27.372,46.0022 25.2016,43.5906C23.0426,41.1791 21.9635,37.9407 21.9635,33.8755C21.9635,29.8102 23.0426,26.5718 25.2016,24.1603C27.372,21.7372 30.2659,20.5254 33.8832,20.5254zM33.8832,23.3505C31.3568,23.3505 29.3475,24.2923 27.8546,26.1757C26.3732,28.059 25.6325,30.6256 25.6325,33.8755C25.6325,37.1138 26.3732,39.6743 27.8546,41.5577C29.3475,43.441 31.3568,44.3828 33.8832,44.3828C36.4096,44.3828 38.4078,43.441 39.8777,41.5577C41.3591,39.6743 42.0998,37.1138 42.0998,33.8755C42.0998,30.6256 41.3591,28.059 39.8777,26.1757C38.4078,24.2923 36.4096,23.3505 33.8832,23.3505z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="29.7441"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M33.8667,0C24.4856,0 16.9333,7.5523 16.9333,16.9333L16.9333,50.8C16.9333,60.1811 24.4856,67.7333 33.8667,67.7333C43.2477,67.7333 50.8,60.1811 50.8,50.8L50.8,16.9333C50.8,7.5523 43.2477,0 33.8667,0zM33.8832,20.5254C37.4891,20.5254 40.3718,21.7372 42.5307,24.1603C44.6897,26.5718 45.7688,29.8102 45.7688,33.8755C45.7688,37.9292 44.6897,41.1676 42.5307,43.5906C40.3718,46.0022 37.4891,47.208 33.8832,47.208C30.2659,47.208 27.372,46.0022 25.2016,43.5906C23.0426,41.1791 21.9635,37.9407 21.9635,33.8755C21.9635,29.8102 23.0426,26.5718 25.2016,24.1603C27.372,21.7372 30.2659,20.5254 33.8832,20.5254zM33.8832,23.3505C31.3568,23.3505 29.3475,24.2923 27.8546,26.1757C26.3732,28.059 25.6325,30.6256 25.6325,33.8755C25.6325,37.1138 26.3732,39.6743 27.8546,41.5577C29.3475,43.441 31.3568,44.3828 33.8832,44.3828C36.4096,44.3828 38.4078,43.441 39.8777,41.5577C41.3591,39.6743 42.0998,37.1138 42.0998,33.8755C42.0998,30.6256 41.3591,28.059 39.8777,26.1757C38.4078,24.2923 36.4096,23.3505 33.8832,23.3505z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="29.7441"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M28.5078,0 L8.1241,20.3838a27.7366,27.7366 88.4859,0 0,0 39.2255,27.7366 27.7366,88.4859 0,0 39.2255,0L67.7333,39.2255ZM12.4178,29.4287l6.2606,0c2.3432,0 4.0913,0.4898 5.2446,1.4692 1.1533,0.9794 1.7301,2.4573 1.7301,4.4344 0,1.2906 -0.3018,2.3615 -0.9059,3.2127 -0.595,0.8512 -1.4645,1.442 -2.6086,1.7715 0.595,0.2014 1.1713,0.6313 1.7296,1.2904 0.5675,0.659 1.1352,1.5654 1.7027,2.7187L28.3853,49.9272L25.4062,49.9272l-2.6226,-5.2586C22.1063,43.2956 21.4472,42.385 20.8065,41.9365c-0.6316,-0.4485 -1.4963,-0.6728 -2.5947,-0.6728L15.1913,41.2636l0,8.6636L12.4178,49.9272ZM37.1864,29.4287l2.7735,0l0,18.1643l4.5305,0l0,2.3342l-11.8075,0l0,-2.3342l4.531,0l0,-15.6383l-4.9289,0.9886l0,-2.5259zM15.1913,31.7076l0,7.2766l3.4871,0c1.3364,0 2.3432,-0.3066 3.0205,-0.9198 0.6865,-0.6224 1.0299,-1.5331 1.0299,-2.7321 0,-1.1991 -0.3434,-2.1006 -1.0299,-2.7047 -0.6773,-0.6133 -1.6841,-0.9198 -3.0205,-0.9198z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M28.5078,0 L8.1241,20.3838a27.7366,27.7366 88.4859,0 0,0 39.2255,27.7366 27.7366,88.4859 0,0 39.2255,0L67.7333,39.2255ZM12.4178,29.4287l6.2606,0c2.3432,0 4.0913,0.4898 5.2446,1.4692 1.1533,0.9794 1.7301,2.4573 1.7301,4.4344 0,1.2906 -0.3018,2.3615 -0.9059,3.2127 -0.595,0.8512 -1.4645,1.442 -2.6086,1.7715 0.595,0.2014 1.1713,0.6313 1.7296,1.2904 0.5675,0.659 1.1352,1.5654 1.7027,2.7187L28.3853,49.9272L25.4062,49.9272l-2.6226,-5.2586C22.1063,43.2956 21.4472,42.385 20.8065,41.9365c-0.6316,-0.4485 -1.4963,-0.6728 -2.5947,-0.6728L15.1913,41.2636l0,8.6636L12.4178,49.9272ZM37.1864,29.4287l2.7735,0l0,18.1643l4.5305,0l0,2.3342l-11.8075,0l0,-2.3342l4.531,0l0,-15.6383l-4.9289,0.9886l0,-2.5259zM15.1913,31.7076l0,7.2766l3.4871,0c1.3364,0 2.3432,-0.3066 3.0205,-0.9198 0.6865,-0.6224 1.0299,-1.5331 1.0299,-2.7321 0,-1.1991 -0.3434,-2.1006 -1.0299,-2.7047 -0.6773,-0.6133 -1.6841,-0.9198 -3.0205,-0.9198z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M20.3838,8.1241 L0,28.5078 39.2255,67.7333 59.6093,47.3496a27.7366,27.7366 88.4859,0 0,0 -39.2255,27.7366 27.7366,88.4859 0,0 -39.2255,0zM48.9278,15.1846c2.1235,0 3.8167,0.5309 5.0798,1.5927 1.2631,1.0618 1.895,2.4804 1.895,4.2561 0,0.8421 -0.1602,1.6432 -0.4806,2.403 -0.3112,0.7506 -0.8832,1.6383 -1.7162,2.6634 -0.2288,0.2654 -0.9568,1.034 -2.1833,2.3063 -1.2265,1.2631 -2.956,3.0342 -5.1893,5.3134l9.679,0l0,2.3342l-13.0157,0l0,-2.3342c1.0526,-1.0892 2.4851,-2.549 4.2974,-4.3796 1.8215,-1.8398 2.9655,-3.025 3.4323,-3.5559 0.8879,-0.9977 1.5058,-1.84 1.8536,-2.5265 0.357,-0.6956 0.5354,-1.3777 0.5354,-2.0459 0,-1.0892 -0.384,-1.9769 -1.1529,-2.6634 -0.7597,-0.6865 -1.7531,-1.0299 -2.9797,-1.0299 -0.8695,-0 -1.7893,0.1511 -2.7595,0.4532 -0.9611,0.3021 -1.9908,0.7598 -3.0892,1.373L43.1338,16.5437c1.1167,-0.4485 2.1603,-0.7871 3.1306,-1.016 0.9702,-0.2288 1.8579,-0.3431 2.6634,-0.3431zM24.1593,15.5551l6.2611,0c2.3432,0 4.0913,0.4898 5.2446,1.4692 1.1533,0.9794 1.7296,2.4578 1.7296,4.4349 0,1.2906 -0.3018,2.3615 -0.9059,3.2127 -0.595,0.8512 -1.4645,1.4414 -2.6086,1.771 0.595,0.2014 1.1713,0.6313 1.7296,1.2904 0.5675,0.659 1.1352,1.5654 1.7027,2.7187l2.8148,5.6017l-2.9797,0l-2.6221,-5.2586c-0.6773,-1.373 -1.3364,-2.2836 -1.9771,-2.7321 -0.6316,-0.4485 -1.4968,-0.6728 -2.5952,-0.6728l-3.0205,0l0,8.6636L24.1593,36.0536ZM26.9327,17.8346l0,7.2766l3.4876,0c1.3364,0 2.3432,-0.3066 3.0205,-0.9198 0.6865,-0.6224 1.0294,-1.5331 1.0294,-2.7321 0,-1.1991 -0.3429,-2.1006 -1.0294,-2.7047 -0.6773,-0.6133 -1.6841,-0.9198 -3.0205,-0.9198z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M20.3838,8.1241 L0,28.5078 39.2255,67.7333 59.6093,47.3496a27.7366,27.7366 88.4859,0 0,0 -39.2255,27.7366 27.7366,88.4859 0,0 -39.2255,0zM48.9278,15.1846c2.1235,0 3.8167,0.5309 5.0798,1.5927 1.2631,1.0618 1.895,2.4804 1.895,4.2561 0,0.8421 -0.1602,1.6432 -0.4806,2.403 -0.3112,0.7506 -0.8832,1.6383 -1.7162,2.6634 -0.2288,0.2654 -0.9568,1.034 -2.1833,2.3063 -1.2265,1.2631 -2.956,3.0342 -5.1893,5.3134l9.679,0l0,2.3342l-13.0157,0l0,-2.3342c1.0526,-1.0892 2.4851,-2.549 4.2974,-4.3796 1.8215,-1.8398 2.9655,-3.025 3.4323,-3.5559 0.8879,-0.9977 1.5058,-1.84 1.8536,-2.5265 0.357,-0.6956 0.5354,-1.3777 0.5354,-2.0459 0,-1.0892 -0.384,-1.9769 -1.1529,-2.6634 -0.7597,-0.6865 -1.7531,-1.0299 -2.9797,-1.0299 -0.8695,-0 -1.7893,0.1511 -2.7595,0.4532 -0.9611,0.3021 -1.9908,0.7598 -3.0892,1.373L43.1338,16.5437c1.1167,-0.4485 2.1603,-0.7871 3.1306,-1.016 0.9702,-0.2288 1.8579,-0.3431 2.6634,-0.3431zM24.1593,15.5551l6.2611,0c2.3432,0 4.0913,0.4898 5.2446,1.4692 1.1533,0.9794 1.7296,2.4578 1.7296,4.4349 0,1.2906 -0.3018,2.3615 -0.9059,3.2127 -0.595,0.8512 -1.4645,1.4414 -2.6086,1.771 0.595,0.2014 1.1713,0.6313 1.7296,1.2904 0.5675,0.659 1.1352,1.5654 1.7027,2.7187l2.8148,5.6017l-2.9797,0l-2.6221,-5.2586c-0.6773,-1.373 -1.3364,-2.2836 -1.9771,-2.7321 -0.6316,-0.4485 -1.4968,-0.6728 -2.5952,-0.6728l-3.0205,0l0,8.6636L24.1593,36.0536ZM26.9327,17.8346l0,7.2766l3.4876,0c1.3364,0 2.3432,-0.3066 3.0205,-0.9198 0.6865,-0.6224 1.0294,-1.5331 1.0294,-2.7321 0,-1.1991 -0.3429,-2.1006 -1.0294,-2.7047 -0.6773,-0.6133 -1.6841,-0.9198 -3.0205,-0.9198z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="5.54109"
|
||||
android:fillColor="@color/control_pressed"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -1,12 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="256dp"
|
||||
android:height="256dp"
|
||||
android:viewportWidth="67.73333"
|
||||
android:viewportHeight="67.73334">
|
||||
<path
|
||||
android:pathData="M67.7333,0C30.3252,0 0,30.3252 0,67.7333l109.6724,34.3597zM50.2982,31.3252c2.1052,0 3.7711,0.4807 4.9976,1.4418 1.2265,0.9519 1.8402,2.2423 1.8402,3.8716 0,1.135 -0.3253,2.0964 -0.9751,2.8835 -0.6499,0.778 -1.5744,1.318 -2.7735,1.6201 1.3272,0.2837 2.3618,0.8739 3.1032,1.771 0.7506,0.897 1.1255,2.0047 1.1255,3.3228 0,2.0228 -0.6954,3.5878 -2.0867,4.6953 -1.3913,1.1075 -3.3685,1.6614 -5.9314,1.6614 -0.8604,0 -1.7481,-0.0871 -2.6634,-0.261 -0.9062,-0.1648 -1.8441,-0.4163 -2.8143,-0.755l0,-2.6774c0.7689,0.4485 1.6106,0.7871 2.5259,1.016 0.9153,0.2288 1.8719,0.3431 2.8696,0.3431 1.7391,0 3.0616,-0.3434 3.9677,-1.0299 0.9153,-0.6865 1.373,-1.6837 1.373,-2.9926 0,-1.2082 -0.4257,-2.1514 -1.2769,-2.8288 -0.8421,-0.6865 -2.0182,-1.0294 -3.5285,-1.0294l-2.389,0l0,-2.2794l2.4991,0c1.3638,0 2.4069,-0.2697 3.13,-0.8098 0.7231,-0.5492 1.0847,-1.3365 1.0847,-2.3616 0,-1.0526 -0.375,-1.858 -1.1255,-2.4164 -0.7414,-0.5675 -1.808,-0.8511 -3.1993,-0.8511 -0.7597,0 -1.5742,0.0823 -2.4438,0.247 -0.8695,0.1648 -1.8261,0.4211 -2.8696,0.7689l0,-2.4717c1.0526,-0.2929 2.0364,-0.5124 2.9518,-0.6589 0.9245,-0.1464 1.794,-0.2196 2.6086,-0.2196zM25.2005,31.6957L31.4611,31.6957c2.3432,0 4.0913,0.4898 5.2446,1.4692 1.1533,0.9794 1.7301,2.4578 1.7301,4.4349 0,1.2906 -0.3018,2.3615 -0.9059,3.2127 -0.595,0.8512 -1.4645,1.4414 -2.6086,1.771 0.595,0.2014 1.1713,0.6319 1.7296,1.2909 0.5675,0.659 1.1352,1.5649 1.7027,2.7182l2.8143,5.6017l-2.9791,0l-2.6226,-5.2581c-0.6773,-1.373 -1.3364,-2.2841 -1.9771,-2.7326 -0.6316,-0.4485 -1.4963,-0.6723 -2.5947,-0.6723l-3.0205,0l0,8.663L25.2005,52.1942ZM27.974,33.9752l0,7.2766l3.4871,0c1.3364,0 2.3432,-0.3066 3.0205,-0.9198 0.6865,-0.6224 1.0299,-1.5331 1.0299,-2.7321 0,-1.1991 -0.3434,-2.1006 -1.0299,-2.7047 -0.6773,-0.6133 -1.6841,-0.9198 -3.0205,-0.9198z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="11.0688"
|
||||
android:fillColor="@color/control_primary"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue