Skip to content

Commit 4c024a5

Browse files
author
Clement Champetier
committed
LoadProfile: rename update function to loadProfile
* Add documentation for the several loadProfile functions. * Transcoder: call "loadProfile".
1 parent 90d4785 commit 4c024a5

File tree

3 files changed

+57
-63
lines changed

3 files changed

+57
-63
lines changed

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ ProfileLoader::ProfileLoader( bool autoload )
1616
loadProfiles();
1717
}
1818

19-
void ProfileLoader::loadProfile( const std::string& avProfileFile )
19+
void ProfileLoader::loadProfile( const std::string& avProfileFileName )
2020
{
2121
std::ifstream infile;
22-
infile.open( avProfileFile.c_str(), std::ifstream::in );
22+
infile.open( avProfileFileName.c_str(), std::ifstream::in );
2323

2424
ProfileLoader::Profile customProfile;
2525

@@ -31,35 +31,7 @@ void ProfileLoader::loadProfile( const std::string& avProfileFile )
3131
if( keyValue.size() == 2 )
3232
customProfile[ keyValue.at( 0 ) ] = keyValue.at( 1 );
3333
}
34-
35-
// check profile long name
36-
if( ! customProfile.count( constants::avProfileIdentificator ) )
37-
{
38-
std::cout << "Warning: A profile has no name. It will not be loaded." << std::endl;
39-
return;
40-
}
41-
42-
// check profile type
43-
if( customProfile.count( constants::avProfileType ) == 0 )
44-
{
45-
std::cout << "Warning: The profile " << customProfile.find( constants::avProfileIdentificator )->second << " has not type. It will not be loaded." << std::endl;
46-
return;
47-
}
48-
49-
// check complete profile
50-
bool isValid = false;
51-
std::string type( customProfile.find( constants::avProfileType )->second );
52-
if( type == constants::avProfileTypeFormat )
53-
isValid = checkFormatProfile( customProfile );
54-
else if( type == constants::avProfileTypeVideo )
55-
isValid = checkVideoProfile( customProfile );
56-
else if( type == constants::avProfileTypeAudio )
57-
isValid = checkAudioProfile( customProfile );
58-
59-
if( isValid )
60-
_profiles.push_back( customProfile );
61-
else
62-
std::cout << "Warning: The profile " << customProfile.find( constants::avProfileIdentificator )->second << " is invalid. It will not be loaded." << std::endl;
34+
loadProfile( customProfile );
6335
}
6436

6537
void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
@@ -84,28 +56,46 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
8456
for( std::vector< std::string >::iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt )
8557
{
8658
const std::string absPath = ( *dirIt ) + "/" + ( *fileIt );
87-
loadProfile( absPath );
59+
try
60+
{
61+
loadProfile( absPath );
62+
}
63+
catch( const std::exception& e )
64+
{
65+
std::cout << e.what() << std::endl;
66+
}
8867
}
8968
}
9069
}
9170

92-
void ProfileLoader::update( const Profile& profile )
71+
void ProfileLoader::loadProfile( const Profile& profile )
9372
{
94-
Profile::const_iterator profileIt = profile.find( constants::avProfileIdentificator );
95-
if( profileIt == profile.end() )
96-
throw std::runtime_error( "Invalid profile: can't get identificator" );
73+
// check profile long name
74+
if( ! profile.count( constants::avProfileIdentificator ) )
75+
{
76+
throw std::runtime_error( "Warning: A profile has no name. It will not be loaded." );
77+
}
9778

98-
std::string profileId( profileIt->second );
99-
size_t profileIndex = 0;
100-
for( Profiles::iterator it = _profiles.begin(); it != _profiles.end(); ++it )
79+
// check profile type
80+
if( profile.count( constants::avProfileType ) == 0 )
10181
{
102-
// profile already exists
103-
if( (*it).find( constants::avProfileIdentificator )->second == profileId )
104-
return;
105-
++profileIndex;
82+
throw std::runtime_error( "Warning: The profile " + profile.find( constants::avProfileIdentificator )->second + " has not type. It will not be loaded." );
10683
}
107-
// profile not found: add the new profile
108-
_profiles.push_back( profile );
84+
85+
// check complete profile
86+
bool isValid = false;
87+
std::string type( profile.find( constants::avProfileType )->second );
88+
if( type == constants::avProfileTypeFormat )
89+
isValid = checkFormatProfile( profile );
90+
else if( type == constants::avProfileTypeVideo )
91+
isValid = checkVideoProfile( profile );
92+
else if( type == constants::avProfileTypeAudio )
93+
isValid = checkAudioProfile( profile );
94+
95+
if( isValid )
96+
_profiles.push_back( profile );
97+
else
98+
throw std::runtime_error( "Warning: The profile " + profile.find( constants::avProfileIdentificator )->second + " is invalid. It will not be loaded." );
10999
}
110100

