diff --git a/src/JT1078.FMp4.Test/Boxs/DataInformationBox_Test.cs b/src/JT1078.FMp4.Test/Boxs/DataInformationBox_Test.cs
new file mode 100644
index 0000000..c6530a3
--- /dev/null
+++ b/src/JT1078.FMp4.Test/Boxs/DataInformationBox_Test.cs
@@ -0,0 +1,42 @@
+using JT1078.FMp4.MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using JT1078.Protocol.Extensions;
+using JT1078.FMp4.Enums;
+
+namespace JT1078.FMp4.Test.Boxs
+{
+ public class DataInformationBox_Test
+ {
+ ///
+ /// 使用doc/video/demo.mp4
+ ///
+ [Fact]
+ public void Test1()
+ {
+ // 00 00 00 24--box size 36
+ // 64 69 6e 66--box type dinf
+ //--------------
+ // 00 00 00 1c--box size 28
+ // 64 72 65 66--box type dref
+ // 00--version
+ // 00 00 00--flags
+ // 00 00 00 01--entry_count
+ //----------------
+ // 00 00 00 0c--box size 12
+ // 75 72 6c 20--box type "url " 有个空格
+ // 00--version
+ // 00 00 01--flags
+ DataInformationBox dataInformationBox = new DataInformationBox();
+ DataReferenceBox dataReferenceBox = new DataReferenceBox();
+ dataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(version: 0, flags: 1));
+ dataInformationBox.DataReferenceBox = dataReferenceBox;
+ FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[48]);
+ dataInformationBox.ToBuffer(ref writer);
+ var hex = writer.FlushAndGetArray().ToHexString();
+ Assert.Equal("0000002464696e660000001c6472656600000000000000010000000c75726c2000000001".ToUpper(), hex);
+ }
+ }
+}
diff --git a/src/JT1078.FMp4.Test/Boxs/DataReferenceBox_Test.cs b/src/JT1078.FMp4.Test/Boxs/DataReferenceBox_Test.cs
new file mode 100644
index 0000000..8cc56dc
--- /dev/null
+++ b/src/JT1078.FMp4.Test/Boxs/DataReferenceBox_Test.cs
@@ -0,0 +1,37 @@
+using JT1078.FMp4.MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using JT1078.Protocol.Extensions;
+using JT1078.FMp4.Enums;
+
+namespace JT1078.FMp4.Test.Boxs
+{
+ public class DataReferenceBox_Test
+ {
+ ///
+ /// 使用doc/video/demo.mp4
+ ///
+ [Fact]
+ public void Test1()
+ {
+// 00 00 00 1c--box size 28
+// 64 72 65 66--box type dref
+// 00--version
+// 00 00 00--flags
+// 00 00 00 01--entry_count
+//----------------
+// 00 00 00 0c--box size 12
+// 75 72 6c 20--box type "url " 有个空格
+// 00--version
+// 00 00 01--flags
+ DataReferenceBox dataReferenceBox = new DataReferenceBox();
+ dataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(version:0,flags:1));
+ FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[48]);
+ dataReferenceBox.ToBuffer(ref writer);
+ var hex = writer.FlushAndGetArray().ToHexString();
+ Assert.Equal("0000001c6472656600000000000000010000000c75726c2000000001".ToUpper(), hex);
+ }
+ }
+}
diff --git a/src/JT1078.FMp4.Test/Boxs/HandlerBox_Test.cs b/src/JT1078.FMp4.Test/Boxs/HandlerBox_Test.cs
new file mode 100644
index 0000000..d31fc32
--- /dev/null
+++ b/src/JT1078.FMp4.Test/Boxs/HandlerBox_Test.cs
@@ -0,0 +1,38 @@
+using JT1078.FMp4.MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xunit;
+using JT1078.Protocol.Extensions;
+using JT1078.FMp4.Enums;
+
+namespace JT1078.FMp4.Test.Boxs
+{
+ public class HandlerBox_Test
+ {
+ ///
+ /// 使用doc/video/demo.mp4
+ ///
+ [Fact]
+ public void Test1()
+ {
+ //00 00 00 35--box size
+ //68 64 6c 72--box type hdlr
+ //00--version
+ //00 00 00--flags
+ //00 00 00 00--pre_defined
+ //73 6f 75 6e--handler_type
+ //00 00 00 00--reserved3 - 1
+ //00 00 00 00--reserved3 - 2
+ //00 00 00 00--reserved3 - 3
+ //42 65 6e 74 6f 34 20 53 6f 75 6e 64 20 48 61 6e 64 6c 65 72 00--Name
+ HandlerBox handlerBox = new HandlerBox(version:0,flags:0);
+ handlerBox.HandlerType = HandlerType.soun;
+ handlerBox.Name = Encoding.UTF8.GetString("42 65 6e 74 6f 34 20 53 6f 75 6e 64 20 48 61 6e 64 6c 65 72 00".ToHexBytes());
+ FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x35]);
+ handlerBox.ToBuffer(ref writer);
+ var hex = writer.FlushAndGetArray().ToHexString();
+ Assert.Equal("0000003568646c720000000000000000736f756e00000000000000000000000042656e746f3420536f756e642048616e646c657200".ToUpper(), hex);
+ }
+ }
+}
diff --git a/src/JT1078.FMp4/Boxs/AVCConfigurationBox.cs b/src/JT1078.FMp4/Boxs/AVCConfigurationBox.cs
index a76e449..d2c71b2 100644
--- a/src/JT1078.FMp4/Boxs/AVCConfigurationBox.cs
+++ b/src/JT1078.FMp4/Boxs/AVCConfigurationBox.cs
@@ -1,14 +1,63 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class AVCConfigurationBox : Mp4Box
+ ///
+ /// avcC
+ ///
+ public class AVCConfigurationBox : Mp4Box,IFMp4MessagePackFormatter
{
+ ///
+ /// avcC
+ ///
public AVCConfigurationBox() : base("avcC")
{
}
- public AVCDecoderConfigurationRecord AVCDecoderConfigurationRecord { get; set; }
+
+ //AVCDecoderConfigurationRecord 结构的定义:
+ //aligned(8) class AVCDecoderConfigurationRecord
+ //{
+ //unsigned int (8) configurationVersion = 1;
+ //unsigned int (8) AVCProfileIndication;
+ //unsigned int (8) profile_compatibility;
+ //unsigned int (8) AVCLevelIndication;
+ //bit(6) reserved = ‘111111’b;
+ //unsigned int (2) lengthSizeMinusOne;
+ //bit(3) reserved = ‘111’b;
+ //unsigned int (5) numOfSequenceParameterSets;
+ //for (i=0; i SPS { get; set; }
+ public byte[] SPSBuffer { get; set; }
+ public byte NumOfPictureParameterSets { get; set; } = 1;
+ public List<(ushort PictureParameterSetLength,byte[] PictureParameterSetNALUnit)> PPS { get; set; }
+ public byte[] PPSBuffer { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ //todo:AVCConfigurationBox
+
+
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/ChunkOffsetBox.cs b/src/JT1078.FMp4/Boxs/ChunkOffsetBox.cs
index ea8f029..f8c0b97 100644
--- a/src/JT1078.FMp4/Boxs/ChunkOffsetBox.cs
+++ b/src/JT1078.FMp4/Boxs/ChunkOffsetBox.cs
@@ -1,10 +1,12 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class ChunkOffsetBox : FullBox
+ public class ChunkOffsetBox : FullBox, IFMp4MessagePackFormatter
{
public ChunkOffsetBox( byte version=0, uint flags=0) : base("stco", version, flags)
{
@@ -15,5 +17,10 @@ namespace JT1078.FMp4
/// length:EntryCount
///
public List ChunkOffset { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/CleanApertureBox.cs b/src/JT1078.FMp4/Boxs/CleanApertureBox.cs
index cf0f4f0..7261b1e 100644
--- a/src/JT1078.FMp4/Boxs/CleanApertureBox.cs
+++ b/src/JT1078.FMp4/Boxs/CleanApertureBox.cs
@@ -1,11 +1,19 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class CleanApertureBox : Mp4Box
+ ///
+ /// clap
+ ///
+ public class CleanApertureBox : Mp4Box,IFMp4MessagePackFormatter
{
+ ///
+ /// clap
+ ///
public CleanApertureBox() : base("clap")
{
}
@@ -18,5 +26,19 @@ namespace JT1078.FMp4
public uint HorizOffD { get; set; }
public uint VertOffN { get; set; }
public uint VertOffD { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ writer.WriteUInt32(CleanApertureWidthN);
+ writer.WriteUInt32(CleanApertureWidthD);
+ writer.WriteUInt32(CleanApertureHeightN);
+ writer.WriteUInt32(CleanApertureHeightD);
+ writer.WriteUInt32(HorizOffN);
+ writer.WriteUInt32(HorizOffD);
+ writer.WriteUInt32(VertOffN);
+ writer.WriteUInt32(VertOffD);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/CompositionOffsetBox.cs b/src/JT1078.FMp4/Boxs/CompositionOffsetBox.cs
index 82a94ab..57700a6 100644
--- a/src/JT1078.FMp4/Boxs/CompositionOffsetBox.cs
+++ b/src/JT1078.FMp4/Boxs/CompositionOffsetBox.cs
@@ -1,10 +1,12 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class CompositionOffsetBox : FullBox
+ public class CompositionOffsetBox : FullBox, IFMp4MessagePackFormatter
{
public CompositionOffsetBox(byte version=0, uint flags=0) : base("ctts", version, flags)
{
@@ -13,6 +15,11 @@ namespace JT1078.FMp4
public List CompositionOffsetInfos { get; set; }
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
public class CompositionOffsetInfo
{
public uint SampleCount { get; set; }
diff --git a/src/JT1078.FMp4/Boxs/DataEntryBox.cs b/src/JT1078.FMp4/Boxs/DataEntryBox.cs
index 325f6dc..6fa5308 100644
--- a/src/JT1078.FMp4/Boxs/DataEntryBox.cs
+++ b/src/JT1078.FMp4/Boxs/DataEntryBox.cs
@@ -1,13 +1,17 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public abstract class DataEntryBox : FullBox
+ public abstract class DataEntryBox : FullBox,IFMp4MessagePackFormatter
{
public DataEntryBox(string boxType, byte version, uint flags) : base(boxType, version, flags)
{
}
+
+ public abstract void ToBuffer(ref FMp4MessagePackWriter writer);
}
}
diff --git a/src/JT1078.FMp4/Boxs/DataEntryUrlBox.cs b/src/JT1078.FMp4/Boxs/DataEntryUrlBox.cs
index bcf2754..75a79a2 100644
--- a/src/JT1078.FMp4/Boxs/DataEntryUrlBox.cs
+++ b/src/JT1078.FMp4/Boxs/DataEntryUrlBox.cs
@@ -1,4 +1,5 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
@@ -15,5 +16,16 @@ namespace JT1078.FMp4
}
public string Location { get; set; }
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ if (!string.IsNullOrEmpty(Location))
+ {
+ writer.WriteUTF8(Location);
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/DataEntryUrnBox.cs b/src/JT1078.FMp4/Boxs/DataEntryUrnBox.cs
index 340378a..967054a 100644
--- a/src/JT1078.FMp4/Boxs/DataEntryUrnBox.cs
+++ b/src/JT1078.FMp4/Boxs/DataEntryUrnBox.cs
@@ -1,4 +1,5 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
@@ -15,5 +16,18 @@ namespace JT1078.FMp4
public string Name { get; set; }
public string Location { get; set; }
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ if (!string.IsNullOrEmpty(Name))
+ {
+ writer.WriteUTF8(Name);
+ }
+ if (!string.IsNullOrEmpty(Location))
+ {
+ writer.WriteUTF8(Location);
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/DataInformationBox.cs b/src/JT1078.FMp4/Boxs/DataInformationBox.cs
index 22a58e8..6a590c1 100644
--- a/src/JT1078.FMp4/Boxs/DataInformationBox.cs
+++ b/src/JT1078.FMp4/Boxs/DataInformationBox.cs
@@ -1,14 +1,32 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class DataInformationBox : Mp4Box
+ ///
+ /// dinf
+ ///
+ public class DataInformationBox : Mp4Box, IFMp4MessagePackFormatter
{
+ ///
+ /// dinf
+ ///
public DataInformationBox() : base("dinf")
{
}
+ ///
+ /// dref
+ ///
public DataReferenceBox DataReferenceBox { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ DataReferenceBox.ToBuffer(ref writer);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/DataReferenceBox.cs b/src/JT1078.FMp4/Boxs/DataReferenceBox.cs
index 3f41d1c..dcbb6aa 100644
--- a/src/JT1078.FMp4/Boxs/DataReferenceBox.cs
+++ b/src/JT1078.FMp4/Boxs/DataReferenceBox.cs
@@ -1,11 +1,21 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class DataReferenceBox : FullBox
+ ///
+ /// dref
+ ///
+ public class DataReferenceBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// dref
+ ///
+ ///
+ ///
public DataReferenceBox(byte version=0, uint flags=0) : base("dref", version, flags)
{
}
@@ -15,6 +25,25 @@ namespace JT1078.FMp4
///
/// length:EntryCount
///
- public List DataEntryBoxes { get; set; }
+ public List DataEntryBoxes { get; set; }= new List();
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ if (DataEntryBoxes!=null && DataEntryBoxes.Count > 0)
+ {
+ writer.WriteUInt32((uint)DataEntryBoxes.Count);
+ foreach(var item in DataEntryBoxes)
+ {
+ item.ToBuffer(ref writer);
+ }
+ }
+ else
+ {
+ writer.WriteUInt32(0);
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/FileTypeBox.cs b/src/JT1078.FMp4/Boxs/FileTypeBox.cs
index 65a2392..a0699b5 100644
--- a/src/JT1078.FMp4/Boxs/FileTypeBox.cs
+++ b/src/JT1078.FMp4/Boxs/FileTypeBox.cs
@@ -12,6 +12,9 @@ namespace JT1078.FMp4
///
public class FileTypeBox : Mp4Box, IFMp4MessagePackFormatter
{
+ ///
+ /// ftyp
+ ///
public FileTypeBox() : base("ftyp")
{
}
diff --git a/src/JT1078.FMp4/Boxs/HandlerBox.cs b/src/JT1078.FMp4/Boxs/HandlerBox.cs
index 5f39a8e..a5400e3 100644
--- a/src/JT1078.FMp4/Boxs/HandlerBox.cs
+++ b/src/JT1078.FMp4/Boxs/HandlerBox.cs
@@ -1,18 +1,50 @@
-using System;
+using JT1078.FMp4.Enums;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class HandlerBox : FullBox
+ ///
+ /// hdlr
+ ///
+ public class HandlerBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// hdlr
+ ///
+ ///
+ ///
public HandlerBox(byte version=0, uint flags=0) : base("hdlr", version, flags)
{
}
public uint PreDefined { get; set; }
- public string HandlerType { get; set; }
+ public HandlerType HandlerType { get; set; }
public uint[] Reserved { get; set; } = new uint[3];
public string Name { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ writer.WriteUInt32(PreDefined);
+ if(HandlerType== HandlerType.none)
+ {
+ writer.WriteASCII("null");
+ }
+ else
+ {
+ writer.WriteASCII(HandlerType.ToString());
+ }
+ foreach(var r in Reserved)
+ {
+ writer.WriteUInt32(r);
+ }
+ writer.WriteUTF8(Name??"\0");
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/MPEG4BitRateBox.cs b/src/JT1078.FMp4/Boxs/MPEG4BitRateBox.cs
index 2aae852..db49761 100644
--- a/src/JT1078.FMp4/Boxs/MPEG4BitRateBox.cs
+++ b/src/JT1078.FMp4/Boxs/MPEG4BitRateBox.cs
@@ -1,11 +1,19 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class MPEG4BitRateBox : Mp4Box
+ ///
+ /// btrt
+ ///
+ public class MPEG4BitRateBox : Mp4Box, IFMp4MessagePackFormatter
{
+ ///
+ /// btrt
+ ///
public MPEG4BitRateBox() : base("btrt")
{
}
@@ -13,5 +21,14 @@ namespace JT1078.FMp4
public uint BufferSizeDB { get; set; }
public uint MaxBitRate { get; set; }
public uint AvgBitRate { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ writer.WriteUInt32(BufferSizeDB);
+ writer.WriteUInt32(MaxBitRate);
+ writer.WriteUInt32(AvgBitRate);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/MediaBox.cs b/src/JT1078.FMp4/Boxs/MediaBox.cs
index e4361ba..eff4e13 100644
--- a/src/JT1078.FMp4/Boxs/MediaBox.cs
+++ b/src/JT1078.FMp4/Boxs/MediaBox.cs
@@ -4,14 +4,28 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// mdia
+ ///
public class MediaBox : Mp4Box
{
+ ///
+ /// mdia
+ ///
public MediaBox() : base("mdia")
{
}
-
+ ///
+ /// mdhd
+ ///
public MediaHeaderBox MediaHeaderBox { get; set; }
+ ///
+ /// hdlr
+ ///
public HandlerBox HandlerBox { get; set; }
+ ///
+ /// minf
+ ///
public MediaInformationBox MediaInformationBox { get; set; }
}
}
diff --git a/src/JT1078.FMp4/Boxs/MediaHeaderBox.cs b/src/JT1078.FMp4/Boxs/MediaHeaderBox.cs
index b2d3f5f..db67b8f 100644
--- a/src/JT1078.FMp4/Boxs/MediaHeaderBox.cs
+++ b/src/JT1078.FMp4/Boxs/MediaHeaderBox.cs
@@ -6,8 +6,16 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// mdhd
+ ///
public class MediaHeaderBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// mdhd
+ ///
+ ///
+ ///
public MediaHeaderBox(byte version, uint flags=0) : base("mdhd", version, flags)
{
}
@@ -27,7 +35,7 @@ namespace JT1078.FMp4
public void ToBuffer(ref FMp4MessagePackWriter writer)
{
Start(ref writer);
- WriterToBuffer(ref writer);
+ WriterFullBoxToBuffer(ref writer);
if (Version == 1)
{
writer.WriteUInt64(CreationTime);
diff --git a/src/JT1078.FMp4/Boxs/MediaInformationBox.cs b/src/JT1078.FMp4/Boxs/MediaInformationBox.cs
index 265a529..7e56a3a 100644
--- a/src/JT1078.FMp4/Boxs/MediaInformationBox.cs
+++ b/src/JT1078.FMp4/Boxs/MediaInformationBox.cs
@@ -1,16 +1,37 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class MediaInformationBox : Mp4Box
+ ///
+ /// minf
+ ///
+ public class MediaInformationBox : Mp4Box,IFMp4MessagePackFormatter
{
+ ///
+ /// minf
+ ///
public MediaInformationBox() : base("minf")
{
}
- public FullBox MediaHeaderBox { get; set; }
+ ///
+ /// dinf
+ ///
public DataInformationBox DataInformationBox { get; set; }
+ ///
+ /// stbl
+ ///
public SampleTableBox SampleTableBox { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ DataInformationBox.ToBuffer(ref writer);
+ SampleTableBox.ToBuffer(ref writer);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/MovieBox.cs b/src/JT1078.FMp4/Boxs/MovieBox.cs
index 9a78f7c..eace22e 100644
--- a/src/JT1078.FMp4/Boxs/MovieBox.cs
+++ b/src/JT1078.FMp4/Boxs/MovieBox.cs
@@ -1,17 +1,42 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace JT1078.FMp4
{
- public class MovieBox : Mp4Box
+ ///
+ /// moov
+ ///
+ public class MovieBox : Mp4Box,IFMp4MessagePackFormatter
{
+ ///
+ /// moov
+ ///
public MovieBox() : base("moov")
{
}
+ ///
+ /// mvhd
+ ///
public MovieHeaderBox MovieHeaderBox { get; set; }
+ ///
+ /// trak
+ ///
public TrackBox TrackBox { get; set; }
- public MovieExtendsBox MovieExtendsBox { get; set; }
+ ///
+ /// trak
+ ///
+ public MovieExtendsBox MovieExtendsBox { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ MovieHeaderBox.ToBuffer(ref writer);
+
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/MovieExtendsBox.cs b/src/JT1078.FMp4/Boxs/MovieExtendsBox.cs
index a674e4a..d7f966d 100644
--- a/src/JT1078.FMp4/Boxs/MovieExtendsBox.cs
+++ b/src/JT1078.FMp4/Boxs/MovieExtendsBox.cs
@@ -4,8 +4,14 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// mvex
+ ///
public class MovieExtendsBox : Mp4Box
{
+ ///
+ /// mvex
+ ///
public MovieExtendsBox() : base("mvex")
{
}
diff --git a/src/JT1078.FMp4/Boxs/MovieHeaderBox.cs b/src/JT1078.FMp4/Boxs/MovieHeaderBox.cs
index 20ae6c0..e330ccc 100644
--- a/src/JT1078.FMp4/Boxs/MovieHeaderBox.cs
+++ b/src/JT1078.FMp4/Boxs/MovieHeaderBox.cs
@@ -6,8 +6,16 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// mvhd
+ ///
public class MovieHeaderBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// mvhd
+ ///
+ ///
+ ///
public MovieHeaderBox(byte version, uint flags=0) : base("mvhd", version, flags)
{
}
@@ -25,7 +33,7 @@ namespace JT1078.FMp4
public void ToBuffer(ref FMp4MessagePackWriter writer)
{
Start(ref writer);
- WriterToBuffer(ref writer);
+ WriterFullBoxToBuffer(ref writer);
if (Version == 1)
{
writer.WriteUInt64(CreationTime);
diff --git a/src/JT1078.FMp4/Boxs/PixelAspectRatioBox.cs b/src/JT1078.FMp4/Boxs/PixelAspectRatioBox.cs
index 4278016..41b1625 100644
--- a/src/JT1078.FMp4/Boxs/PixelAspectRatioBox.cs
+++ b/src/JT1078.FMp4/Boxs/PixelAspectRatioBox.cs
@@ -1,15 +1,30 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class PixelAspectRatioBox : Mp4Box
+ ///
+ /// pasp
+ ///
+ public class PixelAspectRatioBox : Mp4Box, IFMp4MessagePackFormatter
{
+ ///
+ /// pasp
+ ///
public PixelAspectRatioBox() : base("pasp")
{
}
public uint HSpacing { get; set; }
public uint VSpacing { get; set; }
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ writer.WriteUInt32(HSpacing);
+ writer.WriteUInt32(VSpacing);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/SampleDescriptionBox.cs b/src/JT1078.FMp4/Boxs/SampleDescriptionBox.cs
index dcdb2fa..e320b16 100644
--- a/src/JT1078.FMp4/Boxs/SampleDescriptionBox.cs
+++ b/src/JT1078.FMp4/Boxs/SampleDescriptionBox.cs
@@ -1,20 +1,47 @@
-using JT1078.FMp4.Samples;
+using JT1078.FMp4.Enums;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using JT1078.FMp4.Samples;
using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class SampleDescriptionBox : FullBox
+ ///
+ /// stsd
+ ///
+ public class SampleDescriptionBox : FullBox, IFMp4MessagePackFormatter
{
- public string HandlerType { get; set; }
- public SampleDescriptionBox(string handlerType,byte version=0, uint flags=0) : base("stsd", version, flags)
+ ///
+ /// stsd
+ ///
+ ///
+ ///
+ ///
+ public SampleDescriptionBox(HandlerType handlerType,byte version=0, uint flags=0) : base("stsd", version, flags)
{
HandlerType = handlerType;
}
-
+ public HandlerType HandlerType { get; set; }
public uint EntryCount { get; set; }
-
public List SampleEntries { get; set; }
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ if(SampleEntries!=null && SampleEntries.Count > 0)
+ {
+ foreach(var item in SampleEntries)
+ {
+ item.ToBuffer(ref writer);
+ }
+ }
+ else
+ {
+ writer.WriteUInt32(0);
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/SampleTableBox.cs b/src/JT1078.FMp4/Boxs/SampleTableBox.cs
index dad6775..b95f69d 100644
--- a/src/JT1078.FMp4/Boxs/SampleTableBox.cs
+++ b/src/JT1078.FMp4/Boxs/SampleTableBox.cs
@@ -1,29 +1,63 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class SampleTableBox : Mp4Box
+ ///
+ /// stbl
+ ///
+ public class SampleTableBox : Mp4Box, IFMp4MessagePackFormatter
{
+ ///
+ /// stbl
+ ///
public SampleTableBox() : base("stbl")
{
}
+ ///
+ /// stsd
+ ///
public SampleDescriptionBox SampleDescriptionBox { get; set; }
+ ///
+ /// stts
+ ///
public TimeToSampleBox TimeToSampleBox { get; set; }
+ ///
+ /// ctts
+ ///
public CompositionOffsetBox CompositionOffsetBox { get; set; }
+ ///
+ /// stsc
+ ///
public SampleToChunkBox SampleToChunkBox { get; set; }
- public SampleSizeBox SampleSizeBox { get; set; }
- public CompactSampleSizeBox CompactSampleSizeBox { get; set; }
+ //public SampleSizeBox SampleSizeBox { get; set; }
+ //public CompactSampleSizeBox CompactSampleSizeBox { get; set; }
+ ///
+ /// stco
+ ///
public ChunkOffsetBox ChunkOffsetBox { get; set; }
- public ChunkLargeOffsetBox ChunkLargeOffsetBox { get; set; }
- public SyncSampleBox SyncSampleBox { get; set; }
- public ShadowSyncSampleBox ShadowSyncSampleBox { get; set; }
- public PaddingBitsBox PaddingBitsBox { get; set; }
- public DegradationPriorityBox DegradationPriorityBox { get; set; }
- public SampleDependencyTypeBox SampleDependencyTypeBox { get; set; }
- public SampleToGroupBox SampleToGroupBox { get; set; }
- public SampleGroupDescriptionBox SampleGroupDescriptionBox { get; set; }
- public SubSampleInformationBox SubSampleInformationBox { get; set; }
+ //public ChunkLargeOffsetBox ChunkLargeOffsetBox { get; set; }
+ //public SyncSampleBox SyncSampleBox { get; set; }
+ //public ShadowSyncSampleBox ShadowSyncSampleBox { get; set; }
+ //public PaddingBitsBox PaddingBitsBox { get; set; }
+ //public DegradationPriorityBox DegradationPriorityBox { get; set; }
+ //public SampleDependencyTypeBox SampleDependencyTypeBox { get; set; }
+ //public SampleToGroupBox SampleToGroupBox { get; set; }
+ //public SampleGroupDescriptionBox SampleGroupDescriptionBox { get; set; }
+ //public SubSampleInformationBox SubSampleInformationBox { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ SampleDescriptionBox.ToBuffer(ref writer);
+ TimeToSampleBox.ToBuffer(ref writer);
+ CompositionOffsetBox.ToBuffer(ref writer);
+ SampleToChunkBox.ToBuffer(ref writer);
+ ChunkOffsetBox.ToBuffer(ref writer);
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/SampleToChunkBox.cs b/src/JT1078.FMp4/Boxs/SampleToChunkBox.cs
index 7d04a70..f93c996 100644
--- a/src/JT1078.FMp4/Boxs/SampleToChunkBox.cs
+++ b/src/JT1078.FMp4/Boxs/SampleToChunkBox.cs
@@ -1,16 +1,24 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class SampleToChunkBox : FullBox
+ public class SampleToChunkBox : FullBox, IFMp4MessagePackFormatter
{
public SampleToChunkBox(byte version=0, uint flags=0) : base("stsc", version, flags)
{
}
public uint EntryCount { get; set; }
public List SampleToChunkInfos { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
public class SampleToChunkInfo
{
public uint FirstChunk { get; set; }
diff --git a/src/JT1078.FMp4/Boxs/TimeToSampleBox.cs b/src/JT1078.FMp4/Boxs/TimeToSampleBox.cs
index d0fcc42..82afa45 100644
--- a/src/JT1078.FMp4/Boxs/TimeToSampleBox.cs
+++ b/src/JT1078.FMp4/Boxs/TimeToSampleBox.cs
@@ -1,10 +1,12 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class TimeToSampleBox : FullBox
+ public class TimeToSampleBox : FullBox, IFMp4MessagePackFormatter
{
public TimeToSampleBox(byte version = 0, uint flags = 0) : base("stts", version, flags)
{
@@ -14,6 +16,11 @@ namespace JT1078.FMp4
public List TimeToSampleInfos { get; set; }
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ throw new NotImplementedException();
+ }
+
public class TimeToSampleInfo
{
public uint SampleCount { get; set; }
diff --git a/src/JT1078.FMp4/Boxs/TrackBox.cs b/src/JT1078.FMp4/Boxs/TrackBox.cs
index 533e2af..4c08eae 100644
--- a/src/JT1078.FMp4/Boxs/TrackBox.cs
+++ b/src/JT1078.FMp4/Boxs/TrackBox.cs
@@ -4,14 +4,26 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// trak
+ ///
public class TrackBox : Mp4Box
{
+ ///
+ /// trak
+ ///
public TrackBox() : base("trak")
{
}
- public TrackHeaderBox TrackHeaderBox { get; set; }
+ ///
+ /// tkhd
+ ///
+ public TrackHeaderBox TrackHeaderBox { get; set; }
//不是必须的 public TrackReferenceBox TrackReferenceBox { get; set; }
//不是必须的 public EditBox EditBox { get; set; }
+ ///
+ /// mdia
+ ///
public MediaBox MediaBox { get; set; }
}
}
diff --git a/src/JT1078.FMp4/Boxs/TrackHeaderBox.cs b/src/JT1078.FMp4/Boxs/TrackHeaderBox.cs
index 96ea670..42639e7 100644
--- a/src/JT1078.FMp4/Boxs/TrackHeaderBox.cs
+++ b/src/JT1078.FMp4/Boxs/TrackHeaderBox.cs
@@ -6,8 +6,16 @@ using System.Text;
namespace JT1078.FMp4
{
+ ///
+ /// tkhd
+ ///
public class TrackHeaderBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// tkhd
+ ///
+ ///
+ ///
public TrackHeaderBox(byte version, uint flags) : base("tkhd", version, flags)
{
}
@@ -27,7 +35,7 @@ namespace JT1078.FMp4
public void ToBuffer(ref FMp4MessagePackWriter writer)
{
Start(ref writer);
- WriterToBuffer(ref writer);
+ WriterFullBoxToBuffer(ref writer);
if (Version == 1)
{
writer.WriteUInt64(CreationTime);
diff --git a/src/JT1078.FMp4/Boxs/URIBox.cs b/src/JT1078.FMp4/Boxs/URIBox.cs
index 7b90279..6a44d1e 100644
--- a/src/JT1078.FMp4/Boxs/URIBox.cs
+++ b/src/JT1078.FMp4/Boxs/URIBox.cs
@@ -1,15 +1,33 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class URIBox : FullBox
+ ///
+ /// uri
+ ///
+ public class URIBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// uri
+ ///
+ ///
+ ///
public URIBox(byte version=0, uint flags=0) : base("uri ", version, flags)
{
}
public string TheURI { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ writer.WriteUTF8(TheURI ?? "\0");
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Boxs/URIInitBox.cs b/src/JT1078.FMp4/Boxs/URIInitBox.cs
index b1e0ed5..f111c9f 100644
--- a/src/JT1078.FMp4/Boxs/URIInitBox.cs
+++ b/src/JT1078.FMp4/Boxs/URIInitBox.cs
@@ -1,15 +1,39 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class URIInitBox : FullBox
+ ///
+ /// uriI
+ ///
+ public class URIInitBox : FullBox, IFMp4MessagePackFormatter
{
+ ///
+ /// uriI
+ ///
+ ///
+ ///
public URIInitBox(byte version=0, uint flags=0) : base("uriI", version, flags)
{
}
public byte[] UriInitializationData { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterFullBoxToBuffer(ref writer);
+ if(UriInitializationData!=null && UriInitializationData.Length>0)
+ {
+ foreach(var item in UriInitializationData)
+ {
+ writer.WriteByte(item);
+ }
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Enums/HandlerType.cs b/src/JT1078.FMp4/Enums/HandlerType.cs
new file mode 100644
index 0000000..9437e50
--- /dev/null
+++ b/src/JT1078.FMp4/Enums/HandlerType.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JT1078.FMp4.Enums
+{
+ public enum HandlerType
+ {
+ ///
+ /// null
+ ///
+ none,
+ ///
+ /// Video track
+ ///
+ vide,
+ ///
+ /// Audio track
+ ///
+ soun,
+ ///
+ /// Hint track
+ ///
+ hint,
+ ///
+ /// Timed Metadata track
+ ///
+ meta,
+ ///
+ /// Auxiliary Video track
+ ///
+ auxv
+ }
+}
diff --git a/src/JT1078.FMp4/FMp4Box.cs b/src/JT1078.FMp4/FMp4Box.cs
index b720925..32be246 100644
--- a/src/JT1078.FMp4/FMp4Box.cs
+++ b/src/JT1078.FMp4/FMp4Box.cs
@@ -1,14 +1,36 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4
{
- public class FMp4Box
+ ///
+ /// fmp4
+ ///
+ public class FMp4Box:IFMp4MessagePackFormatter
{
+ ///
+ /// ftyp
+ ///
public FileTypeBox FileTypeBox { get; set; }
+ ///
+ /// moov
+ ///
public MovieBox MovieBox { get; set; }
+ ///
+ ///
+ ///
public List FragmentBoxs { get; set; }
+ ///
+ ///
+ ///
public MovieFragmentRandomAccessBox MovieFragmentRandomAccessBox { get; set; }
+
+ public void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ FileTypeBox.ToBuffer(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/FullBox.cs b/src/JT1078.FMp4/FullBox.cs
index 36e7df4..1d0bf88 100644
--- a/src/JT1078.FMp4/FullBox.cs
+++ b/src/JT1078.FMp4/FullBox.cs
@@ -25,7 +25,7 @@ namespace JT1078.FMp4
///
///
///
- protected void WriterToBuffer(ref FMp4MessagePackWriter writer)
+ protected void WriterFullBoxToBuffer(ref FMp4MessagePackWriter writer)
{
writer.WriteByte(Version);
writer.WriteUInt24(Flags);
diff --git a/src/JT1078.FMp4/JT1078.FMp4.xml b/src/JT1078.FMp4/JT1078.FMp4.xml
index 6ff981d..b947e02 100644
--- a/src/JT1078.FMp4/JT1078.FMp4.xml
+++ b/src/JT1078.FMp4/JT1078.FMp4.xml
@@ -4,6 +4,16 @@
JT1078.FMp4
+
+
+ avcC
+
+
+
+
+ avcC
+
+
@@ -19,6 +29,16 @@
length:EntryCount
+
+
+ clap
+
+
+
+
+ clap
+
+
4, 8 or 16
@@ -46,6 +66,33 @@
ISO-639-2/T language code
+
+
+ dinf
+
+
+
+
+ dinf
+
+
+
+
+ dref
+
+
+
+
+ dref
+
+
+
+
+ dref
+
+
+
+
length:EntryCount
@@ -81,6 +128,11 @@
ftyp 盒子相当于就是该 mp4 的纲领性说明。即,告诉解码器它的基本解码版本,兼容格式。简而言之,就是用来告诉客户端,该 MP4 的使用的解码标准。通常,ftyp 都是放在 MP4 的开头。
+
+
+ ftyp
+
+
因为兼容性一般可以分为推荐兼容性和默认兼容性。这里 major_brand 就相当于是推荐兼容性。通常,在 Web 中解码,一般而言都是使用 isom 这个万金油即可。如果是需要特定的格式,可以自行定义。
@@ -109,6 +161,18 @@
填充数量
+
+
+ hdlr
+
+
+
+
+ hdlr
+
+
+
+
0, 4, 8
@@ -165,6 +229,43 @@
assignment_type == 4
+
+
+ mdia
+
+
+
+
+ mdia
+
+
+
+
+ mdhd
+
+
+
+
+ hdlr
+
+
+
+
+ minf
+
+
+
+
+ mdhd
+
+
+
+
+ mdhd
+
+
+
+
ISO-639-2/T language code
@@ -172,6 +273,93 @@
und-undetermined
+
+
+ minf
+
+
+
+
+ minf
+
+
+
+
+ dinf
+
+
+
+
+ stbl
+
+
+
+
+ moov
+
+
+
+
+ moov
+
+
+
+
+ mvhd
+
+
+
+
+ trak
+
+
+
+
+ trak
+
+
+
+
+ mvex
+
+
+
+
+ mvex
+
+
+
+
+ mvhd
+
+
+
+
+ mvhd
+
+
+
+
+
+
+ btrt
+
+
+
+
+ btrt
+
+
+
+
+ pasp
+
+
+
+
+ pasp
+
+
if (version==0)
@@ -202,6 +390,19 @@
is taken from the sample_count in the Sample Size Box ('stsz') or Compact Sample Size Box(‘stz2’).
+
+
+ stsd
+
+
+
+
+ stsd
+
+
+
+
+
if (version==1)
@@ -213,6 +414,41 @@
length:sample_count
+
+
+ stbl
+
+
+
+
+ stbl
+
+
+
+
+ stsd
+
+
+
+
+ stts
+
+
+
+
+ ctts
+
+
+
+
+ stsc
+
+
+
+
+ stco
+
+
version == 1
@@ -304,6 +540,26 @@
length:ItemCount
+
+
+ trak
+
+
+
+
+ trak
+
+
+
+
+ tkhd
+
+
+
+
+ mdia
+
+
4byte 32-26
@@ -324,6 +580,18 @@
4byte 32-32
+
+
+ tkhd
+
+
+
+
+ tkhd
+
+
+
+
可选的
@@ -339,11 +607,90 @@
version == 0
+
+
+ uri
+
+
+
+
+ uri
+
+
+
+
+
+
+ uriI
+
+
+
+
+ uriI
+
+
+
+
+
+
+ null
+
+
+
+
+ Video track
+
+
+
+
+ Audio track
+
+
+
+
+ Hint track
+
+
+
+
+ Timed Metadata track
+
+
+
+
+ Auxiliary Video track
+
+
+
+
+ fmp4
+
+
+
+
+ ftyp
+
+
+
+
+ moov
+
+
+
+
+
+
+
+
+
+
+
+
日期限制于2000年
@@ -359,7 +706,7 @@
bit(24)
-
+
@@ -401,5 +748,169 @@
+
+
+ avc1
+
+
+
+
+ avc1
+
+
+
+
+ avcC
+
+
+
+
+ btrt
+
+
+
+
+ HintSampleEntry
+
+
+
+
+ HintSampleEntry
+
+
+
+
+
+ SampleEntry
+
+
+
+
+ SampleEntry
+
+
+
+
+
+
+
+
+
+
+
+ mett
+
+
+
+
+ mett
+
+
+
+
+
+ optional
+
+
+
+
+
+
+
+
+
+ btrt
+ optional
+
+
+
+
+ urim
+
+
+
+
+ urim
+
+
+
+
+ uri
+
+
+
+
+ uriI
+ optional
+
+
+
+
+ btrt
+ optional
+
+
+
+
+ VisualSampleEntry
+
+
+
+
+ VisualSampleEntry
+
+
+
+
+
+ clap
+ optional
+
+
+
+
+ pasp
+ optional
+
+
+
+
+
+
+
+
+
+
+ metx
+
+
+
+
+ metx
+
+
+
+
+
+ optional
+
+
+
+
+ Namespace
+
+
+
+
+
+ optional
+
+
+
+
+
+ optional
+
+
diff --git a/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs b/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
index 40bb399..d12cbcc 100644
--- a/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
+++ b/src/JT1078.FMp4/MessagePack/FMp4MessagePackWriter.cs
@@ -65,6 +65,13 @@ namespace JT1078.FMp4.MessagePack
writer.Advance(data.Length);
}
+ public void WriteUTF8(string value)
+ {
+ var data = Encoding.UTF8.GetBytes(value);
+ data.CopyTo(writer.Free);
+ writer.Advance(data.Length);
+ }
+
public void WriteArray(ReadOnlySpan src)
{
src.CopyTo(writer.Free);
diff --git a/src/JT1078.FMp4/Samples/AVC1SampleEntry.cs b/src/JT1078.FMp4/Samples/AVC1SampleEntry.cs
index eda3bf1..e00ec60 100644
--- a/src/JT1078.FMp4/Samples/AVC1SampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/AVC1SampleEntry.cs
@@ -1,17 +1,41 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// avc1
+ ///
public class AVC1SampleEntry : VisualSampleEntry
{
+ ///
+ /// avc1
+ ///
public AVC1SampleEntry() : base("avc1")
{
}
+ ///
+ /// avcC
+ ///
public AVCConfigurationBox AVCConfigurationBox { get; set; }
-
+ ///
+ /// btrt
+ ///
public MPEG4BitRateBox MPEG4BitRateBox { get; set; }
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterVisualSampleEntryToBuffer(ref writer);
+ AVCConfigurationBox.ToBuffer(ref writer);
+ if (MPEG4BitRateBox != null)
+ {
+ MPEG4BitRateBox.ToBuffer(ref writer);
+ }
+ End(ref writer);
+ }
//todo:public MPEG4ExtensionDescriptorsBox MPEG4BitRateBox { get; set; }
}
}
diff --git a/src/JT1078.FMp4/Samples/HintSampleEntry.cs b/src/JT1078.FMp4/Samples/HintSampleEntry.cs
index e95303c..a6c435e 100644
--- a/src/JT1078.FMp4/Samples/HintSampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/HintSampleEntry.cs
@@ -1,14 +1,36 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// HintSampleEntry
+ ///
public class HintSampleEntry : SampleEntry
{
+ ///
+ /// HintSampleEntry
+ ///
+ ///
public HintSampleEntry(string protocol) : base(protocol)
{
}
- public List Data { get; set; }
+ public List Data { get; set; } = new List();
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterSampleEntryToBuffer(ref writer);
+ if (Data != null && Data.Count > 0)
+ {
+ foreach (var item in Data)
+ {
+ writer.WriteByte(item);
+ }
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Samples/SampleEntry.cs b/src/JT1078.FMp4/Samples/SampleEntry.cs
index 31ff039..4227943 100644
--- a/src/JT1078.FMp4/Samples/SampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/SampleEntry.cs
@@ -1,15 +1,39 @@
-using System;
+using JT1078.FMp4.Interfaces;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
- public abstract class SampleEntry : Mp4Box
+ ///
+ /// SampleEntry
+ ///
+ public abstract class SampleEntry : Mp4Box,IFMp4MessagePackFormatter
{
+ ///
+ /// SampleEntry
+ ///
+ ///
public SampleEntry(string boxType) : base(boxType)
{
}
public byte[] Reserved { get; set; } = new byte[6];
public ushort DataReferenceIndex { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ protected void WriterSampleEntryToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ foreach(var item in Reserved)
+ {
+ writer.WriteByte(item);
+ }
+ writer.WriteUInt16(DataReferenceIndex);
+ }
+
+ public abstract void ToBuffer(ref FMp4MessagePackWriter writer);
}
}
diff --git a/src/JT1078.FMp4/Samples/TextMetaDataSampleEntry.cs b/src/JT1078.FMp4/Samples/TextMetaDataSampleEntry.cs
index 129f848..80435a6 100644
--- a/src/JT1078.FMp4/Samples/TextMetaDataSampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/TextMetaDataSampleEntry.cs
@@ -1,16 +1,47 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// mett
+ ///
public class TextMetaDataSampleEntry : SampleEntry
{
+ ///
+ /// mett
+ ///
public TextMetaDataSampleEntry() : base("mett")
{
}
+ ///
+ ///
+ /// optional
+ ///
public string ContentEncoding { get; set; }
+ ///
+ ///
+ ///
public string MimeFormat { get; set; }
+ ///
+ /// btrt
+ /// optional
+ ///
public MPEG4BitRateBox BitRateBox { get; set; }
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ if (!string.IsNullOrEmpty(ContentEncoding))
+ {
+ writer.WriteUTF8(ContentEncoding);
+ }
+ writer.WriteUTF8(MimeFormat??"\0");
+ if (BitRateBox != null)
+ {
+ BitRateBox.ToBuffer(ref writer);
+ }
+ }
}
}
diff --git a/src/JT1078.FMp4/Samples/URIMetaSampleEntry.cs b/src/JT1078.FMp4/Samples/URIMetaSampleEntry.cs
index 30c676d..982153b 100644
--- a/src/JT1078.FMp4/Samples/URIMetaSampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/URIMetaSampleEntry.cs
@@ -1,16 +1,53 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// urim
+ ///
public class URIMetaSampleEntry : SampleEntry
{
+ ///
+ /// urim
+ ///
public URIMetaSampleEntry() : base("urim")
{
}
+ ///
+ /// uri
+ ///
public URIBox TheLabel { get; set; }
+ ///
+ /// uriI
+ /// optional
+ ///
public URIInitBox Init { get; set; }
+ ///
+ /// btrt
+ /// optional
+ ///
public MPEG4BitRateBox BitRateBox { get; set; }
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterSampleEntryToBuffer(ref writer);
+ if (TheLabel != null)
+ {
+ TheLabel.ToBuffer(ref writer);
+ }
+ if (Init != null)
+ {
+ Init.ToBuffer(ref writer);
+ }
+ if (BitRateBox != null)
+ {
+ BitRateBox.ToBuffer(ref writer);
+ }
+ End(ref writer);
+ }
}
}
diff --git a/src/JT1078.FMp4/Samples/VisualSampleEntry.cs b/src/JT1078.FMp4/Samples/VisualSampleEntry.cs
index 065332f..1fe2981 100644
--- a/src/JT1078.FMp4/Samples/VisualSampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/VisualSampleEntry.cs
@@ -1,11 +1,19 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// VisualSampleEntry
+ ///
public abstract class VisualSampleEntry : SampleEntry
{
+ ///
+ /// VisualSampleEntry
+ ///
+ ///
public VisualSampleEntry(string boxType) : base(boxType)
{
}
@@ -22,7 +30,50 @@ namespace JT1078.FMp4.Samples
public string CompressorName { get; set; }
public ushort Depth { get; set; } = 0x0018;
public short PreDefined3 { get; set; } = 0x1111;
+ ///
+ /// clap
+ /// optional
+ ///
public CleanApertureBox Clap { get; set; }
+ ///
+ /// pasp
+ /// optional
+ ///
public PixelAspectRatioBox Pasp { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ protected void WriterVisualSampleEntryToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ writer.WriteUInt16(PreDefined1);
+ writer.WriteUInt16(Reserved1);
+ foreach(var item in PreDefined2)
+ {
+ writer.WriteUInt32(item);
+ }
+ writer.WriteUInt16(Width);
+ writer.WriteUInt16(Height);
+ writer.WriteUInt32(HorizreSolution);
+ writer.WriteUInt32(VertreSolution);
+ writer.WriteUInt32(Reserved3);
+ writer.WriteUInt16(FrameCount);
+ if (string.IsNullOrEmpty(CompressorName))
+ {
+ CompressorName = "";
+ }
+ writer.WriteUTF8(CompressorName.PadLeft(32, '\0'));
+ writer.WriteUInt16(Depth);
+ writer.WriteInt16(PreDefined3);
+ if (Clap != null)
+ {
+ Clap.ToBuffer(ref writer);
+ }
+ if (Pasp != null)
+ {
+ Pasp.ToBuffer(ref writer);
+ }
+ }
}
}
diff --git a/src/JT1078.FMp4/Samples/XMLMetaDataSampleEntry.cs b/src/JT1078.FMp4/Samples/XMLMetaDataSampleEntry.cs
index 0e0b61e..e9327b4 100644
--- a/src/JT1078.FMp4/Samples/XMLMetaDataSampleEntry.cs
+++ b/src/JT1078.FMp4/Samples/XMLMetaDataSampleEntry.cs
@@ -1,18 +1,59 @@
-using System;
+using JT1078.FMp4.MessagePack;
+using System;
using System.Collections.Generic;
using System.Text;
namespace JT1078.FMp4.Samples
{
+ ///
+ /// metx
+ ///
public class XMLMetaDataSampleEntry : SampleEntry
{
+ ///
+ /// metx
+ ///
public XMLMetaDataSampleEntry() : base("metx")
{
}
-
+ ///
+ ///
+ /// optional
+ ///
public string ContentEncoding { get; set; }
+ ///
+ /// Namespace
+ ///
public string Namespace { get; set; }
+ ///
+ ///
+ /// optional
+ ///
public string SchemaLocation { get; set; }
+ ///
+ ///
+ /// optional
+ ///
public MPEG4BitRateBox BitRateBox { get; set; }
+
+ public override void ToBuffer(ref FMp4MessagePackWriter writer)
+ {
+ Start(ref writer);
+ WriterSampleEntryToBuffer(ref writer);
+ if (!string.IsNullOrEmpty(ContentEncoding))
+ {
+ writer.WriteUTF8(ContentEncoding);
+ }
+ writer.WriteUTF8(Namespace ?? "\0");
+ if (!string.IsNullOrEmpty(SchemaLocation))
+ {
+ writer.WriteUTF8(SchemaLocation);
+ }
+ if (BitRateBox != null)
+ {
+ BitRateBox.ToBuffer(ref writer);
+ }
+ End(ref writer);
+ }
}
}