public void Close() { _enableBackground = false; _backgroundEncoder?.Wait(); _backgroundEncoder = null; VpxDllCall.EncodeClose(); _srcTexture = null; }
public void Setup(int width, int hight, int bitrate, int useCpu, Texture srcTexture) { this.Width = Mathf.Min(Screen.width, width); this.Hight = Mathf.Min(Screen.height, hight); VpxDllCall.EncodeSetup(this.Width, this.Hight, bitrate, useCpu); _srcTexture = null; // 出力 this.WriteBuffer(); _enableBackground = true; _updateState = UpState.Non; _srcTexture = srcTexture; _backgroundEncoder = Task.Run(BackGroundEncode); }
public event Action <IntPtr, int> OnEncoded = null; // エンコード時 private void WriteBuffer() { while (true) { int size = 0; var ptr = VpxDllCall.EncodeGetData(ref size); if (ptr == IntPtr.Zero) { break; } if (size == 0) { break; } this.OnEncoded?.Invoke(ptr, size); } }
// フレームバッファを変換して任意のバッファに保存 private bool Encode() { try { this.ImgId++; var gcH = GCHandle.Alloc(_pixBuffer, GCHandleType.Pinned); // var size = _pixBuffer.Length * Marshal.SizeOf(typeof(Color32)); var size = _pixBufferSize * Marshal.SizeOf(typeof(Color32)); VpxDllCall.EncodeSetFrameYUV(gcH.AddrOfPinnedObject(), size, this.Width, 0, this.ImgId); gcH.Free(); } catch (Exception e) { Debug.LogError($"error : {e.Message}"); } this.WriteBuffer(); return(true); // 更新あり }