1
0

frame.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include "frameheader.h"
  3. #include "nu/PtrDeque.h"
  4. namespace ID3v2
  5. {
  6. class Frame : public nu::PtrDequeNode
  7. {
  8. public:
  9. virtual ~Frame();
  10. int NewData(size_t new_len, void **data, size_t *data_len);
  11. int GetData(const void **data, size_t *data_len) const;
  12. size_t GetDataSize() const;
  13. virtual const int8_t *GetIdentifier() const=0;
  14. virtual unsigned int GetVersion() const=0;
  15. virtual bool Encrypted() const;
  16. virtual bool Compressed() const;
  17. virtual bool Grouped() const;
  18. virtual bool ReadOnly() const;
  19. virtual bool FrameUnsynchronised() const;
  20. virtual bool DataLengthIndicated() const;
  21. virtual bool TagAlterPreservation() const;
  22. virtual bool FileAlterPreservation() const;
  23. protected:
  24. Frame();
  25. void *data;
  26. size_t data_size; /* REAL size, might be different from header.headerData.size */
  27. };
  28. }
  29. namespace ID3v2_2
  30. {
  31. class Frame : public ID3v2::Frame
  32. {
  33. public:
  34. Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
  35. Frame(const ID3v2_2::FrameHeader &_header);
  36. int Parse(const void *_data, size_t len, size_t *read);
  37. int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
  38. // there is enough room guaranteed to be present because it will be checked with SerializedSize()
  39. int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
  40. const int8_t *GetIdentifier() const;
  41. unsigned int GetVersion() const { return 2; }
  42. private:
  43. ID3v2_2::FrameHeader header;
  44. };
  45. }
  46. namespace ID3v2_3
  47. {
  48. class Frame : public ID3v2::Frame
  49. {
  50. public:
  51. Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
  52. Frame(const ID3v2_3::FrameHeader &_header);
  53. int Parse(const void *_data, size_t len, size_t *read);
  54. int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
  55. // there is enough room guaranteed to be present because it will be checked with SerializedSize()
  56. int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
  57. const int8_t *GetIdentifier() const;
  58. unsigned int GetVersion() const { return 3; }
  59. virtual bool Encrypted() const;
  60. virtual bool Compressed() const;
  61. virtual bool Grouped() const;
  62. virtual bool ReadOnly() const;
  63. virtual bool TagAlterPreservation() const;
  64. virtual bool FileAlterPreservation() const;
  65. private:
  66. ID3v2_3::FrameHeader header;
  67. uint8_t group_identity;
  68. /* helper function
  69. reads num_bytes from input into output, dealing with re-synchronization and length checking
  70. increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
  71. decrements input_len by bytes read
  72. decrements output_len by bytes written
  73. */
  74. bool ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const;
  75. };
  76. }
  77. namespace ID3v2_4
  78. {
  79. class Frame : public ID3v2::Frame
  80. {
  81. public:
  82. Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
  83. Frame(const ID3v2_4::FrameHeader &_header);
  84. int Parse(const void *_data, size_t len, size_t *read);
  85. int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
  86. int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
  87. const int8_t *GetIdentifier() const;
  88. unsigned int GetVersion() const { return 4; }
  89. virtual bool Encrypted() const;
  90. virtual bool Compressed() const;
  91. virtual bool Grouped() const;
  92. virtual bool ReadOnly() const;
  93. virtual bool FrameUnsynchronised() const;
  94. virtual bool DataLengthIndicated() const;
  95. virtual bool TagAlterPreservation() const;
  96. virtual bool FileAlterPreservation() const;
  97. private:
  98. ID3v2_4::FrameHeader header;
  99. uint8_t group_identity;
  100. /* helper function
  101. reads num_bytes from input into output, dealing with re-synchronization and length checking
  102. increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
  103. decrements input_len by bytes read
  104. decrements output_len by bytes written
  105. */
  106. bool ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const;
  107. };
  108. }