示例#1
0
        private void ReaderBuffer(ReadOnlySpan <byte> buffer, Socket socket, SocketReceiveMessageFromResult receiveMessageFromResult)
        {
            try
            {
                var package = JT1078Serializer.Deserialize(buffer);
                package.SIM = package.SIM.TrimStart('0');
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace($"[Accept Hex {receiveMessageFromResult.RemoteEndPoint}]:{buffer.ToArray().ToHexString()}");
                }
                var session = SessionManager.TryLink(package.SIM, socket, receiveMessageFromResult.RemoteEndPoint);
                if (Logger.IsEnabled(LogLevel.Information))
                {
                    Logger.LogInformation($"[Connected]:{receiveMessageFromResult.RemoteEndPoint}");
                }
                if (jT1078UseType == JT1078UseType.Queue)
                {
                    jT1078MsgProducer.ProduceAsync(package.SIM, buffer.ToArray());
                }
                else
                {
                    jT1078PackageProducer.ProduceAsync(package.SIM, package);
                }
            }
            catch (NotImplementedException ex)
            {
                Logger.LogError(ex.Message);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                Logger.LogError(ex, $"[ReaderBuffer]:{ buffer.ToArray().ToHexString()}");
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
示例#2
0
        public void DeserializeTest1()
        {
            //30 31 63 64
            //81
            //E2
            //10 88
            //01 12 34 56 78 10
            //01
            //10
            //00 00 01 6B B3 92 CA 7C
            //02 80
            //00 28
            //00 2E
            //00 00 00 01 61 E1 A2 BF
            //00 98 CF C0 EE 1E 17 28
            //34 07 78 8E 39 A4 03 FD
            //DB D1 D5 46 BF B0 63 01
            //3F 59 AC 34 C9 7A 02 1A
            //B9 6A 28 A4 2C 08
            var           bytes   = "30 31 63 64 81 E2 10 88 01 12 34 56 78 10 01 10 00 00 01 6B B3 92 CA 7C 02 80 00 28 00 2E 00 00 00 01 61 E1 A2 BF 00 98 CF C0 EE 1E 17 28 34 07 78 8E 39 A4 03 FD DB D1 D5 46 BF B0 63 01 3F 59 AC 34 C9 7A 02 1A B9 6A 28 A4 2C 08".ToHexBytes();
            JT1078Package package = JT1078Serializer.Deserialize(bytes);

            Assert.Equal(0x81, package.Label1.ToByte());
            Assert.Equal(0xE2, package.Label2.ToByte());
            Assert.Equal(0x1088, package.SN);
            Assert.Equal("011234567810", package.SIM);
            Assert.Equal(0x01, package.LogicChannelNumber);
            Assert.Equal(0x10, package.Label3.ToByte());
            Assert.Equal((ulong)1562085870204, package.Timestamp);
            Assert.Equal(0x0280, package.LastIFrameInterval);
            Assert.Equal(0x0028, package.LastFrameInterval);
            Assert.Equal(0x002E, package.DataBodyLength);
            Assert.Equal("00 00 00 01 61 E1 A2 BF 00 98 CF C0 EE 1E 17 28 34 07 78 8E 39 A4 03 FD DB D1 D5 46 BF B0 63 01 3F 59 AC 34 C9 7A 02 1A B9 6A 28 A4 2C 08".ToHexBytes(), package.Bodies);
        }
示例#3
0
        public void 测试第一帧的数据()
        {
            JT1078Package Package         = null;
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.txt"));
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                Package          = JT1078Serializer.Merge(package);
            }
            H264Decoder decoder = new H264Decoder();
            //7 8 6 5 1 1 1 1 1 7 8 6 5 1 1 1 1
            var nalus = decoder.ParseNALU(Package);

            Assert.Equal(4, nalus.Count);

            FlvEncoder encoder  = new FlvEncoder();
            var        contents = encoder.CreateFlvFrame(nalus);
            var        filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.flv");

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            FileStream fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);

            fileStream.Write(FlvEncoder.VideoFlvHeaderBuffer);
            fileStream.Write(contents);
            fileStream.Close();
        }
