diff --git a/src/JT1078.Flv/Amf/Amf0.cs b/src/JT1078.Flv/Amf/Amf0.cs new file mode 100644 index 0000000..60c4d16 --- /dev/null +++ b/src/JT1078.Flv/Amf/Amf0.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public static class Amf0 + { + public readonly static byte[] Buffer; + + public readonly static byte[] FixedData = new byte[] { 0x6F, 0x6E, 0x4D, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61 }; + static Amf0() + { + Buffer = new byte[13]; + Buffer[0] = 0x02; + Buffer[1] = 0; + Buffer[2] = 10; + Array.Copy(FixedData, 0, Buffer, 3, 10); + } + } +} diff --git a/src/JT1078.Flv/Amf/Amf3.cs b/src/JT1078.Flv/Amf/Amf3.cs new file mode 100644 index 0000000..4d22c65 --- /dev/null +++ b/src/JT1078.Flv/Amf/Amf3.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public static class Amf3 + { + + } +} diff --git a/src/JT1078.Flv/Enums/AacPacketType.cs b/src/JT1078.Flv/Enums/AacPacketType.cs new file mode 100644 index 0000000..ba928de --- /dev/null +++ b/src/JT1078.Flv/Enums/AacPacketType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public enum AacPacketType + { + SequenceHeader, + Raw + } +} diff --git a/src/JT1078.Flv/Enums/CodecId.cs b/src/JT1078.Flv/Enums/CodecId.cs new file mode 100644 index 0000000..2697103 --- /dev/null +++ b/src/JT1078.Flv/Enums/CodecId.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public enum CodecId + { + Jpeg = 1, + H263, + ScreenVideo, + Vp6, + Vp6WithAlpha, + ScreenVideo2, + Avc + } +} diff --git a/src/JT1078.Flv/Enums/FrameType.cs b/src/JT1078.Flv/Enums/FrameType.cs new file mode 100644 index 0000000..a4cdd1b --- /dev/null +++ b/src/JT1078.Flv/Enums/FrameType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public enum FrameType + { + KeyFrame = 1, + InterFrame, + DisposableInterFrame, + GeneratedKeyFrame, + VideoInfoOrCommandFrame + } +} diff --git a/src/JT1078.Flv/FlvArrayPool.cs b/src/JT1078.Flv/FlvArrayPool.cs new file mode 100644 index 0000000..9ba1113 --- /dev/null +++ b/src/JT1078.Flv/FlvArrayPool.cs @@ -0,0 +1,24 @@ +using System.Buffers; + +namespace JT1078.Flv +{ + internal static class FlvArrayPool + { + private readonly static ArrayPool ArrayPool; + + static FlvArrayPool() + { + ArrayPool = ArrayPool.Create(); + } + + public static byte[] Rent(int minimumLength) + { + return ArrayPool.Rent(minimumLength); + } + + public static void Return(byte[] array, bool clearArray = false) + { + ArrayPool.Return(array, clearArray); + } + } +} diff --git a/src/JT1078.Flv/FlvBody.cs b/src/JT1078.Flv/FlvBody.cs new file mode 100644 index 0000000..7084343 --- /dev/null +++ b/src/JT1078.Flv/FlvBody.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public class FlvBody + { + /// + /// 前一个tag的长度 + /// + public uint PreviousTagSize { get; set; } + public FlvTag Tag { get; set; } + } +} diff --git a/src/JT1078.Flv/FlvHeader.cs b/src/JT1078.Flv/FlvHeader.cs new file mode 100644 index 0000000..5a58274 --- /dev/null +++ b/src/JT1078.Flv/FlvHeader.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Buffers.Binary; + +namespace JT1078.Flv +{ + public struct FlvHeader + { + public FlvHeader(bool hasVideo,bool hasAudio) + { + byte audioFlag = 0x01 << 2; + byte videoFlag = 0x01; + Flags = 0x00; + if (hasAudio) Flags |= audioFlag; + if (hasVideo) Flags |= videoFlag; + } + + private byte Flags; + + public ReadOnlySpan ToArray() + { + Span tmp = new byte[9]; + tmp[0] = 0x46; + tmp[1] = 0x4c; + tmp[2] = 0x66; + tmp[3] = 0x01; + tmp[4] = Flags; + BinaryPrimitives.WriteInt32BigEndian(tmp.Slice(5), 9); + return tmp; + } + } +} diff --git a/src/JT1078.Flv/FlvMuxer.cs b/src/JT1078.Flv/FlvMuxer.cs new file mode 100644 index 0000000..034a9a0 --- /dev/null +++ b/src/JT1078.Flv/FlvMuxer.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public class FlvMuxer + { + private readonly FlvHeader VideoFlvHeader = new FlvHeader(true, false); + public void FlvVideoMuxer() + { + + } + } +} diff --git a/src/JT1078.Flv/FlvTag.cs b/src/JT1078.Flv/FlvTag.cs new file mode 100644 index 0000000..64ad666 --- /dev/null +++ b/src/JT1078.Flv/FlvTag.cs @@ -0,0 +1,11 @@ +namespace JT1078.Flv +{ + public class FlvTag + { + public FlvTagHeader TagHeader { get; set; } + /// + /// 根据tag类型 + /// + public byte[] TagData { get; set; } + } +} \ No newline at end of file diff --git a/src/JT1078.Flv/FlvTagHeader.cs b/src/JT1078.Flv/FlvTagHeader.cs new file mode 100644 index 0000000..d298727 --- /dev/null +++ b/src/JT1078.Flv/FlvTagHeader.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT1078.Flv +{ + public class FlvTagHeader + { + public byte Type { get; set; } + /// + /// Tag Data部分大小 + /// 3个字节 + /// + public uint DataSize { get; set; } + /// + /// Tag时间戳 + /// 3个字节 + /// + public uint Timestamp { get; set; } + public byte TimestampExt { get; set; } = 0; + /// + /// stream id 总是0 + /// 3个字节 + /// + public uint StreamId { get; set; } = 0; + } +} diff --git a/src/JT1078.Flv/JT1078.Flv.csproj b/src/JT1078.Flv/JT1078.Flv.csproj new file mode 100644 index 0000000..474afd8 --- /dev/null +++ b/src/JT1078.Flv/JT1078.Flv.csproj @@ -0,0 +1,10 @@ + + + + netstandard2.0 + + + + + + diff --git a/src/JT1078.sln b/src/JT1078.sln index db25bc3..7aebf90 100644 --- a/src/JT1078.sln +++ b/src/JT1078.sln @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.WebApiTest", "JT808.Protocol.Extensions.WebApiTest\JT808.Protocol.Extensions.WebApiTest.csproj", "{9DB37370-AC73-434B-9CE2-6659321858C8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT1078.Flv", "JT1078.Flv\JT1078.Flv.csproj", "{33E54FFC-7D91-42E5-9DC1-853738AB8980}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -65,6 +67,10 @@ Global {9DB37370-AC73-434B-9CE2-6659321858C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {9DB37370-AC73-434B-9CE2-6659321858C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {9DB37370-AC73-434B-9CE2-6659321858C8}.Release|Any CPU.Build.0 = Release|Any CPU + {33E54FFC-7D91-42E5-9DC1-853738AB8980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33E54FFC-7D91-42E5-9DC1-853738AB8980}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33E54FFC-7D91-42E5-9DC1-853738AB8980}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33E54FFC-7D91-42E5-9DC1-853738AB8980}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE