|
|
|
@ -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 ®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<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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|