public bool BufferFresh(int interfaceNumber) { if (MixCastAV.checkStartedAudioDecodeAsync(audAsyncDec) == 0) { int res = MixCastAV.isBufferFreshAudioDecodeAsync(audAsyncDec, interfaceNumber); if (res == -2) { Debug.LogError("The async audio decode interface buffer is not ready because it has not yet started."); } #if _DEBUG Debug.LogWarning(string.Format("Buffer Freshness: {0} - {1}", (res >= 0 ? "Yes" : "No"), interfaceNumber)); #endif return(res == 0 ? true : false); } else { return(false); } }
protected int EncodeWrite() { if (_audAsyncEncode == IntPtr.Zero || context == null || context.Data == null || _audAsyncDecodeCopy == IntPtr.Zero) { if (isShuttingDown) { return(-1); } Debug.LogError("Audio async encode interface is not yet initialized."); return(-1); } var feed = AudioAsyncFeed.Instance(context.Data.id); bool isFresh = false; //push the audio samples to the output muxer if ready if (feed != null && MixCastAV.checkStartedAudioEncodeAsync(_audAsyncEncode) == 0 && feed.isRunning == true && _audAsyncDecodeCopy != IntPtr.Zero) { //check if the audio stream started, if it hasn't then, return early if (MixCastAV.checkStartedAudioDecodeAsync(_audAsyncDecodeCopy) != 0) { return(-1); } isFresh = feed.BufferFresh(encodeInterfaceNumber); if (isFresh == true) { if (MixCastAV.updateBufferAudioEncodeAsync(_audAsyncEncode) < 0) { Debug.LogError("Error updating the audio async encode interface in pulling new data."); } } } else { if (isShuttingDown) { return(-1); } if (isFresh == false) { Debug.LogError("Error, the buffer was not fresh from the decoder audio async feed"); } else if (MixCastAV.checkStartedAudioEncodeAsync(_audAsyncEncode) != 0) { Debug.LogError("Error, the encoder was not yet started or had problems starting"); } //the buffer is not fresh from the audio decode async interface, may help to catch some weird bugs else if (IsOverAccessBuffer == true) { Debug.Log("Checked buffer, but the buffer from the decode async interface was not yet ready to encode. " + encodeInterfaceNumber); } IsOverAccessBuffer = true; return(-1); //since we are using a callback to write when ready, this is abnormal, if it happens often } IsOverAccessBuffer = false; return(0); }