示例#4
0
        public void 测试可以播放的Flv3()
        {
            FileStream fileStream = null;

            try
            {
                var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.flv");
                var lines    = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt"));
                fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
                bool       isNeedFirstHeadler = true;
                FlvEncoder encoder            = new FlvEncoder();
                foreach (var line in lines)
                {
                    var           data        = line.Split(',');
                    var           bytes       = data[6].ToHexBytes();
                    JT1078Package package     = JT1078Serializer.Deserialize(bytes);
                    JT1078Package fullpackage = JT1078Serializer.Merge(package);
                    if (fullpackage != null)
                    {
                        var videoTag = encoder.EncoderVideoTag(fullpackage, isNeedFirstHeadler);
                        fileStream.Write(videoTag);
                        isNeedFirstHeadler = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Throws <Exception>(() => { });
            }
            finally
            {
                fileStream?.Close();
                fileStream?.Dispose();
            }
        }
示例#5
0
        public void Test_1()
        {
            FileStream fileStream = null;

            try
            {
                var lines    = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt"));
                var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.h264");
                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }
                fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
                foreach (var line in lines)
                {
                    var           data    = line.Split(',');
                    var           bytes   = data[6].ToHexBytes();
                    JT1078Package package = JT1078Serializer.Deserialize(bytes);
                    fileStream.Write(package.Bodies);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                fileStream?.Close();
                fileStream?.Dispose();
            }
        }
        public void Test()
        {
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.txt"));
            JT1078Package merge           = null;
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                merge            = JT1078Serializer.Merge(package);
            }
            var packages = merge.Bodies.ConvertVideo(merge.SIM, merge.LogicChannelNumber, merge.Label2.PT, merge.Label3.DataType,
                                                     merge.Timestamp, merge.LastFrameInterval, merge.LastFrameInterval);

            for (int i = 0; i < packages.Count; i++)
            {
                var data   = lines[i].Split(',');
                var bytes1 = data[6].ToHexBytes();
                var bytes2 = JT1078Serializer.Serialize(packages[i]);
                Assert.Equal(bytes1, bytes2);
            }
        }
示例#7
0
        public void DeserializeTest3()
        {
            //30 31 63 64
            //81
            //E2
            //10 BB
            //01 12 34 56 78 10
            //01
            //10
            //00 00 01 6B B3 92 CF 2C
            //07 30
            //00 28
            //00 1D
            //00 00 00 01 61 E4 62 BF
            //00 32 BE 88 82 3B 94 6F
            //41 EE 7C 28 7D 82 A5 9C
            //29 49 A8 4C BF
            var           bytes   = "30 31 63 64 81 E2 10 BB 01 12 34 56 78 10 01 10 00 00 01 6B B3 92 CF 2C 07 30 00 28 00 1D 00 00 00 01 61 E4 62 BF 00 32 BE 88 82 3B 94 6F 41 EE 7C 28 7D 82 A5 9C 29 49 A8 4C BF".ToHexBytes();
            JT1078Package package = JT1078Serializer.Deserialize(bytes);

            Assert.Equal(0x81, package.Label1.ToByte());
            Assert.Equal(0xE2, package.Label2.ToByte());
            Assert.Equal(0x10BB, package.SN);
            Assert.Equal("011234567810", package.SIM);
            Assert.Equal(0x01, package.LogicChannelNumber);
            Assert.Equal(0x10, package.Label3.ToByte());
            Assert.Equal((ulong)1562085871404, package.Timestamp);
            Assert.Equal(0x0730, package.LastIFrameInterval);
            Assert.Equal(0x0028, package.LastFrameInterval);
            Assert.Equal(0x001D, package.DataBodyLength);
            Assert.Equal("00 00 00 01 61 E4 62 BF 00 32 BE 88 82 3B 94 6F 41 EE 7C 28 7D 82 A5 9C 29 49 A8 4C BF".ToHexBytes(), package.Bodies.ToArray());
        }
 public void TestJT808_0x0200_Deserialize()
 {
     for (int i = 0; i < N; i++)
     {
         JT1078Package package = JT1078Serializer.Deserialize(JT1078Bytes);
     }
 }
示例#9
0
 protected override void ChannelRead0(IChannelHandlerContext ctx, JT1078UdpPackage msg)
 {
     try
     {
         sourcePackageDispatcher.SendAsync(msg.Buffer);
         if (logger.IsEnabled(LogLevel.Trace))
         {
             logger.LogTrace("accept package success count<<<" + AtomicCounterService.MsgSuccessCount.ToString());
             logger.LogTrace("accept msg <<< " + ByteBufferUtil.HexDump(msg.Buffer));
         }
         JT1078Package package = JT1078Serializer.Deserialize(msg.Buffer);
         AtomicCounterService.MsgSuccessIncrement();
         SessionManager.TryAdd(ctx.Channel, msg.Sender, package.SIM);
         handlers.Processor(new JT1078Request(package, msg.Buffer));
         if (logger.IsEnabled(LogLevel.Debug))
         {
             logger.LogDebug("accept package success count<<<" + AtomicCounterService.MsgSuccessCount.ToString());
         }
     }
     catch (Exception ex)
     {
         AtomicCounterService.MsgFailIncrement();
         if (logger.IsEnabled(LogLevel.Error))
         {
             logger.LogError("accept package fail count<<<" + AtomicCounterService.MsgFailCount.ToString());
             logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg.Buffer));
         }
     }
 }
        public JT1078DataService()
        {
            DataBlockingCollection = new BlockingCollection <JT1078Package>(60000);
            var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "2019-07-15.log"));

            Task.Run(() =>
            {
                while (true)
                {
                    for (int i = 0; i < lines.Length; i++)
                    {
                        try
                        {
                            var package = JT1078Serializer.Deserialize(lines[i].Split(',')[6].ToHexBytes());
                            DataBlockingCollection.Add(package);
                            Thread.Sleep(300);
                        }
                        catch
                        {
                        }
                    }
                    Thread.Sleep(60000);
                }
            });
        }
