static unsigned char * set_frame(unsigned char *frame, unsigned long id, const char *text, size_t length) { if (length) { frame = set_4_byte_value(frame, id); /* Set frame size = total size - header size. Frame header and field * bytes include 2-byte header flags, 1 encoding descriptor byte, and * for comment frames: 3-byte language descriptor and 1 content * descriptor byte */ frame = set_4_byte_value(frame, ((id == COMMENT_FRAME_ID) ? 5 : 1) + length); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* clear 1 encoding descriptor byte to indicate ISO-8859-1 format */ *frame++ = 0; if (id == COMMENT_FRAME_ID) { /* use id3lib-compatible bogus language descriptor */ *frame++ = 'X'; *frame++ = 'X'; *frame++ = 'X'; /* clear 1 byte to make content descriptor empty string */ *frame++ = 0; } while (length--) { *frame++ = *text++; } } return frame; }
static unsigned char * set_frame_apic(unsigned char *frame, const char *mimetype, const unsigned char *data, size_t size) { /* ID3v2.3 standard APIC frame: * <Header for 'Attached picture', ID: "APIC"> * Text encoding $xx * MIME type <text string> $00 * Picture type $xx * Description <text string according to encoding> $00 (00) * Picture data <binary data> */ if (mimetype && data && size) { frame = set_4_byte_value(frame, FRAME_ID('A', 'P', 'I', 'C')); frame = set_4_byte_value(frame, (unsigned long) (4 + strlen(mimetype) + size)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* clear 1 encoding descriptor byte to indicate ISO-8859-1 format */ *frame++ = 0; /* copy mime_type */ while (*mimetype) { *frame++ = *mimetype++; } *frame++ = 0; /* set picture type to 0 */ *frame++ = 0; /* empty description field */ *frame++ = 0; /* copy the image data */ while (size--) { *frame++ = *data++; } } return frame; }
static unsigned char * set_frame_custom2(unsigned char *frame, FrameDataNode const *node) { size_t const n = sizeOfNode(node); if (n > 10) { frame = set_4_byte_value(frame, node->fid); frame = set_4_byte_value(frame, (unsigned long) (n - 10)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* clear 1 encoding descriptor byte to indicate ISO-8859-1 format */ *frame++ = node->txt.enc == 1 ? 1 : 0; if (node->dsc.dim > 0) { if (node->dsc.enc != 1) { frame = writeChars(frame, node->dsc.ptr.l, node->dsc.dim); *frame++ = 0; } else { frame = writeUcs2s(frame, node->dsc.ptr.u, node->dsc.dim); *frame++ = 0; *frame++ = 0; } } if (node->txt.enc != 1) { frame = writeChars(frame, node->txt.ptr.l, node->txt.dim); } else { frame = writeUcs2s(frame, node->txt.ptr.u, node->txt.dim); } } return frame; }
static unsigned char * set_frame_comment(unsigned char *frame, FrameDataNode const *node) { size_t const n = sizeOfCommentNode(node); if (n > 10) { frame = set_4_byte_value(frame, node->fid); frame = set_4_byte_value(frame, (uint32_t) (n - 10)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* encoding descriptor byte */ *frame++ = node->txt.enc == 1 ? 1 : 0; /* 3 bytes language */ *frame++ = node->lng[0]; *frame++ = node->lng[1]; *frame++ = node->lng[2]; /* descriptor with zero byte(s) separator */ if (node->dsc.enc != 1) { frame = writeChars(frame, node->dsc.ptr.l, node->dsc.dim); *frame++ = 0; } else { frame = writeUcs2s(frame, node->dsc.ptr.u, node->dsc.dim); *frame++ = 0; *frame++ = 0; } /* comment full text */ if (node->txt.enc != 1) { frame = writeChars(frame, node->txt.ptr.l, node->txt.dim); } else { frame = writeUcs2s(frame, node->txt.ptr.u, node->txt.dim); } } return frame; }
static unsigned char * set_frame_custom(unsigned char *frame, const char *fieldvalue) { if (fieldvalue && *fieldvalue) { const char *value = fieldvalue + 5; size_t length = strlen(value); *frame++ = *fieldvalue++; *frame++ = *fieldvalue++; *frame++ = *fieldvalue++; *frame++ = *fieldvalue++; frame = set_4_byte_value(frame, (unsigned long) (strlen(value) + 1)); /* clear 2-byte header flags */ *frame++ = 0; *frame++ = 0; /* clear 1 encoding descriptor byte to indicate ISO-8859-1 format */ *frame++ = 0; while (length--) { *frame++ = *value++; } } return frame; }