Skip to content

Commit 1887683

Browse files
author
Clement Champetier
committed
ICodec: fix free avcodec in destructor
* Close and free avcodec in destructor only if AVCodecContext and AVCodec are not NULL. * Generator Video / Audio: get a pointer to an ICodec, because we set its codec from the outside (method setVideoCodec / setAudioCodec). And this codec outside will be free elsewhere.
1 parent b08bead commit 1887683

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ ICodec::ICodec( const ECodecType type, const AVCodecID codecId )
2929

3030
ICodec::~ICodec()
3131
{
32-
if( ! _codecContext )
32+
if( _codecContext && _codec )
3333
{
3434
avcodec_close( _codecContext );
3535
av_free( _codecContext );
3636
_codecContext = NULL;
37+
_codec = NULL;
3738
}
3839
}
3940

src/AvTranscoder/essenceStream/GeneratorAudio.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ namespace avtranscoder
55

66
GeneratorAudio::GeneratorAudio( )
77
: IInputEssence( )
8+
, _codec( NULL )
89
, _inputFrame( NULL )
9-
, _codec( eCodecTypeEncoder )
1010
, _frameDesc()
1111
{
1212
}
1313

1414
void GeneratorAudio::setAudioCodec( const AudioCodec& codec )
1515
{
1616
_frameDesc.setFps ( 25.0 );
17-
_codec = codec;
17+
_codec = &codec;
1818

19-
_frameDesc.setSampleRate( _codec.getAVCodecContext()->sample_rate );
20-
_frameDesc.setChannels( _codec.getAVCodecContext()->channels );
21-
_frameDesc.setSampleFormat( _codec.getAVCodecContext()->sample_fmt );
19+
_frameDesc.setSampleRate( _codec->getAVCodecContext()->sample_rate );
20+
_frameDesc.setChannels( _codec->getAVCodecContext()->channels );
21+
_frameDesc.setSampleFormat( _codec->getAVCodecContext()->sample_fmt );
2222
}
2323

24-
AudioCodec& GeneratorAudio::getAudioCodec()
24+
const AudioCodec& GeneratorAudio::getAudioCodec()
2525
{
26-
return _codec;
26+
return *_codec;
2727
}
2828

2929
void GeneratorAudio::setFrame( Frame& inputFrame )

src/AvTranscoder/essenceStream/GeneratorAudio.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AvExport GeneratorAudio : public IInputEssence
1414

1515
void setAudioCodec( const AudioCodec& codec );
1616

17-
AudioCodec& getAudioCodec();
17+
const AudioCodec& getAudioCodec();
1818

1919
void setup() {}
2020

@@ -24,10 +24,9 @@ class AvExport GeneratorAudio : public IInputEssence
2424
bool readNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
2525

2626
private:
27-
AudioCodec _codec;
28-
AudioFrameDesc _frameDesc;
29-
27+
const AudioCodec* _codec;
3028
Frame* _inputFrame;
29+
AudioFrameDesc _frameDesc;
3130
};
3231

3332
}

src/AvTranscoder/essenceStream/GeneratorVideo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ namespace avtranscoder
77

88
GeneratorVideo::GeneratorVideo( )
99
: IInputEssence( )
10+
, _codec( NULL )
1011
, _inputFrame( NULL )
11-
, _codec( eCodecTypeEncoder )
1212
, _videoFrameDesc()
1313
, _numberOfView( 1 )
1414
{
1515
}
1616

1717
void GeneratorVideo::setVideoCodec( const VideoCodec& codec )
1818
{
19-
_codec = codec;
20-
_videoFrameDesc = _codec.getVideoFrameDesc();
19+
_codec = &codec;
20+
_videoFrameDesc = _codec->getVideoFrameDesc();
2121
}
2222

23-
VideoCodec& GeneratorVideo::getVideoCodec()
23+
const VideoCodec& GeneratorVideo::getVideoCodec()
2424
{
25-
return _codec;
25+
return *_codec;
2626
}
2727

2828
void GeneratorVideo::setFrame( Frame& inputFrame )
@@ -40,7 +40,7 @@ bool GeneratorVideo::readNextFrame( Frame& frameBuffer )
4040
if( frameBuffer.getSize() != _videoFrameDesc.getDataSize() )
4141
frameBuffer.getBuffer().resize( _videoFrameDesc.getDataSize() );
4242

43-
VideoFrameDesc desc( _codec.getVideoFrameDesc() );
43+
VideoFrameDesc desc( _codec->getVideoFrameDesc() );
4444
Pixel rgbPixel;
4545
rgbPixel.setColorComponents( eComponentRgb );
4646
rgbPixel.setPlanar( false );

src/AvTranscoder/essenceStream/GeneratorVideo.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AvExport GeneratorVideo : public IInputEssence
1515
// Stream properties
1616
void setVideoCodec( const VideoCodec& codec );
1717

18-
VideoCodec& getVideoCodec();
18+
const VideoCodec& getVideoCodec();
1919

2020
void setup() {}
2121

@@ -25,8 +25,8 @@ class AvExport GeneratorVideo : public IInputEssence
2525
bool readNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
2626

2727
private:
28-
Frame* _inputFrame;
29-
VideoCodec _codec;
28+
const VideoCodec* _codec;
29+
Frame* _inputFrame;
3030
VideoFrameDesc _videoFrameDesc;
3131

3232
size_t _numberOfView;

0 commit comments

Comments
 (0)
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