示例#1
0
 private void _ups_Unpacked(object arg1, Nalu arg2)
 {
     if (_decoder == null)
     {
         _decoder = new VideoDecoder();
         var codicId = Constants.AVCodecID.AV_CODEC_ID_H264;
         _decoder.Create(codicId);
     }
     if (arg2.Header.Type == 7 || arg2.Header.Type == 8)
     {
         _decoder.Decode(arg2.BytesWithStartCode(), out _curWidth, out _curHeight);
     }
     else
     {
         byte[] frameData = _decoder.Decode(arg2.BytesWithStartCode(), out _curWidth, out _curHeight);
         if (frameData != null)
         {
             if (_curWidth != _width || _curHeight != _height)
             {
                 _width  = _curWidth;
                 _height = _curHeight;
                 _renderSource.SetupSurface(_curWidth, _curHeight);
             }
             renderFrame(frameData);
         }
     }
 }
示例#2
0
 private void testReceive(RTP_Packet packet)
 {
     _nlist.Add(Nalu.Parse(packet.Data));
     if (packet.IsMarker)
     {
         buildFrame();
         _nlist = new List <Nalu>();
     }
 }
示例#3
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);

            // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
            Nalu.SkipToEndOfNALU(bitReader);

            Nalu.CheckSize(bitReader);
        }
示例#4
0
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader);                          // read-in the NALU
            Header.Read(bitReader);
            SliceID = bitReader.DecodeUnsignedExpGolomb(); // this is not in base class
            Data.Read(bitReader);

            // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
            Nalu.SkipToEndOfNALU(bitReader);

            Nalu.CheckSize(bitReader);
        }
示例#5
0
 public void Update(Nalu nal)
 {
     if (nal.Header.Type == NaluTypes.SPS)
     {
         _spsStamp = Environment.TickCount;
         _sps      = nal;
     }
     else if (nal.Header.Type == NaluTypes.PPS)
     {
         _ppsStamp = Environment.TickCount;
         _pps      = nal;
     }
 }
        public override void Read(BitReader bitReader)
        {
            base.Read(bitReader); // read-in the NALU

            // NOTE: this coded slice has no Header (it should remain null)
            SliceID = bitReader.DecodeUnsignedExpGolomb();
            if (_pps.RedundantPICCountPresentFlag)
            {
                RedundantPictureCount = bitReader.DecodeUnsignedExpGolomb();
            }
            Data.Read(bitReader);

            // FIXME: SliceData above is not complete, so for now let's just skip the rest of data
            Nalu.SkipToEndOfNALU(bitReader);

            Nalu.CheckSize(bitReader);
        }
示例#7
0
 private void buildFrame()
 {
     using (MemoryStream ms = new MemoryStream())
     {
         bool isFirst = true;
         for (int i = 0; i < _nlist.Count; i++)
         {
             Nalu nal = _nlist[i];
             if (nal.Header.Type < 13)
             {
                 _ups_Unpacked(null, nal);
             }
             else
             {
                 //由于我们自己的RTP服务只使用FU_A封包方式发送数据,因此,此处示例我们只解析此封包方式。
                 if (nal.Header.Type == NaluTypes.FU_A)
                 {
                     FragUnitA fua = FragUnitA.Parse(nal.NaluBytes());
                     ////是接收序列的首包,但不是分片的首包,说明接收数据有丢失,无法正常解析。
                     //if (isFirst && !fua.Header.IsStart)
                     //    return;
                     ////是接收序列的末包,但不是分片的末包,说明接收数据有丢失,无法正常解析。
                     //if (i == _nlist.Count - 1 && !fua.Header.IsEnd)
                     //    return;
                     if (isFirst)
                     {
                         Nalu temp = new Nalu(new NaluHeader(false, fua.Indicator.NRI, fua.Header.Type), fua.Payload);
                         ms.Write(temp.NaluBytes(), 0, temp.TotalBytes);
                         isFirst = false;
                     }
                     else
                     {
                         ms.Write(fua.Payload, 0, fua.PayloadLen);
                     }
                 }
             }
         }
         if (ms.Length > 0)
         {
             _ups_Unpacked(null, Nalu.Parse(ms.ToArray()));
         }
     }
 }
示例#8
0
 public virtual void Read(BitReader bitReader)
 {
     Nalu.Read(bitReader);
 }