You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.5 KiB
93 lines
2.5 KiB
/** |
|
* SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru> |
|
* SPDX-License-Identifier: BSD-3-Clause |
|
*/ |
|
#include <embedder_texture/camera.h> |
|
#include <embedder_texture/camera_egl_helper.h> |
|
#include <embedder_texture/camera_pixels_helper.h> |
|
|
|
Camera::Camera(TextureRegistrar *plugin) |
|
: m_plugin(plugin) |
|
, m_manager(StreamCameraManager()) |
|
{ |
|
CameraEGLHelper::EGLInit(); |
|
} |
|
|
|
void Camera::InitializeCamera(int cameraID) |
|
{ |
|
if (m_cameraId != cameraID && m_manager->getNumberOfCameras()) { |
|
Aurora::StreamCamera::CameraInfo info; |
|
|
|
if (m_manager->getCameraInfo(cameraID, info)) { |
|
m_cameraId = cameraID; |
|
m_camera = m_manager->openCamera(info.id); |
|
m_camera->setListener(this); |
|
} |
|
} |
|
} |
|
|
|
void Camera::StartCapture() |
|
{ |
|
if (m_camera) { |
|
Aurora::StreamCamera::CameraInfo info; |
|
|
|
if (m_camera->getInfo(info)) { |
|
std::vector<Aurora::StreamCamera::CameraCapability> caps; |
|
|
|
if (m_manager->queryCapabilities(info.id, caps)) { |
|
m_camera->startCapture(caps.at(1)); |
|
} |
|
} |
|
} |
|
} |
|
|
|
void Camera::StopCapture() |
|
{ |
|
if (m_camera) { |
|
m_cameraId = -1; |
|
m_buffer = nullptr; |
|
m_camera->stopCapture(); |
|
} |
|
} |
|
|
|
int64_t Camera::Register(int cameraID) |
|
{ |
|
m_textureId = m_plugin->RegisterTexture( |
|
[this](size_t width, size_t height) { return this->m_buffer; }); |
|
|
|
InitializeCamera(cameraID); |
|
StartCapture(); |
|
|
|
return m_textureId; |
|
} |
|
|
|
void Camera::Unregister() |
|
{ |
|
StopCapture(); |
|
m_plugin->UnregisterTexture(m_textureId); |
|
} |
|
|
|
void Camera::onCameraFrame(std::shared_ptr<Aurora::StreamCamera::GraphicBuffer> buffer) |
|
{ |
|
if (buffer->handleType == Aurora::StreamCamera::HandleType::EGL) { |
|
// @todo Not tested. The device needs to be completed. |
|
auto eglImage = CameraEGLHelper::EGLCreateImage(buffer); |
|
this->m_buffer = new TextureVariant(FlutterEGLImage{eglImage}); |
|
} else { |
|
auto pixels = CameraPixelsHelper::YUVtoARGB(buffer->mapYCbCr()); |
|
this->m_buffer = new TextureVariant(FlutterPixelBuffer{pixels}); |
|
} |
|
|
|
m_plugin->MarkTextureAvailable(m_textureId); |
|
} |
|
|
|
void Camera::onCameraError(const std::string &errorDescription) |
|
{ |
|
std::cout << "onCameraError" << std::endl; |
|
} |
|
|
|
void Camera::onCameraParameterChanged(Aurora::StreamCamera::CameraParameter parameter, |
|
const std::string &value) |
|
{ |
|
std::cout << "onCameraParameterChanged" << std::endl; |
|
}
|
|
|