OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "media/base/audio_block_fifo.h" | 5 #include "media/base/audio_block_fifo.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 while (frames_to_push) { | 37 while (frames_to_push) { |
38 // Get the current write block. | 38 // Get the current write block. |
39 AudioBus* current_block = audio_blocks_[write_block_]; | 39 AudioBus* current_block = audio_blocks_[write_block_]; |
40 | 40 |
41 // Figure out what segment sizes we need when adding the new content to | 41 // Figure out what segment sizes we need when adding the new content to |
42 // the FIFO. | 42 // the FIFO. |
43 const int push_frames = | 43 const int push_frames = |
44 std::min(block_frames_ - write_pos_, frames_to_push); | 44 std::min(block_frames_ - write_pos_, frames_to_push); |
45 | 45 |
46 // Deinterleave the content to the FIFO and update the |write_pos_|. | 46 // Deinterleave the content to the FIFO and update the |write_pos_|. |
47 current_block->FromInterleaved(source_ptr, push_frames, bytes_per_sample); | 47 current_block->FromInterleavedPartial( |
| 48 source_ptr, write_pos_, push_frames, bytes_per_sample); |
48 write_pos_ = (write_pos_ + push_frames) % block_frames_; | 49 write_pos_ = (write_pos_ + push_frames) % block_frames_; |
49 if (!write_pos_) { | 50 if (!write_pos_) { |
50 // The current block is completely filled, increment |write_block_| and | 51 // The current block is completely filled, increment |write_block_| and |
51 // |available_blocks_|. | 52 // |available_blocks_|. |
52 write_block_ = (write_block_ + 1) % audio_blocks_.size(); | 53 write_block_ = (write_block_ + 1) % audio_blocks_.size(); |
53 ++available_blocks_; | 54 ++available_blocks_; |
54 } | 55 } |
55 | 56 |
56 source_ptr += push_frames * bytes_per_sample * current_block->channels(); | 57 source_ptr += push_frames * bytes_per_sample * current_block->channels(); |
57 frames_to_push -= push_frames; | 58 frames_to_push -= push_frames; |
| 59 DCHECK_GE(frames_to_push, 0); |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
61 const AudioBus* AudioBlockFifo::Consume() { | 63 const AudioBus* AudioBlockFifo::Consume() { |
62 DCHECK(available_blocks_); | 64 DCHECK(available_blocks_); |
63 AudioBus* audio_bus = audio_blocks_[read_block_]; | 65 AudioBus* audio_bus = audio_blocks_[read_block_]; |
64 read_block_ = (read_block_ + 1) % audio_blocks_.size(); | 66 read_block_ = (read_block_ + 1) % audio_blocks_.size(); |
65 --available_blocks_; | 67 --available_blocks_; |
66 return audio_bus; | 68 return audio_bus; |
67 } | 69 } |
68 | 70 |
69 void AudioBlockFifo::Clear() { | 71 void AudioBlockFifo::Clear() { |
70 write_pos_ = 0; | 72 write_pos_ = 0; |
71 write_block_ = 0; | 73 write_block_ = 0; |
72 read_block_ = 0; | 74 read_block_ = 0; |
73 available_blocks_ = 0; | 75 available_blocks_ = 0; |
74 } | 76 } |
75 | 77 |
| 78 int AudioBlockFifo::GetAvailableFrames() const { |
| 79 return available_blocks_ * block_frames_ + write_pos_; |
| 80 } |
| 81 |
76 int AudioBlockFifo::GetUnfilledFrames() const { | 82 int AudioBlockFifo::GetUnfilledFrames() const { |
77 const int unfilled_frames = | 83 const int unfilled_frames = |
78 (audio_blocks_.size() - available_blocks_) * block_frames_ - write_pos_; | 84 (audio_blocks_.size() - available_blocks_) * block_frames_ - write_pos_; |
79 DCHECK_GE(unfilled_frames, 0); | 85 DCHECK_GE(unfilled_frames, 0); |
80 return unfilled_frames; | 86 return unfilled_frames; |
81 } | 87 } |
82 | 88 |
83 } // namespace media | 89 } // namespace media |
OLD | NEW |