├── .clang-format ├── .gitignore ├── AUTHORS ├── LICENSE ├── README.md ├── analysis_options.yaml └── packages ├── audioplayers ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── elinux │ ├── CMakeLists.txt │ ├── audio_player_stream_handler.h │ ├── audio_player_stream_handler_impl.h │ ├── audioplayers_elinux_plugin.cc │ ├── gst_audio_player.cc │ ├── gst_audio_player.h │ └── include │ │ └── audioplayers_elinux │ │ └── audioplayers_elinux_plugin.h ├── example │ ├── README.md │ ├── assets │ │ ├── ambient_c_motion.mp3 │ │ ├── coins whitespace.wav │ │ ├── coins.mp3 │ │ ├── coins.wav │ │ ├── coins_no_extension │ │ ├── coins_non_ascii_и.wav │ │ ├── invalid.txt │ │ ├── laser.wav │ │ └── nasa_on_a_mission.mp3 │ ├── elinux │ │ ├── CMakeLists.txt │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ └── generated_plugins.cmake │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── command_options.h │ │ │ ├── flutter_embedder_options.h │ │ │ ├── flutter_window.cc │ │ │ ├── flutter_window.h │ │ │ └── main.cc │ ├── lib │ │ ├── components │ │ │ ├── btn.dart │ │ │ ├── cbx.dart │ │ │ ├── dlg.dart │ │ │ ├── drop_down.dart │ │ │ ├── list_tile.dart │ │ │ ├── pad.dart │ │ │ ├── player_widget.dart │ │ │ ├── properties_widget.dart │ │ │ ├── stream_widget.dart │ │ │ ├── tab_content.dart │ │ │ ├── tabs.dart │ │ │ ├── tgl.dart │ │ │ └── txt.dart │ │ ├── main.dart │ │ ├── tabs │ │ │ ├── audio_context.dart │ │ │ ├── controls.dart │ │ │ ├── logger.dart │ │ │ ├── sources.dart │ │ │ └── streams.dart │ │ └── utils.dart │ └── pubspec.yaml └── pubspec.yaml ├── camera ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── elinux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── camera_elinux_plugin.cc │ ├── camera_stream_handler.h │ ├── camera_stream_handler_impl.h │ ├── channels │ │ ├── event_channel_image_stream.cc │ │ ├── event_channel_image_stream.h │ │ ├── method_channel_camera.cc │ │ ├── method_channel_camera.h │ │ ├── method_channel_device.cc │ │ └── method_channel_device.h │ ├── events │ │ └── camera_initialized_event.h │ ├── gst_camera.cc │ ├── gst_camera.h │ ├── include │ │ └── camera_elinux │ │ │ └── camera_elinux_plugin.h │ ├── messages │ │ ├── available_cameras_message.h │ │ ├── messages.h │ │ ├── orientation_message.h │ │ ├── texture_message.h │ │ └── zoom_level_message.h │ └── types │ │ ├── exposure_mode.cc │ │ ├── exposure_mode.h │ │ ├── focus_mode.cc │ │ ├── focus_mode.h │ │ ├── orientation.cc │ │ └── orientation.h ├── example │ ├── elinux │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ ├── generated_plugin_registrant.h │ │ │ └── generated_plugins.cmake │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── command_options.h │ │ │ ├── flutter_embedder_options.h │ │ │ ├── flutter_window.cc │ │ │ ├── flutter_window.h │ │ │ └── main.cc │ ├── integration_test │ │ └── camera_test.dart │ ├── lib │ │ └── main.dart │ ├── pubspec.yaml │ └── test_driver │ │ └── integration_test.dart ├── lib │ ├── camera_elinux.dart │ └── src │ │ ├── elinux_camera.dart │ │ ├── type_conversion.dart │ │ └── utils.dart └── pubspec.yaml ├── joystick ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── elinux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── include │ │ └── joystick │ │ │ └── joystick_plugin.h │ ├── joystick_plugin.cc │ └── linux_joystick.cc ├── example │ ├── .gitignore │ ├── README.md │ ├── elinux │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ ├── generated_plugin_registrant.h │ │ │ └── generated_plugins.cmake │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── command_options.h │ │ │ ├── flutter_embedder_options.h │ │ │ ├── flutter_window.cc │ │ │ ├── flutter_window.h │ │ │ └── main.cc │ ├── lib │ │ └── main.dart │ └── pubspec.yaml ├── lib │ └── joystick.dart └── pubspec.yaml ├── path_provider ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example │ ├── .gitignore │ ├── README.md │ ├── elinux │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ ├── generated_plugin_registrant.h │ │ │ └── generated_plugins.cmake │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── command_options.h │ │ │ ├── flutter_embedder_options.h │ │ │ ├── flutter_window.cc │ │ │ ├── flutter_window.h │ │ │ └── main.cc │ ├── integration_test │ │ └── path_provider_test.dart │ ├── lib │ │ └── main.dart │ ├── pubspec.yaml │ └── test_driver │ │ └── integration_test.dart ├── lib │ ├── path_provider_elinux.dart │ └── src │ │ ├── get_application_id.dart │ │ ├── get_application_id_real.dart │ │ ├── get_application_id_stub.dart │ │ └── path_provider_elinux.dart ├── pubspec.yaml └── test │ └── path_provider_elinux_test.dart ├── shared_preferences ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example │ ├── .gitignore │ ├── README.md │ ├── elinux │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── flutter │ │ │ ├── CMakeLists.txt │ │ │ ├── generated_plugin_registrant.h │ │ │ └── generated_plugins.cmake │ │ └── runner │ │ │ ├── CMakeLists.txt │ │ │ ├── command_options.h │ │ │ ├── flutter_embedder_options.h │ │ │ ├── flutter_window.cc │ │ │ ├── flutter_window.h │ │ │ └── main.cc │ ├── integration_test │ │ └── shared_preferences_test.dart │ ├── lib │ │ └── main.dart │ ├── pubspec.yaml │ └── test_driver │ │ └── integration_test.dart ├── lib │ └── shared_preferences_elinux.dart ├── pubspec.yaml └── test │ └── shared_preferences_elinux_test.dart └── video_player ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── elinux ├── .gitignore ├── CMakeLists.txt ├── gst_video_player.cc ├── gst_video_player.h ├── include │ └── video_player_elinux │ │ └── video_player_elinux_plugin.h ├── messages │ ├── create_message.h │ ├── looping_message.h │ ├── messages.h │ ├── mix_with_others_message.h │ ├── playback_speed_message.h │ ├── position_message.h │ ├── texture_message.h │ └── volume_message.h ├── video_player_elinux_plugin.cc ├── video_player_stream_handler.h └── video_player_stream_handler_impl.h ├── example ├── .gitignore ├── README.md ├── elinux │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ └── runner │ │ ├── CMakeLists.txt │ │ ├── command_options.h │ │ ├── flutter_embedder_options.h │ │ ├── flutter_window.cc │ │ ├── flutter_window.h │ │ └── main.cc ├── lib │ └── main.dart └── pubspec.yaml ├── lib ├── src │ ├── elinux_video_player.dart │ └── messages.g.dart └── video_player_elinux.dart └── pubspec.yaml /.clang-format: -------------------------------------------------------------------------------- 1 | # This file was copied from flutter/packages/.clang-format 2 | 3 | BasedOnStyle: Google 4 | --- 5 | Language: Cpp 6 | DerivePointerAlignment: false 7 | PointerAlignment: Left 8 | --- 9 | Language: ObjC 10 | DerivePointerAlignment: false 11 | PointerAlignment: Right 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This file was copied from flutter/packages/.gitignore. 2 | 3 | .DS_Store 4 | .atom/ 5 | .idea 6 | .packages 7 | .pub/ 8 | .dart_tool/ 9 | .vscode/ 10 | *.iml 11 | 12 | # Gradle? 13 | .uuid 14 | 15 | pubspec.lock 16 | 17 | Podfile.lock 18 | Pods/ 19 | .symlinks/ 20 | 21 | *instrumentscli*.trace 22 | *.cipd 23 | 24 | # Build directories are produced when building using the Flutter CLI. 25 | build 26 | 27 | # This file is produced as a back-up when web_benchmarks fails to parse a 28 | # Chrome trace. 29 | chrome-trace.json 30 | 31 | # Generated files on example apps 32 | flutter_export_environment.sh 33 | .flutter-plugins* 34 | local.properties 35 | keystore.properties 36 | **/Flutter/Generated.xcconfig 37 | **/Flutter/App.framework/ 38 | **/Flutter/ephemeral/ 39 | **/Flutter/Flutter.podspec 40 | **/Flutter/Flutter.framework/ 41 | **/Flutter/flutter_assets/ 42 | 43 | ServiceDefinitions.json 44 | xcuserdata/ 45 | **/DerivedData/ 46 | 47 | generated_plugin_registrant.* 48 | GeneratedPluginRegistrant.* 49 | 50 | # Gradle 51 | **/gradle-wrapper.jar 52 | .gradle/ 53 | gradlew 54 | gradlew.bat 55 | 56 | .project 57 | .classpath 58 | .settings 59 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people and organizations that have contributed 2 | # to sony/flutter-elinux-plugins. Names should be added to the list 3 | # like so: 4 | # 5 | # Name/Organization 6 | 7 | Sony Group Corporation 8 | Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) 9 | Makoto Sato (makoto.sato@atmark-techno.com) 10 | Arjun Patel (patel.arjun50@gmail.com) 11 | Bari Rao (bari.rao@gmail.com) 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter plugins for eLinux 2 | 3 | This repo is a companion repo to the [flutter-elinux](https://github.com/sony/flutter-elinux). It contains the source code for Flutter plugins for eLinux. Check the packages directory for all plugins. 4 | 5 | ### Repositories 6 | 7 | - [flutter-elinux](https://github.com/sony/flutter-elinux): Flutter tools for eLinux 8 | - [flutter-elinux-plugins](https://github.com/sony/flutter-elinux-plugins): Flutter plugins for eLinux 9 | - [flutter-embedded-linux](https://github.com/sony/flutter-embedded-linux): eLinux embedding for Flutter 10 | - [meta-flutter](https://github.com/sony/meta-flutter): Yocto recipes of eLinux embedding for Flutter 11 | 12 | ## Plugins 13 | 14 | The plugins for elinux are basically designed to be API compatible with the official Flutter plugins and others. Therefore, developers can use these plugins like other platforms (Android, iOS, etc.). 15 | 16 | | Package for eLinux | Frontend package | 17 | | ------------------ | ---------------- | 18 | | [video_player_elinux](packages/video_player) | [video_player](https://github.com/flutter/packages/tree/main/packages/video_player/video_player) | 19 | | [camera_elinux](packages/camera) | [camera](https://github.com/flutter/packages/tree/main/packages/camera/camera) | 20 | | [audioplayers_elinux](packages/audioplayers) | [audioplayers](https://github.com/bluefireteam/audioplayers/tree/main/packages/audioplayers) 21 | | [path_provider_elinux](packages/path_provider) | [path_provider](https://github.com/flutter/packages/tree/main/packages/path_provider) | 22 | | [shared_preferences_elinux](packages/shared_preferences) | [shared_preferences](https://github.com/flutter/packages/tree/main/packages/shared_preferences) | 23 | | [joystick](packages/joystick) | - | 24 | |[flutter-webrtc](https://github.com/flutter-webrtc/flutter-webrtc)|<- Thanks, [@cloudwebrtc](https://github.com/cloudwebrtc)| 25 | 26 | ## Getting Started 27 | 28 | For help getting started with Flutter for eLinux, view our online 29 | [documentation](https://github.com/sony/flutter-elinux/wiki). 30 | -------------------------------------------------------------------------------- /packages/audioplayers/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ -------------------------------------------------------------------------------- /packages/audioplayers/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.0 2 | * First draft version. 3 | -------------------------------------------------------------------------------- /packages/audioplayers/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | Copyright (c) 2017 Luan Nico 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following 12 | disclaimer in the documentation and/or other materials provided 13 | with the distribution. 14 | * Neither the names of the copyright holders nor the names of the 15 | contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/audioplayers/README.md: -------------------------------------------------------------------------------- 1 | # audioplayers_elinux 2 | 3 | The implementation of the Audio Player plugin for flutter elinux. APIs are designed to be API compatible with the the official [`audioplayers`](https://github.com/bluefireteam/audioplayers/tree/main/packages/audioplayers). 4 | 5 | ## Required libraries 6 | 7 | This plugin uses [GStreamer](https://gstreamer.freedesktop.org/) internally. 8 | 9 | ```Shell 10 | $ sudo apt install libglib2.0-dev 11 | $ sudo apt install libgstreamer1.0-dev 12 | # Install as needed. 13 | $ sudo apt install libgstreamer-plugins-base1.0-dev \ 14 | gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ 15 | gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav 16 | ``` 17 | 18 | ## Usage 19 | 20 | ### pubspec.yaml 21 | ```yaml 22 | dependencies: 23 | audioplayers: ^6.0.0 24 | audioplayers_elinux: 25 | git: 26 | url: https://github.com/sony/flutter-elinux-plugins.git 27 | path: packages/audioplayers 28 | ref: main 29 | ``` 30 | 31 | ### Source code 32 | Import `audioplayers` in your Dart code: 33 | ```dart 34 | import 'package:audioplayers/audioplayers.dart'; 35 | ``` 36 | -------------------------------------------------------------------------------- /packages/audioplayers/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | set(PROJECT_NAME "audioplayers_elinux") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | # This value is used when generating builds using this plugin, so it must 6 | # not be changed 7 | set(PLUGIN_NAME "audioplayers_elinux_plugin") 8 | 9 | find_package(PkgConfig) 10 | pkg_check_modules(GLIB REQUIRED glib-2.0) 11 | pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) 12 | 13 | add_library(${PLUGIN_NAME} SHARED 14 | "audioplayers_elinux_plugin.cc" 15 | "gst_audio_player.cc" 16 | ) 17 | apply_standard_settings(${PLUGIN_NAME}) 18 | set_target_properties(${PLUGIN_NAME} PROPERTIES 19 | CXX_VISIBILITY_PRESET hidden) 20 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 21 | target_include_directories(${PLUGIN_NAME} INTERFACE 22 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 23 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 24 | 25 | target_include_directories(${PLUGIN_NAME} 26 | PRIVATE 27 | ${GLIB_INCLUDE_DIRS} 28 | ${GSTREAMER_INCLUDE_DIRS} 29 | ) 30 | 31 | target_link_libraries(${PLUGIN_NAME} 32 | PRIVATE 33 | ${GLIB_LIBRARIES} 34 | ${GSTREAMER_LIBRARIES} 35 | ) 36 | 37 | # List of absolute paths to libraries that should be bundled with the plugin 38 | set(audioplayers_elinux_bundled_libraries 39 | "" 40 | PARENT_SCOPE 41 | ) 42 | -------------------------------------------------------------------------------- /packages/audioplayers/elinux/audio_player_stream_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_H_ 6 | #define PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_H_ 7 | 8 | #include 9 | 10 | class AudioPlayerStreamHandler { 11 | public: 12 | AudioPlayerStreamHandler() = default; 13 | virtual ~AudioPlayerStreamHandler() = default; 14 | 15 | // Prevent copying. 16 | AudioPlayerStreamHandler(AudioPlayerStreamHandler const&) = delete; 17 | AudioPlayerStreamHandler& operator=(AudioPlayerStreamHandler const&) = delete; 18 | 19 | // Notifies the completion of preparation the audio player. 20 | void OnNotifyPrepared(const std::string &player_id, 21 | const bool is_prepared) { 22 | OnNotifyPreparedInternal(player_id, is_prepared); 23 | } 24 | 25 | // Notifies the duration of an audio. 26 | void OnNotifyDuration(const std::string &player_id, 27 | const int32_t duration) { 28 | OnNotifyDurationInternal(player_id, duration); 29 | } 30 | 31 | // Notifies the completion of seeks an audio. 32 | void OnNotifySeekCompleted(const std::string &player_id) { 33 | OnNotifySeekCompletedInternal(player_id); 34 | } 35 | 36 | // Notifies the completion of playing an audio. 37 | void OnNotifyPlayCompleted(const std::string &player_id) { 38 | OnNotifyPlayCompletedInternal(player_id); 39 | } 40 | 41 | // Notifies the log of the audio player. 42 | void OnNotifyLog(const std::string &player_id, 43 | const std::string &message) { 44 | OnNotifyLogInternal(player_id, message); 45 | } 46 | 47 | protected: 48 | virtual void OnNotifyPreparedInternal(const std::string&, const bool) = 0; 49 | virtual void OnNotifyDurationInternal(const std::string&, const int32_t) = 0; 50 | virtual void OnNotifySeekCompletedInternal(const std::string&) = 0; 51 | virtual void OnNotifyPlayCompletedInternal(const std::string &) = 0; 52 | virtual void OnNotifyLogInternal(const std::string&, const std::string&) = 0; 53 | }; 54 | 55 | #endif // PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_H_ 56 | -------------------------------------------------------------------------------- /packages/audioplayers/elinux/audio_player_stream_handler_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_IMPL_H_ 6 | #define PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_IMPL_H_ 7 | 8 | #include 9 | 10 | #include "audio_player_stream_handler.h" 11 | 12 | class AudioPlayerStreamHandlerImpl : public AudioPlayerStreamHandler { 13 | public: 14 | using OnNotifyPrepared = std::function; 15 | using OnNotifyDuration = 16 | std::function; 17 | using OnNotifySeekCompleted = std::function; 18 | using OnNotifyPlayCompleted = std::function; 19 | using OnNotifyLog = 20 | std::function; 21 | 22 | AudioPlayerStreamHandlerImpl(OnNotifyPrepared on_notify_prepared, 23 | OnNotifyDuration on_notify_duration, 24 | OnNotifySeekCompleted on_notify_seek_completed, 25 | OnNotifyPlayCompleted on_notify_play_completed, 26 | OnNotifyLog on_notify_log) 27 | : on_notify_prepared_(on_notify_prepared), 28 | on_notify_duration_(on_notify_duration), 29 | on_notify_seek_completed_(on_notify_seek_completed), 30 | on_notify_play_completed_(on_notify_play_completed), 31 | on_notify_log_(on_notify_log) {} 32 | virtual ~AudioPlayerStreamHandlerImpl() = default; 33 | 34 | // Prevent copying. 35 | AudioPlayerStreamHandlerImpl(AudioPlayerStreamHandlerImpl const&) = delete; 36 | AudioPlayerStreamHandlerImpl& operator=(AudioPlayerStreamHandlerImpl const&) = 37 | delete; 38 | 39 | protected: 40 | // |AudioPlayerStreamHandler| 41 | void OnNotifyPreparedInternal(const std::string &player_id, 42 | const bool is_prepared) { 43 | if (on_notify_prepared_) { 44 | on_notify_prepared_(player_id, is_prepared); 45 | } 46 | } 47 | 48 | // |AudioPlayerStreamHandler| 49 | void OnNotifyDurationInternal(const std::string &player_id, 50 | const int32_t duration) { 51 | if (on_notify_duration_) { 52 | on_notify_duration_(player_id, duration); 53 | } 54 | } 55 | 56 | // |AudioPlayerStreamHandler| 57 | void OnNotifySeekCompletedInternal(const std::string &player_id) { 58 | if (on_notify_seek_completed_) { 59 | on_notify_seek_completed_(player_id); 60 | } 61 | } 62 | 63 | // |AudioPlayerStreamHandler| 64 | void OnNotifyPlayCompletedInternal(const std::string &player_id) { 65 | if (on_notify_play_completed_) { 66 | on_notify_play_completed_(player_id); 67 | } 68 | } 69 | 70 | // |AudioPlayerStreamHandler| 71 | void OnNotifyLogInternal(const std::string &player_id, 72 | const std::string &message) { 73 | if (on_notify_log_) { 74 | on_notify_log_(player_id, message); 75 | } 76 | } 77 | 78 | OnNotifyPrepared on_notify_prepared_; 79 | OnNotifyDuration on_notify_duration_; 80 | OnNotifySeekCompleted on_notify_seek_completed_; 81 | OnNotifyPlayCompleted on_notify_play_completed_; 82 | OnNotifyLog on_notify_log_; 83 | }; 84 | 85 | #endif // PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_AUDIO_PLAYER_STREAM_HANDLER_IMPL_H_ 86 | -------------------------------------------------------------------------------- /packages/audioplayers/elinux/gst_audio_player.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_GST_AUDIO_PLAYER_H_ 6 | #define PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_GST_AUDIO_PLAYER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "audio_player_stream_handler.h" 17 | 18 | class GstAudioPlayer { 19 | public: 20 | GstAudioPlayer(const std::string &player_id, 21 | std::unique_ptr handler); 22 | ~GstAudioPlayer(); 23 | 24 | static void GstLibraryLoad(); 25 | static void GstLibraryUnload(); 26 | 27 | void Resume(); 28 | void Play(); 29 | void Pause(); 30 | void Stop(); 31 | void Seek(int64_t position); 32 | void SetSourceUrl(std::string url); 33 | void SetVolume(double volume); 34 | void SetBalance(double balance); 35 | void SetPlaybackRate(double playback_rate); 36 | void SetLooping(bool is_looping); 37 | int64_t GetDuration(); 38 | int64_t GetCurrentPosition(); 39 | void Release(); 40 | void Dispose(); 41 | 42 | private: 43 | struct GstAudioElements { 44 | GstElement* playbin; 45 | GstBus* bus; 46 | GstElement* source; 47 | GstElement* panorama; 48 | GstElement* audiobin; 49 | GstElement* audiosink; 50 | GstPad* panoramasinkpad; 51 | }; 52 | 53 | static GstBusSyncReply HandleGstMessage(GstBus* bus, GstMessage* message, 54 | gpointer user_data); 55 | static void SourceSetup(GstElement* playbin, 56 | GstElement* source, 57 | GstElement** p_src); 58 | bool CreatePipeline(); 59 | std::string ParseUri(const std::string& uri); 60 | 61 | GstAudioElements gst_; 62 | const std::string player_id_; 63 | std::string url_; 64 | bool is_initialized_ = false; 65 | bool is_playing_ = false; 66 | bool is_looping_ = false; 67 | double volume_ = 1.0; 68 | double playback_rate_ = 1.0; 69 | bool is_completed_ = false; 70 | std::unique_ptr stream_handler_; 71 | }; 72 | 73 | #endif // PACKAGES_AUDIOPLAYERS_AUDIOPLAYERS_ELINUX_GST_AUDIO_PLAYER_H_ 74 | -------------------------------------------------------------------------------- /packages/audioplayers/elinux/include/audioplayers_elinux/audioplayers_elinux_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_AUDIOPLAYERS_ELINUX_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_AUDIOPLAYERS_ELINUX_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void AudioplayersElinuxPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_AUDIOPLAYERS_ELINUX_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /packages/audioplayers/example/README.md: -------------------------------------------------------------------------------- 1 | # audioplayers_example 2 | 3 | Demonstrates how to use the audioplayers plugin. 4 | 5 | ## Getting Started 6 | 7 | For help getting started with Flutter for eLinux, view our online 8 | [documentation](https://github.com/sony/flutter-elinux/wiki). -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/ambient_c_motion.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/ambient_c_motion.mp3 -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/coins whitespace.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/coins whitespace.wav -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/coins.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/coins.mp3 -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/coins.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/coins.wav -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/coins_no_extension: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/coins_no_extension -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/coins_non_ascii_и.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/coins_non_ascii_и.wav -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/invalid.txt: -------------------------------------------------------------------------------- 1 | This represents an invalid audio file. 2 | -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/laser.wav -------------------------------------------------------------------------------- /packages/audioplayers/example/assets/nasa_on_a_mission.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sony/flutter-elinux-plugins/b791e8728d7ae9ba5c1ff562c1e0b408b2e8fc1b/packages/audioplayers/example/assets/nasa_on_a_mission.mp3 -------------------------------------------------------------------------------- /packages/audioplayers/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | audioplayers_elinux 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 13 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 16 | endforeach(plugin) 17 | -------------------------------------------------------------------------------- /packages/audioplayers/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/audioplayers/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/audioplayers/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/audioplayers/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/btn.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Btn extends StatelessWidget { 4 | final String txt; 5 | final VoidCallback onPressed; 6 | 7 | const Btn({ 8 | required this.txt, 9 | required this.onPressed, 10 | super.key, 11 | }); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | return Padding( 16 | padding: const EdgeInsets.all(4), 17 | child: ElevatedButton( 18 | style: ElevatedButton.styleFrom(minimumSize: const Size(48, 36)), 19 | onPressed: onPressed, 20 | child: Text(txt), 21 | ), 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/cbx.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Cbx extends StatelessWidget { 4 | final String label; 5 | final bool value; 6 | final void Function({required bool? value}) update; 7 | 8 | const Cbx( 9 | this.label, 10 | this.update, { 11 | required this.value, 12 | super.key, 13 | }); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return CheckboxListTile( 18 | title: Text(label), 19 | value: value, 20 | onChanged: (v) => update(value: v), 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/dlg.dart: -------------------------------------------------------------------------------- 1 | import 'package:audioplayers_elinux_example/components/btn.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class SimpleDlg extends StatelessWidget { 5 | final String message; 6 | final String action; 7 | 8 | const SimpleDlg({ 9 | required this.message, 10 | required this.action, 11 | super.key, 12 | }); 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return Dlg( 17 | child: Column( 18 | mainAxisSize: MainAxisSize.min, 19 | children: [ 20 | Text(message), 21 | Btn( 22 | txt: action, 23 | onPressed: Navigator.of(context).pop, 24 | ), 25 | ], 26 | ), 27 | ); 28 | } 29 | } 30 | 31 | class Dlg extends StatelessWidget { 32 | final Widget child; 33 | 34 | const Dlg({ 35 | required this.child, 36 | super.key, 37 | }); 38 | 39 | @override 40 | Widget build(BuildContext context) { 41 | return Dialog( 42 | child: Padding( 43 | padding: const EdgeInsets.all(16.0), 44 | child: child, 45 | ), 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/drop_down.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class LabeledDropDown extends StatelessWidget { 4 | final String label; 5 | final Map options; 6 | final T selected; 7 | final void Function(T?) onChange; 8 | 9 | const LabeledDropDown({ 10 | required this.label, 11 | required this.options, 12 | required this.selected, 13 | required this.onChange, 14 | super.key, 15 | }); 16 | 17 | @override 18 | Widget build(BuildContext context) { 19 | return ListTile( 20 | title: Text(label), 21 | trailing: CustomDropDown( 22 | options: options, 23 | selected: selected, 24 | onChange: onChange, 25 | ), 26 | ); 27 | } 28 | } 29 | 30 | class CustomDropDown extends StatelessWidget { 31 | final Map options; 32 | final T selected; 33 | final void Function(T?) onChange; 34 | final bool isExpanded; 35 | 36 | const CustomDropDown({ 37 | required this.options, 38 | required this.selected, 39 | required this.onChange, 40 | this.isExpanded = false, 41 | super.key, 42 | }); 43 | 44 | @override 45 | Widget build(BuildContext context) { 46 | return DropdownButton( 47 | isExpanded: isExpanded, 48 | value: selected, 49 | onChanged: onChange, 50 | items: options.entries 51 | .map>( 52 | (entry) => DropdownMenuItem( 53 | value: entry.key, 54 | child: Text(entry.value), 55 | ), 56 | ) 57 | .toList(), 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/list_tile.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class WrappedListTile extends StatelessWidget { 4 | final List children; 5 | final Widget? leading; 6 | final Widget? trailing; 7 | 8 | const WrappedListTile({ 9 | required this.children, 10 | this.leading, 11 | this.trailing, 12 | super.key, 13 | }); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return ListTile( 18 | title: Wrap( 19 | alignment: WrapAlignment.end, 20 | children: children, 21 | ), 22 | leading: leading, 23 | trailing: trailing, 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/pad.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Pad extends StatelessWidget { 4 | final double width; 5 | final double height; 6 | 7 | const Pad({super.key, this.width = 0, this.height = 0}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Container( 12 | width: width, 13 | height: height, 14 | ); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/properties_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:audioplayers/audioplayers.dart'; 2 | import 'package:audioplayers_elinux_example/utils.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class PropertiesWidget extends StatefulWidget { 6 | final AudioPlayer player; 7 | 8 | const PropertiesWidget({ 9 | required this.player, 10 | super.key, 11 | }); 12 | 13 | @override 14 | State createState() => _PropertiesWidgetState(); 15 | } 16 | 17 | class _PropertiesWidgetState extends State { 18 | Future refresh() async { 19 | setState(() {}); 20 | } 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return Column( 25 | children: [ 26 | ListTile( 27 | title: const Text('Properties'), 28 | trailing: ElevatedButton.icon( 29 | icon: const Icon(Icons.refresh), 30 | key: const Key('refreshButton'), 31 | label: const Text('Refresh'), 32 | onPressed: refresh, 33 | ), 34 | ), 35 | ListTile( 36 | title: FutureBuilder( 37 | future: widget.player.getDuration(), 38 | builder: (context, snap) { 39 | return Text( 40 | snap.data?.toString() ?? '-', 41 | key: const Key('durationText'), 42 | ); 43 | }, 44 | ), 45 | subtitle: const Text('Duration'), 46 | leading: const Icon(Icons.timelapse), 47 | ), 48 | ListTile( 49 | title: FutureBuilder( 50 | future: widget.player.getCurrentPosition(), 51 | builder: (context, snap) { 52 | return Text( 53 | snap.data?.toString() ?? '-', 54 | key: const Key('positionText'), 55 | ); 56 | }, 57 | ), 58 | subtitle: const Text('Position'), 59 | leading: const Icon(Icons.timer), 60 | ), 61 | ListTile( 62 | title: Text( 63 | widget.player.state.toString(), 64 | key: const Key('playerStateText'), 65 | ), 66 | subtitle: const Text('State'), 67 | leading: Icon(widget.player.state.getIcon()), 68 | ), 69 | ListTile( 70 | title: Text( 71 | widget.player.source?.toString() ?? '-', 72 | key: const Key('sourceText'), 73 | ), 74 | subtitle: const Text('Source'), 75 | leading: const Icon(Icons.audio_file), 76 | ), 77 | ListTile( 78 | title: Text( 79 | widget.player.volume.toString(), 80 | key: const Key('volumeText'), 81 | ), 82 | subtitle: const Text('Volume'), 83 | leading: const Icon(Icons.volume_up), 84 | ), 85 | ListTile( 86 | title: Text( 87 | widget.player.balance.toString(), 88 | key: const Key('balanceText'), 89 | ), 90 | subtitle: const Text('Balance'), 91 | leading: const Icon(Icons.balance), 92 | ), 93 | ListTile( 94 | title: Text( 95 | widget.player.playbackRate.toString(), 96 | key: const Key('playbackRateText'), 97 | ), 98 | subtitle: const Text('Playback Rate'), 99 | leading: const Icon(Icons.speed), 100 | ), 101 | ], 102 | ); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/stream_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:audioplayers/audioplayers.dart'; 4 | import 'package:audioplayers_elinux_example/utils.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | class StreamWidget extends StatefulWidget { 8 | final AudioPlayer player; 9 | 10 | const StreamWidget({ 11 | required this.player, 12 | super.key, 13 | }); 14 | 15 | @override 16 | State createState() => _StreamWidgetState(); 17 | } 18 | 19 | class _StreamWidgetState extends State { 20 | Duration? streamDuration; 21 | Duration? streamPosition; 22 | PlayerState? streamState; 23 | late List streams; 24 | 25 | AudioPlayer get player => widget.player; 26 | 27 | @override 28 | void initState() { 29 | super.initState(); 30 | // Use initial values from player 31 | streamState = player.state; 32 | player.getDuration().then((it) => setState(() => streamDuration = it)); 33 | player.getCurrentPosition().then( 34 | (it) => setState(() => streamPosition = it), 35 | ); 36 | 37 | streams = [ 38 | player.onDurationChanged 39 | .listen((it) => setState(() => streamDuration = it)), 40 | player.onPlayerStateChanged 41 | .listen((it) => setState(() => streamState = it)), 42 | player.onPositionChanged 43 | .listen((it) => setState(() => streamPosition = it)), 44 | ]; 45 | } 46 | 47 | @override 48 | void dispose() { 49 | super.dispose(); 50 | streams.forEach((it) => it.cancel()); 51 | } 52 | 53 | @override 54 | void setState(VoidCallback fn) { 55 | // Subscriptions only can be closed asynchronously, 56 | // therefore events can occur after widget has been disposed. 57 | if (mounted) { 58 | super.setState(fn); 59 | } 60 | } 61 | 62 | @override 63 | Widget build(BuildContext context) { 64 | return Column( 65 | children: [ 66 | const ListTile(title: Text('Streams')), 67 | ListTile( 68 | title: Text( 69 | streamDuration?.toString() ?? '-', 70 | key: const Key('onDurationText'), 71 | ), 72 | subtitle: const Text('Duration Stream'), 73 | leading: const Icon(Icons.timelapse), 74 | ), 75 | ListTile( 76 | title: Text( 77 | streamPosition?.toString() ?? '-', 78 | key: const Key('onPositionText'), 79 | ), 80 | subtitle: const Text('Position Stream'), 81 | leading: const Icon(Icons.timer), 82 | ), 83 | ListTile( 84 | title: Text( 85 | streamState?.toString() ?? '-', 86 | key: const Key('onStateText'), 87 | ), 88 | subtitle: const Text('State Stream'), 89 | leading: Icon(streamState?.getIcon() ?? Icons.stop), 90 | ), 91 | ], 92 | ); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/tab_content.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class TabContent extends StatelessWidget { 4 | final List children; 5 | 6 | const TabContent({ 7 | required this.children, 8 | super.key, 9 | }); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return Center( 14 | child: Container( 15 | alignment: Alignment.topCenter, 16 | child: SingleChildScrollView( 17 | controller: ScrollController(), 18 | child: Padding( 19 | padding: const EdgeInsets.symmetric(vertical: 8), 20 | child: Column( 21 | children: children, 22 | ), 23 | ), 24 | ), 25 | ), 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/tabs.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class Tabs extends StatelessWidget { 4 | final List tabs; 5 | 6 | const Tabs({ 7 | required this.tabs, 8 | super.key, 9 | }); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return DefaultTabController( 14 | length: tabs.length, 15 | child: Scaffold( 16 | body: Column( 17 | crossAxisAlignment: CrossAxisAlignment.stretch, 18 | children: [ 19 | TabBar( 20 | labelColor: Colors.black, 21 | tabs: tabs 22 | .map( 23 | (tData) => Tab( 24 | key: tData.key != null ? Key(tData.key!) : null, 25 | text: tData.label, 26 | ), 27 | ) 28 | .toList(), 29 | ), 30 | Expanded( 31 | child: TabBarView( 32 | children: tabs.map((tab) => tab.content).toList(), 33 | ), 34 | ), 35 | ], 36 | ), 37 | ), 38 | ); 39 | } 40 | } 41 | 42 | class TabData { 43 | final String? key; 44 | final String label; 45 | final Widget content; 46 | 47 | TabData({ 48 | required this.label, 49 | required this.content, 50 | this.key, 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/tgl.dart: -------------------------------------------------------------------------------- 1 | import 'package:collection/collection.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class Tgl extends StatelessWidget { 5 | final Map options; 6 | final int selected; 7 | final void Function(int) onChange; 8 | 9 | const Tgl({ 10 | required this.options, 11 | required this.selected, 12 | required this.onChange, 13 | super.key, 14 | }); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return ToggleButtons( 19 | isSelected: options.entries 20 | .mapIndexed((index, element) => index == selected) 21 | .toList(), 22 | onPressed: onChange, 23 | borderRadius: const BorderRadius.all(Radius.circular(8)), 24 | selectedBorderColor: Theme.of(context).primaryColor, 25 | children: options.entries 26 | .map( 27 | (entry) => Padding( 28 | padding: const EdgeInsets.all(8), 29 | child: Text( 30 | entry.value, 31 | key: Key(entry.key), 32 | ), 33 | ), 34 | ) 35 | .toList(), 36 | ); 37 | } 38 | } 39 | 40 | class EnumTgl extends StatelessWidget { 41 | final Map options; 42 | final T selected; 43 | final void Function(T) onChange; 44 | 45 | const EnumTgl({ 46 | required this.options, 47 | required this.selected, 48 | required this.onChange, 49 | super.key, 50 | }); 51 | 52 | @override 53 | Widget build(BuildContext context) { 54 | final optionValues = options.values.toList(); 55 | return Tgl( 56 | options: options.map((key, value) => MapEntry(key, value.name)), 57 | selected: optionValues.indexOf(selected), 58 | onChange: (it) => onChange(optionValues[it]), 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/components/txt.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class TxtBox extends StatefulWidget { 4 | final String value; 5 | final void Function(String) onChange; 6 | 7 | const TxtBox({ 8 | required this.value, 9 | required this.onChange, 10 | super.key, 11 | }); 12 | 13 | @override 14 | State createState() => _TxtBoxState(); 15 | } 16 | 17 | class _TxtBoxState extends State { 18 | late TextEditingController _controller; 19 | 20 | @override 21 | void initState() { 22 | super.initState(); 23 | _controller = TextEditingController( 24 | text: widget.value, 25 | )..addListener(() => widget.onChange(_controller.text)); 26 | } 27 | 28 | @override 29 | void dispose() { 30 | _controller.dispose(); 31 | super.dispose(); 32 | } 33 | 34 | @override 35 | Widget build(BuildContext context) { 36 | return TextField(controller: _controller); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/tabs/streams.dart: -------------------------------------------------------------------------------- 1 | import 'package:audioplayers/audioplayers.dart'; 2 | import 'package:audioplayers_elinux_example/components/player_widget.dart'; 3 | import 'package:audioplayers_elinux_example/components/properties_widget.dart'; 4 | import 'package:audioplayers_elinux_example/components/stream_widget.dart'; 5 | import 'package:audioplayers_elinux_example/components/tab_content.dart'; 6 | import 'package:flutter/material.dart'; 7 | 8 | class StreamsTab extends StatelessWidget { 9 | final AudioPlayer player; 10 | 11 | const StreamsTab({ 12 | required this.player, 13 | super.key, 14 | }); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return TabContent( 19 | children: [ 20 | PlayerWidget(player: player), 21 | const Divider(), 22 | StreamWidget(player: player), 23 | const Divider(), 24 | PropertiesWidget(player: player), 25 | ], 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/audioplayers/example/lib/utils.dart: -------------------------------------------------------------------------------- 1 | import 'package:audioplayers/audioplayers.dart'; 2 | import 'package:audioplayers_elinux_example/components/dlg.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | extension StateExt on State { 6 | void toast(String message, {Key? textKey}) { 7 | ScaffoldMessenger.of(context).showSnackBar( 8 | SnackBar( 9 | content: Text(message, key: textKey), 10 | duration: Duration(milliseconds: message.length * 25), 11 | ), 12 | ); 13 | } 14 | 15 | void simpleDialog(String message, [String action = 'Ok']) { 16 | showDialog( 17 | context: context, 18 | builder: (_) { 19 | return SimpleDlg(message: message, action: action); 20 | }, 21 | ); 22 | } 23 | 24 | void dialog(Widget child) { 25 | showDialog( 26 | context: context, 27 | builder: (_) { 28 | return Dlg(child: child); 29 | }, 30 | ); 31 | } 32 | } 33 | 34 | extension PlayerStateIcon on PlayerState { 35 | IconData getIcon() { 36 | return this == PlayerState.playing 37 | ? Icons.play_arrow 38 | : (this == PlayerState.paused 39 | ? Icons.pause 40 | : (this == PlayerState.stopped ? Icons.stop : Icons.stop_circle)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/audioplayers/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: audioplayers_elinux_example 2 | description: Demonstrates how to use the audioplayers plugin. 3 | publish_to: none 4 | 5 | dependencies: 6 | audioplayers: ^6.0.0 7 | audioplayers_elinux: 8 | path: ../ 9 | collection: ^1.16.0 10 | file_picker: ^6.1.1 11 | flutter: 12 | sdk: flutter 13 | http: ^1.0.0 14 | path_provider_elinux: 15 | path: ../../path_provider 16 | provider: ^6.0.5 17 | 18 | dev_dependencies: 19 | 20 | flutter: 21 | uses-material-design: true 22 | 23 | assets: 24 | - assets/ 25 | 26 | environment: 27 | sdk: '>=3.0.0 <4.0.0' 28 | flutter: '>=3.13.0' 29 | -------------------------------------------------------------------------------- /packages/audioplayers/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: audioplayers_elinux 2 | description: Flutter plugin for playing audio with other Flutter widgets on Embedded Linux. 3 | homepage: https://github.com/sony/flutter-elinux-plugins/ 4 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/auidoplayers 5 | version: 0.1.0 6 | 7 | flutter: 8 | plugin: 9 | platforms: 10 | elinux: 11 | pluginClass: AudioplayersElinuxPlugin 12 | 13 | dependencies: 14 | audioplayers_platform_interface: ^7.0.0 15 | flutter: 16 | sdk: flutter 17 | 18 | environment: 19 | sdk: ">=2.18.0 <4.0.0" 20 | flutter: ">=3.7.0" 21 | -------------------------------------------------------------------------------- /packages/camera/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /packages/camera/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.3.2 2 | * Add ELinuxCamera (camera dartPluginClass for eLinux) for flutter 3.13. 3 | 4 | ## 0.3.1 5 | * Update for flutter official camera plugin v0.10.5+3 6 | 7 | ## 0.3.0 8 | * Add TakePicture API 9 | * Enable stream image APIs 10 | 11 | ## 0.2.1 12 | * Update for camera v0.10.0+1 / flutter 3.3.0 release 13 | 14 | ## 0.2.0 15 | * Fix wrong orientation issue. 16 | * Change the camera type from back to external. 17 | 18 | ## 0.1.0 19 | * First draft version. 20 | -------------------------------------------------------------------------------- /packages/camera/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/camera/README.md: -------------------------------------------------------------------------------- 1 | # camera_elinux 2 | 3 | The implementation of the camera plugin for flutter elinux. APIs are designed to be API compatible with the the official [`camera`](https://github.com/flutter/plugins/tree/master/packages/camera). 4 | 5 | ## Required libraries 6 | 7 | This plugin uses [GStreamer](https://gstreamer.freedesktop.org/) internally. 8 | 9 | ```Shell 10 | $ sudo apt install libgstreamer1.0-dev 11 | # Install as needed. 12 | $ sudo apt install libgstreamer-plugins-base1.0-dev \ 13 | gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ 14 | gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav 15 | ``` 16 | 17 | ## Usage 18 | 19 | ### pubspec.yaml 20 | ```yaml 21 | dependencies: 22 | camera: ^0.10.5+3 23 | camera_elinux: 24 | git: 25 | url: https://github.com/sony/flutter-elinux-plugins.git 26 | path: packages/camera 27 | ref: main 28 | ``` 29 | 30 | ### Source code 31 | 32 | Import `camera` in your Dart code: 33 | ```dart 34 | import 'package:camera/camera.dart'; 35 | ``` 36 | 37 | ### Customization for your target devices 38 | 39 | To improve the performance of this plugin, you will need to customize the pipeline in the source file. Please modify the source file and replace the `videoconvert` element with a H/W accelerated element of your target device to perform well. 40 | 41 | `bool GstCamera::CreatePipeline()` in packages/camera/elinux/gst_camera.cc 42 | 43 | #### default: 44 | 45 | ``` 46 | camerabin viewfinder-sink="videoconvert ! video/x-raw,format=RGBA ! fakesink" 47 | ``` 48 | 49 | #### i.MX 8M platforms: 50 | 51 | ``` 52 | camerabin viewfinder-sink="imxvideoconvert_g2d ! video/x-raw,format=RGBA ! fakesink" 53 | ``` 54 | 55 | ## Troubleshooting 56 | 57 | If you get the following error: 58 | ```Shell 59 | Wrong JPEG library version: library is 62, caller expects 80 60 | ``` 61 | 62 | , try the following: 63 | ```Shell 64 | sudo mv /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstjpeg.so \ 65 | /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstjpeg.so.org 66 | ``` 67 | -------------------------------------------------------------------------------- /packages/camera/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | -------------------------------------------------------------------------------- /packages/camera/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | set(PROJECT_NAME "camera_elinux") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | # This value is used when generating builds using this plugin, so it must 6 | # not be changed 7 | set(PLUGIN_NAME "camera_elinux_plugin") 8 | 9 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 10 | 11 | find_package(PkgConfig) 12 | pkg_check_modules(GStreamer REQUIRED IMPORTED_TARGET gstreamer-1.0) 13 | 14 | add_library(${PLUGIN_NAME} SHARED 15 | "camera_elinux_plugin.cc" 16 | "channels/event_channel_image_stream.cc" 17 | "channels/method_channel_camera.cc" 18 | "channels/method_channel_device.cc" 19 | "gst_camera.cc" 20 | "types/exposure_mode.cc" 21 | "types/focus_mode.cc" 22 | "types/orientation.cc" 23 | ) 24 | apply_standard_settings(${PLUGIN_NAME}) 25 | set_target_properties(${PLUGIN_NAME} PROPERTIES 26 | CXX_VISIBILITY_PRESET hidden) 27 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 28 | target_include_directories(${PLUGIN_NAME} INTERFACE 29 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 30 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 31 | 32 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GStreamer) 33 | 34 | # List of absolute paths to libraries that should be bundled with the plugin 35 | set(camera_elinux_bundled_libraries 36 | "" 37 | PARENT_SCOPE 38 | ) 39 | -------------------------------------------------------------------------------- /packages/camera/elinux/camera_stream_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_H_ 6 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_H_ 7 | 8 | class CameraStreamHandler { 9 | public: 10 | CameraStreamHandler() = default; 11 | virtual ~CameraStreamHandler() = default; 12 | 13 | // Prevent copying. 14 | CameraStreamHandler(CameraStreamHandler const&) = delete; 15 | CameraStreamHandler& operator=(CameraStreamHandler const&) = delete; 16 | 17 | // Notifies the completion of decoding a video frame. 18 | void OnNotifyFrameDecoded() { OnNotifyFrameDecodedInternal(); } 19 | 20 | protected: 21 | virtual void OnNotifyFrameDecodedInternal() = 0; 22 | }; 23 | 24 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_H_ 25 | -------------------------------------------------------------------------------- /packages/camera/elinux/camera_stream_handler_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_IMPL_H_ 6 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_IMPL_H_ 7 | 8 | #include 9 | 10 | #include "camera_stream_handler.h" 11 | 12 | class CameraStreamHandlerImpl : public CameraStreamHandler { 13 | public: 14 | using OnNotifyFrameDecoded = std::function; 15 | 16 | CameraStreamHandlerImpl(OnNotifyFrameDecoded on_notify_frame_decoded) 17 | : on_notify_frame_decoded_(on_notify_frame_decoded) {} 18 | virtual ~CameraStreamHandlerImpl() = default; 19 | 20 | // Prevent copying. 21 | CameraStreamHandlerImpl(CameraStreamHandlerImpl const&) = delete; 22 | CameraStreamHandlerImpl& operator=(CameraStreamHandlerImpl const&) = delete; 23 | 24 | protected: 25 | // |CameraStreamHandler| 26 | void OnNotifyFrameDecodedInternal() { 27 | if (on_notify_frame_decoded_) { 28 | on_notify_frame_decoded_(); 29 | } 30 | } 31 | 32 | OnNotifyFrameDecoded on_notify_frame_decoded_; 33 | }; 34 | 35 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_STREAM_HANDLER_IMPL_H_ 36 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/event_channel_image_stream.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "channels/event_channel_image_stream.h" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace { 14 | constexpr char kChannelName[] = "plugins.flutter.io/camera/imageStream"; 15 | 16 | // See: [getFormat()] in 17 | // https://developer.android.com/reference/android/media/Image 18 | constexpr int32_t kImageFormatRGBA8888 = 4; 19 | }; // namespace 20 | 21 | EventChannelImageStream::EventChannelImageStream( 22 | flutter::PluginRegistrar* registrar) { 23 | auto event_channel = 24 | std::make_unique>( 25 | registrar->messenger(), kChannelName, 26 | &flutter::StandardMethodCodec::GetInstance()); 27 | 28 | auto event_channel_handler = std::make_unique< 29 | flutter::StreamHandlerFunctions>( 30 | [this]( 31 | const flutter::EncodableValue* arguments, 32 | std::unique_ptr>&& events) 33 | -> std::unique_ptr< 34 | flutter::StreamHandlerError> { 35 | event_sink_ = std::move(events); 36 | return nullptr; 37 | }, 38 | [this](const flutter::EncodableValue* arguments) 39 | -> std::unique_ptr< 40 | flutter::StreamHandlerError> { 41 | event_sink_ = nullptr; 42 | return nullptr; 43 | }); 44 | event_channel->SetStreamHandler(std::move(event_channel_handler)); 45 | } 46 | 47 | // See: [setImageStreamImageAvailableListener] in 48 | // flutter/plugins/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java 49 | void EventChannelImageStream::Send(const int32_t& width, const int32_t& height, 50 | const uint8_t* pixels) { 51 | const uint32_t len = width * 4 * height; 52 | std::vector bytes(pixels, pixels + len); 53 | 54 | flutter::EncodableList planes; 55 | flutter::EncodableMap plane = { 56 | {flutter::EncodableValue("bytesPerRow"), flutter::EncodableValue(width)}, 57 | {flutter::EncodableValue("bytesPerPixel"), flutter::EncodableValue(4)}, 58 | {flutter::EncodableValue("bytes"), flutter::EncodableValue(bytes)}, 59 | }; 60 | flutter::EncodableValue plane_value(plane); 61 | planes.push_back(plane_value); 62 | 63 | flutter::EncodableMap encodables = { 64 | {flutter::EncodableValue("width"), flutter::EncodableValue(width)}, 65 | {flutter::EncodableValue("height"), flutter::EncodableValue(height)}, 66 | {flutter::EncodableValue("format"), 67 | flutter::EncodableValue(kImageFormatRGBA8888)}, 68 | {flutter::EncodableValue("planes"), flutter::EncodableValue(planes)}}; 69 | flutter::EncodableValue event(encodables); 70 | 71 | event_sink_->Success(event); 72 | } 73 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/event_channel_image_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_EVENT_CHANNEL_IMAGE_STREAM_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_EVENT_CHANNEL_IMAGE_STREAM_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | class EventChannelImageStream { 16 | public: 17 | EventChannelImageStream(flutter::PluginRegistrar* registrar); 18 | ~EventChannelImageStream() = default; 19 | 20 | void Send(const int32_t& width, const int32_t& height, const uint8_t* pixels); 21 | 22 | private: 23 | std::unique_ptr> channel_; 24 | std::unique_ptr> event_sink_; 25 | }; 26 | 27 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_EVENT_CHANNEL_IMAGE_STREAM_H_ 28 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/method_channel_camera.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "channels/method_channel_camera.h" 7 | 8 | #include 9 | 10 | namespace { 11 | constexpr char kChannelName[] = "plugins.flutter.io/camera/camera"; 12 | constexpr char kChannelMethodInitialized[] = "initialized"; 13 | }; // namespace 14 | 15 | MethodChannelCamera::MethodChannelCamera(flutter::PluginRegistrar* registrar, 16 | int64_t camera_id) { 17 | std::string channel_name = kChannelName + std::to_string(camera_id); 18 | channel_ = std::make_unique>( 19 | registrar->messenger(), channel_name.c_str(), 20 | &flutter::StandardMethodCodec::GetInstance()); 21 | } 22 | 23 | void MethodChannelCamera::SendInitializedEvent( 24 | CameraInitializedEvent& message) { 25 | auto value = std::make_unique(message.ToMap()); 26 | Send(kChannelMethodInitialized, std::move(value)); 27 | } 28 | 29 | void MethodChannelCamera::Send( 30 | const std::string& method, 31 | std::unique_ptr&& arguments) { 32 | channel_->InvokeMethod(method, std::move(arguments)); 33 | } 34 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/method_channel_camera.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_CAMERA_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_CAMERA_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "events/camera_initialized_event.h" 16 | 17 | class MethodChannelCamera { 18 | public: 19 | MethodChannelCamera(flutter::PluginRegistrar* registrar, int64_t camera_id); 20 | ~MethodChannelCamera() = default; 21 | 22 | void SendInitializedEvent(CameraInitializedEvent& message); 23 | 24 | private: 25 | void Send(const std::string& method, 26 | std::unique_ptr&& arguments); 27 | 28 | std::unique_ptr> channel_; 29 | }; 30 | 31 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_CAMERA_H_ 32 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/method_channel_device.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "channels/method_channel_device.h" 7 | 8 | #include 9 | 10 | namespace { 11 | constexpr char kChannelName[] = "plugins.flutter.io/camera/fromPlatform"; 12 | constexpr char kChannelMethodOrientationChanged[] = "orientation_changed"; 13 | 14 | constexpr char kOrientation[] = "orientation"; 15 | }; // namespace 16 | 17 | MethodChannelDevice::MethodChannelDevice(flutter::PluginRegistrar* registrar) { 18 | channel_ = std::make_unique>( 19 | registrar->messenger(), kChannelName, 20 | &flutter::StandardMethodCodec::GetInstance()); 21 | } 22 | 23 | void MethodChannelDevice::SendDeviceOrientationChangeEvent( 24 | const DeviceOrientation& orientation) { 25 | flutter::EncodableMap mp; 26 | mp[flutter::EncodableValue(kOrientation)] = 27 | flutter::EncodableValue(SerializeDeviceOrientation(orientation)); 28 | auto value = std::make_unique(mp); 29 | 30 | Send(kChannelMethodOrientationChanged, std::move(value)); 31 | } 32 | 33 | void MethodChannelDevice::Send( 34 | const std::string& method, 35 | std::unique_ptr&& arguments) { 36 | channel_->InvokeMethod(method, std::move(arguments)); 37 | } 38 | -------------------------------------------------------------------------------- /packages/camera/elinux/channels/method_channel_device.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_DEVICE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_DEVICE_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "types/orientation.h" 16 | 17 | class MethodChannelDevice { 18 | public: 19 | MethodChannelDevice(flutter::PluginRegistrar* registrar); 20 | ~MethodChannelDevice() = default; 21 | 22 | void SendDeviceOrientationChangeEvent(const DeviceOrientation& orientation); 23 | 24 | private: 25 | void Send(const std::string& method, 26 | std::unique_ptr&& arguments); 27 | 28 | std::unique_ptr> channel_; 29 | }; 30 | 31 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_CHANNELS_METHOD_CHANNEL_DEVICE_H_ 32 | -------------------------------------------------------------------------------- /packages/camera/elinux/gst_camera.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_GST_CAMERA_H_ 6 | #define PACKAGES_CAMERA_CAMERA_ELINUX_GST_CAMERA_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "camera_stream_handler.h" 16 | 17 | class GstCamera { 18 | public: 19 | using OnNotifyCaptured = 20 | std::function; 21 | 22 | GstCamera(std::unique_ptr handler); 23 | ~GstCamera(); 24 | 25 | static void GstLibraryLoad(); 26 | static void GstLibraryUnload(); 27 | 28 | bool Play(); 29 | bool Pause(); 30 | bool Stop(); 31 | 32 | void TakePicture(OnNotifyCaptured on_notify_captured); 33 | 34 | bool SetZoomLevel(float zoom); 35 | float GetMaxZoomLevel() const { return max_zoom_level_; }; 36 | float GetMinZoomLevel() const { return min_zoom_level_; }; 37 | 38 | const uint8_t* GetPreviewFrameBuffer(); 39 | int32_t GetPreviewWidth() const { return width_; }; 40 | int32_t GetPreviewHeight() const { return height_; }; 41 | 42 | private: 43 | struct GstCameraElements { 44 | GstElement* pipeline; 45 | GstElement* camerabin; 46 | GstElement* video_convert; 47 | GstElement* video_sink; 48 | GstElement* output; 49 | GstBus* bus; 50 | GstBuffer* buffer; 51 | }; 52 | 53 | static void HandoffHandler(GstElement* fakesink, GstBuffer* buf, 54 | GstPad* new_pad, gpointer user_data); 55 | static GstBusSyncReply HandleGstMessage(GstBus* bus, GstMessage* message, 56 | gpointer user_data); 57 | 58 | bool CreatePipeline(); 59 | void DestroyPipeline(); 60 | void Preroll(); 61 | void GetZoomMaxMinSize(float& max, float& min); 62 | 63 | GstCameraElements gst_; 64 | std::unique_ptr pixels_; 65 | int32_t width_ = -1; 66 | int32_t height_ = -1; 67 | std::shared_mutex mutex_buffer_; 68 | std::unique_ptr stream_handler_ = nullptr; 69 | float max_zoom_level_; 70 | float min_zoom_level_; 71 | float zoom_level_ = 1.0f; 72 | int captured_count_ = 0; 73 | 74 | OnNotifyCaptured on_notify_captured_ = nullptr; 75 | }; 76 | 77 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_GST_CAMERA_H_ 78 | -------------------------------------------------------------------------------- /packages/camera/elinux/include/camera_elinux/camera_elinux_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_CAMERA_CAMERA_ELINUX_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_CAMERA_CAMERA_ELINUX_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void CameraElinuxPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_CAMERA_CAMERA_ELINUX_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /packages/camera/elinux/messages/available_cameras_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | class AvailableCamerasMessage { 16 | public: 17 | AvailableCamerasMessage() = default; 18 | ~AvailableCamerasMessage() = default; 19 | 20 | // Prevent copying. 21 | AvailableCamerasMessage(AvailableCamerasMessage const&) = default; 22 | AvailableCamerasMessage& operator=(AvailableCamerasMessage const&) = default; 23 | 24 | void SetName(const std::string& name) { name_ = name; } 25 | std::string GetName() const { return name_; } 26 | 27 | void SetSensorOrientation(const int& sensor_orientation) { 28 | sensor_orientation_ = sensor_orientation; 29 | } 30 | int GetSensorOrientation() const { return sensor_orientation_; } 31 | 32 | void SetLensFacing(const std::string& lens_facing) { 33 | lens_facing_ = lens_facing; 34 | } 35 | std::string GetLensFacing() const { return lens_facing_; } 36 | 37 | flutter::EncodableValue ToMap() { 38 | flutter::EncodableMap map = { 39 | {flutter::EncodableValue("name"), flutter::EncodableValue(name_)}, 40 | {flutter::EncodableValue("sensorOrientation"), 41 | flutter::EncodableValue(sensor_orientation_)}, 42 | {flutter::EncodableValue("lensFacing"), 43 | flutter::EncodableValue(lens_facing_)}}; 44 | return flutter::EncodableValue(map); 45 | } 46 | 47 | static AvailableCamerasMessage FromMap(const flutter::EncodableValue& value) { 48 | AvailableCamerasMessage message; 49 | if (std::holds_alternative(value)) { 50 | auto map = std::get(value); 51 | 52 | flutter::EncodableValue& name = map[flutter::EncodableValue("name")]; 53 | if (std::holds_alternative(name)) { 54 | message.SetName(std::get(name)); 55 | } 56 | 57 | flutter::EncodableValue& sensor_orientation = 58 | map[flutter::EncodableValue("sensorOrientation")]; 59 | if (std::holds_alternative(sensor_orientation)) { 60 | message.SetSensorOrientation(std::get(sensor_orientation)); 61 | } 62 | 63 | flutter::EncodableValue& lens_facing = 64 | map[flutter::EncodableValue("lensFacing")]; 65 | if (std::holds_alternative(lens_facing)) { 66 | message.SetLensFacing(std::get(lens_facing)); 67 | } 68 | } 69 | 70 | return message; 71 | } 72 | 73 | private: 74 | std::string name_; 75 | int sensor_orientation_; 76 | std::string lens_facing_; 77 | }; 78 | 79 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_ 80 | -------------------------------------------------------------------------------- /packages/camera/elinux/messages/messages.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_ 6 | #define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_ 7 | 8 | #include "available_cameras_message.h" 9 | #include "orientation_message.h" 10 | #include "texture_message.h" 11 | #include "zoom_level_message.h" 12 | 13 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_ 14 | -------------------------------------------------------------------------------- /packages/camera/elinux/messages/orientation_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "types/orientation.h" 16 | 17 | class OrientationMessage { 18 | public: 19 | OrientationMessage() = default; 20 | ~OrientationMessage() = default; 21 | 22 | // Prevent copying. 23 | OrientationMessage(OrientationMessage const&) = default; 24 | OrientationMessage& operator=(OrientationMessage const&) = default; 25 | 26 | void SetOrientation(DeviceOrientation orientation) { 27 | orientation_ = orientation; 28 | } 29 | DeviceOrientation GetOrientation() const { return orientation_; } 30 | 31 | flutter::EncodableValue ToMap() { 32 | flutter::EncodableMap map = { 33 | {flutter::EncodableValue("orientation"), 34 | flutter::EncodableValue(SerializeDeviceOrientation(orientation_))}}; 35 | return flutter::EncodableValue(map); 36 | } 37 | 38 | static OrientationMessage FromMap(const flutter::EncodableValue& value) { 39 | OrientationMessage message; 40 | if (std::holds_alternative(value)) { 41 | auto map = std::get(value); 42 | 43 | flutter::EncodableValue& orientation = 44 | map[flutter::EncodableValue("orientation")]; 45 | if (std::holds_alternative(orientation)) { 46 | message.SetOrientation( 47 | DeserializeDeviceOrientation(std::get(orientation))); 48 | } 49 | } 50 | return message; 51 | } 52 | 53 | private: 54 | DeviceOrientation orientation_; 55 | }; 56 | 57 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_ 58 | -------------------------------------------------------------------------------- /packages/camera/elinux/messages/texture_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 8 | 9 | #include 10 | #include 11 | 12 | class TextureMessage { 13 | public: 14 | TextureMessage() = default; 15 | ~TextureMessage() = default; 16 | 17 | // Prevent copying. 18 | TextureMessage(TextureMessage const&) = default; 19 | TextureMessage& operator=(TextureMessage const&) = default; 20 | 21 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 22 | 23 | int64_t GetTextureId() const { return texture_id_; } 24 | 25 | flutter::EncodableValue ToMap() { 26 | flutter::EncodableMap map = {{flutter::EncodableValue("textureId"), 27 | flutter::EncodableValue(texture_id_)}}; 28 | return flutter::EncodableValue(map); 29 | } 30 | 31 | static TextureMessage FromMap(const flutter::EncodableValue& value) { 32 | TextureMessage message; 33 | if (std::holds_alternative(value)) { 34 | auto map = std::get(value); 35 | 36 | flutter::EncodableValue& texture_id = 37 | map[flutter::EncodableValue("textureId")]; 38 | if (std::holds_alternative(texture_id) || 39 | std::holds_alternative(texture_id)) { 40 | message.SetTextureId(texture_id.LongValue()); 41 | } 42 | } 43 | return message; 44 | } 45 | 46 | private: 47 | int64_t texture_id_ = 0; 48 | }; 49 | 50 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 51 | -------------------------------------------------------------------------------- /packages/camera/elinux/messages/zoom_level_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | class ZoomLevelMessage { 15 | public: 16 | ZoomLevelMessage() = default; 17 | ~ZoomLevelMessage() = default; 18 | 19 | // Prevent copying. 20 | ZoomLevelMessage(ZoomLevelMessage const&) = default; 21 | ZoomLevelMessage& operator=(ZoomLevelMessage const&) = default; 22 | 23 | void SetZoom(double zoom) { zoom_ = zoom; } 24 | double GetZoom() const { return zoom_; } 25 | 26 | flutter::EncodableValue ToMap() { 27 | flutter::EncodableMap map = { 28 | {flutter::EncodableValue("zoom"), flutter::EncodableValue(zoom_)}}; 29 | return flutter::EncodableValue(map); 30 | } 31 | 32 | static ZoomLevelMessage FromMap(const flutter::EncodableValue& value) { 33 | ZoomLevelMessage message; 34 | if (std::holds_alternative(value)) { 35 | auto map = std::get(value); 36 | 37 | flutter::EncodableValue& zoom = map[flutter::EncodableValue("zoom")]; 38 | if (std::holds_alternative(zoom)) { 39 | message.SetZoom(std::get(zoom)); 40 | } 41 | } 42 | return message; 43 | } 44 | 45 | private: 46 | double zoom_; 47 | }; 48 | 49 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_ 50 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/exposure_mode.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "types/exposure_mode.h" 7 | 8 | std::string SerializeExposureMode(ExposureMode exposure_mode) { 9 | switch (exposure_mode) { 10 | case ExposureMode::kLocked: 11 | return "locked"; 12 | case ExposureMode::kAuto: 13 | return "auto"; 14 | default: 15 | return "auto"; 16 | std::cerr << "Unknown ExposureMode value" << std::endl; 17 | } 18 | } 19 | 20 | ExposureMode DeserializeExposureMode(std::string str) { 21 | if (!str.compare("locked")) { 22 | return ExposureMode::kLocked; 23 | } 24 | if (!str.compare("auto")) { 25 | return ExposureMode::kAuto; 26 | } 27 | std::cerr << str.c_str() << " is not a valid ExposureMode value" << std::endl; 28 | return ExposureMode::kAuto; 29 | } 30 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/exposure_mode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_EXPOSURE_MODE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_EXPOSURE_MODE_H_ 8 | 9 | #include 10 | #include 11 | 12 | // See: 13 | // flutter/plugins/packages/camera/camera_platform_interface/lib/src/types/exposure_mode.dart 14 | enum class ExposureMode { 15 | kAuto, 16 | kLocked, 17 | }; 18 | 19 | std::string SerializeExposureMode(ExposureMode exposure_mode); 20 | ExposureMode DeserializeExposureMode(std::string str); 21 | 22 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_EXPOSURE_MODE_H_ 23 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/focus_mode.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "types/focus_mode.h" 7 | 8 | std::string SerializeFocusMode(FocusMode focus_mode) { 9 | switch (focus_mode) { 10 | case FocusMode::kLocked: 11 | return "locked"; 12 | case FocusMode::kAuto: 13 | return "auto"; 14 | default: 15 | std::cerr << "Unknown FocusMode value" << std::endl; 16 | return "auto"; 17 | } 18 | } 19 | 20 | FocusMode DeserializeFocusMode(std::string str) { 21 | if (!str.compare("locked")) { 22 | return FocusMode::kLocked; 23 | } 24 | if (!str.compare("auto")) { 25 | return FocusMode::kAuto; 26 | } 27 | std::cerr << str.c_str() << " is not a valid FocusMode value" << std::endl; 28 | return FocusMode::kAuto; 29 | } 30 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/focus_mode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_FOCUS_MODE_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_FOCUS_MODE_H_ 8 | 9 | #include 10 | #include 11 | 12 | // See: 13 | // flutter/plugins/packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart 14 | enum class FocusMode { 15 | kAuto, 16 | kLocked, 17 | }; 18 | 19 | std::string SerializeFocusMode(FocusMode focus_mode); 20 | FocusMode DeserializeFocusMode(std::string str); 21 | 22 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_FOCUS_MODE_H_ 23 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/orientation.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "types/orientation.h" 7 | 8 | std::string SerializeDeviceOrientation(DeviceOrientation orientation) { 9 | switch (orientation) { 10 | case DeviceOrientation::kPortraitUp: 11 | return "portraitUp"; 12 | case DeviceOrientation::kLandscapeLeft: 13 | return "landscapeLeft"; 14 | case DeviceOrientation::kPortraitDown: 15 | return "portraitDown"; 16 | case DeviceOrientation::kLandscapeRight: 17 | return "landscapeRight"; 18 | default: 19 | std::cerr << "Unknown DeviceOrientation value" << std::endl; 20 | return "landscapeLeft"; 21 | } 22 | } 23 | 24 | DeviceOrientation DeserializeDeviceOrientation(std::string str) { 25 | if (!str.compare("portraitUp")) { 26 | return DeviceOrientation::kPortraitUp; 27 | } 28 | if (!str.compare("landscapeLeft")) { 29 | return DeviceOrientation::kLandscapeLeft; 30 | } 31 | if (!str.compare("portraitDown")) { 32 | return DeviceOrientation::kPortraitDown; 33 | } 34 | if (!str.compare("landscapeRight")) { 35 | return DeviceOrientation::kLandscapeRight; 36 | } 37 | std::cerr << str.c_str() << " is not a valid DeviceOrientation value" 38 | << std::endl; 39 | return DeviceOrientation::kLandscapeLeft; 40 | } 41 | -------------------------------------------------------------------------------- /packages/camera/elinux/types/orientation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_ORIENTATION_H_ 7 | #define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_ORIENTATION_H_ 8 | 9 | #include 10 | #include 11 | 12 | // See: [DeviceOrientation] in 13 | // flutter/packages/flutter/lib/src/services/system_chrome.dart 14 | enum class DeviceOrientation { 15 | kPortraitUp, 16 | kLandscapeLeft, 17 | kPortraitDown, 18 | kLandscapeRight, 19 | }; 20 | 21 | std::string SerializeDeviceOrientation(DeviceOrientation orientation); 22 | DeviceOrientation DeserializeDeviceOrientation(std::string str); 23 | 24 | #endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_TYPES_ORIENTATION_H_ 25 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | camera_elinux 7 | video_player_elinux 8 | ) 9 | 10 | set(PLUGIN_BUNDLED_LIBRARIES) 11 | 12 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 13 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 14 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 17 | endforeach(plugin) 18 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/camera/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/camera/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: camera_example 2 | description: Demonstrates how to use the camera plugin. 3 | publish_to: none 4 | 5 | environment: 6 | sdk: ">=2.18.0 <4.0.0" 7 | flutter: ">=3.3.0" 8 | 9 | dependencies: 10 | camera: ^0.10.5+3 11 | camera_elinux: 12 | path: ../ 13 | flutter: 14 | sdk: flutter 15 | path_provider_elinux: 16 | path: ../../path_provider 17 | video_player: ^2.4.7 18 | video_player_elinux: 19 | path: ../../video_player 20 | 21 | dev_dependencies: 22 | flutter_test: 23 | sdk: flutter 24 | flutter_driver: 25 | sdk: flutter 26 | integration_test: 27 | sdk: flutter 28 | 29 | flutter: 30 | uses-material-design: true 31 | -------------------------------------------------------------------------------- /packages/camera/example/test_driver/integration_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:convert'; 7 | import 'dart:io'; 8 | 9 | import 'package:flutter_driver/flutter_driver.dart'; 10 | 11 | const String _examplePackage = 'io.flutter.plugins.cameraexample'; 12 | 13 | Future main() async { 14 | if (!(Platform.isLinux || Platform.isMacOS)) { 15 | print('This test must be run on a POSIX host. Skipping...'); 16 | exit(0); 17 | } 18 | final bool adbExists = 19 | Process.runSync('which', ['adb']).exitCode == 0; 20 | if (!adbExists) { 21 | print('This test needs ADB to exist on the \$PATH. Skipping...'); 22 | exit(0); 23 | } 24 | print('Granting camera permissions...'); 25 | Process.runSync('adb', [ 26 | 'shell', 27 | 'pm', 28 | 'grant', 29 | _examplePackage, 30 | 'android.permission.CAMERA' 31 | ]); 32 | Process.runSync('adb', [ 33 | 'shell', 34 | 'pm', 35 | 'grant', 36 | _examplePackage, 37 | 'android.permission.RECORD_AUDIO' 38 | ]); 39 | print('Starting test.'); 40 | final FlutterDriver driver = await FlutterDriver.connect(); 41 | final String data = await driver.requestData( 42 | null, 43 | timeout: const Duration(minutes: 1), 44 | ); 45 | await driver.close(); 46 | print('Test finished. Revoking camera permissions...'); 47 | Process.runSync('adb', [ 48 | 'shell', 49 | 'pm', 50 | 'revoke', 51 | _examplePackage, 52 | 'android.permission.CAMERA' 53 | ]); 54 | Process.runSync('adb', [ 55 | 'shell', 56 | 'pm', 57 | 'revoke', 58 | _examplePackage, 59 | 'android.permission.RECORD_AUDIO' 60 | ]); 61 | 62 | final Map result = jsonDecode(data); 63 | exit(result['result'] == 'true' ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /packages/camera/lib/camera_elinux.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | export 'src/elinux_camera.dart'; 7 | -------------------------------------------------------------------------------- /packages/camera/lib/src/type_conversion.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:typed_data'; 6 | 7 | import 'package:camera_platform_interface/camera_platform_interface.dart'; 8 | 9 | /// Converts method channel call [data] for `receivedImageStreamData` to a 10 | /// [CameraImageData]. 11 | CameraImageData cameraImageFromPlatformData(Map data) { 12 | return CameraImageData( 13 | format: _cameraImageFormatFromPlatformData(data['format']), 14 | height: data['height'] as int, 15 | width: data['width'] as int, 16 | lensAperture: data['lensAperture'] as double?, 17 | sensorExposureTime: data['sensorExposureTime'] as int?, 18 | sensorSensitivity: data['sensorSensitivity'] as double?, 19 | planes: List.unmodifiable( 20 | (data['planes'] as List).map( 21 | (dynamic planeData) => _cameraImagePlaneFromPlatformData( 22 | planeData as Map)))); 23 | } 24 | 25 | CameraImageFormat _cameraImageFormatFromPlatformData(dynamic data) { 26 | return CameraImageFormat(_imageFormatGroupFromPlatformData(data), raw: data); 27 | } 28 | 29 | ImageFormatGroup _imageFormatGroupFromPlatformData(dynamic data) { 30 | switch (data) { 31 | case 35: // android.graphics.ImageFormat.YUV_420_888 32 | return ImageFormatGroup.yuv420; 33 | case 256: // android.graphics.ImageFormat.JPEG 34 | return ImageFormatGroup.jpeg; 35 | case 17: // android.graphics.ImageFormat.NV21 36 | return ImageFormatGroup.nv21; 37 | } 38 | 39 | return ImageFormatGroup.unknown; 40 | } 41 | 42 | CameraImagePlane _cameraImagePlaneFromPlatformData(Map data) { 43 | return CameraImagePlane( 44 | bytes: data['bytes'] as Uint8List, 45 | bytesPerPixel: data['bytesPerPixel'] as int?, 46 | bytesPerRow: data['bytesPerRow'] as int, 47 | height: data['height'] as int?, 48 | width: data['width'] as int?); 49 | } 50 | -------------------------------------------------------------------------------- /packages/camera/lib/src/utils.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'package:camera_platform_interface/camera_platform_interface.dart'; 6 | import 'package:flutter/services.dart'; 7 | 8 | /// Parses a string into a corresponding CameraLensDirection. 9 | CameraLensDirection parseCameraLensDirection(String string) { 10 | switch (string) { 11 | case 'front': 12 | return CameraLensDirection.front; 13 | case 'back': 14 | return CameraLensDirection.back; 15 | case 'external': 16 | return CameraLensDirection.external; 17 | } 18 | throw ArgumentError('Unknown CameraLensDirection value'); 19 | } 20 | 21 | /// Returns the device orientation as a String. 22 | String serializeDeviceOrientation(DeviceOrientation orientation) { 23 | switch (orientation) { 24 | case DeviceOrientation.portraitUp: 25 | return 'portraitUp'; 26 | case DeviceOrientation.portraitDown: 27 | return 'portraitDown'; 28 | case DeviceOrientation.landscapeRight: 29 | return 'landscapeRight'; 30 | case DeviceOrientation.landscapeLeft: 31 | return 'landscapeLeft'; 32 | } 33 | // The enum comes from a different package, which could get a new value at 34 | // any time, so provide a fallback that ensures this won't break when used 35 | // with a version that contains new values. This is deliberately outside 36 | // the switch rather than a `default` so that the linter will flag the 37 | // switch as needing an update. 38 | // ignore: dead_code 39 | return 'portraitUp'; 40 | } 41 | 42 | /// Returns the device orientation for a given String. 43 | DeviceOrientation deserializeDeviceOrientation(String str) { 44 | switch (str) { 45 | case 'portraitUp': 46 | return DeviceOrientation.portraitUp; 47 | case 'portraitDown': 48 | return DeviceOrientation.portraitDown; 49 | case 'landscapeRight': 50 | return DeviceOrientation.landscapeRight; 51 | case 'landscapeLeft': 52 | return DeviceOrientation.landscapeLeft; 53 | default: 54 | throw ArgumentError('"$str" is not a valid DeviceOrientation value'); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/camera/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: camera_elinux 2 | description: A Flutter plugin for getting information about and controlling the 3 | camera on eLinux. Supports previewing the camera feed, capturing images, capturing video, 4 | and streaming image buffers to dart. 5 | version: 0.3.2 6 | homepage: https://github.com/sony/flutter-elinux-plugins 7 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/camera 8 | 9 | environment: 10 | sdk: ">=2.18.0 <4.0.0" 11 | flutter: ">=3.3.0" 12 | 13 | dependencies: 14 | camera_platform_interface: ^2.5.0 15 | flutter: 16 | sdk: flutter 17 | 18 | flutter: 19 | plugin: 20 | platforms: 21 | elinux: 22 | pluginClass: CameraElinuxPlugin 23 | dartPluginClass: ELinuxCamera 24 | -------------------------------------------------------------------------------- /packages/joystick/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /packages/joystick/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.1 2 | * Update for flutter 3.3.0 release 3 | 4 | ## 1.0.0 5 | * First version. 6 | -------------------------------------------------------------------------------- /packages/joystick/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/joystick/README.md: -------------------------------------------------------------------------------- 1 | # joystick 2 | 3 | The implementation of the joystick plugin for eLinux. 4 | 5 | ## Usage 6 | 7 | ### pubspec.yaml 8 | ```yaml 9 | dependencies: 10 | joystick: 11 | git: 12 | url: https://github.com/sony/flutter-elinux-plugins.git 13 | path: packages/joystick 14 | ref: main 15 | ``` 16 | 17 | ### Source code 18 | Import `joystick` in your Dart code: 19 | ```dart 20 | import 'package:joystick/joystick.dart'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/joystick/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | -------------------------------------------------------------------------------- /packages/joystick/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(PROJECT_NAME "joystick") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | # This value is used when generating builds using this plugin, so it must 6 | # not be changed 7 | set(PLUGIN_NAME "joystick_plugin") 8 | 9 | add_library(${PLUGIN_NAME} SHARED 10 | "joystick_plugin.cc" 11 | "linux_joystick.cc" 12 | ) 13 | apply_standard_settings(${PLUGIN_NAME}) 14 | set_target_properties(${PLUGIN_NAME} PROPERTIES 15 | CXX_VISIBILITY_PRESET hidden) 16 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 17 | target_include_directories(${PLUGIN_NAME} INTERFACE 18 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 19 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 20 | 21 | # List of absolute paths to libraries that should be bundled with the plugin 22 | set(joystick_bundled_libraries 23 | "" 24 | PARENT_SCOPE 25 | ) 26 | -------------------------------------------------------------------------------- /packages/joystick/elinux/include/joystick/joystick_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_JOYSTICK_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_JOYSTICK_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void JoystickPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_JOYSTICK_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /packages/joystick/elinux/joystick_plugin.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "include/joystick/joystick_plugin.h" 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace { 13 | 14 | class JoystickPlugin : public flutter::Plugin { 15 | public: 16 | static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar); 17 | 18 | JoystickPlugin(); 19 | 20 | virtual ~JoystickPlugin(); 21 | }; 22 | 23 | // static 24 | void JoystickPlugin::RegisterWithRegistrar( 25 | flutter::PluginRegistrar *registrar) { 26 | auto plugin = std::make_unique(); 27 | registrar->AddPlugin(std::move(plugin)); 28 | } 29 | 30 | JoystickPlugin::JoystickPlugin() {} 31 | 32 | JoystickPlugin::~JoystickPlugin() {} 33 | 34 | } // namespace 35 | 36 | void JoystickPluginRegisterWithRegistrar( 37 | FlutterDesktopPluginRegistrarRef registrar) { 38 | JoystickPlugin::RegisterWithRegistrar( 39 | flutter::PluginRegistrarManager::GetInstance() 40 | ->GetRegistrar(registrar)); 41 | } 42 | -------------------------------------------------------------------------------- /packages/joystick/elinux/linux_joystick.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | extern "C" __attribute__((visibility("default"))) int joystick_open( 12 | const char* device) { 13 | int fd = open(device, O_NONBLOCK); 14 | if (fd < 0) { 15 | fprintf(stderr, "Failed to open %s (%d)\n", device, errno); 16 | } 17 | return fd; 18 | } 19 | 20 | extern "C" __attribute__((visibility("default"))) int joystick_read( 21 | int fd, js_event* ev) { 22 | int bytes = read(fd, ev, sizeof(*ev)); 23 | if (bytes < 0) { 24 | return -1; 25 | } 26 | return bytes == sizeof(*ev); 27 | } 28 | -------------------------------------------------------------------------------- /packages/joystick/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /packages/joystick/example/README.md: -------------------------------------------------------------------------------- 1 | # joystick_example 2 | 3 | Demonstrates how to use the joystick plugin for eLinux. 4 | 5 | ## Getting Started 6 | 7 | For help getting started with Flutter for eLinux, view our online 8 | [documentation](https://github.com/sony/flutter-elinux/wiki). 9 | 10 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | joystick 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 13 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 16 | endforeach(plugin) 17 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/joystick/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/joystick/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:ffi'; 3 | 4 | import 'package:ffi/ffi.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:joystick/joystick.dart'; 7 | 8 | void main() { 9 | runApp(const MyApp()); 10 | } 11 | 12 | class MyApp extends StatefulWidget { 13 | const MyApp({Key? key}) : super(key: key); 14 | 15 | @override 16 | State createState() => _MyAppState(); 17 | } 18 | 19 | class _MyAppState extends State { 20 | int _fd = -1; 21 | int _ev_time = 0; 22 | int _ev_value = 0; 23 | int _ev_type = 0; 24 | int _ev_number = 0; 25 | 26 | @override 27 | void initState() { 28 | super.initState(); 29 | 30 | const String device = '/dev/input/js0'; 31 | _fd = joystickOpen(device.toNativeUtf8()); 32 | if (_fd < 0) { 33 | return; 34 | } 35 | 36 | Timer.periodic( 37 | const Duration(milliseconds: 13), 38 | _onPolling, 39 | ); 40 | } 41 | 42 | void _onPolling(Timer timer) { 43 | final Pointer pEv = malloc(); 44 | if (joystickRead(_fd, pEv) < 0) { 45 | return; 46 | } 47 | setState(() { 48 | _ev_time = pEv.ref.type; 49 | _ev_value = pEv.ref.value; 50 | _ev_type = pEv.ref.type; 51 | _ev_number = pEv.ref.number; 52 | }); 53 | } 54 | 55 | @override 56 | Widget build(BuildContext context) { 57 | return MaterialApp( 58 | home: Scaffold( 59 | appBar: AppBar( 60 | title: const Text('Joystick example app'), 61 | ), 62 | body: Center( 63 | child: Text('Joystick event: \n' 64 | 'time = $_ev_time\n' 65 | 'value = $_ev_value\n' 66 | 'type = $_ev_type\n' 67 | 'number = $_ev_number\n'), 68 | ), 69 | ), 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /packages/joystick/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: joystick_example 2 | description: Demonstrates how to use the joystick plugin for eLinux. 3 | 4 | environment: 5 | sdk: ">=2.12.0 <3.0.0" 6 | flutter: ">=2.10.0" 7 | 8 | dependencies: 9 | flutter: 10 | sdk: flutter 11 | joystick: 12 | # When depending on this package from a real application you should use: 13 | # joystick: ^x.y.z 14 | # See https://dart.dev/tools/pub/dependencies#version-constraints 15 | # The example app is bundled with the plugin so we use a path dependency on 16 | # the parent directory to use the current plugin's version. 17 | path: ../ 18 | 19 | dev_dependencies: 20 | flutter_lints: ^1.0.0 21 | flutter_test: 22 | sdk: flutter 23 | 24 | flutter: 25 | uses-material-design: true 26 | -------------------------------------------------------------------------------- /packages/joystick/lib/joystick.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // ignore_for_file: public_member_api_docs 6 | 7 | import 'dart:ffi'; 8 | import 'package:ffi/ffi.dart'; 9 | 10 | DynamicLibrary _dylib = DynamicLibrary.open('libjoystick_plugin.so'); 11 | 12 | /// See: 13 | /// struct js_event { 14 | /// __u32 time; /* event timestamp in milliseconds */ 15 | /// __s16 value; /* value */ 16 | /// __u8 type; /* event type */ 17 | /// __u8 number; /* axis/button number */ 18 | /// }; 19 | class JSEvent extends Struct { 20 | @Uint32() 21 | external int time; 22 | @Int16() 23 | external int value; 24 | @Uint8() 25 | external int type; 26 | @Uint8() 27 | external int number; 28 | } 29 | 30 | /// button pressed/released. See [JS_EVENT_BUTTON] in 31 | const int JS_EVENT_BUTTON = 0x01; 32 | 33 | /// joystick moved. See [JS_EVENT_AXIS] in 34 | const int JS_EVENT_AXIS = 0x02; 35 | 36 | /// initial state of device. See [JS_EVENT_INIT] in 37 | const int JS_EVENT_INIT = 0x80; 38 | 39 | typedef JoystickOpenNative = Int32 Function(Pointer); 40 | typedef JoystickOpen = int Function(Pointer); 41 | 42 | /// Opens joystick device. 43 | final JoystickOpen joystickOpen = _dylib 44 | .lookup>('joystick_open') 45 | .asFunction(); 46 | 47 | typedef JoystickReadNative = Int32 Function(Int32 fd, Pointer); 48 | typedef JoystickRead = int Function(int fd, Pointer); 49 | 50 | /// Reads joystick input data. 51 | final JoystickRead joystickRead = _dylib 52 | .lookup>('joystick_read') 53 | .asFunction(); 54 | 55 | /// Returns true if no events. 56 | bool joystickInputIsInactive(JSEvent ev) { 57 | return (ev.type & JS_EVENT_INIT) != 0; 58 | } 59 | 60 | /// Returns true if the event was caused by a button press. 61 | bool joystickInputIsButton(JSEvent ev) { 62 | return (ev.type & JS_EVENT_BUTTON) != 0; 63 | } 64 | 65 | /// Returns true if the event was caused by an axis movement. 66 | bool joystickInputIsAxis(JSEvent ev) { 67 | return (ev.type & JS_EVENT_AXIS) != 0; 68 | } 69 | 70 | /// Returns true if the button is pressed. 71 | bool joystickButtonIsPressed(JSEvent ev) { 72 | return (ev.value & 1) != 0; 73 | } 74 | -------------------------------------------------------------------------------- /packages/joystick/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: joystick 2 | description: A Flutter plugin for getting information about and controlling the 3 | joystick on eLinux. 4 | version: 1.0.1 5 | homepage: https://github.com/sony/flutter-elinux-plugins 6 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/joystick 7 | 8 | environment: 9 | sdk: ">=2.12.0 <3.0.0" 10 | flutter: ">=2.10.0" 11 | 12 | dependencies: 13 | ffi: ^2.0.0 14 | flutter: 15 | sdk: flutter 16 | 17 | flutter: 18 | plugin: 19 | platforms: 20 | elinux: 21 | pluginClass: JoystickPlugin 22 | -------------------------------------------------------------------------------- /packages/path_provider/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /packages/path_provider/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2.2.0 2 | * Update for path_provider 2.2.0 3 | 4 | ## 1.0.2 5 | * Update for flutter 3.3.0 release 6 | 7 | ## 1.0.1 8 | * Remove use of deprecated pedantic package 9 | 10 | ## 1.0.0 11 | * The initial implementation of path_provider for eLinux 12 | -------------------------------------------------------------------------------- /packages/path_provider/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/path_provider/README.md: -------------------------------------------------------------------------------- 1 | # path\_provider\_elinux 2 | The elinux implementation of [`path_provider`]. 3 | 4 | ## Usage 5 | 6 | ### pubspec.yaml 7 | ```Yaml 8 | dependencies: 9 | path_provider_elinux: 10 | git: 11 | url: https://github.com/sony/flutter-elinux-plugins.git 12 | path: packages/path_provider 13 | ref: main 14 | ``` 15 | 16 | ### Source code 17 | Import `path_provider_elinux` in your Dart code: 18 | 19 | ```Dart 20 | import 'package:path_provider_elinux/path_provider_elinux.dart'; 21 | ``` 22 | -------------------------------------------------------------------------------- /packages/path_provider/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | /build/ 32 | 33 | # Web related 34 | lib/generated_plugin_registrant.dart 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Exceptions to above rules. 43 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 44 | -------------------------------------------------------------------------------- /packages/path_provider/example/README.md: -------------------------------------------------------------------------------- 1 | # path_provider_elinux_example 2 | 3 | Demonstrates how to use the path_provider_elinux plugin. 4 | 5 | ## Getting Started 6 | 7 | For help getting started with Flutter for eLinux, view our online 8 | [documentation](https://github.com/sony/flutter-elinux/wiki). 9 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 12 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 15 | endforeach(plugin) 16 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/path_provider/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/path_provider/example/integration_test/path_provider_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:io'; 6 | import 'package:flutter_test/flutter_test.dart'; 7 | import 'package:integration_test/integration_test.dart'; 8 | import 'package:path_provider_elinux/path_provider_elinux.dart'; 9 | 10 | void main() { 11 | IntegrationTestWidgetsFlutterBinding.ensureInitialized(); 12 | 13 | testWidgets('getTemporaryDirectory', (WidgetTester tester) async { 14 | final PathProviderELinux provider = PathProviderELinux(); 15 | final String? result = await provider.getTemporaryPath(); 16 | _verifySampleFile(result, 'temporaryDirectory'); 17 | }); 18 | 19 | testWidgets('getDownloadDirectory', (WidgetTester tester) async { 20 | if (!Platform.isLinux) { 21 | return; 22 | } 23 | final PathProviderELinux provider = PathProviderELinux(); 24 | final String? result = await provider.getDownloadsPath(); 25 | _verifySampleFile(result, 'downloadDirectory'); 26 | }); 27 | 28 | testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async { 29 | final PathProviderELinux provider = PathProviderELinux(); 30 | final String? result = await provider.getApplicationDocumentsPath(); 31 | _verifySampleFile(result, 'applicationDocuments'); 32 | }); 33 | 34 | testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async { 35 | final PathProviderELinux provider = PathProviderELinux(); 36 | final String? result = await provider.getApplicationSupportPath(); 37 | _verifySampleFile(result, 'applicationSupport'); 38 | }); 39 | 40 | testWidgets('getApplicationCacheDirectory', (WidgetTester tester) async { 41 | final PathProviderELinux provider = PathProviderELinux(); 42 | final String? result = await provider.getApplicationCachePath(); 43 | _verifySampleFile(result, 'applicationCache'); 44 | }); 45 | } 46 | 47 | /// Verify a file called [name] in [directoryPath] by recreating it with test 48 | /// contents when necessary. 49 | void _verifySampleFile(String? directoryPath, String name) { 50 | expect(directoryPath, isNotNull); 51 | if (directoryPath == null) { 52 | return; 53 | } 54 | final Directory directory = Directory(directoryPath); 55 | final File file = File('${directory.path}${Platform.pathSeparator}$name'); 56 | 57 | if (file.existsSync()) { 58 | file.deleteSync(); 59 | expect(file.existsSync(), isFalse); 60 | } 61 | 62 | file.writeAsStringSync('Hello world!'); 63 | expect(file.readAsStringSync(), 'Hello world!'); 64 | expect(directory.listSync(), isNotEmpty); 65 | file.deleteSync(); 66 | } 67 | -------------------------------------------------------------------------------- /packages/path_provider/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter/services.dart'; 8 | import 'package:path_provider_elinux/path_provider_elinux.dart'; 9 | 10 | void main() { 11 | runApp(MyApp()); 12 | } 13 | 14 | /// Sample app 15 | class MyApp extends StatefulWidget { 16 | /// Default Constructor 17 | const MyApp({super.key}); 18 | 19 | @override 20 | State createState() => _MyAppState(); 21 | } 22 | 23 | class _MyAppState extends State { 24 | String? _tempDirectory = 'Unknown'; 25 | String? _downloadsDirectory = 'Unknown'; 26 | String? _appSupportDirectory = 'Unknown'; 27 | String? _appCacheDirectory = 'Unknown'; 28 | String? _documentsDirectory = 'Unknown'; 29 | final PathProviderELinux _provider = PathProviderELinux(); 30 | 31 | @override 32 | void initState() { 33 | super.initState(); 34 | initDirectories(); 35 | } 36 | 37 | // Platform messages are asynchronous, so we initialize in an async method. 38 | Future initDirectories() async { 39 | String? tempDirectory; 40 | String? downloadsDirectory; 41 | String? appSupportDirectory; 42 | String? appCacheDirectory; 43 | String? documentsDirectory; 44 | // Platform messages may fail, so we use a try/catch PlatformException. 45 | try { 46 | tempDirectory = await _provider.getTemporaryPath(); 47 | } on PlatformException { 48 | tempDirectory = 'Failed to get temp directory.'; 49 | } 50 | try { 51 | downloadsDirectory = await _provider.getDownloadsPath(); 52 | } on PlatformException { 53 | downloadsDirectory = 'Failed to get downloads directory.'; 54 | } 55 | 56 | try { 57 | documentsDirectory = await _provider.getApplicationDocumentsPath(); 58 | } on PlatformException { 59 | documentsDirectory = 'Failed to get documents directory.'; 60 | } 61 | 62 | try { 63 | appSupportDirectory = await _provider.getApplicationSupportPath(); 64 | } on PlatformException { 65 | appSupportDirectory = 'Failed to get documents directory.'; 66 | } 67 | 68 | try { 69 | appCacheDirectory = await _provider.getApplicationCachePath(); 70 | } on PlatformException { 71 | appCacheDirectory = 'Failed to get cache directory.'; 72 | } 73 | // If the widget was removed from the tree while the asynchronous platform 74 | // message was in flight, we want to discard the reply rather than calling 75 | // setState to update our non-existent appearance. 76 | if (!mounted) { 77 | return; 78 | } 79 | 80 | setState(() { 81 | _tempDirectory = tempDirectory; 82 | _downloadsDirectory = downloadsDirectory; 83 | _appSupportDirectory = appSupportDirectory; 84 | _appCacheDirectory = appCacheDirectory; 85 | _documentsDirectory = documentsDirectory; 86 | }); 87 | } 88 | 89 | @override 90 | Widget build(BuildContext context) { 91 | return MaterialApp( 92 | home: Scaffold( 93 | appBar: AppBar( 94 | title: const Text('Path Provider Linux example app'), 95 | ), 96 | body: Center( 97 | child: Column( 98 | children: [ 99 | Text('Temp Directory: $_tempDirectory\n'), 100 | Text('Documents Directory: $_documentsDirectory\n'), 101 | Text('Downloads Directory: $_downloadsDirectory\n'), 102 | Text('Application Support Directory: $_appSupportDirectory\n'), 103 | Text('Application Cache Directory: $_appCacheDirectory\n'), 104 | ], 105 | ), 106 | ), 107 | ), 108 | ); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /packages/path_provider/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: pathproviderexample 2 | description: Demonstrates how to use the path_provider_elinux plugin. 3 | publish_to: "none" 4 | 5 | environment: 6 | sdk: ">=2.18.0 <4.0.0" 7 | flutter: ">=3.3.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | path_provider_elinux: 14 | path: ../ 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | integration_test: 20 | sdk: flutter 21 | 22 | flutter: 23 | uses-material-design: true 24 | -------------------------------------------------------------------------------- /packages/path_provider/example/test_driver/integration_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'package:integration_test/integration_test_driver.dart'; 6 | 7 | Future main() => integrationDriver(); 8 | -------------------------------------------------------------------------------- /packages/path_provider/lib/path_provider_elinux.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | export 'src/path_provider_elinux.dart'; 7 | -------------------------------------------------------------------------------- /packages/path_provider/lib/src/get_application_id.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // getApplicationId() is implemented using FFI; export a stub for platforms 6 | // that don't support FFI (e.g., web) to avoid having transitive dependencies 7 | // break web compilation. 8 | export 'get_application_id_stub.dart' 9 | if (dart.library.ffi) 'get_application_id_real.dart'; 10 | -------------------------------------------------------------------------------- /packages/path_provider/lib/src/get_application_id_real.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:ffi'; 6 | import 'package:ffi/ffi.dart'; 7 | import 'package:flutter/foundation.dart' show visibleForTesting; 8 | 9 | // GApplication* g_application_get_default(); 10 | typedef _GApplicationGetDefaultC = IntPtr Function(); 11 | typedef _GApplicationGetDefaultDart = int Function(); 12 | 13 | // const gchar* g_application_get_application_id(GApplication* application); 14 | typedef _GApplicationGetApplicationIdC = Pointer Function(IntPtr); 15 | typedef _GApplicationGetApplicationIdDart = Pointer Function(int); 16 | 17 | /// Interface for interacting with libgio. 18 | @visibleForTesting 19 | class GioUtils { 20 | /// Creates a default instance that uses the real libgio. 21 | GioUtils() { 22 | try { 23 | _gio = DynamicLibrary.open('libgio-2.0.so'); 24 | } on ArgumentError { 25 | _gio = null; 26 | } 27 | } 28 | 29 | DynamicLibrary? _gio; 30 | 31 | /// True if libgio was opened successfully. 32 | bool get libraryIsPresent => _gio != null; 33 | 34 | /// Wraps `g_application_get_default`. 35 | int gApplicationGetDefault() { 36 | if (_gio == null) { 37 | return 0; 38 | } 39 | final _GApplicationGetDefaultDart getDefault = _gio! 40 | .lookupFunction<_GApplicationGetDefaultC, _GApplicationGetDefaultDart>( 41 | 'g_application_get_default'); 42 | return getDefault(); 43 | } 44 | 45 | /// Wraps g_application_get_application_id. 46 | Pointer gApplicationGetApplicationId(int app) { 47 | if (_gio == null) { 48 | return nullptr; 49 | } 50 | final _GApplicationGetApplicationIdDart gApplicationGetApplicationId = _gio! 51 | .lookupFunction<_GApplicationGetApplicationIdC, 52 | _GApplicationGetApplicationIdDart>( 53 | 'g_application_get_application_id'); 54 | return gApplicationGetApplicationId(app); 55 | } 56 | } 57 | 58 | /// Allows overriding the default GioUtils instance with a fake for testing. 59 | @visibleForTesting 60 | GioUtils? gioUtilsOverride; 61 | 62 | /// Gets the application ID for this app. 63 | String? getApplicationId() { 64 | final GioUtils gio = gioUtilsOverride ?? GioUtils(); 65 | if (!gio.libraryIsPresent) { 66 | return null; 67 | } 68 | 69 | final int app = gio.gApplicationGetDefault(); 70 | if (app == 0) { 71 | return null; 72 | } 73 | final Pointer appId = gio.gApplicationGetApplicationId(app); 74 | if (appId == nullptr) { 75 | return null; 76 | } 77 | return appId.toDartString(); 78 | } 79 | -------------------------------------------------------------------------------- /packages/path_provider/lib/src/get_application_id_stub.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | /// Gets the application ID for this app. 6 | String? getApplicationId() => null; 7 | -------------------------------------------------------------------------------- /packages/path_provider/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: path_provider_elinux 2 | description: eLinux implementation of the path_provider plugin 3 | homepage: https://github.com/sony/flutter-elinux-plugins 4 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/path_provider 5 | version: 2.2.0 6 | 7 | environment: 8 | sdk: ">=2.18.0 <4.0.0" 9 | flutter: ">=3.3.0" 10 | 11 | flutter: 12 | plugin: 13 | implements: path_provider 14 | platforms: 15 | elinux: 16 | dartPluginClass: PathProviderELinux 17 | pluginClass: none 18 | 19 | dependencies: 20 | ffi: ">=1.1.2 <3.0.0" 21 | flutter: 22 | sdk: flutter 23 | path: ^1.8.0 24 | path_provider_platform_interface: ^2.1.0 25 | xdg_directories: ">=0.2.0 <2.0.0" 26 | 27 | dev_dependencies: 28 | flutter_test: 29 | sdk: flutter 30 | -------------------------------------------------------------------------------- /packages/path_provider/test/path_provider_elinux_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | import 'package:flutter_test/flutter_test.dart'; 6 | import 'package:path_provider_elinux/path_provider_elinux.dart'; 7 | import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; 8 | import 'package:xdg_directories/xdg_directories.dart' as xdg; 9 | 10 | void main() { 11 | TestWidgetsFlutterBinding.ensureInitialized(); 12 | PathProviderELinux.registerWith(); 13 | 14 | test('registered instance', () { 15 | expect(PathProviderPlatform.instance, isA()); 16 | }); 17 | 18 | test('getTemporaryPath defaults to TMPDIR', () async { 19 | final PathProviderPlatform plugin = PathProviderELinux.private( 20 | environment: {'TMPDIR': '/run/user/0/tmp'}, 21 | ); 22 | expect(await plugin.getTemporaryPath(), '/run/user/0/tmp'); 23 | }); 24 | 25 | test('getTemporaryPath uses fallback if TMPDIR is empty', () async { 26 | final PathProviderPlatform plugin = PathProviderELinux.private( 27 | environment: {'TMPDIR': ''}, 28 | ); 29 | expect(await plugin.getTemporaryPath(), '/tmp'); 30 | }); 31 | 32 | test('getTemporaryPath uses fallback if TMPDIR is unset', () async { 33 | final PathProviderPlatform plugin = PathProviderELinux.private( 34 | environment: {}, 35 | ); 36 | expect(await plugin.getTemporaryPath(), '/tmp'); 37 | }); 38 | 39 | test('getApplicationSupportPath', () async { 40 | final PathProviderPlatform plugin = PathProviderELinux.private( 41 | executableName: 'path_provider_elinux_test_binary', 42 | applicationId: 'com.example.Test'); 43 | // Note this will fail if ${xdg.dataHome.path}/path_provider_linux_test_binary exists on the local filesystem. 44 | expect(await plugin.getApplicationSupportPath(), 45 | '${xdg.dataHome.path}/com.example.Test'); 46 | }); 47 | 48 | test('getApplicationSupportPath uses executable name if no application Id', 49 | () async { 50 | final PathProviderPlatform plugin = PathProviderELinux.private( 51 | executableName: 'path_provider_elinux_test_binary'); 52 | expect(await plugin.getApplicationSupportPath(), 53 | '${xdg.dataHome.path}/path_provider_elinux_test_binary'); 54 | }); 55 | 56 | test('getApplicationDocumentsPath', () async { 57 | final PathProviderPlatform plugin = PathProviderPlatform.instance; 58 | expect(await plugin.getApplicationDocumentsPath(), startsWith('/')); 59 | }); 60 | 61 | test('getApplicationCachePath', () async { 62 | final PathProviderPlatform plugin = PathProviderELinux.private( 63 | executableName: 'path_provider_elinux_test_binary'); 64 | expect(await plugin.getApplicationCachePath(), 65 | '${xdg.cacheHome.path}/path_provider_elinux_test_binary'); 66 | }); 67 | 68 | test('getDownloadsPath', () async { 69 | final PathProviderPlatform plugin = PathProviderPlatform.instance; 70 | expect(await plugin.getDownloadsPath(), startsWith('/')); 71 | }); 72 | } 73 | -------------------------------------------------------------------------------- /packages/shared_preferences/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /packages/shared_preferences/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2.2.0 2 | * Update for shared_preferences 2.2.0 3 | 4 | ## 1.0.1 5 | * Update for flutter 3.3.0 release 6 | 7 | ## 1.0.0 8 | * Initial release to support shared_preferences on eLinux. 9 | -------------------------------------------------------------------------------- /packages/shared_preferences/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/shared_preferences/README.md: -------------------------------------------------------------------------------- 1 | # shared\_preferences\_elinux 2 | 3 | The eLinux implementation of [`shared_preferences`](https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences). 4 | 5 | ## Usage 6 | 7 | ### pubspec.yaml 8 | ```Yaml 9 | dependencies: 10 | shared_preferences_elinux: 11 | git: 12 | url: https://github.com/sony/flutter-elinux-plugins.git 13 | path: packages/shared_preferences 14 | ref: main 15 | ``` 16 | 17 | ### Source code 18 | Import `shared_preferences_elinux` in your Dart code: 19 | 20 | ```Dart 21 | import 'package:shared_preferences_elinux/shared_preferences_elinux.dart'; 22 | ``` 23 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | /build/ 32 | 33 | # Web related 34 | lib/generated_plugin_registrant.dart 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Exceptions to above rules. 43 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 44 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/README.md: -------------------------------------------------------------------------------- 1 | # shared_preferences_elinux_example 2 | 3 | Demonstrates how to use the `shared_preferences_elinux` plugin. 4 | 5 | ## Getting Started 6 | 7 | For help getting started with Flutter for eLinux, view our online 8 | [documentation](https://github.com/sony/flutter-elinux/wiki). 9 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 12 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 13 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 15 | endforeach(plugin) 16 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | // ignore_for_file: public_member_api_docs 7 | 8 | import 'dart:async'; 9 | 10 | import 'package:flutter/material.dart'; 11 | import 'package:shared_preferences_elinux/shared_preferences_elinux.dart'; 12 | 13 | void main() { 14 | runApp(const MyApp()); 15 | } 16 | 17 | class MyApp extends StatelessWidget { 18 | const MyApp({super.key}); 19 | 20 | @override 21 | Widget build(BuildContext context) { 22 | return const MaterialApp( 23 | title: 'SharedPreferences Demo', 24 | home: SharedPreferencesDemo(), 25 | ); 26 | } 27 | } 28 | 29 | class SharedPreferencesDemo extends StatefulWidget { 30 | const SharedPreferencesDemo({super.key}); 31 | 32 | @override 33 | SharedPreferencesDemoState createState() => SharedPreferencesDemoState(); 34 | } 35 | 36 | class SharedPreferencesDemoState extends State { 37 | final SharedPreferencesELinux prefs = SharedPreferencesELinux(); 38 | late Future _counter; 39 | 40 | Future _incrementCounter() async { 41 | final Map values = await prefs.getAll(); 42 | final int counter = (values['counter'] as int? ?? 0) + 1; 43 | 44 | setState(() { 45 | _counter = prefs.setValue('Int', 'counter', counter).then((bool success) { 46 | return counter; 47 | }); 48 | }); 49 | } 50 | 51 | @override 52 | void initState() { 53 | super.initState(); 54 | _counter = prefs.getAll().then((Map values) { 55 | return values['counter'] as int? ?? 0; 56 | }); 57 | } 58 | 59 | @override 60 | Widget build(BuildContext context) { 61 | return Scaffold( 62 | appBar: AppBar( 63 | title: const Text('SharedPreferences Demo'), 64 | ), 65 | body: Center( 66 | child: FutureBuilder( 67 | future: _counter, 68 | builder: (BuildContext context, AsyncSnapshot snapshot) { 69 | switch (snapshot.connectionState) { 70 | case ConnectionState.none: 71 | case ConnectionState.waiting: 72 | return const CircularProgressIndicator(); 73 | case ConnectionState.active: 74 | case ConnectionState.done: 75 | if (snapshot.hasError) { 76 | return Text('Error: ${snapshot.error}'); 77 | } else { 78 | return Text( 79 | 'Button tapped ${snapshot.data} time${snapshot.data == 1 ? '' : 's'}.\n\n' 80 | 'This should persist across restarts.', 81 | ); 82 | } 83 | } 84 | })), 85 | floatingActionButton: FloatingActionButton( 86 | onPressed: _incrementCounter, 87 | tooltip: 'Increment', 88 | child: const Icon(Icons.add), 89 | ), 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: shared_preferences_elinux_example 2 | description: Demonstrates how to use the shared_preferences_elinux plugin. 3 | publish_to: none 4 | 5 | environment: 6 | sdk: ">=2.18.0 <4.0.0" 7 | flutter: ">=3.3.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | shared_preferences_elinux: 13 | path: ../ 14 | shared_preferences_platform_interface: ^2.3.0 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | integration_test: 20 | sdk: flutter 21 | 22 | flutter: 23 | uses-material-design: true 24 | -------------------------------------------------------------------------------- /packages/shared_preferences/example/test_driver/integration_test.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'package:integration_test/integration_test_driver.dart'; 6 | 7 | Future main() => integrationDriver(); 8 | -------------------------------------------------------------------------------- /packages/shared_preferences/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: shared_preferences_elinux 2 | description: eLinux implementation of the shared_preferences plugin 3 | homepage: https://github.com/sony/flutter-elinux-plugins 4 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/shared_preferences 5 | version: 2.2.0 6 | 7 | environment: 8 | sdk: ">=2.18.0 <4.0.0" 9 | flutter: ">=3.3.0" 10 | 11 | flutter: 12 | plugin: 13 | implements: shared_preferences 14 | platforms: 15 | elinux: 16 | dartPluginClass: SharedPreferencesELinux 17 | pluginClass: none 18 | 19 | dependencies: 20 | file: ^6.0.0 21 | flutter: 22 | sdk: flutter 23 | path: ^1.8.0 24 | path_provider_elinux: 25 | git: 26 | url: https://github.com/sony/flutter-elinux-plugins.git 27 | path: packages/path_provider 28 | ref: main 29 | shared_preferences_platform_interface: ^2.3.0 30 | 31 | dev_dependencies: 32 | flutter_test: 33 | sdk: flutter 34 | -------------------------------------------------------------------------------- /packages/video_player/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /packages/video_player/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | * Add `isPlaying` functionality with VideoPlayerController. 3 | 4 | ## 0.9.9 5 | * Add ELinuxVideoPlayer (VideoPlayerPlatform for eLinux) for flutter 3.13. 6 | 7 | ## 0.9.8 8 | * Update flutter/dart-sdk versions in environment for flutter 3.13.0. 9 | 10 | ## 0.9.7 11 | * Improve playback performance if GstEGLImage is avalable. 12 | 13 | ## 0.9.6 14 | * Update for video_player_platform_interface v5.1.1 / video_player v2.4.7 / flutter 3.3.0 15 | 16 | ## 0.9.5 17 | * Fix missing include. 18 | 19 | ## 0.9.4 20 | * Upgrade video_player_platform_interface from 4.1.0 to 4.2.0. 21 | * Refactor example source code. 22 | 23 | ## 0.9.3 24 | * Improve the error handling. 25 | * Add the missing mutex. 26 | 27 | ## 0.9.2 28 | * Changed to send stream completed messages from main thread. 29 | 30 | ## 0.9.1 31 | * Temporarily disable auto-repeat. 32 | * Update the elinux template of the example app. 33 | 34 | ## 0.9.0 35 | * First release. 36 | -------------------------------------------------------------------------------- /packages/video_player/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Sony Group Corporation. All rights reserved. 2 | Copyright (c) 2013 The Flutter Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the names of the copyright holders nor the names of the 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /packages/video_player/README.md: -------------------------------------------------------------------------------- 1 | # video_player_elinux 2 | 3 | The implementation of the Video Player plugin for flutter elinux. APIs are designed to be API compatible with the the official [`video_player`](https://github.com/flutter/packages/tree/main/packages/video_player/video_player). 4 | 5 | ![image](https://user-images.githubusercontent.com/62131389/124210378-43f06400-db26-11eb-8723-40dad0eb67b0.png) 6 | 7 | ## Required libraries 8 | 9 | This plugin uses [GStreamer](https://gstreamer.freedesktop.org/) internally. 10 | 11 | ```Shell 12 | $ sudo apt install libglib2.0-dev libgstreamer1.0-dev 13 | # Install as needed. 14 | $ sudo apt install libgstreamer-plugins-base1.0-dev \ 15 | gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ 16 | gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav 17 | ``` 18 | 19 | ## Usage 20 | 21 | ### pubspec.yaml 22 | ```yaml 23 | dependencies: 24 | video_player: ^2.6.1 25 | video_player_elinux: 26 | git: 27 | url: https://github.com/sony/flutter-elinux-plugins.git 28 | path: packages/video_player 29 | ref: main 30 | ``` 31 | 32 | ### Source code 33 | 34 | Import `video_player` in your Dart code: 35 | ```dart 36 | import 'package:video_player/video_player.dart'; 37 | ``` 38 | 39 | ### Enable GstEGLImage 40 | 41 | If GstEGLImage is enabled on your target device, adding the following code to `/elinux/CMakeLists.txt` may improve playback performance. 42 | 43 | ``` 44 | add_definitions(-DUSE_EGL_IMAGE_DMABUF) 45 | set(USE_EGL_IMAGE_DMABUF "on") 46 | ``` 47 | 48 | ### Customize for your target devices 49 | 50 | To improve the performance of this plugin, you will need to customize the pipeline in the source file. Please modify the source file and replace the `videoconvert` element with a H/W accelerated element of your target device to perform well. 51 | 52 | `bool GstVideoPlayer::CreatePipeline()` in packages/video_player/elinux/gst_video_player.cc 53 | 54 | #### default: 55 | 56 | ``` 57 | playbin uri= video-sink="videoconvert ! video/x-raw,format=RGBA ! fakesink" 58 | ``` 59 | 60 | #### i.MX 8M platforms: 61 | 62 | ``` 63 | playbin uri= video-sink="imxvideoconvert_g2d ! video/x-raw,format=RGBA ! fakesink" 64 | ``` 65 | -------------------------------------------------------------------------------- /packages/video_player/elinux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | -------------------------------------------------------------------------------- /packages/video_player/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | set(PROJECT_NAME "video_player_elinux") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | # This value is used when generating builds using this plugin, so it must 6 | # not be changed 7 | set(PLUGIN_NAME "video_player_elinux_plugin") 8 | 9 | find_package(PkgConfig) 10 | pkg_check_modules(GLIB REQUIRED glib-2.0) 11 | pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) 12 | if(USE_EGL_IMAGE_DMABUF) 13 | pkg_check_modules(GSTREAMER_GL REQUIRED gstreamer-gl-1.0) 14 | endif() 15 | 16 | add_library(${PLUGIN_NAME} SHARED 17 | "video_player_elinux_plugin.cc" 18 | "gst_video_player.cc" 19 | ) 20 | apply_standard_settings(${PLUGIN_NAME}) 21 | set_target_properties(${PLUGIN_NAME} PROPERTIES 22 | CXX_VISIBILITY_PRESET hidden) 23 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 24 | target_include_directories(${PLUGIN_NAME} INTERFACE 25 | "${CMAKE_CURRENT_SOURCE_DIR}/include") 26 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 27 | 28 | target_include_directories(${PLUGIN_NAME} 29 | PRIVATE 30 | ${GLIB_INCLUDE_DIRS} 31 | ${GSTREAMER_INCLUDE_DIRS} 32 | ) 33 | if(USE_EGL_IMAGE_DMABUF) 34 | target_include_directories(${PLUGIN_NAME} 35 | PRIVATE 36 | ${GSTREAMER_GL_INCLUDE_DIRS} 37 | ) 38 | endif() 39 | 40 | target_link_libraries(${PLUGIN_NAME} 41 | PRIVATE 42 | ${GLIB_LIBRARIES} 43 | ${GSTREAMER_LIBRARIES} 44 | ) 45 | if(USE_EGL_IMAGE_DMABUF) 46 | target_link_libraries(${PLUGIN_NAME} 47 | PRIVATE 48 | ${GSTREAMER_GL_LIBRARIES} 49 | ) 50 | endif() 51 | 52 | # List of absolute paths to libraries that should be bundled with the plugin 53 | set(video_player_elinux_bundled_libraries 54 | "" 55 | PARENT_SCOPE 56 | ) 57 | -------------------------------------------------------------------------------- /packages/video_player/elinux/gst_video_player.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 7 | 8 | #include 9 | 10 | #ifdef USE_EGL_IMAGE_DMABUF 11 | #include 12 | #include 13 | #include 14 | #include 15 | #endif // USE_EGL_IMAGE_DMABUF 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "video_player_stream_handler.h" 23 | 24 | class GstVideoPlayer { 25 | public: 26 | GstVideoPlayer(const std::string& uri, 27 | std::unique_ptr handler); 28 | ~GstVideoPlayer(); 29 | 30 | static void GstLibraryLoad(); 31 | static void GstLibraryUnload(); 32 | 33 | bool Init(); 34 | bool Play(); 35 | bool Pause(); 36 | bool Stop(); 37 | bool SetVolume(double volume); 38 | bool SetPlaybackRate(double rate); 39 | void SetAutoRepeat(bool auto_repeat) { auto_repeat_ = auto_repeat; }; 40 | bool SetSeek(int64_t position); 41 | int64_t GetDuration(); 42 | int64_t GetCurrentPosition(); 43 | const uint8_t* GetFrameBuffer(); 44 | #ifdef USE_EGL_IMAGE_DMABUF 45 | void* GetEGLImage(void* egl_display, void* egl_context); 46 | #endif // USE_EGL_IMAGE_DMABUF 47 | int32_t GetWidth() const { return width_; }; 48 | int32_t GetHeight() const { return height_; }; 49 | 50 | private: 51 | struct GstVideoElements { 52 | GstElement* pipeline; 53 | GstElement* playbin; 54 | GstElement* video_convert; 55 | GstElement* video_sink; 56 | GstElement* output; 57 | GstBus* bus; 58 | GstBuffer* buffer; 59 | }; 60 | 61 | static void HandoffHandler(GstElement* fakesink, GstBuffer* buf, 62 | GstPad* new_pad, gpointer user_data); 63 | static GstBusSyncReply HandleGstMessage(GstBus* bus, GstMessage* message, 64 | gpointer user_data); 65 | std::string ParseUri(const std::string& uri); 66 | bool CreatePipeline(); 67 | void DestroyPipeline(); 68 | bool Preroll(); 69 | void GetVideoSize(int32_t& width, int32_t& height); 70 | #ifdef USE_EGL_IMAGE_DMABUF 71 | void UnrefEGLImage(); 72 | #endif // USE_EGL_IMAGE_DMABUF 73 | 74 | GstVideoElements gst_; 75 | std::string uri_; 76 | std::unique_ptr pixels_; 77 | int32_t width_; 78 | int32_t height_; 79 | double volume_ = 1.0; 80 | double playback_rate_ = 1.0; 81 | bool mute_ = false; 82 | bool auto_repeat_ = false; 83 | bool is_completed_ = false; 84 | std::mutex mutex_event_completed_; 85 | std::shared_mutex mutex_buffer_; 86 | std::unique_ptr stream_handler_; 87 | 88 | #ifdef USE_EGL_IMAGE_DMABUF 89 | GstVideoInfo gst_video_info_; 90 | GstEGLImage* gst_egl_image_ = NULL; 91 | GstGLContext* gst_gl_ctx_ = NULL; 92 | GstGLDisplayEGL* gst_gl_display_egl_ = NULL; 93 | #endif // USE_EGL_IMAGE_DMABUF 94 | }; 95 | 96 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 97 | -------------------------------------------------------------------------------- /packages/video_player/elinux/include/video_player_elinux/video_player_elinux_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_VIDEO_PLAYER_ELINUX_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_VIDEO_PLAYER_ELINUX_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void VideoPlayerElinuxPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_VIDEO_PLAYER_ELINUX_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/create_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_CREATE_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_CREATE_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class CreateMessage { 12 | public: 13 | CreateMessage() = default; 14 | ~CreateMessage() = default; 15 | 16 | // Prevent copying. 17 | CreateMessage(CreateMessage const&) = default; 18 | CreateMessage& operator=(CreateMessage const&) = default; 19 | 20 | void SetAsset(const std::string& asset) { asset_ = asset; } 21 | 22 | std::string GetAsset() const { return asset_; } 23 | 24 | void SetUri(const std::string& uri) { uri_ = uri; } 25 | 26 | std::string GetUri() const { return uri_; } 27 | 28 | void SetPackageName(const std::string& packageName) { 29 | package_name_ = packageName; 30 | } 31 | 32 | std::string GetPackageName() const { return package_name_; } 33 | 34 | void SetFormatHint(const std::string& formatHint) { 35 | format_hint_ = formatHint; 36 | } 37 | 38 | std::string GetFormatHint() const { return format_hint_; } 39 | 40 | flutter::EncodableValue ToMap() { 41 | // todo: Add httpHeaders. 42 | flutter::EncodableMap map = { 43 | {flutter::EncodableValue("asset"), flutter::EncodableValue(asset_)}, 44 | {flutter::EncodableValue("uri"), flutter::EncodableValue(uri_)}, 45 | {flutter::EncodableValue("packageName"), 46 | flutter::EncodableValue(package_name_)}, 47 | {flutter::EncodableValue("formatHint"), 48 | flutter::EncodableValue(format_hint_)}}; 49 | return flutter::EncodableValue(map); 50 | } 51 | 52 | static CreateMessage FromMap(const flutter::EncodableValue& value) { 53 | CreateMessage message; 54 | if (std::holds_alternative(value)) { 55 | auto map = std::get(value); 56 | 57 | flutter::EncodableValue& asset = map[flutter::EncodableValue("asset")]; 58 | if (std::holds_alternative(asset)) { 59 | message.SetAsset(std::get(asset)); 60 | } 61 | 62 | flutter::EncodableValue& uri = map[flutter::EncodableValue("uri")]; 63 | if (std::holds_alternative(uri)) { 64 | message.SetUri(std::get(uri)); 65 | } 66 | 67 | flutter::EncodableValue& packageName = 68 | map[flutter::EncodableValue("packageName")]; 69 | if (std::holds_alternative(packageName)) { 70 | message.SetPackageName(std::get(packageName)); 71 | } 72 | 73 | flutter::EncodableValue& formatHint = 74 | map[flutter::EncodableValue("formatHint")]; 75 | if (std::holds_alternative(formatHint)) { 76 | message.SetFormatHint(std::get(formatHint)); 77 | } 78 | } 79 | 80 | return message; 81 | } 82 | 83 | private: 84 | std::string asset_; 85 | std::string uri_; 86 | std::string package_name_; 87 | std::string format_hint_; 88 | }; 89 | 90 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_CREATE_MESSAGE_H_ 91 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/looping_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class LoopingMessage { 12 | public: 13 | LoopingMessage() = default; 14 | ~LoopingMessage() = default; 15 | 16 | // Prevent copying. 17 | LoopingMessage(LoopingMessage const&) = default; 18 | LoopingMessage& operator=(LoopingMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetIsLooping(bool is_looping) { is_looping_ = is_looping; } 25 | 26 | bool GetIsLooping() const { return is_looping_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = {{flutter::EncodableValue("textureId"), 30 | flutter::EncodableValue(texture_id_)}, 31 | {flutter::EncodableValue("isLooping"), 32 | flutter::EncodableValue(is_looping_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static LoopingMessage FromMap(const flutter::EncodableValue& value) { 37 | LoopingMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& is_looping = 49 | map[flutter::EncodableValue("isLooping")]; 50 | if (std::holds_alternative(is_looping)) { 51 | message.SetIsLooping(std::get(is_looping)); 52 | } 53 | } 54 | 55 | return message; 56 | } 57 | 58 | private: 59 | int64_t texture_id_ = 0; 60 | bool is_looping_ = false; 61 | }; 62 | 63 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 64 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/messages.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 7 | 8 | #include "create_message.h" 9 | #include "looping_message.h" 10 | #include "mix_with_others_message.h" 11 | #include "playback_speed_message.h" 12 | #include "position_message.h" 13 | #include "texture_message.h" 14 | #include "volume_message.h" 15 | 16 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 17 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/mix_with_others_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class MixWithOthersMessage { 12 | public: 13 | MixWithOthersMessage() = default; 14 | ~MixWithOthersMessage() = default; 15 | 16 | // Prevent copying. 17 | MixWithOthersMessage(MixWithOthersMessage const&) = default; 18 | MixWithOthersMessage& operator=(MixWithOthersMessage const&) = default; 19 | 20 | void SetMixWithOthers(bool mixWithOthers) { 21 | mix_with_others_ = mixWithOthers; 22 | } 23 | 24 | bool GetMixWithOthers() const { return mix_with_others_; } 25 | 26 | flutter::EncodableValue ToMap() { 27 | flutter::EncodableMap map = {{flutter::EncodableValue("mixWithOthers"), 28 | flutter::EncodableValue(mix_with_others_)}}; 29 | 30 | return flutter::EncodableValue(map); 31 | } 32 | 33 | static MixWithOthersMessage FromMap(const flutter::EncodableValue& value) { 34 | MixWithOthersMessage message; 35 | if (std::holds_alternative(value)) { 36 | auto map = std::get(value); 37 | 38 | flutter::EncodableValue& mixWithOthers = 39 | map[flutter::EncodableValue("mixWithOthers")]; 40 | if (std::holds_alternative(mixWithOthers)) { 41 | message.SetMixWithOthers(std::get(mixWithOthers)); 42 | } 43 | } 44 | 45 | return message; 46 | } 47 | 48 | private: 49 | bool mix_with_others_ = false; 50 | }; 51 | 52 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 53 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/playback_speed_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class PlaybackSpeedMessage { 12 | public: 13 | PlaybackSpeedMessage() = default; 14 | ~PlaybackSpeedMessage() = default; 15 | 16 | // Prevent copying. 17 | PlaybackSpeedMessage(PlaybackSpeedMessage const&) = default; 18 | PlaybackSpeedMessage& operator=(PlaybackSpeedMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetSpeed(double speed) { speed_ = speed; } 25 | 26 | double GetSpeed() const { return speed_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = { 30 | {flutter::EncodableValue("textureId"), 31 | flutter::EncodableValue(texture_id_)}, 32 | {flutter::EncodableValue("speed"), flutter::EncodableValue(speed_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static PlaybackSpeedMessage FromMap(const flutter::EncodableValue& value) { 37 | PlaybackSpeedMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& speed = map[flutter::EncodableValue("speed")]; 49 | if (std::holds_alternative(speed)) { 50 | message.SetSpeed(std::get(speed)); 51 | } 52 | } 53 | 54 | return message; 55 | } 56 | 57 | private: 58 | int64_t texture_id_ = 0; 59 | double speed_ = 1.0; 60 | }; 61 | 62 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 63 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/position_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class PositionMessage { 12 | public: 13 | PositionMessage() = default; 14 | ~PositionMessage() = default; 15 | 16 | // Prevent copying. 17 | PositionMessage(PositionMessage const&) = default; 18 | PositionMessage& operator=(PositionMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetPosition(int64_t position) { position_ = position; } 25 | 26 | int64_t GetPosition() const { return position_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap toMapResult = {{flutter::EncodableValue("textureId"), 30 | flutter::EncodableValue(texture_id_)}, 31 | {flutter::EncodableValue("position"), 32 | flutter::EncodableValue(position_)}}; 33 | 34 | return flutter::EncodableValue(toMapResult); 35 | } 36 | 37 | static PositionMessage FromMap(const flutter::EncodableValue& value) { 38 | PositionMessage message; 39 | if (std::holds_alternative(value)) { 40 | auto map = std::get(value); 41 | 42 | flutter::EncodableValue& texture_id = 43 | map[flutter::EncodableValue("textureId")]; 44 | if (std::holds_alternative(texture_id) || 45 | std::holds_alternative(texture_id)) { 46 | message.SetTextureId(texture_id.LongValue()); 47 | } 48 | 49 | flutter::EncodableValue& position = 50 | map[flutter::EncodableValue("position")]; 51 | if (std::holds_alternative(position) || 52 | std::holds_alternative(position)) { 53 | message.SetPosition(position.LongValue()); 54 | } 55 | } 56 | 57 | return message; 58 | } 59 | 60 | private: 61 | int64_t texture_id_ = 0; 62 | int64_t position_ = 0; 63 | }; 64 | 65 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 66 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/texture_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class TextureMessage { 12 | public: 13 | TextureMessage() = default; 14 | ~TextureMessage() = default; 15 | 16 | // Prevent copying. 17 | TextureMessage(TextureMessage const&) = default; 18 | TextureMessage& operator=(TextureMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | flutter::EncodableValue ToMap() { 25 | flutter::EncodableMap map = {{flutter::EncodableValue("textureId"), 26 | flutter::EncodableValue(texture_id_)}}; 27 | return flutter::EncodableValue(map); 28 | } 29 | 30 | static TextureMessage FromMap(const flutter::EncodableValue& value) { 31 | TextureMessage message; 32 | if (std::holds_alternative(value)) { 33 | auto map = std::get(value); 34 | 35 | flutter::EncodableValue& texture_id = 36 | map[flutter::EncodableValue("textureId")]; 37 | if (std::holds_alternative(texture_id) || 38 | std::holds_alternative(texture_id)) { 39 | message.SetTextureId(texture_id.LongValue()); 40 | } 41 | } 42 | return message; 43 | } 44 | 45 | private: 46 | int64_t texture_id_ = 0; 47 | }; 48 | 49 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 50 | -------------------------------------------------------------------------------- /packages/video_player/elinux/messages/volume_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class VolumeMessage { 12 | public: 13 | VolumeMessage() = default; 14 | ~VolumeMessage() = default; 15 | 16 | // Prevent copying. 17 | VolumeMessage(VolumeMessage const&) = default; 18 | VolumeMessage& operator=(VolumeMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetVolume(double volume) { volume_ = volume; } 25 | 26 | double GetVolume() const { return volume_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = { 30 | {flutter::EncodableValue("textureId"), 31 | flutter::EncodableValue(texture_id_)}, 32 | {flutter::EncodableValue("volume"), flutter::EncodableValue(volume_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static VolumeMessage FromMap(const flutter::EncodableValue& value) { 37 | VolumeMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& volume = map[flutter::EncodableValue("volume")]; 49 | if (std::holds_alternative(volume)) { 50 | message.SetVolume(std::get(volume)); 51 | } 52 | } 53 | 54 | return message; 55 | } 56 | 57 | private: 58 | int64_t texture_id_ = 0; 59 | double volume_ = 0; 60 | }; 61 | 62 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 63 | -------------------------------------------------------------------------------- /packages/video_player/elinux/video_player_stream_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 7 | 8 | class VideoPlayerStreamHandler { 9 | public: 10 | VideoPlayerStreamHandler() = default; 11 | virtual ~VideoPlayerStreamHandler() = default; 12 | 13 | // Prevent copying. 14 | VideoPlayerStreamHandler(VideoPlayerStreamHandler const&) = delete; 15 | VideoPlayerStreamHandler& operator=(VideoPlayerStreamHandler const&) = delete; 16 | 17 | // Notifies the completion of initializing the video player. 18 | void OnNotifyInitialized() { OnNotifyInitializedInternal(); } 19 | 20 | // Notifies the completion of decoding a video frame. 21 | void OnNotifyFrameDecoded() { OnNotifyFrameDecodedInternal(); } 22 | 23 | // Notifies the completion of playing a video. 24 | void OnNotifyCompleted() { OnNotifyCompletedInternal(); } 25 | 26 | // Notifies update of playing or pausing a video. 27 | void OnNotifyPlaying(bool is_playing) { OnNotifyPlayingInternal(is_playing); } 28 | 29 | protected: 30 | virtual void OnNotifyInitializedInternal() = 0; 31 | virtual void OnNotifyFrameDecodedInternal() = 0; 32 | virtual void OnNotifyCompletedInternal() = 0; 33 | virtual void OnNotifyPlayingInternal(bool is_playing) = 0; 34 | }; 35 | 36 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 37 | -------------------------------------------------------------------------------- /packages/video_player/elinux/video_player_stream_handler_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 7 | 8 | #include 9 | 10 | #include "video_player_stream_handler.h" 11 | 12 | class VideoPlayerStreamHandlerImpl : public VideoPlayerStreamHandler { 13 | public: 14 | using OnNotifyInitialized = std::function; 15 | using OnNotifyFrameDecoded = std::function; 16 | using OnNotifyCompleted = std::function; 17 | using OnNotifyPlaying = std::function; 18 | 19 | VideoPlayerStreamHandlerImpl(OnNotifyInitialized on_notify_initialized, 20 | OnNotifyFrameDecoded on_notify_frame_decoded, 21 | OnNotifyCompleted on_notify_completed, 22 | OnNotifyPlaying on_notify_playing) 23 | : on_notify_initialized_(on_notify_initialized), 24 | on_notify_frame_decoded_(on_notify_frame_decoded), 25 | on_notify_completed_(on_notify_completed), 26 | on_notify_playing_(on_notify_playing) {} 27 | virtual ~VideoPlayerStreamHandlerImpl() = default; 28 | 29 | // Prevent copying. 30 | VideoPlayerStreamHandlerImpl(VideoPlayerStreamHandlerImpl const&) = delete; 31 | VideoPlayerStreamHandlerImpl& operator=(VideoPlayerStreamHandlerImpl const&) = 32 | delete; 33 | 34 | protected: 35 | // |VideoPlayerStreamHandler| 36 | void OnNotifyInitializedInternal() { 37 | if (on_notify_initialized_) { 38 | on_notify_initialized_(); 39 | } 40 | } 41 | 42 | // |VideoPlayerStreamHandler| 43 | void OnNotifyFrameDecodedInternal() { 44 | if (on_notify_frame_decoded_) { 45 | on_notify_frame_decoded_(); 46 | } 47 | } 48 | 49 | // |VideoPlayerStreamHandler| 50 | void OnNotifyCompletedInternal() { 51 | if (on_notify_completed_) { 52 | on_notify_completed_(); 53 | } 54 | } 55 | 56 | void OnNotifyPlayingInternal(bool is_playing) { 57 | if (on_notify_playing_) { 58 | on_notify_playing_(is_playing); 59 | } 60 | } 61 | 62 | OnNotifyInitialized on_notify_initialized_; 63 | OnNotifyFrameDecoded on_notify_frame_decoded_; 64 | OnNotifyCompleted on_notify_completed_; 65 | OnNotifyPlaying on_notify_playing_; 66 | }; 67 | 68 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 69 | -------------------------------------------------------------------------------- /packages/video_player/example/.gitignore: -------------------------------------------------------------------------------- 1 | lib/generated_plugin_registrant.dart 2 | -------------------------------------------------------------------------------- /packages/video_player/example/README.md: -------------------------------------------------------------------------------- 1 | # video_player_example 2 | 3 | Demonstrates how to use the video_player plugin. 4 | 5 | ## Getting Started 6 | 7 | For help getting started with Flutter for eLinux, view our online 8 | [documentation](https://github.com/sony/flutter-elinux/wiki). 9 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | video_player_elinux 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/elinux plugins/${plugin}) 13 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 16 | endforeach(plugin) 17 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | if(FLUTTER_TARGET_BACKEND_TYPE MATCHES "gbm") 5 | add_definitions(-DFLUTTER_TARGET_BACKEND_GBM) 6 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "eglstream") 7 | add_definitions(-DFLUTTER_TARGET_BACKEND_EGLSTREAM) 8 | elseif(FLUTTER_TARGET_BACKEND_TYPE MATCHES "x11") 9 | add_definitions(-DFLUTTER_TARGET_BACKEND_X11) 10 | else() 11 | add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) 12 | endif() 13 | 14 | add_executable(${BINARY_NAME} 15 | "flutter_window.cc" 16 | "main.cc" 17 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 18 | ) 19 | apply_standard_settings(${BINARY_NAME}) 20 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 21 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 22 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 23 | add_dependencies(${BINARY_NAME} flutter_assemble) 24 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/runner/flutter_window.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter_window.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/generated_plugin_registrant.h" 13 | 14 | FlutterWindow::FlutterWindow( 15 | const flutter::FlutterViewController::ViewProperties view_properties, 16 | const flutter::DartProject project) 17 | : view_properties_(view_properties), project_(project) {} 18 | 19 | bool FlutterWindow::OnCreate() { 20 | flutter_view_controller_ = std::make_unique( 21 | view_properties_, project_); 22 | 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_view_controller_->engine() || 25 | !flutter_view_controller_->view()) { 26 | return false; 27 | } 28 | 29 | // Register Flutter plugins. 30 | RegisterPlugins(flutter_view_controller_->engine()); 31 | 32 | return true; 33 | } 34 | 35 | void FlutterWindow::OnDestroy() { 36 | if (flutter_view_controller_) { 37 | flutter_view_controller_ = nullptr; 38 | } 39 | } 40 | 41 | void FlutterWindow::Run() { 42 | // Main loop. 43 | auto next_flutter_event_time = 44 | std::chrono::steady_clock::time_point::clock::now(); 45 | while (flutter_view_controller_->view()->DispatchEvent()) { 46 | // Wait until the next event. 47 | { 48 | auto wait_duration = 49 | std::max(std::chrono::nanoseconds(0), 50 | next_flutter_event_time - 51 | std::chrono::steady_clock::time_point::clock::now()); 52 | std::this_thread::sleep_for( 53 | std::chrono::duration_cast(wait_duration)); 54 | } 55 | 56 | // Processes any pending events in the Flutter engine, and returns the 57 | // number of nanoseconds until the next scheduled event (or max, if none). 58 | auto wait_duration = flutter_view_controller_->engine()->ProcessMessages(); 59 | { 60 | auto next_event_time = std::chrono::steady_clock::time_point::max(); 61 | if (wait_duration != std::chrono::nanoseconds::max()) { 62 | next_event_time = 63 | std::min(next_event_time, 64 | std::chrono::steady_clock::time_point::clock::now() + 65 | wait_duration); 66 | } else { 67 | // Wait for the next frame if no events. 68 | auto frame_rate = flutter_view_controller_->view()->GetFrameRate(); 69 | next_event_time = std::min( 70 | next_event_time, 71 | std::chrono::steady_clock::time_point::clock::now() + 72 | std::chrono::milliseconds( 73 | static_cast(std::trunc(1000000.0 / frame_rate)))); 74 | } 75 | next_flutter_event_time = 76 | std::max(next_flutter_event_time, next_event_time); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /packages/video_player/example/elinux/runner/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /packages/video_player/example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: video_player_example 2 | description: Demonstrates how to use the video_player plugin. 3 | publish_to: none 4 | 5 | environment: 6 | sdk: ">=2.18.0 <4.0.0" 7 | flutter: ">=3.3.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | video_player: ^2.6.1 13 | video_player_elinux: 14 | path: ../ 15 | 16 | dev_dependencies: 17 | pedantic: ^1.10.0 18 | test: any 19 | 20 | flutter: 21 | uses-material-design: true 22 | -------------------------------------------------------------------------------- /packages/video_player/lib/video_player_elinux.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Group Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | export 'src/elinux_video_player.dart'; 7 | -------------------------------------------------------------------------------- /packages/video_player/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: video_player_elinux 2 | description: Flutter plugin for displaying inline video with other Flutter widgets on Embedded Linux. 3 | version: 0.9.9 4 | homepage: https://github.com/sony/flutter-elinux-plugins 5 | repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/video_player 6 | 7 | environment: 8 | sdk: ">=2.18.0 <4.0.0" 9 | flutter: ">=3.7.0" 10 | 11 | dependencies: 12 | flutter: 13 | sdk: flutter 14 | video_player_platform_interface: ^6.2.1 15 | 16 | flutter: 17 | plugin: 18 | platforms: 19 | elinux: 20 | pluginClass: VideoPlayerElinuxPlugin 21 | dartPluginClass: ELinuxVideoPlayer 22 | --------------------------------------------------------------------------------