Exemplo n.º 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
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public void TestJT808_0x0200_Deserialize()
 {
     for (int i = 0; i < N; i++)
     {
         JT1078Package package = JT1078Serializer.Deserialize(JT1078Bytes);
     }
 }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
        }
        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);
            }
        }
Exemplo n.º 7
0
        public void 测试可以播放的Flv4()
        {
            FileStream fileStream = null;
            int        i          = 0;

            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"));
                fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
                bool       isNeedFirstHeadler = true;
                FlvEncoder encoder            = new FlvEncoder();
                foreach (var line in lines)
                {
                    i++;
                    var           bytes       = line.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)
            {
            }
            finally
            {
                fileStream?.Close();
                fileStream?.Dispose();
            }
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
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>(() => { });
            }
        }
Exemplo n.º 10
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);

            byte[] tmp = new byte[FlvEncoder.VideoFlvHeaderBuffer.Length + contents.Length];
            Array.Copy(FlvEncoder.VideoFlvHeaderBuffer, tmp, FlvEncoder.VideoFlvHeaderBuffer.Length);
            Array.Copy(contents, 0, tmp, FlvEncoder.VideoFlvHeaderBuffer.Length, contents.Length);
            var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_1.flv");

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
            File.WriteAllBytes(filepath, tmp);
        }
 protected override void ChannelRead0(IChannelHandlerContext ctx, byte[] msg)
 {
     try
     {
         sourcePackageDispatcher.SendAsync(msg);
         if (logger.IsEnabled(LogLevel.Trace))
         {
             logger.LogTrace("accept package success count<<<" + AtomicCounterService.MsgSuccessCount.ToString());
             logger.LogTrace("accept msg <<< " + ByteBufferUtil.HexDump(msg));
         }
         JT1078Package package = JT1078Serializer.Deserialize(msg);
         AtomicCounterService.MsgSuccessIncrement();
         SessionManager.TryAdd(package.SIM, ctx.Channel);
         handlers.Processor(new JT1078Request(package, msg));
         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));
         }
     }
 }
Exemplo n.º 12
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();
            }
        }
Exemplo n.º 13
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());
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 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);
        }
 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);
 }
Exemplo n.º 19
0
        public void SerializeTest5()
        {
            JT1078Package jT1078Package = new JT1078Package();

            jT1078Package.Label1             = new JT1078Label1(0x81);
            jT1078Package.Label2             = new JT1078Label2(0x88);
            jT1078Package.SN                 = 0x1135;
            jT1078Package.SIM                = "11234567810";
            jT1078Package.LogicChannelNumber = 0x01;
            jT1078Package.Label3             = new JT1078Label3(0x30);
            jT1078Package.Timestamp          = 1562085874181;
            jT1078Package.Bodies             = Enumerable.Range(0, 900).Select(s => (byte)(s + 1)).ToArray();
            var hex = JT1078Serializer.Serialize(jT1078Package).ToHexString();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 23
0
        public void SerializeTest4()
        {
            JT1078Package jT1078Package = new JT1078Package();

            jT1078Package.Label1             = new JT1078Label1(0x81);
            jT1078Package.Label2             = new JT1078Label2(0x88);
            jT1078Package.SN                 = 0x1135;
            jT1078Package.SIM                = "11234567810";
            jT1078Package.LogicChannelNumber = 0x01;
            jT1078Package.Label3             = new JT1078Label3(0x30);
            jT1078Package.Timestamp          = 1562085874181;
            jT1078Package.Bodies             = "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();
            var hex = JT1078Serializer.Serialize(jT1078Package).ToHexString();

            Assert.Equal("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".Replace(" ", ""), hex);
        }
Exemplo n.º 24
0
        public void SerializeTest2()
        {
            JT1078Package jT1078Package = new JT1078Package();

            jT1078Package.Label1             = new JT1078Label1(0x81);
            jT1078Package.Label2             = new JT1078Label2(0x88);
            jT1078Package.SN                 = 0x10BA;
            jT1078Package.SIM                = "11234567810";
            jT1078Package.LogicChannelNumber = 0x01;
            jT1078Package.Label3             = new JT1078Label3(0x30);
            jT1078Package.Timestamp          = 1562085871501;
            jT1078Package.Bodies             = "FE 6D 3B BE EF 3E 4E 7D FF B7 6D 5F F5 6F C7 BE 6F DF 77 DC DF 8E ED 3B 6F E3 3F B5 73 DF 6F EC F8 FD FF FE BE EF DB F7 6F DB BF FD D7 BF 6F FB 6F 6E F7 FF 5F DF BF D3 F7 8F FD FA B2 EF 3E F7 5F FF F1 5D 3F BF FB 26 BE ED C7 B7 7D 3F AE E3 FB EF 1D 3B AE 93 FE EF 7F DF 77 93 FE B6 65 3B BD FA E6 8E ED F8 F7 EF DB B1 FF C6 6F 7C FF EF FD DB 71 7F FF 6E EE 3E".ToHexBytes();
            var hex = JT1078Serializer.Serialize(jT1078Package).ToHexString();

            Assert.Equal("30 31 63 64 81 88 10 BA 01 12 34 56 78 10 01 30 00 00 01 6B B3 92 CF 8D 00 78 FE 6D 3B BE EF 3E 4E 7D FF B7 6D 5F F5 6F C7 BE 6F DF 77 DC DF 8E ED 3B 6F E3 3F B5 73 DF 6F EC F8 FD FF FE BE EF DB F7 6F DB BF FD D7 BF 6F FB 6F 6E F7 FF 5F DF BF D3 F7 8F FD FA B2 EF 3E F7 5F FF F1 5D 3F BF FB 26 BE ED C7 B7 7D 3F AE E3 FB EF 1D 3B AE 93 FE EF 7F DF 77 93 FE B6 65 3B BD FA E6 8E ED F8 F7 EF DB B1 FF C6 6F 7C FF EF FD DB 71 7F FF 6E EE 3E".Replace(" ", ""), hex);
        }
Exemplo n.º 25
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)
     {
     }
 }