示例#11
0
        public void Test4()
        {
            try
            {
                var hls_file_directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "terminalno");
                if (!File.Exists(hls_file_directory))
                {
                    Directory.CreateDirectory(hls_file_directory);
                }
                var       m3u8_filename = Path.Combine(hls_file_directory, "live.m3u8");
                TSEncoder tSEncoder     = new TSEncoder();
                var       m3u8Manage    = new M3U8FileManage(new Options.M3U8Option {
                    HlsFileDirectory = hls_file_directory, M3U8FileName = m3u8_filename
                }, tSEncoder);

                var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt"));
                foreach (var line in lines)
                {
                    var           data        = line.Split(',');
                    var           bytes       = data[6].ToHexBytes();
                    JT1078Package package     = JT1078Serializer.Deserialize(bytes);
                    JT1078Package fullpackage = JT1078Serializer.Merge(package);
                    if (fullpackage != null)
                    {
                        m3u8Manage.CreateTsData(fullpackage);
                    }
                }
            }
            catch (Exception ex)
            {
                //Assert.Throws<Exception>(() => { });
            }
        }
示例#12
0
        public void FlvEncoder_Test_1()
        {
            JT1078Package Package         = null;
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.txt"));
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                Package          = JT1078Serializer.Merge(package);
            }
            Flv.H264.H264Decoder decoder = new Flv.H264.H264Decoder();
            var nalus = decoder.ParseNALU(Package);

            Assert.Equal(4, nalus.Count);

            FlvEncoder encoder  = new FlvEncoder();
            var        contents = encoder.CreateFlvFrame(nalus);
            var        filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.flv");

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            File.WriteAllBytes(filepath, contents);
        }
