コード例 #1
0
 public bool Init(byte[] pSPS, byte[] pPPS)
 {
     Clear();
     _SPSInfo = Variant.Get();
     _PPSInfo = Variant.Get();
     if (pSPS.Length == 0 || pSPS.Length > 65535 || pPPS.Length == 0 || pPPS.Length > 65535)
     {
         Logger.FATAL("Invalid SPS/PPS lengths");
         return false;
     }
     SPS = pSPS;
     PPS = pPPS;
     Rate = 90000;
     var ms = new MemoryStream(SpsLength-1);
     for (ushort i = 1; i < pSPS.Length; i++)
     {
         if (i + 2 < pSPS.Length - 1 && SPS[i] == 0 && SPS[i + 1] == 0 && SPS[i + 2] == 3)
         {
             ms.WriteByte(0);
             ms.WriteByte(0);
             i += 2;
         }
         else
         {
             ms.WriteByte(SPS[i]);
         }
     }
     ms.Position = 0;
     using (var spsReader = new BitReader(ms))
     {
         if (!ReadSPS(spsReader, _SPSInfo))
         {
             Logger.WARN("Unable to parse SPS");
         }
         else
         {
             _SPSInfo.Compact();
             Width = ((uint)_SPSInfo["pic_width_in_mbs_minus1"] + 1) * 16;
             Height = ((uint)_SPSInfo["pic_height_in_map_units_minus1"] + 1) * 16;
             //		FINEST("_width: %u (%u); _height: %u (%u)",
             //				_width, (uint32_t) _SPSInfo["pic_width_in_mbs_minus1"],
             //				_height, (uint32_t) _SPSInfo["pic_height_in_map_units_minus1"]);
         }
     }
     ms = new MemoryStream(PpsLength-1);
     for (ushort i = 1; i < pPPS.Length; i++)
     {
         if (i + 2 < pPPS.Length - 1 && PPS[i] == 0 && PPS[i + 1] == 0 && PPS[i + 2] == 3)
         {
             ms.WriteByte(0);
             ms.WriteByte(0);
             i += 2;
         }
         else
         {
             ms.WriteByte(PPS[i]);
         }
     }
     ms.Position = 0;
     using (var ppsReader = new BitReader(ms))
     {
         if (!ReadPPS(ppsReader, _PPSInfo))
         {
             Logger.WARN("Unable to read PPS info");
         }
     }
     return true;
 }
コード例 #2
0
        public bool Init(byte[] pSPS, byte[] pPPS)
        {
            Clear();
            _SPSInfo = Variant.Get();
            _PPSInfo = Variant.Get();
            if (pSPS.Length == 0 || pSPS.Length > 65535 || pPPS.Length == 0 || pPPS.Length > 65535)
            {
                Logger.FATAL("Invalid SPS/PPS lengths");
                return(false);
            }
            SPS  = pSPS;
            PPS  = pPPS;
            Rate = 90000;
            var ms = new MemoryStream(SpsLength - 1);

            for (ushort i = 1; i < pSPS.Length; i++)
            {
                if (i + 2 < pSPS.Length - 1 && SPS[i] == 0 && SPS[i + 1] == 0 && SPS[i + 2] == 3)
                {
                    ms.WriteByte(0);
                    ms.WriteByte(0);
                    i += 2;
                }
                else
                {
                    ms.WriteByte(SPS[i]);
                }
            }
            ms.Position = 0;
            using (var spsReader = new BitReader(ms))
            {
                if (!ReadSPS(spsReader, _SPSInfo))
                {
                    Logger.WARN("Unable to parse SPS");
                }
                else
                {
                    _SPSInfo.Compact();
                    Width  = ((uint)_SPSInfo["pic_width_in_mbs_minus1"] + 1) * 16;
                    Height = ((uint)_SPSInfo["pic_height_in_map_units_minus1"] + 1) * 16;
                    //		FINEST("_width: %u (%u); _height: %u (%u)",
                    //				_width, (uint32_t) _SPSInfo["pic_width_in_mbs_minus1"],
                    //				_height, (uint32_t) _SPSInfo["pic_height_in_map_units_minus1"]);
                }
            }
            ms = new MemoryStream(PpsLength - 1);
            for (ushort i = 1; i < pPPS.Length; i++)
            {
                if (i + 2 < pPPS.Length - 1 && PPS[i] == 0 && PPS[i + 1] == 0 && PPS[i + 2] == 3)
                {
                    ms.WriteByte(0);
                    ms.WriteByte(0);
                    i += 2;
                }
                else
                {
                    ms.WriteByte(PPS[i]);
                }
            }
            ms.Position = 0;
            using (var ppsReader = new BitReader(ms))
            {
                if (!ReadPPS(ppsReader, _PPSInfo))
                {
                    Logger.WARN("Unable to read PPS info");
                }
            }
            return(true);
        }