Exemplo n.º 26
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)
     {
     }
 }
        public Task <JT1078Response> Processor(JT1078Request request)
        {
            //var path=Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "h264", $"demo.h264");
            //using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))
            //{
            //    fs.Write(request.Src);
            //    fs.Close();
            //}
            logger.LogInformation(JsonConvert.SerializeObject(request.Package));
            //hexLogger.LogInformation($"{request.Package.SIM},{request.Package.Label3.DataType.ToString()},{request.Package.LastFrameInterval},{request.Package.LastIFrameInterval},{request.Package.Timestamp},{request.Package.SN},{request.Package.LogicChannelNumber},{request.Package.Label3.SubpackageType.ToString()},{ByteBufferUtil.HexDump(request.Src)}");
            hexLogger.LogInformation($"{request.Package.SIM},{request.Package.SN},{request.Package.LogicChannelNumber},{request.Package.Label3.DataType.ToString()},{request.Package.Label3.SubpackageType.ToString()},{ByteBufferUtil.HexDump(request.Src)}");
            var mergePackage = JT1078Serializer.Merge(request.Package);

            if (mergePackage != null)
            {
                jT1078WSFlvDataService.JT1078Packages.Add(mergePackage);
            }
            return(Task.FromResult <JT1078Response>(default));
Exemplo n.º 28
0
        public void SerializeTest3()
        {
            JT1078Package jT1078Package = new JT1078Package();

            jT1078Package.Label1             = new JT1078Label1(0x81);
            jT1078Package.Label2             = new JT1078Label2(0xE2);
            jT1078Package.SN                 = 0x10BB;
            jT1078Package.SIM                = "11234567810";
            jT1078Package.LogicChannelNumber = 0x01;
            jT1078Package.Label3             = new JT1078Label3(0x10);
            jT1078Package.LastIFrameInterval = 0x0730;
            jT1078Package.LastFrameInterval  = 0x0028;
            jT1078Package.Timestamp          = 1562085871404;
            jT1078Package.Bodies             = "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();
            var hex = JT1078Serializer.Serialize(jT1078Package).ToHexString();

            Assert.Equal("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".Replace(" ", ""), hex);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public void SerializeTest1()
        {
            JT1078Package jT1078Package = new JT1078Package();

            jT1078Package.Label1             = new JT1078Label1(0x81);
            jT1078Package.Label2             = new JT1078Label2(0xE2);
            jT1078Package.SN                 = 0x1088;
            jT1078Package.SIM                = "11234567810";
            jT1078Package.LogicChannelNumber = 0x01;
            jT1078Package.Label3             = new JT1078Label3(0x10);
            jT1078Package.Timestamp          = 1562085870204;
            jT1078Package.LastIFrameInterval = 0x0280;
            jT1078Package.LastFrameInterval  = 0x0028;
            jT1078Package.Bodies             = "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();
            var hex = JT1078Serializer.Serialize(jT1078Package).ToHexString();

            Assert.Equal("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".Replace(" ", ""), hex);
        }