Esempio n. 1
0
        protected override void Dispose(bool disposing)
        {
            //Does nothing base.Dispose(disposing);

            //If disposing
            if (disposing)
            {
                IsDisposed = true;
                //Calls Close virtual (Calls Dispose(true) and GC.SuppressFinalize(this))
                //base.Dispose();

                //Clear memory
                Clear();

                m_Position = m_Cursor = -1;

                //Handled with free...
                if (false.Equals(IDisposedExtensions.IsNullOrDisposed(WorkingSegment)))
                {
                    BaseDisposable.SetShouldDispose(WorkingSegment, true, true);

                    WorkingSegment = null;
                }
            }
        }
Esempio n. 2
0
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose();

            if (IDisposedExtensions.IsNullOrDisposed(RtspClient).Equals(false))
            {
                RtspClient.OnConnect -= RtspClient_OnConnect;

                RtspClient.OnDisconnect -= RtspClient_OnDisconnect;

                RtspClient.OnPlay -= RtspClient_OnPlay;

                RtspClient.OnPause -= RtspClient_OnPausing;

                RtspClient.OnStop -= RtspClient_OnStop;

                RtspClient.Dispose();

                RtspClient = null;
            }
        }
Esempio n. 3
0
        protected internal override void Dispose(bool disposing)
        {
            if (false.Equals(disposing) || false.Equals(ShouldDispose))
            {
                return;
            }

            base.Dispose(ShouldDispose);

            if (false.Equals(IsDisposed))
            {
                return;
            }

            if (false.Equals(IDisposedExtensions.IsNullOrDisposed(First16Bits)))
            {
                //Dispose the instance
                First16Bits.Dispose();

                //Remove the reference to the CommonHeaderBits instance
                First16Bits = null;
            }

            if (false.Equals(IDisposedExtensions.IsNullOrDisposed(SegmentToLast6Bytes)))
            {
                //Invalidate the pointer
                SegmentToLast6Bytes.Dispose();

                SegmentToLast6Bytes = null;
            }

            //Remove the reference to the allocated array.
            Last6Bytes = null;
        }
Esempio n. 4
0
        public SegmentStream(IEnumerable <MemorySegment> existing)
        {
            //Create a new list.
            Segments = new System.Collections.Generic.List <MemorySegment>(existing);

            m_Count = Segments.Sum(s => IDisposedExtensions.IsNullOrDisposed(s) ? 0 : s.m_Length);
        }
Esempio n. 5
0
        /// <summary>
        /// Stops streaming from the source
        /// </summary>
        public override void Stop()
        {
            if (IsDisposed || State < StreamState.Started)
            {
                return;
            }

            if (IDisposedExtensions.IsNullOrDisposed(RtspClient).Equals(false))
            {
                if (RtspClient.IsPlaying)
                {
                    RtspClient.StopPlaying();
                }
                else if (RtspClient.IsConnected)
                {
                    RtspClient.Disconnect();
                }

                //Client Dispose
            }

            base.Stop();

            m_StartedTimeUtc = null;
        }
Esempio n. 6
0
        /// <summary>
        /// Disposes of any private data this instance utilized.
        /// </summary>
        protected internal override void Dispose(bool disposing)
        {
            if (false.Equals(disposing) || false.Equals(ShouldDispose))
            {
                return;
            }

            base.Dispose(ShouldDispose);

            if (false.Equals(IsDisposed))
            {
                return;
            }

            //If there is a referenced RtpHeader
            if (m_OwnsHeader && false.Equals(IDisposedExtensions.IsNullOrDisposed(Header)))
            {
                //Dispose it
                Header.Dispose();
            }

            if (false.Equals(IDisposedExtensions.IsNullOrDisposed(Payload)))
            {
                //Payload goes away when Disposing
                Payload.Dispose();

                Payload = null;
            }

            //The private data goes away after calling Dispose
            m_OwnedOctets = null;
        }
