Skip to content

Commit

Permalink
refactor(supermediaplayer): fix SetUpAudioPath logic
Browse files Browse the repository at this point in the history
The audio render could not be created after decoded a aduio frame when packet buffer is very low on
start, and then renderAudio() will crash

Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Aug 14, 2020
1 parent 829eafe commit e76949d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2982,17 +2982,25 @@ int SuperMediaPlayer::setUpAudioDecoder(const Stream_meta *meta)

int SuperMediaPlayer::SetUpAudioPath()
{
if (mBufferController->IsPacketEmtpy(BUFFER_TYPE_AUDIO)) {
return 0;
}
int ret;
if (mAudioDecoder == nullptr) {

unique_ptr<streamMeta> pMeta{};
mDemuxerService->GetStreamMeta(pMeta, mCurrentAudioIndex, false);
Stream_meta *meta = (Stream_meta *) (pMeta.get());
int ret = setUpAudioDecoder(meta);
/*
* make sure the audio stream is opened before get stream meta,
* otherwise, will crash in hls stream
*/
if (mBufferController->IsPacketEmtpy(BUFFER_TYPE_AUDIO)) {
return 0;
}

if (ret < 0) {
return ret;
unique_ptr<streamMeta> pMeta{};
mDemuxerService->GetStreamMeta(pMeta, mCurrentAudioIndex, false);
Stream_meta *meta = (Stream_meta *) (pMeta.get());
ret = setUpAudioDecoder(meta);

if (ret < 0) {
return ret;
}
}

if (mAudioFrameQue.empty() || mAudioRender != nullptr) {
Expand Down

0 comments on commit e76949d

Please sign in to comment.