From bee59639c189655f2cf0b17e8ceb8bd1bda20f00 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Thu, 17 Oct 2019 19:58:36 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9H264=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=E5=99=A8=E7=94=B1=E6=A0=88=E7=B1=BB=E5=9E=8B=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=9B=86=E5=90=88=E7=B1=BB=E5=9E=8B=E8=8E=B7=E5=8F=96NALU?= =?UTF-8?q?=E5=8C=85=202.=E5=AE=8C=E5=96=84=E5=9F=BA=E5=87=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 +++++++++++++++++++++++++-- src/JT1078.Flv.Test/FlvEncoderTest.cs | 1 + src/JT1078.Flv/H264/H264Decoder.cs | 8 ++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0390936..0f8728d 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ Platform=AnyCpu Server=False ### 前提条件 -1. 掌握JT078解码器; +1. 掌握JT078解码; 2. 了解H264解码; 3. 掌握FLV编码; @@ -172,11 +172,36 @@ Platform=AnyCpu Server=False | JT1078属性 | FLV属性 | | :--- | :----| -|Timestamp|JT1078的Timestamp为FLv的累加值(当前的1078包与上一包1078的时间戳相减再进行累加)| +|Timestamp|JT1078的Timestamp为FLv的Timestamp累加值(当前的1078包与上一包1078的时间戳相减再进行累加)| |DataType|JT1078的DataType为FLv的FrameType的值(判断是否为关键帧)| |LastIFrameInterval|JT1078的LastIFrameInterval为FLv(关键帧)的CompositionTime值| |LastFrameInterval|JT1078的LastIFrameInterval为FLv(B/P帧)的CompositionTime值| +### 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) + +``` ini + +BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362 +Intel Core i7-8700K CPU 3.70GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores +.NET Core SDK=3.0.100 + [Host] : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT + Job-QJAHWX : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT + +Platform=AnyCpu Server=False Toolchain=.NET Core 3.0 + +``` +| Method | N | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------- |------- |----------------:|---------------:|---------------:|------------:|----------:|------:|-------------:| +| **EXPGolombReader** | **100** | **12.15 us** | **0.2320 us** | **0.2482 us** | **1.5259** | **-** | **-** | **9.38 KB** | +| H264Decoder | 100 | 1,353.34 us | 10.7795 us | 9.0014 us | 128.9063 | 1.9531 | - | 795.31 KB | +| FlvEncoder | 100 | 215.75 us | 4.3104 us | 8.3047 us | 252.1973 | 3.6621 | - | 1545.31 KB | +| **EXPGolombReader** | **10000** | **1,125.22 us** | **13.9630 us** | **13.0610 us** | **152.3438** | **-** | **-** | **937.5 KB** | +| H264Decoder | 10000 | 136,046.46 us | 2,694.6748 us | 2,388.7590 us | 12750.0000 | 250.0000 | - | 79531.25 KB | +| FlvEncoder | 10000 | 22,609.35 us | 448.6121 us | 1,133.7000 us | 25218.7500 | 343.7500 | - | 154531.25 KB | +| **EXPGolombReader** | **100000** | **11,832.04 us** | **240.9705 us** | **321.6888 us** | **1515.6250** | **-** | **-** | **9375 KB** | +| H264Decoder | 100000 | 1,430,712.75 us | 27,590.0058 us | 27,097.0749 us | 129000.0000 | 3000.0000 | - | 795312.5 KB | +| FlvEncoder | 100000 | 224,622.61 us | 4,087.9082 us | 3,823.8318 us | 252000.0000 | 3666.6667 | - | 1545312.5 KB | + ## 基于JT808扩展的JT1078消息协议 ### JT808扩展协议消息对照表 diff --git a/src/JT1078.Flv.Test/FlvEncoderTest.cs b/src/JT1078.Flv.Test/FlvEncoderTest.cs index 2c1029e..8a8b707 100644 --- a/src/JT1078.Flv.Test/FlvEncoderTest.cs +++ b/src/JT1078.Flv.Test/FlvEncoderTest.cs @@ -31,6 +31,7 @@ namespace JT1078.Flv.Test Package = JT1078Serializer.Merge(package); } Flv.H264.H264Decoder decoder = new Flv.H264.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); diff --git a/src/JT1078.Flv/H264/H264Decoder.cs b/src/JT1078.Flv/H264/H264Decoder.cs index 85ade44..19c8972 100644 --- a/src/JT1078.Flv/H264/H264Decoder.cs +++ b/src/JT1078.Flv/H264/H264Decoder.cs @@ -19,7 +19,7 @@ namespace JT1078.Flv.H264 /// public List ParseNALU(JT1078Package package) { - Stack unitsStacks = new Stack(); + List h264NALUs = new List(); int i=0,state=0; int? lastIndex=null; int length = package.Bodies.Length; @@ -47,7 +47,7 @@ namespace JT1078.Flv.H264 if (lastIndex.HasValue) { var tmp = buffer.Slice(lastIndex.Value, i - state - 1 - lastIndex.Value); - unitsStacks.Push(Create(package, tmp, state)); + h264NALUs.Add(Create(package, tmp, state)); } lastIndex = i; state = 0; @@ -63,9 +63,9 @@ namespace JT1078.Flv.H264 } if (lastIndex.HasValue) { - unitsStacks.Push(Create(package, buffer.Slice(lastIndex.Value), 4)); + h264NALUs.Add(Create(package, buffer.Slice(lastIndex.Value), 4)); } - return unitsStacks.Reverse().ToList(); + return h264NALUs; } private H264NALU Create(JT1078Package package,ReadOnlySpan nalu, int startCodePrefix)