|
|
|
@ -15,7 +15,7 @@
|
|
|
|
|
TextureCamera::TextureCamera(TextureRegistrar *plugin, const CameraErrorHandler &onError) |
|
|
|
|
: m_plugin(plugin) |
|
|
|
|
, m_onError(onError) |
|
|
|
|
, m_variant(nullptr) |
|
|
|
|
, m_buffer(nullptr) |
|
|
|
|
, m_image(nullptr) |
|
|
|
|
, m_manager(StreamCameraManager()) |
|
|
|
|
{ |
|
|
|
@ -155,8 +155,28 @@ void TextureCamera::StopCapture()
|
|
|
|
|
std::map<Encodable, Encodable> TextureCamera::Register(std::string cameraName) |
|
|
|
|
{ |
|
|
|
|
m_textureId = m_plugin->RegisterTexture( |
|
|
|
|
[this]([[maybe_unused]] size_t width, [[maybe_unused]] size_t height) { |
|
|
|
|
return m_variant; |
|
|
|
|
[this]([[maybe_unused]] size_t width, [[maybe_unused]] size_t height, void* egl_display, void* egl_context) -> std::optional<TextureVariant> { |
|
|
|
|
if (m_buffer) { |
|
|
|
|
if (m_buffer->handleType == Aurora::StreamCamera::HandleType::EGL) { |
|
|
|
|
auto eglImage = TextureCameraEGLHelper::EGLCreateImage(m_buffer->handle, egl_display, egl_context); |
|
|
|
|
if (eglImage != EGL_NO_IMAGE_KHR) { |
|
|
|
|
return std::make_optional(TextureVariant(FlutterEGLImage{ |
|
|
|
|
eglImage, |
|
|
|
|
m_buffer->width, |
|
|
|
|
m_buffer->height, |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
m_image = TextureCameraPixelsHelper::YUVtoARGB(m_buffer->mapYCbCr()); |
|
|
|
|
auto pixels = static_cast<uint8_t *>(m_image->bits()); |
|
|
|
|
return std::make_optional(TextureVariant(FlutterPixelBuffer{ |
|
|
|
|
pixels, |
|
|
|
|
m_buffer->width, |
|
|
|
|
m_buffer->height, |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return std::nullopt; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (CreateCamera(cameraName) && m_viewWidth != 0 && m_viewHeight != 0) { |
|
|
|
@ -174,7 +194,7 @@ std::map<Encodable, Encodable> TextureCamera::Unregister()
|
|
|
|
|
m_textureId = 0; |
|
|
|
|
m_captureWidth = 0; |
|
|
|
|
m_captureHeight = 0; |
|
|
|
|
m_variant = nullptr; |
|
|
|
|
m_buffer = nullptr; |
|
|
|
|
m_camera = nullptr; |
|
|
|
|
|
|
|
|
|
m_plugin->UnregisterTexture(m_textureId); |
|
|
|
@ -184,24 +204,7 @@ std::map<Encodable, Encodable> TextureCamera::Unregister()
|
|
|
|
|
|
|
|
|
|
void TextureCamera::onCameraFrame(std::shared_ptr<Aurora::StreamCamera::GraphicBuffer> buffer) |
|
|
|
|
{ |
|
|
|
|
if (buffer->handleType == Aurora::StreamCamera::HandleType::EGL && false) { |
|
|
|
|
// @todo not tested
|
|
|
|
|
auto eglImage = TextureCameraEGLHelper::EGLCreateImage(buffer); |
|
|
|
|
m_variant = new TextureVariant(FlutterEGLImage{ |
|
|
|
|
eglImage, |
|
|
|
|
buffer->width, |
|
|
|
|
buffer->height, |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
m_image = TextureCameraPixelsHelper::YUVtoARGB(buffer->mapYCbCr()); |
|
|
|
|
auto pixels = static_cast<uint8_t *>(m_image->bits()); |
|
|
|
|
m_variant = new TextureVariant(FlutterPixelBuffer{ |
|
|
|
|
pixels, |
|
|
|
|
buffer->width, |
|
|
|
|
buffer->height, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_buffer = buffer; |
|
|
|
|
m_plugin->MarkTextureAvailable(m_textureId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|