111101
const ProfileLoader::Profiles& ProfileLoader::getProfiles()

src/AvTranscoder/ProfileLoader.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,23 @@ class AvExport ProfileLoader
3737
public:
3838
ProfileLoader( bool autoload = false );
3939

40+
/**
41+
* @brief Load profiles from files in avProfilesPath directory
42+
* @param avProfilesPath: if empty, the path is replaced by value of AVPROFILES environment variable
43+
*/
4044
void loadProfiles( const std::string& avProfilesPath = "" );
41-
void loadProfile( const std::string& avProfileFile );
4245

43-
void update( const Profile& profile );
44-
46+
/**
47+
* @brief Load the profile defines in the given file
48+
*/
49+
void loadProfile( const std::string& avProfileFileName );
50+
51+
/**
52+
* @brief Load the given profile
53+
* @exception throw std::runtime_error if the profile is invalid
54+
*/
55+
void loadProfile( const Profile& profile );
56+
4557
const Profiles& getProfiles();
4658

4759
Profiles getFormatProfiles();

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
8686

8787
void Transcoder::add( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, const size_t offset )
8888
{
89-
// Add profile if new
90-
_profileLoader.update( profile );
91-
9289
// Check filename
9390
if( ! filename.length() )
9491
throw std::runtime_error( "Can't transcode a stream without filename indicated" );
@@ -100,9 +97,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, Pro
10097

10198
void Transcoder::add( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, ICodec& codec, const size_t offset )
10299
{
103-
// Add profile if new
104-
_profileLoader.update( profile );
105-
106100
// Generator
107101
if( ! filename.length() )
108102
{
@@ -192,9 +186,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
192186

193187
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, ProfileLoader::Profile& profile, const size_t offset )
194188
{
195-
// Add profile if new
196-
_profileLoader.update( profile );
197-
198189
// No subStream selected
199190
if( subStreamIndex < 0 )
200191
{
@@ -213,9 +204,6 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
213204

214205
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, ProfileLoader::Profile& profile, ICodec& codec, const size_t offset )
215206
{
216-
// Add profile if new
217-
_profileLoader.update( profile );
218-
219207
// No subStream selected
220208
if( subStreamIndex < 0 )
221209
{
@@ -372,7 +360,7 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
372360
profile[ constants::avProfileChannel ] = "1";
373361

374362
// Add profile
375-
_profileLoader.update( profile );
363+
_profileLoader.loadProfile( profile );
376364

377365
switch( referenceFile->getStream( streamIndex ).getStreamType() )
378366
{
@@ -394,6 +382,10 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
394382

395383
void Transcoder::addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, ProfileLoader::Profile& profile, const size_t offset )
396384
{
385+
// Add profile
386+
_profileLoader.loadProfile( profile );
387+
388+
// Add input file
397389
InputFile* referenceFile = addInputFile( filename, streamIndex );
398390

399391
switch( referenceFile->getStream( streamIndex ).getStreamType() )
@@ -417,8 +409,8 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
417409

418410
void Transcoder::addDummyStream( const ProfileLoader::Profile& profile, const ICodec& codec )
419411
{
420-
if( ! profile.count( constants::avProfileType ) )
421-
throw std::runtime_error( "unable to found stream type (audio, video, etc.)" );
412+
// Add profile
413+
_profileLoader.loadProfile( profile );
422414

423415
if( _verbose )
424416
{

0 commit comments

Comments
 (0)