App-MHFS
view release on metacpan or search on metacpan
share/public_html/static/music_worklet_inprogress/decoder/src/mhfs_cl_track.h view on Meta::CPAN
if((pictureData+pictureDataSize) != (frames + (framesize+frameheadersize)))
{
MHFSCLTR_PRINT("picture size is messed up\n");
}
MHFSCLTR_PRINT("APIC encoding: %X mime: %s type: %X, desc: %s\n", encoding, mime, type, desc);
mhfs_cl_track_meta_picture picture = {
.pictureType = type,
.mimeSize = mimeSize,
.mime = (uint8_t*)mime,
.descSize = descSize,
.desc = (uint8_t*)desc,
.pictureDataSize = pictureDataSize,
.pictureData = pictureData
};
on_metablock(context, MHFS_CL_TRACK_M_PICTURE, &picture);
}
}
tagSize -= (framesize+frameheadersize);
frames += (framesize+frameheadersize);
}
}
pTrack->vf.fileoffset = startoffset;
// check for magic
const uint8_t *id;
const blockvf_error idError = blockvf_read_view(&pTrack->vf, 4, &id, &pReturnData->needed_offset);
if(idError != BLOCKVF_SUCCESS)
{
return mhfs_cl_error_from_blockvf_error(idError);
}
const uint32_t uMagic = unaligned_beu32_to_native(id);
// sync
if((uMagic & 0xFFE00000) != 0xFFE00000)
{
return MHFS_CL_ERROR;
}
// version
const unsigned version = (uMagic & 0x00180000) >> 19;
if(version == MCT_MVER_RESERVED)
{
return MHFS_CL_ERROR;
}
// layer
const unsigned layer = (uMagic & 0x00060000) >> 17;
if(layer == MCT_MLAYER_RESERVED)
{
return MHFS_CL_ERROR;
}
// crc
const unsigned crc = (uMagic & 0x00010000) >> 16;
(void)crc;
// bitrate index
const unsigned bitrateindex = (uMagic & 0x0000F000) >> 12;
MHFSCLTR_PRINT("birateindex %u\n", bitrateindex);
if(bitrateindex == 0xF)
{
return MHFS_CL_ERROR;
}
static const uint8_t halfrate[2][3][15] = {
{ { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,16,24,28,32,40,48,56,64,72,80,88,96,112,128 } },
{ { 0,16,20,24,28,32,40,48,56,64,80,96,112,128,160 }, { 0,16,24,28,32,40,48,56,64,80,96,112,128,160,192 }, { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224 } },
};
const unsigned bitrate = 2*halfrate[!!(version & 0x1)][layer - 1][bitrateindex];
MHFSCLTR_PRINT("bitrate %u\n", bitrate);
// samplerate index
const unsigned samplerateindex = (uMagic & 0x00000C00) >> 10;
MHFSCLTR_PRINT("samplerateindex %u\n", samplerateindex);
if(samplerateindex == 0x3)
{
return MHFS_CL_ERROR;
}
static const unsigned g_hz[3] = { 44100, 48000, 32000 };
const unsigned sampleRate = g_hz[samplerateindex] >> (int)!(version & 0x1) >> (int)!(version & 0x2);
//padding and priv -- not read
//channel mode
const unsigned channelmode = (uMagic & 0x000000C0) >> 6;
MHFSCLTR_PRINT("channel mode %u\n", channelmode);
const unsigned channels = (channelmode == 3) ? 1 : 2;
unsigned expectedXing = (channels == 2) ? 32 : 17;
expectedXing += (!crc);
MHFSCLTR_PRINT("Expecting xing %u bytes after mpeg header\n", expectedXing);
const blockvf_error skipblockError = blockvf_seek(&pTrack->vf, expectedXing, blockvf_seek_origin_current);
if(skipblockError != BLOCKVF_SUCCESS)
{
MHFSCLTR_PRINT("Stopping metadata parsing, blockvf error\n");
return mhfs_cl_error_from_blockvf_error(skipblockError);
}
// check for xing
const uint8_t *xing;
const blockvf_error xingError = blockvf_read_view(&pTrack->vf, 4, &xing, &pReturnData->needed_offset);
if(xingError != BLOCKVF_SUCCESS)
{
return mhfs_cl_error_from_blockvf_error(xingError);
}
MHFSCLTR_PRINT("xing/vbr magic %c %c %c %c | %x %x %x %x\n", xing[0], xing[1], xing[2], xing[3], xing[0], xing[1], xing[2], xing[3]);
bool isXing = (memcmp(xing, "Xing", 4) == 0) || (memcmp(xing, "Info", 4) == 0);
if(!isXing)
{
// Xing tag may be misplaced when CRC protection is enabled, check for that and zeroed flag fields
isXing = (memcmp(xing, "ng\0\0", 4) == 0) || (memcmp(xing, "fo\0\0", 4) == 0);
if(isXing)
{
pTrack->vf.fileoffset -= 2;
}
}
if(isXing)
{
const uint8_t *flagsBytes;
const blockvf_error xingFlagsError = blockvf_read_view(&pTrack->vf, 4, &flagsBytes, &pReturnData->needed_offset);
if(xingFlagsError != BLOCKVF_SUCCESS)
{
return mhfs_cl_error_from_blockvf_error(xingFlagsError);
}
const uint32_t xingFlags = unaligned_beu32_to_native(flagsBytes);
if(xingFlags & 0x1)
{
const uint8_t *framesBytes;
const blockvf_error framesError = blockvf_read_view(&pTrack->vf, 4, &framesBytes, &pReturnData->needed_offset);
if(framesError != BLOCKVF_SUCCESS)
{
( run in 2.740 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )