Exemple #1
0
        private void RegisterOutputAvailableCallback()
        {
            _outputBufferAvailableCb = (packetHandle, _) =>
            {
                if (_outputAvailable == null)
                {
                    Interop.MediaPacket.Destroy(packetHandle);
                    return;
                }

                OutputAvailableEventArgs args = null;
                try
                {
                    args = new OutputAvailableEventArgs(packetHandle);
                }
                catch (Exception e)
                {
                    Interop.MediaPacket.Destroy(packetHandle);

                    MultimediaLog.Error(typeof(MediaCodec).FullName, "Failed to raise OutputAvailable event", e);
                }

                if (args != null)
                {
                    _outputAvailable?.Invoke(this, args);
                }
            };

            int ret = Interop.MediaCodec.SetOutputBufferAvailableCb(_handle, _outputBufferAvailableCb);

            MultimediaDebug.AssertNoError(ret);
        }
Exemple #2
0
        private void RegisterOutputAvailableCallback()
        {
            _outputBufferAvailableCb = (packetHandle, _) =>
            {
                if (_outputAvailable == null)
                {
                    try
                    {
                        Native.Destroy(packetHandle).ThrowIfFailed("Failed to destroy packet.");
                    }
                    catch (Exception)
                    {
                        // Do not throw exception in pinvoke callback.
                    }

                    return;
                }

                OutputAvailableEventArgs args = null;
                try
                {
                    args = new OutputAvailableEventArgs(packetHandle);
                }
                catch (Exception e)
                {
                    try
                    {
                        Native.Destroy(packetHandle).ThrowIfFailed("Failed to destroy packet.");
                    }
                    catch
                    {
                        // Do not throw exception in pinvoke callback.
                    }

                    MultimediaLog.Error(typeof(MediaCodec).FullName, "Failed to raise OutputAvailable event", e);
                }

                if (args != null)
                {
                    _outputAvailable?.Invoke(this, args);
                }
            };

            Native.SetOutputBufferAvailableCb(_handle, _outputBufferAvailableCb).
            ThrowIfFailed("Failed to set output buffer available callback.");
        }