Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

126 rindas
3.9 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. }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public uint ReferenceID { get; set; } = 1;
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. public uint Timescale { get; set; } = 1000;
  29. /// <summary>
  30. /// pts
  31. /// if(version==0)
  32. /// version==0 32 bit
  33. /// version>0 64 bit
  34. /// </summary>
  35. public ulong EarliestPresentationTime { get; set; }
  36. /// <summary>
  37. ///
  38. /// </summary>
  39. public ulong FirstOffset { get; set; } = 0;
  40. private ushort Reserved { get; set; }
  41. //private ushort ReferenceCount { get; set; }
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. public List<SegmentIndex> SegmentIndexs { get; set; }
  46. public void ToBuffer(ref FMp4MessagePackWriter writer)
  47. {
  48. Start(ref writer);
  49. WriterFullBoxToBuffer(ref writer);
  50. writer.WriteUInt32(ReferenceID);
  51. writer.WriteUInt32(Timescale);
  52. if (Version == 0)
  53. {
  54. writer.WriteUInt32((uint)EarliestPresentationTime);
  55. writer.WriteUInt32((uint)FirstOffset);
  56. }
  57. else
  58. {
  59. writer.WriteUInt64(EarliestPresentationTime);
  60. writer.WriteUInt64(FirstOffset);
  61. }
  62. writer.WriteUInt16(Reserved);
  63. if(SegmentIndexs!=null && SegmentIndexs.Count > 0)
  64. {
  65. writer.WriteUInt16((ushort)SegmentIndexs.Count);
  66. foreach(var si in SegmentIndexs)
  67. {
  68. if (si.ReferenceType)
  69. {
  70. writer.WriteUInt32(si.ReferencedSize | 0x80000000);
  71. }
  72. else
  73. {
  74. writer.WriteUInt32(si.ReferencedSize);
  75. }
  76. writer.WriteUInt32(si.SubsegmentDuration);
  77. if (si.StartsWithSAP)
  78. {
  79. writer.WriteUInt32((si.SAPDeltaTime | 0x80000000 | (uint)(si.SAPType << 28 & 0x70000000)));
  80. }
  81. else
  82. {
  83. writer.WriteUInt32((si.SAPDeltaTime | (uint)((si.SAPType <<28) & 0x70000000)));
  84. }
  85. }
  86. }
  87. else
  88. {
  89. writer.WriteUInt16(0);
  90. }
  91. End(ref writer);
  92. }
  93. public class SegmentIndex
  94. {
  95. /// <summary>
  96. /// 4byte 32 - 1
  97. /// </summary>
  98. public bool ReferenceType { get; set; } = false;
  99. /// <summary>
  100. /// 4byte 32 - 31
  101. /// ReferencedSize=(moof size) + (mdat size)
  102. /// </summary>
  103. public uint ReferencedSize { get; set; } = 0;
  104. /// <summary>
  105. ///
  106. /// </summary>
  107. public uint SubsegmentDuration { get; set; }
  108. /// <summary>
  109. /// 4byte 32 - 1
  110. /// </summary>
  111. public bool StartsWithSAP { get; set; } = true;
  112. /// <summary>
  113. /// 4byte 32 - 3
  114. /// </summary>
  115. public byte SAPType { get; set; } = 1;
  116. /// <summary>
  117. /// 4byte 32 - 28
  118. /// </summary>
  119. public uint SAPDeltaTime { get; set; } = 0;
  120. }
  121. }
  122. }