コード例 #1
0
        public void RequestSample(/*IUnknown*/ IntPtr pToken)
        {
            CheckShutdown();
            if (!IsActive || (!MediaSource.IsPlaying && !MediaSource.IsPaused))
            {
                throw new SharpDXException(ResultCode.InvalidRequest);
            }
            //Trace.WriteLine($"RtspMediaStream<{Type}>::RequestSample()");

            try {
                _requestQueue.Enqueue(ComObjectUtils.Attach(pToken));
                if (!_sampleQueue.IsEmpty)
                {
                    DeliverSamples();
                }
                _isSampleQueueEmpty.OnNext(_sampleQueue.IsEmpty);
                //if(Type == StreamType.Video) {
                //    Debug.WriteLine($"RtspMediaStream<{Type}>::RequestSample(): SampleQueue={_sampleQueue.Count} RequestQueue={_requestQueue.Count}");
                //}
            } catch (Exception ex) {
                if (!MediaSource.IsShutdown)
                {
                    _eventGenerator.QueueEventParamErr(ex.HResult);
                }
                Debug.WriteLine($"RtspMediaStream<{Type}>::RequestSample(): Error={ex.Message}");
                throw;
            }
        }
コード例 #2
0
        public void Start(/*IMFPresentationDescriptor*/ IntPtr pPresentationDescriptor, ref Guid pguidTimeFormat, ref Variant pvarStartPosition)
        {
            CheckShutdown();
            Trace.WriteLine("RtspMediaSource::Start()");
            if (!IsStopped && !IsPaused)
            {
                throw new SharpDXException(ResultCode.InvalidStateTransition);
            }
            if (pguidTimeFormat != null && pguidTimeFormat != Guid.Empty)
            {
                throw new SharpDXException(ResultCode.UnsupportedTimeFormat);
            }

            if (pPresentationDescriptor == IntPtr.Zero)
            {
                throw new ArgumentNullException();
            }
            var pd = ComObjectUtils.AttachAs <PresentationDescriptor>(pPresentationDescriptor);

            try {
                // Get stream selection
                var selection = new bool[_streams.Length];
                for (var i = 0; i < pd.StreamDescriptorCount; i++)
                {
                    RawBool isSelected;
                    var     sdesc = pd.GetStreamDescriptorByIndex(i, out isSelected);
                    var     id    = sdesc.StreamIdentifier;
                    switch (id)
                    {
                    case (int)RtspMediaStream.StreamType.Video:
                    case (int)RtspMediaStream.StreamType.Audio:
                        selection[id] = isSelected;
                        break;

                    default:
                        throw new ArgumentException();
                    }
                }
                // Activate selected stream
                for (var i = 0; i < selection.Length; i++)
                {
                    if (selection[i])
                    {
                        using (var comStream = new ComObject(_streams[i])) {
                            if (_streams[i].IsActive)
                            {
                                // stream updated
                                _eventGenerator.QueueEventParamUnk(MediaEventTypes.UpdatedStream, Guid.Empty, Result.Ok, comStream);
                            }
                            else
                            {
                                // new stream started
                                _streams[i].Activate();
                                _eventGenerator.QueueEventParamUnk(MediaEventTypes.NewStream, Guid.Empty, Result.Ok, comStream);
                            }
                        }
                    }
                    else
                    {
                        _streams[i].Deactivate();
                    }
                }

                // Ignore pvarStartPosition
                _bufferingStartedSent = false;
                ChangeState(SourceState.Playing);
                _eventGenerator.QueueEventParamVar(MediaEventTypes.SourceStarted, Guid.Empty, Result.Ok, new Variant {
                    Value = 0L
                });
            } catch (Exception ex) {
                if (!IsShutdown)
                {
                    _eventGenerator.QueueEventParamErr(ex.HResult);
                }
                throw;
            } finally {
                pd?.Dispose();
            }
        }