Skip to content

Profile: can have a specific profile path #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 49 additions & 42 deletions src/AvTranscoder/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/Profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
9 changes: 6 additions & 3 deletions src/AvTranscoder/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down