void Pipe::Initialize() { CreateDictionary(); CreateReader(); CreateWriter(); CreateDecoder(); parameters_ = new Parameters; }
void OnStart( const std::string& RootPath ) { auto FS = make_intrusive<clFileSystem>(); FS->Mount( "" ); FS->Mount( RootPath ); FS->AddAliasMountPoint( RootPath, "assets" ); const char* ArchiveName = "test.zip"; auto File = FS->CreateReader( ArchiveName ); auto Reader = make_intrusive<clArchiveReader>(); if ( !Reader->OpenArchive( File ) ) { LOGI( "Bad archive: %s", ArchiveName ); return; } /// Iterate the files in archive for ( size_t i = 0; i != Reader->GetNumFiles(); i++ ) { LOGI( "File[%i]: %s", i, Reader->GetFileName( i ).c_str() ); const char* Data = reinterpret_cast<const char*>( Reader->GetFileDataIdx( i ) ); LOGI( "Data: %s", std::string( Data, static_cast<size_t>( Reader->GetFileSizeIdx( i ) ) ).c_str() ); } }
MediaDecoderStateMachine* MediaOmxCommonDecoder::CreateStateMachine() { mReader = CreateReader(); if (mReader != nullptr) { mReader->SetAudioChannel(GetAudioChannel()); } return CreateStateMachineFromReader(mReader); }
hsError plSoundPreloader::Run() { hsTArray<plSoundBuffer*> templist; while (fRunning) { fCritSect.Lock(); while (fBuffers.GetCount()) { templist.Append(fBuffers.Pop()); } fCritSect.Unlock(); if (templist.GetCount() == 0) { fEvent.Wait(); } else { plAudioFileReader *reader = nil; while (templist.GetCount()) { plSoundBuffer* buf = templist.Pop(); if (buf->GetData()) { reader = CreateReader(true, buf->GetFileName(), buf->GetAudioReaderType(), buf->GetReaderSelect()); if( reader ) { unsigned readLen = buf->GetAsyncLoadLength() ? buf->GetAsyncLoadLength() : buf->GetDataLength(); reader->Read( readLen, buf->GetData() ); buf->SetAudioReader(reader); // give sound buffer reader, since we may need it later } else { buf->SetError(); } } buf->SetLoaded(true); } } } // we need to be sure that all buffers are removed from our load list when shutting this thread down or we will hang, // since the sound buffer will wait to be destroyed until it is marked as loaded fCritSect.Lock(); while (fBuffers.GetCount()) { plSoundBuffer* buf = fBuffers.Pop(); buf->SetLoaded(true); } fCritSect.Unlock(); return hsOK; }
int main(int argc, const char* argv[]) { const char* usage = "usage: %s x file1... file2...\n" \ " where xy are format codes for the input.\n" \ " m - Multifile\n" \ " s - SSD (blockdevice + index)\n" \ " d - Delta (transitional compressed format without index.)\n"; if (argc<3) { printf(usage,argv[0]); return -1; } int consume = argc-2; BaseReader* dr = CreateReader(argv[1][0],&argv[2],consume); if (dr==NULL) { printf("No reader for type %c found.\n",argv[1][0]); return -1; } if (!dr->isOK()) { printf("Error opening files.\n"); return -1; } uint64_t e,i; uint64_t e2,i2; /* Read the first chain */ bool more = dr->Read(e,i); printf("Dumping file."); // printf("%llx %llx\n",e,i); // printf("%llx %llx\n",e2,i2); uint64_t cnt = 0; while(more) { printf("%llx %llx\n",e,i); cnt++; more = dr->Read(e,i); } cnt++; printf("%lli chains read.\n",cnt); delete dr; return 0; }
OGRFeature *OGRFMELayerDB::GetNextFeature() { OGRFeature *poFeature; FME_Boolean eEndOfSchema; FME_MsgNum err; poDS->AcquireSession(); if( poReader == NULL ) { if( !CreateReader() ) { return NULL; poDS->ReleaseSession(); } } err = poReader->read( *poFMEFeature, eEndOfSchema ); if( err ) { CPLFMEError( poDS->GetFMESession(), "Error while reading feature." ); poDS->ReleaseSession(); return NULL; } if( eEndOfSchema == FME_TRUE ) { poDS->ReleaseSession(); return NULL; } poFeature = poDS->ProcessFeature( this, poFMEFeature ); if( nPreviousFeature == -1 ) CPLDebug( "FMEOLEDB", "Fetching first feature from layer `%s'.", GetLayerDefn()->GetName() ); poFeature->SetFID( ++nPreviousFeature ); m_nFeaturesRead++; poDS->ReleaseSession(); return poFeature; }
const VSIArchiveContent* VSIArchiveFilesystemHandler::GetContentOfArchive (const char* archiveFilename, VSIArchiveReader* poReader) { CPLMutexHolder oHolder( &hMutex ); if (oFileList.find(archiveFilename) != oFileList.end() ) { return oFileList[archiveFilename]; } int bMustClose = (poReader == NULL); if (poReader == NULL) { poReader = CreateReader(archiveFilename); if (!poReader) return NULL; } if (poReader->GotoFirstFile() == FALSE) { if (bMustClose) delete(poReader); return NULL; } VSIArchiveContent* content = new VSIArchiveContent; content->nEntries = 0; content->entries = NULL; oFileList[archiveFilename] = content; std::set<CPLString> oSet; do { CPLString osFileName = poReader->GetFileName(); const char* fileName = osFileName.c_str(); /* Remove ./ pattern at the beginning of a filename */ if (fileName[0] == '.' && fileName[1] == '/') { fileName += 2; if (fileName[0] == '\0') continue; } char* pszStrippedFileName = CPLStrdup(fileName); char* pszIter; for(pszIter = pszStrippedFileName;*pszIter;pszIter++) { if (*pszIter == '\\') *pszIter = '/'; } int bIsDir = strlen(fileName) > 0 && fileName[strlen(fileName)-1] == '/'; if (bIsDir) { /* Remove trailing slash */ pszStrippedFileName[strlen(fileName)-1] = 0; } if (oSet.find(pszStrippedFileName) == oSet.end()) { oSet.insert(pszStrippedFileName); /* Add intermediate directory structure */ for(pszIter = pszStrippedFileName;*pszIter;pszIter++) { if (*pszIter == '/') { char* pszStrippedFileName2 = CPLStrdup(pszStrippedFileName); pszStrippedFileName2[pszIter - pszStrippedFileName] = 0; if (oSet.find(pszStrippedFileName2) == oSet.end()) { oSet.insert(pszStrippedFileName2); content->entries = (VSIArchiveEntry*)CPLRealloc(content->entries, sizeof(VSIArchiveEntry) * (content->nEntries + 1)); content->entries[content->nEntries].fileName = pszStrippedFileName2; content->entries[content->nEntries].nModifiedTime = poReader->GetModifiedTime(); content->entries[content->nEntries].uncompressed_size = 0; content->entries[content->nEntries].bIsDir = TRUE; content->entries[content->nEntries].file_pos = NULL; if (ENABLE_DEBUG) CPLDebug("VSIArchive", "[%d] %s : " CPL_FRMT_GUIB " bytes", content->nEntries+1, content->entries[content->nEntries].fileName, content->entries[content->nEntries].uncompressed_size); content->nEntries++; } else { CPLFree(pszStrippedFileName2); } } } content->entries = (VSIArchiveEntry*)CPLRealloc(content->entries, sizeof(VSIArchiveEntry) * (content->nEntries + 1)); content->entries[content->nEntries].fileName = pszStrippedFileName; content->entries[content->nEntries].nModifiedTime = poReader->GetModifiedTime(); content->entries[content->nEntries].uncompressed_size = poReader->GetFileSize(); content->entries[content->nEntries].bIsDir = bIsDir; content->entries[content->nEntries].file_pos = poReader->GetFileOffset(); if (ENABLE_DEBUG) CPLDebug("VSIArchive", "[%d] %s : " CPL_FRMT_GUIB " bytes", content->nEntries+1, content->entries[content->nEntries].fileName, content->entries[content->nEntries].uncompressed_size); content->nEntries++; } else { CPLFree(pszStrippedFileName); } } while(poReader->GotoNextFile()); if (bMustClose) delete(poReader); return content; }
int VSIArchiveFilesystemHandler::Stat( const char *pszFilename, VSIStatBufL *pStatBuf, CPL_UNUSED int nFlags ) { int ret = -1; CPLString osFileInArchive; memset(pStatBuf, 0, sizeof(VSIStatBufL)); char* archiveFilename = SplitFilename(pszFilename, osFileInArchive, TRUE); if (archiveFilename == NULL) return -1; if (strlen(osFileInArchive) != 0) { if (ENABLE_DEBUG) CPLDebug("VSIArchive", "Looking for %s %s\n", archiveFilename, osFileInArchive.c_str()); const VSIArchiveEntry* archiveEntry = NULL; if (FindFileInArchive(archiveFilename, osFileInArchive, &archiveEntry)) { /* Patching st_size with uncompressed file size */ pStatBuf->st_size = archiveEntry->uncompressed_size; pStatBuf->st_mtime = (time_t)archiveEntry->nModifiedTime; if (archiveEntry->bIsDir) pStatBuf->st_mode = S_IFDIR; else pStatBuf->st_mode = S_IFREG; ret = 0; } } else { VSIArchiveReader* poReader = CreateReader(archiveFilename); CPLFree(archiveFilename); archiveFilename = NULL; if (poReader != NULL && poReader->GotoFirstFile()) { /* Skip optionnal leading subdir */ CPLString osFileName = poReader->GetFileName(); const char* fileName = osFileName.c_str(); if (fileName[strlen(fileName)-1] == '/' || fileName[strlen(fileName)-1] == '\\') { if (poReader->GotoNextFile() == FALSE) { delete(poReader); return -1; } } if (poReader->GotoNextFile()) { /* Several files in archive --> treat as dir */ pStatBuf->st_size = 0; pStatBuf->st_mode = S_IFDIR; } else { /* Patching st_size with uncompressed file size */ pStatBuf->st_size = poReader->GetFileSize(); pStatBuf->st_mtime = (time_t)poReader->GetModifiedTime(); pStatBuf->st_mode = S_IFREG; } ret = 0; } delete(poReader); } CPLFree(archiveFilename); return ret; }
VSIArchiveReader* VSIArchiveFilesystemHandler::OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName) { VSIArchiveReader* poReader = CreateReader(archiveFilename); if (poReader == NULL) { return NULL; } if (fileInArchiveName == NULL || strlen(fileInArchiveName) == 0) { if (poReader->GotoFirstFile() == FALSE) { delete(poReader); return NULL; } /* Skip optionnal leading subdir */ CPLString osFileName = poReader->GetFileName(); const char* fileName = osFileName.c_str(); if (fileName[strlen(fileName)-1] == '/' || fileName[strlen(fileName)-1] == '\\') { if (poReader->GotoNextFile() == FALSE) { delete(poReader); return NULL; } } if (poReader->GotoNextFile()) { CPLString msg; msg.Printf("Support only 1 file in archive file %s when no explicit in-archive filename is specified", archiveFilename); const VSIArchiveContent* content = GetContentOfArchive(archiveFilename, poReader); if (content) { int i; msg += "\nYou could try one of the following :\n"; for(i=0;i<content->nEntries;i++) { msg += CPLString().Printf(" %s/%s/%s\n", GetPrefix(), archiveFilename, content->entries[i].fileName); } } CPLError(CE_Failure, CPLE_NotSupported, "%s", msg.c_str()); delete(poReader); return NULL; } } else { const VSIArchiveEntry* archiveEntry = NULL; if (FindFileInArchive(archiveFilename, fileInArchiveName, &archiveEntry) == FALSE || archiveEntry->bIsDir) { delete(poReader); return NULL; } if (!poReader->GotoFileOffset(archiveEntry->file_pos)) { delete poReader; return NULL; } } return poReader; }