I have been trying to send video frames captured by unity plugin (UDesktopDuplication For Windows) using the agora engine for unity but I am only getting the gray screen on agora web platform. (The application I am working on is a Screen share app for windows using Agora engine)
I've been using CustomCaptureVideo.cs script to send the the frames captured via the plugin (this is a windows application) to agora server as you can see in the attached screenshot. The main issue is the texture sent by the plugin is in BGRA format and Agora expecting the texture in RGBA format. I've already tried to convert the texture received from the plugin in RGBA and vice versa for the agora PushVideoFrame() but nothing seems to work.
Can someone please tell me what am I doing wrong? Is their something wrong with my approach or their is another way-around to do this?
private IEnumerator ShareScreen()
{
yield return new WaitForEndOfFrame();
IRtcEngine rtc = Agora.Rtc.RtcEngine.Instance;
if (rtc != null)
{
#if UNITY_EDITOR_OSX
_texture.ReadPixels(_rect, 0, 0);
_texture.Apply();
#else
/* This line will fetch texture data from the UDD Plugin */
_texture = Manager.GetMonitor(displayIndex).texture;
#endif
#if UNITY_2018_1_OR_NEWER
NativeArray<byte> nativeByteArray = _texture.GetRawTextureData<byte>();
if (_shareData == null || _shareData.Length != nativeByteArray.Length)
{
_shareData = new byte[nativeByteArray.Length];
}
nativeByteArray.CopyTo(_shareData);
#else
_shareData = _texture.GetRawTextureData();
#endif
Debug.Log("Texture Format: " + _texture.format);
ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
externalVideoFrame.type = VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
externalVideoFrame.format = VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
// externalVideoFrame.format = VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_RGBA;
externalVideoFrame.buffer = _shareData;
#if UNITY_EDITOR_OSX
externalVideoFrame.stride = (int)_rect.width;
externalVideoFrame.height = (int)_rect.height;
#else
externalVideoFrame.stride = (int)_texture.width;
externalVideoFrame.height = (int)_texture.height;
#endif
externalVideoFrame.cropLeft = 10;
externalVideoFrame.cropTop = 10;
externalVideoFrame.cropRight = 10;
externalVideoFrame.cropBottom = 10;
externalVideoFrame.rotation = 180;
externalVideoFrame.timestamp = System.DateTime.Now.Ticks / 10000;
var ret = rtc.PushVideoFrame(externalVideoFrame, _videoTrack);
if (pushVideoFrame_Result != ret)
{
pushVideoFrame_Result = ret;
Debug.Log("PushVideoFrame ret = " + pushVideoFrame_Result + "time: " + System.DateTime.Now.Millisecond);
}
}
}