Skip to content

Commit b8aaf61

Browse files
committed
Merge pull request #98 from cchampet/fix_threadsAuto
* Encoders/Decoders: fix threads option when indicated in profile. * StreamTranscoder: setProfile of decoders with an empty map.
2 parents 2873e9f + d25be6f commit b8aaf61

File tree

6 files changed

+52
-24
lines changed

6 files changed

+52
-24
lines changed

src/AvTranscoder/ProfileLoader.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace constants
2828
const std::string avProfileHeight = "height";
2929
const std::string avProfileSampleRate = "ar";
3030
const std::string avProfileChannel = "ac";
31+
const std::string avProfileThreads = "threads";
3132
}
3233

3334
class AvExport ProfileLoader

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,26 @@ bool AudioDecoder::decodeNextFrame()
151151

152152
void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
153153
{
154-
// set threads if not in profile
155-
if( ! profile.count( "threads" ) )
156-
_inputStream->getAudioCodec().getOption( "threads" ).setString( "auto" );
154+
AudioCodec& codec = _inputStream->getAudioCodec();
157155

156+
// set threads before any other options
157+
if( profile.count( constants::avProfileThreads ) )
158+
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
159+
else
160+
codec.getOption( constants::avProfileThreads ).setString( "auto" );
161+
162+
// set decoder options
158163
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
159164
{
160165
if( (*it).first == constants::avProfileIdentificator ||
161166
(*it).first == constants::avProfileIdentificatorHuman ||
162-
(*it).first == constants::avProfileType )
167+
(*it).first == constants::avProfileType ||
168+
(*it).first == constants::avProfileThreads )
163169
continue;
164170

165171
try
166172
{
167-
Option& decodeOption = _inputStream->getAudioCodec().getOption( (*it).first );
173+
Option& decodeOption = codec.getOption( (*it).first );
168174
decodeOption.setString( (*it).second );
169175
}
170176
catch( std::exception& e )

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,26 @@ void VideoDecoder::flushDecoder()
110110

111111
void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
112112
{
113-
// set threads if not in profile
114-
if( ! profile.count( "threads" ) )
115-
_inputStream->getVideoCodec().getOption( "threads" ).setString( "auto" );
113+
VideoCodec& codec = _inputStream->getVideoCodec();
116114

115+
// set threads before any other options
116+
if( profile.count( constants::avProfileThreads ) )
117+
codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
118+
else
119+
codec.getOption( constants::avProfileThreads ).setString( "auto" );
120+
121+
// set decoder options
117122
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
118123
{
119124
if( (*it).first == constants::avProfileIdentificator ||
120125
(*it).first == constants::avProfileIdentificatorHuman ||
121-
(*it).first == constants::avProfileType )
126+
(*it).first == constants::avProfileType ||
127+
(*it).first == constants::avProfileThreads )
122128
continue;
123129

124130
try
125131
{
126-
Option& decodeOption = _inputStream->getVideoCodec().getOption( (*it).first );
132+
Option& decodeOption = codec.getOption( (*it).first );
127133
decodeOption.setString( (*it).second );
128134
}
129135
catch( std::exception& e )

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
146146
// set sampleRate, number of channels, sample format
147147
_codec.setAudioParameters( frameDesc );
148148

149-
// set threads if not in profile
150-
if( ! profile.count( "threads" ) )
151-
_codec.getOption( "threads" ).setString( "auto" );
149+
// set threads before any other options
150+
if( profile.count( constants::avProfileThreads ) )
151+
_codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
152+
else
153+
_codec.getOption( constants::avProfileThreads ).setString( "auto" );
154+
152155

153156
// set encoder options
154157
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
@@ -157,7 +160,8 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
157160
(*it).first == constants::avProfileIdentificatorHuman ||
158161
(*it).first == constants::avProfileType ||
159162
(*it).first == constants::avProfileCodec ||
160-
(*it).first == constants::avProfileSampleFormat )
163+
(*it).first == constants::avProfileSampleFormat ||
164+
(*it).first == constants::avProfileThreads )
161165
continue;
162166

163167
try
@@ -177,7 +181,8 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
177181
(*it).first == constants::avProfileIdentificatorHuman ||
178182
(*it).first == constants::avProfileType ||
179183
(*it).first == constants::avProfileCodec ||
180-
(*it).first == constants::avProfileSampleFormat )
184+
(*it).first == constants::avProfileSampleFormat ||
185+
(*it).first == constants::avProfileThreads )
181186
continue;
182187

183188
try

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
137137
// set width, height, pixel format, fps
138138
_codec.setImageParameters( frameDesc );
139139

140-
// set threads if not in profile
141-
if( ! profile.count( "threads" ) )
142-
_codec.getOption( "threads" ).setString( "auto" );
140+
// set threads before any other options
141+
if( profile.count( constants::avProfileThreads ) )
142+
_codec.getOption( constants::avProfileThreads ).setString( profile.at( constants::avProfileThreads ) );
143+
else
144+
_codec.getOption( constants::avProfileThreads ).setString( "auto" );
143145

144146
// set encoder options
145147
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
@@ -151,7 +153,8 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
151153
(*it).first == constants::avProfileWidth ||
152154
(*it).first == constants::avProfileHeight ||
153155
(*it).first == constants::avProfilePixelFormat ||
154-
(*it).first == constants::avProfileFrameRate )
156+
(*it).first == constants::avProfileFrameRate ||
157+
(*it).first == constants::avProfileThreads )
155158
continue;
156159

157160
try
@@ -174,7 +177,8 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
174177
(*it).first == constants::avProfileWidth ||
175178
(*it).first == constants::avProfileHeight ||
176179
(*it).first == constants::avProfilePixelFormat ||
177-
(*it).first == constants::avProfileFrameRate )
180+
(*it).first == constants::avProfileFrameRate ||
181+
(*it).first == constants::avProfileThreads )
178182
continue;
179183

180184
try

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ StreamTranscoder::StreamTranscoder(
133133
case AVMEDIA_TYPE_VIDEO :
134134
{
135135
// input decoder
136-
_inputDecoder = new VideoDecoder( *static_cast<InputStream*>( _inputStream ) );
137-
_inputDecoder->setup();
136+
VideoDecoder* inputVideo = new VideoDecoder( *static_cast<InputStream*>( _inputStream ) );
137+
// set decoder options with empty profile to set some key options to specific values (example: threads to auto)
138+
inputVideo->setProfile( ProfileLoader::Profile() );
139+
inputVideo->setup();
140+
_inputDecoder = inputVideo;
138141
_currentDecoder = _inputDecoder;
139142

140143
// output encoder
@@ -165,8 +168,11 @@ StreamTranscoder::StreamTranscoder(
165168
case AVMEDIA_TYPE_AUDIO :
166169
{
167170
// input decoder
168-
_inputDecoder = new AudioDecoder( *static_cast<InputStream*>( _inputStream ) );
169-
_inputDecoder->setup();
171+
AudioDecoder* inputAudio = new AudioDecoder( *static_cast<InputStream*>( _inputStream ) );
172+
// set decoder options with empty profile to set some key options to specific values (example: threads to auto)
173+
inputAudio->setProfile( ProfileLoader::Profile() );
174+
inputAudio->setup();
175+
_inputDecoder = inputAudio;
170176
_currentDecoder = _inputDecoder;
171177

172178
// output encoder

0 commit comments

Comments
 (0)