Пример #1
0
        public override void Close()
        {
            if (!_isOpen)
            {
                return;
            }

            base.Close();

            if (_rtmp != IntPtr.Zero)
            {
                _libRtmpWrapper.Close(_rtmp);
                _libRtmpWrapper.Free(_rtmp);
            }

            // TODO: Check that InitSockets() was called successfully.
            LogStubWrapper.CleanupSockets();

            _isOpen  = false;
            _canRead = false;
        }
Пример #2
0
        public void Open()
        {
            _libRtmpWrapper.LogSetLevel((int)LogLevel.All); // TODO: Investigate if flags can be used.
            var logCallback = new LogCallback((level, message) =>
            {
                switch (level)
                {
                case LogLevel.Critical:
                case LogLevel.Error:
                    throw new IOException(message);
                }
            });

            LogStubWrapper.SetLogCallback(logCallback);

            _rtmp = _libRtmpWrapper.Alloc();
            if (_rtmp == IntPtr.Zero)
            {
                throw new IOException("Unable to open RTMPStream.");
            }

            _libRtmpWrapper.Init(_rtmp);
            _libRtmpWrapper.SetupUrl(_rtmp, Marshal.StringToHGlobalAnsi(_uriData.ToUri()));

            LogStubWrapper.InitSockets();
            if (_libRtmpWrapper.Connect(_rtmp, IntPtr.Zero) == 0)
            {
                throw new IOException("Failed to establish RTMP connection.");
            }

            if (_libRtmpWrapper.ConnectStream(_rtmp, 0) == 0)
            {
                throw new IOException("Failed to establish RTMP session.");
            }

            _isOpen = true;
        }