Skip to content

Commit 7777579

Browse files
author
Clement Champetier
committed
Use new log system for avTranscoder debug/info/warn/error messages
Remove verbose attribute in concerned classes.
1 parent 7a648e3 commit 7777579

22 files changed

+198
-243
lines changed

app/avProcessor/avProcessor.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ static const std::string dummyAudioCodec = "pcm_s16le";
2121

2222
static bool useVideoGenerator = false;
2323

24-
static bool verbose = false;
25-
2624
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder& transcoder )
2725
{
2826
std::ifstream configFile( configFilename.c_str(), std::ifstream::in );
@@ -49,17 +47,6 @@ void parseConfigFile( const std::string& configFilename, avtranscoder::Transcode
4947
if( separator == '.' )
5048
ss >> subStreamIndex;
5149

52-
if( verbose )
53-
{
54-
std::cout << ( filename.length() ? filename : "dummy stream" );
55-
std::cout << " ( " << streamIndex;
56-
if( subStreamIndex > -1 )
57-
std::cout << " | " << subStreamIndex << " ";
58-
std::cout << " ) : ";
59-
std::cout << ( transcodeProfile.length() ? transcodeProfile : "rewrap" );
60-
std::cout << std::endl;
61-
}
62-
6350
// dummy stream, need a ICodec (audio or video)
6451
if( ! filename.length() )
6552
{
@@ -109,6 +96,10 @@ int main( int argc, char** argv )
10996
help += "\t--generate-black: stream which not referred to an input, will generate an output video stream with black images (by default generate audio stream with silence)\n";
11097
help += "\t--help: display this help\n";
11198

99+
// Preload FFmpeg context
100+
avtranscoder::preloadCodecsAndFormats();
101+
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
102+
112103
// List command line arguments
113104
std::vector< std::string > arguments;
114105
for( int argument = 1; argument < argc; ++argument )
@@ -128,7 +119,7 @@ int main( int argc, char** argv )
128119
}
129120
if( arguments.at( argument ) == "--verbose" )
130121
{
131-
verbose = true;
122+
avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG );
132123
}
133124
}
134125

@@ -140,40 +131,17 @@ int main( int argc, char** argv )
140131
return( -1 );
141132
}
142133

143-
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
144-
if( verbose )
145-
avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG );
146-
147134
try
148135
{
149-
if( verbose )
150-
std::cout << "start ..." << std::endl;
151-
avtranscoder::preloadCodecsAndFormats();
152-
153-
if( verbose )
154-
std::cout << "output file: " << argv[2] << std::endl;
155-
156136
std::string inputConfigFile( argv[1] );
157137
avtranscoder::OutputFile outputFile( argv[2] );
158138

159139
avtranscoder::Transcoder transcoder( outputFile );
160140

161-
if( verbose )
162-
std::cout << "parse config file" << std::endl;
163141
parseConfigFile( inputConfigFile, transcoder );
164142

165-
// set verbose of all stream
166-
transcoder.setVerbose( verbose );
167-
168-
if( verbose )
169-
std::cout << "start Transcode" << std::endl;
170-
171143
avtranscoder::ConsoleProgress progress;
172144
transcoder.process( progress );
173-
174-
std::cout << std::endl;
175-
if( verbose )
176-
std::cout << "end ..." << std::endl;
177145
}
178146
catch( std::exception& e )
179147
{

app/avThumbnail/avThumbnail.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <AvTranscoder/transcoder/Transcoder.hpp>
22
#include <AvTranscoder/file/OutputFile.hpp>
33

4+
#include <iostream>
5+
46
static std::string outputFileName = "thumbnail.jpg";
57
static bool seekInFrame = false;
68

src/AvTranscoder/Option.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern "C" {
55
#include <libavutil/mem.h>
66
}
77

8-
#include <iostream>
98
#include <sstream>
109
#include <stdexcept>
1110

@@ -292,7 +291,9 @@ void loadOptions( OptionMap& outOptions, void* av_class, int req_flags )
292291

293292
if( ! parentFound )
294293
{
295-
std::cout << "Warning: Can't find a choice option for " << itOption->getName() << std::endl;
294+
std::string msg( "Can't find a choice option for ");
295+
msg += itOption->getName();
296+
Logger::warn( msg );
296297
}
297298
}
298299
}

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "common.hpp"
44

