Skip to content

Commit 1002196

Browse files
Merge pull request #105 from cchampet/dev_pyTest
Add python nosetests
2 parents 6e6e9a7 + bae154c commit 1002196

24 files changed

+705
-134
lines changed

.travis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ before_script:
1212
- env | sort
1313
- date -u
1414
- uname -a
15-
15+
1616
- chmod +x tools/travis.linux.install.deps.sh
1717
- chmod +x tools/travis.osx.install.deps.sh
1818

1919
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./tools/travis.linux.install.deps.sh; fi
2020
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ./tools/travis.osx.install.deps.sh; fi
2121

2222
script:
23+
# Build
2324
- mkdir build
2425
- cd build
25-
- cmake ..
26-
- make
27-
26+
- cmake .. -DCMAKE_INSTALL_PREFIX=`pwd`/dist
27+
- make install
28+
# Launch tests
29+
- cd ..
30+
- chmod +x tools/travis.python.nosetests.sh
31+
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./tools/travis.python.nosetests.sh; fi

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ Based on LibAV/FFMpeg libraries to support various video formats, avTranscoder p
66

77
You can also use its Java & Python bindings for simpler integration in your own projects.
88

9-
#### Requirements
10-
* GitPython (>=0.3.2)
11-
129
#### Continuous Integration
1310

1411
###### Drone.io
@@ -23,6 +20,15 @@ You can also use its Java & Python bindings for simpler integration in your own
2320
src="https://scan.coverity.com/projects/2626/badge.svg"/>
2421
</a>
2522

23+
#### Tests
24+
25+
###### nosetests
26+
Python tests using nosetests.
27+
28+
Create environment variables to use your files in tests.
29+
* AVTRANSCODER_TEST_AUDIO_FILE
30+
* AVTRANSCODER_TEST_VIDEO_FILE
31+
2632
#### Packaging
2733

2834
###### Build openSUSE

src/AvTranscoder/avTranscoder.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
%module AvTranscoder
1+
%module avtranscoder
22

3-
%module(directors="1") AvTranscoder
3+
%module(directors="1") avtranscoder
44

55
%include "std_string.i"
66
%include "std_vector.i"

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ ICodec::ICodec( const ECodecType type, const AVCodecID codecId )
2929

3030
ICodec::~ICodec()
3131
{
32-
avcodec_close( _codecContext );
33-
av_free( _codecContext );
34-
_codecContext = NULL;
32+
if( _codecContext && _codec )
33+
{
34+
avcodec_close( _codecContext );
35+
av_free( _codecContext );
36+
_codecContext = NULL;
37+
_codec = NULL;
38+
}
3539
}
3640

3741
std::string ICodec::getCodecName() const

src/AvTranscoder/codedStream/AvOutputStream.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ AvOutputStream::AvOutputStream( OutputFile& outputFile, const size_t streamIndex
1414
{
1515
}
1616

17-
AvOutputStream::~AvOutputStream()
18-
{
19-
}
20-
21-
bool AvOutputStream::wrap( CodedData& data )
17+
bool AvOutputStream::wrap( const CodedData& data )
2218
{
2319
assert( _outputFile != NULL );
24-
2520
return _outputFile->wrap( data, _streamIndex );
2621
}
2722

src/AvTranscoder/codedStream/AvOutputStream.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ class AvExport AvOutputStream : public IOutputStream
1313
public:
1414
AvOutputStream( OutputFile& outputFile, const size_t streamIndex );
1515

16-
~AvOutputStream( );
17-
1816
size_t getStreamIndex() const { return _streamIndex; }
1917

20-
bool wrap( CodedData& data );
18+
bool wrap( const CodedData& data );
2119

2220
private:
2321
OutputFile* _outputFile;

src/AvTranscoder/codedStream/IOutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IOutputStream
1515

1616
virtual size_t getStreamIndex() const = 0;
1717

18-
virtual bool wrap( CodedData& data ) = 0;
18+
virtual bool wrap( const CodedData& data ) = 0;
1919
};
2020

2121
}

src/AvTranscoder/essenceStream/GeneratorAudio.cpp

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

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

14-
GeneratorAudio::~GeneratorAudio( )
15-
{
16-
}
17-
1814
void GeneratorAudio::setAudioCodec( const AudioCodec& codec )
1915
{
2016
_frameDesc.setFps ( 25.0 );
21-
_codec = codec;
17+
_codec = &codec;
2218

23-
_frameDesc.setSampleRate( _codec.getAVCodecContext()->sample_rate );
24-
_frameDesc.setChannels( _codec.getAVCodecContext()->channels );
25-
_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 );
2622
}
2723

28-
AudioCodec& GeneratorAudio::getAudioCodec()
24+
const AudioCodec& GeneratorAudio::getAudioCodec()
2925
{
30-
return _codec;
26+
return *_codec;
3127
}
3228

