Skip to content

Commit bcc0b08

Browse files
author
Clement Champetier
committed
ICodec: add closeCodec public method
To be able to close a codec from outside of the class without calling ffmpeg/libav methods.
1 parent 354c5b2 commit bcc0b08

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ICodec::ICodec(const ECodecType type, AVCodecContext& avCodecContext)
4444

4545
ICodec::~ICodec()
4646
{
47-
avcodec_close(_avCodecContext);
47+
closeCodec();
4848

4949
if(!_isCodecContextAllocated)
5050
return;
@@ -73,14 +73,21 @@ void ICodec::openCodec()
7373
msg += ") ";
7474
}
7575

76-
avcodec_close(_avCodecContext);
76+
closeCodec();
7777

7878
msg += getDescriptionFromErrorCode(ret);
7979

8080
throw std::runtime_error(msg);
8181
}
8282
}
8383

84+
void ICodec::closeCodec()
85+
{
86+
if(!_avCodecContext)
87+
throw std::runtime_error("Unable to close a codec without codec context");
88+
avcodec_close(_avCodecContext);
89+
}
90+
8491
std::string ICodec::getCodecName() const
8592
{
8693
assert(_avCodecContext != NULL);

src/AvTranscoder/codec/ICodec.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class AvExport ICodec
3737

3838
/// Initialize the codec context.
3939
void openCodec();
40+
/// Reset the codec context.
41+
void closeCodec();
4042

4143
std::string getCodecName() const;
4244
AVCodecID getCodecId() const;

0 commit comments

Comments
 (0)