| 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 26 matching lines...) Expand all Loading... |
| 37 buffer->set_timestamp(timestamp_helper.GetTimestamp()); | 37 buffer->set_timestamp(timestamp_helper.GetTimestamp()); |
| 38 buffer->set_duration( | 38 buffer->set_duration( |
| 39 timestamp_helper.GetFrameDuration(buffer->frame_count())); | 39 timestamp_helper.GetFrameDuration(buffer->frame_count())); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // AudioBuffer::TrimEnd() is not as accurate as the timestamp helper, so | 42 // AudioBuffer::TrimEnd() is not as accurate as the timestamp helper, so |
| 43 // manually adjust the duration after trimming. | 43 // manually adjust the duration after trimming. |
| 44 static void AccurateTrimEnd(int frames_to_trim, | 44 static void AccurateTrimEnd(int frames_to_trim, |
| 45 const scoped_refptr<AudioBuffer> buffer, | 45 const scoped_refptr<AudioBuffer> buffer, |
| 46 const AudioTimestampHelper& timestamp_helper) { | 46 const AudioTimestampHelper& timestamp_helper) { |
| 47 DCHECK(buffer->timestamp() == timestamp_helper.GetTimestamp()); | 47 DCHECK_LT(std::abs(timestamp_helper.GetFramesToTarget(buffer->timestamp())), |
| 48 kMinGapSize); |
| 48 buffer->TrimEnd(frames_to_trim); | 49 buffer->TrimEnd(frames_to_trim); |
| 49 buffer->set_duration( | 50 buffer->set_duration( |
| 50 timestamp_helper.GetFrameDuration(buffer->frame_count())); | 51 timestamp_helper.GetFrameDuration(buffer->frame_count())); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Returns an AudioBus whose frame buffer is backed by the provided AudioBuffer. | 54 // Returns an AudioBus whose frame buffer is backed by the provided AudioBuffer. |
| 54 static scoped_ptr<AudioBus> CreateAudioBufferWrapper( | 55 static scoped_ptr<AudioBus> CreateAudioBufferWrapper( |
| 55 const scoped_refptr<AudioBuffer>& buffer) { | 56 const scoped_refptr<AudioBuffer>& buffer) { |
| 56 scoped_ptr<AudioBus> wrapper = | 57 scoped_ptr<AudioBus> wrapper = |
| 57 AudioBus::CreateWrapper(buffer->channel_count()); | 58 AudioBus::CreateWrapper(buffer->channel_count()); |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); | 511 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); |
| 511 CHECK(output_sanitizer_->AddInput(remainder)); | 512 CHECK(output_sanitizer_->AddInput(remainder)); |
| 512 } | 513 } |
| 513 | 514 |
| 514 // Transfer all remaining buffers out and reset once empty. | 515 // Transfer all remaining buffers out and reset once empty. |
| 515 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); | 516 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); |
| 516 post_splice_sanitizer_->Reset(); | 517 post_splice_sanitizer_->Reset(); |
| 517 } | 518 } |
| 518 | 519 |
| 519 } // namespace media | 520 } // namespace media |
| OLD | NEW |