示例#13
0
        public void FlvEncoder_Test_4()
        {
            FileStream fileStream = null;

            Flv.H264.H264Decoder decoder    = new Flv.H264.H264Decoder();
            List <H264NALU>      h264NALULs = new List <H264NALU>();
            FlvEncoder           encoder    = new FlvEncoder();

            try
            {
                var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_4.flv");
                var lines    = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_4.txt"));
                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }

                JT1078Package Package = null;

                foreach (var line in lines)
                {
                    var           data    = line.Split(',');
                    var           bytes   = data[6].ToHexBytes();
                    JT1078Package package = JT1078Serializer.Deserialize(bytes);
                    Package = JT1078Serializer.Merge(package);
                    if (Package != null)
                    {
                        var tmp = decoder.ParseNALU(Package);
                        if (tmp != null && tmp.Count > 0)
                        {
                            h264NALULs = h264NALULs.Concat(tmp).ToList();
                        }
                    }
                }

                fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
                fileStream.Write(FlvEncoder.VideoFlvHeaderBuffer);

                var totalPage = (h264NALULs.Count + 10 - 1) / 10;
                for (var i = 0; i < totalPage; i++)
                {
                    var flv2 = encoder.CreateFlvFrame(h264NALULs.Skip(i * 10).Take(10).ToList());
                    if (flv2.Length != 0)
                    {
                        fileStream.Write(flv2);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Throws <Exception>(() => { });
            }
            finally
            {
                fileStream?.Close();
                fileStream?.Dispose();
            }
        }
示例#14
0
        public void a()
        {
            List <JT1078Package> packages = new List <JT1078Package>();
            var lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "jt1078_3.txt"));
            int mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                var packageMerge = JT1078Serializer.Merge(package);
                if (packageMerge != null)
                {
                    packages.Add(packageMerge);
                }
            }
            List <byte[]> first = new List <byte[]>();
            //var styp = fMp4Encoder.EncoderStypBox();
            //first.Add(styp);
            //q.Enqueue(styp);
            var ftyp = fMp4Encoder.EncoderFtypBox();

            //q.Enqueue(ftyp);
            first.Add(ftyp);
            var package1 = packages[0];
            var nalus1   = h264Decoder.ParseNALU(package1);
            var moov     = fMp4Encoder.EncoderMoovBox(nalus1, package1.Bodies.Length);

            //q.Enqueue(moov);
            first.Add(moov);
            q.Add(first.SelectMany(s => s).ToArray());
            List <int> filter = new List <int>()
            {
                6, 7, 8
            };

            foreach (var package in packages)
            {
                List <byte[]> other       = new List <byte[]>();
                var           otherNalus  = h264Decoder.ParseNALU(package);
                var           filterNalus = otherNalus.Where(w => !filter.Contains(w.NALUHeader.NalUnitType)).ToList();
                var           flag        = package.Label3.DataType == Protocol.Enums.JT1078DataType.视频I帧 ? 1u : 0u;
                var           len         = filterNalus.Sum(s => s.RawData.Length);
                var           len1        = otherNalus.Sum(s => s.RawData.Length);
                var           moofBuffer  = fMp4Encoder.EncoderMoofBox(filterNalus, len, package.Timestamp, package.LastIFrameInterval, flag);
                //q.Enqueue(moofBuffer);
                other.Add(moofBuffer);
                var otherMdatBuffer = fMp4Encoder.EncoderMdatBox(filterNalus, len);
                //q.Enqueue(otherMdatBuffer);
                other.Add(otherMdatBuffer);
                q.Add(other.SelectMany(s => s).ToArray());
            }
        }
示例#15
0
        public void ToBufferTest3()
        {
            FileStream fileStream = null;

            try
            {
                var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.ts");
                File.Delete(filepath);
                var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_3.txt"));
                fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
                bool      isNeedFirstHeadler = true;
                TSEncoder tSEncoder          = new TSEncoder();
                foreach (var line in lines)
                {
                    var           data        = line.Split(',');
                    var           bytes       = data[6].ToHexBytes();
                    JT1078Package package     = JT1078Serializer.Deserialize(bytes);
                    JT1078Package fullpackage = JT1078Serializer.Merge(package);
                    if (fullpackage != null)
                    {
                        if (isNeedFirstHeadler)
                        {
                            var    sdt    = tSEncoder.CreateSDT();
                            string sdtHEX = sdt.ToHexString();
                            fileStream.Write(sdt);
                            var    pat    = tSEncoder.CreatePAT();
                            string patHEX = pat.ToHexString();
                            fileStream.Write(pat);
                            var pmt = tSEncoder.CreatePMT();
                            fileStream.Write(pmt);
                            var pes = tSEncoder.CreatePES(fullpackage, 18888);
                            fileStream.Write(pes);
                            isNeedFirstHeadler = false;
                        }
                        else
                        {
                            fileStream.Write(tSEncoder.CreatePES(fullpackage, 18888));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Throws <Exception>(() => { });
            }
            finally
            {
                fileStream?.Close();
                fileStream?.Dispose();
            }
        }
示例#16
0
        public void ParseNALUTest2()
        {
            JT1078Package Package         = null;
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "jt1078_1.txt"));
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                Package          = JT1078Serializer.Merge(package);
            }
            H264Decoder decoder = new H264Decoder();
            var         nalus   = decoder.ParseNALU(Package);

            Assert.Equal(4, nalus.Count);

            //SPS -> 7
            var spsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 7);

            Assert.NotNull(spsNALU);
            spsNALU.RawData = decoder.DiscardEmulationPreventionBytes(spsNALU.RawData);
            //"Z00AFJWoWCWQ"
            var             spsRawDataHex    = JsonConvert.SerializeObject(spsNALU.RawData);
            ExpGolombReader h264GolombReader = new ExpGolombReader(spsNALU.RawData);
            //(77, 20, 0, 352, 288)
            var spsInfo = h264GolombReader.ReadSPS();

            Assert.Equal(77, spsInfo.profileIdc);
            Assert.Equal(20, spsInfo.levelIdc);
            Assert.Equal(0u, spsInfo.profileCompat);
            Assert.Equal(288, spsInfo.height);
            Assert.Equal(352, spsInfo.width);

            //PPS -> 8
            var ppsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 8);

            Assert.NotNull(ppsNALU);

            //IDR -> 5  关键帧
            var idrNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 5);

            Assert.NotNull(idrNALU);

            //SEI -> 6
            var seiNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 6);

            Assert.NotNull(seiNALU);
        }
