Chromium Code Reviews| Index: media/base/audio_fifo.cc |
| =================================================================== |
| --- media/base/audio_fifo.cc (revision 156920) |
| +++ media/base/audio_fifo.cc (working copy) |
| @@ -6,6 +6,10 @@ |
| #include "base/logging.h" |
| +using base::subtle::Atomic32; |
| +using base::subtle::NoBarrier_AtomicExchange; |
| +using base::subtle::MemoryBarrier; |
| + |
| namespace media { |
| // Given current position in the FIFO, the maximum number of elements in the |
| @@ -40,7 +44,8 @@ |
| AudioFifo::AudioFifo(int channels, int frames) |
| : audio_bus_(AudioBus::Create(channels, frames)), |
| max_frames_(frames), |
| - frames_(0), |
| + frames_pushed_(0), |
| + frames_consumed_(0), |
| read_pos_(0), |
| write_pos_(0) {} |
| @@ -52,7 +57,7 @@ |
| // Ensure that there is space for the new data in the FIFO. |
| const int source_size = source->frames(); |
| - CHECK_LE(source_size + frames_, max_frames_); |
| + CHECK_LE(source_size + frames(), max_frames_); |
| // Figure out if wrapping is needed and if so what segment sizes we need |
| // when adding the new audio bus content to the FIFO. |
| @@ -73,8 +78,13 @@ |
| } |
| } |
| - frames_ += source_size; |
| - DCHECK_LE(frames_, max_frames()); |
| + // Ensure the data is *really* written before updating |frames_pushed_|. |
| + MemoryBarrier(); |
| + |
| + Atomic32 new_frames_pushed = frames_pushed_ + source_size; |
|
scherkus (not reviewing)
2012/09/17 14:51:17
is the intent of this change to make this class lo
Chris Rogers
2012/09/17 20:44:23
Added section in description about thread-safety.
|
| + NoBarrier_AtomicExchange(&frames_pushed_, new_frames_pushed); |
|
jbauman
2012/09/15 00:33:52
This (and the next one) should be NoBarrier_Store,
Chris Rogers
2012/09/17 20:44:23
Done.
|
| + |
| + DCHECK_LE(frames(), max_frames()); |
| write_pos_ = UpdatePos(write_pos_, source_size, max_frames()); |
| } |
| @@ -85,7 +95,7 @@ |
| DCHECK_EQ(destination->channels(), audio_bus_->channels()); |
| // It is not possible to ask for more data than what is available in the FIFO. |
| - CHECK_LE(frames_to_consume, frames_); |
| + CHECK_LE(frames_to_consume, frames()); |
| // A copy from the FIFO to |destination| will only be performed if the |
| // allocated memory in |destination| is sufficient. |
| @@ -113,12 +123,15 @@ |
| } |
| } |
| - frames_ -= frames_to_consume; |
| + Atomic32 new_frames_consumed = frames_consumed_ + frames_to_consume; |
| + NoBarrier_AtomicExchange(&frames_consumed_, new_frames_consumed); |
| + |
| read_pos_ = UpdatePos(read_pos_, frames_to_consume, max_frames()); |
| } |
| void AudioFifo::Clear() { |
|
no longer working on chromium
2012/09/17 20:47:46
when this Clear() is called? is there any potentia
Chris Rogers
2012/09/17 22:00:42
Yes there is, but I already mention in the comment
|
| - frames_ = 0; |
| + frames_pushed_ = 0; |
| + frames_consumed_ = 0; |
| read_pos_ = 0; |
| write_pos_ = 0; |
| } |