10#include <sp/spChunk.h>
16#ifdef SP_SUPPORT_64BIT_INT
18#define SP_CAF_MIN_ENTRY_ALLOC_COUNT 4
20#define SP_CAF_SUPPORTED_FILE_VERSION 1
21#define SP_CAF_SUPPORTED_FILE_FLAGS 0
23#define SP_CAF_INFORMATION_KEY_TITLE "title"
24#define SP_CAF_INFORMATION_KEY_ARTIST "artist"
25#define SP_CAF_INFORMATION_KEY_ALBUM "album"
26#define SP_CAF_INFORMATION_KEY_TRACK "track number"
27#define SP_CAF_INFORMATION_KEY_RELEASE "year"
28#define SP_CAF_INFORMATION_KEY_COMPOSER "composer"
29#define SP_CAF_INFORMATION_KEY_LYRICIST "lyricist"
30#define SP_CAF_INFORMATION_KEY_GENRE "genre"
31#define SP_CAF_INFORMATION_KEY_COMMENT "comments"
32#define SP_CAF_INFORMATION_KEY_COPYRIGHT "copyright"
33#define SP_CAF_INFORMATION_KEY_SOFTWARE "encoding application"
34#define SP_CAF_INFORMATION_KEY_TEMPO "tempo"
36#define SP_CAF_INFORMATION_KEY_ALBUM_ARTIST "album artist"
37#define SP_CAF_INFORMATION_KEY_DISC "disc number"
40 SP_CAF_LPCM_FORMAT_FLAG_IS_FLOAT = (1 << 0),
41 SP_CAF_LPCM_FORMAT_FLAG_IS_LITTLE_ENDIAN = (1 << 1),
43#if BYTE_ORDER == BIG_ENDIAN
44#define SP_CAF_LPCM_FORMAT_FLAG_IS_NATIVE_ENDIAN 0
46#define SP_CAF_LPCM_FORMAT_FLAG_IS_NATIVE_ENDIAN SP_CAF_LPCM_FORMAT_FLAG_IS_LITTLE_ENDIAN
50 SP_CAF_ALAC_FORMAT_FLAG_16BIT_SOURCE_DATA = 1,
51 SP_CAF_ALAC_FORMAT_FLAG_20BIT_SOURCE_DATA = 2,
52 SP_CAF_ALAC_FORMAT_FLAG_24BIT_SOURCE_DATA = 3,
53 SP_CAF_ALAC_FORMAT_FLAG_32BIT_SOURCE_DATA = 4,
56typedef struct _spCafChunkHeader {
63typedef struct _spCafChunk {
64 struct _spCafChunk *parent;
65 struct _spCafChunk *child;
67 struct _spCafChunk *prev;
68 struct _spCafChunk *next;
72 spCafChunkHeader header;
75typedef struct _spCafAudioDescChunk {
76 struct _spCafChunk *parent;
77 struct _spCafChunk *child;
79 struct _spCafChunk *prev;
80 struct _spCafChunk *next;
84 spCafChunkHeader header;
90 long mFramesPerPacket;
91 long mChannelsPerFrame;
95typedef struct _spCafAudioDataChunk {
96 struct _spCafChunk *parent;
97 struct _spCafChunk *child;
99 struct _spCafChunk *prev;
100 struct _spCafChunk *next;
104 spCafChunkHeader header;
108} spCafAudioDataChunk;
110typedef struct _spCafGeneralDataChunk {
111 struct _spCafChunk *parent;
112 struct _spCafChunk *child;
114 struct _spCafChunk *prev;
115 struct _spCafChunk *next;
119 spCafChunkHeader header;
123} spCafGeneralDataChunk;
125typedef struct _spCafChannelDescription {
126 unsigned long mChannelLabel;
127 unsigned long mChannelFlags;
128 float mCoordinates[3];
129} spCafChannelDescription;
131typedef struct _spCafChannelLayoutChunk {
132 struct _spCafChunk *parent;
133 struct _spCafChunk *child;
135 struct _spCafChunk *prev;
136 struct _spCafChunk *next;
140 spCafChunkHeader header;
142 unsigned long mChannelLayoutTag;
143 unsigned long mChannelBitmap;
144 unsigned long mNumberChannelDescriptions;
145 spCafChannelDescription *mChannelDescriptions;
146} spCafChannelLayoutChunk;
148typedef struct _spCafPacketTableChunk {
149 struct _spCafChunk *parent;
150 struct _spCafChunk *child;
152 struct _spCafChunk *prev;
153 struct _spCafChunk *next;
157 spCafChunkHeader header;
159 spLong64 mNumberPackets;
160 spLong64 mNumberValidFrames;
162 long mRemainderFrames;
164 spLong64 mBufferSize;
169} spCafPacketTableChunk;
171typedef struct _spCafInformation {
176typedef struct _spCafInformationChunk {
177 struct _spCafChunk *parent;
178 struct _spCafChunk *child;
180 struct _spCafChunk *prev;
181 struct _spCafChunk *next;
185 spCafChunkHeader header;
189 spCafInformation *mInformations;
190} spCafInformationChunk;
192typedef struct _spCafHeader {
193 struct _spCafChunk *parent;
194 struct _spCafChunk *child;
196 struct _spCafChunk *prev;
197 struct _spCafChunk *next;
201 spCafChunkHeader header;
203 unsigned short mFileVersion;
204 unsigned short mFileFlags;
206 struct _spCafAudioDescChunk *desc;
207 struct _spCafAudioDataChunk *data;
209 struct _spCafPacketTableChunk *pakt;
210 struct _spCafGeneralDataChunk *kuki;
213typedef spChunkSize (*spCafChunkUpdateFunc)(spCafChunk *chunk,
void *data);
215extern spBool spEqCafChunkType(spCafChunk *chunk,
const char *type);
217extern const char *spGetCafInformationValue(spCafInformationChunk *info,
const char *key,
long *index);
218extern long spGetCafInformationValueInLocaleCode(spCafInformationChunk *info,
const char *key,
unsigned char *str_in_locale,
long size);
220extern spChunkSize spGetCafChunkContentMarginSize(spCafChunk *chunk);
221extern spBool spSetCafChunkContentSize(spCafChunk *chunk, spChunkSize size);
222extern spChunkSize spGetCafChunkSize(spCafChunk *chunk,
char *
string);
223extern spChunkSize spGetCafChunkContentSize(spCafChunk *chunk,
char *
string);
225extern spChunkSize spReadCafHeader(spCafHeader *header, FILE *fp);
226extern spBool spFreeCafHeader(spCafHeader *header);
228extern spChunkSize spWriteCafHeader(spCafHeader *header, FILE *fp);
229extern spChunkSize spRewriteCafHeader(spCafHeader *header,
long editCount, spLong64 dataSize, FILE *fp);
231extern spChunkSize spCopyCafHeader(spCafHeader *dest_header, spCafHeader *src_header);
233extern spBool spInitCafHeaderWithCB(spCafHeader *header,
unsigned short fileVersion,
unsigned short fileFlags,
234 spCafChunkUpdateFunc update_func,
void *data);
235extern spBool spInitCafHeader(spCafHeader *header,
unsigned short fileVersion,
unsigned short fileFlags);
236extern spBool spUpdateCafAudioDescChunk(spCafHeader *header,
double sampleRate,
const char *formatID,
237 long formatFlags,
long bytesPerPacket,
long framesPerPacket,
238 long channelsPerFrame,
long bitsPerChannel);
239extern spBool spUpdateCafGeneralDataChunk(spCafHeader *header,
const char *type,
char *data, spLong64 size,
spBool copy_flag);
240extern spBool spUpdateCafPacketTableChunkForFixedFrame(spCafHeader *header,
long packetMarginSize, spLong64 totalFrames,
long *maxPacketSize);
241extern spBool spUpdateCafPacketTableChunkNumberPackets(spCafHeader *header, spLong64 numberPackets, spLong64 totalFrames,
spBool *insufficientBuffer);
243extern spBool spUpdateCafAudioDataChunk(spCafHeader *header,
long editCount, spLong64 dataSize);
245extern spCafInformationChunk *spCreateCafInformationChunk(spCafHeader *header, spLong64 sizeWithFree);
246extern spBool spUpdateCafInformationChunk(spCafInformationChunk *info,
const char *key,
const char *value);
247extern spBool spUpdateCafInformationChunkFromLocaleCode(spCafInformationChunk *info,
const char *key,
const unsigned char *str_in_locale);
249extern spBool spAppendCafInformationChunk(spCafHeader *header,
const char *key,
const char *value);
250extern spBool spAppendCafInformationChunkFromLocaleCode(spCafHeader *header,
const char *key,
const unsigned char *str_in_locale);
255extern spCafChunk *spFindCafChunkFromHeader(spCafHeader *header,
const char *type);
257extern spFileOffset spConvertCafTimeToFileOffset(spCafHeader *header, spLong64 t,
258 long *packet,
long *remainder,
long *packet_frames);
259extern spLong64 spGetCafTotalDuration(spCafHeader *header);
260extern spLong64 spGetCafPacketSize(spCafHeader *header,
long packet);
261extern spBool spSetCafPacketSize(spCafHeader *header,
long packet, spLong64 size);
262extern spBool spSetCafFrameLength(spCafHeader *header,
long packet, spLong64 length);