int IndexBlocks_GetTrackRangeInfo(IndexBlocks blocks, int trackNumber, int* byteOffset, int* length, int* trackOffset) { struct _IndexBlockNode* node = NULL; int trackCount = 0; struct _IndexBlocks* instance = (struct _IndexBlocks*)blocks; if(instance == NULL || trackNumber < 0 || byteOffset == NULL || length == NULL || trackOffset == NULL) { return 0; } if(instance->_blockCount == 0) { return 0; } trackCount = IndexBlocks_GetTrackCount(blocks); if(trackNumber >= trackCount) { return 0; } sem_wait(&instance->_sync); node = _FindTrackBlock(instance->_firstNode, trackNumber); sem_post(&instance->_sync); if(node == NULL) { return 0; } *byteOffset = node->ByteOffset; *length = (int)node->ByteLength; *trackOffset = (int)node->FirstTrackNumber; return 1; }
void _ProcessBuffer(PlayListManager_S state, int done) { int i; char* usableBuffer = NULL; int streamOffset = 0; int trackCount = 0; int bufferLength = CircularBuffer_GetLength(state->_buffer); int startOfFirstItem = CircularBuffer_FindPattern(state->_buffer, 0, "<item", 5); int lengthOfUsableBuffer = -1; if(startOfFirstItem >= 0) { lengthOfUsableBuffer = (CircularBuffer_FindLastPattern(state->_buffer, 0, "</item>", 7) + 7) - startOfFirstItem; trackCount++; } else { CircularBuffer_ConsumeBytes(state->_buffer, bufferLength - 4); state->_streamOffset += (bufferLength - 4); if(done == 1) { sem_post(&state->BlocksFinished); } return; } streamOffset = state->_streamOffset + startOfFirstItem; usableBuffer = (char*)malloc(lengthOfUsableBuffer); CircularBuffer_CopyFrom(state->_buffer, usableBuffer, 0, startOfFirstItem, lengthOfUsableBuffer - startOfFirstItem); CircularBuffer_ConsumeBytes(state->_buffer, lengthOfUsableBuffer + startOfFirstItem); state->_streamOffset += startOfFirstItem; for(i = 5; i < (lengthOfUsableBuffer - 5); i++) { if(memcmp(usableBuffer + i, "<item", (size_t)5) == 0) { trackCount++; } } IndexBlocks_AddBlock(state->Blocks, streamOffset, lengthOfUsableBuffer, trackCount); state->_streamOffset += lengthOfUsableBuffer; state->Parent->TrackCount = IndexBlocks_GetTrackCount(state->Blocks); BitArray_ChangeSize(state->Parent->ShuffleArray, state->Parent->TrackCount); free(usableBuffer); sem_post(&state->FirstBlockFinished); if(done == 1) { sem_post(&state->BlocksFinished); } if(state->Parent->OnTrackCountChanged != NULL) { state->Parent->OnTrackCountChanged(state->Parent); } }