示例#17
0
        public void ParseNALUTest1()
        {
            H264Decoder   demuxer = new H264Decoder();
            var           hexData = "3031636481e2274b01234567899901100000016cd3ed2fa900500050037f0000000161e022bfb28b470069769838a02eb3b5cc4bccd7b37eb98cd65b2a76ce85a6c82876385a8f646da3d0abb6af58ad1dc7db5dab9719577d9968f7efc9836f4bc8fb7e32f5689b190e9e6e07d2f4448efff9147175f22a4b0f83fd24374b881dddcac5998ab9b03d991eb0045ed98826699a5601cdd6bd1e4b3ca53c175ef36e9f46969018c01b7754304790a17888072647e4c473182f05922770f5aff81e02ea46637b5e90b4382f100a2b55c5f49e0fa0b8203804dcd7714fac1dbd15d0583f8ebdfdf980770d58b38349ad7ec5682f01dae88b2117c6f3b3b58b642354bc23735d9c269028df9774e8182f5d636cec09829886de3ee83406e035bffcce3ed24af0f9a2dee150fab93303f2139c8525eeb89516df169137ef46ed99962343ea7b078bcddd284e44be62936a6c44042d89acb17973eb65e1c21faee6d221627ba834d369f4c023acc122d7d3dd3f55a6c4fb2ba2854498d4041ea00b1252c6d9eb57ac0b10313e8905843054dfbf4c847180aee40980bdfe5cb53133214c77c8e95ebe7601cd0d331f75281d1fadd122985133e74855e13cbb10220bc6e0c946b519b35d933a29e38e175b1398dc0946fc58ec7b686b3aac4bfa9e42bb8e643be04dc55036289c7d378fe37c6c3e1fc06015f8b402a65afac23d78d9fb5e3e0115195c11227ee6f261b67834b51bc665e8a6803af835b5032786e58e7f66049dc767520bae35d527a72458834a846dcd1cccf198d772d3ce0a2db5eb1d8270c483840309e224b2798d9271b30729e0c4f51eb7798d0dd0d8adb3d246e686b42e47f351c482dda833747649e421bbbe04098ca220d4e0e60a3b2854029c95c70394a2991314c50199f2158b68635a622f55ebda0b5e41328843552723fba1d5228963e8562c9105838ec9d341fef19b33a438d903ebcef32cec2ad39fd32aff14c79f07de4ca75e65d20f6ee36e464ee3e5c27871ab594ae3a0b43583c6f4d55ac8b71090fca9a1f4379576e07678983935d6f3a236504c2e4d31f99d62c999f41c11b06c41a6adb07b6e62f50ec5c8dbdb6641c5bc55a695f0f7b4f4d430c1e2f38a77edfc3513f943e1c1d4c0a81ef6c26cc4e7b157d318b49802ea94aa8ab38dadd4986e5330ab49daaec010123c39da63943bfe63bdd1cdd6beec19e1469b989ac10877a24065d7b01ff9cee35632e97243eb7acd79ce9d188b786e44bbe0e922be205c1224a41f387fae0f20d4a203d0ba64a366b8adbe2b80".ToHexBytes();
            JT1078Package package = JT1078Serializer.Deserialize(hexData);
            var           nalus   = demuxer.ParseNALU(package);

            Assert.Single(nalus);
            var nalu = nalus[0];

            Assert.Equal(0, nalu.NALUHeader.ForbiddenZeroBit);
            Assert.Equal(3, nalu.NALUHeader.NalRefIdc);
            Assert.Equal(1, nalu.NALUHeader.NalUnitType);
        }