Esempio n. 7
0
        public void UpdatePushedMessages(RtspMessage request, RtspMessage response)
        {
            if (false.Equals(IDisposedExtensions.IsNullOrDisposed(request)) && false.Equals(IDisposedExtensions.IsNullOrDisposed(LastInboundRequest)))
            {
                LastInboundRequest.IsPersistent = false;

                LastInboundRequest.Dispose();
            }


            if (IDisposedExtensions.IsNullOrDisposed(LastInboundRequest = request).Equals(false))
            {
                LastInboundRequest.IsPersistent = true;
            }

            if (false.Equals(IDisposedExtensions.IsNullOrDisposed(LastInboundResponse)))
            {
                LastInboundResponse.IsPersistent = false;

                LastInboundResponse.Dispose();
            }

            if (IDisposedExtensions.IsNullOrDisposed(LastInboundResponse = response).Equals(false))
            {
                LastInboundResponse.IsPersistent = true;
            }
        }
Esempio n. 8
0
 public void Add(HttpContent content)
 {
     if (IDisposedExtensions.IsNullOrDisposed(content))
     {
         throw new ArgumentException("content cannot be null or disposed");
     }
     Contents.Add(content);
 }
Esempio n. 9
0
        public static void LogException(this ILogging log, System.Exception exception)
        {
            if (object.ReferenceEquals(exception, null) || IDisposedExtensions.IsNullOrDisposed(log))
            {
                return;
            }

            log.LogException(exception);
        }
Esempio n. 10
0
        public static void Log(this ILogging log, string message)
        {
            if (string.IsNullOrEmpty(message) || IDisposedExtensions.IsNullOrDisposed(log))
            {
                return;
            }

            log.Log(message);
        }
