📄 aflibfile.cc
字号:
this function will make a call to the derived classes function. */aflibStatusaflibFile::afcreate( const char * file, const aflibConfig& cfg){ aflibStatus status = AFLIB_SUCCESS; if(_file_object) { status = _file_object->afcreate(file, cfg); } else { status = AFLIB_ERROR_INITIALIZATION_FAILURE; } return (status);}/*! \brief Main API function to read a segment of data. This function is only used for module support. For no module support the derived classes afread function will be called instead. For module support this function will make a call to the derived classes function. */aflibStatusaflibFile::afread( aflibData& data, long long position){ aflibStatus status = AFLIB_SUCCESS; if(_file_object) { status = _file_object->afread(data, position); } else { status = AFLIB_ERROR_INITIALIZATION_FAILURE; } return (status);}/*! \brief Main API function to write a segment of audio data. This function is only used for module support. For no module support the derived classes afwrite function will be called instead. For module support this function will make a call to the derived class. */aflibStatusaflibFile::afwrite( aflibData& data, long long position){ aflibStatus status = AFLIB_SUCCESS; if(_file_object) { status = _file_object->afwrite(data, position); } else { status = AFLIB_ERROR_INITIALIZATION_FAILURE; } return (status);}/*! \brief Provides the ability to set format specific information. This provides the ability to set specific information relating to a specific format. One passes an item that is a specific character string that will be recognized by a format. One also passes a void pointer to a data item that is the data to be set. The documentation for the specific item will say what format the data should be. TRUE will be returned if the item was processed successfully otherwise FALSE will be returned. */boolaflibFile::setItem( const char * item, const void * value){ bool status = FALSE; if(_file_object) { status = _file_object->setItem(item, value); } else { status = AFLIB_ERROR_INITIALIZATION_FAILURE; } return (status);}/*! \brief Provides the ability to get format specific information. This provides the ability to get specific information relating to a specific format. One passes an item that is a specific character string that will be recognized by a format. One also passes a void pointer to an allocated object of the correct type. This data will be filled with the correct information. The documentation for the specific item will say what format the data should be. TRUE will be returned if the item was processed successfully otherwise FALSE will be returned. */ boolaflibFile::getItem( const char * item, void * value){ bool status = FALSE; if(_file_object) { status = _file_object->getItem(item, value); } else { status = AFLIB_ERROR_INITIALIZATION_FAILURE; } return (status);} voidaflibFile::setInputConfig(const aflibConfig& cfg){ // This is a virtual function that derived classes can override if needed. // It allows the caller to set the configuration of the audio data of an // object. if (_file_object) _file_object->setInputConfig(cfg); else _cfg_input = cfg;}const aflibConfig&aflibFile::getInputConfig() const{ // This function will return the input audio data configuration if (_file_object) return (_file_object->getInputConfig()); else return (_cfg_input);} voidaflibFile::setOutputConfig(const aflibConfig& cfg){ // This function allows one to store the output audio configuration // for a derived class. if (_file_object) _file_object->setOutputConfig(cfg); else _cfg_output = cfg;}const aflibConfig&aflibFile::getOutputConfig() const{ // This function will return the output audio data configuration if (_file_object) return (_file_object->getOutputConfig()); else return (_cfg_output);} boolaflibFile::isDataSizeSupported(aflib_data_size size){ // See the description for aflibAudio::isDataSizeSupported. bool ret_value = TRUE; if (_file_object) ret_value = _file_object->isDataSizeSupported(size); return (ret_value);} boolaflibFile::isEndianSupported(aflib_data_endian end){ // See the description for aflibAudio::isEndianSupported. bool ret_value = TRUE; if (initialized()==true) ret_value = _file_object->isEndianSupported(end); return (ret_value);} boolaflibFile::isSampleRateSupported(int& rate){ // See the description for aflibAudio::isSampleRateSupported. bool ret_value = TRUE; if (_file_object) ret_value = _file_object->isSampleRateSupported(rate); return (ret_value);} boolaflibFile::isChannelsSupported(int& channels){ // See the description for aflibAudio::isChannelsSupported. bool ret_value = TRUE; if (_file_object) ret_value = _file_object->isChannelsSupported(channels); return (ret_value);}const char *aflibFile::findModuleFile( const string& file_name){ /* * FIXME: Shouldn't use FILE. Doesn't work well for unseekable streams. * I think we could use a module for this and have it open up the proper * format module. * */ const char * module_format = NULL; FILE * fd; list<aflibFileItem *>::iterator it; vector<unsigned char> array; bool recognized = FALSE; int i; // Open the audio file fd = fopen(file_name.c_str(), "r"); if (fd != NULL) { // Read first 1000 bytes to be used to ID the file for (i = 0; i < 1000; i++) { array.push_back((unsigned char)fgetc(fd)); } fclose(fd); // Loop thru every format to see if it is the file for (it = _support_list.begin(); it != _support_list.end(); it++) { // Is this the correct format if (*(*it) == array) recognized = TRUE; if (recognized == TRUE) { module_format = (*it)->getFormat().c_str(); break; } } } return(module_format);}aflibFile *aflibFile::allocateModuleFile( aflibFileType type_enum, const char * module_format){ // This is a static private function. It allocates an aflibFile object for // modules support. For no module support it allocates an object of the // derived class. For this users call the derived functions directly. For // module support the base class functions are called. Since this is really // just a wrapper aflibFile object it contains a pointer to the real derived // object. aflibFile * file_return = NULL;#ifndef NO_MODULES /* TODO should'nt hardcode filetypes. should just use strings - DAS */ if (type_enum == AFLIB_AUTO_TYPE) { if (module_format != NULL) file_return = new aflibFile(module_format); } else if (type_enum == AFLIB_DEV_TYPE) { file_return = new aflibFile("DEVICE"); } else if (type_enum == AFLIB_MPEG_TYPE) { file_return = new aflibFile("MP3(LAME) 48Khz"); } else if (type_enum == AFLIB_WAV_TYPE) { file_return = new aflibFile("WAV"); } else if (type_enum == AFLIB_AU_TYPE) { file_return = new aflibFile("AU"); } // Check to see if the correct module was loaded. If not return NULL as error if (file_return) { if (file_return->initialized() == FALSE) { delete file_return; file_return = NULL; } }#else if (type_enum == AFLIB_DEV_TYPE) { file_return = new aflibDevFile(); } else if (type_enum == AFLIB_MPEG_TYPE) { file_return = new aflibLameFile(); } else if (type_enum == AFLIB_WAV_TYPE) { file_return = new aflibWavFile(); } else if (type_enum == AFLIB_AU_TYPE) { file_return = new aflibWavFile(); }#endif return (file_return);} voidaflibFile::parseModuleFile(){ string path; DIR* dir_handle; void* dl_handle; void (*query)(list<aflibFileItem*>&); struct dirent* entry; const char* dl_errstr; string module_name; string module_path_name; // We are creating a static list. Has it been created yet if (_list_created == TRUE) return; _list_created = TRUE; /*TODO should save this path in aflibFileItem class. */ if (getenv("AFLIB_MODULE_FILE_DIR")) { path = getenv("AFLIB_MODULE_FILE_DIR"); } else { path = MODULE_INSTALL_DIR; } if((dir_handle = opendir(path.c_str())) == NULL ) return; path += "/"; for(entry = readdir(dir_handle);entry;entry = readdir(dir_handle)) { module_name = entry->d_name; if((module_name.find("aflib") < module_name.length())&& (module_name.find("File.so") < module_name.length())) { module_path_name = path + module_name; dl_handle = dlopen(module_path_name.c_str(),RTLD_LAZY); if(dl_handle == NULL) { dl_errstr = dlerror(); aflib_debug("%s",dl_errstr); continue; } query = (void (*)(list<aflibFileItem*>&) ) dlsym(dl_handle,"query"); if(query==NULL) { dl_errstr = dlerror(); aflib_warning("%s",dl_errstr); } else { (query)(_support_list); aflib_debug("Recognized file module %s",module_name.c_str()); } dlclose(dl_handle); } } closedir(dir_handle);} boolaflibFile::initialized(){ // For the dynamic load logic this will let static functions determine if // the module to be loaded was initialized correctly. return(_file_object != NULL);}/*! \brief Returns all currently supported formats. This public static function returns to the user two lists. The first is the list of supported formats. The second is a corresponding list of descriptions that relate to the formats returned. */voidaflibFile::returnSupportedFormats( list <string>& formats, list <string>& descriptions){ list<aflibFileItem *>::iterator it; // IF we have not parsed the modules file then do so parseModuleFile(); for (it = _support_list.begin(); it != _support_list.end(); it++) { formats.push_back((*it)->getFormat()); descriptions.push_back((*it)->getDescription()); }}/*! \brief Returns all currently supported formats. This public static function returns a reference to the supported module formats. See aflibFileItem.h for details. */const list<aflibFileItem*>&aflibFile::returnSupportedFormats () { // IF we have not parsed the modules file then do so parseModuleFile(); return _support_list;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -