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 #include "media/base/audio_splicer.h" | 5 #include "media/base/audio_splicer.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 } | 207 } |
208 | 208 |
209 void AudioStreamSanitizer::AddOutputBuffer( | 209 void AudioStreamSanitizer::AddOutputBuffer( |
210 const scoped_refptr<AudioBuffer>& buffer) { | 210 const scoped_refptr<AudioBuffer>& buffer) { |
211 output_timestamp_helper_.AddFrames(buffer->frame_count()); | 211 output_timestamp_helper_.AddFrames(buffer->frame_count()); |
212 output_buffers_.push_back(buffer); | 212 output_buffers_.push_back(buffer); |
213 } | 213 } |
214 | 214 |
215 int AudioStreamSanitizer::GetFrameCount() const { | 215 int AudioStreamSanitizer::GetFrameCount() const { |
216 int frame_count = 0; | 216 int frame_count = 0; |
217 for (BufferQueue::const_iterator it = output_buffers_.begin(); | 217 for (const auto& buffer : output_buffers_) |
wolenetz
2014/09/26 01:22:31
aside ditto: (rietveld lint C++11 bug...)
"Storage
| |
218 it != output_buffers_.end(); ++it) { | 218 frame_count += buffer->frame_count(); |
219 frame_count += (*it)->frame_count(); | |
220 } | |
221 return frame_count; | 219 return frame_count; |
222 } | 220 } |
223 | 221 |
224 bool AudioStreamSanitizer::DrainInto(AudioStreamSanitizer* output) { | 222 bool AudioStreamSanitizer::DrainInto(AudioStreamSanitizer* output) { |
225 while (HasNextBuffer()) { | 223 while (HasNextBuffer()) { |
226 if (!output->AddInput(GetNextBuffer())) | 224 if (!output->AddInput(GetNextBuffer())) |
227 return false; | 225 return false; |
228 } | 226 } |
229 return true; | 227 return true; |
230 } | 228 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 442 |
445 // All necessary buffers have been processed, it's safe to reset. | 443 // All necessary buffers have been processed, it's safe to reset. |
446 pre_splice_sanitizer_->Reset(); | 444 pre_splice_sanitizer_->Reset(); |
447 DCHECK_EQ(output_bus->frames(), frames_read); | 445 DCHECK_EQ(output_bus->frames(), frames_read); |
448 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); | 446 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); |
449 return output_bus.Pass(); | 447 return output_bus.Pass(); |
450 } | 448 } |
451 | 449 |
452 void AudioSplicer::CrossfadePostSplice( | 450 void AudioSplicer::CrossfadePostSplice( |
453 scoped_ptr<AudioBus> pre_splice_bus, | 451 scoped_ptr<AudioBus> pre_splice_bus, |
454 scoped_refptr<AudioBuffer> crossfade_buffer) { | 452 const scoped_refptr<AudioBuffer>& crossfade_buffer) { |
455 // Use the calculated timestamp and duration to ensure there's no extra gaps | 453 // Use the calculated timestamp and duration to ensure there's no extra gaps |
456 // or overlaps to process when adding the buffer to |output_sanitizer_|. | 454 // or overlaps to process when adding the buffer to |output_sanitizer_|. |
457 const AudioTimestampHelper& output_ts_helper = | 455 const AudioTimestampHelper& output_ts_helper = |
458 output_sanitizer_->timestamp_helper(); | 456 output_sanitizer_->timestamp_helper(); |
459 crossfade_buffer->set_timestamp(output_ts_helper.GetTimestamp()); | 457 crossfade_buffer->set_timestamp(output_ts_helper.GetTimestamp()); |
460 | 458 |
461 // AudioBuffer::ReadFrames() only allows output into an AudioBus, so wrap | 459 // AudioBuffer::ReadFrames() only allows output into an AudioBus, so wrap |
462 // our AudioBuffer in one so we can avoid extra data copies. | 460 // our AudioBuffer in one so we can avoid extra data copies. |
463 scoped_ptr<AudioBus> output_bus = CreateAudioBufferWrapper(crossfade_buffer); | 461 scoped_ptr<AudioBus> output_bus = CreateAudioBufferWrapper(crossfade_buffer); |
464 | 462 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); | 498 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); |
501 CHECK(output_sanitizer_->AddInput(remainder)); | 499 CHECK(output_sanitizer_->AddInput(remainder)); |
502 } | 500 } |
503 | 501 |
504 // Transfer all remaining buffers out and reset once empty. | 502 // Transfer all remaining buffers out and reset once empty. |
505 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); | 503 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); |
506 post_splice_sanitizer_->Reset(); | 504 post_splice_sanitizer_->Reset(); |
507 } | 505 } |
508 | 506 |
509 } // namespace media | 507 } // namespace media |
OLD | NEW |