Skip to content
Browse files

libmyth: Avoid a divide by 0 exception in AudioOutputBase

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>
(cherry picked from commit 84aac9d)
  • Loading branch information...
1 parent c1147b6 commit 9b412a7cbc5556af31b8973f43ece7142a341d9d Lawrence Rust committed with jyavenard Jun 24, 2012
Showing with 4 additions and 4 deletions.
  1. +4 −4 mythtv/libs/libmyth/audio/audiooutputbase.cpp
View
8 mythtv/libs/libmyth/audio/audiooutputbase.cpp
@@ -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
@@ -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

0 comments on commit 9b412a7

Please sign in to comment.
Something went wrong with that request. Please try again.