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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 if (frames_to_fill > 0) { | 177 if (frames_to_fill > 0) { |
178 DVLOG(1) << "Gap detected @ " << expected_timestamp.InMicroseconds() | 178 DVLOG(1) << "Gap detected @ " << expected_timestamp.InMicroseconds() |
179 << " us: " << delta.InMicroseconds() << " us"; | 179 << " us: " << delta.InMicroseconds() << " us"; |
180 | 180 |
181 // Create a buffer with enough silence samples to fill the gap and | 181 // Create a buffer with enough silence samples to fill the gap and |
182 // add it to the output buffer. | 182 // add it to the output buffer. |
183 scoped_refptr<AudioBuffer> gap = AudioBuffer::CreateEmptyBuffer( | 183 scoped_refptr<AudioBuffer> gap = AudioBuffer::CreateEmptyBuffer( |
184 input->channel_layout(), | 184 input->channel_layout(), |
| 185 input->channel_count(), |
185 input->sample_rate(), | 186 input->sample_rate(), |
186 frames_to_fill, | 187 frames_to_fill, |
187 expected_timestamp, | 188 expected_timestamp, |
188 output_timestamp_helper_.GetFrameDuration(frames_to_fill)); | 189 output_timestamp_helper_.GetFrameDuration(frames_to_fill)); |
189 AddOutputBuffer(gap); | 190 AddOutputBuffer(gap); |
190 | 191 |
191 // Add the input buffer now that the gap has been filled. | 192 // Add the input buffer now that the gap has been filled. |
192 AddOutputBuffer(input); | 193 AddOutputBuffer(input); |
193 return true; | 194 return true; |
194 } | 195 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 scoped_refptr<AudioBuffer> preroll = pre_splice_sanitizer_->GetNextBuffer(); | 427 scoped_refptr<AudioBuffer> preroll = pre_splice_sanitizer_->GetNextBuffer(); |
427 | 428 |
428 // We don't know the channel count until we see the first buffer, so wait | 429 // We don't know the channel count until we see the first buffer, so wait |
429 // until the first buffer to allocate the output AudioBus. | 430 // until the first buffer to allocate the output AudioBus. |
430 if (!output_bus) { | 431 if (!output_bus) { |
431 output_bus = | 432 output_bus = |
432 AudioBus::Create(preroll->channel_count(), frames_to_crossfade); | 433 AudioBus::Create(preroll->channel_count(), frames_to_crossfade); |
433 // Allocate output buffer for crossfade. | 434 // Allocate output buffer for crossfade. |
434 *crossfade_buffer = AudioBuffer::CreateBuffer(kSampleFormatPlanarF32, | 435 *crossfade_buffer = AudioBuffer::CreateBuffer(kSampleFormatPlanarF32, |
435 preroll->channel_layout(), | 436 preroll->channel_layout(), |
| 437 preroll->channel_count(), |
436 preroll->sample_rate(), | 438 preroll->sample_rate(), |
437 frames_to_crossfade); | 439 frames_to_crossfade); |
438 } | 440 } |
439 | 441 |
440 // There may be enough of a gap introduced during decoding such that an | 442 // There may be enough of a gap introduced during decoding such that an |
441 // entire buffer exists before the splice point. | 443 // entire buffer exists before the splice point. |
442 if (frames_before_splice >= preroll->frame_count()) { | 444 if (frames_before_splice >= preroll->frame_count()) { |
443 // Adjust the number of frames remaining before the splice. NOTE: This is | 445 // Adjust the number of frames remaining before the splice. NOTE: This is |
444 // safe since |pre_splice_sanitizer_| is a continuation of the timeline in | 446 // safe since |pre_splice_sanitizer_| is a continuation of the timeline in |
445 // |output_sanitizer_|. As such we're guaranteed there are no gaps or | 447 // |output_sanitizer_|. As such we're guaranteed there are no gaps or |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); | 529 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); |
528 CHECK(output_sanitizer_->AddInput(remainder)); | 530 CHECK(output_sanitizer_->AddInput(remainder)); |
529 } | 531 } |
530 | 532 |
531 // Transfer all remaining buffers out and reset once empty. | 533 // Transfer all remaining buffers out and reset once empty. |
532 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); | 534 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); |
533 post_splice_sanitizer_->Reset(); | 535 post_splice_sanitizer_->Reset(); |
534 } | 536 } |
535 | 537 |
536 } // namespace media | 538 } // namespace media |
OLD | NEW |