Skip to content

Commit 21fac64

Browse files
committed
Merge pull request #242 from cchampet/clean_logAndExceptionMessage
Clean log and exception message
2 parents 075e2f9 + 8c6fe7e commit 21fac64

File tree

10 files changed

+50
-43
lines changed

10 files changed

+50
-43
lines changed

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ ICodec::~ICodec()
5454
void ICodec::openCodec()
5555
{
5656
if( ! _avCodecContext )
57-
throw std::runtime_error( "unable to open a codec with no codec context" );
57+
throw std::runtime_error( "Unable to open a codec without codec context" );
5858

59-
int ret = avcodec_open2( _avCodecContext, _avCodec, NULL );
59+
const int ret = avcodec_open2( _avCodecContext, _avCodec, NULL );
6060
if( ret < 0 )
6161
{
62-
std::string msg = "unable open codec: ";
62+
std::string msg = "Unable to open codec: ";
6363

6464
if( _avCodec && _avCodec->long_name )
6565
msg += _avCodec->long_name;
@@ -84,7 +84,7 @@ std::string ICodec::getCodecName() const
8484
assert( _avCodecContext != NULL );
8585
const AVCodecDescriptor * desc = avcodec_descriptor_get( _avCodecContext->codec_id );
8686
if( ! desc )
87-
throw std::runtime_error( "Codec Descriptor is not available." );
87+
throw std::runtime_error( "Codec Descriptor is not available." );
8888

8989
return desc->name;
9090
}
@@ -116,7 +116,7 @@ void ICodec::setCodec( const ECodecType type, const std::string& codecName )
116116
const AVCodecDescriptor* avCodecDescriptor = avcodec_descriptor_get_by_name( codecName.c_str() );
117117
if( ! avCodecDescriptor )
118118
{
119-
std::string msg( "unable to find codec " );
119+
std::string msg( "Unable to find codec " );
120120
msg += codecName;
121121
throw std::runtime_error( msg );
122122
}
@@ -146,7 +146,7 @@ void ICodec::allocateContext()
146146
_avCodecContext = avcodec_alloc_context3( _avCodec );
147147
if( ! _avCodecContext )
148148
{
149-
throw std::runtime_error( "unable to allocate the codecContext and set its fields to default values" );
149+
throw std::runtime_error( "Unable to allocate the codecContext and set its fields to default values" );
150150
}
151151
_avCodecContext->codec = _avCodec;
152152
}

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ FormatContext::FormatContext( const std::string& filename, int req_flags, AVDict
1515
int ret = avformat_open_input( &_avFormatContext, filename.c_str(), NULL, options );
1616
if( ret < 0 )
1717
{
18-
std::string msg = "unable to open file ";
18+
std::string msg = "Unable to open file ";
1919
msg += filename;
2020
msg += ": ";
2121
msg += getDescriptionFromErrorCode( ret );
@@ -56,7 +56,7 @@ void FormatContext::findStreamInfo( AVDictionary** options )
5656
int err = avformat_find_stream_info( _avFormatContext, options );
5757
if( err < 0 )
5858
{
59-
throw std::ios_base::failure( "unable to find stream informations: " + getDescriptionFromErrorCode( err ) );
59+
throw std::ios_base::failure( "Unable to find stream informations: " + getDescriptionFromErrorCode( err ) );
6060
}
6161
}
6262

@@ -68,7 +68,7 @@ void FormatContext::openRessource( const std::string& url, int flags )
6868
int err = avio_open2( &_avFormatContext->pb, url.c_str(), flags, NULL, NULL );
6969
if( err < 0 )
7070
{
71-
throw std::ios_base::failure( "error when opening output format: " + getDescriptionFromErrorCode( err ) );
71+
throw std::ios_base::failure( "Error when opening output format: " + getDescriptionFromErrorCode( err ) );
7272
}
7373
}
7474

@@ -80,7 +80,7 @@ void FormatContext::closeRessource()
8080
int err = avio_close( _avFormatContext->pb );
8181
if( err < 0 )
8282
{
83-
throw std::ios_base::failure( "error when close output format: " + getDescriptionFromErrorCode( err ) );
83+
throw std::ios_base::failure( "Error when close output format: " + getDescriptionFromErrorCode( err ) );
8484
}
8585
}
8686

