1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using Com.Tencent.Trtc;
- using System;
- using System.Collections.Concurrent;
- using System.Runtime.InteropServices;
- using Vinno.FIS.TRTCClient.Common.Log;
- using Vinno.FIS.TRTCClient.Common.Models;
- namespace Vinno.FIS.TRTCClient.Android
- {
- public class RemoteVideoRenderListener : Java.Lang.Object, TRTCCloudListener.ITRTCVideoRenderListener
- {
- private readonly Action<TRTCVideoFrameData> _callBack;
- private ConcurrentDictionary<string, TRTCVideoFrameData> _remoteFrameCaches;
- public RemoteVideoRenderListener(Action<TRTCVideoFrameData> callBack)
- {
- _remoteFrameCaches = new ConcurrentDictionary<string, TRTCVideoFrameData>();
- _callBack = callBack;
- }
- public void OnRenderVideoFrame(string userId, int streamType, TRTCCloudDef.TRTCVideoFrame frame)
- {
- try
- {
- if (!_remoteFrameCaches.ContainsKey(userId))
- {
- _remoteFrameCaches[userId] = new TRTCVideoFrameData(userId, frame.Width, frame.Height, new byte[frame.Height * frame.Width * 4]);
- }
- var remoteFrameCache = _remoteFrameCaches[userId];
- var height = frame.Height;
- var width = frame.Width;
- if (width != remoteFrameCache.Width || height != remoteFrameCache.Height)
- {
- remoteFrameCache.Width = width;
- remoteFrameCache.Height = height;
- remoteFrameCache.Data = new byte[height * width * 4];
- }
- Marshal.Copy(frame.Buffer.GetDirectBufferAddress(), remoteFrameCache.Data, 0, remoteFrameCache.Data.Length);
- _callBack?.Invoke(remoteFrameCache);
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Receive Remote Image Error:{ex}");
- }
- }
- }
- }
|