Mpeg4Atoms.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) Kuba Szczodrzyński 2022-1-8.
  2. #pragma once
  3. #include <cstdint>
  4. enum class AudioSampleFormat;
  5. enum class MP4AObjectType;
  6. enum class MP4AProfile;
  7. typedef struct {
  8. /** Absolute offset of mdat header (or moof for fMP4) */
  9. uint32_t start;
  10. /** Absolute offset of the last mdat byte */
  11. uint32_t end;
  12. /** Total duration of this fragment */
  13. uint32_t duration;
  14. } Mpeg4Fragment;
  15. typedef struct {
  16. /** Number of chunks this descriptor applies to */
  17. uint16_t count;
  18. /** Number of samples in the described chunks */
  19. uint32_t samples;
  20. uint16_t sampleDescriptionId;
  21. } Mpeg4ChunkRange;
  22. /** Absolute offset of the chunk data */
  23. typedef uint32_t Mpeg4ChunkOffset;
  24. typedef struct {
  25. /** Abs. offset of data start in the current chunk */
  26. uint32_t start;
  27. /** Abs. offset of data end in the current chunk */
  28. uint32_t end;
  29. /** Abs. offset of the next chunk data, or 0 for last chunk in a fragment */
  30. uint32_t nextStart;
  31. } Mpeg4Chunk;
  32. typedef struct {
  33. /** Number of samples this descriptor applies to */
  34. uint32_t count;
  35. /** Duration of the described samples */
  36. uint32_t duration;
  37. } Mpeg4SampleRange;
  38. /** Size of a single sample */
  39. typedef uint32_t Mpeg4SampleSize;
  40. /** Flags for a sample */
  41. typedef uint32_t SampleFlags;
  42. /** Default values for samples in the movie/fragment */
  43. typedef struct {
  44. /** Absolute offset of first mdat byte */
  45. uint32_t offset;
  46. uint32_t sampleDescriptionId;
  47. uint32_t duration;
  48. uint32_t size;
  49. SampleFlags flags;
  50. } SampleDefaults;
  51. /** Sample Description Table */
  52. typedef struct {
  53. uint16_t dataReferenceIndex;
  54. AudioSampleFormat format;
  55. // params for MPEG-4 Elementary Stream Descriptors
  56. MP4AObjectType mp4aObjectType;
  57. MP4AProfile mp4aProfile;
  58. // atom header for unknown descriptors
  59. uint32_t dataType;
  60. // codec-specific data (either DecoderSpecificInfo or the entire descriptor)
  61. uint32_t dataLength;
  62. uint8_t *data;
  63. } SampleDescription;
  64. typedef struct {
  65. // byte 1 - bits 0:7
  66. bool durationIsEmpty : 1;
  67. bool defaultBaseIsMoof : 1;
  68. bool dummy1 : 6;
  69. // byte 2 - bits 0:7
  70. uint8_t dummy2 : 8;
  71. // byte 3 - bits 0:7
  72. bool baseDataOffsetPresent : 1;
  73. bool sampleDescriptionIndexPresent : 1;
  74. bool dummy3 : 1;
  75. bool defaultSampleDurationPresent : 1;
  76. bool defaultSampleSizePresent : 1;
  77. bool defaultSampleFlagsPresent : 1;
  78. bool dummy4 : 2;
  79. } TfFlags;
  80. typedef struct {
  81. // byte 1 - bits 0:7
  82. uint8_t dummy1 : 8;
  83. // byte 2 - bits 0:7
  84. bool sampleDurationPresent : 1;
  85. bool sampleSizePresent : 1;
  86. bool sampleFlagsPresent : 1;
  87. bool sampleCompositionTimeOffsetsPresent : 1;
  88. bool dummy2 : 4;
  89. // byte 3 - bits 0:7
  90. bool dataOffsetPresent : 1;
  91. bool dummy3 : 1;
  92. bool firstSampleFlagsPresent : 1;
  93. bool dummy4 : 5;
  94. } TrFlags;