@@ -89,7 +89,7 @@ void FormatContext::writeHeader( AVDictionary** options )
8989
int ret = avformat_write_header( _avFormatContext, options );
9090
if( ret != 0 )
9191
{
92-
throw std::runtime_error( "could not write header: " + getDescriptionFromErrorCode( ret ) );
92+
throw std::runtime_error( "Could not write header: " + getDescriptionFromErrorCode( ret ) );
9393
}
9494
// when muxing, priv_data of AVFormatContext is set by avformat_write_header()
9595
if( _avFormatContext->oformat->priv_class )
@@ -109,7 +109,7 @@ void FormatContext::writeFrame( AVPacket& packet, bool interleaved )
109109

110110
if( ret < 0 )
111111
{
112-
throw std::runtime_error( "error when writting packet in stream: " + getDescriptionFromErrorCode( ret ) );
112+
throw std::runtime_error( "Error when writting packet in stream: " + getDescriptionFromErrorCode( ret ) );
113113
}
114114
}
115115

@@ -118,7 +118,7 @@ void FormatContext::writeTrailer()
118118
int ret = av_write_trailer( _avFormatContext );
119119
if( ret != 0 )
120120
{
121-
throw std::runtime_error( "could not write trailer: " + getDescriptionFromErrorCode( ret ) );
121+
throw std::runtime_error( "Could not write trailer: " + getDescriptionFromErrorCode( ret ) );
122122
}
123123
}
124124

