Example #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            // TODO: Validate input parameters.

            if (!_isOpen)
            {
                Open();
            }

            int bytesRead;

            if (offset == 0 && buffer.Length == count)
            {
                // Read directly into buffer.
                bytesRead = _libRtmpWrapper.Read(_rtmp, buffer, buffer.Length);
            }
            else
            {
                // Create intermediary buffer.
                var intermediaryBuffer = new byte[count];
                bytesRead = _libRtmpWrapper.Read(_rtmp, intermediaryBuffer, intermediaryBuffer.Length);

                // Copy to buffer.
                for (int i = 0; i < bytesRead; i++)
                {
                    buffer[offset + i] = intermediaryBuffer[i];
                }
            }

            if (bytesRead == 0)
            {
                _canRead = false;
            }
            else
            {
                _position += bytesRead;
            }

            if (!_durationFired)
            {
                var seconds           = _libRtmpWrapper.GetDuration(_rtmp);
                var durationEventArgs = new DurationEventArgs(TimeSpan.FromSeconds(seconds));
                OnDuration(durationEventArgs);

                _durationFired = true;
            }

            var rtmp = (LibRtmp.Rtmp)Marshal.PtrToStructure(_rtmp, typeof(LibRtmp.Rtmp));

            if (rtmp.m_read.timestamp != 0)
            {
                var elapsed = TimeSpan.FromMilliseconds(rtmp.m_read.timestamp);
                OnElapsed(new ElapsedEventArgs(elapsed, _position));
            }

            return(bytesRead);
        }
Example #2
0
        protected virtual void OnDuration(DurationEventArgs durationEventArgs)
        {
            if (durationEventArgs == null)
            {
                throw new ArgumentNullException("durationEventArgs");
            }

            var handler = Duration;

            if (handler != null)
            {
                handler(this, durationEventArgs);
            }
        }
Example #3
0
        protected virtual void OnDuration(DurationEventArgs durationEventArgs)
        {
            if (durationEventArgs == null) throw new ArgumentNullException("durationEventArgs");

            var handler = Duration;
            if (handler != null)
            {
                handler(this, durationEventArgs);
            }
        }
Example #4
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            // TODO: Validate input parameters.

            if (!_isOpen)
            {
                Open();
            }

            int bytesRead;
            if (offset == 0 && buffer.Length == count)
            {
                // Read directly into buffer.
                bytesRead = _libRtmpWrapper.Read(_rtmp, buffer, buffer.Length);
            }
            else
            {
                // Create intermediary buffer.
                var intermediaryBuffer = new byte[count];
                bytesRead = _libRtmpWrapper.Read(_rtmp, intermediaryBuffer, intermediaryBuffer.Length);

                // Copy to buffer.
                for (int i = 0; i < bytesRead; i++)
                {
                    buffer[offset + i] = intermediaryBuffer[i];
                }
            }

            if (bytesRead == 0)
            {
                _canRead = false;
            }
            else
            {
                _position += bytesRead;
            }

            if (!_durationFired)
            {
                var seconds = _libRtmpWrapper.GetDuration(_rtmp);
                var durationEventArgs = new DurationEventArgs(TimeSpan.FromSeconds(seconds));
                OnDuration(durationEventArgs);

                _durationFired = true;
            }

            var rtmp = (LibRtmp.Rtmp)Marshal.PtrToStructure(_rtmp, typeof(LibRtmp.Rtmp));
            if (rtmp.m_read.timestamp != 0)
            {
                var elapsed = TimeSpan.FromMilliseconds(rtmp.m_read.timestamp);
                OnElapsed(new ElapsedEventArgs(elapsed, _position));
            }

            return bytesRead;
        }