summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-25 23:57:42 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-25 23:57:42 +0000
commit54c496b498e8234e94c86fdd3d3f847e3b85b066 (patch)
tree7e31e6acadae28f41e7b29f3a3acfc051d3aeb2a /media/audio
parent7829a22a8cfb6345fdf96ccbe8b3a73fce91a3b5 (diff)
downloadchromium_src-54c496b498e8234e94c86fdd3d3f847e3b85b066.zip
chromium_src-54c496b498e8234e94c86fdd3d3f847e3b85b066.tar.gz
chromium_src-54c496b498e8234e94c86fdd3d3f847e3b85b066.tar.bz2
Prevent integer underflow when calculating next_fill_time_ms in AlsaPcmOutputStream.
BUG=35819 TEST=play any content containing audio under linux, the sound should no longer cut out Review URL: http://codereview.chromium.org/660066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40070 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/linux/alsa_output.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc
index 8971ca6..1ecd685 100644
--- a/media/audio/linux/alsa_output.cc
+++ b/media/audio/linux/alsa_output.cc
@@ -625,12 +625,21 @@ void AlsaPcmOutputStream::ScheduleNextWrite(Packet* current_packet) {
FramesInPacket(*current_packet, bytes_per_output_frame_);
uint32 frames_avail_wanted =
(frames_leftover > 0) ? frames_leftover : frames_per_packet_;
- uint32 frames_until_empty_enough = frames_avail_wanted - GetAvailableFrames();
- uint32 next_fill_time_ms =
- FramesToMillis(frames_until_empty_enough, sample_rate_);
+ uint32 available_frames = GetAvailableFrames();
+ uint32 next_fill_time_ms = 0;
+
+ // It's possible to have more frames available than what we want, in which
+ // case we'll leave our |next_fill_time_ms| at 0ms.
+ if (available_frames < frames_avail_wanted) {
+ uint32 frames_until_empty_enough = frames_avail_wanted - available_frames;
+ next_fill_time_ms =
+ FramesToMillis(frames_until_empty_enough, sample_rate_);
+ }
// Adjust for timer resolution issues.
- if (next_fill_time_ms > kSleepErrorMilliseconds) {
+ if (next_fill_time_ms < kSleepErrorMilliseconds) {
+ next_fill_time_ms = 0;
+ } else {
next_fill_time_ms -= kSleepErrorMilliseconds;
}
@@ -644,7 +653,7 @@ void AlsaPcmOutputStream::ScheduleNextWrite(Packet* current_packet) {
// Only schedule more reads/writes if we are still in the playing state.
if (shared_data_.state() == kIsPlaying) {
- if (next_fill_time_ms <= 0) {
+ if (next_fill_time_ms == 0) {
message_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this, &AlsaPcmOutputStream::WriteTask));