Browse Source

[texture] Add stream camera

embedder_texture
Vitaliy Zarubin 1 year ago
parent
commit
e6e3352e7f
  1. 2
      example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop
  2. 1
      example/aurora/rpm/ru.auroraos.flutter_example_packages.spec
  3. 3
      packages/embedder_texture/aurora/CMakeLists.txt
  4. 98
      packages/embedder_texture/aurora/embedder_texture_plugin.cpp
  5. 4
      packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h

2
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

1
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}.

3
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)

98
packages/embedder_texture/aurora/embedder_texture_plugin.cpp

@ -6,6 +6,38 @@
#include <flutter/method-channel.h>
#include <flutter/platform-methods.h>
#include <functional>
typedef std::function<void(Aurora::StreamCamera::GraphicBuffer *buffer)> 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<Aurora::StreamCamera::GraphicBuffer> buffer) override
{
std::cout << "onCameraFrame" << std::endl;
m_callback(buffer.get());
}
private:
ListenerHandler m_callback;
};
void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
TextureRegistrar *plugin = registrar.GetRegisterTexture();
@ -15,15 +47,18 @@ void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
[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<Aurora::StreamCamera::CameraCapability> 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<AuroraCameraListener>([=](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);
}

4
packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h

@ -6,6 +6,7 @@
#define EMBEDDER_TEXTURE_PLUGIN_H
#include <flutter/plugin-interface.h>
#include <streamcamera/streamcamera.h>
#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 */

Loading…
Cancel
Save