示例#18
0
        public void DeserializeTest6()
        {
            var           bytes   = "3031636481E20492001901305037031000000174922CB80F00A00050033D0000000161E042BF50E2C3B950968B6CB9B80E2CB3F68DBFA51A9C9DC3C0B85C5215C0A4DE5C1D48B72D760400BF88D5EA46D276C8682573C459CD33E8D98C4C77A96F366D636454DC62AFCD4491A670744247B727859C14ECE91C03013D37CFDDBE93CA8C5651863E47DE5231BE914029A04A9E1318D983DB115800C01FC961DBA05DA3D2CEF66761CA5BF7CFA1815429DDE0AF2CF527C251C2E190407D313A651895FAFA7A1AC2E4ABEFDD7E26F1B37D9C643A1AF302ACD77A8A74A34747BC333C89A2E02AD902137708251313D77A649A751EA81E48A341C44D895694F37D2BEC8B9B50A46B9C2CB9AE62DCE10BF7692D1151A3B55CA3310AC494CF095D6258A71F875ED8D9C54694B29C217F48E0C511ECB52951F6DF1B9CF9FB6CFCAEFF515645D66278A964D4CCF64D9999F82D639A77F3B79E91C1B9A1F0A156B712D52E9F810FA6B6885A788EB7C1EA6272660F108C5A3D0C5893BA0021B1A080EC158D77BE40DC92A2EBEF96469FC8B258F3EDF843859DD83861D1B27E72019DC5FBF97D2489554092C2DEEAECD15FE6C2455D8A8CDEB590707914C2D01DA003C84C9F04D45569655A05648C465EBE1E04B6B330F6DFE7DE4F0975ED884275D8D8931405E88DC9D54084F25DED012E175F61E5EDB56F308D36F046C127CC96B0CCACA3B96018A6354D15A6520901A4EBC699AA9DC5E45FF17C35FED9A14B4BA84457534FB636EE998990C7B9E6A44638FB51615A09CCB922B6DA47C5E3A45EA794E76514DFA76CBA2DEB5F947CB71557AFA34F6D9DD37F747FB4D37AD14EFBF5070831DDC59C78713DF1CA8A394636158E761A12D6B763645D220D356B8B48462AD7A0112C4A59BEF52AD70BB69907CDDB350ED2D389DB0B003ECEF40FACBB4A3F29409C51AAEAB4A21AA3C70DFEDD116B7534E5A938974B431BC46956D376D73C6A7A0B0E9FF6A4A006097D680C93E5BFA75B3D4D533EA83F93A2503A2F813D3DA037498B4F31270845B3807A61AF0E722EA9ABBF2C0A5DCEA564DE3F58CC1273A8E52CB675B26700AD24F2115823F2BF918279321628FDBAD3B8C0FA0C50536DF88022F6C3956EE0ACCBF31B602AEB0D1933A677EB40125C89FE2A61A05BA7DE296DAE20EEF74790B1405B9766FBF1A0FFFD03BA07D943B504FA0C568DA0".ToHexBytes();
            JT1078Package package = JT1078Serializer.Deserialize(bytes);

            Assert.Equal(0b10000001, package.Label1.ToByte());
            Assert.Equal(0b11100010, package.Label2.ToByte());
            Assert.Equal(1170u, package.SN);
            Assert.Equal("001901305037", package.SIM);
            Assert.Equal(0x03, package.LogicChannelNumber);
            Assert.Equal(0b00010000, package.Label3.ToByte());
            Assert.Equal((ulong)1600180238351, package.Timestamp);
            Assert.Equal(829u, package.DataBodyLength);
        }
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     JT1078MsgConsumer.OnMessage(async(Message) =>
     {
         JT1078Package package = JT1078Serializer.Deserialize(Message.Data);
         var merge             = JT1078.Protocol.JT1078Serializer.Merge(package);
         if (merge != null)
         {
             await messageDispatchDataService.HlsChannel.Writer.WriteAsync(merge);
             await messageDispatchDataService.FlvChannel.Writer.WriteAsync(merge);
         }
     });
     return(Task.CompletedTask);
 }