Esempio n. 11
0
        public RtspSource(string name, Uri source, bool perPacket, RtspClient client)
            : base(name, source, perPacket)
        {
            if (IDisposedExtensions.IsNullOrDisposed(client))
            {
                throw new ArgumentNullException("client");
            }

            RtspClient = client;
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="source"></param>
        /// <param name="client"></param>
        /// <param name="perPacket"></param>
        public RtpSource(string name, System.Uri source, Rtp.RtpClient client, bool perPacket = false)
            : this(name, source, perPacket)
        {
            if (IDisposedExtensions.IsNullOrDisposed(client))
            {
                throw new ExceptionExtensions.ArgumentNullOrDisposedException(client);
            }

            RtpClient = client;
        }
Esempio n. 13
0
        public void AddMemory(MemorySegment segment)
        {
            if (IDisposedExtensions.IsNullOrDisposed(segment))
            {
                segment = MemorySegment.Empty;
            }

            Segments.Add(segment);

            m_Count += segment.m_Length;
        }
Esempio n. 14
0
        public SegmentStream(IList <MemorySegment> existing)
        {
            if (existing == null)
            {
                throw new ArgumentNullException();
            }

            //Use the existing list
            Segments = existing;

            m_Count = Segments.Sum(s => IDisposedExtensions.IsNullOrDisposed(s) ? 0 : s.m_Length);
        }
Esempio n. 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sessionDescription"></param>
        public RtpSource(string name, Sdp.SessionDescription sessionDescription)
            : base(name, new System.Uri(string.Join(System.Uri.SchemeDelimiter, Rtp.RtpClient.RtpProtcolScheme, ((Sdp.Lines.SessionConnectionLine)sessionDescription.ConnectionLine).Host)))
        {
            if (IDisposedExtensions.IsNullOrDisposed(sessionDescription))
            {
                throw new ExceptionExtensions.ArgumentNullOrDisposedException("sessionDescription", sessionDescription);
            }

            RtpClient = Rtp.RtpClient.FromSessionDescription(SessionDescription = sessionDescription);

            RtpClient.FrameChangedEventsEnabled = PerPacket == false;
        }
Esempio n. 16
0
        //Should be extensions because it makes intellisense weird for all derived types.

        /// <summary>
        /// Throws an <see cref="ArgumentException"/> if the given header is null or disposed or does not have the given payloadType.
        /// </summary>
        /// <param name="payloadType"></param>
        /// <param name="header"></param>
        internal static void CheckHeaderAndPayloadType(ref int payloadType, RtcpHeader header)
        {
            if (IDisposedExtensions.IsNullOrDisposed(header))
            {
                throw new ArgumentException("header IsNullOrDisposed");
            }

            int headerPayloadType = header.PayloadType;

            if (headerPayloadType != payloadType)
            {
                throw new ArgumentException(string.Format("Header.PayloadType is not equal to the expected type of {0}, found {1}.", payloadType, headerPayloadType), "header");
            }
        }
Esempio n. 17
0
        public static void SetShouldDispose(BaseDisposable toDispose, bool value, bool callDispose = false)
        {
            if (IDisposedExtensions.IsNullOrDisposed(toDispose))
            {
                return;
            }

            toDispose.ShouldDispose = value;

            if (callDispose)
            {
                toDispose.Dispose();
            }
        }
Esempio n. 18
0
        public void InsertPersistedMemory(ref int index, MemorySegment toInsert)
        {
            if (IDisposedExtensions.IsNullOrDisposed(toInsert))
            {
                InsertMemory(ref index, (MemorySegment.Empty));

                return;
            }

            MemorySegment copy = new MemorySegment(toInsert.Count);

            System.Array.Copy(toInsert.m_Array, toInsert.m_Offset, copy.m_Array, 0, toInsert.m_Length);

            InsertMemory(ref index, copy);
        }
Esempio n. 19
0
        public override void Dispose()
        {
            if (IsDisposed || ShouldDispose.Equals(false))
            {
                return;
            }

            base.Dispose();

            if (IDisposedExtensions.IsNullOrDisposed(RtpClient).Equals(false))
            {
                RtpClient.Dispose();

                RtpClient = null;
            }
        }
Esempio n. 20
0
        public override void Stop()
        {
            if (State <= StreamState.StopRequested)
            {
                return;
            }

            //When the stream is not stared
            if (IDisposedExtensions.IsNullOrDisposed(RtpClient).Equals(false))
            {
                RtpClient.Deactivate();
            }

            //Indicate no longer ready.
            base.Ready = false;

            //Call stop which sets state
            base.Stop();
        }
Esempio n. 21
0
        public static TimeDescription GetTimeDescription(this MediaDescription mediaDescription, SessionDescription sessionDescription)
        {
            if (IDisposedExtensions.IsNullOrDisposed(mediaDescription) || IDisposedExtensions.IsNullOrDisposed(sessionDescription))
            {
                return(null);
            }

            //Get index of mediaDescription

            //Needs a better way to get the index of the media description
            int index = sessionDescription.GetIndexFor(mediaDescription);  //Array.IndexOf(sessionDescription.MediaDescriptions.ToArray(), mediaDescription);

            if (index == -1)
            {
                return(null);
            }

            return(sessionDescription.GetTimeDescription(index));
        }
Esempio n. 22
0
        public void AddPersistedMemory(MemorySegment segment)
        {
            //Allow dead space...
            if (IDisposedExtensions.IsNullOrDisposed(segment))
            {
                AddMemory(MemorySegment.Empty);

                return;
            }

            //Could avoid LOH allocation by splitting blocks..
            //Would need additional state, seems like a job for a dervied class, BlockSegmentStream...
            MemorySegment copy = new MemorySegment(segment.m_Length, false); //Don't dispose unless forced

            //Copy the data
            System.Array.Copy(segment.m_Array, segment.m_Offset, copy.m_Array, 0, segment.m_Length);

            //Add it.
            AddMemory(copy);
        }
Esempio n. 23
0
        public MemorySegment(MemorySegment other, bool force = false, bool shouldDispose = true)
            : base(shouldDispose)
        {
            //If there is no other instance return
            if (IDisposedExtensions.IsNullOrDisposed(other))
            {
                return;
            }

            //If the finalizer has ran
            if (false.Equals(other.IsUndisposed))
            {
                //If this allocation was not contrived
                if (false.Equals(force))
                {
                    m_Array = EmptyBytes;

                    m_Length = m_Offset = 0;

                    //Dispose immediately
                    Dispose(true);

                    //Do nothing else
                    return;
                }

                //Reregister for finalize the other instance
                if (other.IsFinalized)
                {
                    GC.ReRegisterForFinalize(other);
                }
            }

            m_Array = other.Array;

            m_Offset = other.m_Offset;

            m_Length = other.m_Length;

            //ByteOrder = other.ByteOrder;
        }
Esempio n. 24
0
        public void InsertMemory(ref int index, MemorySegment toInsert)
        {
            if (IDisposedExtensions.IsNullOrDisposed(toInsert))
            {
                toInsert = MemorySegment.Empty;
            }

            Segments.Insert(index, toInsert);

            //Should be optional to update the position
            //m_Postion should be offset also if the segment being inserted is at an index <= m_Index;
            if (index <= m_Index)
            {
                m_Position += toInsert.m_Length;

                ++m_Index;
            }

            //Update the count;
            m_Count += toInsert.m_Length;
        }
Esempio n. 25
0
        //Stop recoding a stream
        public virtual void Stop(IMedia stream)
        {
            if (stream is RtpSource)
            {
                Program program;

                if (false == Attached.TryGetValue(stream, out program))
                {
                    return;
                }

                if (program != null && false == IDisposedExtensions.IsNullOrDisposed(program.Writer))
                {
                    program.Writer.Dispose();
                }

                Attached.Remove(stream);

                (stream as RtpSource).RtpClient.RtpPacketReceieved  -= RtpClientPacketReceieved;
                (stream as RtpSource).RtpClient.RtcpPacketReceieved -= RtpClientPacketReceieved;
            }
        }
Esempio n. 26
0
        public void ApplyCachingPolocy(NodeAction n, bool combine = false, bool eraseCache = true)
        {
            if (n == null)
            {
                throw new ArgumentNullException("n");
            }

            IDisposedExtensions.CheckDisposed(this as IDisposed);

            if (combine)
            {
                m_NodeCachingPolicy += n;
            }
            else
            {
                m_NodeCachingPolicy = n;
            }

            if (eraseCache)
            {
                if (m_NodeCache != null)
                {
                    m_NodeCache.Clear();
                }
                else if (n != null && m_NodeCache == null)
                {
                    m_NodeCache = new SortedDictionary <long, Node>();
                }
                else if (n == null && m_NodeCache != null)
                {
                    m_NodeCache.Clear();

                    m_NodeCache = null;
                }
            }
        }
Esempio n. 27
0
        //Should have a date when or should return the date playable, which would then be used by another method to compare against a time.
        public static bool IsPlayable(this MediaDescription mediaDescription, SessionDescription sessionDescription) //, DateTime? check = null) ,TimeSpan within = TimeSpan.Zero
        {
            if (IDisposedExtensions.IsNullOrDisposed(mediaDescription) || IDisposedExtensions.IsNullOrDisposed(sessionDescription))
            {
                return(false);
            }

            //Get index of mediaDesription

            //Check TimeDescription @ index.

            TimeDescription td = GetTimeDescription(mediaDescription, sessionDescription);

            //Assume true
            if (IDisposedExtensions.IsNullOrDisposed(td))
            {
                return(true);
            }

            //Unbound start and end ?
            if (td.IsPermanent)
            {
                return(true);
            }

            //Notes multiple calls to UtcNow... (avoid with a within parameter)?
            try
            {
                //Ensure not a bounded end and that the end time is less than now
                if (false.Equals(td.StopTime.Equals(0))
                    &&
                    td.NtpStopDateTime >= DateTime.UtcNow)
                {
                    return(false);
                }

                //Ensure start time is not bounded and that the start time is greater than now
                if (false.Equals(td.StartTime.Equals(0))
                    &&
                    td.NtpStartDateTime > DateTime.UtcNow)
                {
                    return(false);
                }

                //Check repeat times.

                //td.RepeatTimes;
            }
            catch
            {
                //Out of range values for conversion, assume true if end is unbounded
                if (false.Equals(td.StopTime.Equals(0)))
                {
                    return(false);
                }
            }
            finally
            {
                td = null;
            }

            return(true);
        }
Esempio n. 28
0
        /// <summary>
        /// Provides the logic for cloning a RtpPacket instance.
        /// The RtpPacket class does not have a Copy Constructor because of the variations in which a RtpPacket can be cloned.
        /// </summary>
        /// <param name="includeSourceList">Indicates if the SourceList should be copied.</param>
        /// <param name="includeExtension">Indicates if the Extension should be copied.</param>
        /// <param name="includePadding">Indicates if the Padding should be copied.</param>
        /// <param name="selfReference">Indicates if the new instance should reference the data contained in this instance.</param>
        /// <returns>The RtpPacket cloned as result of calling this function</returns>
        public RtpPacket Clone(bool includeSourceList, bool includeExtension, bool includePadding, bool includePayloadData, bool selfReference, bool shouldDispose = true)
        {
            //If the sourcelist and extensions are to be included and selfReference is true then return the new instance using the a reference to the data already contained.
            if (includeSourceList && includeExtension && includePadding && includePayloadData)
            {
                return selfReference ? new RtpPacket(Header, Payload, shouldDispose)
                       {
                           Transferred = Transferred
                       }
            }
            : new RtpPacket(Prepare().ToArray(), 0, Length, shouldDispose)
            {
                Transferred = Transferred
            };

            IEnumerable <byte> binarySequence = MemorySegment.EmptyBytes;

            bool hasSourceList = ContributingSourceCount > 0;

            //If the source list is included then include it.
            if (includeSourceList && hasSourceList)
            {
                RFC3550.SourceList sourceList = GetSourceList();

                if (false.Equals(IDisposedExtensions.IsNullOrDisposed(sourceList)))
                {
                    binarySequence = sourceList.GetBinaryEnumerable();
                }
                else
                {
                    binarySequence = MemorySegment.EmptyBytes;
                }
            }

            //Determine if the clone should have extenison
            bool hasExtension = Header.Extension;

            //If there is a header extension to be included in the clone
            if (hasExtension && includeExtension)
            {
                //Get the Extension
                using (RtpExtension extension = GetExtension())
                {
                    //If an extension could be obtained include it
                    if (false.Equals(IDisposedExtensions.IsNullOrDisposed(extension)))
                    {
                        binarySequence = binarySequence.Concat(extension);
                    }
                }
            }

            //if the video data is required in the clone then include it
            if (includePayloadData)
            {
                binarySequence = binarySequence.Concat(PayloadData);                     //Add the binary data to the packet except any padding
            }
            //Determine if padding is present
            bool hasPadding = Header.Padding;

            //if padding is to be included in the clone then obtain the original padding directly from the packet
            if (hasPadding && includePadding)
            {
                binarySequence = binarySequence.Concat(Payload.Array.Skip(Payload.Offset + Payload.Count - PaddingOctets));                               //If just the padding is required the skip the Coefficients
            }
            //Return the result of creating the new instance with the given binary
            return(new RtpPacket(new RtpHeader(Header.Version, includePadding && hasPadding, includeExtension && hasExtension)
            {
                Timestamp = Header.Timestamp,
                SequenceNumber = Header.SequenceNumber,
                SynchronizationSourceIdentifier = Header.SynchronizationSourceIdentifier,
                PayloadType = Header.PayloadType,
                ContributingSourceCount = includeSourceList ? Header.ContributingSourceCount : 0
            }.Concat(binarySequence).ToArray(), 0, shouldDispose)
            {
                Transferred = Transferred
            });
        }
Esempio n. 29
0
        /// <summary>
        /// Disposes <see cref="LastRequest"/> and <see cref="LastResponse"/>.
        /// Removes any references stored in the instance.
        /// </summary>
        protected internal override void Dispose(bool disposing)
        {
            if (false == disposing || false == ShouldDispose)
            {
                return;
            }

            base.Dispose(ShouldDispose);

            //If there is a LastRequest
            if (LastRequest != null)
            {
                //It is no longer persistent
                using (LastRequest) LastRequest.IsPersistent = false;

                //It is no longer scoped.
                LastRequest = null;
            }

            //If there is a LastResponse
            if (LastResponse != null)
            {
                //It is no longer persistent
                using (LastResponse) LastResponse.IsPersistent = false;

                //It is no longer scoped.
                LastResponse = null;
            }

            //If there is a SessionDescription
            if (IDisposedExtensions.IsNullOrDisposed(SessionDescription).Equals(false))
            {
                //Call dispose
                SessionDescription.Dispose();

                //Remove the reference
                SessionDescription = null;
            }

            //If there is a MediaDescription
            //if (MediaDescription != null)
            //{
            //    //Call dispose
            //    //MediaDescription.Dispose();

            //    //Remove the reference
            //    MediaDescription = null;
            //}

            //If there is a Context
            if (Context != null)
            {
                //Call dispose
                //Context.Dispose();

                //Remove the reference
                Context = null;
            }

            TransportHeader = null;
        }
Esempio n. 30
0
 System.Collections.Generic.IEnumerable <System.Threading.Thread> IThreadReference.GetReferencedThreads()
 {
     return(IDisposedExtensions.IsNullOrDisposed(RtpClient) ? null : LinqExtensions.Yield(RtpClient.m_WorkerThread));
 }