| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 preroll->TrimEnd(preroll->frame_count() - frames_before_splice); | 433 preroll->TrimEnd(preroll->frame_count() - frames_before_splice); |
| 434 CHECK(output_sanitizer_->AddInput(preroll)); | 434 CHECK(output_sanitizer_->AddInput(preroll)); |
| 435 frames_before_splice = 0; | 435 frames_before_splice = 0; |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Ensure outputs were properly allocated. The method should not have been | 439 // Ensure outputs were properly allocated. The method should not have been |
| 440 // called if there is not enough data to crossfade. | 440 // called if there is not enough data to crossfade. |
| 441 // TODO(dalecurtis): Convert to DCHECK() once http://crbug.com/356073 fixed. | 441 // TODO(dalecurtis): Convert to DCHECK() once http://crbug.com/356073 fixed. |
| 442 CHECK(output_bus); | 442 CHECK(output_bus); |
| 443 CHECK(*crossfade_buffer); | 443 CHECK(crossfade_buffer->get()); |
| 444 | 444 |
| 445 // All necessary buffers have been processed, it's safe to reset. | 445 // All necessary buffers have been processed, it's safe to reset. |
| 446 pre_splice_sanitizer_->Reset(); | 446 pre_splice_sanitizer_->Reset(); |
| 447 DCHECK_EQ(output_bus->frames(), frames_read); | 447 DCHECK_EQ(output_bus->frames(), frames_read); |
| 448 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); | 448 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); |
| 449 return output_bus.Pass(); | 449 return output_bus.Pass(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void AudioSplicer::CrossfadePostSplice( | 452 void AudioSplicer::CrossfadePostSplice( |
| 453 scoped_ptr<AudioBus> pre_splice_bus, | 453 scoped_ptr<AudioBus> pre_splice_bus, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 470 scoped_refptr<AudioBuffer> postroll = | 470 scoped_refptr<AudioBuffer> postroll = |
| 471 post_splice_sanitizer_->GetNextBuffer(); | 471 post_splice_sanitizer_->GetNextBuffer(); |
| 472 const int frames_to_read = | 472 const int frames_to_read = |
| 473 std::min(postroll->frame_count(), output_bus->frames() - frames_read); | 473 std::min(postroll->frame_count(), output_bus->frames() - frames_read); |
| 474 postroll->ReadFrames(frames_to_read, 0, frames_read, output_bus.get()); | 474 postroll->ReadFrames(frames_to_read, 0, frames_read, output_bus.get()); |
| 475 frames_read += frames_to_read; | 475 frames_read += frames_to_read; |
| 476 | 476 |
| 477 // If only part of the buffer was consumed, save it for after we've added | 477 // If only part of the buffer was consumed, save it for after we've added |
| 478 // the crossfade buffer | 478 // the crossfade buffer |
| 479 if (frames_to_read < postroll->frame_count()) { | 479 if (frames_to_read < postroll->frame_count()) { |
| 480 DCHECK(!remainder); | 480 DCHECK(!remainder.get()); |
| 481 remainder.swap(postroll); | 481 remainder.swap(postroll); |
| 482 frames_to_trim = frames_to_read; | 482 frames_to_trim = frames_to_read; |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 DCHECK_EQ(output_bus->frames(), frames_read); | 486 DCHECK_EQ(output_bus->frames(), frames_read); |
| 487 | 487 |
| 488 // Crossfade the audio into |crossfade_buffer|. | 488 // Crossfade the audio into |crossfade_buffer|. |
| 489 for (int ch = 0; ch < output_bus->channels(); ++ch) { | 489 for (int ch = 0; ch < output_bus->channels(); ++ch) { |
| 490 vector_math::Crossfade(pre_splice_bus->channel(ch), | 490 vector_math::Crossfade(pre_splice_bus->channel(ch), |
| 491 pre_splice_bus->frames(), | 491 pre_splice_bus->frames(), |
| 492 output_bus->channel(ch)); | 492 output_bus->channel(ch)); |
| 493 } | 493 } |
| 494 | 494 |
| 495 CHECK(output_sanitizer_->AddInput(crossfade_buffer)); | 495 CHECK(output_sanitizer_->AddInput(crossfade_buffer)); |
| 496 DCHECK_EQ(crossfade_buffer->frame_count(), output_bus->frames()); | 496 DCHECK_EQ(crossfade_buffer->frame_count(), output_bus->frames()); |
| 497 | 497 |
| 498 if (remainder) { | 498 if (remainder.get()) { |
| 499 // Trim off consumed frames. | 499 // Trim off consumed frames. |
| 500 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); | 500 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); |
| 501 CHECK(output_sanitizer_->AddInput(remainder)); | 501 CHECK(output_sanitizer_->AddInput(remainder)); |
| 502 } | 502 } |
| 503 | 503 |
| 504 // Transfer all remaining buffers out and reset once empty. | 504 // Transfer all remaining buffers out and reset once empty. |
| 505 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); | 505 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); |
| 506 post_splice_sanitizer_->Reset(); | 506 post_splice_sanitizer_->Reset(); |
| 507 } | 507 } |
| 508 | 508 |
| 509 } // namespace media | 509 } // namespace media |
| OLD | NEW |