You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 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. /// tfhd
  10. /// </summary>
  11. public class TrackFragmentHeaderBox : FullBox, IFMp4MessagePackFormatter
  12. {
  13. /// <summary>
  14. /// tfhd
  15. /// </summary>
  16. /// <param name="version"></param>
  17. /// <param name="flags"></param>
  18. public TrackFragmentHeaderBox(byte version, uint flags) : base("tfhd", version, flags)
  19. {
  20. }
  21. /// <summary>
  22. /// tfhd
  23. /// </summary>
  24. /// <param name="flags"></param>
  25. public TrackFragmentHeaderBox(uint flags = 0) : this(0, flags)
  26. {
  27. }
  28. public uint TrackID { get; set; }
  29. #region all the following are optional fields
  30. /// <summary>
  31. /// TFHD_FLAG_BASE_DATA_OFFSET
  32. /// </summary>
  33. public ulong BaseDataOffset { get; set; }
  34. /// <summary>
  35. /// TFHD_FLAG_SAMPLE_DESCRIPTION_INDEX
  36. /// </summary>
  37. public uint SampleDescriptionIndex { get; set; }
  38. /// <summary>
  39. /// TFHD_FLAG_DEFAULT_DURATION
  40. /// </summary>
  41. public uint DefaultSampleDuration { get; set; }
  42. /// <summary>
  43. /// TFHD_FLAG_DEFAULT_SIZE
  44. /// H.264 NALU SIZE
  45. /// </summary>
  46. public uint DefaultSampleSize { get; set; }
  47. /// <summary>
  48. /// TFHD_FLAG_DEFAULT_FLAGS
  49. /// MOV_AUDIO == handler_type ? 0x02000000 : (0x00010000| 0x01000000);
  50. /// </summary>
  51. public uint DefaultSampleFlags { get; set; }
  52. #endregion
  53. public void ToBuffer(ref FMp4MessagePackWriter writer)
  54. {
  55. Start(ref writer);
  56. WriterFullBoxToBuffer(ref writer);
  57. writer.WriteUInt32(TrackID);
  58. if ((FMp4Constants.TFHD_FLAG_BASE_DATA_OFFSET & Flags) > 0)
  59. {
  60. writer.WriteUInt64(BaseDataOffset);
  61. }
  62. if ((FMp4Constants.TFHD_FLAG_SAMPLE_DESCRIPTION_INDEX & Flags) > 0)
  63. {
  64. writer.WriteUInt32(SampleDescriptionIndex);
  65. }
  66. if ((FMp4Constants.TFHD_FLAG_DEFAULT_DURATION & Flags) > 0)
  67. {
  68. writer.WriteUInt32(DefaultSampleDuration);
  69. }
  70. if ((FMp4Constants.TFHD_FLAG_DEFAULT_SIZE & Flags) > 0)
  71. {
  72. writer.WriteUInt32(DefaultSampleSize);
  73. }
  74. if ((FMp4Constants.TFHD_FLAG_DEFAULT_FLAGS & Flags) > 0)
  75. {
  76. writer.WriteUInt32(DefaultSampleFlags);
  77. }
  78. End(ref writer);
  79. }
  80. }
  81. }