frameheader.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include "foundation/types.h"
  3. #include "header.h"
  4. namespace ID3v2
  5. {
  6. class FrameHeader
  7. {
  8. protected:
  9. FrameHeader(const ID3v2::Header &_header);
  10. const ID3v2::Header &tagHeader;
  11. };
  12. }
  13. namespace ID3v2_2
  14. {
  15. struct FrameHeaderData
  16. {
  17. int8_t id[4]; // ID3v2.2 uses 3 bytes but we add a NULL for the last to make it easier
  18. uint8_t size[3]; // 24 bit size field
  19. };
  20. class FrameHeader : public ID3v2::FrameHeader
  21. {
  22. public:
  23. FrameHeader(const ID3v2_2::FrameHeader &frame_header, const ID3v2::Header &_header);
  24. FrameHeader(const ID3v2::Header &_header, const int8_t *id, int flags);
  25. FrameHeader(const ID3v2::Header &_header, const void *data);
  26. bool IsValid() const;
  27. bool Unsynchronised() const;
  28. uint32_t FrameSize() const;
  29. const int8_t *GetIdentifier() const;
  30. void SetSize(uint32_t data_size);
  31. int SerializedSize(uint32_t *written) const;
  32. int Serialize(void *data) const;
  33. enum
  34. {
  35. SIZE=6,
  36. };
  37. private:
  38. FrameHeaderData frameHeaderData;
  39. };
  40. }
  41. namespace ID3v2_3
  42. {
  43. class FrameHeaderBase : public ID3v2::FrameHeader
  44. {
  45. public:
  46. int SerializedSize(uint32_t *written) const;
  47. int Serialize(void *data, uint32_t *written) const;
  48. bool IsValid() const;
  49. const int8_t *GetIdentifier() const;
  50. enum
  51. {
  52. SIZE=10,
  53. };
  54. protected:
  55. FrameHeaderBase(const ID3v2_3::FrameHeaderBase &frame_header_base, const ID3v2::Header &_header);
  56. FrameHeaderBase(const ID3v2::Header &_header);
  57. FrameHeaderBase(const ID3v2::Header &_header, const int8_t *id, int flags);
  58. int8_t id[4];
  59. uint32_t size;
  60. uint8_t flags[2];
  61. };
  62. class FrameHeader : public ID3v2_3::FrameHeaderBase
  63. {
  64. public:
  65. FrameHeader(const ID3v2_3::FrameHeader &frame_header, const ID3v2::Header &_header);
  66. FrameHeader(const ID3v2::Header &_header, const int8_t *id, int flags);
  67. FrameHeader(const ID3v2::Header &_header, const void *data);
  68. uint32_t FrameSize() const;
  69. bool Encrypted() const;
  70. bool Compressed() const;
  71. bool Grouped() const;
  72. bool ReadOnly() const;
  73. bool Unsynchronised() const;
  74. bool TagAlterPreservation() const;
  75. bool FileAlterPreservation() const;
  76. void ClearCompressed();
  77. /* sets a new size, given a data size. this function might add additional size (grouped, compressed, etc) */
  78. void SetSize(uint32_t data_size);
  79. private:
  80. };
  81. }
  82. namespace ID3v2_4
  83. {
  84. class FrameHeader : public ID3v2_3::FrameHeaderBase
  85. {
  86. public:
  87. FrameHeader(const ID3v2_4::FrameHeader &frame_header, const ID3v2::Header &_header);
  88. FrameHeader(const ID3v2::Header &_header, const int8_t *id, int flags);
  89. FrameHeader(const ID3v2::Header &_header, const void *data);
  90. /* size to read from disk */
  91. uint32_t FrameSize() const;
  92. bool Encrypted() const;
  93. bool Compressed() const;
  94. bool Grouped() const;
  95. bool ReadOnly() const;
  96. bool Unsynchronised() const;
  97. bool FrameUnsynchronised() const;
  98. bool DataLengthIndicated() const;
  99. bool TagAlterPreservation() const;
  100. bool FileAlterPreservation() const;
  101. void ClearUnsynchronized();
  102. void ClearCompressed();
  103. /* sets a new size, given a data size. this function might add additional size (grouped, compressed, etc) */
  104. void SetSize(uint32_t data_size);
  105. int SerializedSize(uint32_t *written) const;
  106. int Serialize(void *data, uint32_t *written) const;
  107. };
  108. }