Repository: mariotaku/ihsplay Branch: main Commit: 3b382603a123 Files: 150 Total size: 351.1 KB Directory structure: gitextract_wabvwvnr/ ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ └── feature_request.md │ └── workflows/ │ ├── build-test.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── .run/ │ └── ihsplay.run.xml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── app/ │ ├── .gitignore │ ├── CMakeLists.txt │ ├── app.c │ ├── app.h │ ├── app_events.c │ ├── app_gamepad.c │ ├── backend/ │ │ ├── CMakeLists.txt │ │ ├── host_manager.c │ │ ├── host_manager.h │ │ ├── input_manager.c │ │ ├── input_manager.h │ │ ├── stream/ │ │ │ ├── CMakeLists.txt │ │ │ ├── stream_input.c │ │ │ ├── stream_input.h │ │ │ ├── stream_manager.c │ │ │ ├── stream_manager.h │ │ │ ├── stream_manager_internal.h │ │ │ ├── stream_media.c │ │ │ └── stream_media.h │ │ └── stream_manager.h │ ├── config.h.in │ ├── lvgl/ │ │ ├── CMakeLists.txt │ │ ├── display.c │ │ ├── display.h │ │ ├── ext/ │ │ │ ├── CMakeLists.txt │ │ │ ├── lv_child_group.c │ │ │ ├── lv_child_group.h │ │ │ ├── lv_dir_focus.c │ │ │ ├── lv_dir_focus.h │ │ │ ├── msgbox_ext.c │ │ │ └── msgbox_ext.h │ │ ├── fonts/ │ │ │ └── bootstrap-icons/ │ │ │ ├── regular.h │ │ │ └── symbols.h │ │ ├── keypad.c │ │ ├── keypad.h │ │ ├── lv_conf.h │ │ ├── mouse.c │ │ ├── mouse.h │ │ ├── theme.c │ │ └── theme.h │ ├── main.c │ ├── platform/ │ │ ├── CMakeLists.txt │ │ ├── common/ │ │ │ ├── CMakeLists.txt │ │ │ ├── app_common.c │ │ │ └── client_info_common.c │ │ └── webos/ │ │ ├── CMakeLists.txt │ │ ├── app_webos.c │ │ └── client_info_webos.c │ ├── settings/ │ │ ├── CMakeLists.txt │ │ ├── app_settings.h │ │ └── settings.c │ ├── ui/ │ │ ├── CMakeLists.txt │ │ ├── app_ui.c │ │ ├── app_ui.h │ │ ├── app_ui_font.c │ │ ├── app_ui_font.h │ │ ├── common/ │ │ │ ├── CMakeLists.txt │ │ │ ├── error_messages.c │ │ │ ├── error_messages.h │ │ │ ├── group_utils.c │ │ │ ├── group_utils.h │ │ │ ├── progress_dialog.c │ │ │ └── progress_dialog.h │ │ ├── connection/ │ │ │ ├── CMakeLists.txt │ │ │ ├── conn_error_fragment.c │ │ │ ├── conn_error_fragment.h │ │ │ ├── connection_fragment.c │ │ │ ├── connection_fragment.h │ │ │ ├── pin_fragment.c │ │ │ └── pin_fragment.h │ │ ├── hosts/ │ │ │ ├── hosts_fragment.c │ │ │ └── hosts_fragment.h │ │ ├── launcher.c │ │ ├── launcher.h │ │ ├── session/ │ │ │ ├── CMakeLists.txt │ │ │ ├── connection_progress.c │ │ │ ├── connection_progress.h │ │ │ ├── session.c │ │ │ ├── session.h │ │ │ ├── streaming_overlay.c │ │ │ └── streaming_overlay.h │ │ ├── settings/ │ │ │ ├── basic.c │ │ │ ├── basic.h │ │ │ ├── settings.c │ │ │ ├── settings.h │ │ │ ├── widgets.c │ │ │ └── widgets.h │ │ └── support/ │ │ ├── CMakeLists.txt │ │ ├── feedback.c │ │ ├── feedback.h │ │ ├── support.c │ │ ├── support.h │ │ ├── wiki.c │ │ └── wiki.h │ └── util/ │ ├── CMakeLists.txt │ ├── client_info.c │ ├── client_info.h │ ├── listeners_list.c │ ├── listeners_list.h │ ├── random.c │ ├── random.h │ ├── refcounter.h │ └── video/ │ ├── CMakeLists.txt │ └── sps/ │ ├── CMakeLists.txt │ ├── bitstream.c │ ├── bitstream.h │ ├── common.c │ ├── common.h │ ├── include/ │ │ └── sps_util.h │ ├── sps_util_h264.c │ ├── sps_util_h265.c │ └── tests/ │ ├── CMakeLists.txt │ ├── sample_data.h │ ├── sps_parser_tests.c │ ├── test_dimension_h265.c │ └── test_nal_start_code.c ├── cmake/ │ ├── AresPackage.cmake │ ├── CleanupNameLink.cmake │ ├── PackageDebian.cmake │ └── PackageWebOS.cmake ├── deploy/ │ ├── raspbian/ │ │ └── sysroot-packages.list │ └── webos/ │ └── appinfo.in.json ├── tests/ │ ├── CMakeLists.txt │ └── app/ │ ├── CMakeLists.txt │ └── utils/ │ └── CMakeLists.txt └── tools/ ├── resource-tools/ │ ├── .gitignore │ ├── .nvmrc │ ├── async-transform.ts │ ├── binheader.ts │ ├── codepoints.ts │ ├── gulp-subset-font.ts │ ├── gulpfile.ts │ ├── package.json │ ├── res/ │ │ ├── bootstrap-icons.json │ │ └── bootstrap-icons.list │ ├── symheader.ts │ └── tsconfig.json └── webos/ ├── easy_build.sh └── easy_install.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: [mariotaku] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help us improve title: "[BUG]" labels: '' assignees: '' --- ## Issue Summary A clear and concise description of what the bug is. ## Steps to Reproduce Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Select '....' 4. See error ## Expected Behavior A clear and concise description of what you expected to happen. ## Basic Information ### IHSplay Information ### Computer Setup ## Additional Context Add any other context about the problem here. For example error message on the screen, and settings in IHSplay ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea for this project title: '' labels: '' assignees: '' --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/workflows/build-test.yml ================================================ name: Build Test on: push: # Don't run for tags tags-ignore: - '**' branches: - '**' env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release jobs: build-webos: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive - name: Download ares-cli-rs uses: robinraju/release-downloader@v1.9 with: repository: "webosbrew/ares-cli-rs" latest: true fileName: "ares-package_*.deb" out-file-path: "temp" - name: Download Homebrew Toolbox uses: robinraju/release-downloader@v1.9 with: repository: "webosbrew/dev-toolbox-cli" latest: true fileName: "webosbrew-toolbox-*.deb" out-file-path: "temp" - name: Install Tools run: sudo apt-get install ./temp/*.deb - name: Download webOS NDK uses: robinraju/release-downloader@v1.9 with: repository: "openlgtv/buildroot-nc4" latest: true fileName: "arm-webos-linux-gnueabi_sdk-buildroot.tar.gz" out-file-path: "/tmp" - name: Extract webOS NDK shell: bash working-directory: /tmp run: | tar xzf arm-webos-linux-gnueabi_sdk-buildroot.tar.gz ./arm-webos-linux-gnueabi_sdk-buildroot/relocate-sdk.sh - name: Build env: TOOLCHAIN_FILE: /tmp/arm-webos-linux-gnueabi_sdk-buildroot/usr/share/buildroot/toolchainfile.cmake run: ./tools/webos/easy_build.sh -DCMAKE_BUILD_TYPE=$BUILD_TYPE - name: Add Commit Hash Suffix shell: bash working-directory: dist run: for file in *.ipk ; do mv $file ${file//_arm/-${GITHUB_SHA:0:8}_arm} ; done - uses: actions/upload-artifact@v4 with: name: webos-snapshot path: dist/*.ipk - name: Compatibility Check run: webosbrew-ipk-verify -f markdown -d -o $GITHUB_STEP_SUMMARY dist/*.ipk build-raspi: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Run apt-get update shell: bash run: sudo apt-get -y -qq update - name: Prepare Sysroot id: pi-sysroot uses: mariotaku/raspbian-sysroot-action@v1.2 with: release: bullseye packages: ${{github.workspace}}/deploy/raspbian/sysroot-packages.list - name: Install Build Tools shell: bash # apt-get update was implicitly called, so we don't have to call it here run: sudo apt-get -y -qq install crossbuild-essential-armhf cmake - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory # We'll use this as our working directory for all subsequent commands run: cmake -E make_directory ${{github.workspace}}/build - name: Configure CMake # Use a bash shell, so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash working-directory: ${{github.workspace}}/build # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the GitHub Actions machines are (as of this writing) 3.12 run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTARGET_RASPI=ON -DCMAKE_TOOLCHAIN_FILE=${{steps.pi-sysroot.outputs.cmake-toolchain}} - name: Build working-directory: ${{github.workspace}}/build shell: bash # Execute the build. You can specify a specific target with "--target " run: | cmake --build . --config $BUILD_TYPE ================================================ FILE: .github/workflows/release.yml ================================================ name: Release on: release: types: [ created ] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Debug jobs: build-webos: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Download ares-cli-rs uses: robinraju/release-downloader@v1.9 with: repository: "webosbrew/ares-cli-rs" latest: true fileName: "ares-package_*.deb" out-file-path: "temp" - name: Download Homebrew Toolbox uses: robinraju/release-downloader@v1.9 with: repository: "webosbrew/dev-toolbox-cli" latest: true fileName: "webosbrew-toolbox-gen-manifest_*.deb" out-file-path: "temp" - name: Install Tools run: sudo apt-get install ./temp/*.deb - name: Download webOS NDK uses: robinraju/release-downloader@v1.9 with: repository: "openlgtv/buildroot-nc4" latest: true fileName: "arm-webos-linux-gnueabi_sdk-buildroot.tar.gz" out-file-path: "/tmp" - name: Extract webOS NDK shell: bash working-directory: /tmp run: | tar xzf arm-webos-linux-gnueabi_sdk-buildroot.tar.gz ./arm-webos-linux-gnueabi_sdk-buildroot/relocate-sdk.sh - name: Build env: TOOLCHAIN_FILE: /tmp/arm-webos-linux-gnueabi_sdk-buildroot/usr/share/buildroot/toolchainfile.cmake run: ./tools/webos/easy_build.sh -DCMAKE_BUILD_TYPE=$BUILD_TYPE - name: Create Release (webOS) id: create_release_webos uses: ncipollo/release-action@v1.14.0 with: token: ${{ secrets.GITHUB_TOKEN }} name: Release ${{ steps.tagName.outputs.tag }} allowUpdates: true omitNameDuringUpdate: true omitBodyDuringUpdate: true omitPrereleaseDuringUpdate: true artifacts: dist/*.ipk,dist/*.manifest.json ================================================ FILE: .gitignore ================================================ ### C++ template # Prerequisites *.d # Compiled Object files *.slo *.lo *.o *.obj # Precompiled Headers *.gch *.pch # Compiled Dynamic libraries *.so *.dylib *.dll # Fortran module files *.mod *.smod # Compiled Static libraries *.lai *.la *.a *.lib # Executables *.exe *.out *.app ### C template # Prerequisites # Object files *.ko *.elf # Linker output *.ilk *.map *.exp # Precompiled Headers # Libraries # Shared objects (inc. Windows DLLs) *.so.* # Executables *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd .tmp_versions/ modules.order Module.symvers Mkfile.old dkms.conf # Everything under .idea directory .idea/ ### CMake template CMakeLists.txt.user CMakeCache.txt CMakeFiles CMakeScripts Testing Makefile cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake _deps build/ dist/ ================================================ FILE: .gitmodules ================================================ [submodule "third_party/lvgl"] path = third_party/lvgl url = https://github.com/lvgl/lvgl.git [submodule "third_party/ihslib"] path = core url = https://github.com/mariotaku/ihslib.git [submodule "cmake/sanitizers"] path = cmake/sanitizers url = https://github.com/arsenm/sanitizers-cmake.git [submodule "third_party/ss4s"] path = third_party/ss4s url = https://github.com/mariotaku/ss4s.git [submodule "third_party/commons"] path = third_party/commons url = https://github.com/mariotaku/commons-c.git ================================================ FILE: .run/ihsplay.run.xml ================================================ ================================================ FILE: CMakeLists.txt ================================================ cmake_minimum_required(VERSION 3.16) execute_process(COMMAND git describe --tags --abbrev=0 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE IHSPLAY_VERSION ERROR_QUIET) if (IHSPLAY_VERSION) string(STRIP "${IHSPLAY_VERSION}" IHSPLAY_VERSION) string(SUBSTRING "${IHSPLAY_VERSION}" 1 -1 IHSPLAY_VERSION) else () set(IHSPLAY_VERSION "0.0.0") endif () project(ihsplay VERSION ${IHSPLAY_VERSION} LANGUAGES C) # To suppress warnings for MbedTLS if (POLICY CMP0048) cmake_policy(SET CMP0048 NEW) endif () # To suppress warnings for ExternalProject DOWNLOAD_EXTRACT_TIMESTAMP if (POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif () enable_testing() # Somehow the directory containing FindMbedTLS.cmake must be in the first place list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/core/scripts ${CMAKE_SOURCE_DIR}/third_party/commons/cmake ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/sanitizers/cmake) option(IHSPLAY_WIP_FEATURES "Enable Work-in-Progress Features" OFF) option(IHSPLAY_FEATURE_FORCE_FULLSCREEN "Force full screen mode" OFF) set(IHSPLAY_FEATURE_LIBCEC ON) option(COMMONS_LV_SDL_IMG_USE_IMAGE "Don't use SDL_Image" OFF) set(COMMONS_LOGGING_SDL ON) set(COMMONS_LOGGING_LVGL ON) set(COMMONS_LOGGING_SS4S ON) get_filename_component(CMAKE_C_COMPILER_NAME "${CMAKE_C_COMPILER}" NAME) if (CMAKE_C_COMPILER_NAME MATCHES "^arm-webos-linux-gnueabi-") set(TARGET_WEBOS TRUE) endif () # Use `pkg-config` to link needed libraries. find_package(PkgConfig REQUIRED) find_package(Freetype REQUIRED) find_package(Fontconfig REQUIRED) find_package(MbedTLS) # Use SDL2 for window creation and event handling. if (TARGET_WEBOS) set(CMAKE_INSTALL_LIBDIR lib/backports) set(SDL2_BACKPORT_REVISION "webOS-2.30.x") include(ExternalSDL2BackportForWebOS) unset(CMAKE_INSTALL_LIBDIR) else () pkg_check_modules(SDL2 REQUIRED sdl2>=2.0.14) endif() pkg_check_modules(PROTOBUF_C libprotobuf-c) pkg_check_modules(OPUS opus) if (NOT PROTOBUF_C_FOUND) list(APPEND CMAKE_MESSAGE_INDENT " ") message(STATUS "Including protobuf-c from source...") include(ExternalProtobufC) list(POP_BACK CMAKE_MESSAGE_INDENT) endif () if (NOT OPUS_FOUND) list(APPEND CMAKE_MESSAGE_INDENT " ") message(STATUS "Including opus from source...") include(ExternalOPUS) list(POP_BACK CMAKE_MESSAGE_INDENT) endif () if (NOT MBEDTLS_FOUND) list(APPEND CMAKE_MESSAGE_INDENT " ") message(STATUS "Including mbedtls from source...") include(ExternalMbedTLS) list(POP_BACK CMAKE_MESSAGE_INDENT) endif () if (TARGET_WEBOS) # set(IHSLIB_SDL_TARGETVERSION "2.28.0") set(SS4S_MODULE_DISABLE_MMAL ON) endif () add_subdirectory(core) add_subdirectory(third_party/lvgl EXCLUDE_FROM_ALL) target_include_directories(lvgl SYSTEM PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(lvgl SYSTEM PRIVATE ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(lvgl PRIVATE ${SDL2_LIBRARIES} ${FREETYPE_LIBRARIES}) target_compile_definitions(lvgl PUBLIC LV_CONF_PATH=../../../app/lvgl/lv_conf.h) add_subdirectory(third_party/ss4s) add_subdirectory(third_party/commons) set(CMAKE_C_STANDARD 11) add_subdirectory(app) target_include_directories(ihsplay PRIVATE app) target_link_libraries(ihsplay PRIVATE lvgl ihslib ihslib-hid-sdl ss4s commons-array-list commons-os-info commons-logging commons-ss4s-modules-list) target_link_libraries(ihsplay PRIVATE lv_gridview) get_target_property(SS4S_MODULE_LIBRARY_OUTPUT_DIRECTORY ss4s SS4S_MODULE_LIBRARY_OUTPUT_DIRECTORY) target_include_directories(ihsplay SYSTEM PRIVATE ${SDL2_INCLUDE_DIRS} ${OPUS_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS}) target_link_libraries(ihsplay PRIVATE ${SDL2_LIBRARIES} ${OPUS_LIBRARIES} Fontconfig::Fontconfig Freetype::Freetype ${MBEDCRYPTO_LIBRARY}) if (TARGET_WEBOS) set(IHSPLAY_FEATURE_LIBCEC OFF) set(IHSPLAY_FEATURE_FORCE_FULLSCREEN ON) target_link_libraries(ihsplay PRIVATE commons-luna-sync) set_target_properties(ihsplay PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH_USE_LINK_PATH TRUE INSTALL_RPATH "$ORIGIN/lib/backports:$ORIGIN") include(PackageWebOS) else () set(CMAKE_INSTALL_PREFIX /usr) include(GNUInstallDirs) endif () if (IHSPLAY_FEATURE_LIBCEC AND TARGET commons-cec-sdl) target_link_libraries(ihsplay PRIVATE commons-cec-sdl) else () set(IHSPLAY_FEATURE_LIBCEC OFF) endif () if (IHSPLAY_SANITIZE_ADDRESS) target_compile_options(ihsplay PRIVATE -fsanitize=address) target_link_options(ihsplay PRIVATE -fsanitize=address) target_link_libraries(ihsplay PRIVATE asan) endif () if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(IHSPLAY_IS_DEBUG ON) endif () configure_file(app/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) target_include_directories(ihsplay PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(tests) ================================================ FILE: LICENSE ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble 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, 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. 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 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. 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. 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. 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. 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. TERMS AND CONDITIONS 0. Definitions. "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. "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. 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 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 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 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 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 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 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 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: {project} Copyright (C) {year} {fullname} 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 GPL, see . 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 . ================================================ FILE: README.md ================================================ ``` ______ _______ __ / _/ / / / ___/____ / /___ ___ __ In-Home / // /_/ /\__ \/ __ \/ / __ `/ / / / Streaming _/ // __ /___/ / /_/ / / /_/ / /_/ / Player /___/_/ /_//____/ .___/_/\__,_/\__, / For Steam /_/ /____/ ``` IHSplay is an SDL2 based Steam Link Client, primarily targeting webOS TV and Raspberry Pi. The application will be providing a TV remote / gamepad friendly UI, and low latency video / audio output, as well as generic mouse / keyboard / gamepad support. --- ![Home UI](https://user-images.githubusercontent.com/830358/219081008-e5eb646a-76fa-4683-9869-35e3923618ce.png) ![Streaming Overlay](https://user-images.githubusercontent.com/830358/207047480-8cc96496-4fab-4a0e-8d1a-896183c54a6e.png) Stay tuned! ================================================ FILE: app/.gitignore ================================================ ./config.h ================================================ FILE: app/CMakeLists.txt ================================================ add_executable(ihsplay main.c app.c app_events.c app_gamepad.c ) add_subdirectory(settings) add_subdirectory(backend) add_subdirectory(lvgl) add_subdirectory(ui) add_subdirectory(util) add_subdirectory(platform) ================================================ FILE: app/app.c ================================================ #include #include #include "app.h" #include "ui/app_ui.h" #include "backend/host_manager.h" #include "backend/stream_manager.h" #include "backend/input_manager.h" #include "util/client_info.h" app_t *app_create(app_settings_t *settings, void *disp) { assert(settings != NULL); assert(disp != NULL); app_t *app = calloc(1, sizeof(app_t)); app->settings = settings; app->main_thread_id = SDL_ThreadID(); app->running = true; bool client_info_loaded = client_info_load(&app->client_info); assert(client_info_loaded); app->input_manager = input_manager_create(); app->host_manager = host_manager_create(app); app->stream_manager = stream_manager_create(app); app->ui = app_ui_create(app, (lv_disp_t *) disp); app_ui_created(app->ui); return app; } void app_destroy(app_t *app) { app_ui_destroy(app->ui); stream_manager_destroy(app->stream_manager); host_manager_destroy(app->host_manager); input_manager_destroy(app->input_manager); client_info_clear(&app->client_info); free(app); } void app_quit(app_t *app) { stream_manager_stop_active(app->stream_manager); app->running = false; } void app_assert_main_thread(app_t *app) { assert(app->main_thread_id == SDL_ThreadID()); } ================================================ FILE: app/app.h ================================================ #pragma once #include #include #include "ihslib.h" #include "ss4s.h" #include "settings/app_settings.h" #include "util/client_info.h" #include "os_info.h" typedef struct app_ui_t app_ui_t; typedef struct stream_manager_t stream_manager_t; typedef struct host_manager_t host_manager_t; typedef struct input_manager_t input_manager_t; typedef struct app_t { bool running; SDL_threadID main_thread_id; app_ui_t *ui; app_settings_t *settings; client_info_t client_info; os_info_t os_info; host_manager_t *host_manager; stream_manager_t *stream_manager; input_manager_t *input_manager; } app_t; typedef enum app_event_type_t { APP_EVENT_BEGIN = SDL_USEREVENT, APP_RUN_ON_MAIN, APP_UI_EVENT_BEGIN, APP_UI_NAV_QUIT, APP_UI_NAV_BACK, APP_UI_REQUEST_OVERLAY, APP_UI_CLOSE_OVERLAY, APP_UI_GAMEPAD_DEVICE_CHANGED, APP_UI_EVENT_LAST, APP_EVENT_LAST, } app_event_type_t; typedef void(*app_run_action_fn)(app_t *, void *); void app_preinit(int argc, char *argv[]); app_t *app_create(app_settings_t *settings, void *disp); void app_destroy(app_t *app); void app_quit(app_t *app); void app_post_event(app_t *app, app_event_type_t type, void *data1, void *data2); void app_run_on_main(app_t *app, app_run_action_fn action, void *data); void app_run_on_main_sync(app_t *app, app_run_action_fn action, void *data); void app_sdl_input_event(app_t *app, const SDL_Event *event); void app_assert_main_thread(app_t *app); void app_ihs_log(IHS_LogLevel level, const char *tag, const char *message); ================================================ FILE: app/app_events.c ================================================ #include "app.h" typedef struct bus_blocking_action_t { app_run_action_fn action; void *data; SDL_mutex *mutex; SDL_cond *cond; bool done; } bus_action_sync_t; static void invoke_action_sync(app_t *app, void *data); void app_post_event(app_t *app, app_event_type_t type, void *data1, void *data2) { (void) app; SDL_Event event; event.user.type = type; event.user.data1 = data1; event.user.data2 = data2; SDL_PushEvent(&event); } void app_run_on_main(app_t *app, app_run_action_fn action, void *data) { (void) app; app_post_event(app, APP_RUN_ON_MAIN, action, data); } void app_run_on_main_sync(app_t *app, app_run_action_fn action, void *data) { bus_action_sync_t sync = { .action = action, .data = data, .mutex = SDL_CreateMutex(), .cond = SDL_CreateCond(), .done = false, }; app_run_on_main(app, invoke_action_sync, &sync); SDL_LockMutex(sync.mutex); while (!sync.done) { SDL_CondWait(sync.cond, sync.mutex); } SDL_UnlockMutex(sync.mutex); SDL_DestroyMutex(sync.mutex); SDL_DestroyCond(sync.cond); } static void invoke_action_sync(app_t *app, void *data) { (void) app; bus_action_sync_t *sync = data; SDL_LockMutex(sync->mutex); sync->action(app, sync->data); sync->done = true; SDL_CondSignal(sync->cond); SDL_UnlockMutex(sync->mutex); } ================================================ FILE: app/app_gamepad.c ================================================ #include "ui/app_ui.h" #include "lvgl/keypad.h" #include "app.h" #include "backend/input_manager.h" void app_sdl_input_event(app_t *app, const SDL_Event *event) { switch (event->type) { case SDL_CONTROLLERDEVICEADDED: { input_manager_sdl_gamepad_added(app->input_manager, event->cdevice.which); app_post_event(app, APP_UI_GAMEPAD_DEVICE_CHANGED, NULL, NULL); break; } case SDL_CONTROLLERDEVICEREMOVED: { input_manager_sdl_gamepad_removed(app->input_manager, event->cdevice.which); app_post_event(app, APP_UI_GAMEPAD_DEVICE_CHANGED, NULL, NULL); break; } case SDL_KEYUP: case SDL_KEYDOWN: { app_indev_keypad_sdl_key_event(app->ui->indev.keypad, &event->key); break; } case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONDOWN: { app_indev_keypad_sdl_cbutton_event(app->ui->indev.keypad, &event->cbutton); break; } } } ================================================ FILE: app/backend/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE host_manager.c input_manager.c) add_subdirectory(stream) ================================================ FILE: app/backend/host_manager.c ================================================ #include #include "app.h" #include "host_manager.h" #include "array_list.h" #include "util/refcounter.h" #include "util/listeners_list.h" #include "ui/common/error_messages.h" #include "logging.h" struct host_manager_t { app_t *app; IHS_Client *client; SDL_TimerID timer; array_list_t *hosts; array_list_t *listeners; }; typedef struct host_manager_session_error_t { IHS_HostInfo host; uint32_t result; } host_manager_enum_error_t; typedef struct host_manager_authorization_result_t { IHS_HostInfo host; uint64_t steam_id; } host_manager_authorization_result_t; typedef struct host_manager_streaming_result_t { IHS_HostInfo host; IHS_SessionInfo session; } host_manager_streaming_result_t; static void client_host_discovered(IHS_Client *client, const IHS_HostInfo *host, void *context); static void client_authorization_success(IHS_Client *client, const IHS_HostInfo *host, uint64_t steamId, void *context); static void client_authorization_failed(IHS_Client *client, const IHS_HostInfo *host, IHS_AuthorizationResult result, void *context); static void client_streaming_success(IHS_Client *client, const IHS_HostInfo *host, const IHS_SocketAddress *address, const uint8_t *sessionKey, size_t sessionKeyLen, void *context); static void client_streaming_failed(IHS_Client *client, const IHS_HostInfo *host, IHS_StreamingResult result, void *context); static void client_host_discovered_main(app_t *app, void *data); static void client_streaming_success_main(app_t *app, void *data); static void client_streaming_failed_main(app_t *app, void *data); static void client_authorization_success_main(app_t *app, void *data); static void client_authorization_failed_main(app_t *app, void *data); static int compare_host_name(const void *a, const void *b); static const IHS_ClientDiscoveryCallbacks discovery_callbacks = { .discovered = client_host_discovered, }; static const IHS_ClientAuthorizationCallbacks authorization_callbacks = { .success = client_authorization_success, .failed = client_authorization_failed, }; static const IHS_ClientStreamingCallbacks streaming_callbacks = { .success = client_streaming_success, .failed = client_streaming_failed, }; host_manager_t *host_manager_create(app_t *app) { host_manager_t *manager = SDL_calloc(1, sizeof(host_manager_t)); manager->app = app; manager->client = IHS_ClientCreate(&app->client_info.config); manager->hosts = array_list_create(sizeof(IHS_HostInfo), 16); manager->listeners = listeners_list_create(); IHS_ClientSetLogFunction(manager->client, app_ihs_log); IHS_ClientSetDiscoveryCallbacks(manager->client, &discovery_callbacks, manager); IHS_ClientSetAuthorizationCallbacks(manager->client, &authorization_callbacks, manager); IHS_ClientSetStreamingCallbacks(manager->client, &streaming_callbacks, manager); return manager; } void host_manager_destroy(host_manager_t *manager) { IHS_ClientStop(manager->client); IHS_ClientThreadedJoin(manager->client); IHS_ClientDestroy(manager->client); listeners_list_destroy(manager->listeners); array_list_destroy(manager->hosts); SDL_free(manager); } void host_manager_discovery_start(host_manager_t *manager) { IHS_ClientStartDiscovery(manager->client, 10000); } void host_manager_discovery_stop(host_manager_t *manager) { IHS_ClientStopDiscovery(manager->client); } array_list_t *host_manager_get_hosts(host_manager_t *manager) { return manager->hosts; } void host_manager_session_request(host_manager_t *manager, const IHS_HostInfo *host) { IHS_StreamingRequest request = { .audioChannelCount = 2, .streamingEnable.audio = true, .streamingEnable.video = true, .streamingEnable.input = true, .maxResolution.x = 1920, .maxResolution.y = 1080, }; IHS_ClientStreamingRequest(manager->client, host, &request); } void host_manager_register_listener(host_manager_t *manager, const host_manager_listener_t *listener, void *context) { listeners_list_add(manager->listeners, listener, context); } void host_manager_unregister_listener(host_manager_t *manager, const host_manager_listener_t *listener) { listeners_list_remove(manager->listeners, listener); } void host_manager_authorization_request(host_manager_t *manager, const IHS_HostInfo *host, const char *pin) { IHS_ClientAuthorizationRequest(manager->client, host, pin); } bool host_manager_authorization_cancel(host_manager_t *manager) { return IHS_ClientAuthorizationCancel(manager->client); } static void client_host_discovered(IHS_Client *client, const IHS_HostInfo *host, void *context) { (void) client; host_manager_t *manager = context; IHS_HostInfo *host_copy = SDL_calloc(1, sizeof(IHS_HostInfo)); *host_copy = *host; app_run_on_main(manager->app, client_host_discovered_main, host_copy); } static void client_authorization_success(IHS_Client *client, const IHS_HostInfo *host, uint64_t steamId, void *context) { (void) client; host_manager_t *manager = context; host_manager_authorization_result_t *result = SDL_calloc(1, sizeof(host_manager_authorization_result_t)); result->host = *host; result->steam_id = steamId; app_run_on_main(manager->app, client_authorization_success_main, result); } static void client_authorization_failed(IHS_Client *client, const IHS_HostInfo *host, IHS_AuthorizationResult result, void *context) { (void) client; host_manager_t *manager = context; commons_log_error("Client", "Authorization failed: %u", result); host_manager_enum_error_t *error = SDL_calloc(1, sizeof(host_manager_enum_error_t)); error->host = *host; error->result = result; app_run_on_main(manager->app, client_authorization_failed_main, error); } static void client_streaming_success(IHS_Client *client, const IHS_HostInfo *host, const IHS_SocketAddress *address, const uint8_t *sessionKey, size_t sessionKeyLen, void *context) { (void) client; host_manager_t *manager = context; host_manager_streaming_result_t *result = SDL_calloc(1, sizeof(host_manager_streaming_result_t)); result->host = *host; result->session.address = *address; SDL_memcpy(result->session.sessionKey, sessionKey, sessionKeyLen); result->session.sessionKeyLen = sessionKeyLen; app_run_on_main(manager->app, client_streaming_success_main, result); } static void client_streaming_failed(IHS_Client *client, const IHS_HostInfo *host, IHS_StreamingResult result, void *context) { (void) client; host_manager_t *manager = context; commons_log_error("Client", "Failed to start streaming: %s", streaming_result_str(result)); host_manager_enum_error_t *error = SDL_calloc(1, sizeof(host_manager_enum_error_t)); error->host = *host; error->result = result; app_run_on_main(manager->app, client_streaming_failed_main, error); } static void client_host_discovered_main(app_t *app, void *data) { host_manager_t *manager = app->host_manager; IHS_HostInfo *host = data; IHS_HostInfo *info = NULL; array_list_t *hosts = manager->hosts; int insert_index = -1, update_index = -1; int old_size = array_list_size(hosts); for (int i = 0, j = old_size; i < j; ++i) { IHS_HostInfo *item = array_list_get(hosts, i); if (item->clientId == host->clientId) { info = item; update_index = i; break; } else if (compare_host_name(item, host) > 0) { if (insert_index == -1) { insert_index = i; } } } host_manager_hosts_change change_type; int change_index; if (info == NULL) { commons_log_debug("Hosts", "New host discovered: %s", host->hostname); info = array_list_add(hosts, insert_index); change_type = HOST_MANAGER_HOSTS_NEW; change_index = insert_index < 0 ? old_size : insert_index; } else { change_type = HOST_MANAGER_HOSTS_UPDATE; assert(update_index >= 0); change_index = update_index; } assert(info != NULL); *info = *host; SDL_free(host); listeners_list_notify(manager->listeners, host_manager_listener_t, hosts_changed, hosts, change_type, change_index); } static void client_streaming_success_main(app_t *app, void *data) { host_manager_t *manager = app->host_manager; host_manager_streaming_result_t *result = data; listeners_list_notify(manager->listeners, host_manager_listener_t, session_started, &result->host, &result->session); SDL_free(result); } static void client_streaming_failed_main(app_t *app, void *data) { host_manager_t *manager = app->host_manager; host_manager_enum_error_t *error = data; listeners_list_notify(manager->listeners, host_manager_listener_t, session_start_failed, &error->host, error->result); SDL_free(error); } static void client_authorization_success_main(app_t *app, void *data) { host_manager_t *manager = app->host_manager; host_manager_authorization_result_t *result = data; listeners_list_notify(manager->listeners, host_manager_listener_t, authorized, &result->host, result->steam_id); SDL_free(result); } static void client_authorization_failed_main(app_t *app, void *data) { host_manager_t *manager = app->host_manager; host_manager_enum_error_t *error = data; listeners_list_notify(manager->listeners, host_manager_listener_t, authorization_failed, &error->host, error->result); SDL_free(error); } static int compare_host_name(const void *a, const void *b) { const IHS_HostInfo *info1 = a; const IHS_HostInfo *info2 = b; return strncasecmp(info1->hostname, info2->hostname, 63); } ================================================ FILE: app/backend/host_manager.h ================================================ #pragma once #include typedef struct app_t app_t; typedef struct host_manager_t host_manager_t; typedef struct array_list_t array_list_t; typedef enum host_manager_hosts_change { HOST_MANAGER_HOSTS_NEW, HOST_MANAGER_HOSTS_UPDATE } host_manager_hosts_change; typedef struct host_manager_listener_t { void (*hosts_changed)(array_list_t *list, host_manager_hosts_change change, int index, void *context); void (*session_started)(const IHS_HostInfo *host, const IHS_SessionInfo *config, void *context); void (*session_start_failed)(const IHS_HostInfo *host, IHS_StreamingResult result, void *context); void (*authorized)(const IHS_HostInfo *host, uint64_t steam_id, void *context); void (*authorization_failed)(const IHS_HostInfo *host, IHS_AuthorizationResult result, void *context); } host_manager_listener_t; host_manager_t *host_manager_create(app_t *app); void host_manager_destroy(host_manager_t *manager); void host_manager_discovery_start(host_manager_t *manager); void host_manager_discovery_stop(host_manager_t *manager); array_list_t *host_manager_get_hosts(host_manager_t *manager); void host_manager_session_request(host_manager_t *manager, const IHS_HostInfo *host); void host_manager_register_listener(host_manager_t *manager, const host_manager_listener_t *listener, void *context); void host_manager_unregister_listener(host_manager_t *manager, const host_manager_listener_t *listener); void host_manager_authorization_request(host_manager_t *manager, const IHS_HostInfo *host, const char *pin); bool host_manager_authorization_cancel(host_manager_t *manager); ================================================ FILE: app/backend/input_manager.c ================================================ #include "logging.h" #include "input_manager.h" #include #include "ihslib/hid/sdl.h" static void insert_controller(input_manager_t *manager, SDL_JoystickID id, SDL_GameController *controller); static void remove_controller_at(input_manager_t *manager, size_t index); static int manager_index(const input_manager_t *manager, SDL_JoystickID id); static int js_count(void *context); static int js_index(SDL_JoystickID instance_id, void *context); static SDL_JoystickID js_instance_id(int index, void *context); static SDL_GameController *js_controller(int index, void *context); static int instance_id_compar(const void *id, const void *item); static const IHS_HIDProviderSDLDeviceList hid_device_list = { .count = js_count, .index = js_index, .instanceId = js_instance_id, .controller = js_controller, }; input_manager_t *input_manager_create() { input_manager_t *manager = calloc(1, sizeof(input_manager_t)); array_list_init(&manager->controllers, sizeof(opened_controller_t), 8); manager->hid_provider = IHS_HIDProviderSDLCreateUnmanaged(&hid_device_list, manager); return manager; } void input_manager_destroy(input_manager_t *manager) { IHS_HIDProviderSDLDestroy(manager->hid_provider); for (int i = 0, j = array_list_size(&manager->controllers); i < j; i++) { opened_controller_t *controller = array_list_get(&manager->controllers, i); SDL_GameControllerClose(controller->controller); } array_list_deinit(&manager->controllers); free(manager); } IHS_HIDProvider *input_manager_get_hid_provider(input_manager_t *manager) { return manager->hid_provider; } void input_manager_sdl_gamepad_added(input_manager_t *manager, int which) { SDL_GameController *controller = SDL_GameControllerOpen(which); if (controller == NULL) { commons_log_error("Input", "Failed to open gamepad #%d: %s", which, SDL_GetError()); return; } SDL_Joystick *joystick = SDL_GameControllerGetJoystick(controller); SDL_JoystickID id = SDL_JoystickInstanceID(joystick); insert_controller(manager, id, controller); commons_log_info("Input", "Gamepad #%d: %s added.", id, SDL_JoystickName(joystick)); } void input_manager_sdl_gamepad_removed(input_manager_t *manager, SDL_JoystickID which) { commons_log_info("Input", "Removing gamepad, instance_id: #%d.", which); int index = manager_index(manager, which); assert(index >= 0); opened_controller_t *controller = array_list_get(&manager->controllers, index); SDL_GameControllerClose(controller->controller); remove_controller_at(manager, index); commons_log_info("Input", "Gamepad #%d removed.", which); } size_t input_manager_sdl_gamepad_count(const input_manager_t *manager) { return array_list_size(&manager->controllers); } void input_manager_ignore_next_mouse_movement(input_manager_t *manager) { manager->ignore_next_mouse_movement = true; } bool input_manager_get_and_reset_mouse_movement(input_manager_t *manager) { bool ignore = manager->ignore_next_mouse_movement; manager->ignore_next_mouse_movement = false; return ignore; } static void insert_controller(input_manager_t *manager, SDL_JoystickID id, SDL_GameController *controller) { int insert_after; for (insert_after = (int) (array_list_size(&manager->controllers) - 1); insert_after >= 0; insert_after--) { opened_controller_t *item = array_list_get(&manager->controllers, insert_after); if (id >= item->id) { break; } } opened_controller_t *new_item = array_list_add(&manager->controllers, insert_after + 1); new_item->id = id; new_item->controller = controller; } static void remove_controller_at(input_manager_t *manager, size_t index) { array_list_remove(&manager->controllers, (int) index); } static int manager_index(const input_manager_t *manager, SDL_JoystickID id) { return array_list_bsearch(&manager->controllers, &id, instance_id_compar); } static int js_count(void *context) { input_manager_t *manager = context; return (int) array_list_size(&manager->controllers); } static int js_index(SDL_JoystickID instance_id, void *context) { input_manager_t *manager = context; for (int i = 0, j = array_list_size(&manager->controllers); i < j; i++) { opened_controller_t *item = array_list_get(&manager->controllers, i); if (item->id == instance_id) { return i; } } return -1; } static SDL_JoystickID js_instance_id(int index, void *context) { input_manager_t *manager = context; opened_controller_t *item = array_list_get(&manager->controllers, index); if (item == NULL) { return -1; } return item->id; } static SDL_GameController *js_controller(int index, void *context) { input_manager_t *manager = context; opened_controller_t *item = array_list_get(&manager->controllers, index); if (item == NULL) { return NULL; } return item->controller; } static int instance_id_compar(const void *id, const void *item) { return *((SDL_JoystickID *) id) - ((const opened_controller_t *) item)->id; } ================================================ FILE: app/backend/input_manager.h ================================================ #pragma once #include #include #include "ihslib/hid/sdl.h" #include "array_list.h" typedef struct opened_controller_t { SDL_GameController *controller; SDL_JoystickID id; } opened_controller_t; typedef struct input_manager_t { array_list_t controllers; IHS_HIDProvider *hid_provider; bool ignore_next_mouse_movement; } input_manager_t; input_manager_t *input_manager_create(); void input_manager_destroy(input_manager_t *manager); IHS_HIDProvider *input_manager_get_hid_provider(input_manager_t *manager); void input_manager_sdl_gamepad_added(input_manager_t *manager, int which); void input_manager_sdl_gamepad_removed(input_manager_t *manager, SDL_JoystickID which); size_t input_manager_sdl_gamepad_count(const input_manager_t *manager); /** * Tell the app to ignore next mouse movement, for manual moving the cursor position * @param manager */ void input_manager_ignore_next_mouse_movement(input_manager_t *manager); bool input_manager_get_and_reset_mouse_movement(input_manager_t *manager); ================================================ FILE: app/backend/stream/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE stream_manager.c stream_media.c stream_input.c) ================================================ FILE: app/backend/stream/stream_input.c ================================================ #include "app.h" #include "ui/app_ui.h" #include "stream_input.h" #include "stream_manager_internal.h" #include "backend/input_manager.h" bool stream_input_handle_key_event(stream_manager_t *manager, const SDL_KeyboardEvent *event) { #ifdef __WEBOS__ SDL_Keysym keysym = event->keysym; switch ((int) keysym.scancode) { case SDL_SCANCODE_WEBOS_EXIT: { if (event->state == SDL_RELEASED) { stream_manager_set_overlay_opened(manager, true); } return true; } case SDL_SCANCODE_WEBOS_BACK: { // TODO: Send ESC key return true; } } #endif if (event->keysym.sym == SDLK_ESCAPE) { if (event->state == SDL_RELEASED) { stream_manager_set_overlay_opened(manager, true); } return true; } if (!manager->app->settings->enable_input) { return true; } if (event->state == SDL_PRESSED) { IHS_SessionSendKeyDown(manager->session, event->keysym.scancode); } else { IHS_SessionSendKeyUp(manager->session, event->keysym.scancode); } return true; } bool stream_input_handle_mouse_event(stream_manager_t *manager, const SDL_Event *event) { if (!manager->app->settings->enable_input) { return true; } switch (event->type) { case SDL_MOUSEMOTION: { if (input_manager_get_and_reset_mouse_movement(manager->app->input_manager)) { break; } if (manager->app->settings->relmouse) { IHS_SessionSendMouseMovement(manager->session, event->motion.xrel, event->motion.yrel); } else { int w, h; SDL_GetWindowSize(manager->app->ui->window, &w, &h); IHS_SessionSendMousePosition(manager->session, (float) event->motion.x / (float) w, (float) event->motion.y / (float) h); } return true; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { IHS_StreamInputMouseButton button = 0; switch (event->button.button) { case SDL_BUTTON_LEFT: button = IHS_MOUSE_BUTTON_LEFT; break; case SDL_BUTTON_RIGHT: button = IHS_MOUSE_BUTTON_RIGHT; break; case SDL_BUTTON_MIDDLE: button = IHS_MOUSE_BUTTON_MIDDLE; break; case SDL_BUTTON_X1: button = IHS_MOUSE_BUTTON_X1; break; case SDL_BUTTON_X2: button = IHS_MOUSE_BUTTON_X2; break; } if (button != 0) { if (event->button.state == SDL_RELEASED) { IHS_SessionSendMouseUp(manager->session, button); } else { IHS_SessionSendMouseDown(manager->session, button); } } return true; } case SDL_MOUSEWHEEL: { Sint32 x = event->wheel.x, y = event->wheel.y; if (event->wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { x *= -1; y *= -1; } if (x != 0) { IHS_SessionSendMouseWheel(manager->session, x < 0 ? IHS_MOUSE_WHEEL_LEFT : IHS_MOUSE_WHEEL_RIGHT); } if (y != 0) { IHS_SessionSendMouseWheel(manager->session, y > 0 ? IHS_MOUSE_WHEEL_UP : IHS_MOUSE_WHEEL_DOWN); } return true; } } return false; } ================================================ FILE: app/backend/stream/stream_input.h ================================================ #pragma once #include "stream_manager.h" bool stream_input_handle_key_event(stream_manager_t *manager, const SDL_KeyboardEvent *event); bool stream_input_handle_mouse_event(stream_manager_t *manager, const SDL_Event *event); ================================================ FILE: app/backend/stream/stream_manager.c ================================================ #include #include "stream_manager.h" #include "stream_manager_internal.h" #include "app.h" #include "ui/app_ui.h" #include "util/listeners_list.h" #include "ihslib/hid/sdl.h" #include "ss4s.h" #include "stream_media.h" #include "stream_input.h" #include "backend/input_manager.h" #include "logging.h" static void session_initialized(IHS_Session *session, void *context); static void session_finalized(IHS_Session *session, void *context); static void session_configuring(IHS_Session *session, IHS_SessionConfig *config, void *context); static void session_connected(IHS_Session *session, void *context); static void session_disconnected(IHS_Session *session, void *context); static void session_show_cursor(IHS_Session *session, float x, float y, void *context); // Main thread callbacks static void session_connected_main(app_t *app, void *context); static void session_disconnected_main(app_t *app, void *context); static void session_show_cursor_main(app_t *app, void *context); static void destroy_session_main(app_t *app, void *context); static void controller_back_pressed(stream_manager_t *manager); static void controller_back_released(stream_manager_t *manager); static Uint32 back_timer_callback(Uint32 duration, void *param); static void back_timer_progress_main(app_t *app, void *context); static void back_timer_finish_main(app_t *app, void *context); static void grab_mouse(stream_manager_t *manager, bool grab); #define BACK_COUNTER_MAX 100 typedef struct event_context_t { stream_manager_t *manager; void *arg1; uint32_t value1; } event_context_t; static const IHS_StreamSessionCallbacks session_callbacks = { .initialized = session_initialized, .configuring = session_configuring, .connected = session_connected, .disconnected = session_disconnected, .finalized = session_finalized, }; static const IHS_StreamInputCallbacks input_callbacks = { .showCursor = session_show_cursor, // .hideCursor = session_hide_cursor, // .setCursor = session_set_cursor, // .cursorImage = session_cursor_image, }; stream_manager_t *stream_manager_create(app_t *app) { assert(app->input_manager != NULL); stream_manager_t *manager = calloc(1, sizeof(stream_manager_t)); manager->app = app; manager->listeners = listeners_list_create(); return manager; } void stream_manager_destroy(stream_manager_t *manager) { switch (manager->state) { case STREAM_MANAGER_STATE_IDLE: { break; } default: { destroy_session_main(manager->app, manager->session); break; } } listeners_list_destroy(manager->listeners); free(manager); } void stream_manager_register_listener(stream_manager_t *manager, const stream_manager_listener_t *listener, void *context) { listeners_list_add(manager->listeners, listener, context); } void stream_manager_unregister_listener(stream_manager_t *manager, const stream_manager_listener_t *listener) { listeners_list_remove(manager->listeners, listener); } bool stream_manager_start_session(stream_manager_t *manager, const IHS_SessionInfo *info) { app_assert_main_thread(manager->app); if (manager->state != STREAM_MANAGER_STATE_IDLE) { return false; } // Reset all states for last session manager->back_counter = 0; manager->back_timer = 0; manager->overlay_opened = false; manager->requested_disconnect = false; stream_media_session_t *media = stream_media_create(manager); manager->media = media; IHS_Session *session = IHS_SessionCreate(&manager->app->client_info.config, info); IHS_SessionSetLogFunction(session, app_ihs_log); IHS_SessionSetSessionCallbacks(session, &session_callbacks, manager); IHS_SessionSetInputCallbacks(session, &input_callbacks, manager); IHS_SessionSetAudioCallbacks(session, stream_media_audio_callbacks(), media); IHS_SessionSetVideoCallbacks(session, stream_media_video_callbacks(), media); IHS_SessionHIDAddProvider(session, input_manager_get_hid_provider(manager->app->input_manager)); manager->state = STREAM_MANAGER_STATE_CONNECTING; commons_log_info("StreamManager", "Change state to CONNECTING"); manager->session = session; stream_media_set_viewport_size(media, manager->viewport_width, manager->viewport_height); stream_media_set_overlay_height(media, manager->overlay_height); IHS_SessionConnect(session); return true; } IHS_Session *stream_manager_active_session(const stream_manager_t *manager) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return NULL; } return manager->session; } void stream_manager_stop_active(stream_manager_t *manager) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return; } manager->requested_disconnect = true; IHS_SessionDisconnect(manager->session); } bool stream_manager_intercept_event(const stream_manager_t *manager, const SDL_Event *event) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { // Ignore events when idle return false; } if (manager->overlay_opened) { // No input event should be handled when overlay opened return false; } switch (event->type) { // Following events MUST be handled by the app too case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMAPPED: return false; } return true; } void stream_manager_handle_event(stream_manager_t *manager, const SDL_Event *event) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return; } if (manager->overlay_opened) { switch (event->type) { // Following events be always handled by IHS, even with overlay opened case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMAPPED: break; default: return; } } switch (event->type) { case SDL_KEYDOWN: case SDL_KEYUP: { // Keyboard events stream_input_handle_key_event(manager, &event->key); break; } case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_MOUSEWHEEL: { stream_input_handle_mouse_event(manager, event); break; } case SDL_CONTROLLERBUTTONDOWN: { if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { controller_back_pressed(manager); } break; } case SDL_CONTROLLERBUTTONUP: { if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { controller_back_released(manager); } break; } } if (manager->app->settings->enable_input) { IHS_HIDHandleSDLEvent(manager->session, event); } } void stream_manager_set_viewport_size(stream_manager_t *manager, int width, int height) { manager->viewport_width = width; manager->viewport_height = height; if (manager->media != NULL) { stream_media_set_viewport_size(manager->media, width, height); } } bool stream_manager_is_overlay_opened(const stream_manager_t *manager) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return false; } return manager->overlay_opened; } void stream_manager_set_overlay_height(stream_manager_t *manager, int height) { manager->overlay_height = height; if (manager->media != NULL) { stream_media_set_overlay_height(manager->media, height); } } bool stream_manager_set_overlay_opened(stream_manager_t *manager, bool opened) { app_assert_main_thread(manager->app); if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return false; } manager->overlay_opened = opened; stream_media_set_overlay_shown(manager->media, opened); if (opened) { app_post_event(manager->app, APP_UI_REQUEST_OVERLAY, NULL, NULL); } else { app_post_event(manager->app, APP_UI_CLOSE_OVERLAY, NULL, NULL); } grab_mouse(manager, !opened); return true; } void stream_manager_set_capture_size(stream_manager_t *manager, int width, int height) { manager->capture_width = width; manager->capture_height = height; } bool stream_manager_is_active(const stream_manager_t *manager) { return manager->state == STREAM_MANAGER_STATE_STREAMING; } static void session_initialized(IHS_Session *session, void *context) { stream_manager_t *manager = (stream_manager_t *) context; assert (manager->state == STREAM_MANAGER_STATE_CONNECTING); IHS_SessionConnect(session); } static void session_finalized(IHS_Session *session, void *context) { stream_manager_t *manager = (stream_manager_t *) context; assert(manager->state == STREAM_MANAGER_STATE_DISCONNECTING); assert(manager->session == session); manager->state = STREAM_MANAGER_STATE_IDLE; commons_log_info("StreamManager", "Change state to IDLE"); app_run_on_main(manager->app, destroy_session_main, session); } static void session_configuring(IHS_Session *session, IHS_SessionConfig *config, void *context) { (void) session; stream_manager_t *manager = (stream_manager_t *) context; assert (manager->media != NULL); config->enableHevc = stream_media_supports_hevc(manager->media); } static void session_connected(IHS_Session *session, void *context) { stream_manager_t *manager = (stream_manager_t *) context; assert(manager->state == STREAM_MANAGER_STATE_CONNECTING); assert(manager->session == session); manager->state = STREAM_MANAGER_STATE_STREAMING; commons_log_info("StreamManager", "Change state to STREAMING"); event_context_t ec = { .manager = manager, .arg1 = (void *) IHS_SessionGetInfo(session), }; app_run_on_main_sync(manager->app, session_connected_main, &ec); if (manager->app->settings->enable_input) { IHS_SessionHIDNotifyDeviceChange(session); } } static void session_disconnected(IHS_Session *session, void *context) { stream_manager_t *manager = (stream_manager_t *) context; assert(manager->state != STREAM_MANAGER_STATE_DISCONNECTING); assert(manager->session == session); if (manager->back_timer != 0) { SDL_RemoveTimer(manager->back_timer); manager->back_timer = 0; } bool requested = manager->requested_disconnect; manager->state = STREAM_MANAGER_STATE_DISCONNECTING; commons_log_info("StreamManager", "Change state to DISCONNECTING"); event_context_t ec = { .manager = manager, .arg1 = (void *) IHS_SessionGetInfo(session), .value1 = requested }; app_run_on_main_sync(manager->app, session_disconnected_main, &ec); } static void session_show_cursor(IHS_Session *session, float x, float y, void *context) { (void) session; stream_manager_t *manager = (stream_manager_t *) context; if (manager->capture_width <= 0 && manager->capture_height <= 0 || manager->viewport_width <= 0 || manager->viewport_height <= 0) { return; } if (stream_manager_is_overlay_opened(manager)) { return; } float scale = SDL_min((float) manager->viewport_width / manager->capture_width, (float) manager->viewport_height / manager->capture_height); float dst_width = (float) manager->capture_width * scale, dst_height = (float) manager->capture_height * scale; SDL_Point *point = calloc(1, sizeof(SDL_Point)); point->x = (int) (((float) manager->viewport_width - dst_width) / 2.0f + dst_width * x); point->y = (int) (((float) manager->viewport_height - dst_height) / 2.0f + dst_height * y); app_run_on_main(manager->app, session_show_cursor_main, point); } static void session_connected_main(app_t *app, void *context) { (void) app; event_context_t *ec = context; stream_manager_t *manager = ec->manager; listeners_list_notify(manager->listeners, stream_manager_listener_t, connected, (const IHS_SessionInfo *) ec->arg1); grab_mouse(manager, true); } static void session_disconnected_main(app_t *app, void *context) { (void) app; event_context_t *ec = context; stream_manager_t *manager = ec->manager; grab_mouse(manager, false); listeners_list_notify(manager->listeners, stream_manager_listener_t, disconnected, (const IHS_SessionInfo *) ec->arg1, ec->value1); } static void session_show_cursor_main(app_t *app, void *context) { stream_manager_t *manager = app->stream_manager; SDL_Point *point = context; input_manager_ignore_next_mouse_movement(manager->app->input_manager); // SDL_WarpMouseInWindow(app->ui->window, point->x, point->y); free(context); } static void destroy_session_main(app_t *app, void *context) { (void) app; IHS_Session *session = context; IHS_SessionThreadedJoin(session); IHS_SessionDestroy(session); stream_media_destroy(app->stream_manager->media); app->stream_manager->media = NULL; } static void controller_back_pressed(stream_manager_t *manager) { if (manager->state != STREAM_MANAGER_STATE_STREAMING || manager->back_timer != 0) { return; } manager->back_counter = 0; manager->back_timer = SDL_AddTimer(300, back_timer_callback, manager); } static void controller_back_released(stream_manager_t *manager) { if (manager->state != STREAM_MANAGER_STATE_STREAMING || manager->back_timer == 0) { return; } SDL_RemoveTimer(manager->back_timer); manager->back_timer = 0; commons_log_info("Streaming", "Overlay timer cancelled"); // This function is expected to be called in main thread. app_assert_main_thread(manager->app); listeners_list_notify(manager->listeners, stream_manager_listener_t, overlay_progress_finished, false); } static void grab_mouse(stream_manager_t *manager, bool grab) { if (manager->state != STREAM_MANAGER_STATE_STREAMING) { SDL_SetRelativeMouseMode(SDL_FALSE); return; } SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE); } static Uint32 back_timer_callback(Uint32 duration, void *param) { (void) duration; stream_manager_t *manager = (stream_manager_t *) param; if (manager->state != STREAM_MANAGER_STATE_STREAMING) { return 0; } manager->back_counter += 1; if (manager->back_counter >= BACK_COUNTER_MAX) { manager->back_timer = 0; manager->back_counter = 0; IHS_HIDResetSDLGameControllers(manager->session); commons_log_info("Streaming", "Requesting overlay"); app_run_on_main(manager->app, back_timer_finish_main, manager); return 0; } else { app_run_on_main(manager->app, back_timer_progress_main, manager); } return 16; } static void back_timer_progress_main(app_t *app, void *context) { (void) app; stream_manager_t *manager = (stream_manager_t *) context; listeners_list_notify(manager->listeners, stream_manager_listener_t, overlay_progress, manager->back_counter); } static void back_timer_finish_main(app_t *app, void *context) { (void) app; stream_manager_t *manager = (stream_manager_t *) context; stream_manager_set_overlay_opened(manager, true); listeners_list_notify(manager->listeners, stream_manager_listener_t, overlay_progress_finished, true); } ================================================ FILE: app/backend/stream/stream_manager.h ================================================ #pragma once #include "ihslib.h" #include typedef struct app_t app_t; typedef struct host_manager_t host_manager_t; typedef struct stream_manager_t stream_manager_t; typedef struct stream_manager_callbacks_t { void (*connected)(const IHS_SessionInfo *info, void *context); void (*disconnected)(const IHS_SessionInfo *info, bool requested, void *context); void (*overlay_progress)(int percentage, void *context); void (*overlay_progress_finished)(bool requested, void *context); } stream_manager_listener_t; stream_manager_t *stream_manager_create(app_t *app); void stream_manager_destroy(stream_manager_t *manager); void stream_manager_register_listener(stream_manager_t *manager, const stream_manager_listener_t *listener, void *context); void stream_manager_unregister_listener(stream_manager_t *manager, const stream_manager_listener_t *listener); bool stream_manager_start_session(stream_manager_t *manager, const IHS_SessionInfo *info); IHS_Session *stream_manager_active_session(const stream_manager_t *manager); void stream_manager_stop_active(stream_manager_t *manager); /** * Check if an event should only be dispatched to stream manager. This method call should not change any state * @return true if the event should only be processed by this manager */ bool stream_manager_intercept_event(const stream_manager_t *manager, const SDL_Event *event); void stream_manager_handle_event(stream_manager_t *manager, const SDL_Event *event); void stream_manager_set_viewport_size(stream_manager_t *manager, int width, int height); bool stream_manager_is_overlay_opened(const stream_manager_t *manager); void stream_manager_set_overlay_height(stream_manager_t *manager, int height); bool stream_manager_set_overlay_opened(stream_manager_t *manager, bool opened); void stream_manager_set_capture_size(stream_manager_t *manager, int width, int height); bool stream_manager_is_active(const stream_manager_t *manager); ================================================ FILE: app/backend/stream/stream_manager_internal.h ================================================ #pragma once #include "stream_manager.h" #include "stream_media.h" #include "array_list.h" typedef enum stream_manager_state_t { STREAM_MANAGER_STATE_IDLE, STREAM_MANAGER_STATE_CONNECTING, STREAM_MANAGER_STATE_STREAMING, STREAM_MANAGER_STATE_DISCONNECTING, } stream_manager_state_t; struct stream_manager_t { app_t *app; array_list_t *listeners; stream_manager_state_t state; stream_media_session_t *media; IHS_Session *session; SDL_TimerID back_timer; int back_counter; bool overlay_opened; bool requested_disconnect; int viewport_width, viewport_height; int capture_width, capture_height; int overlay_height; }; ================================================ FILE: app/backend/stream/stream_media.c ================================================ #include #include "stream_media.h" #include "ss4s.h" #include "stream_manager.h" #include "app.h" #include "logging.h" #include "util/video/sps/include/sps_util.h" #include #include struct stream_media_session_t { stream_manager_t *manager; SDL_mutex *lock; SS4S_Player *player; SS4S_VideoCapabilities video_cap; SS4S_VideoInfo video_info; OpusMSDecoder *opus_decoder; size_t pcm_unit_size; int16_t *pcm_buffer; int pcm_buffer_size; int viewport_width, viewport_height; int overlay_height; }; static int audio_start(IHS_Session *session, const IHS_StreamAudioConfig *config, void *context); static void audio_stop(IHS_Session *session, void *context); static int audio_submit(IHS_Session *session, IHS_Buffer *data, void *context); static int video_start(IHS_Session *session, const IHS_StreamVideoConfig *config, void *context); static void video_stop(IHS_Session *session, void *context); static int video_submit(IHS_Session *session, IHS_Buffer *data, IHS_StreamVideoFrameFlag flags, void *context); static int video_set_capture_size(IHS_Session *session, int width, int height, void *context); static const IHS_StreamAudioCallbacks audio_callbacks = { .start = audio_start, .stop = audio_stop, .submit = audio_submit, }; static const IHS_StreamVideoCallbacks video_callbacks = { .start = video_start, .stop = video_stop, .submit = video_submit, .setCaptureSize = video_set_capture_size, }; stream_media_session_t *stream_media_create(stream_manager_t *manager) { stream_media_session_t *media_session = calloc(1, sizeof(stream_media_session_t)); media_session->manager = manager; media_session->lock = SDL_CreateMutex(); media_session->player = SS4S_PlayerOpen(); SS4S_PlayerSetWaitAudioVideoReady(media_session->player, true); SS4S_GetVideoCapabilities(&media_session->video_cap); return media_session; } void stream_media_destroy(stream_media_session_t *media_session) { SS4S_PlayerClose(media_session->player); SDL_DestroyMutex(media_session->lock); free(media_session); } void stream_media_set_viewport_size(stream_media_session_t *media_session, int width, int height) { SDL_LockMutex(media_session->lock); media_session->viewport_width = width; media_session->viewport_height = height; SDL_UnlockMutex(media_session->lock); } void stream_media_set_overlay_height(stream_media_session_t *media_session, int height) { SDL_LockMutex(media_session->lock); media_session->overlay_height = height; SDL_UnlockMutex(media_session->lock); } void stream_media_set_overlay_shown(stream_media_session_t *media_session, bool overlay) { if (media_session->video_cap.transform & SS4S_VIDEO_CAP_TRANSFORM_UI_COMPOSITING) { return; } if (overlay) { SDL_LockMutex(media_session->lock); int ui_width = media_session->viewport_width, ui_height = media_session->viewport_height, overlay_height = media_session->overlay_height; if (ui_width <= 0 || ui_height <= 0 || overlay_height <= 0) { SDL_UnlockMutex(media_session->lock); return; } SS4S_VideoRect src = { .x = 0, .y = 0, .width = media_session->video_info.width, .height = media_session->video_info.height * (ui_height - overlay_height) / ui_height }; SDL_UnlockMutex(media_session->lock); SS4S_VideoRect dest = {0, 0, ui_width, ui_height - overlay_height}; SS4S_PlayerVideoSetDisplayArea(media_session->player, &src, &dest); } else { SS4S_PlayerVideoSetDisplayArea(media_session->player, NULL, NULL); } } bool stream_media_supports_hevc(stream_media_session_t *media_session) { return media_session->video_cap.codecs & SS4S_VIDEO_H265; } const IHS_StreamAudioCallbacks *stream_media_audio_callbacks() { return &audio_callbacks; } const IHS_StreamVideoCallbacks *stream_media_video_callbacks() { return &video_callbacks; } static int audio_start(IHS_Session *session, const IHS_StreamAudioConfig *config, void *context) { (void) session; commons_log_info("Media", "Audio start. codec=%u, channels=%u, sampleRate=%u", config->codec, config->channels, config->frequency); if (config->codec != IHS_StreamAudioCodecOpus) { return -1; } stream_media_session_t *media_session = (stream_media_session_t *) context; SDL_LockMutex(media_session->lock); int rc; unsigned char mapping[2] = {0, 1}; const int samples_per_frame = 240; media_session->pcm_buffer_size = samples_per_frame * 64; media_session->pcm_unit_size = config->channels * sizeof(int16_t); media_session->opus_decoder = opus_multistream_decoder_create(config->frequency, config->channels, 1, 1, mapping, &rc); media_session->pcm_buffer = calloc(media_session->pcm_unit_size, media_session->pcm_buffer_size); SS4S_AudioInfo info = { .codec = SS4S_AUDIO_PCM_S16LE, .numOfChannels = (int) config->channels, .sampleRate = (int) config->frequency, .samplesPerFrame = samples_per_frame, .appName = "IHSplay", .streamName = "Streaming", }; SDL_UnlockMutex(media_session->lock); return SS4S_PlayerAudioOpen(media_session->player, &info); } static void audio_stop(IHS_Session *session, void *context) { (void) session; stream_media_session_t *media_session = (stream_media_session_t *) context; SS4S_PlayerAudioClose(media_session->player); opus_multistream_decoder_destroy(media_session->opus_decoder); free(media_session->pcm_buffer); } static int audio_submit(IHS_Session *session, IHS_Buffer *data, void *context) { (void) session; stream_media_session_t *media_session = (stream_media_session_t *) context; int decode_len = opus_multistream_decode(media_session->opus_decoder, data->data + data->offset, data->size, media_session->pcm_buffer, media_session->pcm_buffer_size, 0); return SS4S_PlayerAudioFeed(media_session->player, (const unsigned char *) media_session->pcm_buffer, media_session->pcm_unit_size * decode_len); } static int video_start(IHS_Session *session, const IHS_StreamVideoConfig *config, void *context) { (void) session; SS4S_VideoCodec codec; switch (config->codec) { case IHS_StreamVideoCodecH264: codec = SS4S_VIDEO_H264; break; case IHS_StreamVideoCodecHEVC: codec = SS4S_VIDEO_H265; break; default: return -1; } stream_media_session_t *media_session = (stream_media_session_t *) context; SDL_LockMutex(media_session->lock); commons_log_info("Media", "Video start. codec=%u, width=%u, height=%u", config->codec, config->width, config->height); SS4S_VideoInfo info = { .codec = codec, .width = (int) config->width, .height = (int) config->height, }; media_session->video_info = info; SDL_UnlockMutex(media_session->lock); return SS4S_PlayerVideoOpen(media_session->player, &info); } static void video_stop(IHS_Session *session, void *context) { (void) session; stream_media_session_t *media_session = (stream_media_session_t *) context; SS4S_PlayerVideoClose(media_session->player); } static int video_submit(IHS_Session *session, IHS_Buffer *data, IHS_StreamVideoFrameFlag flags, void *context) { (void) session; stream_media_session_t *media_session = (stream_media_session_t *) context; SS4S_VideoFeedFlags sflgs = 0; if (flags & IHS_StreamVideoFrameKeyFrame) { SDL_LockMutex(media_session->lock); sflgs = SS4S_VIDEO_FEED_DATA_KEYFRAME; sps_dimension_t dimension = {0, 0}; bool dimension_parsed = false; switch (media_session->video_info.codec) { case SS4S_VIDEO_H264: { dimension_parsed = sps_util_parse_dimension_h264(IHS_BufferPointer(data), data->size, &dimension); break; } case SS4S_VIDEO_H265: { dimension_parsed = sps_util_parse_dimension_hevc(IHS_BufferPointer(data), data->size, &dimension); break; } default: { commons_log_fatal("Media", "Unexpected video codec %s!!", SS4S_VideoCodecName(media_session->video_info.codec)); abort(); } } if (!dimension_parsed) { commons_log_warn("Media", "Can't parse NAL Unit."); commons_log_hexdump(COMMONS_LOG_LEVEL_WARN, "Media", IHS_BufferPointer(data), data->size); } if (dimension_parsed && (dimension.width != media_session->video_info.width || dimension.height != media_session->video_info.height)) { commons_log_info("Media", "Size change detected by NAL header. (%d*%d)=>(%d*%d)", media_session->video_info.width, media_session->video_info.height, dimension.width, dimension.height); media_session->video_info.width = dimension.width; media_session->video_info.height = dimension.height; SS4S_PlayerVideoSizeChanged(media_session->player, dimension.width, dimension.height); } SDL_UnlockMutex(media_session->lock); } return SS4S_PlayerVideoFeed(media_session->player, data->data + data->offset, data->size, sflgs); } static int video_set_capture_size(IHS_Session *session, int width, int height, void *context) { (void) session; stream_media_session_t *media_session = (stream_media_session_t *) context; stream_manager_set_capture_size(media_session->manager, width, height); return 0; } ================================================ FILE: app/backend/stream/stream_media.h ================================================ #pragma once #include "ihslib.h" typedef struct stream_media_session_t stream_media_session_t; typedef struct stream_manager_t stream_manager_t; stream_media_session_t *stream_media_create(stream_manager_t *manager); void stream_media_destroy(stream_media_session_t *media); void stream_media_set_viewport_size(stream_media_session_t *media_session, int width, int height); void stream_media_set_overlay_height(stream_media_session_t *media_session, int height); void stream_media_set_overlay_shown(stream_media_session_t *media_session, bool overlay); bool stream_media_supports_hevc(stream_media_session_t *media_session); const IHS_StreamAudioCallbacks *stream_media_audio_callbacks(); const IHS_StreamVideoCallbacks *stream_media_video_callbacks(); ================================================ FILE: app/backend/stream_manager.h ================================================ #pragma once #include "stream/stream_manager.h" ================================================ FILE: app/config.h.in ================================================ #pragma once #define IHSPLAY_VERSION_STRING "@PROJECT_VERSION@" #define SS4S_MODULES_INI_PATH "@SS4S_MODULES_INI_PATH_RUNTIME@" #cmakedefine01 IHSPLAY_IS_DEBUG #cmakedefine01 IHSPLAY_WIP_FEATURES #cmakedefine01 IHSPLAY_FEATURE_FORCE_FULLSCREEN #cmakedefine01 IHSPLAY_FEATURE_LIBCEC ================================================ FILE: app/lvgl/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE display.c mouse.c keypad.c theme.c) add_subdirectory(ext) ================================================ FILE: app/lvgl/display.c ================================================ #include "display.h" #include #include static void flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *src); lv_disp_t *app_lv_disp_init(SDL_Window *window) { int width, height; SDL_GetWindowSize(window, &width, &height); assert(width > 0 || height > 0); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); lv_disp_draw_buf_t *draw_buf = malloc(sizeof(lv_disp_draw_buf_t)); SDL_Texture *texture = lv_draw_sdl_create_screen_texture(renderer, width, height); lv_disp_draw_buf_init(draw_buf, texture, NULL, width * height); lv_disp_drv_t *driver = malloc(sizeof(lv_disp_drv_t)); lv_disp_drv_init(driver); lv_draw_sdl_drv_param_t *param = lv_mem_alloc(sizeof(lv_draw_sdl_drv_param_t)); param->renderer = renderer; param->user_data = window; driver->user_data = param; driver->draw_buf = draw_buf; driver->dpi = (int) (width / 5.333333); driver->flush_cb = flush_cb; driver->hor_res = width; driver->ver_res = height; SDL_SetRenderTarget(renderer, texture); lv_disp_t *disp = lv_disp_drv_register(driver); disp->bg_color = lv_color_black(); disp->bg_opa = LV_OPA_TRANSP; return disp; } void app_lv_disp_deinit(lv_disp_t *disp) { lv_disp_drv_t *drv = disp->driver; lv_draw_ctx_t *draw_ctx = drv->draw_ctx; drv->draw_ctx_deinit(drv, draw_ctx); free(draw_ctx); lv_disp_draw_buf_t *draw_buf = drv->draw_buf; SDL_DestroyTexture(draw_buf->buf1); free(draw_buf); lv_draw_sdl_drv_param_t *param = drv->user_data; SDL_DestroyRenderer(param->renderer); free(param); // Set act_scr to NULL to suppress warning when we remove the display disp->act_scr = NULL; lv_disp_remove(disp); free(drv); } static void flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *src) { LV_UNUSED(src); if (area->x2 < 0 || area->y2 < 0 || area->x1 > disp_drv->hor_res - 1 || area->y1 > disp_drv->ver_res - 1) { lv_disp_flush_ready(disp_drv); return; } if (lv_disp_flush_is_last(disp_drv)) { lv_draw_sdl_drv_param_t *param = disp_drv->user_data; SDL_Renderer *renderer = param->renderer; SDL_Texture *texture = disp_drv->draw_buf->buf1; SDL_SetRenderTarget(renderer, NULL); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); SDL_SetRenderTarget(renderer, texture); } lv_disp_flush_ready(disp_drv); } ================================================ FILE: app/lvgl/display.h ================================================ #pragma once #include #include lv_disp_t *app_lv_disp_init(SDL_Window *window); void app_lv_disp_deinit(lv_disp_t *disp); ================================================ FILE: app/lvgl/ext/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE lv_child_group.c msgbox_ext.c lv_dir_focus.c) ================================================ FILE: app/lvgl/ext/lv_child_group.c ================================================ #include "lv_child_group.h" void cb_child_group_add(lv_event_t *event) { lv_obj_t *child = lv_event_get_param(event); if (!child || !lv_obj_is_group_def(child)) return; lv_group_t *group = lv_event_get_user_data(event); if (lv_obj_get_group(child)) { lv_group_remove_obj(child); } lv_group_add_obj(group, child); } ================================================ FILE: app/lvgl/ext/lv_child_group.h ================================================ #pragma once #include "lvgl.h" void cb_child_group_add(lv_event_t *event); ================================================ FILE: app/lvgl/ext/lv_dir_focus.c ================================================ #include "lv_dir_focus.h" static lv_style_prop_t props[4] = { LV_STYLE_PROP_INV, LV_STYLE_PROP_INV, LV_STYLE_PROP_INV, LV_STYLE_PROP_INV }; typedef enum focus_dir_index { DIR_INDEX_LEFT = 0, DIR_INDEX_RIGHT = 1, DIR_INDEX_TOP = 2, DIR_INDEX_BOTTOM = 3, } focus_dir_index; void lv_dir_focus_register() { LV_ASSERT(lv_is_initialized()); props[DIR_INDEX_LEFT] = lv_style_register_prop(LV_STYLE_PROP_FLAG_NONE); props[DIR_INDEX_RIGHT] = lv_style_register_prop(LV_STYLE_PROP_FLAG_NONE); props[DIR_INDEX_TOP] = lv_style_register_prop(LV_STYLE_PROP_FLAG_NONE); props[DIR_INDEX_BOTTOM] = lv_style_register_prop(LV_STYLE_PROP_FLAG_NONE); } void lv_obj_set_dir_focus_obj(lv_obj_t *obj, lv_dir_t dir, const lv_obj_t *to_focus) { lv_style_value_t value = {.ptr = to_focus}; if (dir & LV_DIR_LEFT) { lv_obj_set_local_style_prop(obj, props[DIR_INDEX_LEFT], value, 0); } if (dir & LV_DIR_RIGHT) { lv_obj_set_local_style_prop(obj, props[DIR_INDEX_RIGHT], value, 0); } if (dir & LV_DIR_TOP) { lv_obj_set_local_style_prop(obj, props[DIR_INDEX_TOP], value, 0); } if (dir & LV_DIR_BOTTOM) { lv_obj_set_local_style_prop(obj, props[DIR_INDEX_BOTTOM], value, 0); } } bool lv_obj_focus_dir(lv_obj_t *obj, lv_dir_t dir) { lv_style_value_t value; switch (dir) { case LV_DIR_LEFT: if (lv_obj_get_local_style_prop(obj, props[DIR_INDEX_LEFT], &value, 0) != LV_RES_OK) { return false; } break; case LV_DIR_RIGHT: if (lv_obj_get_local_style_prop(obj, props[DIR_INDEX_RIGHT], &value, 0) != LV_RES_OK) { return false; } break; case LV_DIR_TOP: if (lv_obj_get_local_style_prop(obj, props[DIR_INDEX_TOP], &value, 0) != LV_RES_OK) { return false; } break; case LV_DIR_BOTTOM: if (lv_obj_get_local_style_prop(obj, props[DIR_INDEX_BOTTOM], &value, 0) != LV_RES_OK) { return false; } break; default: return false; } lv_group_t *group = lv_obj_get_group(obj); lv_obj_t **group_item = NULL; _LV_LL_READ(&group->obj_ll, group_item) { if (*group_item == value.ptr) { break; } } if (group_item == NULL) { return false; } lv_group_focus_obj(*group_item); return true; } bool lv_obj_focus_dir_by_key(lv_obj_t *obj, lv_key_t dir) { switch (dir) { case LV_KEY_LEFT: { return lv_obj_focus_dir(obj, LV_DIR_LEFT); } case LV_KEY_RIGHT: { return lv_obj_focus_dir(obj, LV_DIR_RIGHT); } case LV_KEY_UP: { return lv_obj_focus_dir(obj, LV_DIR_TOP); } case LV_KEY_DOWN: { return lv_obj_focus_dir(obj, LV_DIR_BOTTOM); } default: { return false; } } } ================================================ FILE: app/lvgl/ext/lv_dir_focus.h ================================================ #pragma once #include "lvgl.h" void lv_dir_focus_register(); void lv_obj_set_dir_focus_obj(lv_obj_t *obj, lv_dir_t dir, const lv_obj_t *to_focus); bool lv_obj_focus_dir(lv_obj_t *obj, lv_dir_t dir); bool lv_obj_focus_dir_by_key(lv_obj_t *obj, lv_key_t dir); ================================================ FILE: app/lvgl/ext/msgbox_ext.c ================================================ #include "msgbox_ext.h" #include "ui/app_ui.h" #include "lv_child_group.h" static void msgbox_key(lv_event_t *event); static void msgbox_cancel(lv_event_t *event); static void msgbox_destroy(lv_event_t *event); void msgbox_inject_nav(app_ui_t *ui, lv_obj_t *obj) { lv_group_t *group = lv_group_create(); group->user_data = ui; app_ui_push_modal_group(ui, group); lv_obj_add_event_cb(obj, cb_child_group_add, LV_EVENT_CHILD_CREATED, group); lv_obj_add_event_cb(obj, msgbox_key, LV_EVENT_KEY, NULL); lv_obj_add_event_cb(obj, msgbox_cancel, LV_EVENT_CANCEL, NULL); lv_obj_add_event_cb(obj, msgbox_destroy, LV_EVENT_DELETE, group); } void msgbox_fix_sizes(lv_obj_t *obj, const char *btn_texts[]) { lv_obj_t *btns = lv_msgbox_get_btns(obj); if (btns != NULL) { int i; for (i = 0; btn_texts[i][0] != '\0'; i++); lv_obj_set_width(btns, i * LV_DPX(70) + (i - 1) * LV_DPX(10)); } } static void msgbox_key(lv_event_t *event) { lv_obj_t *target = lv_event_get_target(event); lv_group_t *group = lv_obj_get_group(target); if (!group) return; switch (lv_event_get_key(event)) { case LV_KEY_UP: { lv_group_focus_prev(group); break; } case LV_KEY_DOWN: { lv_group_focus_next(group); break; } default: { break; } } } static void msgbox_cancel(lv_event_t *event) { lv_obj_t *mbox = lv_event_get_current_target(event); lv_obj_t *target = lv_event_get_target(event); lv_group_t *group = lv_obj_get_group(target); if (!group) return; lv_obj_t *btns = lv_msgbox_get_btns(mbox); if (btns && !lv_obj_has_flag(btns, LV_OBJ_FLAG_HIDDEN) && !lv_btnmatrix_has_btn_ctrl(btns, 0, LV_BTNMATRIX_CTRL_DISABLED)) { lv_msgbox_close(mbox); } } static void msgbox_destroy(lv_event_t *event) { lv_group_t *group = lv_event_get_user_data(event); app_ui_remove_modal_group(group->user_data, group); lv_group_remove_all_objs(group); lv_group_del(group); } ================================================ FILE: app/lvgl/ext/msgbox_ext.h ================================================ #pragma once #include "lvgl.h" typedef struct app_ui_t app_ui_t; void msgbox_inject_nav(app_ui_t *ui, lv_obj_t *obj); void msgbox_fix_sizes(lv_obj_t *obj, const char *btn_texts[]); ================================================ FILE: app/lvgl/fonts/bootstrap-icons/regular.h ================================================ #pragma once const unsigned char ttf_bootstrap_icons_data[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x03, 0x00, 0x30, 0x47, 0x53, 0x55, 0x42, 0xb8, 0xfc, 0xb8, 0xea, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x00, 0x28, 0x4f, 0x53, 0x2f, 0x32, 0x3f, 0x32, 0x50, 0xfb, 0x00, 0x00, 0x01, 0xc8, 0x00, 0x00, 0x00, 0x60, 0x63, 0x6d, 0x61, 0x70, 0xb6, 0x0c, 0xaf, 0x9e, 0x00, 0x00, 0x02, 0xb8, 0x00, 0x00, 0x00, 0x9c, 0x67, 0x6c, 0x79, 0x66, 0xf3, 0xe0, 0xad, 0xaa, 0x00, 0x00, 0x03, 0x54, 0x00, 0x00, 0x0a, 0x54, 0x68, 0x65, 0x61, 0x64, 0x60, 0xac, 0xa0, 0x3f, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x36, 0x68, 0x68, 0x65, 0x61, 0x02, 0x70, 0x01, 0x12, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x24, 0x68, 0x6d, 0x74, 0x78, 0x01, 0x29, 0xff, 0xff, 0x00, 0x00, 0x01, 0x44, 0x00, 0x00, 0x00, 0x24, 0x6c, 0x6f, 0x63, 0x61, 0x19, 0x5a, 0x16, 0x91, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x22, 0x6d, 0x61, 0x78, 0x70, 0x01, 0x47, 0x01, 0x31, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x06, 0xf1, 0x1f, 0x96, 0x00, 0x00, 0x02, 0x28, 0x00, 0x00, 0x00, 0x90, 0x70, 0x6f, 0x73, 0x74, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x25, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, 0xef, 0x01, 0x3b, 0x02, 0x06, 0x02, 0x64, 0x02, 0xe4, 0x03, 0x23, 0x03, 0x4d, 0x03, 0x7c, 0x03, 0xd6, 0x04, 0x40, 0x04, 0x98, 0x04, 0xdf, 0x04, 0xfd, 0x05, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0xff, 0xf9, 0xff, 0xe3, 0x01, 0x49, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x26, 0x00, 0x26, 0x00, 0x02, 0x44, 0x46, 0x4c, 0x54, 0x00, 0x12, 0x6c, 0x61, 0x74, 0x6e, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x4d, 0xb9, 0x5b, 0x5f, 0x0f, 0x3c, 0xf5, 0x08, 0x0b, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x25, 0xb0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x25, 0xb0, 0x80, 0xff, 0xf9, 0xff, 0xe3, 0x01, 0x49, 0x01, 0x33, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x2c, 0x01, 0x90, 0x00, 0x05, 0x00, 0x00, 0x00, 0xbe, 0x00, 0xd2, 0x00, 0x00, 0x00, 0x2a, 0x00, 0xbe, 0x00, 0xd2, 0x00, 0x00, 0x00, 0x90, 0x00, 0x0e, 0x00, 0x4d, 0x00, 0x00, 0x02, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x66, 0x45, 0x64, 0x00, 0xc0, 0xf2, 0x29, 0xf6, 0xce, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x1b, 0x01, 0x47, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x4e, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x24, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x16, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x24, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x24, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x06, 0x00, 0x1e, 0x00, 0x24, 0x00, 0x56, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x72, 0x00, 0x62, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x61, 0x00, 0x70, 0x00, 0x2d, 0x00, 0x69, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x73, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x14, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x04, 0x00, 0x88, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x10, 0x00, 0x03, 0x00, 0x0e, 0xf2, 0x29, 0xf2, 0xcc, 0xf2, 0xd4, 0xf3, 0x02, 0xf3, 0xe2, 0xf4, 0xf2, 0xf4, 0xff, 0xf5, 0x04, 0xf5, 0xed, 0xf6, 0x59, 0xf6, 0x5b, 0xf6, 0x5e, 0xf6, 0xc1, 0xf6, 0xce, 0xff, 0xff, 0x00, 0x00, 0xf2, 0x29, 0xf2, 0xcc, 0xf2, 0xd4, 0xf3, 0x02, 0xf3, 0xe2, 0xf4, 0xf1, 0xf4, 0xff, 0xf5, 0x04, 0xf5, 0xed, 0xf6, 0x59, 0xf6, 0x5b, 0xf6, 0x5e, 0xf6, 0xc1, 0xf6, 0xce, 0xff, 0xff, 0x0d, 0xd9, 0x0d, 0x37, 0x0d, 0x30, 0x0d, 0x03, 0x0c, 0x24, 0x0b, 0x16, 0x0b, 0x0a, 0x0b, 0x06, 0x0a, 0x1f, 0x09, 0xb6, 0x09, 0xa6, 0x09, 0xb0, 0x09, 0x4a, 0x09, 0x3f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xff, 0xfd, 0x01, 0x11, 0x01, 0x2d, 0x00, 0x11, 0x00, 0x45, 0x00, 0x57, 0x00, 0x8b, 0x00, 0x00, 0x13, 0x26, 0x06, 0x07, 0x0e, 0x01, 0x07, 0x06, 0x07, 0x14, 0x16, 0x36, 0x37, 0x3e, 0x01, 0x37, 0x36, 0x34, 0x17, 0x30, 0x27, 0x26, 0x27, 0x26, 0x37, 0x36, 0x3f, 0x01, 0x34, 0x26, 0x27, 0x26, 0x2b, 0x01, 0x26, 0x0f, 0x01, 0x06, 0x22, 0x27, 0x2e, 0x01, 0x07, 0x06, 0x07, 0x0e, 0x01, 0x17, 0x16, 0x1f, 0x01, 0x16, 0x17, 0x1e, 0x01, 0x17, 0x1e, 0x02, 0x3e, 0x01, 0x32, 0x16, 0x17, 0x16, 0x37, 0x3e, 0x01, 0x37, 0x36, 0x27, 0x26, 0x06, 0x07, 0x0e, 0x01, 0x07, 0x06, 0x07, 0x14, 0x16, 0x36, 0x37, 0x3e, 0x01, 0x37, 0x36, 0x34, 0x17, 0x30, 0x27, 0x26, 0x27, 0x26, 0x37, 0x36, 0x3f, 0x01, 0x34, 0x26, 0x27, 0x26, 0x2b, 0x01, 0x26, 0x0f, 0x01, 0x06, 0x22, 0x27, 0x2e, 0x01, 0x07, 0x06, 0x07, 0x0e, 0x01, 0x17, 0x16, 0x1f, 0x01, 0x16, 0x17, 0x1e, 0x01, 0x17, 0x1e, 0x02, 0x3e, 0x01, 0x32, 0x16, 0x17, 0x16, 0x37, 0x3e, 0x01, 0x37, 0x36, 0xd2, 0x01, 0x0f, 0x08, 0x0b, 0x12, 0x04, 0x03, 0x01, 0x01, 0x11, 0x09, 0x0c, 0x10, 0x04, 0x02, 0x3e, 0x03, 0x0f, 0x08, 0x10, 0x02, 0x04, 0x1a, 0x02, 0x0f, 0x08, 0x0e, 0x10, 0x01, 0x0a, 0x0c, 0x0f, 0x13, 0x06, 0x0b, 0x12, 0x17, 0x16, 0x0a, 0x08, 0x0d, 0x10, 0x01, 0x01, 0x05, 0x01, 0x05, 0x04, 0x06, 0x0f, 0x0a, 0x08, 0x0b, 0x15, 0x0f, 0x15, 0x0c, 0x12, 0x09, 0x0e, 0x11, 0x08, 0x16, 0x0c, 0x0a, 0x3f, 0x01, 0x0f, 0x08, 0x0b, 0x12, 0x04, 0x03, 0x01, 0x01, 0x11, 0x09, 0x0c, 0x10, 0x04, 0x02, 0x3e, 0x03, 0x0f, 0x08, 0x10, 0x02, 0x04, 0x1a, 0x02, 0x0f, 0x08, 0x0e, 0x10, 0x01, 0x0a, 0x0c, 0x0f, 0x13, 0x06, 0x0b, 0x12, 0x17, 0x16, 0x0a, 0x08, 0x0d, 0x10, 0x01, 0x01, 0x05, 0x01, 0x05, 0x04, 0x06, 0x0f, 0x0a, 0x08, 0x0b, 0x15, 0x0f, 0x15, 0x0c, 0x12, 0x09, 0x0e, 0x11, 0x08, 0x16, 0x0c, 0x0a, 0x01, 0x2c, 0x01, 0x03, 0x05, 0x05, 0x14, 0x0c, 0x09, 0x09, 0x06, 0x02, 0x02, 0x05, 0x06, 0x17, 0x0b, 0x09, 0x0d, 0xdb, 0x02, 0x0a, 0x0a, 0x13, 0x17, 0x24, 0x10, 0x02, 0x01, 0x10, 0x04, 0x08, 0x02, 0x04, 0x05, 0x06, 0x04, 0x07, 0x04, 0x09, 0x04, 0x08, 0x0b, 0x25, 0x1e, 0x17, 0x0e, 0x02, 0x10, 0x09, 0x10, 0x16, 0x0b, 0x08, 0x08, 0x02, 0x08, 0x05, 0x05, 0x05, 0x05, 0x07, 0x03, 0x1a, 0x17, 0x16, 0xde, 0x01, 0x03, 0x05, 0x05, 0x14, 0x0c, 0x09, 0x09, 0x06, 0x02, 0x02, 0x05, 0x06, 0x17, 0x0b, 0x09, 0x0d, 0xdb, 0x02, 0x0a, 0x0a, 0x13, 0x17, 0x24, 0x10, 0x02, 0x01, 0x10, 0x04, 0x08, 0x02, 0x04, 0x05, 0x06, 0x04, 0x07, 0x04, 0x09, 0x04, 0x08, 0x0b, 0x25, 0x1e, 0x17, 0x0e, 0x02, 0x10, 0x09, 0x10, 0x16, 0x0b, 0x08, 0x08, 0x02, 0x08, 0x05, 0x05, 0x05, 0x05, 0x07, 0x03, 0x1a, 0x17, 0x16, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0xe2, 0x00, 0x0e, 0x00, 0x00, 0x37, 0x27, 0x26, 0x3e, 0x01, 0x3b, 0x01, 0x32, 0x1e, 0x01, 0x06, 0x0f, 0x01, 0x06, 0x22, 0x88, 0x5a, 0x05, 0x01, 0x0a, 0x08, 0xb4, 0x05, 0x0a, 0x04, 0x01, 0x04, 0x5a, 0x05, 0x12, 0x5b, 0x67, 0x06, 0x0f, 0x0a, 0x06, 0x0a, 0x0b, 0x04, 0x67, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x23, 0x00, 0x0b, 0x00, 0x17, 0x00, 0x27, 0x00, 0x37, 0x00, 0x00, 0x37, 0x22, 0x26, 0x34, 0x36, 0x3b, 0x01, 0x32, 0x16, 0x14, 0x06, 0x23, 0x27, 0x22, 0x26, 0x34, 0x36, 0x3b, 0x01, 0x32, 0x16, 0x14, 0x06, 0x23, 0x07, 0x14, 0x16, 0x3b, 0x01, 0x32, 0x36, 0x3d, 0x01, 0x34, 0x26, 0x2b, 0x01, 0x22, 0x06, 0x15, 0x17, 0x22, 0x26, 0x3d, 0x01, 0x34, 0x36, 0x3b, 0x01, 0x32, 0x16, 0x1d, 0x01, 0x14, 0x06, 0x23, 0x2f, 0x04, 0x05, 0x05, 0x04, 0xce, 0x04, 0x06, 0x06, 0x04, 0xa9, 0x04, 0x05, 0x05, 0x04, 0x84, 0x04, 0x05, 0x05, 0x04, 0xd8, 0x10, 0x0c, 0xf4, 0x0c, 0x10, 0x10, 0x0c, 0xf4, 0x0c, 0x10, 0x1c, 0x04, 0x05, 0x05, 0x04, 0xf4, 0x04, 0x05, 0x05, 0x04, 0xea, 0x06, 0x08, 0x05, 0x05, 0x08, 0x06, 0x26, 0x05, 0x08, 0x06, 0x06, 0x08, 0x05, 0xd8, 0x0b, 0x11, 0x11, 0x0b, 0x84, 0x0b, 0x11, 0x11, 0x0b, 0x8d, 0x05, 0x04, 0x84, 0x03, 0x06, 0x06, 0x03, 0x84, 0x04, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x26, 0x01, 0x06, 0x00, 0x08, 0x00, 0x12, 0x00, 0x1b, 0x00, 0x24, 0x00, 0x30, 0x00, 0x69, 0x00, 0x8c, 0x00, 0x00, 0x37, 0x14, 0x06, 0x22, 0x26, 0x34, 0x36, 0x32, 0x16, 0x07, 0x32, 0x36, 0x34, 0x26, 0x22, 0x06, 0x14, 0x16, 0x33, 0x37, 0x14, 0x06, 0x22, 0x26, 0x34, 0x36, 0x32, 0x16, 0x07, 0x32, 0x36, 0x34, 0x26, 0x22, 0x06, 0x14, 0x16, 0x27, 0x33, 0x15, 0x33, 0x15, 0x23, 0x15, 0x23, 0x35, 0x23, 0x35, 0x33, 0x27, 0x26, 0x36, 0x3f, 0x01, 0x36, 0x16, 0x17, 0x36, 0x32, 0x17, 0x34, 0x36, 0x1f, 0x01, 0x1e, 0x01, 0x07, 0x16, 0x17, 0x1e, 0x02, 0x17, 0x16, 0x07, 0x0e, 0x01, 0x27, 0x26, 0x27, 0x26, 0x2f, 0x01, 0x26, 0x27, 0x26, 0x22, 0x07, 0x06, 0x0f, 0x01, 0x06, 0x07, 0x06, 0x07, 0x06, 0x26, 0x27, 0x26, 0x37, 0x3e, 0x02, 0x37, 0x36, 0x37, 0x17, 0x0e, 0x04, 0x17, 0x16, 0x33, 0x36, 0x37, 0x36, 0x3f, 0x01, 0x36, 0x37, 0x36, 0x32, 0x17, 0x16, 0x1f, 0x01, 0x16, 0x17, 0x16, 0x17, 0x32, 0x37, 0x36, 0x2e, 0x04, 0x22, 0xd8, 0x06, 0x08, 0x05, 0x05, 0x08, 0x06, 0x1c, 0x03, 0x06, 0x06, 0x07, 0x06, 0x06, 0x03, 0x2f, 0x05, 0x08, 0x05, 0x05, 0x08, 0x05, 0x1c, 0x04, 0x06, 0x06, 0x08, 0x05, 0x05, 0x76, 0x13, 0x13, 0x13, 0x13, 0x12, 0x12, 0x1b, 0x01, 0x04, 0x04, 0x24, 0x04, 0x07, 0x01, 0x12, 0x29, 0x13, 0x07, 0x04, 0x25, 0x04, 0x04, 0x03, 0x04, 0x03, 0x0b, 0x13, 0x0c, 0x01, 0x01, 0x07, 0x04, 0x0f, 0x08, 0x0f, 0x0e, 0x04, 0x09, 0x08, 0x0c, 0x0b, 0x10, 0x2a, 0x10, 0x0b, 0x0c, 0x08, 0x09, 0x04, 0x0e, 0x0f, 0x08, 0x0f, 0x04, 0x07, 0x01, 0x01, 0x0c, 0x13, 0x0b, 0x03, 0x05, 0x25, 0x18, 0x10, 0x12, 0x0a, 0x02, 0x05, 0x03, 0x05, 0x09, 0x09, 0x04, 0x07, 0x09, 0x0e, 0x0e, 0x14, 0x34, 0x14, 0x0e, 0x0e, 0x09, 0x07, 0x04, 0x09, 0x09, 0x05, 0x03, 0x05, 0x02, 0x0a, 0x12, 0x10, 0x30, 0x3e, 0xbb, 0x04, 0x05, 0x05, 0x08, 0x05, 0x05, 0x20, 0x05, 0x08, 0x06, 0x06, 0x08, 0x05, 0x09, 0x04, 0x05, 0x05, 0x08, 0x06, 0x06, 0x20, 0x06, 0x07, 0x06, 0x06, 0x07, 0x06, 0x38, 0x12, 0x13, 0x13, 0x13, 0x13, 0x3d, 0x04, 0x06, 0x01, 0x0a, 0x01, 0x04, 0x04, 0x02, 0x02, 0x04, 0x04, 0x01, 0x0a, 0x01, 0x08, 0x04, 0x03, 0x03, 0x0b, 0x2b, 0x34, 0x16, 0x1a, 0x10, 0x08, 0x08, 0x01, 0x01, 0x0d, 0x04, 0x0b, 0x08, 0x0e, 0x06, 0x09, 0x09, 0x06, 0x0e, 0x08, 0x0a, 0x05, 0x0d, 0x01, 0x01, 0x08, 0x08, 0x10, 0x1a, 0x16, 0x34, 0x2b, 0x0b, 0x04, 0x02, 0x06, 0x05, 0x10, 0x28, 0x2d, 0x2c, 0x0c, 0x05, 0x01, 0x09, 0x04, 0x08, 0x0a, 0x10, 0x08, 0x0b, 0x0b, 0x08, 0x10, 0x09, 0x09, 0x04, 0x09, 0x01, 0x05, 0x0c, 0x2c, 0x2d, 0x28, 0x10, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x07, 0x00, 0x2e, 0x00, 0x43, 0x00, 0x00, 0x35, 0x34, 0x37, 0x36, 0x37, 0x3e, 0x01, 0x3b, 0x01, 0x17, 0x16, 0x17, 0x1e, 0x01, 0x1d, 0x01, 0x07, 0x06, 0x07, 0x0e, 0x01, 0x2b, 0x01, 0x14, 0x17, 0x33, 0x32, 0x16, 0x14, 0x06, 0x2b, 0x01, 0x22, 0x26, 0x34, 0x36, 0x3b, 0x01, 0x36, 0x35, 0x23, 0x27, 0x26, 0x27, 0x2e, 0x01, 0x35, 0x37, 0x0e, 0x01, 0x1d, 0x01, 0x14, 0x1e, 0x01, 0x3b, 0x01, 0x32, 0x3e, 0x01, 0x3d, 0x01, 0x34, 0x2e, 0x01, 0x27, 0x23, 0x22, 0x01, 0x01, 0x03, 0x04, 0x10, 0x0d, 0xe1, 0x05, 0x07, 0x06, 0x08, 0x0b, 0x01, 0x01, 0x03, 0x04, 0x10, 0x0c, 0x4b, 0x04, 0x0e, 0x04, 0x06, 0x06, 0x04, 0x70, 0x04, 0x06, 0x06, 0x04, 0x0e, 0x05, 0x4b, 0x06, 0x07, 0x06, 0x08, 0x0b, 0x1a, 0x03, 0x04, 0x04, 0x09, 0x05, 0xe2, 0x07, 0x07, 0x04, 0x05, 0x08, 0x06, 0xe0, 0x08, 0xe1, 0x03, 0x03, 0x07, 0x06, 0x08, 0x0b, 0x01, 0x01, 0x03, 0x04, 0x10, 0x0d, 0x70, 0x06, 0x07, 0x06, 0x08, 0x0b, 0x13, 0x09, 0x06, 0x07, 0x06, 0x06, 0x07, 0x06, 0x09, 0x13, 0x01, 0x01, 0x03, 0x04, 0x10, 0x0d, 0x80, 0x02, 0x09, 0x05, 0x70, 0x08, 0x07, 0x04, 0x05, 0x08, 0x05, 0x71, 0x07, 0x07, 0x04, 0x01, 0x00, 0x02, 0xff, 0xfd, 0xff, 0xfd, 0x01, 0x2f, 0x01, 0x2f, 0x00, 0x47, 0x00, 0x50, 0x00, 0x00, 0x13, 0x2e, 0x01, 0x06, 0x0f, 0x01, 0x0e, 0x01, 0x2f, 0x01, 0x26, 0x0e, 0x01, 0x1f, 0x01, 0x16, 0x06, 0x0f, 0x01, 0x0e, 0x01, 0x16, 0x1f, 0x01, 0x1e, 0x01, 0x0f, 0x01, 0x06, 0x1e, 0x01, 0x3f, 0x01, 0x36, 0x16, 0x1f, 0x01, 0x1e, 0x01, 0x36, 0x3f, 0x01, 0x3e, 0x01, 0x1f, 0x01, 0x16, 0x3e, 0x01, 0x2f, 0x01, 0x26, 0x36, 0x3f, 0x01, 0x3e, 0x01, 0x26, 0x2f, 0x01, 0x2e, 0x01, 0x3f, 0x01, 0x36, 0x2e, 0x01, 0x0f, 0x01, 0x06, 0x26, 0x27, 0x07, 0x22, 0x26, 0x34, 0x36, 0x32, 0x16, 0x14, 0x06, 0xb0, 0x03, 0x17, 0x17, 0x03, 0x02, 0x04, 0x18, 0x0c, 0x05, 0x0c, 0x17, 0x09, 0x06, 0x03, 0x07, 0x0a, 0x0d, 0x06, 0x0d, 0x09, 0x09, 0x0d, 0x06, 0x0d, 0x0a, 0x07, 0x03, 0x06, 0x09, 0x17, 0x0b, 0x06, 0x0c, 0x18, 0x04, 0x02, 0x03, 0x17, 0x17, 0x03, 0x02, 0x04, 0x18, 0x0c, 0x06, 0x0b, 0x17, 0x09, 0x06, 0x03, 0x07, 0x0a, 0x0d, 0x06, 0x0d, 0x09, 0x09, 0x0d, 0x06, 0x0d, 0x0a, 0x07, 0x03, 0x06, 0x09, 0x17, 0x0b, 0x06, 0x0c, 0x18, 0x04, 0x1c, 0x17, 0x20, 0x20, 0x2e, 0x20, 0x20, 0x01, 0x18, 0x0d, 0x09, 0x09, 0x0d, 0x06, 0x0d, 0x0a, 0x07, 0x03, 0x06, 0x09, 0x17, 0x0b, 0x06, 0x0c, 0x18, 0x04, 0x02, 0x03, 0x17, 0x17, 0x03, 0x02, 0x04, 0x18, 0x0c, 0x05, 0x0c, 0x17, 0x09, 0x06, 0x03, 0x07, 0x0a, 0x0d, 0x06, 0x0d, 0x09, 0x09, 0x0d, 0x06, 0x0d, 0x0a, 0x07, 0x03, 0x06, 0x09, 0x17, 0x0b, 0x06, 0x0c, 0x18, 0x04, 0x02, 0x03, 0x17, 0x17, 0x03, 0x02, 0x04, 0x18, 0x0c, 0x06, 0x0b, 0x17, 0x09, 0x06, 0x03, 0x07, 0x0a, 0x0d, 0xb3, 0x20, 0x2e, 0x20, 0x20, 0x2e, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x07, 0x00, 0x0b, 0x00, 0x1b, 0x00, 0x2b, 0x00, 0x00, 0x37, 0x26, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3f, 0x01, 0x36, 0x34, 0x2f, 0x01, 0x34, 0x36, 0x3b, 0x01, 0x32, 0x16, 0x1d, 0x01, 0x14, 0x06, 0x2b, 0x01, 0x22, 0x26, 0x35, 0x25, 0x34, 0x26, 0x2b, 0x01, 0x22, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3b, 0x01, 0x32, 0x36, 0x35, 0x7f, 0x04, 0x0a, 0x0a, 0x04, 0x42, 0x04, 0x04, 0xc1, 0x16, 0x10, 0xe1, 0x0f, 0x16, 0x16, 0x10, 0xe0, 0x10, 0x16, 0x01, 0x19, 0x0b, 0x07, 0xe1, 0x08, 0x0b, 0x0b, 0x08, 0xe1, 0x07, 0x0b, 0xcd, 0x03, 0x05, 0x06, 0x5e, 0x06, 0x05, 0x03, 0x2f, 0x03, 0x0a, 0x03, 0x43, 0x10, 0x16, 0x16, 0x10, 0x96, 0x10, 0x15, 0x15, 0x10, 0x96, 0x08, 0x0b, 0x0b, 0x08, 0x96, 0x08, 0x0b, 0x0b, 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2d, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x00, 0x25, 0x14, 0x0e, 0x01, 0x22, 0x2e, 0x01, 0x34, 0x3e, 0x01, 0x32, 0x1e, 0x01, 0x27, 0x26, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3f, 0x01, 0x36, 0x34, 0x27, 0x01, 0x2c, 0x28, 0x45, 0x52, 0x45, 0x28, 0x28, 0x45, 0x52, 0x45, 0x28, 0xad, 0x04, 0x0a, 0x0a, 0x04, 0x42, 0x04, 0x04, 0x96, 0x29, 0x45, 0x28, 0x28, 0x45, 0x52, 0x45, 0x28, 0x28, 0x45, 0x0e, 0x03, 0x05, 0x06, 0x5e, 0x06, 0x05, 0x03, 0x2f, 0x03, 0x0a, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0d, 0x01, 0x1a, 0x00, 0x03, 0x00, 0x1b, 0x00, 0x00, 0x13, 0x15, 0x33, 0x35, 0x07, 0x34, 0x36, 0x37, 0x27, 0x0e, 0x01, 0x1e, 0x02, 0x3e, 0x01, 0x26, 0x27, 0x07, 0x1e, 0x02, 0x0e, 0x02, 0x2e, 0x02, 0x8d, 0x12, 0x67, 0x1a, 0x17, 0x0a, 0x21, 0x1e, 0x12, 0x3d, 0x4c, 0x3d, 0x15, 0x1e, 0x21, 0x09, 0x13, 0x18, 0x06, 0x10, 0x20, 0x2a, 0x2c, 0x24, 0x14, 0x01, 0x19, 0x83, 0x83, 0x92, 0x19, 0x2c, 0x0d, 0x10, 0x12, 0x47, 0x4a, 0x2f, 0x01, 0x2e, 0x4a, 0x47, 0x13, 0x10, 0x0b, 0x25, 0x2c, 0x2a, 0x1f, 0x0c, 0x07, 0x1b, 0x27, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2d, 0x00, 0x0c, 0x00, 0x34, 0x00, 0x3d, 0x00, 0x00, 0x25, 0x14, 0x0e, 0x01, 0x22, 0x2e, 0x01, 0x34, 0x3e, 0x01, 0x32, 0x1e, 0x01, 0x07, 0x33, 0x32, 0x36, 0x37, 0x3e, 0x01, 0x32, 0x16, 0x15, 0x14, 0x07, 0x0e, 0x01, 0x07, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3b, 0x01, 0x32, 0x36, 0x3d, 0x01, 0x34, 0x3e, 0x01, 0x37, 0x36, 0x35, 0x34, 0x26, 0x22, 0x07, 0x06, 0x07, 0x06, 0x16, 0x17, 0x32, 0x36, 0x34, 0x26, 0x22, 0x06, 0x14, 0x16, 0x01, 0x2c, 0x28, 0x45, 0x52, 0x45, 0x28, 0x28, 0x45, 0x52, 0x45, 0x28, 0xc5, 0x10, 0x01, 0x03, 0x01, 0x01, 0x0d, 0x15, 0x0e, 0x05, 0x03, 0x15, 0x05, 0x06, 0x03, 0x02, 0x0f, 0x02, 0x03, 0x07, 0x17, 0x05, 0x07, 0x1d, 0x29, 0x0e, 0x10, 0x01, 0x01, 0x03, 0x2e, 0x08, 0x0b, 0x0b, 0x11, 0x0a, 0x0a, 0x96, 0x29, 0x45, 0x28, 0x28, 0x45, 0x52, 0x45, 0x28, 0x28, 0x45, 0x04, 0x03, 0x02, 0x09, 0x0c, 0x0b, 0x0b, 0x08, 0x06, 0x04, 0x10, 0x07, 0x0a, 0x0c, 0x04, 0x02, 0x03, 0x03, 0x02, 0x02, 0x09, 0x0a, 0x11, 0x07, 0x0a, 0x0d, 0x15, 0x15, 0x09, 0x0b, 0x16, 0x02, 0x03, 0x79, 0x0a, 0x0f, 0x0a, 0x0a, 0x0f, 0x0a, 0x00, 0x04, 0x00, 0x00, 0xff, 0xff, 0x01, 0x2d, 0x01, 0x2d, 0x00, 0x25, 0x00, 0x34, 0x00, 0x3d, 0x00, 0x46, 0x00, 0x00, 0x37, 0x1e, 0x02, 0x33, 0x32, 0x3e, 0x01, 0x34, 0x2e, 0x01, 0x22, 0x0e, 0x01, 0x07, 0x17, 0x36, 0x17, 0x37, 0x35, 0x34, 0x36, 0x32, 0x16, 0x15, 0x14, 0x0e, 0x02, 0x23, 0x07, 0x16, 0x0e, 0x02, 0x2e, 0x01, 0x27, 0x17, 0x16, 0x3e, 0x01, 0x2e, 0x01, 0x07, 0x17, 0x1e, 0x01, 0x0e, 0x01, 0x2f, 0x01, 0x16, 0x37, 0x14, 0x16, 0x32, 0x36, 0x34, 0x26, 0x22, 0x06, 0x37, 0x32, 0x16, 0x14, 0x06, 0x22, 0x26, 0x34, 0x36, 0x06, 0x0a, 0x2a, 0x3b, 0x21, 0x29, 0x45, 0x28, 0x28, 0x45, 0x50, 0x43, 0x29, 0x03, 0x51, 0x0b, 0x0d, 0x25, 0x22, 0x2f, 0x21, 0x09, 0x10, 0x16, 0x0b, 0x35, 0x01, 0x0a, 0x12, 0x15, 0x13, 0x0d, 0x02, 0x1c, 0x0c, 0x18, 0x0a, 0x09, 0x18, 0x0c, 0x13, 0x0a, 0x07, 0x08, 0x12, 0x09, 0x12, 0x05, 0x51, 0x16, 0x20, 0x16, 0x16, 0x20, 0x16, 0x26, 0x0c, 0x11, 0x11, 0x18, 0x10, 0x10, 0x6a, 0x1f, 0x30, 0x1b, 0x28, 0x45, 0x52, 0x45, 0x28, 0x25, 0x40, 0x27, 0x21, 0x07, 0x01, 0x36, 0x01, 0x17, 0x22, 0x22, 0x17, 0x0c, 0x15, 0x10, 0x09, 0x25, 0x0b, 0x12, 0x0c, 0x03, 0x08, 0x10, 0x0a, 0x15, 0x04, 0x0a, 0x18, 0x18, 0x0a, 0x04, 0x08, 0x04, 0x12, 0x12, 0x07, 0x03, 0x08, 0x0b, 0x79, 0x10, 0x16, 0x16, 0x1f, 0x17, 0x17, 0x0d, 0x11, 0x17, 0x11, 0x11, 0x17, 0x11, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x07, 0x00, 0x0c, 0x00, 0x21, 0x00, 0x3d, 0x00, 0x00, 0x37, 0x34, 0x36, 0x3b, 0x01, 0x32, 0x16, 0x14, 0x06, 0x2b, 0x01, 0x22, 0x26, 0x37, 0x33, 0x1e, 0x02, 0x1d, 0x01, 0x14, 0x0e, 0x01, 0x2b, 0x01, 0x22, 0x2e, 0x01, 0x3d, 0x01, 0x34, 0x3e, 0x01, 0x33, 0x37, 0x23, 0x22, 0x06, 0x07, 0x06, 0x0f, 0x01, 0x15, 0x14, 0x16, 0x17, 0x16, 0x1f, 0x01, 0x33, 0x32, 0x36, 0x37, 0x36, 0x3f, 0x01, 0x35, 0x34, 0x26, 0x27, 0x26, 0x27, 0x2f, 0x05, 0x04, 0xbc, 0x04, 0x05, 0x05, 0x04, 0xbc, 0x04, 0x05, 0xd7, 0x01, 0x05, 0x08, 0x05, 0x04, 0x07, 0x07, 0xe2, 0x05, 0x08, 0x05, 0x04, 0x07, 0x08, 0xe1, 0xe1, 0x0d, 0x10, 0x04, 0x03, 0x01, 0x01, 0x0b, 0x08, 0x06, 0x07, 0x06, 0xe1, 0x0c, 0x10, 0x04, 0x03, 0x01, 0x01, 0x0b, 0x08, 0x06, 0x07, 0x2f, 0x04, 0x05, 0x05, 0x08, 0x05, 0x05, 0xc9, 0x01, 0x04, 0x07, 0x07, 0x71, 0x05, 0x08, 0x05, 0x04, 0x07, 0x07, 0x71, 0x06, 0x08, 0x05, 0x13, 0x0b, 0x08, 0x06, 0x07, 0x06, 0x70, 0x0d, 0x10, 0x04, 0x03, 0x01, 0x01, 0x0b, 0x08, 0x06, 0x07, 0x06, 0x70, 0x0d, 0x10, 0x04, 0x03, 0x01, 0x00, 0x04, 0xff, 0xff, 0x00, 0x00, 0x01, 0x2d, 0x01, 0x1a, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x29, 0x00, 0x33, 0x00, 0x00, 0x37, 0x22, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3b, 0x01, 0x32, 0x36, 0x3d, 0x01, 0x34, 0x26, 0x23, 0x27, 0x22, 0x06, 0x1d, 0x01, 0x14, 0x16, 0x3b, 0x01, 0x32, 0x36, 0x3d, 0x01, 0x34, 0x26, 0x23, 0x07, 0x34, 0x36, 0x3b, 0x01, 0x36, 0x16, 0x1d, 0x01, 0x21, 0x15, 0x21, 0x15, 0x14, 0x06, 0x2b, 0x01, 0x22, 0x26, 0x35, 0x42, 0x04, 0x06, 0x06, 0x04, 0xa8, 0x04, 0x06, 0x06, 0x04, 0xbd, 0x13, 0x1a, 0x1a, 0x13, 0xd2, 0x13, 0x1a, 0x1a, 0x13, 0xec, 0x0f, 0x0b, 0xd2, 0x0b, 0x0f, 0xfe, 0xfa, 0x01, 0x06, 0x0f, 0x0b, 0xd2, 0x0b, 0x0f, 0x5e, 0x06, 0x04, 0x12, 0x04, 0x06, 0x06, 0x04, 0x12, 0x04, 0x06, 0xbb, 0x1a, 0x12, 0xae, 0x12, 0x1a, 0x1a, 0x12, 0xae, 0x12, 0x1a, 0x2c, 0x0b, 0x0e, 0x01, 0x0f, 0x0b, 0x0c, 0x13, 0x8f, 0x0b, 0x0f, 0x0f, 0x0b, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x2c, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x13, 0x07, 0x15, 0x33, 0x07, 0x17, 0x35, 0x23, 0x1f, 0x02, 0x3d, 0x01, 0x07, 0x15, 0x33, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x88, 0x01, 0xa3, 0xa3, 0xa3, 0x01, 0x12, 0x10, 0x66, 0x73, 0x11, 0x78, 0x01, 0x78, 0x17, 0x8f, 0x9d, 0x17, 0x79, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x07, 0x00, 0x1b, 0x00, 0x00, 0x37, 0x26, 0x34, 0x36, 0x32, 0x1f, 0x01, 0x37, 0x36, 0x32, 0x16, 0x14, 0x0f, 0x01, 0x17, 0x16, 0x14, 0x06, 0x22, 0x2f, 0x01, 0x07, 0x06, 0x22, 0x26, 0x34, 0x3f, 0x01, 0x28, 0x03, 0x06, 0x08, 0x03, 0x60, 0x60, 0x03, 0x08, 0x06, 0x03, 0x61, 0x61, 0x03, 0x06, 0x08, 0x03, 0x60, 0x60, 0x03, 0x08, 0x06, 0x03, 0x61, 0xf6, 0x03, 0x08, 0x06, 0x03, 0x61, 0x61, 0x03, 0x06, 0x08, 0x03, 0x60, 0x60, 0x03, 0x08, 0x06, 0x03, 0x61, 0x61, 0x03, 0x06, 0x08, 0x03, 0x60, }; extern const unsigned char ttf_bootstrap_icons_data[]; #define ttf_bootstrap_icons_size 3496 ================================================ FILE: app/lvgl/fonts/bootstrap-icons/symbols.h ================================================ #pragma once #define BS_SYMBOL_CARET_DOWN_FILL "\xef\x88\xa9" #define BS_SYMBOL_COLLECTION "\xef\x8b\x8c" #define BS_SYMBOL_CONTROLLER "\xef\x8b\x94" #define BS_SYMBOL_DISPLAY "\xef\x8c\x82" #define BS_SYMBOL_GEAR_FILL "\xef\x8f\xa2" #define BS_SYMBOL_PLAY_BTN "\xef\x93\xb1" #define BS_SYMBOL_PLAY_CIRCLE_FILL "\xef\x93\xb2" #define BS_SYMBOL_POWER "\xef\x93\xbf" #define BS_SYMBOL_QUESTION_CIRCLE_FILL "\xef\x94\x84" #define BS_SYMBOL_TV "\xef\x97\xad" #define BS_SYMBOL_X_LG "\xef\x99\x99" #define BS_SYMBOL_APPLE "\xef\x99\x9b" #define BS_SYMBOL_WINDOWS "\xef\x99\x9e" #define BS_SYMBOL_STEAM "\xef\x9b\x81" #define BS_SYMBOL_WINDOW_DESKTOP "\xef\x9b\x8e" ================================================ FILE: app/lvgl/keypad.c ================================================ #include "mouse.h" #include "logging.h" #include "app.h" #include "ui/app_ui.h" #include typedef struct keyboard_state_t { app_t *app; bool ignore_input; /** * Key code of last pressed key event, will be 0 if released */ uint32_t key; /** * Key code of last key event, no matter its released or not */ uint32_t ev_key; lv_indev_state_t state; bool changed; } keyboard_state_t; static void read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data); static void handle_esc(keyboard_state_t *state); static uint32_t key_from_keysym(const SDL_Keysym *keysym); static uint32_t key_from_cbutton(uint8_t button); lv_indev_t *app_indev_keypad_init(app_t *app) { lv_indev_drv_t *driver = malloc(sizeof(lv_indev_drv_t)); lv_indev_drv_init(driver); driver->type = LV_INDEV_TYPE_KEYPAD; driver->read_cb = read_cb; keyboard_state_t *state = calloc(1, sizeof(keyboard_state_t)); state->app = app; driver->user_data = state; lv_indev_t *indev = lv_indev_drv_register(driver); lv_indev_set_group(indev, lv_group_get_default()); return indev; } void app_indev_keypad_deinit(lv_indev_t *indev) { lv_indev_drv_t *driver = indev->driver; lv_indev_delete(indev); free(driver->user_data); free(driver); } void app_indev_keypad_set_ignore(lv_indev_t *indev, bool ignore) { keyboard_state_t *state = indev->driver->user_data; state->ignore_input = ignore; } void app_indev_keypad_sdl_key_event(lv_indev_t *indev, const SDL_KeyboardEvent *event) { keyboard_state_t *state = indev->driver->user_data; uint32_t key = key_from_keysym(&event->keysym); if (key == 0) { #ifdef SDL_WEBOS_SCANCODE_EXIT if (event->state == SDL_RELEASED && event->keysym.scancode == SDL_WEBOS_SCANCODE_EXIT) { app_post_event(state->app, APP_UI_NAV_QUIT, NULL, NULL); } #endif return; } if (event->state == SDL_PRESSED) { if (state->key == 0) { state->key = state->ev_key = key; state->state = LV_INDEV_STATE_PRESSED; state->changed = true; } } else if (event->state == SDL_RELEASED) { if (state->key == key) { state->ev_key = key; state->key = 0; state->state = LV_INDEV_STATE_RELEASED; state->changed = true; } } } void app_indev_keypad_sdl_cbutton_event(lv_indev_t *indev, const SDL_ControllerButtonEvent *event) { uint32_t key = key_from_cbutton(event->button); if (key == 0) { return; } keyboard_state_t *state = indev->driver->user_data; if (event->state == SDL_PRESSED) { if (state->key == 0) { state->key = state->ev_key = key; state->state = LV_INDEV_STATE_PRESSED; state->changed = true; } } else if (event->state == SDL_RELEASED) { if (state->key == key) { state->ev_key = key; state->key = 0; state->state = LV_INDEV_STATE_RELEASED; state->changed = true; } } } void app_indev_keypad_inject_key(lv_indev_t *indev, lv_key_t key, bool pressed) { keyboard_state_t *state = indev->driver->user_data; if (pressed) { if (state->key == 0) { state->key = state->ev_key = key; state->state = LV_INDEV_STATE_PRESSED; state->changed = true; } } else { if (state->key == key) { state->ev_key = key; state->key = 0; state->state = LV_INDEV_STATE_RELEASED; state->changed = true; } } } static void read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) { keyboard_state_t *state = drv->user_data; if (state->changed && state->ev_key == LV_KEY_ESC) { handle_esc(state); } state->changed = false; data->key = state->key; if (state->ignore_input) { data->state = false; } else { data->state = state->state; } data->continue_reading = false; } /** * Special case for esc keys * @param state */ static void handle_esc(keyboard_state_t *state) { lv_group_t *group = app_ui_get_input_group(state->app->ui); lv_obj_t *focused = lv_group_get_focused(group); if (focused == NULL) { // Next key event will not be handled by any object. Send global BACK event if (state->state == LV_INDEV_STATE_RELEASED) { app_post_event(state->app, APP_UI_NAV_BACK, NULL, NULL); } return; } // TODO: for things like dropdown, cancel event will be sent when ESC pressed. // So we can compare PRESS and RELEASE event to see if it's closed or not. Send BACK event if no state change. if (state->state == LV_INDEV_STATE_PRESSED) { // Backup object state (e.g. is dropdown opened) } else { // Compare object state, and send BACK event if no change. app_post_event(state->app, APP_UI_NAV_BACK, NULL, NULL); } } static uint32_t key_from_keysym(const SDL_Keysym *keysym) { switch (keysym->sym) { case SDLK_UP: return LV_KEY_UP; case SDLK_DOWN: return LV_KEY_DOWN; case SDLK_LEFT: return LV_KEY_LEFT; case SDLK_RIGHT: return LV_KEY_RIGHT; case SDLK_RETURN: case SDLK_RETURN2: case SDLK_KP_ENTER: return LV_KEY_ENTER; case SDLK_ESCAPE: return LV_KEY_ESC; case SDLK_TAB: return keysym->mod & KMOD_SHIFT ? LV_KEY_PREV : LV_KEY_NEXT; default: #ifdef SDL_WEBOS_SCANCODE_BACK switch ((int) keysym->scancode) { case SDL_WEBOS_SCANCODE_BACK: return LV_KEY_ESC; case SDL_WEBOS_SCANCODE_CH_UP: return LV_KEY_PREV; case SDL_WEBOS_SCANCODE_CH_DOWN: return LV_KEY_NEXT; default: break; } #endif return 0; } } static uint32_t key_from_cbutton(uint8_t button) { switch (button) { case SDL_CONTROLLER_BUTTON_DPAD_UP: return LV_KEY_UP; case SDL_CONTROLLER_BUTTON_DPAD_DOWN: return LV_KEY_DOWN; case SDL_CONTROLLER_BUTTON_DPAD_LEFT: return LV_KEY_LEFT; case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: return LV_KEY_RIGHT; case SDL_CONTROLLER_BUTTON_A: return LV_KEY_ENTER; case SDL_CONTROLLER_BUTTON_B: return LV_KEY_ESC; case SDL_CONTROLLER_BUTTON_BACK: return LV_KEY_NEXT; default: return 0; } } ================================================ FILE: app/lvgl/keypad.h ================================================ #pragma once #include #include typedef struct app_t app_t; lv_indev_t *app_indev_keypad_init(app_t *app); void app_indev_keypad_deinit(lv_indev_t *indev); void app_indev_keypad_set_ignore(lv_indev_t *indev, bool ignore); void app_indev_keypad_sdl_key_event(lv_indev_t *indev, const SDL_KeyboardEvent *event); void app_indev_keypad_sdl_cbutton_event(lv_indev_t *indev, const SDL_ControllerButtonEvent *event); void app_indev_keypad_inject_key(lv_indev_t *indev, lv_key_t key, bool pressed); ================================================ FILE: app/lvgl/lv_conf.h ================================================ #ifndef LV_CONF_H #define LV_CONF_H #include /* Use 32-bit color depth */ #define LV_COLOR_DEPTH 32 #define LV_DPI_DEF 360 /* Use stdlib to allocate/free memory */ #define LV_MEM_CUSTOM 1 #define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ #define LV_MEM_CUSTOM_ALLOC malloc #define LV_MEM_CUSTOM_FREE free #define LV_MEM_CUSTOM_REALLOC realloc /* Use the standard `memcpy` and `memset` instead of LVGL's own functions. */ #define LV_MEMCPY_MEMSET_STD 1 #define LV_DISP_DEF_REFR_PERIOD 17 #define LV_INDEV_DEF_READ_PERIOD 5 #define LV_USE_REFR_DEBUG 0 /* Let LVGL call SDL_GetTicks automatically so we can skip creating a separate timer thread. */ #define LV_TICK_CUSTOM 1 #define LV_TICK_CUSTOM_INCLUDE #define LV_TICK_CUSTOM_SYS_TIME_EXPR (SDL_GetTicks()) #define LV_DRAW_COMPLEX 1 #define LV_SHADOW_CACHE_SIZE 0 #define LV_IMG_CACHE_DEF_SIZE 0 #define LV_GRADIENT_MAX_STOPS 8 /* Use SDL draw backend */ #define LV_USE_GPU_SDL 1 #define LV_GPU_SDL_INCLUDE_PATH #define LV_GPU_SDL_CUSTOM_BLEND_MODE 0 /*Change the built in (v)snprintf functions*/ #define LV_SPRINTF_CUSTOM 1 #if LV_SPRINTF_CUSTOM # define LV_SPRINTF_INCLUDE # define lv_snprintf snprintf # define lv_vsnprintf vsnprintf #else /*LV_SPRINTF_CUSTOM*/ # define LV_SPRINTF_USE_FLOAT 0 #endif /*LV_SPRINTF_CUSTOM*/ /*Enable the log module*/ #define LV_USE_LOG 1 #if LV_USE_LOG /*How important log should be added: *LV_LOG_LEVEL_TRACE A lot of logs to give detailed information *LV_LOG_LEVEL_INFO Log important events *LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail *LV_LOG_LEVEL_USER Only logs added by the user *LV_LOG_LEVEL_NONE Do not log anything*/ # define LV_LOG_LEVEL LV_LOG_LEVEL_WARN /*1: Print the log with 'printf'; *0: User need to register a callback with `lv_log_register_print_cb()`*/ # define LV_LOG_PRINTF 0 /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ # define LV_LOG_TRACE_MEM 1 # define LV_LOG_TRACE_TIMER 1 # define LV_LOG_TRACE_INDEV 1 # define LV_LOG_TRACE_DISP_REFR 1 # define LV_LOG_TRACE_EVENT 1 # define LV_LOG_TRACE_OBJ_CREATE 1 # define LV_LOG_TRACE_LAYOUT 1 # define LV_LOG_TRACE_ANIM 1 #endif /*LV_USE_LOG*/ /* Abort on assertion failure */ #define LV_ASSERT_HANDLER_INCLUDE #define LV_ASSERT_HANDLER abort(); #define LV_USE_USER_DATA 1 /* Use 32bit coordinates */ #define LV_USE_LARGE_COORD 1 #define LV_USE_FREETYPE 1 #define LV_FONT_UNSCII_16 1 #define LV_FONT_DEFAULT &lv_font_unscii_16 #define LV_TXT_ENC LV_TXT_ENC_UTF8 /*================== * WIDGET USAGE *================*/ /*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/ #define LV_USE_ARC 1 #define LV_USE_ANIMIMG 0 #define LV_USE_BAR 1 #define LV_USE_BTN 1 #define LV_USE_BTNMATRIX 1 #define LV_USE_CANVAS 1 #define LV_USE_CHECKBOX 1 #define LV_USE_DROPDOWN 1 /*Requires: lv_label*/ #define LV_USE_IMG 1 /*Requires: lv_label*/ #define LV_USE_LABEL 1 #if LV_USE_LABEL # define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/ # define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/ #endif #define LV_USE_LINE 1 #define LV_USE_ROLLER 0 /*Requires: lv_label*/ #if LV_USE_ROLLER # define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/ #endif #define LV_USE_SLIDER 1 /*Requires: lv_bar*/ #define LV_USE_SWITCH 0 #define LV_USE_TEXTAREA 0 /*Requires: lv_label*/ #if LV_USE_TEXTAREA != 0 # define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ #endif #define LV_USE_TABLE 0 /*================== * EXTRA COMPONENTS *==================*/ /*----------- * Widgets *----------*/ #define LV_USE_CALENDAR 0 #if LV_USE_CALENDAR # define LV_CALENDAR_WEEK_STARTS_MONDAY 0 # if LV_CALENDAR_WEEK_STARTS_MONDAY # define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"} # else # define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"} # endif # define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} # define LV_USE_CALENDAR_HEADER_ARROW 1 # define LV_USE_CALENDAR_HEADER_DROPDOWN 1 #endif /*LV_USE_CALENDAR*/ #define LV_USE_CHART 0 #define LV_USE_COLORWHEEL 0 #define LV_USE_GRIDVIEW 1 #define LV_USE_IMGBTN 1 #define LV_USE_KEYBOARD 0 #define LV_USE_LED 1 #define LV_USE_LIST 1 #define LV_USE_METER 0 #define LV_USE_MSGBOX 1 #define LV_USE_SPINBOX 0 #define LV_USE_SPINNER 1 #define LV_USE_TABVIEW 1 #define LV_USE_TILEVIEW 0 #define LV_USE_WIN 1 #define LV_USE_SPAN 1 #if LV_USE_SPAN /*A line text can contain maximum num of span descriptor */ # define LV_SPAN_SNIPPET_STACK_SIZE 64 #endif /*----------- * Themes *----------*/ /*A simple, impressive and very complete theme*/ #define LV_USE_THEME_DEFAULT 0 #if LV_USE_THEME_DEFAULT /*0: Light mode; 1: Dark mode*/ # define LV_THEME_DEFAULT_DARK 0 /*1: Enable grow on press*/ # define LV_THEME_DEFAULT_GROW 0 /*Default transition time in [ms]*/ # define LV_THEME_DEFAULT_TRANSITON_TIME 80 #endif /*LV_USE_THEME_DEFAULT*/ /*An very simple them that is a good starting point for a custom theme*/ #define LV_USE_THEME_BASIC 1 /*A theme designed for monochrome displays*/ #define LV_USE_THEME_MONO 0 /*----------- * Layouts *----------*/ /*A layout similar to Flexbox in CSS.*/ #define LV_USE_FLEX 1 /*A layout similar to Grid in CSS.*/ #define LV_USE_GRID 1 /*----------- * Extras *----------*/ #define LV_USE_FRAGMENT 1 #define LV_USE_QRCODE 1 /*---------- * Icon font symbol overrides *---------*/ #define LV_SYMBOL_DOWN "\xef\x88\xa9" /*BS_SYMBOL_CARET_DOWN_FILL*/ #endif /*LV_CONF_H*/ ================================================ FILE: app/lvgl/mouse.c ================================================ #include "mouse.h" #include static void read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data); lv_indev_t *app_lv_mouse_indev_init() { lv_indev_drv_t *driver = malloc(sizeof(lv_indev_drv_t)); lv_indev_drv_init(driver); driver->type = LV_INDEV_TYPE_POINTER; driver->read_cb = read_cb; lv_indev_t *indev = lv_indev_drv_register(driver); lv_indev_set_group(indev, lv_group_get_default()); return indev; } void app_lv_mouse_indev_deinit(lv_indev_t *indev) { lv_indev_drv_t *driver = indev->driver; lv_indev_delete(indev); free(driver); } static void read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) { int x, y; Uint32 buttons = SDL_GetMouseState(&x, &y); data->state = (buttons & SDL_BUTTON_LEFT) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; data->point.x = x; data->point.y = y; data->continue_reading = false; } ================================================ FILE: app/lvgl/mouse.h ================================================ #pragma once #include lv_indev_t *app_lv_mouse_indev_init(); void app_lv_mouse_indev_deinit(lv_indev_t *indev); ================================================ FILE: app/lvgl/theme.c ================================================ #include "theme.h" #include "config.h" #include "ui/app_ui.h" #include "ext/msgbox_ext.h" static void apply_cb(lv_theme_t *theme, lv_obj_t *obj); typedef struct theme_context_t { app_ui_t *ui; lv_style_t scr; lv_style_t obj; lv_style_t focused; lv_style_t label; lv_style_t btn; lv_style_t btn_focused; lv_style_t btn_pressed; lv_style_t dropdown_list; lv_style_t modal_bg; lv_style_t msgbox; lv_style_t msgbox_backdrop; lv_style_t msgbox_title; lv_style_t msgbox_text; lv_style_t msgbox_btns; lv_style_t msgbox_btns_item; lv_style_t msgbox_btns_item_focused; lv_style_t msgbox_btns_item_pressed; lv_style_t win_title; lv_style_t win_btn; lv_style_t win_header; lv_style_t win_content; lv_style_t arc_indic; lv_style_t arc_indic_primary; } theme_context_t; void app_theme_init(lv_theme_t *theme, app_ui_t *ui) { theme_context_t *styles = lv_mem_alloc(sizeof(theme_context_t)); lv_memset_00(styles, sizeof(theme_context_t)); styles->ui = ui; theme->font_small = ui->font.small; theme->font_normal = ui->font.body; theme->font_large = ui->font.heading3; lv_color_t primary_color = lv_color_hex(0x1387b8); lv_color_t accent_color = lv_color_lighten(primary_color, 1); lv_color_t focus_color = lv_color_make(31, 169, 255); theme->color_primary = primary_color; lv_style_init(&styles->scr); const static lv_grad_dsc_t grad = { .dir = LV_GRAD_DIR_VER, .stops = { {.color = {.ch = {.red = 0x11, .green = 0x1d, .blue = 0x2e, .alpha = 255}}, .frac = 0}, {.color = {.ch = {.red = 0x05, .green = 0x18, .blue = 0x39, .alpha = 255}}, .frac = 63}, {.color = {.ch = {.red = 0x0a, .green = 0x1b, .blue = 0x48, .alpha = 255}}, .frac = 119}, {.color = {.ch = {.red = 0x13, .green = 0x2e, .blue = 0x62, .alpha = 255}}, .frac = 172}, {.color = {.ch = {.red = 0x14, .green = 0x4b, .blue = 0x7e, .alpha = 255}}, .frac = 216}, {.color = {.ch = {.red = 0x13, .green = 0x64, .blue = 0x97, .alpha = 255}}, .frac = 255}, }, .stops_count = 6, }; lv_style_set_bg_grad(&styles->scr, &grad); lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER); lv_style_init(&styles->obj); lv_style_set_text_color(&styles->obj, lv_color_white()); lv_style_set_pad_gap(&styles->obj, LV_DPX(10)); lv_style_init(&styles->focused); lv_style_set_outline_width(&styles->focused, LV_DPX(2)); lv_style_set_outline_opa(&styles->focused, LV_OPA_COVER); lv_style_set_outline_color(&styles->focused, primary_color); lv_style_set_outline_pad(&styles->focused, LV_DPX(5)); lv_style_set_radius(&styles->focused, LV_DPX(5)); lv_style_init(&styles->label); lv_style_set_text_font(&styles->label, ui->font.body); lv_style_init(&styles->btn); lv_style_set_pad_all(&styles->btn, LV_DPX(10)); lv_style_set_bg_color(&styles->btn, lv_color_white()); lv_style_set_bg_opa(&styles->btn, LV_OPA_20); lv_style_init(&styles->btn_focused); lv_style_set_bg_color(&styles->btn_focused, focus_color); lv_style_set_bg_opa(&styles->btn_focused, LV_OPA_COVER); lv_style_init(&styles->btn_pressed); lv_style_set_bg_color(&styles->btn_pressed, lv_color_darken(focus_color, LV_OPA_20)); lv_style_set_bg_opa(&styles->btn_pressed, LV_OPA_COVER); lv_style_init(&styles->dropdown_list); lv_style_set_pad_ver(&styles->dropdown_list, LV_DPX(20)); lv_style_set_pad_hor(&styles->dropdown_list, LV_DPX(15)); lv_style_set_text_line_space(&styles->dropdown_list, LV_DPX(20)); lv_style_init(&styles->modal_bg); lv_style_set_bg_color(&styles->modal_bg, lv_color_hex(0x25282e)); lv_style_set_bg_opa(&styles->modal_bg, LV_OPA_COVER); lv_style_set_shadow_color(&styles->modal_bg, lv_color_black()); lv_style_set_shadow_opa(&styles->modal_bg, LV_OPA_30); lv_style_set_shadow_width(&styles->modal_bg, LV_DPX(20)); lv_style_set_shadow_ofs_y(&styles->modal_bg, LV_DPX(10)); lv_style_set_radius(&styles->modal_bg, LV_DPX(5)); lv_style_set_min_width(&styles->modal_bg, LV_DPX(480)); lv_style_set_max_width(&styles->modal_bg, LV_DPX(576)); lv_style_init(&styles->msgbox); lv_style_set_pad_top(&styles->msgbox, LV_DPX(16)); lv_style_set_pad_bottom(&styles->msgbox, LV_DPX(8)); lv_style_set_pad_hor(&styles->msgbox, LV_DPX(8)); lv_style_set_flex_main_place(&styles->msgbox, LV_FLEX_ALIGN_END); lv_style_init(&styles->msgbox_backdrop); lv_style_set_bg_color(&styles->msgbox_backdrop, lv_color_black()); lv_style_set_bg_opa(&styles->msgbox_backdrop, LV_OPA_30); lv_style_init(&styles->msgbox_title); lv_style_set_text_font(&styles->msgbox_title, ui->font.heading2); lv_style_set_text_letter_space(&styles->msgbox_title, LV_DPX(1)); lv_style_set_pad_hor(&styles->msgbox_title, LV_DPX(16)); lv_style_init(&styles->msgbox_text); lv_style_set_text_font(&styles->msgbox_text, ui->font.body); lv_style_set_pad_top(&styles->msgbox_text, LV_DPX(8)); lv_style_set_pad_hor(&styles->msgbox_text, LV_DPX(16)); lv_style_set_pad_bottom(&styles->msgbox_text, LV_DPX(16)); lv_style_init(&styles->msgbox_btns); lv_style_init(&styles->msgbox_btns_item); lv_style_set_radius(&styles->msgbox_btns_item, LV_DPX(2)); lv_style_set_text_font(&styles->msgbox_btns_item, ui->font.small); lv_style_set_text_color(&styles->msgbox_btns_item, accent_color); lv_style_init(&styles->msgbox_btns_item_focused); lv_style_set_bg_color(&styles->msgbox_btns_item_focused, primary_color); lv_style_set_bg_opa(&styles->msgbox_btns_item_focused, LV_OPA_10); lv_style_init(&styles->msgbox_btns_item_pressed); lv_style_set_bg_color(&styles->msgbox_btns_item_pressed, primary_color); lv_style_set_bg_opa(&styles->msgbox_btns_item_pressed, LV_OPA_20); lv_style_init(&styles->win_title); lv_style_set_text_font(&styles->win_title, ui->font.heading2); lv_style_init(&styles->win_btn); lv_style_set_text_font(&styles->win_btn, ui->iconfont.heading3); lv_style_set_radius(&styles->win_btn, LV_RADIUS_CIRCLE); lv_style_set_min_height(&styles->win_btn, LV_DPX(40)); lv_style_set_max_height(&styles->win_btn, LV_DPX(40)); lv_style_init(&styles->win_header); lv_style_set_min_height(&styles->win_header, LV_DPX(60)); lv_style_set_pad_hor(&styles->win_header, LV_DPX(30)); lv_style_set_pad_top(&styles->win_header, LV_DPX(20)); lv_style_set_pad_bottom(&styles->win_header, LV_DPX(10)); lv_style_init(&styles->win_content); lv_style_set_pad_hor(&styles->win_content, LV_DPX(30)); lv_style_set_pad_top(&styles->win_content, LV_DPX(10)); lv_style_set_pad_bottom(&styles->win_content, LV_DPX(15)); lv_style_init(&styles->arc_indic); lv_style_set_arc_color(&styles->arc_indic, lv_color_lighten(accent_color, LV_OPA_80)); lv_style_set_arc_opa(&styles->arc_indic, LV_OPA_20); lv_style_set_arc_width(&styles->arc_indic, LV_DPX(15)); lv_style_set_arc_rounded(&styles->arc_indic, true); lv_style_init(&styles->arc_indic_primary); lv_style_set_arc_color(&styles->arc_indic_primary, accent_color); lv_style_set_arc_opa(&styles->arc_indic_primary, LV_OPA_COVER); theme->user_data = styles; lv_theme_set_apply_cb(theme, apply_cb); } void app_theme_deinit(lv_theme_t *theme) { theme_context_t *styles = theme->user_data; lv_style_reset(&styles->arc_indic_primary); lv_style_reset(&styles->arc_indic); lv_style_reset(&styles->win_content); lv_style_reset(&styles->win_header); lv_style_reset(&styles->win_btn); lv_style_reset(&styles->win_title); lv_style_reset(&styles->msgbox_btns_item_pressed); lv_style_reset(&styles->msgbox_btns_item_focused); lv_style_reset(&styles->msgbox_btns_item); lv_style_reset(&styles->msgbox_btns); lv_style_reset(&styles->msgbox_text); lv_style_reset(&styles->msgbox_title); lv_style_reset(&styles->msgbox_backdrop); lv_style_reset(&styles->msgbox); lv_style_reset(&styles->modal_bg); lv_style_reset(&styles->dropdown_list); lv_style_reset(&styles->btn_focused); lv_style_reset(&styles->btn_pressed); lv_style_reset(&styles->btn); lv_style_reset(&styles->focused); lv_style_reset(&styles->obj); lv_style_reset(&styles->scr); free(styles); } lv_coord_t app_win_header_size(lv_theme_t *theme) { if (theme->apply_cb != apply_cb) { return LV_SIZE_CONTENT; } theme_context_t *styles = theme->user_data; lv_style_value_t value; if (lv_style_get_prop(&styles->win_header, LV_STYLE_MIN_HEIGHT, &value) != LV_RES_OK) { return LV_SIZE_CONTENT; } return value.num; } lv_obj_t *app_lv_win_create(lv_obj_t *parent) { lv_theme_t *theme = lv_disp_get_theme(lv_obj_get_disp(parent)); lv_obj_t *win = lv_win_create(parent, app_win_header_size(theme)); lv_obj_t *header = lv_win_get_header(win); lv_obj_clear_flag(header, LV_OBJ_FLAG_SCROLLABLE); #if IHSPLAY_WIP_FEATURES lv_obj_t *footer = lv_obj_create(win); lv_obj_set_style_bg_opa(footer, LV_OPA_30, 0); lv_obj_set_style_bg_color(footer, lv_color_black(), 0); lv_obj_set_style_pad_hor(footer, lv_obj_get_style_pad_left(header, 0), 0); lv_obj_set_size(footer, LV_PCT(100), LV_DPX(40)); lv_obj_set_flex_flow(footer, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(footer, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t *prompt_a = lv_label_create(footer); lv_label_set_text(prompt_a, "(A) Open"); lv_obj_t *prompt_b = lv_label_create(footer); lv_label_set_text(prompt_b, "(B) Back"); #endif return win; } static void apply_cb(lv_theme_t *theme, lv_obj_t *obj) { theme_context_t *styles = theme->user_data; lv_obj_t *parent = lv_obj_get_parent(obj); if (parent == NULL) { lv_obj_add_style(obj, &styles->scr, 0); return; } lv_obj_add_style(obj, &styles->obj, 0); if (lv_obj_has_class(obj, &lv_btn_class)) { lv_obj_add_style(obj, &styles->btn, 0); lv_obj_add_style(obj, &styles->btn_pressed, LV_STATE_PRESSED); lv_obj_add_style(obj, &styles->btn_focused, LV_STATE_FOCUS_KEY); if (parent->parent != NULL && lv_obj_check_type(parent->parent, &lv_win_class)) { if (lv_win_get_header(parent->parent) == obj->parent) { lv_obj_add_style(obj, &styles->win_btn, 0); } } } else if (lv_obj_has_class(obj, &lv_label_class)) { lv_obj_add_style(obj, &styles->label, 0); if (lv_obj_check_type(parent, &lv_msgbox_class)) { if (lv_msgbox_get_title(parent) == NULL && lv_msgbox_get_content(parent) == NULL) { // Title was not assigned, and the content was not created either. Assume this is the title lv_obj_add_style(obj, &styles->msgbox_title, 0); } } else if (parent->parent != NULL) { if (lv_obj_check_type(parent->parent, &lv_msgbox_class)) { if (lv_msgbox_get_content(parent->parent) == lv_obj_get_parent(obj)) { lv_obj_add_style(obj, &styles->msgbox_text, 0); } } else if (lv_obj_check_type(parent->parent, &lv_win_class)) { if (lv_win_get_header(parent->parent) == lv_obj_get_parent(obj)) { lv_obj_add_style(obj, &styles->win_title, 0); } } } } else if (lv_obj_has_class(obj, &lv_dropdown_class)) { lv_obj_add_style(obj, &styles->label, 0); lv_obj_add_style(obj, &styles->focused, LV_STATE_FOCUS_KEY); } else if (lv_obj_has_class(obj, &lv_dropdownlist_class)) { lv_obj_add_style(obj, &styles->modal_bg, 0); lv_obj_add_style(obj, &styles->modal_bg, 0); lv_obj_add_style(obj, &styles->label, LV_PART_SELECTED); lv_obj_add_style(obj, &styles->dropdown_list, 0); lv_obj_add_style(obj, &styles->dropdown_list, LV_PART_SELECTED); } else if (lv_obj_has_class(obj, &lv_btnmatrix_class)) { if (lv_obj_check_type(parent, &lv_msgbox_class)) { lv_obj_add_style(obj, &styles->msgbox_btns, 0); lv_obj_add_style(obj, &styles->msgbox_btns_item, LV_PART_ITEMS); lv_obj_add_style(obj, &styles->msgbox_btns_item_focused, LV_PART_ITEMS | LV_STATE_FOCUSED); lv_obj_add_style(obj, &styles->msgbox_btns_item_pressed, LV_PART_ITEMS | LV_STATE_PRESSED); } } else if (lv_obj_check_type(obj, &lv_msgbox_class)) { lv_obj_add_style(obj, &styles->modal_bg, 0); lv_obj_add_style(obj, &styles->msgbox, 0); msgbox_inject_nav(styles->ui, obj); } else if (lv_obj_check_type(obj, &lv_msgbox_backdrop_class)) { lv_obj_add_style(obj, &styles->msgbox_backdrop, 0); } else if (lv_obj_check_type(obj, &lv_spinner_class)) { lv_obj_add_style(obj, &styles->arc_indic, 0); lv_obj_add_style(obj, &styles->arc_indic, LV_PART_INDICATOR); lv_obj_add_style(obj, &styles->arc_indic_primary, LV_PART_INDICATOR); } else if (lv_obj_check_type(obj, &lv_arc_class)) { lv_obj_add_style(obj, &styles->arc_indic, 0); lv_obj_add_style(obj, &styles->arc_indic, LV_PART_INDICATOR); lv_obj_add_style(obj, &styles->arc_indic_primary, LV_PART_INDICATOR); } else if (lv_obj_check_type(parent, &lv_win_class)) { if (obj == lv_win_get_header(parent)) { lv_obj_add_style(obj, &styles->win_header, 0); } else if (obj == lv_win_get_content(parent)) { lv_obj_add_style(obj, &styles->win_content, 0); } } } ================================================ FILE: app/lvgl/theme.h ================================================ #pragma once #include typedef struct app_ui_t app_ui_t; void app_theme_init(lv_theme_t *theme, app_ui_t *ui); void app_theme_deinit(lv_theme_t *theme); lv_coord_t app_win_header_size(lv_theme_t *theme); lv_obj_t *app_lv_win_create(lv_obj_t *parent); ================================================ FILE: app/main.c ================================================ #include #include #include "app.h" #include "config.h" #include "ui/app_ui.h" #include "lvgl/display.h" #include "lvgl/ext/lv_dir_focus.h" #include "ss4s.h" #include "backend/host_manager.h" #include "backend/stream_manager.h" #include "backend/input_manager.h" #include "logging.h" #include "logging_ext_ss4s.h" #include "logging_ext_sdl.h" #include "logging_ext_lvgl.h" #include "os_info.h" #if IHSPLAY_FEATURE_LIBCEC #include "cec_sdl.h" #endif static void process_events(); static void logging_init(); static app_t *app = NULL; static bool use_windowed(); int main(int argc, char *argv[]) { logging_init(); app_preinit(argc, argv); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC); os_info_t os_info; if (os_info_get(&os_info) == 0) { char *str = os_info_str(&os_info); commons_log_info("APP", "System: %s", str); free(str); } app_settings_t settings; app_settings_init(&settings, &os_info); SS4S_Config ss4s_config = { .audioDriver = settings.audio_driver, .videoDriver = settings.video_driver, .loggingFunction = commons_ss4s_logf, }; SS4S_Init(argc, argv, &ss4s_config); IHS_Init(); SDL_RegisterEvents((APP_EVENT_LAST - APP_EVENT_BEGIN) + 1); lv_init(); lv_dir_focus_register(); int w = 1920, h = 1080; SDL_DisplayMode mode; SDL_GetDisplayMode(0, 0, &mode); /* Get display size. Fallback to 1920x1080 if failed. */ if (mode.w > 0 && mode.h > 0) { w = mode.w; h = mode.h; } Uint32 fullscreen_flag; #ifdef TARGET_WEBOS fullscreen_flag = SDL_WINDOW_FULLSCREEN; #elif IHSPLAY_FEATURE_FORCE_FULLSCREEN fullscreen_flag = SDL_WINDOW_FULLSCREEN_DESKTOP; #else bool windowed = use_windowed(); if (windowed) { w = 1920; h = 1080; fullscreen_flag = SDL_WINDOW_RESIZABLE; } else { fullscreen_flag = SDL_WINDOW_FULLSCREEN_DESKTOP; } #endif /* Caveat: Don't use SDL_WINDOW_FULLSCREEN_DESKTOP on webOS. On older platforms it's not supported. */ SDL_Window *window = SDL_CreateWindow("IHSplay", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_ALLOW_HIGHDPI | fullscreen_flag); SS4S_PostInit(argc, argv); lv_disp_t *disp = app_lv_disp_init(window); lv_disp_set_default(disp); app = app_create(&settings, disp); app->os_info = os_info; #if IHSPLAY_FEATURE_LIBCEC cec_sdl_ctx_t cec; cec_sdl_init(&cec, "IHSplay"); #endif while (app->running) { process_events(); uint32_t next_delay = lv_task_handler(); SDL_Delay(stream_manager_is_active(app->stream_manager) ? 1 : next_delay); } // Drain remaining events process_events(); #if IHSPLAY_FEATURE_LIBCEC cec_sdl_deinit(&cec); #endif app_destroy(app); app_lv_disp_deinit(disp); app_settings_deinit(&settings); SDL_DestroyWindow(window); IHS_Quit(); SS4S_Quit(); SDL_Quit(); commons_logging_deinit(); os_info_clear(&os_info); return 0; } static void process_events() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYUP: case SDL_KEYDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_CONTROLLERAXISMOTION: case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: { bool intercept_by_stream = stream_manager_intercept_event(app->stream_manager, &event); if (!intercept_by_stream) { app_sdl_input_event(app, &event); } stream_manager_handle_event(app->stream_manager, &event); break; } case SDL_APP_WILLENTERBACKGROUND: { #if IHSPLAY_FEATURE_FORCE_FULLSCREEN stream_manager_stop_active(app->stream_manager); #endif break; } case SDL_APP_DIDENTERFOREGROUND: { lv_obj_invalidate(lv_scr_act()); break; } case SDL_QUIT: { app_quit(app); break; } case APP_RUN_ON_MAIN: { void (*action)(app_t *, void *) = event.user.data1; void *data = event.user.data2; action(app, data); break; } default: { if (event.type > APP_UI_EVENT_BEGIN && event.type < APP_UI_EVENT_LAST) { app_ui_event_data_t data = {.data1 = event.user.data1, .data2 = event.user.data2}; if (!app_ui_dispatch_event(app->ui, event.type, &data)) { commons_log_debug("UI", "Unhandled UI event 0x%x", event.type); } } break; } } } } static void logging_init() { commons_logging_init("ihsplay"); lv_log_register_print_cb(commons_lv_log); SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); SDL_LogSetOutputFunction(commons_sdl_log, NULL); } static bool use_windowed() { const char *v = SDL_getenv("IHSPLAY_WINDOWED"); if (v == NULL) { return false; } return strcmp(v, "1") == 0 || strcmp(v, "true") == 0; } void app_ihs_log(IHS_LogLevel level, const char *tag, const char *message) { char app_tag[32] = "IHS."; strncpy(app_tag + 4, tag, 28); commons_log_printf((commons_log_level) level, app_tag, "%s", message); } ================================================ FILE: app/platform/CMakeLists.txt ================================================ if (TARGET_WEBOS) add_subdirectory(webos) else() add_subdirectory(common) endif () ================================================ FILE: app/platform/common/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE app_common.c client_info_common.c) ================================================ FILE: app/platform/common/app_common.c ================================================ #include "app.h" void app_preinit(int argc, char *argv[]) { } void app_ui_set_handle_nav_back(app_ui_t *ui, bool handle) { } ================================================ FILE: app/platform/common/client_info_common.c ================================================ #include "util/client_info.h" bool client_info_load(client_info_t *info) { client_info_load_default(info); return true; } ================================================ FILE: app/platform/webos/CMakeLists.txt ================================================ pkg_check_modules(PBNJSON_C REQUIRED pbnjson_c) target_sources(ihsplay PRIVATE app_webos.c client_info_webos.c) target_include_directories(ihsplay PRIVATE ${PBNJSON_C_INCLUDE_DIRS}) target_link_libraries(ihsplay PRIVATE ${PBNJSON_C_LIBRARIES}) ================================================ FILE: app/platform/webos/app_webos.c ================================================ #include "app.h" void app_preinit(int argc, char *argv[]) { (void) argc; (void) argv; SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT, "true"); SDL_SetHint(SDL_HINT_WEBOS_CURSOR_SLEEP_TIME, "5000"); } void app_ui_set_handle_nav_back(app_ui_t *ui, bool handle) { (void) ui; SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_BACK, handle ? "true" : "false"); } ================================================ FILE: app/platform/webos/client_info_webos.c ================================================ #include "util/client_info.h" #include #include #include #include "lunasynccall.h" #include "logging.h" #include #include bool client_info_load(client_info_t *info) { memset(info, 0, sizeof(*info)); char *payload = NULL; const char *uri = "luna://com.webos.service.config/getConfigs"; if (!HLunaServiceCallSync(uri, "{\"configNames\":[\"tv.model.serialnumber\", \"tv.model.modelname\"]}", true, &payload) || !payload) { commons_log_warn("OSInfo", "Failed to call %s", uri); return client_info_load_default(info); } JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); jdomparser_ref parser = jdomparser_create(&schemaInfo, 0); jdomparser_feed(parser, payload, (int) strlen(payload)); jdomparser_end(parser); jvalue_ref body = jdomparser_get_result(parser); jvalue_ref configs = jobject_get(body, j_cstr_to_buffer("configs")); if (jis_null(configs)) { jdomparser_release(&parser); return client_info_load_default(info); } jvalue_ref serial_number = jobject_get(configs, j_cstr_to_buffer("tv.model.serialnumber")); jvalue_ref module_name = jobject_get(configs, j_cstr_to_buffer("tv.model.modelname")); if (!jis_string(serial_number) || !jis_string(module_name)) { jdomparser_release(&parser); return client_info_load_default(info); } raw_buffer serial_number_buf = jstring_get(serial_number); raw_buffer module_name_buf = jstring_get(module_name); unsigned char sha1[20]; mbedtls_sha1((const unsigned char *) serial_number_buf.m_str, serial_number_buf.m_len, sha1); memcpy(&info->device_id, &sha1[4], 16); mbedtls_sha256((const unsigned char *) serial_number_buf.m_str, serial_number_buf.m_len, info->secret_key, 0); char name[64]; snprintf(name, 64, "webOS TV %.*s", module_name_buf.m_len, module_name_buf.m_str); info->name = strndup(name, 64); jdomparser_release(&parser); info->config.deviceId = info->device_id; info->config.secretKey = info->secret_key; info->config.deviceName = info->name; return true; } ================================================ FILE: app/settings/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE settings.c) ================================================ FILE: app/settings/app_settings.h ================================================ #pragma once #include #include #include "array_list.h" typedef struct os_info_t os_info_t; typedef struct app_settings_t { bool enable_input; bool relmouse; /** The pointer references to modules */ const char *audio_driver; /** The pointer references to modules */ const char *video_driver; array_list_t modules; uint64_t selected_client_id; } app_settings_t; void app_settings_init(app_settings_t *settings, const os_info_t *os_info); void app_settings_deinit(app_settings_t *settings); ================================================ FILE: app/settings/settings.c ================================================ #include #include "app_settings.h" #include "ss4s_modules.h" #include "array_list.h" #include "os_info.h" #include "logging.h" void app_settings_init(app_settings_t *settings, const os_info_t *os_info) { memset(settings, 0, sizeof(app_settings_t)); int errno; if ((errno = SS4S_ModulesList(&settings->modules, os_info)) != 0) { commons_log_error("SS4S", "Can't load modules list: %s", strerror(errno)); } settings->enable_input = true; settings->relmouse = true; SS4S_ModulePreferences preferences = {.audio_module = NULL, .video_module = NULL}; SS4S_ModuleSelection selection = {.audio_module = NULL, .video_module = NULL}; // TODO: check result SS4S_ModulesSelect(&settings->modules, &preferences, &selection, true); settings->video_driver = SS4S_ModuleInfoGetId(selection.video_module); settings->audio_driver = SS4S_ModuleInfoGetId(selection.audio_module); } void app_settings_deinit(app_settings_t *settings) { SS4S_ModulesListClear(&settings->modules); } ================================================ FILE: app/ui/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE app_ui.c app_ui_font.c launcher.c hosts/hosts_fragment.c settings/settings.c settings/basic.c settings/widgets.c) add_subdirectory(common) add_subdirectory(connection) add_subdirectory(session) add_subdirectory(support) ================================================ FILE: app/ui/app_ui.c ================================================ #include #include #include #include "app_ui.h" #include "launcher.h" #include "lvgl/fonts/bootstrap-icons/regular.h" #include "lvgl/keypad.h" #include "lvgl/mouse.h" #include "lvgl/theme.h" #include "backend/stream_manager.h" static void app_input_populate_group(app_ui_t *ui); static void app_ui_focus_cb(lv_group_t *group); app_ui_t *app_ui_create(app_t *app, lv_disp_t *disp) { lv_draw_sdl_drv_param_t *param = disp->driver->user_data; app_ui_t *ui = calloc(1, sizeof(app_ui_t)); ui->app = app; ui->window = param->user_data; ui->root = lv_disp_get_scr_act(disp); ui->fm = lv_fragment_manager_create(NULL); lv_group_t *group = lv_group_create(); group->user_data = ui; lv_group_set_editing(group, 0); lv_group_set_default(group); lv_group_set_focus_cb(group, app_ui_focus_cb); ui->group = group; _lv_ll_init(&ui->modal_groups, sizeof(lv_group_t *)); ui->indev.mouse = app_lv_mouse_indev_init(); ui->indev.keypad = app_indev_keypad_init(app); app_ui_fontset_set_default_size(ui, &ui->font); app_ui_fontset_set_default_size(ui, &ui->iconfont); app_ui_fontset_init_fc(&ui->font, "sans-serif"); app_ui_fontset_init_mem(&ui->iconfont, "bootstrap-icons", ttf_bootstrap_icons_data, ttf_bootstrap_icons_size); app_ui_fontset_apply_fallback(&ui->font, &ui->iconfont); lv_obj_set_style_bg_opa(ui->root, LV_OPA_0, 0); lv_style_init(&ui->styles.action_btn_label); lv_style_set_text_font(&ui->styles.action_btn_label, ui->iconfont.heading2); lv_theme_set_parent(&ui->theme, lv_disp_get_theme(disp)); app_theme_init(&ui->theme, ui); lv_disp_set_theme(disp, &ui->theme); return ui; } void app_ui_created(app_ui_t *ui) { app_ui_push_fragment(ui, &launcher_fragment_class, NULL); app_ui_resized(ui, lv_obj_get_width(ui->root), lv_obj_get_height(ui->root)); } void app_ui_destroy(app_ui_t *ui) { lv_group_set_default(NULL); lv_group_del(ui->group); _lv_ll_clear(&ui->modal_groups); lv_style_reset(&ui->styles.action_btn_label); app_ui_fontset_deinit(&ui->iconfont); app_ui_fontset_deinit(&ui->font); lv_fragment_manager_del(ui->fm); app_indev_keypad_deinit(ui->indev.keypad); app_lv_mouse_indev_deinit(ui->indev.mouse); app_theme_deinit(&ui->theme); free(ui); } void app_ui_resized(app_ui_t *ui, int width, int height) { stream_manager_set_viewport_size(ui->app->stream_manager, width, height); } void app_ui_set_ignore_keys(app_ui_t *ui, bool ignore) { app_indev_keypad_set_ignore(ui->indev.keypad, ignore); } lv_fragment_t *app_ui_create_fragment(app_ui_t *ui, const lv_fragment_class_t *cls, void *args) { app_ui_fragment_args_t fargs = {ui->app, args}; return lv_fragment_create(cls, &fargs); } void app_ui_push_fragment(app_ui_t *ui, const lv_fragment_class_t *cls, void *args) { lv_fragment_t *f = app_ui_create_fragment(ui, cls, args); lv_fragment_manager_push(ui->fm, f, &ui->root); app_ui_update_nav_back(ui); } void app_ui_remove_fragment(app_ui_t *ui, lv_fragment_t *f) { lv_fragment_manager_remove(ui->fm, f); app_ui_update_nav_back(ui); } void app_ui_pop_top_fragment(app_ui_t *ui) { lv_fragment_manager_pop(ui->fm); app_ui_update_nav_back(ui); } bool app_ui_dispatch_event(app_ui_t *ui, app_event_type_t type, app_ui_event_data_t *data) { bool handled = lv_fragment_manager_send_event(ui->fm, type, data); if (type == APP_UI_NAV_QUIT && !handled) { app_quit(ui->app); return true; } return handled; } void app_ui_push_modal_group(app_ui_t *ui, lv_group_t *group) { LV_ASSERT_NULL(group); lv_group_t **tail = _lv_ll_ins_tail(&ui->modal_groups); *tail = group; app_input_populate_group(ui); } void app_ui_remove_modal_group(app_ui_t *ui, lv_group_t *group) { lv_group_t **node = NULL; _LV_LL_READ_BACK(&ui->modal_groups, node) { if (*node == group) break; } if (node) { _lv_ll_remove(&ui->modal_groups, node); lv_mem_free(node); } app_input_populate_group(ui); } lv_group_t *app_ui_get_input_group(app_ui_t *ui) { return ui->indev.keypad->group; } void app_ui_update_nav_back(app_ui_t *ui) { size_t stack_size = lv_fragment_manager_get_stack_size(ui->fm); LV_ASSERT(stack_size > 0); app_ui_set_handle_nav_back(ui, stack_size > 1); } static void app_input_populate_group(app_ui_t *ui) { lv_group_t *group = NULL; lv_group_t *const *tail = _lv_ll_get_tail(&ui->modal_groups); if (tail) { group = *tail; } if (!group) { group = ui->group; } if (!group) { group = lv_group_get_default(); } lv_indev_set_group(ui->indev.keypad, group); lv_indev_set_group(ui->indev.mouse, group); } static void app_ui_focus_cb(lv_group_t *group) { } ================================================ FILE: app/ui/app_ui.h ================================================ #pragma once #include #include #include "app.h" #include "app_ui_font.h" typedef struct app_t app_t; typedef struct app_ui_t { app_t *app; lv_theme_t theme; lv_obj_t *root; lv_fragment_manager_t *fm; SDL_Window *window; app_ui_fontset_t font; app_ui_fontset_t iconfont; lv_group_t *group; lv_ll_t modal_groups; struct { lv_indev_t *mouse; lv_indev_t *keypad; } indev; struct { lv_style_t action_btn_label; } styles; } app_ui_t; typedef struct app_ui_fragment_args_t { app_t *app; void *data; } app_ui_fragment_args_t; typedef struct app_ui_event_data_t { void *data1; void *data2; } app_ui_event_data_t; app_ui_t *app_ui_create(app_t *app, lv_disp_t *disp); void app_ui_created(app_ui_t *ui); void app_ui_destroy(app_ui_t *ui); void app_ui_resized(app_ui_t *ui, int width, int height); void app_ui_set_ignore_keys(app_ui_t *ui, bool ignore); lv_fragment_t *app_ui_create_fragment(app_ui_t *ui, const lv_fragment_class_t *cls, void *args); void app_ui_push_fragment(app_ui_t *ui, const lv_fragment_class_t *cls, void *args); void app_ui_remove_fragment(app_ui_t *ui, lv_fragment_t *f); void app_ui_pop_top_fragment(app_ui_t *ui); /** * @warning DO NOT call this directly! * @return true if this event has been handled by someone */ bool app_ui_dispatch_event(app_ui_t *ui, app_event_type_t type, app_ui_event_data_t *data); void app_ui_push_modal_group(app_ui_t *ui, lv_group_t *group); void app_ui_remove_modal_group(app_ui_t *ui, lv_group_t *group); lv_group_t *app_ui_get_input_group(app_ui_t *ui); void app_ui_update_nav_back(app_ui_t *ui); void app_ui_set_handle_nav_back(app_ui_t *ui, bool handle); ================================================ FILE: app/ui/app_ui_font.c ================================================ #include "app_ui.h" #include "app_ui_font.h" #include #include static lv_font_t *load_font(const lv_ft_info_t *info, lv_coord_t size); static bool fontset_load_fc(app_ui_fontset_t *set, FcPattern *font); void app_ui_fontset_set_default_size(const app_ui_t *ui, app_ui_fontset_t *set) { set->sizes.heading1 = LV_DPX(42); set->sizes.heading2 = LV_DPX(28); set->sizes.heading3 = LV_DPX(21); set->sizes.body = LV_DPX(16); set->sizes.small = LV_DPX(14); set->sizes.huge = LV_DPX(96); } void app_ui_fontset_init_mem(app_ui_fontset_t *set, const char *name, const void *mem, size_t size) { lv_ft_info_t ft_info = {.name = name, .mem = mem, .mem_size = size, .style = FT_FONT_STYLE_NORMAL}; set->body = load_font(&ft_info, set->sizes.body); set->heading1 = load_font(&ft_info, set->sizes.heading1); set->heading2 = load_font(&ft_info, set->sizes.heading2); set->heading3 = load_font(&ft_info, set->sizes.heading3); set->small = load_font(&ft_info, set->sizes.small); set->huge = load_font(&ft_info, set->sizes.huge); } void app_ui_fontset_init_fc(app_ui_fontset_t *set, const char *name) { //does not necessarily have to be a specific name. You could put anything here and Fontconfig WILL find a font for you FcPattern *pattern = FcNameParse((const FcChar8 *) name); assert(pattern != NULL); FcConfigSubstitute(NULL, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); FcResult result; FcPattern *font = FcFontMatch(NULL, pattern, &result); fontset_load_fc(set, font); if (font) { FcPatternDestroy(font); font = NULL; } FcPatternDestroy(pattern); pattern = NULL; #ifdef FONT_FAMILY_FALLBACK const i18n_entry_t *loc_entry = i18n_entry(i18n_locale()); pattern = FcNameParse((const FcChar8 *) ((loc_entry && loc_entry->font) ? loc_entry->font : FONT_FAMILY_FALLBACK)); if (pattern) { FcLangSet *ls = FcLangSetCreate(); if (loc_entry) { FcLangSetAdd(ls, (const FcChar8 *) loc_entry->locale); FcPatternAddLangSet(pattern, FC_LANG, ls); } FcConfigSubstitute(NULL, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); font = FcFontMatch(NULL, pattern, &result); if (font) { fontset.fallback = calloc(1, sizeof(app_fontset_t)); if (fontset_load_fc(fontset.fallback, font)) { fontset.normal->fallback = fontset.fallback->normal; fontset.large->fallback = fontset.fallback->large; fontset.small->fallback = fontset.fallback->small; } else { free(fontset.fallback); fontset.fallback = NULL; } FcPatternDestroy(font); font = NULL; } FcLangSetDestroy(ls); FcPatternDestroy(pattern); pattern = NULL; } #endif } void app_ui_fontset_apply_fallback(app_ui_fontset_t *set, const app_ui_fontset_t *fallback) { set->small->fallback = fallback->small; set->body->fallback = fallback->body; set->heading3->fallback = fallback->heading3; set->heading2->fallback = fallback->heading2; set->heading1->fallback = fallback->heading1; set->huge->fallback = fallback->huge; } void app_ui_fontset_deinit(app_ui_fontset_t *set) { lv_ft_font_destroy(set->small); lv_ft_font_destroy(set->body); lv_ft_font_destroy(set->heading3); lv_ft_font_destroy(set->heading2); lv_ft_font_destroy(set->heading1); lv_ft_font_destroy(set->huge); } static lv_font_t *load_font(const lv_ft_info_t *info, lv_coord_t size) { lv_ft_info_t ft_info = *info; ft_info.font = NULL; ft_info.weight = size; if (!lv_ft_font_init(&ft_info)) { LV_LOG_ERROR("Failed to load font"); } return ft_info.font; } static bool fontset_load_fc(app_ui_fontset_t *set, FcPattern *font) { //The pointer stored in 'file' is tied to 'font'; therefore, when 'font' is freed, this pointer is freed automatically. //If you want to return the filename of the selected font, pass a buffer and copy the file name into that buffer FcChar8 *file = NULL; if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { lv_ft_info_t ft_info = {.name = (char *) file, .style = FT_FONT_STYLE_NORMAL}; set->body = load_font(&ft_info, set->sizes.body); set->heading1 = load_font(&ft_info, set->sizes.heading1); set->heading2 = load_font(&ft_info, set->sizes.heading2); set->heading3 = load_font(&ft_info, set->sizes.heading3); set->small = load_font(&ft_info, set->sizes.small); set->huge = load_font(&ft_info, set->sizes.huge); return true; } return false; } ================================================ FILE: app/ui/app_ui_font.h ================================================ #pragma once #include #include "lvgl.h" typedef struct app_t app_t; typedef struct app_ui_t app_ui_t; typedef struct app_ui_font_sizes_t { uint16_t heading1; uint16_t heading2; uint16_t heading3; uint16_t small; uint16_t body; } app_ui_font_sizes_t; typedef struct app_ui_fontset_t { struct { uint16_t heading1; uint16_t heading2; uint16_t heading3; uint16_t body; uint16_t small; uint16_t huge; } sizes; lv_font_t *heading1; lv_font_t *heading2; lv_font_t *heading3; lv_font_t *body; lv_font_t *small; lv_font_t *huge; } app_ui_fontset_t; void app_ui_fontset_set_default_size(const app_ui_t *ui, app_ui_fontset_t *set); void app_ui_fontset_init_mem(app_ui_fontset_t *set, const char *name, const void *mem, size_t size); void app_ui_fontset_init_fc(app_ui_fontset_t *set, const char *name); void app_ui_fontset_apply_fallback(app_ui_fontset_t *set, const app_ui_fontset_t*fallback); void app_ui_fontset_deinit(app_ui_fontset_t *set); ================================================ FILE: app/ui/common/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE error_messages.c progress_dialog.c group_utils.c ) ================================================ FILE: app/ui/common/error_messages.c ================================================ #include "error_messages.h" const char *authorization_result_str(IHS_AuthorizationResult result) { switch (result) { case IHS_AuthorizationDenied: return "Host denied authorization"; case IHS_AuthorizationNotLoggedIn: return "Not logged in"; case IHS_AuthorizationOffline: return "Host is offline"; case IHS_AuthorizationBusy: return "Host is busy"; case IHS_AuthorizationTimedOut: return "Authorization timed out"; case IHS_AuthorizationCanceled: return "Authorization cancelled"; default: return "Unknown error"; } } const char *streaming_result_str(IHS_StreamingResult result) { switch (result) { case IHS_StreamingUnauthorized: { return "Unauthorized"; } case IHS_StreamingScreenLocked: { return "Screen is locked"; } case IHS_StreamingBusy: { return "Host is busy"; } case IHS_StreamingPINRequired: { return "PIN is not supported"; } case IHS_StreamingTimeout: { return "Request timed out"; } default: { return "Unknown error"; } } } ================================================ FILE: app/ui/common/error_messages.h ================================================ #pragma once #include "ihslib.h" const char *authorization_result_str(IHS_AuthorizationResult result); const char *streaming_result_str(IHS_StreamingResult result); ================================================ FILE: app/ui/common/group_utils.c ================================================ #include "group_utils.h" lv_obj_t *ui_group_first_in_parent(lv_group_t *group, lv_obj_t *parent) { lv_obj_t **obj = NULL; _LV_LL_READ(&group->obj_ll, obj) { lv_obj_t *cur = *obj; if (cur == parent) { return cur; } while (cur != NULL) { cur = lv_obj_get_parent(cur); if (cur == parent) { return *obj; } } } return NULL; } ================================================ FILE: app/ui/common/group_utils.h ================================================ #pragma once #include "lvgl.h" lv_obj_t * ui_group_first_in_parent(lv_group_t *group, lv_obj_t*parent); ================================================ FILE: app/ui/common/progress_dialog.c ================================================ #include "progress_dialog.h" lv_obj_t *progress_dialog_create(const char *message) { lv_obj_t *dialog = lv_msgbox_create(NULL, NULL, NULL, NULL, false); lv_obj_t *content = lv_msgbox_get_content(dialog); lv_obj_set_layout(content, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(content, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(content, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t *spinner = lv_spinner_create(content, 1000, 60); lv_obj_set_style_arc_width(spinner, lv_dpx(10), 0); lv_obj_set_style_arc_width(spinner, lv_dpx(10), LV_PART_INDICATOR); lv_obj_set_size(spinner, lv_dpx(50), lv_dpx(50)); lv_obj_set_flex_grow(spinner, 0); lv_obj_t *label = lv_label_create(content); lv_obj_set_style_pad_hor(label, LV_DPX(20), 0); lv_label_set_text(label, message); lv_obj_set_flex_grow(label, 1); lv_obj_center(dialog); return dialog; } void progress_dialog_set_message(lv_obj_t *obj, const char *message) { lv_obj_t *content = lv_msgbox_get_content(obj); for (int i = (int) lv_obj_get_child_cnt(content) - 1; i >= 0; --i) { lv_obj_t *child = lv_obj_get_child(content, i); if (!lv_obj_check_type(child, &lv_label_class)) { continue; } lv_label_set_text(obj, message); } } ================================================ FILE: app/ui/common/progress_dialog.h ================================================ #pragma once #include "lvgl.h" lv_obj_t *progress_dialog_create(const char *message); void progress_dialog_set_message(lv_obj_t *obj, const char *message); ================================================ FILE: app/ui/connection/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE connection_fragment.c pin_fragment.c conn_error_fragment.c) ================================================ FILE: app/ui/connection/conn_error_fragment.c ================================================ #include "conn_error_fragment.h" #include "ui/app_ui.h" typedef struct conn_error_fragment_t { lv_fragment_t base; app_t *app; char *error_message; } conn_error_fragment_t; static void conn_error_ctor(lv_fragment_t *self, void *arg); static void conn_error_dtor(lv_fragment_t *self); static lv_obj_t *conn_error_create_obj(lv_fragment_t *self, lv_obj_t *container); static void conn_error_obj_created(lv_fragment_t *self, lv_obj_t *obj); const lv_fragment_class_t conn_error_fragment_class = { .constructor_cb = conn_error_ctor, .destructor_cb = conn_error_dtor, .create_obj_cb = conn_error_create_obj, .obj_created_cb = conn_error_obj_created, .instance_size = sizeof(conn_error_fragment_t) }; static void conn_error_ctor(lv_fragment_t *self, void *arg) { conn_error_fragment_t *fragment = (conn_error_fragment_t *) self; app_ui_fragment_args_t *args = arg; fragment->app = args->app; conn_error_fragment_data *data = args->data; fragment->error_message = strdup(data->message); } static void conn_error_dtor(lv_fragment_t *self) { conn_error_fragment_t *fragment = (conn_error_fragment_t *) self; free(fragment->error_message); } static lv_obj_t *conn_error_create_obj(lv_fragment_t *self, lv_obj_t *container) { conn_error_fragment_t *fragment = (conn_error_fragment_t *) self; lv_obj_t *obj = lv_obj_create(container); lv_obj_set_style_pad_gap(obj, LV_DPX(10), 0); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(obj, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t *conn_error_label = lv_label_create(obj); lv_label_set_text(conn_error_label, fragment->error_message); return obj; } static void conn_error_obj_created(lv_fragment_t *self, lv_obj_t *obj) { } ================================================ FILE: app/ui/connection/conn_error_fragment.h ================================================ #pragma once #include "lvgl.h" typedef struct conn_error_fragment_data { const char *message; } conn_error_fragment_data; extern const lv_fragment_class_t conn_error_fragment_class; ================================================ FILE: app/ui/connection/connection_fragment.c ================================================ #include "connection_fragment.h" #include "backend/host_manager.h" #include "lvgl/theme.h" #include "ui/app_ui.h" #include "ui/common/error_messages.h" #include "ui/session/session.h" #include "util/random.h" #include "pin_fragment.h" #include "conn_error_fragment.h" typedef struct connection_fragment_t { lv_fragment_t base; app_t *app; IHS_HostInfo host; lv_obj_t *content; lv_obj_t *title; } connection_fragment_t; static void conn_ctor(lv_fragment_t *self, void *arg); static lv_obj_t *conn_create_obj(lv_fragment_t *self, lv_obj_t *container); static void conn_obj_created(lv_fragment_t *self, lv_obj_t *obj); static void conn_obj_will_del(lv_fragment_t *self, lv_obj_t *obj); static void session_started(const IHS_HostInfo *host, const IHS_SessionInfo *info, void *context); static void session_start_failed(const IHS_HostInfo *host, IHS_StreamingResult result, void *context); static void authorized(const IHS_HostInfo *host, uint64_t steam_id, void *context); static void authorization_failed(const IHS_HostInfo *host, IHS_AuthorizationResult result, void *context); static void open_authorization(connection_fragment_t *fragment, const IHS_HostInfo *info); static void conn_show_page(connection_fragment_t *fragment, const lv_fragment_class_t *cls, void *data); const lv_fragment_class_t connection_fragment_class = { .constructor_cb = conn_ctor, .create_obj_cb = conn_create_obj, .obj_created_cb = conn_obj_created, .obj_will_delete_cb = conn_obj_will_del, .instance_size = sizeof(connection_fragment_t) }; static const host_manager_listener_t conn_host_listener = { .session_started = session_started, .session_start_failed = session_start_failed, .authorized = authorized, .authorization_failed = authorization_failed, }; static void conn_ctor(lv_fragment_t *self, void *arg) { connection_fragment_t *fragment = (connection_fragment_t *) self; app_ui_fragment_args_t *args = arg; fragment->app = args->app; fragment->host = (*(IHS_HostInfo *) args->data); free(args->data); } static lv_obj_t *conn_create_obj(lv_fragment_t *self, lv_obj_t *container) { connection_fragment_t *fragment = (connection_fragment_t *) self; lv_obj_t *win = app_lv_win_create(container); fragment->title = lv_win_add_title(win, "Connecting"); fragment->content = lv_win_get_content(win); return win; } static void conn_obj_created(lv_fragment_t *self, lv_obj_t *obj) { connection_fragment_t *fragment = (connection_fragment_t *) self; host_manager_t *hosts_manager = fragment->app->host_manager; host_manager_register_listener(hosts_manager, &conn_host_listener, fragment); host_manager_session_request(hosts_manager, &fragment->host); } static void conn_obj_will_del(lv_fragment_t *self, lv_obj_t *obj) { connection_fragment_t *fragment = (connection_fragment_t *) self; host_manager_t *hosts_manager = fragment->app->host_manager; host_manager_unregister_listener(hosts_manager, &conn_host_listener); } void connection_fragment_set_title(lv_fragment_t *self, const char *title) { connection_fragment_t *fragment = (connection_fragment_t *) self; lv_label_set_text(fragment->title, title); } static void session_started(const IHS_HostInfo *host, const IHS_SessionInfo *info, void *context) { connection_fragment_t *fragment = (connection_fragment_t *) context; session_fragment_args_t args = { .host = *host, .session = *info, }; app_ui_push_fragment(fragment->app->ui, &session_fragment_class, &args); app_ui_remove_fragment(fragment->app->ui, (lv_fragment_t *) fragment); } static void session_start_failed(const IHS_HostInfo *host, IHS_StreamingResult result, void *context) { connection_fragment_t *fragment = (connection_fragment_t *) context; if (result == IHS_StreamingUnauthorized) { open_authorization(fragment, host); } else { conn_error_fragment_data data = { .message = streaming_result_str(result), }; conn_show_page(fragment, &conn_error_fragment_class, &data); } } static void authorized(const IHS_HostInfo *host, uint64_t steam_id, void *context) { (void) host; (void) steam_id; connection_fragment_t *fragment = (connection_fragment_t *) context; // TODO Hide authorization UI // TODO Performance test? host_manager_t *hosts_manager = fragment->app->host_manager; host_manager_session_request(hosts_manager, &fragment->host); } static void authorization_failed(const IHS_HostInfo *host, IHS_AuthorizationResult result, void *context) { (void) host; connection_fragment_t *fragment = (connection_fragment_t *) context; conn_error_fragment_data data = { .message = authorization_result_str(result), }; conn_show_page(fragment, &conn_error_fragment_class, &data); } static void open_authorization(connection_fragment_t *fragment, const IHS_HostInfo *info) { char pin[8]; random_pin(pin); host_manager_authorization_request(fragment->app->host_manager, info, pin); conn_show_page(fragment, &pin_fragment_class, pin); } static void conn_show_page(connection_fragment_t *fragment, const lv_fragment_class_t *cls, void *data) { lv_fragment_t *pin_fragment = app_ui_create_fragment(fragment->app->ui, cls, data); lv_fragment_manager_replace(fragment->base.child_manager, pin_fragment, &fragment->content); lv_obj_set_size(pin_fragment->obj, LV_PCT(100), LV_PCT(100)); } ================================================ FILE: app/ui/connection/connection_fragment.h ================================================ #pragma once #include "lvgl.h" extern const lv_fragment_class_t connection_fragment_class; void connection_fragment_set_title(lv_fragment_t *self, const char *title); ================================================ FILE: app/ui/connection/pin_fragment.c ================================================ #include "pin_fragment.h" #include "ui/app_ui.h" #include "connection_fragment.h" typedef struct pin_fragment_t { lv_fragment_t base; app_t *app; char pin[8]; } pin_fragment_t; static void pin_ctor(lv_fragment_t *self, void *arg); static lv_obj_t *pin_create_obj(lv_fragment_t *self, lv_obj_t *container); static void pin_obj_created(lv_fragment_t *self, lv_obj_t *obj); const lv_fragment_class_t pin_fragment_class = { .constructor_cb = pin_ctor, .create_obj_cb = pin_create_obj, .obj_created_cb = pin_obj_created, .instance_size = sizeof(pin_fragment_t) }; static void pin_ctor(lv_fragment_t *self, void *arg) { pin_fragment_t *fragment = (pin_fragment_t *) self; app_ui_fragment_args_t *args = arg; fragment->app = args->app; strncpy(fragment->pin, args->data, sizeof(fragment->pin) - 1); } static lv_obj_t *pin_create_obj(lv_fragment_t *self, lv_obj_t *container) { pin_fragment_t *fragment = (pin_fragment_t *) self; lv_obj_t *obj = lv_obj_create(container); lv_obj_set_style_pad_gap(obj, LV_DPX(10), 0); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(obj, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t *pin_label = lv_label_create(obj); lv_obj_set_style_text_font(pin_label, fragment->app->ui->font.huge, 0); lv_label_set_text(pin_label, fragment->pin); lv_obj_t *hint1 = lv_label_create(obj); lv_label_set_text(hint1, "Input PIN above on the computer to pair with this device"); return obj; } static void pin_obj_created(lv_fragment_t *self, lv_obj_t *obj) { lv_fragment_t *parent = lv_fragment_get_parent(self); connection_fragment_set_title(parent, "Pairing"); } ================================================ FILE: app/ui/connection/pin_fragment.h ================================================ #pragma once #include "lvgl.h" extern const lv_fragment_class_t pin_fragment_class; ================================================ FILE: app/ui/hosts/hosts_fragment.c ================================================ #include "hosts_fragment.h" #include "app.h" #include "backend/host_manager.h" #include "lv_gridview.h" #include "ui/app_ui.h" #include "ui/session/session.h" #include "array_list.h" #include "lvgl/fonts/bootstrap-icons/symbols.h" #include "util/random.h" #include "lvgl/ext/msgbox_ext.h" #include "ui/common/error_messages.h" #include "logging.h" #include "lvgl/theme.h" #include "ui/launcher.h" typedef struct hosts_fragment { lv_fragment_t base; app_t *app; lv_fragment_t *launcher_fragment; lv_obj_t *grid_view; lv_obj_t *msgbox; } hosts_fragment; typedef struct host_obj_holder { lv_obj_t *icon; lv_obj_t *os_icon; lv_obj_t *name; } host_obj_holder; static void constructor(lv_fragment_t *self, void *arg); static void destructor(lv_fragment_t *self); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container); static void obj_created(lv_fragment_t *self, lv_obj_t *obj); static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj); static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj); static bool event_cb(lv_fragment_t *self, int code, void *data); static void hosts_changed(array_list_t *list, host_manager_hosts_change change_type, int change_index, void *context); static int host_item_count(lv_obj_t *grid, void *data); static lv_obj_t *host_item_create(lv_obj_t *grid); static void host_item_delete(lv_event_t *e); static void host_item_clicked(lv_event_t *e); static void size_changed_cb(lv_event_t *e); static void grid_focused(lv_event_t *e); static void grid_unfocused(lv_event_t *e); static void grid_key_cb(lv_event_t *e); static void host_item_bind(lv_obj_t *grid, lv_obj_t *item_view, void *data, int position); static void grid_size_populate(hosts_fragment *fragment); static lv_obj_t *open_msgbox(hosts_fragment *fragment, const char *title, const char *message, const char *btns[]); static void close_msgbox(hosts_fragment *fragment); static void msgbox_confirm_cb(lv_event_t *e); static void msgbox_del_cb(lv_event_t *e); static void authorization_cancel_cb(lv_event_t *e); const lv_fragment_class_t hosts_fragment_class = { .constructor_cb = constructor, .destructor_cb = destructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .obj_will_delete_cb = obj_will_delete, .obj_deleted_cb = obj_deleted, .event_cb = event_cb, .instance_size = sizeof(hosts_fragment), }; static const host_manager_listener_t host_manager_listener = { .hosts_changed = hosts_changed, }; static const lv_gridview_adapter_t hosts_adapter = { .item_count = host_item_count, .create_view = host_item_create, .bind_view = host_item_bind, }; void hosts_fragment_focus_hosts(lv_fragment_t *self) { if (self->cls != &hosts_fragment_class) { return; } hosts_fragment *fragment = (hosts_fragment *) self; lv_group_focus_obj(fragment->grid_view); lv_gridview_focus_when_available(fragment->grid_view, 0); } static void constructor(lv_fragment_t *self, void *arg) { hosts_fragment *fragment = (hosts_fragment *) self; app_ui_fragment_args_t *args = arg; fragment->app = args->app; fragment->launcher_fragment = args->data; } static void destructor(lv_fragment_t *self) { LV_UNUSED(self); } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { hosts_fragment *fragment = (hosts_fragment *) self; lv_obj_t *win = app_lv_win_create(container); lv_win_add_title(win, "Select Computer"); lv_obj_t *content = lv_win_get_content(win); lv_obj_set_style_pad_hor(content, 0, 0); fragment->grid_view = lv_gridview_create(content); lv_obj_set_size(fragment->grid_view, LV_PCT(100), LV_PCT(100)); lv_obj_update_layout(fragment->grid_view); lv_obj_set_user_data(fragment->grid_view, fragment); lv_obj_set_style_pad_bottom(fragment->grid_view, LV_DPX(30), 0); lv_obj_set_style_pad_hor(fragment->grid_view, LV_DPX(30), 0); lv_obj_set_style_pad_gap(fragment->grid_view, LV_DPX(15), 0); lv_obj_set_style_pad_right(fragment->grid_view, LV_DPX(13), LV_PART_SCROLLBAR); lv_gridview_set_adapter(fragment->grid_view, &hosts_adapter); grid_size_populate(fragment); lv_obj_add_event_cb(fragment->grid_view, size_changed_cb, LV_EVENT_SIZE_CHANGED, fragment); lv_obj_add_event_cb(fragment->grid_view, host_item_clicked, LV_EVENT_CLICKED, fragment); lv_obj_add_event_cb(fragment->grid_view, grid_focused, LV_EVENT_FOCUSED, fragment); lv_obj_add_event_cb(fragment->grid_view, grid_unfocused, LV_EVENT_DEFOCUSED, fragment); lv_obj_add_event_cb(fragment->grid_view, grid_key_cb, LV_EVENT_KEY, fragment); return win; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); hosts_fragment *fragment = (hosts_fragment *) self; host_manager_t *hosts_manager = fragment->app->host_manager; host_manager_register_listener(hosts_manager, &host_manager_listener, fragment); lv_gridview_set_data(fragment->grid_view, host_manager_get_hosts(hosts_manager)); lv_group_t *group = app_ui_get_input_group(fragment->app->ui); if (group != NULL && lv_group_get_focused(group) == NULL) { hosts_fragment_focus_hosts(self); } host_manager_discovery_start(hosts_manager); } static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); hosts_fragment *fragment = (hosts_fragment *) self; host_manager_discovery_stop(fragment->app->host_manager); } static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); hosts_fragment *fragment = (hosts_fragment *) self; host_manager_unregister_listener(fragment->app->host_manager, &host_manager_listener); } static void hosts_changed(array_list_t *list, host_manager_hosts_change change_type, int change_index, void *context) { hosts_fragment *fragment = (hosts_fragment *) context; lv_obj_t *grid = fragment->grid_view; switch (change_type) { case HOST_MANAGER_HOSTS_NEW: { lv_gridview_data_change_t changes[] = { {.start = change_index, .remove_count = 0, .add_count = 1} }; lv_gridview_set_data_advanced(grid, list, changes, 1); break; } case HOST_MANAGER_HOSTS_UPDATE: { lv_gridview_data_change_t changes[] = { {.start = change_index, .remove_count = 1, .add_count = 1} }; lv_gridview_set_data_advanced(grid, list, changes, 1); break; } } } static lv_obj_t *open_msgbox(hosts_fragment *fragment, const char *title, const char *message, const char *btns[]) { close_msgbox(fragment); lv_obj_t *mbox = lv_msgbox_create(NULL, title, message, btns, false); msgbox_fix_sizes(mbox, btns); lv_obj_add_event_cb(mbox, msgbox_del_cb, LV_EVENT_DELETE, fragment); lv_obj_center(mbox); return fragment->msgbox = mbox; } static void close_msgbox(hosts_fragment *fragment) { if (fragment->msgbox == NULL) { return; } lv_msgbox_close(fragment->msgbox); fragment->msgbox = NULL; } static void msgbox_confirm_cb(lv_event_t *e) { lv_obj_t *mbox = lv_event_get_current_target(e); lv_event_stop_processing(e); lv_msgbox_close(mbox); } static void msgbox_del_cb(lv_event_t *e) { hosts_fragment *fragment = lv_event_get_user_data(e); if (lv_event_get_current_target(e) != fragment->msgbox) { return; } fragment->msgbox = NULL; } static void authorization_cancel_cb(lv_event_t *e) { hosts_fragment *fragment = lv_event_get_user_data(e); lv_obj_t *mbox = lv_event_get_current_target(e); lv_event_stop_processing(e); lv_msgbox_close(mbox); host_manager_authorization_cancel(fragment->app->host_manager); } static int host_item_count(lv_obj_t *grid, void *data) { LV_UNUSED(grid); return array_list_size(data); } static lv_obj_t *host_item_create(lv_obj_t *grid) { hosts_fragment *fragment = lv_obj_get_user_data(grid); lv_obj_t *item_view = lv_btn_create(grid); lv_group_remove_obj(item_view); lv_obj_set_style_radius(item_view, 0, 0); lv_obj_set_layout(item_view, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(item_view, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(item_view, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); host_obj_holder *holder = malloc(sizeof(host_obj_holder)); item_view->user_data = holder; holder->icon = lv_obj_create(item_view); lv_obj_remove_style_all(holder->icon); lv_obj_clear_flag(holder->icon, LV_OBJ_FLAG_CLICKABLE); lv_obj_set_size(holder->icon, LV_DPX(128), LV_DPX(128)); lv_obj_set_style_text_font(holder->icon, fragment->app->ui->iconfont.huge, 0); lv_obj_set_style_bg_color(holder->icon, lv_color_white(), 0); lv_obj_set_style_bg_opa(holder->icon, LV_OPA_30, 0); lv_obj_set_style_radius(holder->icon, LV_RADIUS_CIRCLE, 0); lv_obj_set_style_bg_img_src(holder->icon, BS_SYMBOL_DISPLAY, 0); holder->os_icon = lv_obj_create(holder->icon); lv_obj_remove_style_all(holder->os_icon); lv_obj_clear_flag(holder->os_icon, LV_OBJ_FLAG_CLICKABLE); lv_obj_set_size(holder->os_icon, LV_DPX(40), LV_DPX(40)); lv_obj_set_style_text_font(holder->os_icon, fragment->app->ui->iconfont.heading2, 0); lv_obj_align(holder->os_icon, LV_ALIGN_CENTER, 0, -LV_DPX(4)); holder->name = lv_label_create(item_view); lv_obj_add_event_cb(item_view, host_item_delete, LV_EVENT_DELETE, NULL); lv_obj_set_size(item_view, LV_SIZE_CONTENT, LV_SIZE_CONTENT); lv_obj_add_flag(item_view, LV_OBJ_FLAG_EVENT_BUBBLE); return item_view; } static void host_item_delete(lv_event_t *e) { free(lv_event_get_current_target(e)->user_data); } static void host_item_bind(lv_obj_t *grid, lv_obj_t *item_view, void *data, int position) { LV_UNUSED(grid); host_obj_holder *holder = item_view->user_data; IHS_HostInfo *item = array_list_get(data, position); lv_label_set_text(holder->name, item->hostname); if (item->ostype >= IHS_SteamOSTypeWindows) { lv_obj_set_style_bg_img_src(holder->os_icon, BS_SYMBOL_WINDOWS, 0); } else if (item->ostype >= IHS_SteamOSTypeMacos && item->ostype < IHS_SteamOSTypeUnknown) { lv_obj_set_style_bg_img_src(holder->os_icon, BS_SYMBOL_APPLE, 0); } else { lv_obj_set_style_bg_img_src(holder->os_icon, LV_SYMBOL_DUMMY, 0); } } static void grid_size_populate(hosts_fragment *fragment) { lv_coord_t content_width = lv_obj_get_content_width(fragment->grid_view); int col_count = 5; if (content_width > 0) { lv_coord_t pad_column = lv_obj_get_style_pad_column(fragment->grid_view, 0); col_count = (content_width + pad_column) / (LV_DPX(150) + pad_column); } lv_gridview_set_config(fragment->grid_view, col_count, LV_DPX(200), LV_GRID_ALIGN_STRETCH, LV_GRID_ALIGN_STRETCH); } static void host_item_clicked(lv_event_t *e) { hosts_fragment *fragment = e->user_data; lv_obj_t *target = lv_event_get_target(e); lv_obj_t *grid = fragment->grid_view; if (target->parent != grid) return; int index = lv_gridview_get_item_data_index(grid, target); if (index < 0) return; const IHS_HostInfo *item = array_list_get(lv_gridview_get_data(grid), index); launcher_fragment_set_selected_host(fragment->launcher_fragment, item->clientId); app_ui_pop_top_fragment(fragment->app->ui); } static void size_changed_cb(lv_event_t *e) { hosts_fragment *fragment = e->user_data; grid_size_populate(fragment); } static void grid_focused(lv_event_t *e) { if (e->target == e->current_target) { array_list_t *data = lv_gridview_get_data(e->target); if (data == NULL || array_list_size(data) == 0) { return; } lv_gridview_focus(e->target, 0); } else { int index = lv_gridview_get_focused_index(e->current_target); if (index >= 0) { lv_obj_t *item_view = lv_gridview_get_item_view(e->current_target, index); if (item_view != NULL && lv_obj_has_state(item_view, LV_STATE_FOCUSED)) { lv_obj_add_state(item_view, LV_STATE_FOCUS_KEY); } } } } static void grid_unfocused(lv_event_t *e) { if (e->target != e->current_target) return; lv_gridview_focus(e->target, -1); } static void grid_key_cb(lv_event_t *e) { if (e->target != e->current_target || e->stop_processing) return; switch (lv_event_get_key(e)) { case LV_KEY_UP: { lv_group_focus_prev(lv_group_get_default()); break; } } } static bool event_cb(lv_fragment_t *self, int code, void *data) { (void) data; hosts_fragment *fragment = (hosts_fragment *) self; if (code == APP_UI_NAV_BACK) { app_ui_pop_top_fragment(fragment->app->ui); return true; } return false; } ================================================ FILE: app/ui/hosts/hosts_fragment.h ================================================ #pragma once #include extern const lv_fragment_class_t hosts_fragment_class; void hosts_fragment_focus_hosts(lv_fragment_t *self); ================================================ FILE: app/ui/launcher.c ================================================ #include #include "app.h" #include "app_ui.h" #include "config.h" #include "launcher.h" #include "hosts/hosts_fragment.h" #include "settings/settings.h" #include "support/support.h" #include "lvgl/fonts/bootstrap-icons/symbols.h" #include "backend/host_manager.h" #include "array_list.h" #include "lvgl/ext/lv_dir_focus.h" #include "lvgl/theme.h" #include "ui/connection/connection_fragment.h" #include "backend/input_manager.h" typedef struct launcher_fragment { lv_fragment_t base; app_t *app; lv_coord_t row_dsc[5], col_dsc[4]; struct { lv_style_t root; lv_style_t option_icon; } styles; lv_obj_t *nav_content; lv_obj_t *selected_host; lv_obj_t *gamepads; uint64_t selected_host_id; int num_launch_options; } launcher_fragment; static void constructor(lv_fragment_t *self, void *arg); static void destructor(lv_fragment_t *self); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container); static void obj_created(lv_fragment_t *self, lv_obj_t *obj); static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj); static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj); static void hosts_changed(array_list_t *list, host_manager_hosts_change change_type, int change_index, void *context); static void launcher_gamepads_changed(launcher_fragment *fragment);; static bool event_cb(lv_fragment_t *self, int type, void *data); static lv_obj_t *launch_option_create_label_action(launcher_fragment *fragment, const char *icon, const char *label); static lv_obj_t *launch_option_get_label(lv_obj_t *obj); static void launch_option_set_text(lv_obj_t *obj, const char *label); static void focus_content(lv_event_t *e); static void open_settings(lv_event_t *e); static void open_support(lv_event_t *e); static void select_host(lv_event_t *e); static void request_session(lv_event_t *e); static void launcher_quit(lv_event_t *e); static void hosts_update(launcher_fragment *fragment); static const IHS_HostInfo *get_selected_host(launcher_fragment *fragment); const lv_fragment_class_t launcher_fragment_class = { .constructor_cb = constructor, .destructor_cb = destructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .obj_will_delete_cb = obj_will_delete, .obj_deleted_cb = obj_deleted, .event_cb = event_cb, .instance_size = sizeof(launcher_fragment), }; static const host_manager_listener_t host_manager_listener = { .hosts_changed = hosts_changed, }; static void constructor(lv_fragment_t *self, void *arg) { app_ui_fragment_args_t *fargs = arg; launcher_fragment *fragment = (launcher_fragment *) self; fragment->app = fargs->app; fragment->col_dsc[0] = LV_DPX(250); fragment->col_dsc[1] = LV_DPX(350); fragment->col_dsc[2] = LV_GRID_TEMPLATE_LAST; fragment->row_dsc[0] = LV_DPX(40); fragment->row_dsc[1] = LV_DPX(40); fragment->row_dsc[2] = LV_DPX(40); fragment->row_dsc[3] = LV_GRID_FR(1); fragment->row_dsc[4] = LV_GRID_TEMPLATE_LAST; lv_style_init(&fragment->styles.root); lv_style_set_pad_gap(&fragment->styles.root, LV_DPX(10)); lv_style_set_pad_hor(&fragment->styles.root, 0); lv_style_set_pad_top(&fragment->styles.root, LV_DPX(40)); lv_style_set_pad_bottom(&fragment->styles.root, 0); lv_style_init(&fragment->styles.option_icon); lv_style_set_text_font(&fragment->styles.option_icon, fragment->app->ui->font.heading3); lv_style_set_translate_y(&fragment->styles.option_icon, LV_DPX(4)); } static void destructor(lv_fragment_t *self) { launcher_fragment *fragment = (launcher_fragment *) self; lv_style_reset(&fragment->styles.option_icon); lv_style_reset(&fragment->styles.root); } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { launcher_fragment *fragment = (launcher_fragment *) self; fragment->num_launch_options = 0; lv_obj_t *win = app_lv_win_create(container); lv_win_add_title(win, "IHSplay"); // lv_obj_add_event_cb(actions, focus_content, LV_EVENT_KEY, fragment); lv_obj_add_event_cb(lv_win_get_header(win), focus_content, LV_EVENT_KEY, fragment); lv_obj_t *btn_settings = lv_win_add_btn(win, BS_SYMBOL_GEAR_FILL, LV_DPX(40)); lv_obj_add_event_cb(btn_settings, open_settings, LV_EVENT_CLICKED, fragment); lv_obj_add_flag(btn_settings, LV_OBJ_FLAG_EVENT_BUBBLE); #if !IHSPLAY_WIP_FEATURES lv_obj_add_flag(btn_settings, LV_OBJ_FLAG_HIDDEN); #endif lv_obj_t *btn_support = lv_win_add_btn(win, BS_SYMBOL_QUESTION_CIRCLE_FILL, LV_DPX(40)); lv_obj_add_event_cb(btn_support, open_support, LV_EVENT_CLICKED, fragment); lv_obj_add_flag(btn_support, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_t *btn_quit = lv_win_add_btn(win, BS_SYMBOL_X_LG, LV_DPX(40)); lv_obj_add_event_cb(btn_quit, launcher_quit, LV_EVENT_CLICKED, fragment->app); lv_obj_add_flag(btn_quit, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_t *nav_content = lv_win_get_content(win); lv_obj_add_event_cb(nav_content, focus_content, LV_EVENT_KEY, fragment); fragment->nav_content = nav_content; lv_obj_set_layout(nav_content, LV_LAYOUT_GRID); lv_obj_set_grid_dsc_array(nav_content, fragment->col_dsc, fragment->row_dsc); lv_obj_set_style_pad_gap(nav_content, LV_DPX(20), 0); lv_obj_t *btn_play = lv_btn_create(nav_content); lv_obj_add_flag(btn_play, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_set_size(btn_play, LV_SIZE_CONTENT, LV_DPX(180)); lv_obj_set_flex_flow(btn_play, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(btn_play, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_set_grid_cell(btn_play, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_START, 0, 4); lv_obj_t *img_play = lv_label_create(btn_play); lv_obj_set_style_text_font(img_play, fragment->app->ui->iconfont.heading1, 0); lv_label_set_text_static(img_play, BS_SYMBOL_PLAY_CIRCLE_FILL); lv_obj_t *label_play = lv_label_create(btn_play); lv_label_set_text(label_play, "Start Streaming"); lv_obj_add_event_cb(btn_play, request_session, LV_EVENT_CLICKED, fragment); lv_obj_t *selected_host = launch_option_create_label_action(fragment, BS_SYMBOL_DISPLAY, NULL); fragment->selected_host = selected_host; lv_obj_add_event_cb(selected_host, select_host, LV_EVENT_CLICKED, fragment); lv_obj_t *gamepads = launch_option_create_label_action(fragment, BS_SYMBOL_CONTROLLER, NULL); fragment->gamepads = gamepads; lv_obj_set_dir_focus_obj(btn_settings, LV_DIR_RIGHT, btn_support); lv_obj_set_dir_focus_obj(btn_settings, LV_DIR_BOTTOM, btn_play); lv_obj_set_dir_focus_obj(btn_support, LV_DIR_RIGHT, btn_quit); lv_obj_set_dir_focus_obj(btn_support, LV_DIR_LEFT, btn_settings); lv_obj_set_dir_focus_obj(btn_support, LV_DIR_BOTTOM, btn_play); lv_obj_set_dir_focus_obj(btn_quit, LV_DIR_LEFT, btn_support); lv_obj_set_dir_focus_obj(btn_quit, LV_DIR_BOTTOM, btn_play); lv_obj_set_dir_focus_obj(btn_play, LV_DIR_TOP, btn_settings); lv_obj_set_dir_focus_obj(btn_play, LV_DIR_RIGHT, selected_host); lv_obj_set_dir_focus_obj(selected_host, LV_DIR_LEFT, btn_play); lv_obj_set_dir_focus_obj(selected_host, LV_DIR_TOP, btn_settings); lv_obj_set_dir_focus_obj(selected_host, LV_DIR_BOTTOM, gamepads); lv_obj_set_dir_focus_obj(gamepads, LV_DIR_LEFT, btn_play); lv_obj_set_dir_focus_obj(gamepads, LV_DIR_TOP, selected_host); return win; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { launcher_fragment *fragment = (launcher_fragment *) self; hosts_update(fragment); host_manager_t *hosts_manager = fragment->app->host_manager; host_manager_register_listener(hosts_manager, &host_manager_listener, fragment); host_manager_discovery_start(hosts_manager); hosts_update(fragment); launcher_gamepads_changed(fragment); } static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj) { launcher_fragment *fragment = (launcher_fragment *) self; host_manager_discovery_stop(fragment->app->host_manager); host_manager_unregister_listener(fragment->app->host_manager, &host_manager_listener); } static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); } void launcher_fragment_set_selected_host(lv_fragment_t *self, uint64_t client_id) { launcher_fragment *fragment = (launcher_fragment *) self; fragment->selected_host_id = client_id; } static void hosts_changed(array_list_t *list, host_manager_hosts_change change_type, int change_index, void *context) { launcher_fragment *fragment = (launcher_fragment *) context; if (array_list_size(list) > 0 && fragment->selected_host_id == 0) { const IHS_HostInfo *host = array_list_get(list, 0); fragment->selected_host_id = host->clientId; } hosts_update(fragment); } static void launcher_gamepads_changed(launcher_fragment *fragment) { input_manager_t *manager = fragment->app->input_manager; size_t count = input_manager_sdl_gamepad_count(manager); lv_obj_t *label = launch_option_get_label(fragment->gamepads); if (count == 0) { lv_label_set_text(label, "No gamepad connected"); } else if (count == 1) { lv_label_set_text(label, "1 gamepad connected"); } else { lv_label_set_text_fmt(label, "%u gamepads connected", count); } } static bool event_cb(lv_fragment_t *self, int type, void *data) { (void) data; launcher_fragment *fragment = (launcher_fragment *) self; switch (type) { case APP_UI_GAMEPAD_DEVICE_CHANGED: launcher_gamepads_changed(fragment); return true; case APP_UI_NAV_BACK: return true; default: return false; } } static lv_obj_t *launch_option_create_label_action(launcher_fragment *fragment, const char *icon, const char *label) { int row_pos = fragment->num_launch_options++; lv_obj_t *action = lv_btn_create(fragment->nav_content); lv_obj_add_flag(action, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_set_grid_cell(action, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, row_pos, 1); lv_obj_set_size(action, LV_SIZE_CONTENT, LV_SIZE_CONTENT); lv_obj_set_flex_flow(action, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(action, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_t *icon_obj = lv_img_create(action); lv_obj_add_style(icon_obj, &fragment->styles.option_icon, 0); lv_img_set_src(icon_obj, icon); lv_obj_t *label_obj = lv_label_create(action); lv_obj_set_flex_grow(label_obj, 1); if (label != NULL) { lv_label_set_text(label_obj, label); } return action; } static lv_obj_t *launch_option_get_label(lv_obj_t *obj) { return lv_obj_get_child(obj, 1); } static void launch_option_set_text(lv_obj_t *obj, const char *label) { lv_label_set_text(launch_option_get_label(obj), label); } static void focus_content(lv_event_t *e) { lv_obj_t *current_target = lv_event_get_current_target(e); lv_obj_t *target = lv_event_get_target(e); if (lv_obj_get_parent(target) != current_target) { return; } lv_obj_focus_dir_by_key(target, lv_event_get_key(e)); } static void open_settings(lv_event_t *e) { launcher_fragment *fragment = lv_event_get_user_data(e); app_ui_push_fragment(fragment->app->ui, &settings_fragment_class, NULL); } static void open_support(lv_event_t *e) { launcher_fragment *fragment = lv_event_get_user_data(e); app_ui_push_fragment(fragment->app->ui, &support_fragment_class, NULL); } static void select_host(lv_event_t *e) { launcher_fragment *fragment = lv_event_get_user_data(e); app_ui_push_fragment(fragment->app->ui, &hosts_fragment_class, fragment); } static void request_session(lv_event_t *e) { launcher_fragment *fragment = lv_event_get_user_data(e); const IHS_HostInfo *host = get_selected_host(fragment); if (host == NULL) { return; } IHS_HostInfo *data = calloc(1, sizeof(IHS_HostInfo)); *data = *host; app_ui_push_fragment(fragment->app->ui, &connection_fragment_class, data); } static void launcher_quit(lv_event_t *e) { app_quit(lv_event_get_user_data(e)); } static void hosts_update(launcher_fragment *fragment) { const IHS_HostInfo *host = get_selected_host(fragment); if (host != NULL) { launch_option_set_text(fragment->selected_host, host->hostname); } else { launch_option_set_text(fragment->selected_host, "Select computer..."); } } static const IHS_HostInfo *get_selected_host(launcher_fragment *fragment) { host_manager_t *manager = fragment->app->host_manager; array_list_t *hosts = host_manager_get_hosts(manager); const IHS_HostInfo *host = NULL; for (int i = 0, j = array_list_size(hosts); i < j; i++) { const IHS_HostInfo *info = array_list_get(hosts, i); if (fragment->selected_host_id == info->clientId) { host = info; break; } } return host; } ================================================ FILE: app/ui/launcher.h ================================================ #pragma once #include extern const lv_fragment_class_t launcher_fragment_class; void launcher_fragment_set_selected_host(lv_fragment_t *self, uint64_t client_id); ================================================ FILE: app/ui/session/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE session.c connection_progress.c streaming_overlay.c ) ================================================ FILE: app/ui/session/connection_progress.c ================================================ #include "connection_progress.h" #include "session.h" #include "app.h" #include "ui/app_ui.h" typedef struct connection_progress_fragment { lv_fragment_t base; app_t *app; lv_coord_t col_dsc[3], row_dsc[3]; } connection_progress_fragment; void constructor(lv_fragment_t *self, void *args) { connection_progress_fragment *fragment = (connection_progress_fragment *) self; fragment->app = args; } lv_obj_t *create_obj_cb(lv_fragment_t *self, lv_obj_t *container) { connection_progress_fragment *fragment = (connection_progress_fragment *) self; lv_fragment_t *session_fragment = lv_fragment_get_parent(self); lv_obj_t *content = lv_obj_create(container); lv_obj_remove_style_all(content); lv_obj_add_style(content, session_fragment_get_overlay_style(session_fragment), 0); lv_obj_set_layout(content, LV_LAYOUT_GRID); fragment->col_dsc[0] = LV_GRID_CONTENT; fragment->col_dsc[1] = LV_GRID_FR(1); fragment->col_dsc[2] = LV_GRID_TEMPLATE_LAST; fragment->row_dsc[0] = LV_GRID_FR(1); fragment->row_dsc[1] = LV_DPX(50); fragment->row_dsc[2] = LV_GRID_TEMPLATE_LAST; lv_obj_set_grid_dsc_array(content, fragment->col_dsc, fragment->row_dsc); lv_obj_t *title = lv_label_create(content); lv_obj_set_style_text_font(title, lv_theme_get_font_large(content), 0); lv_obj_set_grid_cell(title, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 0, 1); lv_obj_set_style_pad_top(title, LV_DPX(20), 0); lv_label_set_text_static(title, "Connecting"); lv_obj_t *subtitle = lv_label_create(content); lv_obj_set_style_pad_top(subtitle, LV_DPX(15), 0); lv_obj_set_grid_cell(subtitle, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 1, 1); lv_label_set_text_fmt(subtitle, "Setting up streaming for %s...", session_fragment_get_host_name(session_fragment)); lv_obj_t *spinner = lv_spinner_create(content, 1000, 60); lv_obj_set_style_arc_width(spinner, LV_DPX(10), 0); lv_obj_set_style_arc_width(spinner, LV_DPX(10), LV_PART_INDICATOR); lv_obj_set_size(spinner, LV_DPX(50), LV_DPX(50)); lv_obj_set_grid_cell(spinner, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 0, 2); return content; } const lv_fragment_class_t connection_progress_class = { .constructor_cb = constructor, .create_obj_cb = create_obj_cb, .instance_size = sizeof(connection_progress_fragment), }; ================================================ FILE: app/ui/session/connection_progress.h ================================================ #pragma once #include "lvgl.h" extern const lv_fragment_class_t connection_progress_class; ================================================ FILE: app/ui/session/session.c ================================================ #include #include "session.h" #include "ihslib.h" #include "ui/app_ui.h" #include "app.h" #include "ui/common/progress_dialog.h" #include "array_list.h" #include "backend/stream_manager.h" #include "streaming_overlay.h" #include "backend/host_manager.h" #include "connection_progress.h" #include "backend/input_manager.h" #include "logging.h" #include "config.h" typedef struct session_fragment_t { lv_fragment_t base; app_t *app; session_fragment_args_t args; array_list_t *cursors; SDL_Cursor *blank_cursor; uint64_t cursor_id; bool cursor_visible; lv_fragment_t *overlay; lv_obj_t *overlay_hint; lv_obj_t *overlay_progress; struct { lv_style_t overlay; } styles; } session_fragment_t; typedef struct cursor_t { uint64_t id; SDL_Cursor *cursor; } cursor_t; static void constructor(lv_fragment_t *self, void *args); static void destructor(lv_fragment_t *self); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container); static void obj_created(lv_fragment_t *self, lv_obj_t *obj); static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj); static bool event_cb(lv_fragment_t *self, int code, void *userdata); const lv_fragment_class_t session_fragment_class = { .constructor_cb = constructor, .destructor_cb = destructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .obj_will_delete_cb = obj_will_delete, .event_cb = event_cb, .instance_size = sizeof(session_fragment_t) }; static void session_connected_main(const IHS_SessionInfo *info, void *context); static void session_disconnected_main(const IHS_SessionInfo *info, bool requested, void *context); static void session_overlay_progress(int percentage, void *context); static void session_overlay_progress_finished(bool requested, void *context); const static stream_manager_listener_t stream_manager_listener = { .connected = session_connected_main, .disconnected = session_disconnected_main, .overlay_progress = session_overlay_progress, .overlay_progress_finished = session_overlay_progress_finished, }; static void session_show_cursor(IHS_Session *session, float x, float y, void *context); static void session_hide_cursor(IHS_Session *session, void *context); static bool session_set_cursor(IHS_Session *session, uint64_t cursorId, void *context); static void session_cursor_image(IHS_Session *session, const IHS_StreamInputCursorImage *image, void *context); static const cursor_t *session_current_cursor(session_fragment_t *fragment); static void disconnected_dialog_cb(lv_event_t *e); static void screen_clicked_cb(lv_event_t *e); static void set_overlay_visible(session_fragment_t *fragment, bool visible); static void constructor(lv_fragment_t *self, void *args) { session_fragment_t *fragment = (session_fragment_t *) self; const app_ui_fragment_args_t *fargs = args; fragment->app = fargs->app; #if IHSPLAY_IS_DEBUG if (fargs->data == NULL) { memset(&fragment->args, 0, sizeof(fragment->args)); } else { fragment->args = *(session_fragment_args_t *) fargs->data; } #else assert (fargs->data != NULL); fragment->args = *(session_fragment_args_t *) fargs->data; #endif fragment->cursors = array_list_create(sizeof(cursor_t), 16); const static Uint8 blank_pixel[1] = {0}; fragment->blank_cursor = SDL_CreateCursor(blank_pixel, blank_pixel, 1, 1, 0, 0); lv_coord_t overlay_height = LV_DPX(100); lv_style_init(&fragment->styles.overlay); lv_style_set_border_side(&fragment->styles.overlay, LV_BORDER_SIDE_TOP); lv_style_set_border_width(&fragment->styles.overlay, LV_DPX(2)); lv_style_set_border_color(&fragment->styles.overlay, lv_palette_main(LV_PALETTE_BLUE)); lv_style_set_bg_color(&fragment->styles.overlay, lv_palette_main(LV_PALETTE_BLUE_GREY)); lv_style_set_bg_opa(&fragment->styles.overlay, LV_OPA_80); lv_style_set_pad_ver(&fragment->styles.overlay, LV_DPX(5)); lv_style_set_pad_hor(&fragment->styles.overlay, LV_DPX(30)); lv_style_set_width(&fragment->styles.overlay, LV_PCT(100)); lv_style_set_height(&fragment->styles.overlay, overlay_height); lv_style_set_align(&fragment->styles.overlay, LV_ALIGN_BOTTOM_MID); stream_manager_set_overlay_height(fragment->app->stream_manager, overlay_height); } static void destructor(lv_fragment_t *self) { session_fragment_t *fragment = (session_fragment_t *) self; lv_style_reset(&fragment->styles.overlay); array_list_destroy(fragment->cursors); SDL_FreeCursor(fragment->blank_cursor); } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { session_fragment_t *fragment = (session_fragment_t *) self; lv_obj_t *obj = lv_obj_create(container); lv_obj_remove_style_all(obj); lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); lv_obj_add_event_cb(obj, screen_clicked_cb, LV_EVENT_CLICKED, fragment); lv_obj_t *overlay_hint = lv_obj_create(obj); lv_obj_set_size(overlay_hint, LV_SIZE_CONTENT, LV_DPX(60)); lv_obj_set_style_bg_opa(overlay_hint, LV_OPA_80, 0); lv_obj_set_style_bg_color(overlay_hint, lv_palette_main(LV_PALETTE_BLUE_GREY), 0); lv_obj_set_layout(overlay_hint, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(overlay_hint, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(overlay_hint, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START); lv_obj_set_style_pad_ver(overlay_hint, LV_DPX(15), 0); lv_obj_set_style_pad_hor(overlay_hint, LV_DPX(20), 0); lv_obj_set_style_pad_gap(overlay_hint, LV_DPX(15), 0); lv_obj_t *overlay_label = lv_label_create(overlay_hint); lv_label_set_text_static(overlay_label, "Long press to open the menu"); lv_obj_t *overlay_progress = lv_arc_create(overlay_hint); lv_obj_set_size(overlay_progress, LV_DPX(30), LV_DPX(30)); lv_arc_set_bg_angles(overlay_progress, 0, 360); lv_arc_set_angles(overlay_progress, 0, 360); lv_arc_set_rotation(overlay_progress, 270); lv_arc_set_range(overlay_progress, 0, 99); lv_arc_set_value(overlay_progress, 30); lv_obj_set_style_arc_width(overlay_progress, LV_DPX(5), 0); lv_obj_set_style_arc_width(overlay_progress, LV_DPX(5), LV_PART_INDICATOR); fragment->overlay_hint = overlay_hint; fragment->overlay_progress = overlay_progress; lv_obj_add_flag(overlay_hint, LV_OBJ_FLAG_HIDDEN); lv_obj_align(overlay_hint, LV_ALIGN_LEFT_MID, 0, LV_PCT(10)); return obj; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); session_fragment_t *fragment = (session_fragment_t *) self; fragment->overlay = lv_fragment_create(&connection_progress_class, fragment->app); lv_fragment_manager_replace(fragment->base.child_manager, fragment->overlay, &fragment->base.obj); stream_manager_t *stream_manager = fragment->app->stream_manager; stream_manager_register_listener(stream_manager, &stream_manager_listener, fragment); if (fragment->args.session.sessionKeyLen > 0) { stream_manager_start_session(stream_manager, &fragment->args.session); } app_ui_set_ignore_keys(fragment->app->ui, true); lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_TRANSP, 0); } static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); session_fragment_t *fragment = (session_fragment_t *) self; app_ui_set_ignore_keys(fragment->app->ui, false); stream_manager_unregister_listener(fragment->app->stream_manager, &stream_manager_listener); lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, 0); } static bool event_cb(lv_fragment_t *self, int code, void *userdata) { LV_UNUSED(userdata); session_fragment_t *fragment = (session_fragment_t *) self; switch (code) { case APP_UI_REQUEST_OVERLAY: { set_overlay_visible(fragment, true); return true; } case APP_UI_CLOSE_OVERLAY: { set_overlay_visible(fragment, false); return true; } case APP_UI_NAV_BACK: { stream_manager_t *stream_manager = fragment->app->stream_manager; if (stream_manager_is_overlay_opened(stream_manager)) { stream_manager_set_overlay_opened(stream_manager, false); return true; } return false; } case APP_UI_NAV_QUIT: { return true; } default: break; } return false; } static void session_connected_main(const IHS_SessionInfo *info, void *context) { LV_UNUSED(info); session_fragment_t *fragment = (session_fragment_t *) context; if (fragment->overlay != NULL) { lv_fragment_manager_remove(fragment->base.child_manager, fragment->overlay); fragment->overlay = NULL; } } static void session_disconnected_main(const IHS_SessionInfo *info, bool requested, void *context) { LV_UNUSED(info); session_fragment_t *fragment = (session_fragment_t *) context; // SDL_SetCursor(SDL_GetDefaultCursor()); if (!requested) { static const char *btn_txts[] = {"OK", ""}; lv_obj_t *mbox = lv_msgbox_create(NULL, NULL, "Disconnected.", btn_txts, false); lv_obj_add_event_cb(mbox, disconnected_dialog_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_center(mbox); } app_ui_pop_top_fragment(fragment->app->ui); } static void session_overlay_progress(int percentage, void *context) { session_fragment_t *fragment = (session_fragment_t *) context; if (lv_obj_has_flag(fragment->overlay_hint, LV_OBJ_FLAG_HIDDEN)) { lv_obj_clear_flag(fragment->overlay_hint, LV_OBJ_FLAG_HIDDEN); } lv_arc_set_value(fragment->overlay_progress, (int16_t) percentage); } static void session_overlay_progress_finished(bool requested, void *context) { session_fragment_t *fragment = (session_fragment_t *) context; lv_obj_add_flag(fragment->overlay_hint, LV_OBJ_FLAG_HIDDEN); } static void session_show_cursor(IHS_Session *session, float x, float y, void *context) { session_fragment_t *fragment = context; commons_log_info("Session", "show_cursor: x=%f, y=%f", x, y); if (!fragment->cursor_visible) { fragment->cursor_visible = true; const cursor_t *cursor = session_current_cursor(fragment); if (cursor != NULL) { // SDL_SetCursor(cursor->cursor); } } } static bool session_set_cursor(IHS_Session *session, uint64_t cursorId, void *context) { session_fragment_t *fragment = context; fragment->cursor_id = cursorId; const cursor_t *cursor = session_current_cursor(fragment); if (!cursor) { return false; } if (fragment->cursor_visible) { SDL_SetCursor(cursor->cursor); } return true; } static void session_hide_cursor(IHS_Session *session, void *context) { session_fragment_t *fragment = context; if (fragment->cursor_visible) { fragment->cursor_visible = false; SDL_SetCursor(fragment->blank_cursor); } } static const cursor_t *session_current_cursor(session_fragment_t *fragment) { cursor_t *cursor = NULL; for (int i = 0, j = array_list_size(fragment->cursors); i < j; ++i) { cursor_t *item = array_list_get(fragment->cursors, i); if (item->id == fragment->cursor_id) { cursor = item; break; } } return cursor; } static void session_cursor_image(IHS_Session *session, const IHS_StreamInputCursorImage *image, void *context) { session_fragment_t *fragment = context; cursor_t *cursor = NULL; for (int i = 0, j = array_list_size(fragment->cursors); i < j; ++i) { cursor_t *item = array_list_get(fragment->cursors, i); if (item->id == image->width) { cursor = item; break; } } if (cursor == NULL) { cursor = array_list_add(fragment->cursors, -1); } else { SDL_FreeCursor(cursor->cursor); } SDL_Surface *surface = SDL_CreateRGBSurfaceFrom((void *) image->image, image->width, image->height, 32, image->width * 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); cursor->id = image->cursorId; cursor->cursor = SDL_CreateColorCursor(surface, image->hotX, image->hotY); SDL_FreeSurface(surface); if (fragment->cursor_visible && fragment->cursor_id == cursor->id) { SDL_SetCursor(cursor->cursor); } } static void disconnected_dialog_cb(lv_event_t *e) { lv_obj_t *msgbox = lv_event_get_current_target(e); lv_msgbox_close_async(msgbox); } static void screen_clicked_cb(lv_event_t *e) { session_fragment_t *fragment = lv_event_get_user_data(e); stream_manager_t *manager = fragment->app->stream_manager; if (!stream_manager_is_overlay_opened(manager)) { return; } stream_manager_set_overlay_opened(manager, false); } static void set_overlay_visible(session_fragment_t *fragment, bool visible) { if (visible == (fragment->overlay != NULL && fragment->overlay->cls == &streaming_overlay_class)) { return; } app_ui_set_ignore_keys(fragment->app->ui, !visible); if (visible) { lv_fragment_t *overlay_fragment = lv_fragment_create(&streaming_overlay_class, fragment->app); lv_fragment_manager_replace(fragment->base.child_manager, overlay_fragment, &fragment->base.obj); fragment->overlay = overlay_fragment; } else { lv_fragment_manager_remove(fragment->base.child_manager, fragment->overlay); fragment->overlay = NULL; } } lv_style_t *session_fragment_get_overlay_style(lv_fragment_t *fragment) { return &((session_fragment_t *) fragment)->styles.overlay; } const char *session_fragment_get_host_name(lv_fragment_t *fragment) { return ((session_fragment_t *) fragment)->args.host.hostname; } ================================================ FILE: app/ui/session/session.h ================================================ #pragma once #include "lvgl.h" #include "ihslib.h" typedef struct session_fragment_args_t { IHS_HostInfo host; IHS_SessionInfo session; } session_fragment_args_t; extern const lv_fragment_class_t session_fragment_class; lv_style_t *session_fragment_get_overlay_style(lv_fragment_t *fragment); const char *session_fragment_get_host_name(lv_fragment_t *fragment); ================================================ FILE: app/ui/session/streaming_overlay.c ================================================ #include "streaming_overlay.h" #include "lvgl/fonts/bootstrap-icons/symbols.h" #include "app.h" #include "ui/app_ui.h" #include "backend/stream_manager.h" #include "session.h" typedef struct streaming_overlay_fragment_t { lv_fragment_t base; app_t *app; struct { } styles; } streaming_overlay_fragment_t; static void constructor_cb(lv_fragment_t *self, void *args); static void destructor_cb(lv_fragment_t *self); static lv_obj_t *create_obj_cb(lv_fragment_t *self, lv_obj_t *container); static void obj_created_cb(lv_fragment_t *self, lv_obj_t *obj); static void quit_clicked_cb(lv_event_t *e); const lv_fragment_class_t streaming_overlay_class = { .constructor_cb = constructor_cb, .destructor_cb = destructor_cb, .create_obj_cb = create_obj_cb, .obj_created_cb = obj_created_cb, .instance_size = sizeof(streaming_overlay_fragment_t), }; static void constructor_cb(lv_fragment_t *self, void *args) { streaming_overlay_fragment_t *fragment = (streaming_overlay_fragment_t *) self; fragment->app = args; } static void destructor_cb(lv_fragment_t *self) { } static lv_obj_t *create_obj_cb(lv_fragment_t *self, lv_obj_t *container) { streaming_overlay_fragment_t *fragment = (streaming_overlay_fragment_t *) self; lv_fragment_t *session_fragment = lv_fragment_get_parent(self); lv_obj_t *content = lv_obj_create(container); lv_obj_remove_style_all(content); lv_obj_add_style(content, session_fragment_get_overlay_style(session_fragment), 0); lv_obj_set_style_pad_hor(content, LV_DPX(30), 0); lv_obj_add_flag(content, LV_OBJ_FLAG_CLICKABLE); lv_obj_t *quit = lv_btn_create(content); lv_obj_set_style_radius(quit, LV_DPX(4), 0); lv_obj_add_event_cb(quit, quit_clicked_cb, LV_EVENT_CLICKED, self); lv_obj_t *quit_label = lv_label_create(quit); lv_obj_add_style(quit_label, &fragment->app->ui->styles.action_btn_label, 0); lv_label_set_text(quit_label, BS_SYMBOL_POWER); lv_obj_align(quit, LV_ALIGN_LEFT_MID, 0, 0); return content; } static void obj_created_cb(lv_fragment_t *self, lv_obj_t *obj) { } static void quit_clicked_cb(lv_event_t *e) { streaming_overlay_fragment_t *fragment = lv_event_get_user_data(e); stream_manager_stop_active(fragment->app->stream_manager); } ================================================ FILE: app/ui/session/streaming_overlay.h ================================================ #pragma once #include "lvgl.h" extern const lv_fragment_class_t streaming_overlay_class; ================================================ FILE: app/ui/settings/basic.c ================================================ #include "app.h" #include "basic.h" #include "widgets.h" #include "config.h" typedef struct basic_fragment { lv_fragment_t base; app_t *app; } basic_fragment; static void constructor(lv_fragment_t *self, void *arg) { } static void destructor(lv_fragment_t *self) { } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { lv_obj_t *list = lv_obj_create(container); lv_obj_remove_style_all(list); lv_obj_set_size(list, LV_PCT(100), LV_PCT(100)); lv_obj_set_layout(list, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(list, LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_style_pad_ver(list, LV_DPX(15), 0); lv_obj_set_style_pad_hor(list, LV_DPX(20), 0); lv_obj_set_style_pad_gap(list, LV_DPX(10), 0); #if IHSPLAY_WIP_FEATURES settings_select_create(list, "Resolution"); settings_select_create(list, "Framerate"); settings_select_create(list, "Bitrate"); #endif settings_select_create(list, "Audio Backend"); settings_select_create(list, "Video Decoder"); return list; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { } static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj) { } static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj) { } const lv_fragment_class_t settings_basic_fragment_class = { .constructor_cb = constructor, .destructor_cb = destructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .obj_will_delete_cb = obj_will_delete, .obj_deleted_cb = obj_deleted, .instance_size = sizeof(basic_fragment), }; ================================================ FILE: app/ui/settings/basic.h ================================================ #pragma once #include extern const lv_fragment_class_t settings_basic_fragment_class; ================================================ FILE: app/ui/settings/settings.c ================================================ #include "settings.h" #include "app.h" #include "ui/launcher.h" #include "lvgl/theme.h" #include "basic.h" #include "ui/app_ui.h" typedef struct settings_fragment { lv_fragment_t base; app_t *app; lv_obj_t *content; } settings_fragment; static void constructor(lv_fragment_t *self, void *arg); static void destructor(lv_fragment_t *self); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container); static void obj_created(lv_fragment_t *self, lv_obj_t *obj); static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj); static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj); static bool event_cb(lv_fragment_t *self, int code, void *data); const lv_fragment_class_t settings_fragment_class = { .constructor_cb = constructor, .destructor_cb = destructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .obj_will_delete_cb = obj_will_delete, .obj_deleted_cb = obj_deleted, .event_cb = event_cb, .instance_size = sizeof(settings_fragment), }; static void constructor(lv_fragment_t *self, void *arg) { settings_fragment *fragment = (settings_fragment *) self; fragment->app = ((app_ui_fragment_args_t *) arg)->app; } static void destructor(lv_fragment_t *self) { } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { settings_fragment *fragment = (settings_fragment *) self; lv_obj_t *win = app_lv_win_create(container); lv_win_add_title(win, "Settings"); fragment->content = lv_win_get_content(win); return win; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { settings_fragment *fragment = (settings_fragment *) self; lv_fragment_t *f = lv_fragment_create(&settings_basic_fragment_class, NULL); lv_fragment_manager_replace(self->child_manager, f, &fragment->content); } static void obj_will_delete(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); } static void obj_deleted(lv_fragment_t *self, lv_obj_t *obj) { LV_UNUSED(obj); } static bool event_cb(lv_fragment_t *self, int code, void *data) { (void) data; settings_fragment *fragment = (settings_fragment *) self; if (code == APP_UI_NAV_BACK) { app_ui_pop_top_fragment(fragment->app->ui); return true; } return false; } ================================================ FILE: app/ui/settings/settings.h ================================================ #pragma once #include extern const lv_fragment_class_t settings_fragment_class; ================================================ FILE: app/ui/settings/widgets.c ================================================ #include "widgets.h" lv_obj_t *settings_select_create(lv_obj_t *parent, const char *name) { lv_obj_t *item = lv_label_create(parent); lv_label_set_text(item, name); lv_obj_set_width(item, LV_PCT(100)); lv_obj_t *dropdown = lv_dropdown_create(item); lv_obj_set_width(dropdown, LV_PCT(50)); lv_obj_align(dropdown, LV_ALIGN_RIGHT_MID, 0, 0); return item; } ================================================ FILE: app/ui/settings/widgets.h ================================================ #pragma once #include lv_obj_t *settings_select_create(lv_obj_t *parent, const char *name); ================================================ FILE: app/ui/support/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE support.c wiki.c feedback.c) ================================================ FILE: app/ui/support/feedback.c ================================================ #include "wiki.h" #include "ss4s.h" #include "config.h" #include "app.h" typedef struct feedback_fragment_t { lv_fragment_t base; app_t *app; } feedback_fragment_t; static void feedback_ctor(lv_fragment_t *self, void *arg); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent); const lv_fragment_class_t feedback_fragment_class = { .constructor_cb = feedback_ctor, .create_obj_cb = create_obj, .instance_size = sizeof(feedback_fragment_t) }; static void feedback_ctor(lv_fragment_t *self, void *arg) { ((feedback_fragment_t *) self)->app = arg; } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent) { app_t *app = ((feedback_fragment_t *) self)->app; lv_obj_t *content = lv_obj_create(parent); lv_obj_set_size(content, LV_PCT(100), LV_PCT(100)); lv_obj_set_layout(content, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(content, LV_FLEX_FLOW_ROW_WRAP); lv_obj_t *hint1 = lv_label_create(content); lv_obj_set_width(hint1, LV_PCT(100)); lv_label_set_text(hint1, "Please include information below when you send feedback. " "You can also scan the QR code to copy the text."); lv_obj_t *qrcode = lv_qrcode_create(content, LV_DPX(200), lv_color_black(), lv_color_white()); lv_obj_set_style_pad_all(qrcode, LV_DPX(5), 0); lv_obj_set_style_bg_opa(qrcode, LV_OPA_COVER, 0); lv_obj_set_style_bg_color(qrcode, lv_color_white(), 0); static const char *info_fmt = "Version: %s\n" "Audio Module: %s\n" "Video Module: %s\n" "System: %s\n"; lv_obj_t *info_label = lv_label_create(content); char *os_str = os_info_str(&app->os_info); lv_label_set_text_fmt(info_label, info_fmt, IHSPLAY_VERSION_STRING, SS4S_GetAudioModuleName(), SS4S_GetVideoModuleName(), os_str); if (os_str != NULL) { free(os_str); } lv_obj_set_flex_grow(info_label, 1); const char *info_txt = lv_label_get_text(info_label); lv_qrcode_update(qrcode, info_txt, strlen(info_txt)); return content; } ================================================ FILE: app/ui/support/feedback.h ================================================ #pragma once #include extern const lv_fragment_class_t feedback_fragment_class; ================================================ FILE: app/ui/support/support.c ================================================ #include "support.h" #include "wiki.h" #include "feedback.h" #include "app.h" #include "lvgl/theme.h" #include "ui/app_ui.h" typedef struct support_fragment_t { lv_fragment_t base; lv_coord_t col_dsc[3], row_dsc[4]; lv_obj_t *win_content; int num_btns; app_t *app; } support_fragment_t; static void constructor(lv_fragment_t *self, void *args); static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent); static void obj_created(lv_fragment_t *self, lv_obj_t *obj); static bool event_cb(lv_fragment_t *self, int code, void *data); static void show_page(lv_fragment_t *self, const lv_fragment_class_t *cls); static lv_obj_t *add_btn(support_fragment_t *fragment, lv_obj_t *parent, const char *text, const lv_fragment_class_t *cls); static void btn_click_cb(lv_event_t *e); static void btn_key_cb(lv_event_t *e); const lv_fragment_class_t support_fragment_class = { .constructor_cb = constructor, .create_obj_cb = create_obj, .obj_created_cb = obj_created, .event_cb = event_cb, .instance_size = sizeof(support_fragment_t) }; static void constructor(lv_fragment_t *self, void *args) { support_fragment_t *fragment = (support_fragment_t *) self; fragment->app = ((app_ui_fragment_args_t *) args)->app; fragment->col_dsc[0] = LV_DPX(200); fragment->col_dsc[1] = LV_GRID_FR(1); fragment->col_dsc[2] = LV_GRID_TEMPLATE_LAST; fragment->row_dsc[0] = LV_DPX(40); fragment->row_dsc[1] = LV_DPX(40); fragment->row_dsc[2] = LV_GRID_FR(1); fragment->row_dsc[3] = LV_GRID_TEMPLATE_LAST; fragment->num_btns = 0; } static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent) { support_fragment_t *fragment = (support_fragment_t *) self; lv_obj_t *win = app_lv_win_create(parent); lv_win_add_title(win, "Support"); lv_obj_set_size(win, LV_PCT(100), LV_PCT(100)); fragment->win_content = lv_win_get_content(win); lv_obj_set_style_pad_row(fragment->win_content, LV_DPX(15), 0); lv_obj_set_style_pad_column(fragment->win_content, LV_DPX(30), 0); lv_obj_set_layout(fragment->win_content, LV_LAYOUT_GRID); lv_obj_set_grid_dsc_array(fragment->win_content, fragment->col_dsc, fragment->row_dsc); lv_obj_add_event_cb(fragment->win_content, btn_click_cb, LV_EVENT_CLICKED, fragment); lv_obj_add_event_cb(fragment->win_content, btn_key_cb, LV_EVENT_KEY, fragment); add_btn(fragment, fragment->win_content, "Get Help", &wiki_fragment_class); add_btn(fragment, fragment->win_content, "Feedback", &feedback_fragment_class); return win; } static void obj_created(lv_fragment_t *self, lv_obj_t *obj) { show_page(self, &wiki_fragment_class); } static bool event_cb(lv_fragment_t *self, int code, void *data) { (void) data; support_fragment_t *fragment = (support_fragment_t *) self; if (code == APP_UI_NAV_BACK) { app_ui_pop_top_fragment(fragment->app->ui); return true; } return false; } static lv_obj_t *add_btn(support_fragment_t *fragment, lv_obj_t *parent, const char *text, const lv_fragment_class_t *cls) { LV_ASSERT_NULL(cls); lv_obj_t *btn = lv_btn_create(parent); lv_obj_t *label = lv_label_create(btn); lv_label_set_text(label, text); lv_obj_set_grid_cell(btn, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, fragment->num_btns++, 1); lv_obj_set_user_data(btn, (void *) cls); lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE); return btn; } static void show_page(lv_fragment_t *self, const lv_fragment_class_t *cls) { support_fragment_t *fragment = (support_fragment_t *) self; lv_fragment_t *page = lv_fragment_create(cls, fragment->app); lv_fragment_manager_replace(self->child_manager, page, &fragment->win_content); lv_obj_set_grid_cell(page->obj, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 0, 3); } static void btn_click_cb(lv_event_t *e) { lv_obj_t *target = lv_event_get_target(e); if (!lv_obj_check_type(target, &lv_btn_class)) { return; } const lv_fragment_class_t *cls = lv_obj_get_user_data(target); lv_fragment_t *self = lv_event_get_user_data(e); show_page(self, cls); } static void btn_key_cb(lv_event_t *e) { lv_obj_t *target = lv_event_get_target(e); if (!lv_obj_check_type(target, &lv_btn_class)) { return; } lv_fragment_t *self = lv_event_get_user_data(e); lv_coord_t pos = lv_obj_get_style_grid_cell_row_pos(target, 0); lv_group_t *group = lv_obj_get_group(target); switch (lv_event_get_key(e)) { case LV_KEY_UP: { if (pos > 0) { lv_group_focus_prev(group); } break; } case LV_KEY_DOWN: { support_fragment_t *fragment = (support_fragment_t *) self; if (pos < fragment->num_btns - 1) { lv_group_focus_next(group); } break; } } } ================================================ FILE: app/ui/support/support.h ================================================ #pragma once #include extern const lv_fragment_class_t support_fragment_class; ================================================ FILE: app/ui/support/wiki.c ================================================ #include "wiki.h" static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent); const lv_fragment_class_t wiki_fragment_class = { .create_obj_cb = create_obj, .instance_size = sizeof(lv_fragment_t) }; static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *parent) { lv_obj_t *content = lv_obj_create(parent); lv_obj_set_size(content, LV_PCT(100), LV_PCT(100)); lv_obj_set_layout(content, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(content, LV_FLEX_FLOW_COLUMN); lv_obj_t *hint = lv_label_create(content); lv_obj_set_size(hint, LV_PCT(100), LV_SIZE_CONTENT); const char *url = "https://github.com/mariotaku/ihsplay/wiki"; lv_label_set_text_fmt(hint, "Open %s for guides and frequently asked questions. Or scan the QR code below.", url); lv_obj_t *qrcode = lv_qrcode_create(content, LV_DPX(200), lv_color_black(), lv_color_white()); lv_obj_set_style_bg_opa(qrcode, LV_OPA_COVER, 0); lv_obj_set_style_bg_color(qrcode, lv_color_white(), 0); lv_qrcode_update(qrcode, url, strlen(url)); return content; } ================================================ FILE: app/ui/support/wiki.h ================================================ #pragma once #include extern const lv_fragment_class_t wiki_fragment_class; ================================================ FILE: app/util/CMakeLists.txt ================================================ target_sources(ihsplay PRIVATE listeners_list.c random.c client_info.c) add_subdirectory(video) ================================================ FILE: app/util/client_info.c ================================================ #include #include #include "client_info.h" static const uint8_t secretKey[32] = { 11, 45, 14, 19, 19, 8, 1, 0, 11, 45, 14, 19, 19, 8, 1, 0, 11, 45, 14, 19, 19, 8, 1, 0, 11, 45, 14, 19, 19, 8, 1, 0, }; bool client_info_load_default(client_info_t *info) { memset(info, 0, sizeof(*info)); info->config.deviceName = "IHSplay"; // TODO: generate random number and store them info->config.deviceId = 11451419190810; info->config.secretKey = secretKey; return true; } void client_info_clear(client_info_t *info) { if (info->name != NULL) { free(info->name); } memset(info, 0, sizeof(*info)); } ================================================ FILE: app/util/client_info.h ================================================ #pragma once #include "ihslib.h" typedef struct client_info_t { uint64_t device_id; uint8_t secret_key[32]; char *name; IHS_ClientConfig config; } client_info_t; bool client_info_load(client_info_t *info); bool client_info_load_default(client_info_t *info); void client_info_clear(client_info_t *info); ================================================ FILE: app/util/listeners_list.c ================================================ #include "listeners_list.h" array_list_t *listeners_list_create() { return array_list_create(sizeof(registered_listener_t), 16); } void listeners_list_destroy(array_list_t *list) { for (int i = 0, j = array_list_size(list); i < j; ++i) { registered_listener_t *l = array_list_get(list, i); if (l->refcounter.lock != NULL) { refcounter_destroy(&l->refcounter); } } array_list_destroy(list); } void listeners_list_add(array_list_t *list, const void *listener, void *context) { registered_listener_t *item = array_list_add(list, -1); memset(item, 0, sizeof(registered_listener_t)); refcounter_init(&item->refcounter); item->listener = listener; item->context = context; } void listeners_list_remove(array_list_t *list, const void *listener) { registered_listener_t *to_unregister = NULL; int i; for (i = array_list_size(list) - 1; i >= 0; --i) { registered_listener_t *item = array_list_get(list, i); if (item->listener == listener) { to_unregister = item; break; } } if (to_unregister == NULL || to_unregister->refcounter.counter == 0) return; if (refcounter_unref(&to_unregister->refcounter)) { refcounter_destroy(&to_unregister->refcounter); array_list_remove(list, i); } } ================================================ FILE: app/util/listeners_list.h ================================================ #pragma once #include "array_list.h" #include "refcounter.h" typedef struct registered_listener_t { const void *listener; void *context; refcounter_t refcounter; } registered_listener_t; array_list_t *listeners_list_create(); void listeners_list_destroy(array_list_t *list); void listeners_list_add(array_list_t *list, const void *listener, void *context); void listeners_list_remove(array_list_t *list, const void *listener); #define listeners_list_notify(lst, t, f, ...) { \ for(int i = array_list_size(lst) - 1; i >= 0; i--) { \ registered_listener_t *reg = array_list_get(lst, i); \ if (reg->refcounter.counter == 0) { \ continue; \ } \ const t *l = (const t*) reg->listener; \ refcounter_ref(®->refcounter); \ if (l->f) l->f(__VA_ARGS__, reg->context); \ if (refcounter_unref(®->refcounter)){ \ refcounter_destroy(®->refcounter); \ array_list_remove(lst, i); \ } \ } \ } \ (void) lst ================================================ FILE: app/util/random.c ================================================ #include #include #include #include "random.h" void random_pin(char *pin) { srand(time(NULL)); // NOLINT(cert-msc51-cpp) sprintf(pin, "%04u", rand() / (RAND_MAX / 9999)); // NOLINT(cert-msc50-cpp) } ================================================ FILE: app/util/random.h ================================================ #pragma once void random_pin(char *pin); ================================================ FILE: app/util/refcounter.h ================================================ #pragma once #include #include typedef struct refcounter_t { int counter; SDL_mutex *lock; } refcounter_t; static inline void refcounter_init(refcounter_t *counter) { counter->counter = 1; counter->lock = SDL_CreateMutex(); } static inline void refcounter_destroy(refcounter_t *counter) { SDL_assert(counter->counter == 0 && counter->lock != NULL); SDL_DestroyMutex(counter->lock); counter->lock = NULL; } static inline void refcounter_ref(refcounter_t *counter) { SDL_assert(counter->counter > 0); SDL_LockMutex(counter->lock); counter->counter++; SDL_UnlockMutex(counter->lock); } static inline bool refcounter_unref(refcounter_t *counter) { SDL_assert(counter->counter > 0); SDL_LockMutex(counter->lock); counter->counter--; SDL_UnlockMutex(counter->lock); return counter->counter == 0; } ================================================ FILE: app/util/video/CMakeLists.txt ================================================ add_subdirectory(sps) target_link_libraries(ihsplay PRIVATE sps_util) ================================================ FILE: app/util/video/sps/CMakeLists.txt ================================================ add_library(sps_util STATIC sps_util_h264.c sps_util_h265.c common.c bitstream.c) target_include_directories(sps_util PUBLIC include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(tests) ================================================ FILE: app/util/video/sps/bitstream.c ================================================ #include "bitstream.h" void bitstream_init(bitstream_t *buf, const unsigned char *data, size_t size) { buf->data = data; buf->data_size = size; buf->offset = 0; buf->consecutive_zeroes = 0; } bool bitstream_read_bits(bitstream_t *buf, uint32_t size, uint32_t *value) { if (size > 32) return false; uint32_t result = 0; for (uint32_t i = 0; i < size; i++) { if ((buf->offset + i) % 8 == 0) { uint32_t byte_index = (buf->offset + i) / 8; if (byte_index >= buf->data_size) { return false; } unsigned char b = buf->data[byte_index]; if (b == 0) { buf->consecutive_zeroes++; } else if (b == 0x03 && buf->consecutive_zeroes == 2) { if (++byte_index >= buf->data_size) { return false; } buf->offset += 8; buf->consecutive_zeroes = buf->data[byte_index] == 0; } else { buf->consecutive_zeroes = 0; } } uint32_t cur_offset = buf->offset + i; uint32_t byte_index = cur_offset / 8; if (byte_index >= buf->data_size) { return false; } uint8_t bit_offset = 7 - cur_offset % 8; result |= (buf->data[byte_index] >> bit_offset & 0x1) << (size - i - 1); } buf->offset += size; *value = result; return true; } bool bitstream_skip_bits(bitstream_t *buf, uint32_t size) { uint32_t tmp; for (int i = 0; i < size; i += 16) { if (!bitstream_read_bits(buf, size - i < 16 ? size - i : 16, &tmp)) return false; } return true; } bool bitstream_read_ueg(bitstream_t *buf, uint32_t *value) { uint32_t bitcount = 0; uint32_t tmp; for (;;) { if (!bitstream_read_bits(buf, 1, &tmp)) return false; if (tmp == 0) { bitcount++; } else { // bitOffset--; break; } } // bitOffset --; uint32_t result = 0; if (bitcount) { if (!bitstream_read_bits(buf, bitcount, &tmp)) { return false; } result = (uint32_t) ((1 << bitcount) - 1 + tmp); } *value = result; return true; } bool bitstream_read_eg(bitstream_t *buf, int32_t *value) { uint32_t tmp; if (!bitstream_read_ueg(buf, &tmp)) { return false; } if (tmp & 0x01) { *value = (int32_t) (tmp + 1) / 2; } else { *value = (int32_t) -(tmp / 2); } return true; } bool bitstream_skip_scaling_list(bitstream_t *buf, uint8_t count) { uint32_t lastScale = 8, nextScale = 8; int32_t deltaScale; for (uint8_t j = 0; j < count; j++) { if (nextScale != 0) { if (!bitstream_read_eg(buf, &deltaScale)) return false; nextScale = (lastScale + deltaScale + 256) % 256; } lastScale = (nextScale == 0 ? lastScale : nextScale); } return true; } ================================================ FILE: app/util/video/sps/bitstream.h ================================================ #pragma once #include #include #include typedef struct bitstream_t { const unsigned char *data; size_t data_size; uint32_t offset; uint32_t consecutive_zeroes; } bitstream_t; void bitstream_init(bitstream_t *buf, const unsigned char *data, size_t size); bool bitstream_read_bits(bitstream_t *buf, uint32_t size, uint32_t *value); bool bitstream_read_eg(bitstream_t *buf, int32_t *value); bool bitstream_read_ueg(bitstream_t *buf, uint32_t *value); bool bitstream_skip_bits(bitstream_t *buf, uint32_t size); bool bitstream_skip_scaling_list(bitstream_t *buf, uint8_t count); static inline bool bitstream_read1(bitstream_t *buf, bool *value) { uint32_t tmp; if (!bitstream_read_bits(buf, 1, &tmp)) return false; *value = tmp; return true; } static inline bool bitstream_read2(bitstream_t *buf, uint8_t *value) { uint32_t tmp; if (!bitstream_read_bits(buf, 2, &tmp)) return false; *value = tmp; return true; } static inline bool bitstream_read3(bitstream_t *buf, uint8_t *value) { uint32_t tmp; if (!bitstream_read_bits(buf, 3, &tmp)) return false; *value = tmp; return true; } static inline bool bitstream_read4(bitstream_t *buf, uint8_t *value) { uint32_t tmp; if (!bitstream_read_bits(buf, 4, &tmp)) return false; *value = tmp; return true; } static inline bool bitstream_read8(bitstream_t *buf, uint8_t *value) { uint32_t tmp; if (!bitstream_read_bits(buf, 8, &tmp)) return false; *value = tmp; return true; } ================================================ FILE: app/util/video/sps/common.c ================================================ #include "common.h" int sps_util_nal_skip_start_code(const unsigned char *data, size_t size, size_t begin) { int consecutive_zeroes = 0; bool found = false; for (size_t i = begin; i < size; ++i) { unsigned char b = data[i]; if (found) { return (int) i; } else if (b == 0) { consecutive_zeroes++; } else if (consecutive_zeroes >= 2 && b == 1) { found = true; continue; } else { consecutive_zeroes = 0; } } return -1; } ================================================ FILE: app/util/video/sps/common.h ================================================ #pragma once #include #include #include "bitstream.h" #define bitstream_skip_bits_checked(s, v) if (!bitstream_skip_bits((s), (v))) return false #define bitstream_read1_checked(s, v) if (!bitstream_read1((s), (v))) return false #define bitstream_read2_checked(s, v) if (!bitstream_read2((s), (v))) return false #define bitstream_read3_checked(s, v) if (!bitstream_read3((s), (v))) return false #define bitstream_read4_checked(s, v) if (!bitstream_read4((s), (v))) return false #define bitstream_read8_checked(s, v) if (!bitstream_read8((s), (v))) return false #define bitstream_read_eg_checked(s, v) if (!bitstream_read_eg((s), (v))) return false #define bitstream_read_ueg_checked(s, v) if (!bitstream_read_ueg((s), (v))) return false #define bitstream_skip_scaling_list_checked(s, v) if (!bitstream_skip_scaling_list((s), (v))) return false #define CHECK_RETURN(ret) if (!(ret)) return false /** * * @return Index of the first byte of the NAL needed */ int sps_util_nal_skip_start_code(const unsigned char *data, size_t size, size_t begin); ================================================ FILE: app/util/video/sps/include/sps_util.h ================================================ #pragma once #include #include #include typedef struct sps_dimension_t { uint16_t width; uint16_t height; } sps_dimension_t; bool sps_util_parse_dimension_h264(const unsigned char *data, size_t size, sps_dimension_t *dimension); bool sps_util_parse_dimension_hevc(const unsigned char *data, size_t size, sps_dimension_t *dimension); ================================================ FILE: app/util/video/sps/sps_util_h264.c ================================================ #include "sps_util.h" #include "bitstream.h" #include "common.h" #define EXTENDED_SAR 255 static bool skip_vui_parameters(bitstream_t *buf); static bool skip_hrd_parameters(bitstream_t *buf); bool sps_util_parse_dimension_h264(const unsigned char *data, size_t size, sps_dimension_t *dimension) { int begin = 0; while ((begin = sps_util_nal_skip_start_code(data, size, begin)) >= 0) { if ((data[begin] & 0x1F) == 0x07/* SPS */) { break; } } if (begin < 0|| begin >= size) { return false; } bitstream_t buf; bitstream_init(&buf, data + begin, size - begin); uint8_t subwc[] = {1, 2, 2, 1}; uint8_t subhc[] = {1, 2, 1, 1}; uint32_t chroma_format_idc = 1; uint32_t width, height; // nalu_header bitstream_skip_bits_checked(&buf, 8); uint8_t profile_idc; bitstream_read8_checked(&buf, &profile_idc); // constraint_set[0-5]_flag bitstream_skip_bits_checked(&buf, 6); /* skip reserved_zero_2bits */ if (!bitstream_skip_bits(&buf, 2)) return false; // level_idc bitstream_skip_bits_checked(&buf, 8); uint32_t tmp; // id bitstream_read_ueg_checked(&buf, &tmp); if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || profile_idc == 128 || profile_idc == 138 || profile_idc == 139 || profile_idc == 134 || profile_idc == 135) { if (!bitstream_read_ueg(&buf, &chroma_format_idc)) return false; if (chroma_format_idc > 3) return false; if (chroma_format_idc == 3) { // separate_colour_plane_flag bitstream_skip_bits_checked(&buf, 1); } // bit_depth_luma_minus8 bitstream_read_ueg_checked(&buf, &tmp); // bit_depth_chroma_minus8 bitstream_read_ueg_checked(&buf, &tmp); // qpprime_y_zero_transform_bypass_flag bitstream_skip_bits_checked(&buf, 1); bool scaling_matrix_present_flag; bitstream_read1_checked(&buf, &scaling_matrix_present_flag); if (scaling_matrix_present_flag) { for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); i++) { bool scaling_list_present_flag; bitstream_read1_checked(&buf, &scaling_list_present_flag); if (scaling_list_present_flag) { bitstream_skip_scaling_list_checked(&buf, i < 6 ? 16 : 64); } } } } // log2_max_frame_num_minus4 bitstream_read_ueg_checked(&buf, &tmp); uint32_t pic_order_cnt_type; bitstream_read_ueg_checked(&buf, &pic_order_cnt_type); if (pic_order_cnt_type == 0) { // log2_max_pic_order_cnt_lsb_minus4 bitstream_read_ueg_checked(&buf, &tmp); } else if (pic_order_cnt_type == 1) { // delta_pic_order_always_zero_flag bitstream_skip_bits_checked(&buf, 1); // offset_for_non_ref_pic bitstream_read_eg_checked(&buf, (int32_t *) (&tmp)); // offset_for_top_to_bottom_field bitstream_read_eg_checked(&buf, (int32_t *) (&tmp)); uint32_t num_ref_frames_in_pic_order_cnt_cycle; bitstream_read_ueg_checked(&buf, &num_ref_frames_in_pic_order_cnt_cycle); for (int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) { // offset_for_ref_frame[i] bitstream_read_eg_checked(&buf, (int32_t *) (&tmp)); } } // num_ref_frames bitstream_read_ueg_checked(&buf, &tmp); // gaps_in_frame_num_value_allowed_flag bitstream_skip_bits_checked(&buf, 1); uint32_t pic_width_in_mbs_minus1; if (!bitstream_read_ueg(&buf, &pic_width_in_mbs_minus1)) return false; uint32_t pic_height_in_map_units_minus1; if (!bitstream_read_ueg(&buf, &pic_height_in_map_units_minus1)) return false; bool frame_mbs_only_flag = 0; bitstream_read1_checked(&buf, &frame_mbs_only_flag); if (!frame_mbs_only_flag) { // mb_adaptive_frame_field_flag bitstream_skip_bits_checked(&buf, 1); } // direct_8x8_inference_flag bitstream_skip_bits(&buf, 1); bool frame_cropping_flag; bitstream_read1_checked(&buf, &frame_cropping_flag); uint32_t frame_crop_left_offset = 0, frame_crop_right_offset = 0, frame_crop_top_offset = 0, frame_crop_bottom_offset = 0; if (frame_cropping_flag) { bitstream_read_ueg_checked(&buf, &frame_crop_left_offset); bitstream_read_ueg_checked(&buf, &frame_crop_right_offset); bitstream_read_ueg_checked(&buf, &frame_crop_top_offset); bitstream_read_ueg_checked(&buf, &frame_crop_bottom_offset); } bool vui_parameters_present_flag = false; bitstream_read1_checked(&buf, &vui_parameters_present_flag); if (vui_parameters_present_flag) { if (!skip_vui_parameters(&buf)) return false; } /* Calculate width and height */ width = ((int) pic_width_in_mbs_minus1 + 1); width *= 16; height = ((int) pic_height_in_map_units_minus1 + 1); height *= 16 * (2 - frame_mbs_only_flag); if (frame_cropping_flag) { const uint32_t crop_unit_x = subwc[chroma_format_idc]; const uint32_t crop_unit_y = subhc[chroma_format_idc] * (2 - frame_mbs_only_flag); width -= (frame_crop_left_offset + frame_crop_right_offset) * crop_unit_x; height -= (frame_crop_top_offset + frame_crop_bottom_offset) * crop_unit_y; } if ((int) width <= 0 || (int) height <= 0 || width % 2 != 0 || height % 2 != 0) { return false; } dimension->width = width; dimension->height = height; return true; } static bool skip_vui_parameters(bitstream_t *buf) { bool aspect_ratio_info_present_flag = false; bitstream_read1_checked(buf, &aspect_ratio_info_present_flag); if (aspect_ratio_info_present_flag) { uint8_t aspect_ratio_idc; bitstream_read8(buf, &aspect_ratio_idc); if (aspect_ratio_idc == EXTENDED_SAR) { // sar_width bitstream_skip_bits(buf, 16); // sar_height bitstream_skip_bits(buf, 16); } } bool overscan_info_present_flag = false; bitstream_read1_checked(buf, &overscan_info_present_flag); if (overscan_info_present_flag) { // overscan_appropriate_flag bitstream_skip_bits(buf, 1); } bool video_signal_type_present_flag = false; bitstream_read1_checked(buf, &video_signal_type_present_flag); if (video_signal_type_present_flag) { // video_format bitstream_skip_bits(buf, 3); // video_full_range_flag bitstream_skip_bits(buf, 1); bool colour_description_present_flag = false; bitstream_read1_checked(buf, &colour_description_present_flag); if (colour_description_present_flag) { bitstream_skip_bits(buf, 8); bitstream_skip_bits(buf, 8); bitstream_skip_bits(buf, 8); } } bool chroma_loc_info_present_flag = false; bitstream_read1_checked(buf, &chroma_loc_info_present_flag); if (chroma_loc_info_present_flag) { bitstream_skip_bits(buf, 5); bitstream_skip_bits(buf, 5); } bool timing_info_present_flag = false; bitstream_read1_checked(buf, &timing_info_present_flag); if (timing_info_present_flag) { // num_units_in_tick bitstream_skip_bits(buf, 32); // time_scale bitstream_skip_bits(buf, 32); // fixed_frame_rate_flag bitstream_skip_bits(buf, 1); } bool nal_hrd_parameters_present_flag = false; bitstream_read1_checked(buf, &nal_hrd_parameters_present_flag); if (nal_hrd_parameters_present_flag) { if (!skip_hrd_parameters(buf)) return false; } bool vcl_hrd_parameters_present_flag = false; bitstream_read1_checked(buf, &vcl_hrd_parameters_present_flag); if (vcl_hrd_parameters_present_flag) { if (!skip_hrd_parameters(buf)) return false; } if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) { // low_delay_hrd_flag bitstream_skip_bits(buf, 1); } // pic_struct_present_flag bitstream_skip_bits(buf, 1); bool bitstream_restriction_flag = false; bitstream_read1_checked(buf, &bitstream_restriction_flag); if (bitstream_restriction_flag) { // motion_vectors_over_pic_boundaries_flag bitstream_skip_bits(buf, 1); uint32_t tmp; // max_bytes_per_pic_denom bitstream_read_ueg(buf, &tmp); // max_bits_per_mb_denom bitstream_read_ueg(buf, &tmp); // log2_max_mv_length_horizontal bitstream_read_ueg(buf, &tmp); // log2_max_mv_length_vertical bitstream_read_ueg(buf, &tmp); // num_reorder_frames bitstream_read_ueg(buf, &tmp); // max_dec_frame_buffering bitstream_read_ueg(buf, &tmp); } return true; } static bool skip_hrd_parameters(bitstream_t *buf) { uint32_t cpb_cnt_minus1; bitstream_read_ueg(buf, &cpb_cnt_minus1); if (cpb_cnt_minus1 > 31) return false; // bit_rate_scale bitstream_skip_bits(buf, 4); // cpb_size_scale bitstream_skip_bits(buf, 4); uint32_t tmp; for (int sched_sel_idx = 0; sched_sel_idx <= cpb_cnt_minus1; sched_sel_idx++) { // bit_rate_value_minus1[sched_sel_idx] bitstream_read_ueg(buf, &tmp); // cpb_size_value_minus1[sched_sel_idx] bitstream_read_ueg(buf, &tmp); // cbr_flag[sched_sel_idx] bitstream_skip_bits(buf, 1); } // initial_cpb_removal_delay_length_minus1 bitstream_skip_bits(buf, 5); // cpb_removal_delay_length_minus1 bitstream_skip_bits(buf, 5); // dpb_output_delay_length_minus1 bitstream_skip_bits(buf, 5); // time_offset_length bitstream_skip_bits(buf, 5); return true; } ================================================ FILE: app/util/video/sps/sps_util_h265.c ================================================ /** * @see https://www.itu.int/rec/T-REC-H.265 */ #include #include "sps_util.h" #include "bitstream.h" #include "common.h" #define EXTENDED_SAR 255 static bool parse_profile_info(bitstream_t *buf); static bool parse_profile_tier_level(bitstream_t *buf, uint8_t max_sub_layers_minus1); bool sps_util_parse_dimension_hevc(const unsigned char *data, size_t size, sps_dimension_t *dimension) { int begin = 0; while ((begin = sps_util_nal_skip_start_code(data, size, begin)) >= 0) { if ((data[begin] & 0x7E) >> 1 == 33/* SPS */) { break; } } if (begin < 0 || begin >= size) { return false; } bitstream_t buf; bitstream_init(&buf, data + begin, size - begin); uint8_t subwc[] = {1, 2, 2, 1, 1}; uint8_t subhc[] = {1, 2, 1, 1, 1}; uint8_t max_sub_layers_minus1 = 0; uint32_t tmp; // sps_video_parameter_set_id bitstream_skip_bits_checked(&buf, 4); // sps_max_sub_layers_minus1 bitstream_read3_checked(&buf, &max_sub_layers_minus1); // sps_temporal_id_nesting_flag bitstream_skip_bits(&buf, 1); if (!parse_profile_tier_level(&buf, max_sub_layers_minus1)) { return false; } // seq_parameter_set_id if (!bitstream_read_ueg(&buf, &tmp)) return false; uint32_t chroma_format_idc; if (!bitstream_read_ueg(&buf, &chroma_format_idc)) return false; if (chroma_format_idc == 3) { // separate_colour_plane_flag:1 bitstream_skip_bits(&buf, 1); } uint32_t pic_width_in_luma_samples; uint32_t pic_height_in_luma_samples; if (!bitstream_read_ueg(&buf, &pic_width_in_luma_samples)) return false; if (!bitstream_read_ueg(&buf, &pic_height_in_luma_samples)) return false; if (pic_width_in_luma_samples <= 0 || pic_height_in_luma_samples <= 0) return false; bool conformance_window_flag = false; bitstream_read1(&buf, &conformance_window_flag); uint32_t conf_win_left_offset = 0, conf_win_right_offset = 0, conf_win_top_offset = 0, conf_win_bottom_offset = 0; if (conformance_window_flag) { bitstream_read_ueg_checked(&buf, &conf_win_left_offset); bitstream_read_ueg_checked(&buf, &conf_win_right_offset); bitstream_read_ueg_checked(&buf, &conf_win_top_offset); bitstream_read_ueg_checked(&buf, &conf_win_bottom_offset); } uint32_t width = pic_width_in_luma_samples, height = pic_height_in_luma_samples; if (conformance_window_flag) { const uint8_t crop_unit_x = subwc[chroma_format_idc]; const uint8_t crop_unit_y = subhc[chroma_format_idc]; width -= (conf_win_left_offset + conf_win_right_offset) * crop_unit_x; height -= (conf_win_top_offset + conf_win_bottom_offset) * crop_unit_y; } if ((int) width <= 0 || (int) height <= 0 || width % 2 != 0 || height % 2 != 0) { return false; } dimension->width = width; dimension->height = height; return true; } static bool parse_profile_info(bitstream_t *buf) { // profile_space:2 bitstream_skip_bits_checked(buf, 2); // tier_flag:1 bitstream_skip_bits_checked(buf, 1); // profile_idc:5 bitstream_skip_bits_checked(buf, 5); for (int i = 0; i < 32; i++) { // profile_compatibility_flag[i] bitstream_skip_bits_checked(buf, 1); } // progressive_source_flag bitstream_skip_bits_checked(buf, 1); // interlaced_source_flag bitstream_skip_bits_checked(buf, 1); // non_packed_constraint_flag bitstream_skip_bits_checked(buf, 1); // frame_only_constraint_flag bitstream_skip_bits_checked(buf, 1); bitstream_skip_bits_checked(buf, 44); return true; } static bool parse_profile_tier_level(bitstream_t *buf, uint8_t max_sub_layers_minus1) { bool sub_layer_profile_present_flag[6]; bool sub_layer_level_present_flag[6]; CHECK_RETURN(parse_profile_info(buf)); // level_idc bitstream_skip_bits(buf, 8); for (int i = 0; i < max_sub_layers_minus1; i++) { bitstream_read1_checked(buf, &sub_layer_profile_present_flag[i]); bitstream_read1_checked(buf, &sub_layer_level_present_flag[i]); } if (max_sub_layers_minus1 > 0) { for (int i = max_sub_layers_minus1; i < 8; i++) { // skip 2 bits bitstream_skip_bits_checked(buf, 2); } } for (int i = 0; i < max_sub_layers_minus1; i++) { if (sub_layer_profile_present_flag[i]) { CHECK_RETURN(parse_profile_info(buf)); } if (sub_layer_level_present_flag[i]) { // sub_layer_level_idc[i] bitstream_skip_bits_checked(buf, 8); } } return true; } ================================================ FILE: app/util/video/sps/tests/CMakeLists.txt ================================================ add_executable(test_dimension_h265 test_dimension_h265.c) target_link_libraries(test_dimension_h265 sps_util) add_test(test_dimension_h265 test_dimension_h265) add_executable(test_sps_parsing sps_parser_tests.c) target_link_libraries(test_sps_parsing sps_util) add_test(test_sps_parsing test_sps_parsing) add_executable(test_nal_start_code test_nal_start_code.c) target_link_libraries(test_nal_start_code sps_util) target_include_directories(test_nal_start_code PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../) add_test(test_nal_start_code test_nal_start_code) ================================================ FILE: app/util/video/sps/tests/sample_data.h ================================================ #pragma once #include static const uint8_t sample_data_sps_h265_1[] = { 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x21, 0x40, 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x7b, 0xa0, 0x03, 0xc0, 0x80, 0x11, 0x07, 0xcb, 0x96, 0x5d, 0x29, 0x08, 0x46, 0x45, 0xfd, 0x0c, 0x05, 0xa8, 0x30, 0x30, 0x30, 0x20, 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x07, 0x81, }; ================================================ FILE: app/util/video/sps/tests/sps_parser_tests.c ================================================ #include "sps_util.h" #include static const unsigned char h264_test_data[] = { 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x2a, 0xac, 0x2b, 0x40, 0x3c, 0x01, 0x13, 0xf2, 0xe0, 0x2d, 0x41, 0x81, 0x81, 0xa9, 0x40, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x75, 0x30, 0x23, 0xc7, 0x0a, 0xa8 }; static const unsigned char h265_test_data[] = { 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x21, 0x40, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x7B, 0xA0, 0x03, 0xC0, 0x80, 0x11, 0x07, 0xCB, 0x96, 0xB4, 0xA4, 0x21, 0x19, 0x2E, 0x30, 0x16, 0xA0, 0xC0, 0xC0, 0xD4, 0x82, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x78, 0x5F, 0x1A, 0x2D }; void test_sps_parse_dimension_h264(void) { sps_dimension_t dimension; assert(sps_util_parse_dimension_h264(h264_test_data, sizeof(h264_test_data), &dimension)); assert(dimension.width == 1920); assert(dimension.height == 1080); } void test_sps_parse_dimension_hevc(void) { sps_dimension_t dimension; assert(sps_util_parse_dimension_hevc(h265_test_data, sizeof(h265_test_data), &dimension)); assert(dimension.width == 1920); assert(dimension.height == 1080); } // not needed when using generate_test_runner.rb int main() { test_sps_parse_dimension_h264(); test_sps_parse_dimension_hevc(); return 0; } ================================================ FILE: app/util/video/sps/tests/test_dimension_h265.c ================================================ #include #include "sample_data.h" #include "sps_util.h" int main() { sps_dimension_t dimension; assert(sps_util_parse_dimension_hevc(sample_data_sps_h265_1, sizeof(sample_data_sps_h265_1), &dimension)); assert(dimension.width == 1920); assert(dimension.height == 1080); return 0; } ================================================ FILE: app/util/video/sps/tests/test_nal_start_code.c ================================================ #include #include "common.h" int main() { unsigned char data1[] = {0x00, 0x00, 0x00, 0x01, 0x33}; assert(sps_util_nal_skip_start_code(data1, 5, 0) == 4); unsigned char data2[] = {0x00, 0x00, 0x00, 0x02, 0x33}; assert(sps_util_nal_skip_start_code(data2, 5, 0) == -1); unsigned char data3[] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x33}; assert(sps_util_nal_skip_start_code(data3, 6, 0) == 5); unsigned char data4[] = {0x00, 0x01}; assert(sps_util_nal_skip_start_code(data4, 2, 0) == -1); return 0; } ================================================ FILE: cmake/AresPackage.cmake ================================================ execute_process(COMMAND ares-package "${CPACK_TEMPORARY_DIRECTORY}" -o "${CPACK_PACKAGE_DIRECTORY}" -e include -e cmake -e pkgconfig -e "libmbedtls[.].*" -e "libmbedx509[.].*" ) find_program(GEN_MANIFEST_CMD webosbrew-gen-manifest) if (GEN_MANIFEST_CMD) execute_process(COMMAND "${GEN_MANIFEST_CMD}" -p "${CPACK_PACKAGE_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}.ipk" -o "${CPACK_PACKAGE_DIRECTORY}/${CPACK_PACKAGE_NAME}.manifest.json" -i "https://github.com/mariotaku/ihsplay/raw/master/deploy/webos/largeIcon.png" -l "https://github.com/mariotaku/ihsplay" ) else () message("Skip webOS homebrew manifest generation because command line tool is not found") endif () ================================================ FILE: cmake/CleanupNameLink.cmake ================================================ file(GLOB_RECURSE FOUND_LIBS "${CPACK_TEMPORARY_INSTALL_DIRECTORY}/**/*.so*") function(get_soname PATH) set(SONAME PARENT_SCOPE) execute_process(COMMAND objdump -p ${PATH} OUTPUT_VARIABLE OBJDUMP_OUTPUT COMMAND_ERROR_IS_FATAL ANY) string(REGEX MATCH [[SONAME +([^ ]+)]] SONAME_MATCHES "${OBJDUMP_OUTPUT}") if (SONAME_MATCHES) string(STRIP "${CMAKE_MATCH_1}" SONAME) set(SONAME ${SONAME} PARENT_SCOPE) endif () endfunction() foreach (FOUND_LIB ${FOUND_LIBS}) cmake_path(GET FOUND_LIB FILENAME LIB_BASENAME) cmake_path(GET FOUND_LIB PARENT_PATH LIB_DIRNAME) if (IS_SYMLINK ${FOUND_LIB}) message("Delete symlink ${LIB_BASENAME}") file(REMOVE ${FOUND_LIB}) else () get_soname(${FOUND_LIB}) if (NOT SONAME STREQUAL LIB_BASENAME) message("Rename ${LIB_BASENAME} => ${SONAME}") file(RENAME ${FOUND_LIB} ${LIB_DIRNAME}/${SONAME}) endif () endif () endforeach () ================================================ FILE: cmake/PackageDebian.cmake ================================================ include(CPack) ================================================ FILE: cmake/PackageWebOS.cmake ================================================ get_filename_component(CMAKE_C_COMPILER_NAME "${CMAKE_C_COMPILER}" NAME) if (CMAKE_C_COMPILER_NAME MATCHES "^arm-webos-linux-gnueabi-") set(CPACK_PACKAGE_ARCHITECTURE "arm") else () message(FATAL_ERROR "Unknown build architecture inferred from C compiler ${CMAKE_C_COMPILER_NAME}") endif () set(CPACK_PACKAGE_NAME "org.mariotaku.ihsplay") set(CPACK_GENERATOR "External") set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/AresPackage.cmake") set(CPACK_EXTERNAL_ENABLE_STAGING TRUE) set(CPACK_MONOLITHIC_INSTALL TRUE) set(CPACK_PACKAGE_DIRECTORY ${CMAKE_SOURCE_DIR}/dist) set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${PROJECT_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}") set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_SOURCE_DIR}/cmake/CleanupNameLink.cmake") # Copy manifest configure_file(deploy/webos/appinfo.in.json ./appinfo.json @ONLY) install(TARGETS ihsplay RUNTIME DESTINATION .) install(DIRECTORY ${CMAKE_SOURCE_DIR}/deploy/webos/ DESTINATION . PATTERN ".*" EXCLUDE PATTERN "*.in" EXCLUDE PATTERN "*.in.json" EXCLUDE) install(FILES "${CMAKE_BINARY_DIR}/appinfo.json" DESTINATION .) # Will use all cores on CMake 3.20+ set(CPACK_THREADS 0) if (NOT ENV{CI}) add_custom_target(webos-package-ihsplay COMMAND cpack DEPENDS ihsplay) if (ENV{ARES_DEVICE}) set(ares_arguments "-d" $ENV{ARES_DEVICE}) endif () add_custom_target(webos-install-ihsplay COMMAND ares-install "${CPACK_PACKAGE_FILE_NAME}.ipk" ${ares_arguments} WORKING_DIRECTORY ${CPACK_PACKAGE_DIRECTORY} DEPENDS webos-package-ihsplay ) add_custom_target(webos-launch-ihsplay COMMAND ares-launch "${CPACK_PACKAGE_NAME}" ${ares_arguments} DEPENDS webos-install-ihsplay ) endif () include(CPack) ================================================ FILE: deploy/raspbian/sysroot-packages.list ================================================ libsdl2-dev libopus-dev libmbedtls-dev libraspberrypi-dev libprotobuf-c-dev libfreetype6-dev libfontconfig-dev libcec-dev ================================================ FILE: deploy/webos/appinfo.in.json ================================================ { "id": "@CPACK_PACKAGE_NAME@", "type": "native", "main": "ihsplay", "icon": "icon.png", "largeIcon": "largeIcon.png", "iconColor": "#ffffff", "title": "IHSplay", "version": "@PROJECT_VERSION@", "requiredPermissions": [ "settings", "activities.callbacks" ], "supportTouchMode": "full" } ================================================ FILE: tests/CMakeLists.txt ================================================ enable_testing() function(ihsplay_add_test NAME) cmake_parse_arguments(TEST "" "" "SOURCES;ARGS;INCLUDES;LIBRARIES" ${ARGN}) set(IHSPLAY_TEST_CASE "ihsplay_test_${NAME}") add_executable(${IHSPLAY_TEST_CASE} ${TEST_SOURCES}) target_include_directories(${IHSPLAY_TEST_CASE} PRIVATE ${CMAKE_SOURCE_DIR}/app ${TEST_INCLUDES}) if (TEST_LIBRARIES) target_link_libraries(${IHSPLAY_TEST_CASE} PRIVATE ${TEST_LIBRARIES}) endif () set_target_properties(${IHSPLAY_TEST_CASE} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH_USE_LINK_PATH TRUE INSTALL_RPATH "${IHSPLAY_MODULE_LIBRARY_OUTPUT_DIRECTORY}") add_test(${NAME} ${IHSPLAY_TEST_CASE} ${TEST_ARGS}) set_tests_properties(${NAME} PROPERTIES SKIP_RETURN_CODE 127) set(IHSPLAY_TEST_CASE ${IHSPLAY_TEST_CASE} PARENT_SCOPE) endfunction() add_subdirectory(app) ================================================ FILE: tests/app/CMakeLists.txt ================================================ add_subdirectory(utils) ================================================ FILE: tests/app/utils/CMakeLists.txt ================================================ ================================================ FILE: tools/resource-tools/.gitignore ================================================ node_modules/ ================================================ FILE: tools/resource-tools/.nvmrc ================================================ 16 ================================================ FILE: tools/resource-tools/async-transform.ts ================================================ import {BufferFile, StreamFile} from "vinyl"; import through2 from "through2"; import * as stream from "stream"; type File = BufferFile | StreamFile; export default function asyncTransform(fn: (file: BufferFile | StreamFile) => Promise): stream.Transform { return through2.obj((file, _, cb) => fn(file) .then(ret => cb(null, ret || file)) .catch(e => cb(e))); } ================================================ FILE: tools/resource-tools/binheader.ts ================================================ import {BufferFile} from "vinyl"; import {camelCase, constantCase, pascalCase, snakeCase} from "change-case"; import asyncTransform from "./async-transform"; export type Case = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE'; export interface Option { naming: Case; prefix: string; } function joinWithCase(segments: string[], naming: Case): string { switch (naming) { case "camelCase": { return camelCase(segments.map(s => pascalCase(s)).join()); } case "PascalCase": { return segments.map(s => pascalCase(s)).join(); } case "UPPER_CASE": { return segments.map(s => constantCase(s)).join('_'); } case "snake_case": { return segments.map(s => snakeCase(s)).join('_'); } } } export default function binHeader(option?: Partial