コード例 #1
0
ファイル: RtmpStream.cs プロジェクト: JanRou/DrNuDownloader
        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);
        }
コード例 #2
0
ファイル: RtmpStream.cs プロジェクト: JanRou/DrNuDownloader
        protected virtual void OnDuration(DurationEventArgs durationEventArgs)
        {
            if (durationEventArgs == null)
            {
                throw new ArgumentNullException("durationEventArgs");
            }

            var handler = Duration;

            if (handler != null)
            {
                handler(this, durationEventArgs);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: JanRou/DrNuDownloader
        protected virtual void OnDuration(DurationEventArgs durationEventArgs)
        {
            if (durationEventArgs == null) throw new ArgumentNullException("durationEventArgs");

            var handler = Duration;
            if (handler != null)
            {
                handler(this, durationEventArgs);
            }
        }
コード例 #4
0
ファイル: RtmpStream.cs プロジェクト: JanRou/DrNuDownloader
        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;
        }