private void StartNativeRendering(int width, int height) { // Subscription is only used to ge the frame dimensions to generate the textures. So Unsubscribe once that is done. _source.I420AVideoFrameReady -= I420AVideoFrameReady; _i420aFrameQueue = null; CreateEmptyVideoTextures(width, height, 128); _nativeVideo = new NativeVideo(_source.NativeHandle); RegisterRemoteTextures(); }
private void TearDown() { try { _nativeVideo?.DisableRemoteVideo(); _nativeVideo?.Dispose(); } finally { _nativeVideo = null; } _source = null; }
private IEnumerator CallPluginAtEndOfFrames() { IntPtr videoUpdateMethod = NativeVideo.GetVideoUpdateMethod(); while (true) { // Wait until all frame rendering is done yield return(new WaitForEndOfFrame()); // No specific event ID needed, since we only handle one thing. if (_nativeVideoRenderersRefs.Count > 0) { GL.IssuePluginEvent(videoUpdateMethod, 0); } } }
/// <summary> /// Start rendering the passed source. /// </summary> /// <remarks> /// Can be used to handle <see cref="VideoTrackSource.VideoStreamStarted"/> or <see cref="VideoReceiver.VideoStreamStarted"/>. /// </remarks> public void StartRendering(IVideoSource source) { _source = source as RemoteVideoTrack; Debug.Assert(_source != null, "NativeVideoRender currently only supports RemoteVideoTack"); switch (source.FrameEncoding) { case VideoEncoding.I420A: _nativeVideo = new NativeVideo(_source.NativeHandle); _nativeVideo.TextureSizeChanged += TextureSizeChangeCallback; _nativeVideo.EnableRemoteVideo(VideoKind.I420, null); break; case VideoEncoding.Argb32: break; } }
public static void AddRef(MonoBehaviour nativeVideoRenderer) { Debug.Log("NativeRenderingPluginUpdate AddRef"); if (_nativeVideoRenderersRefs.Count == 0) { if (!_pluginInitialized) { _pluginInitialized = true; NativeVideo.SetLoggingFunctions( LogDebugCallback, LogErrorCallback, LogWarningCallback); } _owner = new GameObject("mrwebrtc-unityplugin"); _owner.AddComponent <NativeRenderingPluginUpdate>(); } _nativeVideoRenderersRefs.Add(nativeVideoRenderer); #if WEBRTC_DEBUGGING Debug.Log($"NativeRenderingPluginUpdate.AddRef: {_nativeVideoRenderersRefs.Count}"); #endif }