3329
void GeneratorAudio::setFrame( Frame& inputFrame )

src/AvTranscoder/essenceStream/GeneratorAudio.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ class AvExport GeneratorAudio : public IInputEssence
1212
public:
1313
GeneratorAudio( );
1414

15-
~GeneratorAudio( );
16-
1715
void setAudioCodec( const AudioCodec& codec );
1816

19-
AudioCodec& getAudioCodec();
17+
const AudioCodec& getAudioCodec();
2018

2119
void setup() {}
2220

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

2826
private:
29-
AudioCodec _codec;
30-
AudioFrameDesc _frameDesc;
31-
27+
const AudioCodec* _codec;
3228
Frame* _inputFrame;
29+
AudioFrameDesc _frameDesc;
3330
};
3431

3532
}

src/AvTranscoder/essenceStream/GeneratorVideo.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +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

17-
GeneratorVideo::~GeneratorVideo( )
18-
{
19-
}
20-
2117
void GeneratorVideo::setVideoCodec( const VideoCodec& codec )
2218
{
23-
_codec = codec;
24-
_videoFrameDesc = _codec.getVideoFrameDesc();
19+
_codec = &codec;
20+
_videoFrameDesc = _codec->getVideoFrameDesc();
2521
}
2622

27-
VideoCodec& GeneratorVideo::getVideoCodec()
23+
const VideoCodec& GeneratorVideo::getVideoCodec()
2824
{
29-
return _codec;
25+
return *_codec;
3026
}
3127

3228
void GeneratorVideo::setFrame( Frame& inputFrame )
@@ -44,7 +40,7 @@ bool GeneratorVideo::readNextFrame( Frame& frameBuffer )
4440
if( frameBuffer.getSize() != _videoFrameDesc.getDataSize() )
4541
frameBuffer.getBuffer().resize( _videoFrameDesc.getDataSize() );
4642

47-
VideoFrameDesc desc( _codec.getVideoFrameDesc() );
43+
VideoFrameDesc desc( _codec->getVideoFrameDesc() );
4844
Pixel rgbPixel;
4945
rgbPixel.setColorComponents( eComponentRgb );
5046
rgbPixel.setPlanar( false );

src/AvTranscoder/essenceStream/GeneratorVideo.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ class AvExport GeneratorVideo : public IInputEssence
1212
public:
1313
GeneratorVideo( );
1414

15-
~GeneratorVideo( );
16-
1715
// Stream properties
1816
void setVideoCodec( const VideoCodec& codec );
1917

20-
VideoCodec& getVideoCodec();
18+
const VideoCodec& getVideoCodec();
2119

2220
void setup() {}
2321

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

2927
private:
30-
Frame* _inputFrame;
31-
VideoCodec _codec;
28+
const VideoCodec* _codec;
29+
Frame* _inputFrame;
3230
VideoFrameDesc _videoFrameDesc;
3331

3432
size_t _numberOfView;

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace avtranscoder
1717
OutputFile::OutputFile( const std::string& filename )
1818
: _outputFormat ( NULL )
1919
, _formatContext ( NULL )
20-
, _codec ( NULL )
21-
, _codecContext ( NULL )
2220
, _stream ( NULL )
2321
, _filename ( filename )
2422
, _packetCount ( 0 )
@@ -192,7 +190,7 @@ bool OutputFile::endWrap( )
192190
{
193191
throw std::runtime_error( "could not write trailer" );
194192
}
195-
avcodec_close( _stream->codec );
193+
196194
if( !( _formatContext->oformat->flags & AVFMT_NOFILE ) )
197195
{
198196
avio_close( _formatContext->pb );

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class AvExport OutputFile
114114
AVOutputFormat* _outputFormat;
115115
AVFormatContext* _formatContext;
116116

117-
AVCodec* _codec;
118-
AVCodecContext* _codecContext;
119117
AVStream* _stream;
120118

121119
std::vector<size_t> _frameCount;

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ StreamTranscoder::StreamTranscoder(
162162
}
163163

164164
StreamTranscoder::StreamTranscoder(
165-
IInputEssence& inputEssence,
165+
const ICodec& inputCodec,
166166
OutputFile& outputFile,
167167
const Profile::ProfileDesc& profile
168168
)
169169
: _inputStream( NULL )
170170
, _outputStream( NULL )
171171
, _sourceBuffer( NULL )
172172
, _frameBuffer( NULL )
173-
, _inputEssence( &inputEssence )
173+
, _inputEssence( NULL )
174174
, _generatorEssence( NULL )
175175
, _currentEssence( NULL )
176176
, _outputEssence( NULL )
@@ -189,66 +189,72 @@ StreamTranscoder::StreamTranscoder(
189189

190190
if( profile.find( constants::avProfileType )->second == constants::avProfileTypeVideo )
191191
{
192-
AvOutputVideo* outputVideo = new AvOutputVideo();
193-
194-
_outputEssence = outputVideo;
195-
196-
VideoFrameDesc inputFrameDesc = static_cast<GeneratorVideo*>( _inputEssence )->getVideoCodec().getVideoFrameDesc();
197-
192+
// Create input essence based on a given input VideoCodec
193+
GeneratorVideo* generatorVideo = new GeneratorVideo();
194+
const VideoCodec& inputVideoCodec = static_cast<const VideoCodec&>( inputCodec );
195+
generatorVideo->setVideoCodec( inputVideoCodec );
196+
_inputEssence = generatorVideo;
197+
198+
// Create inputFrame, and outputFrame which is based on a given profile
199+
VideoFrameDesc inputFrameDesc = inputVideoCodec.getVideoFrameDesc();
198200
VideoFrameDesc outputFrameDesc = inputFrameDesc;
199201
outputFrameDesc.setParameters( profile );
202+
_sourceBuffer = new VideoFrame( inputFrameDesc );
203+
_frameBuffer = new VideoFrame( outputFrameDesc );
204+
205+
// Create output essence
206+
AvOutputVideo* outputVideo = new AvOutputVideo();
200207
outputVideo->setProfile( profile, outputFrameDesc );
208+
_outputEssence = outputVideo;
201209

210+
// Create a video stream in the output file
202211
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoCodec() );
203-
_sourceBuffer = new VideoFrame( inputFrameDesc );
204-
_frameBuffer = new VideoFrame( outputFrameDesc );
205212

206213
_transform = new VideoTransform();
207214

208-
_currentEssence = _inputEssence;
209-
210-
return;
215+
_currentEssence = _inputEssence;
211216
}
212-
213-
if( profile.find( constants::avProfileType )->second == constants::avProfileTypeAudio )
217+
else if( profile.find( constants::avProfileType )->second == constants::avProfileTypeAudio )
214218
{
215-
AvOutputAudio* outputAudio = new AvOutputAudio();
216-
217-
_outputEssence = outputAudio;
218-
219-
AudioFrameDesc inputFrameDesc = static_cast<GeneratorAudio*>( _inputEssence )->getAudioCodec().getFrameDesc();
220-
219+
// Create input essence based on a given input AudioCodec
220+
GeneratorAudio* generatorAudio = new GeneratorAudio();
221+
const AudioCodec& inputAudioCodec = static_cast<const AudioCodec&>( inputCodec );
222+
generatorAudio->setAudioCodec( inputAudioCodec );
223+
_inputEssence = generatorAudio;
224+
225+
// Create inputFrame, and outputFrame which is based on a given profile
226+
AudioFrameDesc inputFrameDesc = inputAudioCodec.getFrameDesc();
221227
AudioFrameDesc outputFrameDesc = inputFrameDesc;
222228
outputFrameDesc.setParameters( profile );
229+
_sourceBuffer = new AudioFrame( inputFrameDesc );
230+
_frameBuffer = new AudioFrame( outputFrameDesc );
231+
232+
// Create output essence
233+
AvOutputAudio* outputAudio = new AvOutputAudio();
223234
outputAudio->setProfile( profile, outputFrameDesc );
235+
_outputEssence = outputAudio;
224236

237+
// Create an audio stream in the output file
225238
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioCodec() );
226-
_sourceBuffer = new AudioFrame( inputFrameDesc );
227-
_frameBuffer = new AudioFrame( outputFrameDesc );
228239

229240
_transform = new AudioTransform();
230-
241+
231242
_currentEssence = _inputEssence;
232-
return;
233243
}
234-
235-
throw std::runtime_error( "unupported stream type" );
244+
else
245+
{
246+
throw std::runtime_error( "unupported stream type" );
247+
}
236248
}
237249

238250
StreamTranscoder::~StreamTranscoder()
239251
{
240-
if( _frameBuffer )
241-
delete _frameBuffer;
242-
if( _sourceBuffer )
243-
delete _sourceBuffer;
244-
if( _inputEssence && _inputStream )
245-
delete _inputEssence;
246-
if( _generatorEssence )
247-
delete _generatorEssence;
248-
if( _outputEssence )
249-
delete _outputEssence;
250-
if( _transform )
251-
delete _transform;
252+
delete _frameBuffer;
253+
delete _sourceBuffer;
254+
delete _generatorEssence;
255+
delete _outputEssence;
256+
delete _transform;
257+
delete _inputEssence;
252258
}
253259

254260
void StreamTranscoder::init()

0 commit comments

Comments
 (0)