int extract(FILE *f, ArchFileInfo *info, char *fileName) { LOGGING_FUNC_START; int _error = 0; FILE *fOut = NULL; char *buf = malloc(BUF_SIZE*sizeof(char)); char *buf2Write = malloc(BUF_SIZE*sizeof(char)*8); size_t lenBits = 0; size_t readBytes = 0; size_t returnBytes = 0; size_t readedBytes = 0; size_t howManyBytesRead = 0; Tree *haffTree = NULL; if (NULL == (fOut = fopen(fileName, "wb"))) { IO(L"Couldnt open file `%s`", fileName); __forErrorFileName = fileName; LOGGING_FUNC_STOP; return FILE_OPEN_ERROR; } haffTree = decodeTree(info->haffTree,info->haffTreeSize); initDecoding(haffTree); for (readedBytes=0; readedBytes < info->dataSize;) { howManyBytesRead = min(BUF_SIZE, (info->dataSize - readedBytes)); _error = readNBytes(f, howManyBytesRead, buf, &readBytes); readedBytes += readBytes; if (_error) { IO(L"Error reading archive file"); LOGGING_FUNC_STOP; return ARCHIVE_ERROR; } lenBits = (howManyBytesRead < BUF_SIZE) ? readBytes*8 - info->endUnusedBits : readBytes*8; decode(buf,lenBits,buf2Write,&returnBytes); _error = writeNBytes(fOut, returnBytes, buf2Write); if (_error) { IO("Write error to `%s`", fileName); __forErrorFileName = fileName; return _error; } } fclose(fOut); free(haffTree); LOGGING_FUNC_STOP; return 0; }
SoundSourceMp3::SoundSourceMp3(const QUrl& url) : SoundSource(url, "mp3"), m_file(getLocalFileName()), m_fileSize(0), m_pFileData(nullptr), m_avgSeekFrameCount(0), m_curFrameIndex(getMinFrameIndex()), m_madSynthCount(0) { m_seekFrameList.reserve(kSeekFrameListCapacity); initDecoding(); }
void SoundSourceMp3::close() { finishDecoding(); if (m_pFileData) { m_file.unmap(m_pFileData); m_pFileData = nullptr; } m_file.close(); m_seekFrameList.clear(); // Re-init the decoder, because the SoundSource might be reopened and // the destructor calls finishDecoding() after close(). initDecoding(); }