Hi guys Is there any way to convert Godot's PoolByteArray to a type that can converted or cast to a uint8_t* pointer?
I'm trying to add some NDI functionality to Godot via gdnative script C++ plugin. NDI is a protocol for sending video and audio over a network. Basically I want to take whatever you see in the viewport and send it via NDI to any NDI device on the network.
Using the NDI SDK it requires you to send it frames as a uint8_t* but Godot outputs image data as a PoolByteArray.
Now I'm able to copy the PoolByteArray by copying each element of the array one by one using a loop.
e.g
uint8_t* frame_data = (uint8_t*)malloc(1920*1080*4); //used by NDI in another function
//this function is called by on the gdscript end where image_data is the result of vieworpt.get_texture().get_data().get_data()
void NDI::set_video_data(PoolByteArray image_data)
{
int size = image_data.size();
for (int i = 0; i < size; i++)
{
frame_data[i] = image_data[i];
}
}
This works but naturally it's incredibly slow. Having to copy 8,294,400 elements per frame for a 1920 1080 4 image. Where the 4 is the number of bytes use to represent each pixel in RGBA color format.
My knowledge of C++ is rather limited. Is there any way I could do this conversion better?
I'd love to hear and ideas on this thanks.