Ejemplo n.º 1
0
        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);
        }