aboutsummaryrefslogtreecommitdiff
path: root/Src/replicant/nsid3v2/frame.h
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nsid3v2/frame.h
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nsid3v2/frame.h')
-rw-r--r--Src/replicant/nsid3v2/frame.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/Src/replicant/nsid3v2/frame.h b/Src/replicant/nsid3v2/frame.h
new file mode 100644
index 00000000..3cf5fe99
--- /dev/null
+++ b/Src/replicant/nsid3v2/frame.h
@@ -0,0 +1,117 @@
+#pragma once
+#include "frameheader.h"
+#include "nu/PtrDeque.h"
+
+namespace ID3v2
+{
+ class Frame : public nu::PtrDequeNode
+ {
+ public:
+ virtual ~Frame();
+ int NewData(size_t new_len, void **data, size_t *data_len);
+ int GetData(const void **data, size_t *data_len) const;
+ size_t GetDataSize() const;
+ virtual const int8_t *GetIdentifier() const=0;
+ virtual unsigned int GetVersion() const=0;
+
+ virtual bool Encrypted() const;
+ virtual bool Compressed() const;
+ virtual bool Grouped() const;
+ virtual bool ReadOnly() const;
+ virtual bool FrameUnsynchronised() const;
+ virtual bool DataLengthIndicated() const;
+ virtual bool TagAlterPreservation() const;
+ virtual bool FileAlterPreservation() const;
+ protected:
+ Frame();
+ void *data;
+ size_t data_size; /* REAL size, might be different from header.headerData.size */
+ };
+}
+
+namespace ID3v2_2
+{
+ class Frame : public ID3v2::Frame
+ {
+ public:
+ Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
+ Frame(const ID3v2_2::FrameHeader &_header);
+ int Parse(const void *_data, size_t len, size_t *read);
+ int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
+ // there is enough room guaranteed to be present because it will be checked with SerializedSize()
+ int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
+ const int8_t *GetIdentifier() const;
+ unsigned int GetVersion() const { return 2; }
+ private:
+ ID3v2_2::FrameHeader header;
+ };
+}
+
+
+namespace ID3v2_3
+{
+ class Frame : public ID3v2::Frame
+ {
+ public:
+ Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
+ Frame(const ID3v2_3::FrameHeader &_header);
+ int Parse(const void *_data, size_t len, size_t *read);
+
+ int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
+ // there is enough room guaranteed to be present because it will be checked with SerializedSize()
+ int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
+
+ const int8_t *GetIdentifier() const;
+ unsigned int GetVersion() const { return 3; }
+ virtual bool Encrypted() const;
+ virtual bool Compressed() const;
+ virtual bool Grouped() const;
+ virtual bool ReadOnly() const;
+ virtual bool TagAlterPreservation() const;
+ virtual bool FileAlterPreservation() const;
+
+ private:
+ ID3v2_3::FrameHeader header;
+ uint8_t group_identity;
+ /* helper function
+ reads num_bytes from input into output, dealing with re-synchronization and length checking
+ increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
+ decrements input_len by bytes read
+ decrements output_len by bytes written
+ */
+ bool ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const;
+ };
+}
+
+namespace ID3v2_4
+{
+ class Frame : public ID3v2::Frame
+ {
+ public:
+ Frame(const ID3v2::Header &_header, const int8_t *id, int flags); // creates an empty frame with a given ID
+ Frame(const ID3v2_4::FrameHeader &_header);
+ int Parse(const void *_data, size_t len, size_t *read);
+ int SerializedSize(uint32_t *length, const ID3v2::Header &tag_header, int flags) const;
+ int Serialize(void *data, uint32_t *written, const ID3v2::Header &tag_header, int flags) const;
+ const int8_t *GetIdentifier() const;
+ unsigned int GetVersion() const { return 4; }
+ virtual bool Encrypted() const;
+ virtual bool Compressed() const;
+ virtual bool Grouped() const;
+ virtual bool ReadOnly() const;
+ virtual bool FrameUnsynchronised() const;
+ virtual bool DataLengthIndicated() const;
+ virtual bool TagAlterPreservation() const;
+ virtual bool FileAlterPreservation() const;
+ private:
+ ID3v2_4::FrameHeader header;
+ uint8_t group_identity;
+ /* helper function
+ reads num_bytes from input into output, dealing with re-synchronization and length checking
+ increments bytes_read value by number of input bytes read (different from num_bytes when data is unsynchronized
+ decrements input_len by bytes read
+ decrements output_len by bytes written
+ */
+ bool ReadData(void *output, const void *&input, size_t &input_len, size_t &frame_len, size_t num_bytes, size_t *bytes_read) const;
+ };
+}