From e6e3352e7f25b6d1f88bbdf6578d57fa8a5341a4 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Tue, 24 Oct 2023 10:26:27 +0300 Subject: [PATCH] [texture] Add stream camera --- ....auroraos.flutter_example_packages.desktop | 2 +- .../ru.auroraos.flutter_example_packages.spec | 1 + .../embedder_texture/aurora/CMakeLists.txt | 3 +- .../aurora/embedder_texture_plugin.cpp | 98 +++++++++++++++++-- .../embedder_texture_plugin.h | 4 +- 5 files changed, 95 insertions(+), 13 deletions(-) diff --git a/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop b/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop index 1aa1d2b..bbeda1c 100644 --- a/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop +++ b/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop @@ -7,6 +7,6 @@ Exec=/usr/bin/ru.auroraos.flutter_example_packages X-Nemo-Application-Type=silica-qt5 [X-Application] -Permissions=DeviceInfo;UserDirs +Permissions=DeviceInfo;UserDirs;Camera OrganizationName=ru.auroraos ApplicationName=flutter_example_packages diff --git a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec index 2c965f8..11da8fa 100644 --- a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec +++ b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.zst BuildRequires: cmake BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(flutter-embedder) +BuildRequires: pkgconfig(streamcamera) %description %{summary}. diff --git a/packages/embedder_texture/aurora/CMakeLists.txt b/packages/embedder_texture/aurora/CMakeLists.txt index 4a322ae..d543439 100644 --- a/packages/embedder_texture/aurora/CMakeLists.txt +++ b/packages/embedder_texture/aurora/CMakeLists.txt @@ -17,13 +17,14 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") find_package(PkgConfig REQUIRED) pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) pkg_check_modules(GLES REQUIRED IMPORTED_TARGET glesv2) +pkg_check_modules(SC REQUIRED IMPORTED_TARGET streamcamera) add_library(${PLUGIN_NAME} SHARED embedder_texture_plugin.cpp ) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) -target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder PkgConfig::GLES) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder PkgConfig::GLES PkgConfig::SC) target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp index 3f22718..0b533fd 100644 --- a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp +++ b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp @@ -6,6 +6,38 @@ #include #include +#include + +typedef std::function ListenerHandler; + +class AuroraCameraListener : public Aurora::StreamCamera::CameraListener +{ + +public: + AuroraCameraListener(const ListenerHandler &callback) : m_callback(callback) { + std::cout << "constructor" << std::endl; + }; + + void onCameraError(const std::string &errorDescription) override { + std::cout << "onCameraFrame: " << errorDescription << std::endl; + } + + void onCameraParameterChanged(Aurora::StreamCamera::CameraParameter, const std::string &value) override { + std::cout << "onCameraFrame: " << value << std::endl; + } + + void onCameraFrame(std::shared_ptr buffer) override + { + std::cout << "onCameraFrame" << std::endl; + + m_callback(buffer.get()); + } + +private: + ListenerHandler m_callback; + +}; + void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) { TextureRegistrar *plugin = registrar.GetRegisterTexture(); @@ -15,15 +47,18 @@ void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) [this, plugin](const MethodCall &call) { this->onMethodCall(call, plugin); }); } -FlutterPixelBuffer EmbedderTexturePlugin::getBuffer() { - uint8_t pixels[] = - { - 1, 0, 0, - 0, 1, 0, - 0, 0, 1, - }; - return FlutterPixelBuffer { pixels }; -} +// FlutterPixelBuffer EmbedderTexturePlugin::getBuffer() { +// uint8_t pixels[] = +// { +// 1, 0, 0, +// 0, 1, 0, +// 0, 0, 1, +// }; + +// std::cout << logger::detail::thin("[" + std::string(tag) + "] ") << message << std::endl; + +// return FlutterPixelBuffer { pixels }; +// } void EmbedderTexturePlugin::onMethodCall(const MethodCall &call, TextureRegistrar *plugin) { const auto &method = call.GetMethod(); @@ -45,9 +80,52 @@ void EmbedderTexturePlugin::onCreate(const MethodCall &call, TextureRegistrar *p { auto textureId = plugin->RegisterTexture(TextureType::Pixels, [this](size_t width, size_t height) { - return TextureVariant(this->getBuffer()); + + std::cout << "get callback" << std::endl; + + return TextureVariant(this->m_buffer); }); + Aurora::StreamCamera::CameraManager *manager = StreamCameraManager(); + + if (manager->getNumberOfCameras()) + { + Aurora::StreamCamera::CameraInfo info; + + if (manager->getCameraInfo(1, info)) + { + std::vector caps; + + if (manager->queryCapabilities(info.id, caps)) + { + const Aurora::StreamCamera::CameraCapability cap = caps.at(1); + + auto camera = manager->openCamera(info.id); + + auto listener = std::make_unique([=](Aurora::StreamCamera::GraphicBuffer *buffer) { + + uint8_t pixels[] = + { + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + }; + + m_buffer = FlutterPixelBuffer { pixels }; + + std::cout << "MarkTextureAvailable" << std::endl; + + plugin->MarkTextureAvailable(textureId); + }); + + camera->setListener(listener.get()); + + std::cout << info.id << std::endl; + std::cout << camera->startCapture(cap) << std::endl; + } + } + } + call.SendSuccessResponse(textureId); } diff --git a/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h b/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h index eada95c..f4c5f09 100644 --- a/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h +++ b/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h @@ -6,6 +6,7 @@ #define EMBEDDER_TEXTURE_PLUGIN_H #include +#include #ifdef PLUGIN_IMPL #define PLUGIN_EXPORT __attribute__((visibility("default"))) @@ -23,7 +24,8 @@ private: void onCreate(const MethodCall &call, TextureRegistrar *plugin); void onRemove(const MethodCall &call, TextureRegistrar *plugin); void unimplemented(const MethodCall &call); - FlutterPixelBuffer getBuffer(); + + FlutterPixelBuffer m_buffer; }; #endif /* EMBEDDER_TEXTURE_PLUGIN_H */