5-
#include <iostream>
65
#include <fstream>
76
#include <cstdlib>
87
#include <stdexcept>
@@ -65,7 +64,7 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
6564
}
6665
catch( const std::exception& e )
6766
{
68-
std::cout << e.what() << std::endl;
67+
Logger::warn( e.what() );
6968
}
7069
}
7170
}
@@ -219,7 +218,12 @@ int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
219218
struct dirent *dirp;
220219
if( ( dp = opendir( dir.c_str() ) ) == NULL )
221220
{
222-
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
221+
std::string msg( "Can't get files in directory " );
222+
msg += dir;
223+
msg += " (";
224+
msg += errno;
225+
msg += ")";
226+
Logger::error( msg );
223227
return errno;
224228
}
225229

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66

77
#include <stdexcept>
88
#include <cassert>
9-
#include <iostream>
109

1110
namespace avtranscoder {
1211

@@ -120,7 +119,7 @@ void ICodec::setCodec( const ECodecType type, const AVCodecID codecId )
120119
{
121120
if( codecId == 0 )
122121
{
123-
std::cout << "Warning: Unsupported codec with id 0" << std::endl;
122+
Logger::warn( "Unsupported codec with id 0");
124123
return;
125124
}
126125

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
#include <libavutil/channel_layout.h>
1313
}
1414

15-
#include <iostream>
1615
#include <stdexcept>
1716

1817
namespace avtranscoder
@@ -169,7 +168,13 @@ void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
169168
}
170169
catch( std::exception& e )
171170
{
172-
std::cout << "[AudioDecoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
171+
std::string msg( "AudioDecoder - can't set option " );
172+
msg += (*it).first;
173+
msg += " to ";
174+
msg += (*it).second;
175+
msg += ": ";
176+
msg += e.what();
177+
Logger::warn( msg );
173178
}
174179
}
175180
}

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
}
1313

1414
#include <stdexcept>
15-
#include <iostream>
1615

1716
namespace avtranscoder
1817
{
@@ -128,7 +127,13 @@ void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
128127
}
129128
catch( std::exception& e )
130129
{
131-
std::cout << "[VideoDecoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
130+
std::string msg( "VideoDecoder - can't set option " );
131+
msg += (*it).first;
132+
msg += " to ";
133+
msg += (*it).second;
134+
msg += ": ";
135+
msg += e.what();
136+
Logger::warn( msg );
132137
}
133138
}
134139
}

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66
#include <libavutil/avutil.h>
77
}
88

9-
#include <iostream>
109
#include <stdexcept>
1110

1211
namespace avtranscoder
@@ -187,7 +186,13 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
187186
}
188187
catch( std::exception& e )
189188
{
190-
std::cout << "[AudioEncoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
189+
std::string msg( "AudioEncoder - can't set option " );
190+
msg += (*it).first;
191+
msg += " to ";
192+
msg += (*it).second;
193+
msg += ": ";
194+
msg += e.what();
195+
Logger::warn( msg );
191196
}
192197
}
193198
}

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66
#include <libavutil/avutil.h>
77
}
88

9-
#include <iostream>
109
#include <stdexcept>
1110
#include <cstdlib>
1211

@@ -184,7 +183,13 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
184183
}
185184
catch( std::exception& e )
186185
{
187-
std::cout << "[VideoEncoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
186+
std::string msg( "VideoEncoder - can't set option " );
187+
msg += (*it).first;
188+
msg += " to ";
189+
msg += (*it).second;
190+
msg += ": ";
191+
msg += e.what();
192+
Logger::warn( msg );
188193
}
189194
}
190195
}

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <stdexcept>
44
#include <sstream>
5-
#include <iostream>
65

