diff --git a/src/AvTranscoder/Profile.cpp b/src/AvTranscoder/Profile.cpp index 05cf6e56..df8695f3 100644 --- a/src/AvTranscoder/Profile.cpp +++ b/src/AvTranscoder/Profile.cpp @@ -34,54 +34,61 @@ Profile::Profile( bool autoload ) loadProfiles(); } -void Profile::loadProfiles() +void Profile::loadProfile( const std::string& avProfileFile ) +{ + std::ifstream infile; + infile.open( avProfileFile.c_str(), std::ifstream::in ); + + Profile::ProfileDesc customProfile; + + std::string line; + while( std::getline( infile, line ) ) + { + std::vector< std::string > keyValue; + split( keyValue, line, "=" ); + if( keyValue.size() == 2 ) + customProfile[ keyValue.at( 0 ) ] = keyValue.at( 1 ); + } + // check if profile contains required values + if( + customProfile.count( avProfileIdentificator ) && + customProfile.count( avProfileIdentificatorHuman ) && + customProfile.count( avProfileType ) && + ( customProfile.find( avProfileType )->second == avProfileTypeVideo || + customProfile.find( avProfileType )->second == avProfileTypeAudio ) + ) + { + _profiles.push_back( customProfile ); + } +} + +void Profile::loadProfiles( const std::string& avProfilesPath ) { loadXdCamHD422( _profiles ); loadDNxHD( _profiles ); loadWave( _profiles ); - - if( const char* envAvProfiles = std::getenv( "AVPROFILES" ) ) + + std::string realAvProfilesPath = avProfilesPath; + if( realAvProfilesPath.empty() ) + { + if( std::getenv( "AVPROFILES" ) ) + realAvProfilesPath = std::getenv( "AVPROFILES" ); + else + return; + } + + std::vector< std::string > paths; + split( paths, realAvProfilesPath, ":" ); + for( std::vector< std::string >::iterator dirIt = paths.begin(); dirIt != paths.end(); ++dirIt ) { - std::vector< std::string > paths; - split( paths, envAvProfiles, ":" ); - for( std::vector< std::string >::iterator dirIt = paths.begin(); dirIt != paths.end(); ++dirIt ) + std::vector< std::string > files; + if( getFilesInDir( *dirIt, files ) != 0 ) + continue; + + for( std::vector< std::string >::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt ) { - //std::cout << "search profile in path " << *dirIt << std::endl; - std::vector< std::string > files; - if( getFilesInDir( *dirIt, files ) != 0 ) - continue; - - for( std::vector< std::string >::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt ) - { - if( ( *fileIt == "." ) || ( *fileIt == ".." ) ) - continue; - - std::ifstream infile; - infile.open( ( ( *dirIt ) + "/" + ( *fileIt ) ).c_str(), std::ifstream::in ); - - // std::cout << "file " << *dirIt << *fileIt << std::endl; - Profile::ProfileDesc customProfile; - - std::string line; - while( std::getline( infile, line ) ) - { - std::vector< std::string > keyValue; - split( keyValue, line, "=" ); - if( keyValue.size() == 2 ) - customProfile[ keyValue.at( 0 ) ] = keyValue.at( 1 ); - } - // check if profile contains required values - if( - customProfile.count( avProfileIdentificator ) && - customProfile.count( avProfileIdentificatorHuman ) && - customProfile.count( avProfileType ) && - ( customProfile.find( avProfileType )->second == avProfileTypeVideo || - customProfile.find( avProfileType )->second == avProfileTypeAudio ) - ) - { - _profiles.push_back( customProfile ); - } - } + const std::string absPath = ( *dirIt ) + "/" + ( *fileIt ); + loadProfile( absPath ); } } } diff --git a/src/AvTranscoder/Profile.hpp b/src/AvTranscoder/Profile.hpp index 445f8e0d..eca96a4f 100644 --- a/src/AvTranscoder/Profile.hpp +++ b/src/AvTranscoder/Profile.hpp @@ -29,13 +29,16 @@ class Profile static const std::string avProfileWidth; static const std::string avProfileHeight; +public: // typedef std::pair< std::string, std::string > KeyDesc; typedef std::map< std::string, std::string > ProfileDesc; typedef std::vector< ProfileDesc > ProfilesDesc; +public: Profile( bool autoload = false ); - void loadProfiles(); + void loadProfiles( const std::string& avProfilesPath = "" ); + void loadProfile( const std::string& avProfileFile ); void update( const ProfileDesc& profile ); diff --git a/src/AvTranscoder/common.cpp b/src/AvTranscoder/common.cpp index 80fb53fb..af3e5e97 100644 --- a/src/AvTranscoder/common.cpp +++ b/src/AvTranscoder/common.cpp @@ -16,19 +16,22 @@ void split( std::vector< std::string >& splitedString, const std::string& inputS } } -int getFilesInDir( std::string dir, std::vector< std::string > &files ) +int getFilesInDir( const std::string& dir, std::vector< std::string >& files ) { DIR *dp; struct dirent *dirp; if( ( dp = opendir( dir.c_str() ) ) == NULL ) { - std::cout << "Error(" << errno << ") opening " << dir << std::endl; + std::cerr << "Error(" << errno << ") opening " << dir << std::endl; return errno; } while( ( dirp = readdir( dp ) ) != NULL ) { - files.push_back( std::string( dirp->d_name ) ); + std::string filename( dirp->d_name ); + if( filename == "." || filename == ".." ) + continue; + files.push_back( filename ); } closedir( dp ); return 0; diff --git a/src/AvTranscoder/common.hpp b/src/AvTranscoder/common.hpp index a182698c..075234ff 100644 --- a/src/AvTranscoder/common.hpp +++ b/src/AvTranscoder/common.hpp @@ -61,7 +61,7 @@ struct Ratio void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" ); -int getFilesInDir( std::string dir, std::vector< std::string > &files ); +int getFilesInDir( const std::string& dir, std::vector< std::string >& files ); }