Skip to content

Commit b664bf3

Browse files
fix transcoder for dummy streams
1 parent 2676792 commit b664bf3

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

src/AvTranscoder/Transcoder/StreamTranscoder.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,36 @@ StreamTranscoder::StreamTranscoder(
110110
, _outputEssence( NULL )
111111
, _transcodeStream( true )
112112
{
113-
// create an encoder case from a dummy
114-
switch( _inputStream->getStreamType() )
113+
if( ! profile.count( Profile::avProfileType ) )
114+
throw std::runtime_error( "unable to found stream type (audio, video, etc.)" );
115+
116+
if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeAudio )
115117
{
116-
case AVMEDIA_TYPE_VIDEO :
117-
{
118-
OutputVideo* outputVideo = new OutputVideo();
119-
_outputEssence = outputVideo;
118+
OutputAudio* outputAudio = new OutputAudio();
120119

121-
_outputEssence->setProfile( profile );
122-
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() );
123-
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );
124-
_frameBuffer = _videoFrameBuffer;
125-
126-
break;
127-
}
128-
case AVMEDIA_TYPE_AUDIO :
129-
{
130-
OutputAudio* outputAudio = new OutputAudio();
131-
_outputEssence = outputAudio;
120+
_outputEssence = outputAudio;
121+
_outputEssence->setProfile( profile );
132122

133-
_outputEssence->setProfile( profile );
134-
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() );
135-
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
136-
_frameBuffer = _audioFrameBuffer;
137-
138-
break;
139-
}
140-
default:
141-
{
142-
throw std::runtime_error( "unupported stream type" );
143-
break;
144-
}
123+
_outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() );
124+
_audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() );
125+
_frameBuffer = _audioFrameBuffer;
126+
return;
145127
}
128+
129+
if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeVideo )
130+
{
131+
OutputVideo* outputVideo = new OutputVideo();
132+
133+
_outputEssence = outputVideo;
134+
_outputEssence->setProfile( profile );
135+
136+
_outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() );
137+
_videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() );
138+
_frameBuffer = _videoFrameBuffer;
139+
return;
140+
}
141+
142+
throw std::runtime_error( "unupported stream type" );
146143
}
147144

148145
StreamTranscoder::~StreamTranscoder()
@@ -182,19 +179,24 @@ bool StreamTranscoder::processTranscode()
182179
assert( _outputEssence != NULL );
183180
assert( _frameBuffer != NULL );
184181

182+
std::cout << "transcode" << std::endl;
183+
185184
DataStream dataStream;
186185
if( _inputEssence->readNextFrame( *_frameBuffer ) )
187186
{
187+
std::cout << "encode" << std::endl;
188188
_outputEssence->encodeFrame( *_frameBuffer, dataStream );
189189
}
190190
else
191191
{
192+
std::cout << "encode last frame" << std::endl;
192193
if( ! _outputEssence->encodeFrame( dataStream ) )
193194
{
194195
return false;
195196
}
196197
}
197198

199+
std::cout << "wrap" << std::endl;
198200
_outputStream->wrap( dataStream );
199201
return true;
200202
}

src/AvTranscoder/Transcoder/Transcoder.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, Pro
6666

6767
bool Transcoder::processFrame()
6868
{
69-
for( size_t streamIndex = 0; streamIndex < _inputStreams.size(); ++streamIndex )
69+
if( _verbose )
70+
std::cout << "process frame" << std::endl;
71+
for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
7072
{
71-
if( ( _streamTranscoders.size() > streamIndex ) &&
72-
! _streamTranscoders.at( streamIndex )->processFrame() )
73+
if( ! _streamTranscoders.at( streamIndex )->processFrame() )
7374
{
74-
//_inputStreams.erase( _inputStreams.begin() + streamIndex );
75-
_inputStreams.clear();
75+
_streamTranscoders.clear();
7676
}
7777
}
7878

79-
if( _inputStreams.size() == 0 )
79+
if( _streamTranscoders.size() == 0 )
8080
{
8181
return false;
8282
}
@@ -164,13 +164,15 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
164164
default:
165165
{
166166
throw std::runtime_error( "unsupported media type in transcode setup" );
167-
return;
168167
}
169168
}
170169
}
171170

172171
void Transcoder::addDummyStream( Profile::ProfileDesc& profile )
173172
{
173+
if( ! profile.count( Profile::avProfileType ) )
174+
throw std::runtime_error( "unable to found stream type (audio, video, etc.)" );
175+
174176
if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeAudio )
175177
{
176178
_dummyAudio.push_back( new DummyAudio() );

0 commit comments

Comments
 (0)