diff --git a/.gitignore b/.gitignore
index 92bb157..47e7f0c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -333,3 +333,4 @@ ASALocalRun/
/src/JT1078.Flv.Test/H264/JT1078_5.txt
/doc/tools/FlvAnalyzer.exe
/doc/tools/EasyICE_2.7.0.2
+/doc/tools/mp4parse
diff --git a/doc/tools/mp4parse.zip b/doc/tools/mp4parse.zip
new file mode 100644
index 0000000..95c33d2
Binary files /dev/null and b/doc/tools/mp4parse.zip differ
diff --git a/src/JT1078.FMp4.Test/Boxs/FileTypeBox_Test.cs b/src/JT1078.FMp4.Test/Boxs/FileTypeBox_Test.cs
new file mode 100644
index 0000000..af1876d
--- /dev/null
+++ b/src/JT1078.FMp4.Test/Boxs/FileTypeBox_Test.cs
@@ -0,0 +1,28 @@
+using JT1078.FMp4.MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using JT1078.Protocol.Extensions;
+
+namespace JT1078.FMp4.Test.Boxs
+{
+ public class FileTypeBox_Test
+ {
+ ///
+ /// 使用doc/video/demo.mp4
+ ///
+ [Fact]
+ public void Test1()
+ {
+ FileTypeBox fileTypeBox = new FileTypeBox();
+ fileTypeBox.MajorBrand = "mp42";
+ fileTypeBox.CompatibleBrands.Add("mp42");
+ fileTypeBox.CompatibleBrands.Add("isom");
+ FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x18]);
+ fileTypeBox.ToBuffer(ref writer);
+ var hex=writer.FlushAndGetArray().ToHexString();
+ Assert.Equal("00000018667479706d703432000000006d70343269736f6d".ToUpper(), hex);
+ }
+ }
+}
diff --git a/src/JT1078.FMp4.Test/UnitTest1.cs b/src/JT1078.FMp4.Test/UnitTest1.cs
deleted file mode 100644
index cea9638..0000000
--- a/src/JT1078.FMp4.Test/UnitTest1.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using Xunit;
-
-namespace JT1078.FMp4.Test
-{
- public class UnitTest1
- {
- [Fact]
- public void Test1()
- {
-
- }
- }
-}
diff --git a/src/JT1078.FMp4/Boxs/FileTypeBox.cs b/src/JT1078.FMp4/Boxs/FileTypeBox.cs
index 84b5d52..a0cedd9 100644
--- a/src/JT1078.FMp4/Boxs/FileTypeBox.cs
+++ b/src/JT1078.FMp4/Boxs/FileTypeBox.cs
@@ -1,4 +1,6 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
@@ -8,7 +10,7 @@ namespace JT1078.FMp4
///
/// ftyp 盒子相当于就是该 mp4 的纲领性说明。即,告诉解码器它的基本解码版本,兼容格式。简而言之,就是用来告诉客户端,该 MP4 的使用的解码标准。通常,ftyp 都是放在 MP4 的开头。
///
- public class FileTypeBox : Mp4Box
+ public class FileTypeBox : Mp4Box, IFMp4MessagePackFormatter
{
public FileTypeBox() : base("ftyp")
{
@@ -22,11 +24,26 @@ namespace JT1078.FMp4
/// 最低兼容版本
/// 4位
///
- public uint MinorVersion { get; set; }
+ public string MinorVersion { get; set; } = "\0\0\0\0";
///
/// 和MajorBrand类似,通常是针对 MP4 中包含的额外格式,比如,AVC,AAC 等相当于的音视频解码格式。
/// 4位*n
///
- public List CompatibleBrands { get; set; }
+ public List CompatibleBrands { get; set; } = new List();
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ ToBuffer(ref writer,out int sizePosition);
+ writer.WriteASCII(MajorBrand);
+ writer.WriteASCII(MinorVersion);
+ if(CompatibleBrands!=null && CompatibleBrands.Count > 0)
+ {
+ foreach(var item in CompatibleBrands)
+ {
+ writer.WriteASCII(item);
+ }
+ }
+ writer.WriteUInt32Return((uint)(writer.GetCurrentPosition()- sizePosition), sizePosition);
+ }
}
}
diff --git a/src/JT1078.FMp4/FullBox.cs b/src/JT1078.FMp4/FullBox.cs
index 83abdb7..3c9cbc5 100644
--- a/src/JT1078.FMp4/FullBox.cs
+++ b/src/JT1078.FMp4/FullBox.cs
@@ -11,7 +11,13 @@ namespace JT1078.FMp4
Version = version;
Flags = flags;
}
+ ///
+ /// unsigned int(8)
+ ///
public byte Version { get; set; }
+ ///
+ /// bit(24)
+ ///
public uint Flags { get; set; }
}
}
diff --git a/src/JT1078.FMp4/JT1078.FMp4.xml b/src/JT1078.FMp4/JT1078.FMp4.xml
index 119cc17..4f8615f 100644
--- a/src/JT1078.FMp4/JT1078.FMp4.xml
+++ b/src/JT1078.FMp4/JT1078.FMp4.xml
@@ -348,6 +348,16 @@
日期限制于2000年
+
+
+ unsigned int(8)
+
+
+
+
+ bit(24)
+
+
@@ -362,6 +372,23 @@
+
+
+ 盒子大小
+
+
+
+
+ 盒子类型
+
+
+
+
+
+
+
+
+
diff --git a/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs b/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
index 7d80f21..9dc34df 100644
--- a/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
+++ b/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
@@ -43,6 +43,14 @@ namespace JT1078.FMp4.MessagePack
BinaryPrimitives.WriteUInt32BigEndian(writer.Free, value);
writer.Advance(4);
}
+
+ public void WriteASCII(string value)
+ {
+ var data = Encoding.ASCII.GetBytes(value);
+ data.CopyTo(writer.Free);
+ writer.Advance(data.Length);
+ }
+
public void WriteArray(ReadOnlySpan src)
{
src.CopyTo(writer.Free);
@@ -55,6 +63,24 @@ namespace JT1078.FMp4.MessagePack
tmp.CopyTo(writer.Free);
writer.Advance(count);
}
+
+ public void WriteUInt16Return(ushort value, int position)
+ {
+ BinaryPrimitives.WriteUInt16BigEndian(writer.Written.Slice(position, 2), value);
+ }
+ public void WriteInt32Return(int value, int position)
+ {
+ BinaryPrimitives.WriteInt32BigEndian(writer.Written.Slice(position, 4), value);
+ }
+ public void WriteUInt32Return(uint value, int position)
+ {
+ BinaryPrimitives.WriteUInt32BigEndian(writer.Written.Slice(position, 4), value);
+ }
+ public void WriteByteReturn(byte value, int position)
+ {
+ writer.Written[position] = value;
+ }
+
public int GetCurrentPosition()
{
return writer.WrittenCount;
diff --git a/src/JT1078.FMp4/Mp4Box.cs b/src/JT1078.FMp4/Mp4Box.cs
index 3d39821..326f907 100644
--- a/src/JT1078.FMp4/Mp4Box.cs
+++ b/src/JT1078.FMp4/Mp4Box.cs
@@ -1,4 +1,5 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
@@ -6,22 +7,57 @@ namespace JT1078.FMp4
{
public abstract class Mp4Box
{
- public const string UUID = "uuid";
+ //public const string UUID = "uuid";
+
+ public const int FixedSizeLength = 4;
+
public Mp4Box(string boxType)
{
BoxType = boxType;
}
- public Mp4Box(string boxType,string extendedType)
+ /////
+ ///// 不考虑自定义
+ /////
+ //public Mp4Box(string boxType, string extendedType)
+ //{
+ // BoxType = boxType;
+ // if (boxType == UUID)
+ // {
+ // UserType = extendedType;
+ // }
+ //}
+ ///
+ /// 盒子大小
+ ///
+ public uint Size { get; set; }
+
+ /////
+ ///// 不考虑size==1
+ ///// size==1
+ /////
+ //public ulong SizeLarge { get; set; }
+
+ ///
+ /// 盒子类型
+ ///
+ public string BoxType { get; set; }
+
+ /////
+ ///// 不考虑boxtype==‘uuid'
+ ///// boxtype==‘uuid’
+ ///// int(8)[16]
+ /////
+ //public string UserType { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void ToBuffer(ref FMp4MessagePackWriter writer, out int sizePosition)
{
- BoxType = boxType;
- if(boxType == UUID)
- {
- UserType = extendedType;
- }
+ writer.Skip(FixedSizeLength, out sizePosition);
+ writer.WriteASCII(BoxType);
}
- public string BoxType { get; set; }
- public string UserType { get; set; }
- public uint Size { get; set; }
- public ulong SizeLarge{get;set;}
}
}