/// <summary>
 /// Starts or resumes the clock.
 /// </summary>
 public void Play()
 {
     using (Locker.AcquireWriterLock())
     {
         if (Chrono.IsRunning)
         {
             return;
         }
         Chrono.Start();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///     Sets a new position value atomically.
 /// </summary>
 /// <param name="value">The new value that the position porperty will hold.</param>
 public void Update(TimeSpan value)
 {
     using (_locker.AcquireWriterLock())
     {
         var resume = _chrono.IsRunning;
         _chrono.Reset();
         _offsetTicks = value.Ticks;
         if (resume)
         {
             _chrono.Start();
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Tries the acquire a writer lock on the unmanaged buffer.
 /// Returns false if the buffer has been disposed.
 /// </summary>
 /// <param name="locker">The locker.</param>
 /// <returns>The disposable lock</returns>
 public bool TryAcquireWriterLock(out IDisposable locker)
 {
     locker = null;
     lock (SyncLock)
     {
         if (m_IsDisposed)
         {
             return(false);
         }
         locker = Locker.AcquireWriterLock();
         return(true);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="alsoManaged"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool alsoManaged)
        {
            lock (SyncLock)
            {
                if (m_IsDisposed)
                {
                    return;
                }

                if (alsoManaged)
                {
                    // Dispose managed state (managed objects).
                }

                // Free unmanaged resources (unmanaged objects) and override a finalizer below.
                using (Locker.AcquireWriterLock())
                {
                    Deallocate();
                }

                // set large fields to null.
                Locker.Dispose();
                Locker       = null;
                m_IsDisposed = true;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets or sets the <see cref="AVPacket"/> at the specified index.
 /// </summary>
 /// <value>
 /// The <see cref="AVPacket"/>.
 /// </value>
 /// <param name="index">The index.</param>
 /// <returns>The packet reference</returns>
 private AVPacket *this[int index]
 {
     get
     {
         using (Locker.AcquireReaderLock())
         {
             return((AVPacket *)PacketPointers[index]);
         }
     }
     set
     {
         using (Locker.AcquireWriterLock())
         {
             PacketPointers[index] = (IntPtr)value;
         }
     }
 }
        /// <summary>
        /// Skips the specified amount requested bytes to be read.
        /// </summary>
        /// <param name="requestedBytes">The requested bytes.</param>
        /// <exception cref="InvalidOperationException">When requested bytes GT readable count</exception>
        public void Skip(int requestedBytes)
        {
            using (Locker.AcquireWriterLock())
            {
                if (requestedBytes > m_ReadableCount)
                {
                    throw new InvalidOperationException(
                              $"Unable to skip {requestedBytes} bytes. Only {m_ReadableCount} bytes are available for skipping");
                }

                m_ReadIndex     += requestedBytes;
                m_ReadableCount -= requestedBytes;

                if (m_ReadIndex >= m_Length)
                {
                    m_ReadIndex = 0;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            using (Locker.AcquireWriterLock())
            {
                while (PoolBlocks.Count > 0)
                {
                    var block = PoolBlocks.Dequeue();
                    block.Dispose();
                }

                for (var i = PlaybackBlocks.Count - 1; i >= 0; i--)
                {
                    var block = PlaybackBlocks[i];
                    PlaybackBlocks.RemoveAt(i);
                    block.Dispose();
                }
            }

            Locker.Dispose();
            Locker = null;
        }