Skip to content

Commit fe38214

Browse files
Merge pull request #19 from cchampet/master
Profile: can have a specific profile path
2 parents ad58e98 + ec9eda9 commit fe38214

File tree

4 files changed

+60
-47
lines changed

4 files changed

+60
-47
lines changed

src/AvTranscoder/Profile.cpp

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,61 @@ Profile::Profile( bool autoload )
3434
loadProfiles();
3535
}
3636

37-
void Profile::loadProfiles()
37+
void Profile::loadProfile( const std::string& avProfileFile )
38+
{
39+
std::ifstream infile;
40+
infile.open( avProfileFile.c_str(), std::ifstream::in );
41+
42+
Profile::ProfileDesc customProfile;
43+
44+
std::string line;
45+
while( std::getline( infile, line ) )
46+
{
47+
std::vector< std::string > keyValue;
48+
split( keyValue, line, "=" );
49+
if( keyValue.size() == 2 )
50+
customProfile[ keyValue.at( 0 ) ] = keyValue.at( 1 );
51+
}
52+
// check if profile contains required values
53+
if(
54+
customProfile.count( avProfileIdentificator ) &&
55+
customProfile.count( avProfileIdentificatorHuman ) &&
56+
customProfile.count( avProfileType ) &&
57+
( customProfile.find( avProfileType )->second == avProfileTypeVideo ||
58+
customProfile.find( avProfileType )->second == avProfileTypeAudio )
59+
)
60+
{
61+
_profiles.push_back( customProfile );
62+
}
63+
}
64+
65+
void Profile::loadProfiles( const std::string& avProfilesPath )
3866
{
3967
loadXdCamHD422( _profiles );
4068
loadDNxHD( _profiles );
4169
loadWave( _profiles );
42-
43-
if( const char* envAvProfiles = std::getenv( "AVPROFILES" ) )
70+
71+
std::string realAvProfilesPath = avProfilesPath;
72+
if( realAvProfilesPath.empty() )
73+
{
74+
if( std::getenv( "AVPROFILES" ) )
75+
realAvProfilesPath = std::getenv( "AVPROFILES" );
76+
else
77+
return;
78+
}
79+
80+
std::vector< std::string > paths;
81+
split( paths, realAvProfilesPath, ":" );
82+
for( std::vector< std::string >::iterator dirIt = paths.begin(); dirIt != paths.end(); ++dirIt )
4483
{
45-
std::vector< std::string > paths;
46-
split( paths, envAvProfiles, ":" );
47-
for( std::vector< std::string >::iterator dirIt = paths.begin(); dirIt != paths.end(); ++dirIt )
84+
std::vector< std::string > files;
85+
if( getFilesInDir( *dirIt, files ) != 0 )
86+
continue;
87+
88+
for( std::vector< std::string >::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt )
4889
{
49-
//std::cout << "search profile in path " << *dirIt << std::endl;
50-
std::vector< std::string > files;
51-
if( getFilesInDir( *dirIt, files ) != 0 )
52-
continue;
53-
54-
for( std::vector< std::string >::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt )
55-
{
56-
if( ( *fileIt == "." ) || ( *fileIt == ".." ) )
57-
continue;
58-
59-
std::ifstream infile;
60-
infile.open( ( ( *dirIt ) + "/" + ( *fileIt ) ).c_str(), std::ifstream::in );
61-
62-
// std::cout << "file " << *dirIt << *fileIt << std::endl;
63-
Profile::ProfileDesc customProfile;
64-
65-
std::string line;
66-
while( std::getline( infile, line ) )
67-
{
68-
std::vector< std::string > keyValue;
69-
split( keyValue, line, "=" );
70-
if( keyValue.size() == 2 )
71-
customProfile[ keyValue.at( 0 ) ] = keyValue.at( 1 );
72-
}
73-
// check if profile contains required values
74-
if(
75-
customProfile.count( avProfileIdentificator ) &&
76-
customProfile.count( avProfileIdentificatorHuman ) &&
77-
customProfile.count( avProfileType ) &&
78-
( customProfile.find( avProfileType )->second == avProfileTypeVideo ||
79-
customProfile.find( avProfileType )->second == avProfileTypeAudio )
80-
)
81-
{
82-
_profiles.push_back( customProfile );
83-
}
84-
}
90+
const std::string absPath = ( *dirIt ) + "/" + ( *fileIt );
91+
loadProfile( absPath );
8592
}
8693
}
8794
}

src/AvTranscoder/Profile.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ class Profile
2929
static const std::string avProfileWidth;
3030
static const std::string avProfileHeight;
3131

32+
public:
3233
// typedef std::pair< std::string, std::string > KeyDesc;
3334
typedef std::map< std::string, std::string > ProfileDesc;
3435
typedef std::vector< ProfileDesc > ProfilesDesc;
3536

37+
public:
3638
Profile( bool autoload = false );
3739

38-
void loadProfiles();
40+
void loadProfiles( const std::string& avProfilesPath = "" );
41+
void loadProfile( const std::string& avProfileFile );
3942

4043
void update( const ProfileDesc& profile );
4144

src/AvTranscoder/common.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ void split( std::vector< std::string >& splitedString, const std::string& inputS
1616
}
1717
}
1818

19-
int getFilesInDir( std::string dir, std::vector< std::string > &files )
19+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
2020
{
2121
DIR *dp;
2222
struct dirent *dirp;
2323
if( ( dp = opendir( dir.c_str() ) ) == NULL )
2424
{
25-
std::cout << "Error(" << errno << ") opening " << dir << std::endl;
25+
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
2626
return errno;
2727
}
2828

2929
while( ( dirp = readdir( dp ) ) != NULL )
3030
{
31-
files.push_back( std::string( dirp->d_name ) );
31+
std::string filename( dirp->d_name );
32+
if( filename == "." || filename == ".." )
33+
continue;
34+
files.push_back( filename );
3235
}
3336
closedir( dp );
3437
return 0;

src/AvTranscoder/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct Ratio
6161

6262
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" );
6363

64-
int getFilesInDir( std::string dir, std::vector< std::string > &files );
64+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
6565

6666
}
6767

0 commit comments

Comments
 (0)