Exemplo n.º 1
0
 public void UpdateRtpFrame(RtpFrame frame)
 {
     if (_media != null && _media.State == SourceMedia.StreamState.Started)
     {
         _media.AddFrame(frame);
     }
 }
Exemplo n.º 2
0
 protected void Client_RtpFrameChanged(object sender, RtpFrame rtpFrame)
 {
     if (rtpFrame.PayloadTypeByte == 96)
     {
         Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame h264 =
             new Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame(rtpFrame);
         h264.Depacketize(rtpFrame);
         System.IO.MemoryStream memory = h264.Buffer;
         byte[] data = memory.ToArray();
     //    if (data == null || data.Length <= 0)
     //    {
     //        return;
     //    }
     //    if (IsIFrame)
     //    {
     //        if (data[4] == 103)
     //        {
     //            IsIFrame = false;
     //            WriteData.Write(data, 0, data.Length);
     //            return;
     //        }
     //    }
     //    WriteData.Write(data, 0, data.Length);
     //    WriteData.Flush(true);
         string str = Bytes10To16(data);
         if (string.IsNullOrEmpty(str))
         {
             return;
         }
         textBox1.AppendText(str + "\n");
     }
 }
Exemplo n.º 3
0
 protected void Client_RtpFrameChanged(object sender, RtpFrame rtpFrame)
 {
     if (rtpFrame.PayloadTypeByte == 96)
     {
         Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame h264 =
             new Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame(rtpFrame);
         h264.Depacketize(rtpFrame);
         System.IO.MemoryStream memory = h264.Buffer;
         byte[] data = memory.ToArray();
         //    if (data == null || data.Length <= 0)
         //    {
         //        return;
         //    }
         //    if (IsIFrame)
         //    {
         //        if (data[4] == 103)
         //        {
         //            IsIFrame = false;
         //            WriteData.Write(data, 0, data.Length);
         //            return;
         //        }
         //    }
         //    WriteData.Write(data, 0, data.Length);
         //    WriteData.Flush(true);
         string str = Bytes10To16(data);
         if (string.IsNullOrEmpty(str))
         {
             return;
         }
         textBox1.AppendText(str + "\n");
     }
 }
