Skip to content

Commit d2bd6ed

Browse files
author
Clement Champetier
committed
StreamTranscoder: refactoring - constructors with const ProfileDesc
* Use "const ProfileDesc" instead of "ProfileDesc" when instanciate a StreamTranscoder. * Consequences: * OutputAudio: setProfile with a const ProfileDesc. * OutputVideo: setProfile with a const ProfileDesc. * use find instead of [] to access the elements of ProfileDesc.
1 parent 9ea90af commit d2bd6ed

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

src/AvTranscoder/EssenceStream/OutputAudio.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,23 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame )
176176
#endif
177177
}
178178

179-
void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
179+
void OutputAudio::setProfile( const Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc )
180180
{
181181
if( ! desc.count( Profile::avProfileCodec ) ||
182182
! desc.count( Profile::avProfileSampleFormat ) ||
183183
! desc.count( Profile::avProfileSampleRate ) ||
184184
! desc.count( Profile::avProfileChannel ) )
185185
{
186-
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
186+
throw std::runtime_error( "The profile " + desc.find( Profile::avProfileIdentificatorHuman )->second + " is invalid." );
187187
}
188188

189-
_audioDesc.setCodec( desc[ Profile::avProfileCodec ] );
189+
_audioDesc.setCodec( desc.find( Profile::avProfileCodec )->second );
190190

191-
size_t sample_rate = std::strtoul( desc[ Profile::avProfileSampleRate ].c_str(), NULL, 0 );
192-
size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 );
193-
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) );
191+
size_t sample_rate = std::strtoul( desc.find( Profile::avProfileSampleRate )->second.c_str(), NULL, 0 );
192+
size_t channels = std::strtoul( desc.find( Profile::avProfileChannel )->second.c_str(), NULL, 0 );
193+
_audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc.find( Profile::avProfileSampleFormat )->second.c_str() ) );
194194

195-
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
195+
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
196196
{
197197
if( (*it).first == Profile::avProfileIdentificator ||
198198
(*it).first == Profile::avProfileIdentificatorHuman ||
@@ -215,7 +215,7 @@ void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc&
215215

216216
setup();
217217

218-
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
218+
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
219219
{
220220
if( (*it).first == Profile::avProfileIdentificator ||
221221
(*it).first == Profile::avProfileIdentificatorHuman ||

src/AvTranscoder/EssenceStream/OutputAudio.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OutputAudio : public OutputEssence
2929
*/
3030
bool encodeFrame( DataStream& codedFrame );
3131

32-
void setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc );
32+
void setProfile( const Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc );
3333

3434
AudioDesc& getAudioDesc() { return _audioDesc; }
3535

src/AvTranscoder/EssenceStream/OutputVideo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,23 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame )
186186
#endif
187187
}
188188

189-
void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc )
189+
void OutputVideo::setProfile( const Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc )
190190
{
191191
if( ! desc.count( Profile::avProfileCodec ) ||
192192
! desc.count( Profile::avProfilePixelFormat ) ||
193193
! desc.count( Profile::avProfileFrameRate ) )
194194
{
195-
throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." );
195+
throw std::runtime_error( "The profile " + desc.find( Profile::avProfileIdentificatorHuman )->second + " is invalid." );
196196
}
197197

198-
_videoDesc.setCodec( desc[ Profile::avProfileCodec ] );
198+
_videoDesc.setCodec( desc.find( Profile::avProfileCodec )->second );
199199

200-
const size_t frameRate = std::strtoul( desc[ Profile::avProfileFrameRate ].c_str(), NULL, 0 );
200+
const size_t frameRate = std::strtoul( desc.find( Profile::avProfileFrameRate )->second.c_str(), NULL, 0 );
201201
_videoDesc.setTimeBase( 1, frameRate );
202202

203203
_videoDesc.setImageParameters( imageDesc );
204204

205-
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
205+
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
206206
{
207207
if( (*it).first == Profile::avProfileIdentificator ||
208208
(*it).first == Profile::avProfileIdentificatorHuman ||
@@ -224,7 +224,7 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im
224224

225225
setup();
226226

227-
for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )
227+
for( Profile::ProfileDesc::const_iterator it = desc.begin(); it != desc.end(); ++it )
228228
{
229229
if( (*it).first == Profile::avProfileIdentificator ||
230230
(*it).first == Profile::avProfileIdentificatorHuman ||

src/AvTranscoder/EssenceStream/OutputVideo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AvExport OutputVideo : public OutputEssence
4444
*/
4545
bool encodeFrame( DataStream& codedFrame );
4646

47-
void setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc );
47+
void setProfile( const Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc );
4848

4949
VideoDesc& getVideoDesc() { return _videoDesc; }
5050

src/AvTranscoder/Transcoder/StreamTranscoder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ StreamTranscoder::StreamTranscoder(
5050
StreamTranscoder::StreamTranscoder(
5151
InputStream& inputStream,
5252
OutputFile& outputFile,
53-
Profile::ProfileDesc& profile,
53+
const Profile::ProfileDesc& profile,
5454
const int subStreamIndex
5555
)
5656
: _inputStream( &inputStream )
@@ -78,7 +78,7 @@ StreamTranscoder::StreamTranscoder(
7878

7979
ImageDesc outputImageDesc = _inputStream->getVideoDesc().getImageDesc();
8080

81-
outputImageDesc.setPixel( Pixel( profile[ Profile::avProfilePixelFormat ].c_str() ) );
81+
outputImageDesc.setPixel( Pixel( profile.find( Profile::avProfilePixelFormat )->second.c_str() ) );
8282

8383
outputVideo->setProfile( profile, outputImageDesc );
8484

@@ -129,7 +129,7 @@ StreamTranscoder::StreamTranscoder(
129129
StreamTranscoder::StreamTranscoder(
130130
InputEssence& inputEssence,
131131
OutputFile& outputFile,
132-
Profile::ProfileDesc& profile
132+
const Profile::ProfileDesc& profile
133133
)
134134
: _inputStream( NULL )
135135
, _outputStream( NULL )
@@ -151,8 +151,8 @@ StreamTranscoder::StreamTranscoder(
151151
OutputAudio* outputAudio = new OutputAudio();
152152

153153
_outputEssence = outputAudio;
154-
AudioFrameDesc srcAudioFrameDesc; // @todo better solution ?
155-
outputAudio->setProfile( profile, srcAudioFrameDesc );
154+
AudioFrameDesc inputAudioFrameDesc = static_cast<DummyAudio*>( _inputEssence )->getAudioDesc().getFrameDesc();
155+
outputAudio->setProfile( profile, inputAudioFrameDesc );
156156

157157
static_cast<DummyAudio*>( _inputEssence )->setAudioDesc( outputAudio->getAudioDesc() );
158158

src/AvTranscoder/Transcoder/StreamTranscoder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class StreamTranscoder
2929
/**
3030
* @brief transcode stream
3131
**/
32-
StreamTranscoder( InputStream& inputStream, OutputFile& outputFile, Profile::ProfileDesc& profile, const int subStreamIndex = -1 );
32+
StreamTranscoder( InputStream& inputStream, OutputFile& outputFile, const Profile::ProfileDesc& profile, const int subStreamIndex = -1 );
3333

3434
/**
3535
* @brief encode from dummy stream
3636
**/
37-
StreamTranscoder( InputEssence& inputEssence, OutputFile& outputFile, Profile::ProfileDesc& profile );
37+
StreamTranscoder( InputEssence& inputEssence, OutputFile& outputFile, const Profile::ProfileDesc& profile );
3838

3939
~StreamTranscoder();
4040

0 commit comments

Comments
 (0)