Added external camera feed from external plugin on Android

This commit is contained in:
maxime.chambefort
2024-03-17 20:44:47 +01:00
committed by maxime.chambefort
parent db66bd35af
commit 6f846eb5c5
21 changed files with 350 additions and 15 deletions

View File

@@ -50,6 +50,8 @@ void CameraFeed::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_rgb_image", "rgb_image"), &CameraFeed::set_rgb_image);
ClassDB::bind_method(D_METHOD("set_ycbcr_image", "ycbcr_image"), &CameraFeed::set_ycbcr_image);
ClassDB::bind_method(D_METHOD("set_external", "width", "height"), &CameraFeed::set_external);
ClassDB::bind_method(D_METHOD("get_texture_tex_id", "feed_image_type"), &CameraFeed::get_texture_tex_id);
ClassDB::bind_method(D_METHOD("get_datatype"), &CameraFeed::get_datatype);
@@ -68,6 +70,7 @@ void CameraFeed::_bind_methods() {
BIND_ENUM_CONSTANT(FEED_RGB);
BIND_ENUM_CONSTANT(FEED_YCBCR);
BIND_ENUM_CONSTANT(FEED_YCBCR_SEP);
BIND_ENUM_CONSTANT(FEED_EXTERNAL);
BIND_ENUM_CONSTANT(FEED_UNSPECIFIED);
BIND_ENUM_CONSTANT(FEED_FRONT);
@@ -137,6 +140,10 @@ RID CameraFeed::get_texture(CameraServer::FeedImage p_which) {
return texture[p_which];
}
uint64_t CameraFeed::get_texture_tex_id(CameraServer::FeedImage p_which) {
return RenderingServer::get_singleton()->texture_get_native_handle(texture[p_which]);
}
CameraFeed::CameraFeed() {
// initialize our feed
id = CameraServer::get_singleton()->get_free_id();
@@ -252,6 +259,19 @@ void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p
}
}
void CameraFeed::set_external(int p_width, int p_height) {
if ((base_width != p_width) || (base_height != p_height)) {
// We're assuming here that our camera image doesn't change around formats etc, allocate the whole lot...
base_width = p_width;
base_height = p_height;
auto new_texture = RenderingServer::get_singleton()->texture_external_create(p_width, p_height, 0);
RenderingServer::get_singleton()->texture_replace(texture[CameraServer::FEED_YCBCR_IMAGE], new_texture);
}
datatype = CameraFeed::FEED_EXTERNAL;
}
bool CameraFeed::activate_feed() {
// nothing to do here
return true;