Exemplo n.º 4
0
 private void Client_RtpFrameChanged(object sender, RtpFrame frame)
 //private void Client_RtpFrameChanged(object sender, RtpFrame frame, RtpClient.TransportContext tc, bool final)
 {///基于RTP的H264视频数据打包解包类 http://blog.csdn.net/dengzikun/article/details/5807694
     //Console.WriteLine($"RtpFrameChanged : {frame.IsComplete}, {frame.Count},{frame.Timestamp}, {frame.Created}");
     if (frame.IsComplete && frame.PayloadTypeByte == 96)
     {
         _buffers.Enqueue(frame.Select(_ => _.PayloadData.ToArray()).ToList());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a frame using the specified payloadType.
        /// </summary>
        /// <param name="payloadType"></param>
        /// <param name="frame"></param>
        public void Add(int payloadType, RtpFrame frame)
        {
            if (Common.IDisposedExtensions.IsNullOrDisposed(frame))
            {
                return;
            }

            Frames.Add(payloadType, frame);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the given packet to the contained frames and provides the frame which was added to.
        /// </summary>
        /// <param name="payloadType">The payloadType to use for the add operation</param>
        /// <param name="packet">The packet to add</param>
        /// <param name="addedTo">The frame which the packet was added to.</param>
        /// <returns>True if <paramref name="addedTo"/> is complete (it is no longer contained), otherwise false.</returns>
        public bool Add(int payloadType, bool allowDuplicatePackets, bool allowPacketsAfterMarker, RtpPacket packet, out RtpFrame addedTo)
        {
            addedTo = null;

            if (Common.IDisposedExtensions.IsNullOrDisposed(packet))
            {
                return(false);
            }

            System.Collections.Generic.IList <RtpFrame> framesList;

            //Use the given payloadType to get frames
            if (Frames.TryGetValueList(ref payloadType, out framesList))
            {
                //loop the frames found
                foreach (RtpFrame frame in framesList)
                {
                    //if the timestamp is eqaul try to add the packet
                    if (frame.Timestamp == packet.Timestamp)
                    {
                        //Try to add the packet and if added return.
                        if (frame.TryAdd(packet, allowDuplicatePackets, allowPacketsAfterMarker))
                        {
                            addedTo = frame;

                            //If the add results in completion
                            if (frame.IsComplete)
                            {
                                //Remove the frame
                                framesList.Remove(frame);

                                //Return true
                                return(true);
                            }
                        }
                    }
                }

                //Must add a new frame to frames.
                addedTo = new RtpFrame(packet);

                if (addedTo.IsComplete)
                {
                    return(true);
                }

                Frames.Add(ref payloadType, ref addedTo);
            }

            return(false);
        }
Exemplo n.º 7
0
        private void Client_RtpFrameChanged(object sender, RtpFrame frame)
        {
            if (frame.IsComplete && frame.PayloadTypeByte == 96)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.Write(_startCode, 0, _startCode.Length);

                    bool haveData = false;
                    foreach (RtpPacket packet in frame)
                    {
                        haveData |= writeH264PacketData(ms, packet);
                    }

                    if (haveData)
                    {
                        fireVideoDataEvent(ms.ToArray());
                    }
                }
            }
        }
Exemplo n.º 8
0
 private void onRtpFrame(RtpFrame frame, CCTVFrameType frameType)
 {
     _rtspServer?.UpdateRtpFrame(frame);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds the given frame using the PayloadType specified by the frame.
 /// </summary>
 /// <param name="frame"></param>
 public void Add(RtpFrame frame)
 {
     Add(frame.PayloadType, frame);
 }
Exemplo n.º 10
0
 void OnSourceFrameChanged(object sender, RtpFrame frame)
 {
     if (frame != null && false == frame.IsDisposed /*&& frame.IsComplete*/) foreach (var packet in frame) OnSourceRtpPacketRecieved(sender, packet);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Selects a TransportContext for a RtpPacket by matching the packet's PayloadType to the TransportContext's MediaDescription.MediaFormat
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 public TransportContext GetContextForFrame(RtpFrame frame)
 {
     if (frame == null) return null; return GetContextByPayloadType(frame.PayloadTypeByte);
 }
Exemplo n.º 12
0
 public void EnqueFrame(RtpFrame frame)
 {
     if (frame == null || frame.IsDisposed) return; foreach (RtpPacket packet in frame) EnquePacket(packet);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Raises the RtpFrameHandler for the given frame if FrameEvents are enabled
        /// </summary>
        /// <param name="frame">The frame to raise the RtpFrameHandler with</param>
        internal void OnRtpFrameChanged(RtpFrame frame)
        {
            if (IsDisposed || false == FrameChangedEventsEnabled) return;

            RtpFrameHandler action = RtpFrameChanged;

            if (action == null) return;

            foreach (RtpFrameHandler handler in action.GetInvocationList())
            {
                try { handler(this, frame); }
                catch { continue; }
            }
        }
Exemplo n.º 14
0
 protected internal virtual void HandleFrameChange(object /*RtpClient*/ sender, RtpFrame frame)
 {
     ////TransportContext context = GetContextByPayloadType(frame.PayloadTypeByte);
     //////If there is a context
     ////if (context == null) return;
 }
Exemplo n.º 15
0
 public void SendRtpFrame(RtpFrame frame, int? ssrc = null)
 {
     SocketError error;
     SendRtpFrame(frame, out error, ssrc);
 }
Exemplo n.º 16
0
 public void SendRtpFrame(RtpFrame frame, out SocketError error, int? ssrc = null)
 {
     error = SocketError.SocketError; if (frame == null || frame.IsDisposed) return; foreach (RtpPacket packet in frame) SendRtpPacket(packet, out error, ssrc);
 }