void ReleaseRenderTexture(object encoderLock)
        {
            if (_cameraOutputTexture != null)
            {
                _cameraOutputTexture.Release();
            }
            _cameraOutputTexture = null;

            if (_vidEnc != IntPtr.Zero && _vCfgEnc != IntPtr.Zero && _vTxfEnc != IntPtr.Zero &&
                _aCfgEnc != IntPtr.Zero && _audEnc != IntPtr.Zero)
            {
                IntPtr _vidEncCopy  = _vidEnc;
                IntPtr _vCfgEncCopy = _vCfgEnc;
                IntPtr _vTxfEncCopy = _vTxfEnc;
                IntPtr _aCfgEncCopy = _aCfgEnc;
                IntPtr _audEncCopy  = _audEnc;


                int msTimeout = 1000 / MixCastAV.chunksPerSec;

                new Thread(() =>
                {
                    lock (encoderLock)
                    {
                        Thread.Sleep(msTimeout);
                        //Debug.Log("Asynchronously cleaning up encoder: " + _encCopy.ToString());
                        MixCastAV.writeTrailerCloseStreams(_vidEncCopy);
                        MixCastAV.freeVideoCfg(_vCfgEncCopy);
                        MixCastAV.freeAudioEncodeContext(_audEncCopy);
                        MixCastAV.freeVideoTransform(_vTxfEncCopy);
                        MixCastAV.freeAudioCfg(_aCfgEncCopy);
                    }
                }).Start();
            }

            _vidEnc  = IntPtr.Zero;
            _vCfgEnc = IntPtr.Zero;
            _vTxfEnc = IntPtr.Zero;
            _aCfgEnc = IntPtr.Zero;
            _audEnc  = IntPtr.Zero;
        }
        private void _killDecoder()
        {
            bool resFreeDec = false;
            bool resFreeCfg = false;
            bool resFreeTxf = false;

            MixCastAV.ReleaseDecodeInterface(decoderInterface);
            System.Threading.Thread.Sleep(2);             //untested amount of sleep time in ms needed to avoid race condition


            //free the decoder
            if (vidDec != IntPtr.Zero)
            {
                resFreeDec = MixCastAV.freeDecodeContext(vidDec) == 0 ? true : false;
            }
            vidDec = IntPtr.Zero;

            //free the data config
            if (cfgVidDec != IntPtr.Zero)
            {
                resFreeCfg = MixCastAV.freeVideoCfg(cfgVidDec) == 0 ? true : false;
            }
            cfgVidDec = IntPtr.Zero;

            //free the transformer
            if (vidTxfDec != IntPtr.Zero)
            {
                resFreeTxf = MixCastAV.freeVideoTransform(vidTxfDec) == 0 ? true : false;
            }
            vidTxfDec = IntPtr.Zero;


            if (resFreeDec == false || resFreeCfg == false || resFreeTxf == false)
            {
                Debug.LogError("Error Freeing Device Feed. " + vidDec);
            }
        }