示例#20
0
        public void Setup()
        {
            var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JT1078_1.txt"));

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                Package = JT1078Serializer.Merge(package);
            }
            H264NALUs       = h264Decoder.ParseNALU(Package);
            SPSNALu         = H264NALUs.FirstOrDefault(f => f.NALUHeader.NalUnitType == 7);
            SPSNALu.RawData = h264Decoder.DiscardEmulationPreventionBytes(SPSNALu.RawData);
        }
示例#21
0
        public ActionResult <JTResultDto> Parse1078([FromBody] JTRequestDto parameter)
        {
            JTResultDto jTResultDto = new JTResultDto();

            try
            {
                jTResultDto.Code = 200;
                jTResultDto.Data = JT1078Serializer.Deserialize(parameter.HexData.ToHexBytes());
            }
            catch (Exception ex)
            {
                jTResultDto.Code    = 500;
                jTResultDto.Message = ex.Message;
            }
            return(jTResultDto);
        }
示例#22
0
        public JT1078Package ParseNALUTest()
        {
            JT1078Package Package         = null;
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "jt1078_1.txt"));
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                Package          = JT1078Serializer.Merge(package);
            }
            return(Package);
        }
示例#23
0
 public void EncoderVideoTagTest2()
 {
     try
     {
         var           bytes       = "3031636481E2022D0019013050370210000001749179C79D05C80050000E0000000161E1E2FF000003006840".ToHexBytes();
         FlvEncoder    encoder     = new FlvEncoder();
         JT1078Package package     = JT1078Serializer.Deserialize(bytes);
         JT1078Package fullpackage = JT1078Serializer.Merge(package);
         if (fullpackage != null)
         {
             var videoTag = encoder.EncoderVideoTag(fullpackage, false);
         }
     }
     catch (Exception ex)
     {
     }
 }
示例#24
0
 public void EncoderVideoTagTest1()
 {
     try
     {
         var           bytes       = "3031636481E206AD0019013050370210000001749162905508480050000E0000000161E4025F0000030037A03031636481E206AE001901305037021000000174916290A508980050000E0000000161E4225F0000030037A0".ToHexBytes();
         FlvEncoder    encoder     = new FlvEncoder();
         JT1078Package package     = JT1078Serializer.Deserialize(bytes);
         JT1078Package fullpackage = JT1078Serializer.Merge(package);
         if (fullpackage != null)
         {
             var videoTag = encoder.EncoderVideoTag(fullpackage, false);
         }
     }
     catch (Exception ex)
     {
     }
 }
示例#25
0
        public void MergeTest()
        {
            var           lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JT1078.txt"));
            JT1078Package merge           = null;
            int           mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[5].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                merge            = JT1078Serializer.Merge(package);
            }
            Assert.NotNull(merge);
            Assert.Equal(mergeBodyLength, merge.Bodies.Length);
            Assert.Equal(JT1078SubPackageType.分包处理时的第一个包, merge.Label3.SubpackageType);
        }
示例#26
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBox1.Text))
            {
                MessageBox.Show("请输入数据包!");
                return;
            }
            try
            {
                var buffer = this.textBox1.Text.ToHexBytes();

                JT1078Package package = JT1078Serializer.Deserialize(buffer);

                this.textBox2.Text = JsonConvert.SerializeObject(package, Formatting.Indented);
            }
            catch (Exception ex)
            {
                this.textBox2.Text = JsonConvert.SerializeObject(ex);
            }
        }
示例#27
0
        public void ParseNALUTest3()
        {
            string file     = "jt1078_1";
            var    lines    = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", $"{file}.txt"));
            string filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", $"{file}.h264");

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            using var fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                fileStream.Write(package.Bodies);
            }
            fileStream.Close();
        }
