/// <summary>
        /// Provides a byte buffer of the next sample in the internal FIFO (thread-safe)
        /// </summary>
        /// <returns>byte[].Lenth may =0 if called when internal queue is empty</returns>
        public VideoSample DequeueNextSample()
        {
            //int c;
            //lock(outBuffers)
            //{
            //    c = outBuffers.Count;
            //}
            //Task.Run(() => Debug.WriteLine("buffers ready count: " + c));


            PacketizedElementaryStream pes = DequeueNextPacket();



            byte[] buf    = new byte[0];//empty array
            var    sample = new VideoSample();

            if (pes != null)
            {
                buf = pes.GetPayload();

                if (pes.HasPts)
                {
                    sample.PresentationTimeStamp = pes.PTS;
                }
            }

            sample.Buffer = buf;

            return(sample);
        }
Exemple #2
0
        private PacketizedElementaryStream DequeueNextPacket()
        {
            PacketizedElementaryStream pes = null;

            outBuffers.TryDequeue(out pes);

            return(pes);
        }
        public PacketizedElementaryStream DequeueNextPacket()
        {
            PacketizedElementaryStream pes = null;

            lock (outBuffers)
            {
                if (outBuffers.Count > 0)
                {
                    pes         = outBuffers.Dequeue();
                    SampleCount = outBuffers.Count;
                }
            }

            return(pes);
        }
Exemple #4
0
        /// <summary>
        /// Provides a byte buffer of the next sample in the internal FIFO (thread-safe)
        /// </summary>
        /// <returns>byte[].Lenth may =0 if called when internal queue is empty</returns>
        public VideoSample DequeueNextSample()
        {
            PacketizedElementaryStream pes = DequeueNextPacket();

            var sample = new VideoSample();

            byte[] buff = null;

            bool gotPayload = false;

            if (pes != null)
            {
                buff       = GetLargeBuffer(pes.EstimateBufferSize());
                gotPayload = pes.GetPayload(buff);

                if (!gotPayload)
                {
                    ReturnLargeBuffer(buff);
                }

                if (pes.HasPts)
                {
                    sample.PresentationTimeStamp = pes.PTS;
                }

                //this is now handled in pes.Dispose() !
                //// reclaim buffers
                //if (usePool)
                //{
                //    lock (bufferPool)
                //    {
                //        var returnedBuffers = pes.GetBuffers();

                //        foreach (var buffer in returnedBuffers)
                //            bufferPool.Push(buffer);
                //    }
                //}
            }

            sample.Buffer = gotPayload ? buff : null;

            return(sample);
        }
Exemple #5
0
        /// <summary>
        /// Write the next sample to an output stream.<para/>
        /// the returned <see cref="VideoSample.Length"/> = # of bytes writen to outStream
        /// </summary>
        /// <param name="outStream"></param>
        /// <returns><see cref="VideoSample.Length"/> = # of bytes writen to outStream</returns>
        private VideoSample DequeueNextSample(System.IO.Stream outStream)
        {
            VideoSample sample             = null;
            PacketizedElementaryStream pes = DequeueNextPacket();

            if (pes != null)
            {
                sample = new VideoSample();
                //long cursor = outStream.Position;

                //pes.WriteToStream(outStream);

                if (pes.HasPts)
                {
                    sample.PresentationTimeStamp = pes.PTS;
                }


                sample.Pes = pes;// (int)(outStream.Position - cursor);
            }

            return(sample);
        }
Exemple #6
0
 internal void RecyclePES(PacketizedElementaryStream pes)
 {
     RecycleSmallBuffer(pes.packets);
     pes.packets.Clear();
 }