16#include "id3dependencies/ByteStream/include/byteStream.h"
17#include "id3dependencies/ByteStream/include/byteInt.h"
35 header->
flags = flags;
111 header->
flags = setBit(header->
flags, 6, bit);
137 header->
flags = setBit(header->
flags, 5, bit);
161 header->
flags = setBit(header->
flags, 4, bit);
181 return readBit(header->
flags, 7);
199 return readBit(header->
flags, 6);
217 return readBit(header->
flags, 6);
241 return readBit(header->
flags, 5);
265 return readBit(header->
flags, 4);
281 uint8_t restrictions) {
286 extendedHeader->
padding = padding;
287 extendedHeader->
crc = crc;
288 extendedHeader->
update = update;
292 return extendedHeader;
321 if (!header || bits > 0x03) {
387 if (!header || bits > 0x03) {
453 if (!header || bits > 0x03) {
500 return (msb << 1) | lsb;
547 return (msb << 1) | lsb;
594 return (msb << 1) | lsb;
649 listFree((*toDelete)->frames);
677 ByteStream *stream = NULL;
680 unsigned char *tmp = NULL;
681 unsigned char crcb[5] = {0, 0, 0, 0, 0};
692 buildSize = 10 + ((ext->
crc) ? 4 : 0);
694 stream = byteStreamCreate(NULL, buildSize);
696 tmp = (
unsigned char *) itob(buildSize);
697 byteStreamWrite(stream, tmp, 4);
701 byteStreamWriteBit(stream, (ext->
crc > 0) ? 1 : 0, 7);
702 byteStreamSeek(stream, 2, SEEK_CUR);
706 byteStreamWrite(stream, tmp, 4);
710 tmp = u32tob(ext->
crc);
711 byteStreamWrite(stream, tmp, 4);
721 stream = byteStreamCreate(NULL, buildSize);
725 tmp = u32tob(buildSize);
726 byteStreamWrite(stream, tmp, 4);
730 tmp = (
unsigned char *) itob(buildSize - 6);
731 byteStreamWrite(stream, &tmp[3], 1);
735 byteStreamWriteBit(stream, ext->
update, 6);
736 byteStreamWriteBit(stream, (ext->
crc > 0) ? 1 : 0, 5);
738 byteStreamSeek(stream, 1, SEEK_CUR);
744 tmp = sttob(byteSyncintEncode(ext->
crc));
746 while (offset <
sizeof(
size_t) && tmp[offset] == 0) {
755 toWrite = ((int) (
sizeof(size_t) - offset) > 5) ? 5 : (int) (
sizeof(
size_t) - offset);
756 memcpy(crcb, tmp + offset, toWrite);
758 byteStreamSeek(stream, 6, SEEK_SET);
759 byteStreamWrite(stream, crcb, 5);
776 byteStreamRewind(stream);
777 out = calloc(stream->bufferSize,
sizeof(uint8_t));
778 *outl = stream->bufferSize;
779 byteStreamRead(stream, out, stream->bufferSize);
780 byteStreamDestroy(stream);
809 json = calloc(memCount,
sizeof(
char));
810 memcpy(json,
"{}\0", memCount);
817 memCount += snprintf(NULL, 0,
818 "{\"padding\":%"PRIu32
",\"crc\":%"PRIu32
"}",
822 json = calloc(memCount + 1,
sizeof(
char));
824 (void) snprintf(json, memCount,
825 "{\"padding\":%"PRIu32
",\"crc\":%"PRIu32
"}",
832 memCount += snprintf(NULL, 0,
833 "{\"padding\":%"PRIu32
",\"crc\":%"PRIu32
834 ",\"update\":%s,\"tagRestrictions\":%s,\"restrictions\":%d}",
837 ext->
update ?
"true" :
"false",
841 json = calloc(memCount + 1,
sizeof(
char));
843 (void) snprintf(json, memCount,
844 "{\"padding\":%"PRIu32
",\"crc\":%"PRIu32
845 ",\"update\":%s,\"tagRestrictions\":%s,\"restrictions\":%d}",
848 ext->
update ?
"true" :
"false",
857 json = malloc(
sizeof(
char) * memCount);
858 memcpy(json,
"{}\0", memCount);
884 ByteStream *stream = NULL;
886 unsigned char *tmp = NULL;
888 if (header == NULL) {
899 stream = byteStreamCreate(NULL, 10);
934 byteStreamSeek(stream, 1, SEEK_CUR);
936 tmp = u32tob(byteSyncintEncode(uintSize));
937 byteStreamWrite(stream, tmp,
sizeof(uint32_t));
945 byteStreamResize(stream, stream->bufferSize + extSize);
946 byteStreamWrite(stream, ext, extSize);
951 byteStreamRewind(stream);
952 *outl = stream->bufferSize;
953 out = calloc(stream->bufferSize,
sizeof(uint8_t));
954 byteStreamRead(stream, out, stream->bufferSize);
955 byteStreamDestroy(stream);
983 char *extJson = NULL;
985 if (header == NULL) {
986 json = calloc(memCount,
sizeof(
char));
987 memcpy(json,
"{}\0", memCount);
994 memCount += snprintf(NULL, 0,
995 "{\"major\":%d,\"minor\":%d,\"flags\":%d}",
1000 json = calloc(memCount + 1,
sizeof(
char));
1002 (void) snprintf(json, memCount,
1003 "{\"major\":%d,\"minor\":%d,\"flags\":%d}",
1013 memCount += snprintf(NULL, 0,
1014 "{\"major\":%d,\"minor\":%d,\"flags\":%d,\"extended\":%s}",
1020 json = calloc(memCount + 1,
sizeof(
char));
1023 (void) snprintf(json, memCount,
1024 "{\"major\":%d,\"minor\":%d,\"flags\":%d,\"extended\":%s}",
1036 memCount += snprintf(NULL, 0,
1037 "{\"major\":%d,\"minor\":%d,\"flags\":%d,\"extended\":%s}",
1043 json = calloc(memCount + 1,
sizeof(
char));
1046 (void) snprintf(json, memCount,
1047 "{\"major\":%d,\"minor\":%d,\"flags\":%d,\"extended\":%s}",
1059 json = malloc(
sizeof(
char) * memCount);
1060 memcpy(json,
"{}\0", memCount);
char * id3v2TagHeaderToJSON(const Id3v2TagHeader *header)
Converts an ID3v2 tag header structure to JSON string representation.
Id3v2Tag * id3v2CreateTag(Id3v2TagHeader *header, List *frames)
Creates and allocates an ID3v2 tag structure.
int id3v2ReadImageSizeRestriction(Id3v2TagHeader *header)
Reads the image size restriction from an ID3v2.4 extended header.
void id3v2DestroyTag(Id3v2Tag **toDelete)
Frees an ID3v2 tag and all associated resources, nullifying the pointer.
bool id3v2WriteUnsynchronisationIndicator(Id3v2TagHeader *header, bool bit)
Sets or clears the unsynchronisation flag in the tag header.
int id3v2ReadFooterIndicator(Id3v2TagHeader *header)
Reads the footer presence flag from an ID3v2.4 tag header.
int id3v2ReadTextFieldsSizeRestriction(Id3v2TagHeader *header)
Reads the text fields size restriction from an ID3v2.4 extended header.
Id3v2ExtendedTagHeader * id3v2CreateExtendedTagHeader(uint32_t padding, uint32_t crc, bool update, bool tagRestrictions, uint8_t restrictions)
Creates and allocates an ID3v2 extended tag header structure.
int id3v2ReadImageEncodingRestriction(Id3v2TagHeader *header)
Reads the image encoding restriction from an ID3v2.4 extended header.
int id3v2ReadUnsynchronisationIndicator(Id3v2TagHeader *header)
Reads the unsynchronisation flag from a tag header.
bool id3v2WriteExtendedHeaderIndicator(Id3v2TagHeader *header, bool bit)
Sets or clears the extended header flag in ID3v2.3/ID3v2.4 tag headers.
int id3v2ReadExperimentalIndicator(Id3v2TagHeader *header)
Reads the experimental indicator flag from an ID3v2.3/ID3v2.4 tag header.
void id3v2DestroyTagHeader(Id3v2TagHeader **toDelete)
Frees an ID3v2 tag header and nullifies the pointer.
uint8_t * id3v2ExtendedTagHeaderSerialize(Id3v2ExtendedTagHeader *ext, uint8_t version, size_t *outl)
Serializes an ID3v2 extended tag header into a byte stream.
bool id3v2WriteFooterIndicator(Id3v2TagHeader *header, bool bit)
Sets or clears the footer presence flag in ID3v2.4 tag headers.
bool id3v2WriteCompressionIndicator(Id3v2TagHeader *header, bool bit)
Sets or clears the compression flag in ID3v2.2 tag headers.
bool id3v2WriteTextEncodingRestriction(Id3v2TagHeader *header, bool bit)
Sets the text encoding restriction in an ID3v2.4 extended header.
void id3v2DestroyExtendedTagHeader(Id3v2ExtendedTagHeader **toDelete)
Frees an ID3v2 extended tag header and nullifies the pointer.
Id3v2TagHeader * id3v2CreateTagHeader(uint8_t majorVersion, uint8_t minorVersion, uint8_t flags, Id3v2ExtendedTagHeader *extendedHeader)
Creates and allocates an ID3v2 tag header structure.
bool id3v2WriteExperimentalIndicator(Id3v2TagHeader *header, bool bit)
Sets or clears the experimental indicator flag in ID3v2.3/ID3v2.4 tag headers.
int id3v2ReadExtendedHeaderIndicator(Id3v2TagHeader *header)
Reads the extended header flag from an ID3v2.3/ID3v2.4 tag header.
bool id3v2WriteImageSizeRestriction(Id3v2TagHeader *header, uint8_t bits)
Sets the image size restriction in an ID3v2.4 extended header.
int id3v2ReadTextEncodingRestriction(Id3v2TagHeader *header)
Reads the text encoding restriction from an ID3v2.4 extended header.
uint8_t * id3v2TagHeaderSerialize(Id3v2TagHeader *header, uint32_t uintSize, size_t *outl)
Serializes an ID3v2 tag header into a byte stream.
int id3v2ReadCompressionIndicator(Id3v2TagHeader *header)
Reads the compression flag from an ID3v2.2 tag header.
char * id3v2ExtendedTagHeaderToJSON(const Id3v2ExtendedTagHeader *ext, uint8_t version)
Converts an ID3v2 extended tag header structure to JSON string representation.
bool id3v2WriteImageEncodingRestriction(Id3v2TagHeader *header, bool bit)
Sets the image encoding restriction in an ID3v2.4 extended header.
bool id3v2WriteTagSizeRestriction(Id3v2TagHeader *header, uint8_t bits)
Sets the tag size restriction in an ID3v2.4 extended header.
int id3v2ReadTagSizeRestriction(Id3v2TagHeader *header)
Reads the tag size restriction from an ID3v2.4 extended header.
bool id3v2ClearTagRestrictions(Id3v2TagHeader *header)
Clears all tag restrictions from an ID3v2.4 extended header.
bool id3v2WriteTextFieldsSizeRestriction(Id3v2TagHeader *header, uint8_t bits)
Sets the text encoding restriction in an ID3v2.4 extended header.
Function definitions of ID3v2 tag header and tag structure creation, manipulation,...
#define ID3V2_TAG_VERSION_3
ID3v2.3 major version number (3)
struct _Id3v2Tag Id3v2Tag
Complete ID3v2 tag structure containing header and metadata frames.
#define ID3V2_TAG_VERSION_2
ID3v2.2 major version number (2)
struct _Id3v2ExtendedTagHeader Id3v2ExtendedTagHeader
Optional ID3v2 extended header containing supplementary tag metadata.
#define ID3V2_TAG_ID_SIZE
Size in bytes of the ID3v2 tag identifier "ID3" or "3DI" (3 bytes)
#define ID3V2_TAG_VERSION_4
ID3v2.4 major version number (4)
struct _Id3v2TagHeader Id3v2TagHeader
ID3v2 tag header containing version and parsing information.
List * frames
Linked list of Id3v2Frame structures containing all tag metadata.
Id3v2TagHeader * header
Tag header with version, flags, and optional extended header.