示例#28
0
        public List <JT1078Package> ParseNALUTests()
        {
            List <JT1078Package> packages = new List <JT1078Package>();
            var lines           = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "jt1078_3.txt"));
            int mergeBodyLength = 0;

            foreach (var line in lines)
            {
                var           data    = line.Split(',');
                var           bytes   = data[6].ToHexBytes();
                JT1078Package package = JT1078Serializer.Deserialize(bytes);
                mergeBodyLength += package.DataBodyLength;
                var packageMerge = JT1078Serializer.Merge(package);
                if (packageMerge != null)
                {
                    packages.Add(packageMerge);
                }
            }
            return(packages);
        }
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     MsgConsumer.OnMessage((Message) =>
     {
         JT1078Package package = JT1078Serializer.Deserialize(Message.Data);
         var merge             = JT1078.Protocol.JT1078Serializer.Merge(package);
         if (merge != null)
         {
             var hasHttpSessionn = HttpSessionManager.GetAllHttpContextBySimAndChannelNo(merge.SIM, merge.LogicChannelNumber);
             if (hasHttpSessionn.Count > 0)
             {
                 M3U8FileManage.CreateTsData(merge);
             }
             else
             {
                 M3U8FileManage.Clear(merge.SIM, merge.LogicChannelNumber);
             }
         }
     });
     return(Task.CompletedTask);
 }
示例#30
0
        public void DeserializeTest4()
        {
            //30 31 63 64
            //81
            //88
            //11 35
            //01 12 34 56 78 10
            //01
            //30
            //00 00 01 6B B3 92 DA 05
            //00 78
            //B7 6D FF EF 7D FB A9 9D
            //FE A9 1F 37 77 F3 37 BE
            //EF FB F7 FB FB BE 7D DF
            //B7 FD FB 76 AF DE 77 65
            //C7 EF E3 FB BE FF DB 4E
            //FF DB B7 63 FF EE EF D8
            //BE 1D 37 B7 7D E7 7D F3
            //C6 F7 FD F4 BE 1F F7 B7
            //55 FF 76 FC FE CE 7B FF
            //B7 7D 3F F5 FF FE 76 6C
            //DF FE 53 DB CF 6D FB BF
            //FD DE B1 EF 3E 77 D3 3F
            //6E 9A BF BF FF DB F7 FD
            //DB 7F 63 FF 6E EC F8 EE
            //1F FB FD 7F FB 7D 7C DB
            var           bytes   = "30 31 63 64 81 88 11 35 01 12 34 56 78 10 01 30 00 00 01 6B B3 92 DA 05 00 78 B7 6D FF EF 7D FB A9 9D FE A9 1F 37 77 F3 37 BE EF FB F7 FB FB BE 7D DF B7 FD FB 76 AF DE 77 65 C7 EF E3 FB BE FF DB 4E FF DB B7 63 FF EE EF D8 BE 1D 37 B7 7D E7 7D F3 C6 F7 FD F4 BE 1F F7 B7 55 FF 76 FC FE CE 7B FF B7 7D 3F F5 FF FE 76 6C DF FE 53 DB CF 6D FB BF FD DE B1 EF 3E 77 D3 3F 6E 9A BF BF FF DB F7 FD DB 7F 63 FF 6E EC F8 EE 1F FB FD 7F FB 7D 7C DB".ToHexBytes();
            JT1078Package package = JT1078Serializer.Deserialize(bytes);

            Assert.Equal(0x81, package.Label1.ToByte());
            Assert.Equal(0x88, package.Label2.ToByte());
            Assert.Equal(0x1135, package.SN);
            Assert.Equal("011234567810", package.SIM);
            Assert.Equal(0x01, package.LogicChannelNumber);
            Assert.Equal(0x30, package.Label3.ToByte());
            Assert.Equal((ulong)1562085874181, package.Timestamp);
            Assert.Equal(0x0078, package.DataBodyLength);
            Assert.Equal("B7 6D FF EF 7D FB A9 9D FE A9 1F 37 77 F3 37 BE EF FB F7 FB FB BE 7D DF B7 FD FB 76 AF DE 77 65 C7 EF E3 FB BE FF DB 4E FF DB B7 63 FF EE EF D8 BE 1D 37 B7 7D E7 7D F3 C6 F7 FD F4 BE 1F F7 B7 55 FF 76 FC FE CE 7B FF B7 7D 3F F5 FF FE 76 6C DF FE 53 DB CF 6D FB BF FD DE B1 EF 3E 77 D3 3F 6E 9A BF BF FF DB F7 FD DB 7F 63 FF 6E EC F8 EE 1F FB FD 7F FB 7D 7C DB".ToHexBytes(), package.Bodies.ToArray());
        }