@@ -137,7 +137,7 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
137137
AVStream* stream = avformat_new_stream( _avFormatContext, const_cast<AVCodec*>(&avCodec) );
138138
if( stream == NULL )
139139
{
140-
throw std::runtime_error( "unable to add new video stream" );
140+
throw std::runtime_error( "Unable to add new video stream" );
141141
}
142142
return *stream;
143143
}
@@ -189,7 +189,7 @@ void FormatContext::setOutputFormat( const std::string& filename, const std::str
189189
AVOutputFormat* oformat = av_guess_format( shortName.c_str(), filename.c_str(), mimeType.c_str() );
190190
if( ! oformat )
191191
{
192-
std::string msg( "unable to find format for " );
192+
std::string msg( "Unable to find format for " );
193193
msg += filename;
194194
if( ! shortName.empty() )
195195
{

src/AvTranscoder/file/InputFile.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
6060
bool nextPacketFound = false;
6161
while( ! nextPacketFound )
6262
{
63-
int ret = av_read_frame( &_formatContext.getAVFormatContext(), &data.getAVPacket() );
63+
const int ret = av_read_frame( &_formatContext.getAVFormatContext(), &data.getAVPacket() );
6464
if( ret < 0 ) // error or end of file
6565
{
66+
LOG_INFO( "No more data to read on file '" << _filename << "'" )
6667
return false;
6768
}
6869

6970
// if the packet stream is the expected one
7071
// return the packet data
71-
int packetStreamIndex = data.getAVPacket().stream_index;
72+
const int packetStreamIndex = data.getAVPacket().stream_index;
7273
if( packetStreamIndex == (int)streamIndex )
7374
{
75+
LOG_DEBUG( "Get a packet data of the stream " << streamIndex )
7476
nextPacketFound = true;
7577
}
7678
// else add the packet data to the stream cache
@@ -85,13 +87,13 @@ bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
8587

8688
bool InputFile::seekAtFrame( const size_t frame, const int flag )
8789
{
88-
uint64_t position = frame / getFps() * AV_TIME_BASE;
90+
const uint64_t position = frame / getFps() * AV_TIME_BASE;
8991
return _formatContext.seek( position, flag );
9092
}
9193

9294
bool InputFile::seekAtTime( const double time, const int flag )
9395
{
94-
uint64_t position = time * AV_TIME_BASE;
96+
const uint64_t position = time * AV_TIME_BASE;
9597
return _formatContext.seek( position, flag );
9698
}
9799

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
155155
// free packet.side_data, set packet.data to NULL and packet.size to 0
156156
av_free_packet( &packet );
157157

158-
double currentStreamDuration = _outputStreams.at( streamId )->getStreamDuration();
158+
const double currentStreamDuration = _outputStreams.at( streamId )->getStreamDuration();
159159
if( currentStreamDuration < _previousProcessedStreamDuration )
160160
{
161161
// if the current stream is strictly shorter than the previous, wait for more data
162162
return IOutputStream::eWrappingWaitingForData;
163163
}
164164

165165
_previousProcessedStreamDuration = currentStreamDuration;
166-
167166
_frameCount.at( streamId )++;
167+
168168
return IOutputStream::eWrappingSuccess;
169169
}
170170

src/AvTranscoder/mediaProperty/mediaProperty.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace std {
2929
%ignore vector< avtranscoder::UnknownProperties >::resize;
3030

3131
// Create instantiations of a template classes
32+
%template(StreamVector) vector< avtranscoder::StreamProperties* >;
3233
%template(VideoVector) vector< avtranscoder::VideoProperties >;
3334
%template(AudioVector) vector< avtranscoder::AudioProperties >;
3435
%template(DataVector) vector< avtranscoder::DataProperties >;

src/AvTranscoder/stream/InputStream.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ bool InputStream::readNextPacket( CodedData& data )
5858
// if packet is already cached
5959
if( ! _streamCache.empty() )
6060
{
61+
LOG_DEBUG( "Get packet data of stream " << _streamIndex << " from the cache" )
6162
data.copyData( _streamCache.front().getData(), _streamCache.front().getSize() );
6263
_streamCache.pop();
6364
}
6465
// else read next packet
6566
else
6667
{
68+
LOG_DEBUG( "Read next packet" )
6769
return _inputFile->readNextPacket( data, _streamIndex ) && _streamCache.empty();
6870
}
6971

@@ -120,8 +122,12 @@ void InputStream::addPacket( AVPacket& packet )
120122
{
121123
// Do not cache data if the stream is declared as unused in process
122124
if( ! _isActivated )
125+
{
126+
LOG_DEBUG( "Do not add a packet data for the stream " << _streamIndex << " to the cache: stream not activated" )
123127
return;
128+
}
124129

130+
LOG_DEBUG( "Add a packet data for the stream " << _streamIndex << " to the cache" )
125131
_streamCache.push( CodedData() );
126132
_streamCache.back().copyData( packet.data, packet.size );
127133
}

src/AvTranscoder/stream/OutputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ float OutputStream::getStreamDuration() const
3535

3636
size_t OutputStream::getNbFrames() const
3737
{
38-
AVStream& outputStream = _outputFile->getFormatContext().getAVStream( _streamIndex );
38+
const AVStream& outputStream = _outputFile->getFormatContext().getAVStream( _streamIndex );
3939
return outputStream.nb_frames;
4040
}
4141

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ bool StreamTranscoder::processFrame()
326326
// Manage offset
327327
if( _offset > 0 )
328328
{
329-
bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
329+
const bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
330330
if( endOfOffset )
331331
{
332332
LOG_INFO( "End of positive offset" )
@@ -349,7 +349,7 @@ bool StreamTranscoder::processFrame()
349349
}
350350
else if( _offset < 0 )
351351
{
352-
bool endOfStream = _outputStream->getStreamDuration() >= ( _inputStream->getDuration() + _offset );
352+
const bool endOfStream = _outputStream->getStreamDuration() >= ( _inputStream->getDuration() + _offset );
353353
if( endOfStream )
354354
{
355355
LOG_INFO( "End of negative offset" )
@@ -371,15 +371,14 @@ bool StreamTranscoder::processRewrap()
371371
assert( _outputStream != NULL );
372372
assert( _inputDecoder == NULL );
373373

374-
LOG_DEBUG( "Rewrap a frame" )
374+
LOG_DEBUG( "StreamTranscoder::processRewrap" )
375375

376376
// if switched to generator, process frame
377377
if( _currentDecoder == _generator )
378378
{
379379
return processTranscode();
380380
}
381381

382-
LOG_DEBUG( "read next packet" )
383382
CodedData data;
384383
if( ! _inputStream->readNextPacket( data ) )
385384
{
@@ -391,9 +390,7 @@ bool StreamTranscoder::processRewrap()
391390
return false;
392391
}
393392

394-
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
395-
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
396-
393+
const IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
397394
switch( wrappingStatus )
398395
{
399396
case IOutputStream::eWrappingSuccess:
@@ -417,9 +414,9 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
417414
assert( _frameBuffer != NULL );
418415
assert( _transform != NULL );
419416

420-
LOG_DEBUG( "Transcode a frame" )
417+
LOG_DEBUG( "StreamTranscoder::processTranscode" )
421418

422-
LOG_DEBUG( "decode next frame" )
419+
LOG_DEBUG( "Decode next frame" )
423420
bool decodingStatus = false;
424421
if( subStreamIndex < 0 )
425422
decodingStatus = _currentDecoder->decodeNextFrame( *_sourceBuffer );
@@ -429,15 +426,15 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
429426
CodedData data;
430427
if( decodingStatus )
431428
{
432-
LOG_DEBUG( "convert (" << _sourceBuffer->getSize() << " bytes)" )
429+
LOG_DEBUG( "Convert (" << _sourceBuffer->getSize() << " bytes)" )
433430
_transform->convert( *_sourceBuffer, *_frameBuffer );
434431

435-
LOG_DEBUG( "encode (" << _frameBuffer->getSize() << " bytes)" )
432+
LOG_DEBUG( "Encode (" << _frameBuffer->getSize() << " bytes)" )
436433
_outputEncoder->encodeFrame( *_frameBuffer, data );
437434
}
438435
else
439436
{
440-
LOG_DEBUG( "encode last frame(s)" )
437+
LOG_DEBUG( "Encode last frame(s)" )
441438
if( ! _outputEncoder->encodeFrame( data ) )
442439
{
443440
if( _canSwitchToGenerator )
@@ -450,8 +447,7 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
450447
}
451448

452449
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
453-
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
454-
450+
const IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
455451
switch( wrappingStatus )
456452
{
457453
case IOutputStream::eWrappingSuccess:

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AvExport StreamTranscoder
8989
*/
9090
void canSwitchToGenerator( bool canSwitch ) { _canSwitchToGenerator = canSwitch; }
9191

92-
void setOffset( bool offset = true ){ _offset = offset; }
92+
void setOffset( const float offset ){ _offset = offset; }
9393

9494
private:
9595
bool processRewrap();

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ ProcessStat Transcoder::process()
231231
ProcessStat Transcoder::process( IProgress& progress )
232232
{
233233
if( _streamTranscoders.size() == 0 )
234-
throw std::runtime_error( "missing input streams in transcoder" );
234+
throw std::runtime_error( "Missing input streams in transcoder" );
235235

236236
manageSwitchToGenerator();
237237

@@ -241,14 +241,14 @@ ProcessStat Transcoder::process( IProgress& progress )
241241

242242
preProcessCodecLatency();
243243

244-
double outputDuration = getOutputDuration();
245-
LOG_DEBUG( "Output duration of the process will be " << outputDuration )
244+
const double outputDuration = getOutputDuration();
245+
LOG_INFO( "Output duration of the process will be " << outputDuration << "s." )
246246

247247
size_t frame = 0;
248248
bool frameProcessed = true;
249249
while( frameProcessed )
250250
{
251-
double progressDuration = _outputFile.getStream( 0 ).getStreamDuration();
251+
const double progressDuration = _outputFile.getStream( 0 ).getStreamDuration();
252252

253253
// check if JobStatusCancel
254254
if( progress.progress( ( progressDuration > outputDuration ) ? outputDuration : progressDuration, outputDuration ) == eJobStatusCancel )
@@ -521,12 +521,13 @@ void Transcoder::fillProcessStat( ProcessStat& processStat )
521521
for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
522522
{
523523
IOutputStream& stream = _streamTranscoders.at( streamIndex )->getOutputStream();
524-
AVCodecContext& encoderContext = _streamTranscoders.at( streamIndex )->getEncoder().getCodec().getAVCodecContext();
525-
switch( encoderContext.codec_type )
524+
const AVMediaType mediaType = _streamTranscoders.at( streamIndex )->getInputStream().getStreamType();
525+
switch( mediaType )
526526
{
527527
case AVMEDIA_TYPE_VIDEO:
528528
{
529529
VideoStat videoStat( stream.getStreamDuration(), stream.getNbFrames() );
530+
const AVCodecContext& encoderContext = _streamTranscoders.at( streamIndex )->getEncoder().getCodec().getAVCodecContext();
530531
if( encoderContext.coded_frame && ( encoderContext.flags & CODEC_FLAG_PSNR) )
531532
{
532533
videoStat._quality = encoderContext.coded_frame->quality;
@@ -542,6 +543,7 @@ void Transcoder::fillProcessStat( ProcessStat& processStat )
542543
break;
543544
}
544545
default:
546+
LOG_WARN( "No process statistics for stream at index: " << streamIndex << " (AVMediaType = " << mediaType << ")" )
545547
break;
546548
}
547549
}

0 commit comments

Comments
 (0)