Skip to content

Commit 398033d

Browse files
author
Clement Champetier
committed
OutputEssence: raise exception in setup instead of return false
OutputVideo and OutputAudio: raise runtime_error if "could not allocate" or "could not open" video / audio codec.
1 parent e07fb93 commit 398033d

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,27 @@ OutputAudio::OutputAudio()
2424
{
2525
}
2626

27-
bool OutputAudio::setup()
27+
void OutputAudio::setup()
2828
{
2929
av_register_all(); // Warning: should be called only once
3030

3131
AVCodecContext* codecContext( _audioDesc.getCodecContext() );
3232

3333
if( codecContext == NULL )
34-
return false;
34+
{
35+
throw std::runtime_error( "could not allocate audio codec context" );
36+
}
3537

3638
// try to open encoder with parameters.
37-
if( avcodec_open2( codecContext, _audioDesc.getCodec(), NULL ) < 0 )
38-
return false;
39-
40-
return true;
39+
int ret = avcodec_open2( codecContext, _audioDesc.getCodec(), NULL );
40+
if( ret < 0 )
41+
{
42+
char err[250];
43+
av_strerror( ret, err, 250);
44+
std::string msg = "could not open audio encoder: ";
45+
msg += err;
46+
throw std::runtime_error( msg );
47+
}
4148
}
4249

4350
bool OutputAudio::encodeFrame( const Frame& sourceFrame, DataStream& codedFrame )

src/AvTranscoder/EssenceStream/OutputAudio.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class OutputAudio : public OutputEssence
1717
public:
1818
OutputAudio();
1919

20-
bool setup();
20+
void setup();
2121

2222
/**
2323
* @param[out] codedFrame

src/AvTranscoder/EssenceStream/OutputEssence.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ class AvExport OutputEssence
3030

3131
/**
3232
* @brief Setup the encoder
33-
* @return status of setup
3433
*/
35-
virtual bool setup() = 0;
34+
virtual void setup() = 0;
3635

3736
/**
3837
* @brief Encode a new frame, and get coded frame

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,27 @@ OutputVideo::OutputVideo( )
2727
{
2828
}
2929

30-
bool OutputVideo::setup( )
30+
void OutputVideo::setup( )
3131
{
3232
av_register_all(); // Warning: should be called only once
3333

3434
AVCodecContext* codecContext( _videoDesc.getCodecContext() );
3535

3636
if( codecContext == NULL )
37-
return false;
37+
{
38+
throw std::runtime_error( "could not allocate video codec context" );
39+
}
3840

3941
// try to open encoder with parameters
40-
if( avcodec_open2( codecContext, _videoDesc.getCodec(), NULL ) < 0 )
41-
return false;
42-
43-
return true;
42+
int ret = avcodec_open2( codecContext, _videoDesc.getCodec(), NULL );
43+
if( ret < 0 )
44+
{
45+
char err[250];
46+
av_strerror( ret, err, 250);
47+
std::string msg = "could not open video encoder: ";
48+
msg += err;
49+
throw std::runtime_error( msg );
50+
}
4451
}
4552

4653

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AvExport OutputVideo : public OutputEssence
3030
public:
3131
OutputVideo();
3232

33-
bool setup();
33+
void setup();
3434

3535
//void setVideoDesc( const VideoDesc& videoDesc );
3636

0 commit comments

Comments
 (0)