您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

131 行
4.1 KiB

  1. using JT1078.FMp4.Interfaces;
  2. using JT1078.FMp4.MessagePack;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace JT1078.FMp4
  7. {
  8. /// <summary>
  9. /// sidx
  10. /// </summary>
  11. public class SegmentIndexBox : FullBox,IFMp4MessagePackFormatter
  12. {
  13. /// <summary>
  14. /// sidx
  15. /// </summary>
  16. /// <param name="version"></param>
  17. /// <param name="flags"></param>
  18. public SegmentIndexBox(byte version, uint flags=0) : base("sidx", version, flags)
  19. {
  20. ReferencedSizePositions = new List<int>();
  21. }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. public uint ReferenceID { get; set; } = 1;
  26. /// <summary>
  27. ///
  28. /// </summary>
  29. public uint Timescale { get; set; } = 1000;
  30. /// <summary>
  31. /// pts
  32. /// if(version==0)
  33. /// version==0 32 bit
  34. /// version>0 64 bit
  35. /// </summary>
  36. public ulong EarliestPresentationTime { get; set; }
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. public ulong FirstOffset { get; set; } = 0;
  41. private ushort Reserved { get; set; }
  42. //private ushort ReferenceCount { get; set; }
  43. /// <summary>
  44. ///
  45. /// </summary>
  46. public List<SegmentIndex> SegmentIndexs { get; set; }
  47. public List<int> ReferencedSizePositions { get; set; }
  48. public void ToBuffer(ref FMp4MessagePackWriter writer)
  49. {
  50. Start(ref writer);
  51. WriterFullBoxToBuffer(ref writer);
  52. writer.WriteUInt32(ReferenceID);
  53. writer.WriteUInt32(Timescale);
  54. if (Version == 0)
  55. {
  56. writer.WriteUInt32((uint)EarliestPresentationTime);
  57. writer.WriteUInt32((uint)FirstOffset);
  58. }
  59. else
  60. {
  61. writer.WriteUInt64(EarliestPresentationTime);
  62. writer.WriteUInt64(FirstOffset);
  63. }
  64. writer.WriteUInt16(Reserved);
  65. if(SegmentIndexs!=null && SegmentIndexs.Count > 0)
  66. {
  67. writer.WriteUInt16((ushort)SegmentIndexs.Count);
  68. foreach(var si in SegmentIndexs)
  69. {
  70. if (si.ReferenceType)
  71. {
  72. ReferencedSizePositions.Add(writer.GetCurrentPosition());
  73. writer.WriteUInt32(si.ReferencedSize | 0x80000000);
  74. }
  75. else
  76. {
  77. ReferencedSizePositions.Add(writer.GetCurrentPosition());
  78. writer.WriteUInt32(si.ReferencedSize);
  79. }
  80. writer.WriteUInt32(si.SubsegmentDuration);
  81. if (si.StartsWithSAP)
  82. {
  83. writer.WriteUInt32((si.SAPDeltaTime | 0x80000000 | (uint)(si.SAPType << 28 & 0x70000000)));
  84. }
  85. else
  86. {
  87. writer.WriteUInt32((si.SAPDeltaTime | (uint)((si.SAPType <<28) & 0x70000000)));
  88. }
  89. }
  90. }
  91. else
  92. {
  93. writer.WriteUInt16(0);
  94. }
  95. End(ref writer);
  96. }
  97. public class SegmentIndex
  98. {
  99. /// <summary>
  100. /// 4byte 32 - 1
  101. /// </summary>
  102. public bool ReferenceType { get; set; } = false;
  103. /// <summary>
  104. /// 4byte 32 - 31
  105. /// ReferencedSize=(moof size) + (mdat size)
  106. /// </summary>
  107. public uint ReferencedSize { get; set; } = 0;
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. public uint SubsegmentDuration { get; set; }
  112. /// <summary>
  113. /// 4byte 32 - 1
  114. /// </summary>
  115. public bool StartsWithSAP { get; set; } = true;
  116. /// <summary>
  117. /// 4byte 32 - 3
  118. /// </summary>
  119. public byte SAPType { get; set; } = 1;
  120. /// <summary>
  121. /// 4byte 32 - 28
  122. /// </summary>
  123. public uint SAPDeltaTime { get; set; } = 0;
  124. }
  125. }
  126. }