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 <stdint.h> | 7 #include <stdint.h> |
8 | |
9 #include <cstdlib> | 8 #include <cstdlib> |
10 #include <deque> | 9 #include <deque> |
| 10 #include <utility> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "media/base/audio_buffer.h" | 14 #include "media/base/audio_buffer.h" |
15 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
16 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/audio_timestamp_helper.h" | 17 #include "media/base/audio_timestamp_helper.h" |
18 #include "media/base/media_log.h" | 18 #include "media/base/media_log.h" |
19 #include "media/base/vector_math.h" | 19 #include "media/base/vector_math.h" |
20 | 20 |
(...skipping 28 matching lines...) Expand all Loading... |
49 // Returns an AudioBus whose frame buffer is backed by the provided AudioBuffer. | 49 // Returns an AudioBus whose frame buffer is backed by the provided AudioBuffer. |
50 scoped_ptr<AudioBus> CreateAudioBufferWrapper( | 50 scoped_ptr<AudioBus> CreateAudioBufferWrapper( |
51 const scoped_refptr<AudioBuffer>& buffer) { | 51 const scoped_refptr<AudioBuffer>& buffer) { |
52 scoped_ptr<AudioBus> wrapper = | 52 scoped_ptr<AudioBus> wrapper = |
53 AudioBus::CreateWrapper(buffer->channel_count()); | 53 AudioBus::CreateWrapper(buffer->channel_count()); |
54 wrapper->set_frames(buffer->frame_count()); | 54 wrapper->set_frames(buffer->frame_count()); |
55 for (int ch = 0; ch < buffer->channel_count(); ++ch) { | 55 for (int ch = 0; ch < buffer->channel_count(); ++ch) { |
56 wrapper->SetChannelData( | 56 wrapper->SetChannelData( |
57 ch, reinterpret_cast<float*>(buffer->channel_data()[ch])); | 57 ch, reinterpret_cast<float*>(buffer->channel_data()[ch])); |
58 } | 58 } |
59 return wrapper.Pass(); | 59 return wrapper; |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 class AudioStreamSanitizer { | 64 class AudioStreamSanitizer { |
65 public: | 65 public: |
66 AudioStreamSanitizer(int samples_per_second, | 66 AudioStreamSanitizer(int samples_per_second, |
67 const scoped_refptr<MediaLog>& media_log); | 67 const scoped_refptr<MediaLog>& media_log); |
68 ~AudioStreamSanitizer(); | 68 ~AudioStreamSanitizer(); |
69 | 69 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 input->timestamp() + input->duration() < max_splice_end_timestamp_) { | 373 input->timestamp() + input->duration() < max_splice_end_timestamp_) { |
374 return true; | 374 return true; |
375 } | 375 } |
376 | 376 |
377 scoped_refptr<AudioBuffer> crossfade_buffer; | 377 scoped_refptr<AudioBuffer> crossfade_buffer; |
378 scoped_ptr<AudioBus> pre_splice = | 378 scoped_ptr<AudioBus> pre_splice = |
379 ExtractCrossfadeFromPreSplice(&crossfade_buffer); | 379 ExtractCrossfadeFromPreSplice(&crossfade_buffer); |
380 | 380 |
381 // Crossfade the pre splice and post splice sections and transfer all relevant | 381 // Crossfade the pre splice and post splice sections and transfer all relevant |
382 // buffers into |output_sanitizer_|. | 382 // buffers into |output_sanitizer_|. |
383 CrossfadePostSplice(pre_splice.Pass(), crossfade_buffer); | 383 CrossfadePostSplice(std::move(pre_splice), crossfade_buffer); |
384 | 384 |
385 // Clear the splice timestamp so new splices can be accepted. | 385 // Clear the splice timestamp so new splices can be accepted. |
386 reset_splice_timestamps(); | 386 reset_splice_timestamps(); |
387 return true; | 387 return true; |
388 } | 388 } |
389 | 389 |
390 bool AudioSplicer::HasNextBuffer() const { | 390 bool AudioSplicer::HasNextBuffer() const { |
391 return output_sanitizer_->HasNextBuffer(); | 391 return output_sanitizer_->HasNextBuffer(); |
392 } | 392 } |
393 | 393 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // Ensure outputs were properly allocated. The method should not have been | 490 // Ensure outputs were properly allocated. The method should not have been |
491 // called if there is not enough data to crossfade. | 491 // called if there is not enough data to crossfade. |
492 // TODO(dalecurtis): Convert to DCHECK() once http://crbug.com/356073 fixed. | 492 // TODO(dalecurtis): Convert to DCHECK() once http://crbug.com/356073 fixed. |
493 CHECK(output_bus); | 493 CHECK(output_bus); |
494 CHECK(crossfade_buffer->get()); | 494 CHECK(crossfade_buffer->get()); |
495 | 495 |
496 // All necessary buffers have been processed, it's safe to reset. | 496 // All necessary buffers have been processed, it's safe to reset. |
497 pre_splice_sanitizer_->Reset(); | 497 pre_splice_sanitizer_->Reset(); |
498 DCHECK_EQ(output_bus->frames(), frames_read); | 498 DCHECK_EQ(output_bus->frames(), frames_read); |
499 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); | 499 DCHECK_EQ(output_ts_helper.GetFramesToTarget(splice_timestamp_), 0); |
500 return output_bus.Pass(); | 500 return output_bus; |
501 } | 501 } |
502 | 502 |
503 void AudioSplicer::CrossfadePostSplice( | 503 void AudioSplicer::CrossfadePostSplice( |
504 scoped_ptr<AudioBus> pre_splice_bus, | 504 scoped_ptr<AudioBus> pre_splice_bus, |
505 const scoped_refptr<AudioBuffer>& crossfade_buffer) { | 505 const scoped_refptr<AudioBuffer>& crossfade_buffer) { |
506 // Use the calculated timestamp and duration to ensure there's no extra gaps | 506 // Use the calculated timestamp and duration to ensure there's no extra gaps |
507 // or overlaps to process when adding the buffer to |output_sanitizer_|. | 507 // or overlaps to process when adding the buffer to |output_sanitizer_|. |
508 const AudioTimestampHelper& output_ts_helper = | 508 const AudioTimestampHelper& output_ts_helper = |
509 output_sanitizer_->timestamp_helper(); | 509 output_sanitizer_->timestamp_helper(); |
510 crossfade_buffer->set_timestamp(output_ts_helper.GetTimestamp()); | 510 crossfade_buffer->set_timestamp(output_ts_helper.GetTimestamp()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); | 551 AccurateTrimStart(frames_to_trim, remainder, output_ts_helper); |
552 CHECK(output_sanitizer_->AddInput(remainder)); | 552 CHECK(output_sanitizer_->AddInput(remainder)); |
553 } | 553 } |
554 | 554 |
555 // Transfer all remaining buffers out and reset once empty. | 555 // Transfer all remaining buffers out and reset once empty. |
556 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); | 556 CHECK(post_splice_sanitizer_->DrainInto(output_sanitizer_.get())); |
557 post_splice_sanitizer_->Reset(); | 557 post_splice_sanitizer_->Reset(); |
558 } | 558 } |
559 | 559 |
560 } // namespace media | 560 } // namespace media |
OLD | NEW |