76
namespace avtranscoder
87
{
@@ -127,7 +126,7 @@ void FormatContext::addMetaData( const std::string& key, const std::string& valu
127126
{
128127
char err[AV_ERROR_MAX_STRING_SIZE];
129128
av_strerror( ret, err, sizeof(err) );
130-
std::cout << err << std::endl;
129+
Logger::error( err );
131130
}
132131
}
133132

src/AvTranscoder/file/InputFile.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616
}
1717

1818
#include <stdexcept>
19+
#include <sstream>
1920

2021
namespace avtranscoder
2122
{
@@ -25,7 +26,6 @@ InputFile::InputFile( const std::string& filename )
2526
, _properties( _formatContext )
2627
, _filename( filename )
2728
, _inputStreams()
28-
, _verbose( false )
2929
{
3030
_formatContext.findStreamInfo();
3131

@@ -160,7 +160,11 @@ void InputFile::seek( uint64_t position )
160160

161161
if( av_seek_frame( &_formatContext.getAVFormatContext(), -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
162162
{
163-
std::cerr << "Error during seek at " << position << " (in AV_TIME_BASE units) in file" << std::endl;
163+
std::stringstream os;
164+
os << "Error when seek at ";
165+
os << position;
166+
os << " (in AV_TIME_BASE units) in file";
167+
Logger::error( os.str() );;
164168
}
165169

166170
for( std::vector<InputStream*>::iterator it = _inputStreams.begin(); it != _inputStreams.end(); ++it )
@@ -214,8 +218,13 @@ void InputFile::setProfile( const ProfileLoader::Profile& profile )
214218
}
215219
catch( std::exception& e )
216220
{
217-
if( _verbose )
218-
std::cout << "[InputFile] warning: " << e.what() << std::endl;
221+
std::string msg( "InputFile - can't set option " );
222+
msg += (*it).first;
223+
msg += " to ";
224+
msg += (*it).second;
225+
msg += ": ";
226+
msg += e.what();
227+
Logger::warn( msg );
219228
}
220229
}
221230
}

src/AvTranscoder/file/InputFile.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ class AvExport InputFile
8484
*/
8585
virtual void setProfile( const ProfileLoader::Profile& profile );
8686

87-
/**
88-
* @brief Set to verbose mode.
89-
*/
90-
void setVerbose( bool verbose = true ) { _verbose = verbose; }
91-
9287
public:
9388
/**
9489
* @brief Get media file properties using static method.
@@ -117,8 +112,6 @@ class AvExport InputFile
117112
FileProperties _properties;
118113
std::string _filename;
119114
std::vector<InputStream*> _inputStreams; ///< Has ownership
120-
121-
bool _verbose;
122115
};
123116

124117
}

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <AvTranscoder/util.hpp>
44

5-
#include <iostream>
65
#include <stdexcept>
76

87
namespace avtranscoder
@@ -14,7 +13,6 @@ OutputFile::OutputFile( const std::string& filename )
1413
, _frameCount()
1514
, _filename( filename )
1615
, _previousProcessedStreamDuration( 0.0 )
17-
, _verbose( false )
1816
{
1917
_formatContext.setOutputFormat( _filename );
2018
_formatContext.openRessource( _filename, AVIO_FLAG_WRITE );
@@ -100,8 +98,11 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
10098
{
10199
if( ! data.getSize() )
102100
return IOutputStream::eWrappingSuccess;
103-
if( _verbose )
104-
std::cout << "wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")" << std::endl;
101+
102+
std::stringstream os;
103+
os << "Wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")";
104+
Logger::debug( os.str() );
105+
105106
AVPacket packet;
106107
av_init_packet( &packet );
107108

@@ -178,7 +179,13 @@ void OutputFile::setProfile( const ProfileLoader::Profile& profile )
178179
}
179180
catch( std::exception& e )
180181
{
181-
std::cout << "[OutputFile] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
182+
std::string msg( "OutputFile - can't set option " );
183+
msg += (*it).first;
184+
msg += " to ";
185+
msg += (*it).second;
186+
msg += ": ";
187+
msg += e.what();
188+
Logger::warn( msg );
182189
}
183190
}
184191
}

0 commit comments

Comments
 (0)