bool SendStreamSample(IStreamSource source, MediaStreamDescription mediaStreamDescription, bool canCallReportBufferingProgress)
        {
            _taskScheduler.ThrowIfNotOnThread();

            var packet = source.GetNextSample();

            if (null == packet)
            {
                if (source.IsEof)
                    return SendLastStreamSample(mediaStreamDescription);

                if (canCallReportBufferingProgress)
                {
                    var progress = source.BufferingProgress;

                    if (progress.HasValue)
                    {
                        if (Math.Abs(_bufferingProgress - progress.Value) < 0.05)
                            return false;

                        Debug.WriteLine("Sample {0} buffering {1:F2}%", mediaStreamDescription.Type, progress * 100);

                        _bufferingProgress = progress.Value;

                        ValidateEvent(MediaStreamFsm.MediaEvent.CallingReportSampleCompleted);
                        ReportGetSampleProgress(progress.Value);
                    }
                    else
                    {
                        Debug.WriteLine("Sample {0} not buffering", mediaStreamDescription.Type);

                        // Try again, data might have arrived between the last call to GetNextSample() and
                        // when we checked the buffering progress.
                        packet = source.GetNextSample();
                    }
                }

                if (null == packet)
                    return false;
            }

            _bufferingProgress = -1;

            try
            {
                _pesStream.Packet = packet;

                var sample = new MediaStreamSample(mediaStreamDescription, _pesStream, 0, packet.Length,
                    packet.PresentationTimestamp.Ticks, NoMediaSampleAttributes);

                //Debug.WriteLine("Sample {0} at {1}", sample.MediaStreamDescription.Type, TimeSpan.FromTicks(sample.Timestamp));

                ValidateEvent(MediaStreamFsm.MediaEvent.CallingReportSampleCompleted);
                ReportGetSampleCompleted(sample);
            }
            finally
            {
                _pesStream.Packet = null;

                source.FreeSample(packet);
            }

            return true;
        }
Exemple #2
0
        private bool SendStreamSample(IStreamSource source, MediaStreamDescription mediaStreamDescription, bool canCallReportBufferingProgress)
        {
            this._taskScheduler.ThrowIfNotOnThread();
            TsPesPacket nextSample = source.GetNextSample();

            if (null == nextSample)
            {
                if (source.IsEof)
                {
                    return(this.SendLastStreamSample(mediaStreamDescription));
                }
                if (canCallReportBufferingProgress)
                {
                    float?bufferingProgress = source.BufferingProgress;
                    if (bufferingProgress.HasValue)
                    {
                        if ((double)Math.Abs(this._bufferingProgress - bufferingProgress.Value) < 0.05)
                        {
                            return(false);
                        }
                        string   format    = "Sample {0} buffering {1:F2}%";
                        object[] objArray1 = new object[2]
                        {
                            (object)mediaStreamDescription.Type,
                            null
                        };
                        object[] objArray2 = objArray1;
                        int      index     = 1;
                        float?   nullable  = bufferingProgress;
                        // ISSUE: variable of a boxed type
                        var local = (ValueType)(nullable.HasValue ? new float?(nullable.GetValueOrDefault() * 100f) : new float?());
                        objArray2[index] = (object)local;
                        object[] objArray3 = objArray1;
                        Debug.WriteLine(format, objArray3);
                        this._bufferingProgress = bufferingProgress.Value;
                        this.ValidateEvent(MediaStreamFsm.MediaEvent.CallingReportSampleCompleted);
                        this.ReportGetSampleProgress((double)bufferingProgress.Value);
                    }
                    else
                    {
                        Debug.WriteLine("Sample {0} not buffering", (object)mediaStreamDescription.Type);
                        nextSample = source.GetNextSample();
                    }
                }
                if (null == nextSample)
                {
                    return(false);
                }
            }
            this._bufferingProgress = -1f;
            try
            {
                this._pesStream.Packet = nextSample;
                MediaStreamSample mediaStreamSample = new MediaStreamSample(mediaStreamDescription, (Stream)this._pesStream, 0L, (long)nextSample.Length, nextSample.PresentationTimestamp.Ticks, (IDictionary <MediaSampleAttributeKeys, string>)TsMediaStreamSource.NoMediaSampleAttributes);
                this.ValidateEvent(MediaStreamFsm.MediaEvent.CallingReportSampleCompleted);
                this.ReportGetSampleCompleted(mediaStreamSample);
            }
            finally
            {
                this._pesStream.Packet = (TsPesPacket)null;
                source.FreeSample(nextSample);
            }
            return(true);
        }