| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // THREAD SAFETY | 5 // THREAD SAFETY |
| 6 // | 6 // |
| 7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used | 7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used |
| 8 // from the audio thread. We DCHECK on this assumption whenever we can. | 8 // from the audio thread. We DCHECK on this assumption whenever we can. |
| 9 // | 9 // |
| 10 // SEMANTICS OF Close() | 10 // SEMANTICS OF Close() |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 next_fill_time_ms = std::max(next_fill_time_ms, kNoDataSleepMilliseconds); | 597 next_fill_time_ms = std::max(next_fill_time_ms, kNoDataSleepMilliseconds); |
| 598 | 598 |
| 599 // Only schedule more reads/writes if we are still in the playing state. | 599 // Only schedule more reads/writes if we are still in the playing state. |
| 600 if (state() == kIsPlaying) { | 600 if (state() == kIsPlaying) { |
| 601 if (next_fill_time_ms == 0) { | 601 if (next_fill_time_ms == 0) { |
| 602 manager_->GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | 602 manager_->GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
| 603 &AlsaPcmOutputStream::WriteTask, weak_factory_.GetWeakPtr())); | 603 &AlsaPcmOutputStream::WriteTask, weak_factory_.GetWeakPtr())); |
| 604 } else { | 604 } else { |
| 605 // TODO(ajwong): Measure the reliability of the delay interval. Use | 605 // TODO(ajwong): Measure the reliability of the delay interval. Use |
| 606 // base/metrics/histogram.h. | 606 // base/metrics/histogram.h. |
| 607 manager_->GetMessageLoop()->PostDelayedTask(FROM_HERE, | 607 manager_->GetMessageLoop()->PostDelayedTask( |
| 608 FROM_HERE, |
| 608 base::Bind(&AlsaPcmOutputStream::WriteTask, | 609 base::Bind(&AlsaPcmOutputStream::WriteTask, |
| 609 weak_factory_.GetWeakPtr()), | 610 weak_factory_.GetWeakPtr()), |
| 610 next_fill_time_ms); | 611 base::TimeDelta::FromMilliseconds(next_fill_time_ms)); |
| 611 } | 612 } |
| 612 } | 613 } |
| 613 } | 614 } |
| 614 | 615 |
| 615 uint32 AlsaPcmOutputStream::FramesToMicros(uint32 frames, uint32 sample_rate) { | 616 uint32 AlsaPcmOutputStream::FramesToMicros(uint32 frames, uint32 sample_rate) { |
| 616 return frames * base::Time::kMicrosecondsPerSecond / sample_rate; | 617 return frames * base::Time::kMicrosecondsPerSecond / sample_rate; |
| 617 } | 618 } |
| 618 | 619 |
| 619 uint32 AlsaPcmOutputStream::FramesToMillis(uint32 frames, uint32 sample_rate) { | 620 uint32 AlsaPcmOutputStream::FramesToMillis(uint32 frames, uint32 sample_rate) { |
| 620 return frames * base::Time::kMillisecondsPerSecond / sample_rate; | 621 return frames * base::Time::kMillisecondsPerSecond / sample_rate; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 if (source_callback_) | 845 if (source_callback_) |
| 845 source_callback_->OnError(this, code); | 846 source_callback_->OnError(this, code); |
| 846 } | 847 } |
| 847 | 848 |
| 848 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to | 849 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to |
| 849 // release ownership of the currently registered callback. | 850 // release ownership of the currently registered callback. |
| 850 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { | 851 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { |
| 851 DCHECK(IsOnAudioThread()); | 852 DCHECK(IsOnAudioThread()); |
| 852 source_callback_ = callback; | 853 source_callback_ = callback; |
| 853 } | 854 } |
| OLD | NEW |