Skip to content

Commit

Permalink
libmyth: Avoid a divide by 0 exception in AudioOutputBase
Browse files Browse the repository at this point in the history
If MythMusic starts when the default audio is ALSA and if the device
is in use by another process then snd_pcm_open can fail.  In this
case AudioOutputBase::SetAudiotime can cause a divide by 0 exception
because this->effdsp is 0.

This patch checks the value of effdsp and avoids the division if it's 0.

Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
  • Loading branch information
Lawrence Rust authored and jyavenard committed Jul 21, 2012
1 parent c35c003 commit 84aac9d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/audio/audiooutputbase.cpp
Expand Up @@ -1068,9 +1068,9 @@ int64_t AudioOutputBase::GetAudiotime(void)
of major post-stretched buffer contents
processing latencies are catered for in AddData/SetAudiotime
to eliminate race */
audiotime = audbuf_timecode - (
audiotime = audbuf_timecode - (effdsp && obpf ? (
((int64_t)(main_buffer + soundcard_buffer) * eff_stretchfactor) /
(effdsp * obpf));
(effdsp * obpf)) : 0);

/* audiotime should never go backwards, but we might get a negative
value if GetBufferedOnSoundcard() isn't updated by the driver very
Expand Down Expand Up @@ -1122,9 +1122,9 @@ void AudioOutputBase::SetAudiotime(int frames, int64_t timecode)
}

audbuf_timecode =
timecode + ((frames + processframes_unstretched * 100000) +
timecode + (effdsp ? ((frames + processframes_unstretched * 100000) +
(processframes_stretched * eff_stretchfactor)
) / effdsp;
) / effdsp : 0);

// check for timecode wrap and reset audiotime if detected
// timecode will always be monotonic asc if not seeked and reset
Expand Down

0 comments on commit 84aac9d

Please sign in to comment.