diff --git a/src/AvTranscoder/codec/ICodec.cpp b/src/AvTranscoder/codec/ICodec.cpp index 3e64cd76..0e588acf 100644 --- a/src/AvTranscoder/codec/ICodec.cpp +++ b/src/AvTranscoder/codec/ICodec.cpp @@ -44,8 +44,6 @@ ICodec::ICodec(const ECodecType type, AVCodecContext& avCodecContext) ICodec::~ICodec() { - avcodec_close(_avCodecContext); - if(!_isCodecContextAllocated) return; @@ -73,7 +71,7 @@ void ICodec::openCodec() msg += ") "; } - avcodec_close(_avCodecContext); + closeCodec(); msg += getDescriptionFromErrorCode(ret); @@ -81,6 +79,13 @@ void ICodec::openCodec() } } +void ICodec::closeCodec() +{ + if(!_avCodecContext) + throw std::runtime_error("Unable to close a codec without codec context"); + avcodec_close(_avCodecContext); +} + std::string ICodec::getCodecName() const { assert(_avCodecContext != NULL); diff --git a/src/AvTranscoder/codec/ICodec.hpp b/src/AvTranscoder/codec/ICodec.hpp index ede6cafa..de3203dd 100644 --- a/src/AvTranscoder/codec/ICodec.hpp +++ b/src/AvTranscoder/codec/ICodec.hpp @@ -37,6 +37,8 @@ class AvExport ICodec /// Initialize the codec context. void openCodec(); + /// Reset the codec context. + void closeCodec(); std::string getCodecName() const; AVCodecID getCodecId() const; diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index 4b7f6101..a995a3df 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -27,6 +27,8 @@ AudioDecoder::AudioDecoder(InputStream& inputStream) AudioDecoder::~AudioDecoder() { + if(_isSetup) + _inputStream->getAudioCodec().closeCodec(); } void AudioDecoder::setupDecoder(const ProfileLoader::Profile& profile) @@ -73,7 +75,7 @@ void AudioDecoder::setupDecoder(const ProfileLoader::Profile& profile) } // open decoder - _inputStream->getAudioCodec().openCodec(); + codec.openCodec(); _isSetup = true; } diff --git a/src/AvTranscoder/decoder/VideoDecoder.cpp b/src/AvTranscoder/decoder/VideoDecoder.cpp index 6b48536a..ae76fb05 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.cpp +++ b/src/AvTranscoder/decoder/VideoDecoder.cpp @@ -24,6 +24,8 @@ VideoDecoder::VideoDecoder(InputStream& inputStream) VideoDecoder::~VideoDecoder() { + if(_isSetup) + _inputStream->getVideoCodec().closeCodec(); } void VideoDecoder::setupDecoder(const ProfileLoader::Profile& profile) @@ -70,7 +72,7 @@ void VideoDecoder::setupDecoder(const ProfileLoader::Profile& profile) } // open decoder - _inputStream->getVideoCodec().openCodec(); + codec.openCodec(); _isSetup = true; } diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index fe9d1829..3e35ad4e 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -25,12 +25,12 @@ Transcoder::Transcoder(IOutputFile& outputFile) Transcoder::~Transcoder() { - for(std::vector::iterator it = _inputFiles.begin(); it != _inputFiles.end(); ++it) + for(std::vector::iterator it = _streamTranscodersAllocated.begin(); + it != _streamTranscodersAllocated.end(); ++it) { delete(*it); } - for(std::vector::iterator it = _streamTranscodersAllocated.begin(); - it != _streamTranscodersAllocated.end(); ++it) + for(std::vector::iterator it = _inputFiles.begin(); it != _inputFiles.end(); ++it) { delete(*it); } diff --git a/test/pyTest/testAudioReader.py b/test/pyTest/testAudioReader.py index 30a9b080..7711f9d7 100644 --- a/test/pyTest/testAudioReader.py +++ b/test/pyTest/testAudioReader.py @@ -55,6 +55,10 @@ def testAudioReaderChannelsExtraction(): assert_equals( sizeOfFrameWithAllChannels / nbChannels, sizeOfFrameWithOneChannels ) + # Force to call the readers destructor before the inputFile destructor (which cannot happen in C++) + readerOfAllChannels = None + readerOfOneChannel = None + def testAudioReaderWithGenerator(): """ @@ -62,8 +66,7 @@ def testAudioReaderWithGenerator(): When there is no more data to decode, switch to a generator and process some frames. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] - inputFile = av.InputFile(inputFileName) - reader = av.AudioReader(inputFile) + reader = av.AudioReader(inputFileName) # read all frames and check their size while True: diff --git a/test/pyTest/testVideoReader.py b/test/pyTest/testVideoReader.py index b4e782a7..bf853592 100644 --- a/test/pyTest/testVideoReader.py +++ b/test/pyTest/testVideoReader.py @@ -25,7 +25,6 @@ def testVideoReaderCreateNewInputFile(): assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel ) # check if there is no next frame - frame = reader.readNextFrame() assert_equals( reader.readNextFrame(), None ) @@ -47,6 +46,9 @@ def testVideoReaderReferenceInputFile(): # check if there is no next frame assert_equals( reader.readNextFrame(), None ) + # Force to call the reader destructor before the inputFile destructor (which cannot happen in C++) + reader = None + def testVideoReaderWithGenerator(): """ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy