Skip to content

Commit 2129ab2

Browse files
author
Clement Champetier
committed
Merge branch 'dev_setFrame_v2' of https://github.com/cchampet/avTranscoder into develop
Conflicts: src/AvTranscoder/essenceStream/AvInputVideo.cpp src/AvTranscoder/essenceStream/AvInputVideo.hpp src/AvTranscoder/transcoder/StreamTranscoder.cpp src/AvTranscoder/transcoder/Transcoder.cpp
2 parents 67475cc + 175b1a8 commit 2129ab2

36 files changed

+346
-282
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ int main( int argc, char** argv )
114114
// set verbose of all stream
115115
transcoder.setVerbose( verbose );
116116
transcoder.setProcessMethod( avtranscoder::eProcessMethodLongest );
117-
//transcoder.setOutputFps( 12 );
118117
transcoder.init();
119118

120119
if( verbose )

app/presetChecker/presetChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
3434
if( profile.find( avtranscoder::constants::avProfileType )->second == avtranscoder::constants::avProfileTypeAudio )
3535
{
3636
avtranscoder::AvOutputAudio outputAudio;
37-
outputAudio.setProfile( profile, outputAudio.getAudioCodec().getFrameDesc() );
37+
outputAudio.setProfile( profile, outputAudio.getAudioCodec().getAudioFrameDesc() );
3838
}
3939
}
4040
catch( ... )

src/AvTranscoder/avTranscoder.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <AvTranscoder/essenceStream/IInputEssence.hpp>
4141
#include <AvTranscoder/essenceStream/AvInputAudio.hpp>
4242
#include <AvTranscoder/essenceStream/AvInputVideo.hpp>
43+
#include <AvTranscoder/essenceStream/GeneratorVideo.hpp>
44+
#include <AvTranscoder/essenceStream/GeneratorAudio.hpp>
4345

4446
#include <AvTranscoder/file/InputFile.hpp>
4547
#include <AvTranscoder/file/OutputFile.hpp>
@@ -59,6 +61,7 @@ namespace std {
5961
%template(ChannelVector) vector< avtranscoder::Channel >;
6062
%template(ProfileMap) map< string, string >;
6163
%template(ProfilesVector) vector< map< string, string > >;
64+
%template(DataBuffer) std::vector< unsigned char >;
6265
}
6366

6467
%include "AvTranscoder/progress/progress.i"
@@ -90,6 +93,8 @@ namespace std {
9093
%include <AvTranscoder/essenceStream/IInputEssence.hpp>
9194
%include <AvTranscoder/essenceStream/AvInputAudio.hpp>
9295
%include <AvTranscoder/essenceStream/AvInputVideo.hpp>
96+
%include <AvTranscoder/essenceStream/GeneratorVideo.hpp>
97+
%include <AvTranscoder/essenceStream/GeneratorAudio.hpp>
9398

9499
%include <AvTranscoder/file/InputFile.hpp>
95100
%include <AvTranscoder/file/OutputFile.hpp>

src/AvTranscoder/codec/AudioCodec.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ AudioCodec::AudioCodec( const ICodec& codec )
2020
{
2121
}
2222

23-
AudioFrameDesc AudioCodec::getFrameDesc() const
23+
AudioFrameDesc AudioCodec::getAudioFrameDesc() const
2424
{
2525
assert( _codecContext != NULL );
2626
AudioFrameDesc audioFrameDesc;
@@ -33,24 +33,6 @@ AudioFrameDesc AudioCodec::getFrameDesc() const
3333
return audioFrameDesc;
3434
}
3535

36-
const size_t AudioCodec::getSampleRate() const
37-
{
38-
assert( _codecContext != NULL );
39-
return _codecContext->sample_rate;
40-
}
41-
42-
const size_t AudioCodec::getChannels() const
43-
{
44-
assert( _codecContext != NULL );
45-
return _codecContext->channels;
46-
}
47-
48-
const AVSampleFormat AudioCodec::getAVSampleFormat() const
49-
{
50-
assert( _codecContext != NULL );
51-
return _codecContext->sample_fmt;
52-
}
53-
5436
void AudioCodec::setAudioParameters( const AudioFrameDesc& audioFrameDesc )
5537
{
5638
setAudioParameters( audioFrameDesc.getSampleRate(), audioFrameDesc.getChannels(), audioFrameDesc.getAVSampleFormat() );

src/AvTranscoder/codec/AudioCodec.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ class AvExport AudioCodec : public ICodec
1414
AudioCodec( const ECodecType type, const AVCodecID codecId );
1515
AudioCodec( const ICodec& codec );
1616

17-
AudioFrameDesc getFrameDesc() const;
18-
const size_t getSampleRate() const;
19-
const size_t getChannels() const;
20-
const AVSampleFormat getAVSampleFormat() const;
21-
17+
AudioFrameDesc getAudioFrameDesc() const;
18+
2219
void setAudioParameters( const AudioFrameDesc& audioFrameDesc );
2320
void setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat );
2421
};

src/AvTranscoder/codec/VideoCodec.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ VideoCodec::VideoCodec( const ICodec& codec )
2323
VideoFrameDesc VideoCodec::getVideoFrameDesc() const
2424
{
2525
assert( _codecContext != NULL );
26-
VideoFrameDesc VideoFrameDesc;
26+
27+
VideoFrameDesc videoFrameDesc;
28+
videoFrameDesc.setWidth ( _codecContext->width );
29+
videoFrameDesc.setHeight( _codecContext->height );
30+
videoFrameDesc.setDar( _codecContext->width, _codecContext->height );
31+
2732
Pixel pixel( _codecContext->pix_fmt );
33+
videoFrameDesc.setPixel( pixel );
2834

29-
VideoFrameDesc.setWidth ( _codecContext->width );
30-
VideoFrameDesc.setHeight( _codecContext->height );
31-
VideoFrameDesc.setPixel ( pixel );
32-
VideoFrameDesc.setDar ( _codecContext->height, _codecContext->width );
33-
return VideoFrameDesc;
35+
return videoFrameDesc;
3436
}
3537

3638
std::pair< size_t, size_t > VideoCodec::getTimeBase() const

src/AvTranscoder/codedStream/AvInputStream.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ AvInputStream::AvInputStream( InputFile& inputFile, const size_t streamIndex )
1717
: IInputStream( )
1818
, _inputFile( &inputFile )
1919
, _codec( NULL )
20-
, _packetDuration( 0 )
2120
, _streamIndex( streamIndex )
2221
, _bufferized( false )
2322
{
@@ -98,7 +97,6 @@ void AvInputStream::addPacket( AVPacket& packet )
9897
//std::cout << "add packet for stream " << _streamIndex << std::endl;
9998
CodedData data;
10099
_streamCache.push_back( data );
101-
_packetDuration = packet.duration;
102100

103101
if( ! _bufferized )
104102
return;
@@ -166,11 +164,6 @@ double AvInputStream::getDuration() const
166164
return 1.0 * _inputFile->getFormatContext().duration / AV_TIME_BASE;
167165
}
168166

169-
double AvInputStream::getPacketDuration() const
170-
{
171-
return _packetDuration * av_q2d( _inputFile->getFormatContext().streams[_streamIndex]->time_base );
172-
}
173-
174167
void AvInputStream::clearBuffering()
175168
{
176169
_streamCache.clear();

src/AvTranscoder/codedStream/AvInputStream.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class AvExport AvInputStream : public IInputStream
3030
AVMediaType getStreamType() const;
3131

3232
double getDuration() const;
33-
double getPacketDuration() const;
3433

3534
void addPacket( AVPacket& packet );
3635

@@ -43,14 +42,13 @@ class AvExport AvInputStream : public IInputStream
4342
AVStream* getAVStream() const;
4443

4544
private:
46-
InputFile* _inputFile;
47-
std::vector<CodedData> _streamCache;
48-
45+
InputFile* _inputFile; ///< Has link (no ownership)
4946
ICodec* _codec; ///< Has ownership
5047

51-
int _packetDuration;
52-
size_t _streamIndex;
53-
bool _bufferized;
48+
std::vector<CodedData> _streamCache;
49+
50+
size_t _streamIndex; ///< Index of the stream in the input file
51+
bool _bufferized; ///< If the stream is bufferized
5452
};
5553

5654
}

src/AvTranscoder/codedStream/AvOutputStream.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class AvExport AvOutputStream : public IOutputStream
1818
IOutputStream::EWrappingStatus wrap( const CodedData& data );
1919

2020
private:
21-
OutputFile* _outputFile;
21+
OutputFile* _outputFile; ///< Has link (no ownership)
2222

23-
size_t _streamIndex;
23+
size_t _streamIndex; ///< Index of the stream in the output file
2424
};
2525

2626
}

src/AvTranscoder/codedStream/IInputStream.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class IInputStream
2626
virtual AVMediaType getStreamType() const = 0;
2727

2828
virtual double getDuration() const = 0;
29-
virtual double getPacketDuration() const = 0;
3029

3130
virtual void setBufferred( const bool bufferized ) = 0;
3231

src/AvTranscoder/essenceStream/AvInputAudio.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace avtranscoder
2020
AvInputAudio::AvInputAudio( AvInputStream& inputStream )
2121
: IInputEssence()
2222
, _inputStream ( &inputStream )
23-
, _codec( eCodecTypeDecoder, inputStream.getAudioCodec().getCodecId() )
23+
, _codec( &inputStream.getAudioCodec() )
2424
, _frame ( NULL )
25-
, _selectedStream( -1 )
25+
, _selectedStream( inputStream.getStreamIndex() )
2626
{
2727
}
2828

@@ -46,10 +46,10 @@ AvInputAudio::~AvInputAudio()
4646

4747
void AvInputAudio::setup()
4848
{
49-
AVCodecContext* avCodecContext = _codec.getAVCodecContext();
50-
AVCodec* avCodec = _codec.getAVCodec();
49+
AVCodecContext* avCodecContext = _codec->getAVCodecContext();
50+
AVCodec* avCodec = _codec->getAVCodec();
5151

52-
avCodecContext->channels = _inputStream->getAudioCodec().getChannels();
52+
avCodecContext->channels = _inputStream->getAudioCodec().getAudioFrameDesc().getChannels();
5353

5454
int ret = avcodec_open2( avCodecContext, avCodec, NULL );
5555

@@ -82,10 +82,10 @@ void AvInputAudio::setup()
8282

8383
bool AvInputAudio::readNextFrame( Frame& frameBuffer )
8484
{
85-
if( ! getNextFrame() )
85+
if( ! decodeNextFrame() )
8686
return false;
8787

88-
AVCodecContext* avCodecContext = _codec.getAVCodecContext();
88+
AVCodecContext* avCodecContext = _codec->getAVCodecContext();
8989

9090
size_t decodedSize = av_samples_get_buffer_size(
9191
NULL, avCodecContext->channels,
@@ -116,14 +116,14 @@ bool AvInputAudio::readNextFrame( Frame& frameBuffer )
116116

117117
bool AvInputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex )
118118
{
119-
if( ! getNextFrame() )
119+
if( ! decodeNextFrame() )
120120
return false;
121121

122122
const int output_nbChannels = 1;
123123
const int output_align = 1;
124-
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codec.getAVCodecContext()->sample_fmt, output_align);
124+
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codec->getAVCodecContext()->sample_fmt, output_align);
125125

126-
size_t nbSubStreams = _codec.getAVCodecContext()->channels;
126+
size_t nbSubStreams = _codec->getAVCodecContext()->channels;
127127
size_t bytePerSample = av_get_bytes_per_sample( (AVSampleFormat)_frame->format );
128128

129129
if( subStreamIndex > nbSubStreams - 1 )
@@ -156,7 +156,7 @@ bool AvInputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamInde
156156
return true;
157157
}
158158

159-
bool AvInputAudio::getNextFrame()
159+
bool AvInputAudio::decodeNextFrame()
160160
{
161161
int got_frame = 0;
162162
while( ! got_frame )
@@ -172,7 +172,7 @@ bool AvInputAudio::getNextFrame()
172172
packet.data = data.getPtr();
173173
packet.size = data.getSize();
174174

175-
int ret = avcodec_decode_audio4( _codec.getAVCodecContext(), _frame, &got_frame, &packet );
175+
int ret = avcodec_decode_audio4( _codec->getAVCodecContext(), _frame, &got_frame, &packet );
176176

177177
if( ret < 0 )
178178
{

src/AvTranscoder/essenceStream/AvInputAudio.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ class AvExport AvInputAudio : public IInputEssence
2323
bool readNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
2424

2525
private:
26-
bool getNextFrame();
26+
bool decodeNextFrame();
2727

28-
AvInputStream* _inputStream;
29-
AudioCodec _codec;
30-
AVFrame* _frame;
28+
AvInputStream* _inputStream; ///< Stream from which we read next frames
29+
const AudioCodec* _codec; ///< Audio decoder. Has link (no ownership)
30+
AVFrame* _frame; ///< Libav object to store decoded data
3131

32-
int _selectedStream;
32+
int _selectedStream; ///< Index of the selected stream in the input file
3333
};
3434

3535
}

0 commit comments

Comments
 (0)