| 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 #ifndef MEDIA_BASE_AUDIO_SPLICER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_SPLICER_H_ |
| 6 #define MEDIA_BASE_AUDIO_SPLICER_H_ | 6 #define MEDIA_BASE_AUDIO_SPLICER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "media/base/audio_parameters.h" | 13 #include "media/base/audio_parameters.h" |
| 13 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
| 14 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 class AudioBuffer; | 19 class AudioBuffer; |
| 19 class AudioBus; | 20 class AudioBus; |
| 20 class AudioStreamSanitizer; | 21 class AudioStreamSanitizer; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Extracts frames to be crossfaded from |pre_splice_sanitizer_|. Transfers | 72 // Extracts frames to be crossfaded from |pre_splice_sanitizer_|. Transfers |
| 72 // all frames before |splice_timestamp_| into |output_sanitizer_| and drops | 73 // all frames before |splice_timestamp_| into |output_sanitizer_| and drops |
| 73 // frames outside of the crossfade duration. | 74 // frames outside of the crossfade duration. |
| 74 // | 75 // |
| 75 // The size of the returned AudioBus is the crossfade duration in frames. | 76 // The size of the returned AudioBus is the crossfade duration in frames. |
| 76 // Crossfade duration is calculated based on the number of frames available | 77 // Crossfade duration is calculated based on the number of frames available |
| 77 // after |splice_timestamp_| in each sanitizer and capped by | 78 // after |splice_timestamp_| in each sanitizer and capped by |
| 78 // |max_crossfade_duration_|. | 79 // |max_crossfade_duration_|. |
| 79 // | 80 // |
| 80 // |pre_splice_sanitizer_| will be empty after this operation. | 81 // |pre_splice_sanitizer_| will be empty after this operation. |
| 81 scoped_ptr<AudioBus> ExtractCrossfadeFromPreSplice( | 82 std::unique_ptr<AudioBus> ExtractCrossfadeFromPreSplice( |
| 82 scoped_refptr<AudioBuffer>* crossfade_buffer); | 83 scoped_refptr<AudioBuffer>* crossfade_buffer); |
| 83 | 84 |
| 84 // Crossfades |pre_splice_bus->frames()| frames from | 85 // Crossfades |pre_splice_bus->frames()| frames from |
| 85 // |post_splice_sanitizer_| | 86 // |post_splice_sanitizer_| |
| 86 // with those from |pre_splice_bus|. Adds the crossfaded buffer to | 87 // with those from |pre_splice_bus|. Adds the crossfaded buffer to |
| 87 // |output_sanitizer_| along with all buffers in |post_splice_sanitizer_|. | 88 // |output_sanitizer_| along with all buffers in |post_splice_sanitizer_|. |
| 88 // | 89 // |
| 89 // |post_splice_sanitizer_| will be empty after this operation. | 90 // |post_splice_sanitizer_| will be empty after this operation. |
| 90 void CrossfadePostSplice(scoped_ptr<AudioBus> pre_splice_bus, | 91 void CrossfadePostSplice(std::unique_ptr<AudioBus> pre_splice_bus, |
| 91 const scoped_refptr<AudioBuffer>& crossfade_buffer); | 92 const scoped_refptr<AudioBuffer>& crossfade_buffer); |
| 92 | 93 |
| 93 // Reset the splice and splice end timestamps. | 94 // Reset the splice and splice end timestamps. |
| 94 void reset_splice_timestamps() { | 95 void reset_splice_timestamps() { |
| 95 splice_timestamp_ = max_splice_end_timestamp_ = kNoTimestamp(); | 96 splice_timestamp_ = max_splice_end_timestamp_ = kNoTimestamp(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 const base::TimeDelta max_crossfade_duration_; | 99 const base::TimeDelta max_crossfade_duration_; |
| 99 base::TimeDelta splice_timestamp_; | 100 base::TimeDelta splice_timestamp_; |
| 100 base::TimeDelta max_splice_end_timestamp_; | 101 base::TimeDelta max_splice_end_timestamp_; |
| 101 | 102 |
| 102 // The various sanitizers for each stage of the crossfade process. Buffers in | 103 // The various sanitizers for each stage of the crossfade process. Buffers in |
| 103 // |output_sanitizer_| are immediately available for consumption by external | 104 // |output_sanitizer_| are immediately available for consumption by external |
| 104 // callers. | 105 // callers. |
| 105 // | 106 // |
| 106 // Overlapped buffers go into the |pre_splice_sanitizer_| while overlapping | 107 // Overlapped buffers go into the |pre_splice_sanitizer_| while overlapping |
| 107 // buffers go into the |post_splice_sanitizer_|. Once enough buffers for | 108 // buffers go into the |post_splice_sanitizer_|. Once enough buffers for |
| 108 // crossfading are received the pre and post sanitizers are drained into | 109 // crossfading are received the pre and post sanitizers are drained into |
| 109 // |output_sanitizer_| by the two ExtractCrossfadeFromXXX methods above. | 110 // |output_sanitizer_| by the two ExtractCrossfadeFromXXX methods above. |
| 110 // | 111 // |
| 111 // |pre_splice_sanitizer_| is not constructed until the first splice frame is | 112 // |pre_splice_sanitizer_| is not constructed until the first splice frame is |
| 112 // encountered. At which point it is constructed based on the timestamp state | 113 // encountered. At which point it is constructed based on the timestamp state |
| 113 // of |output_sanitizer_|. It is destructed once the splice is finished. | 114 // of |output_sanitizer_|. It is destructed once the splice is finished. |
| 114 scoped_ptr<AudioStreamSanitizer> output_sanitizer_; | 115 std::unique_ptr<AudioStreamSanitizer> output_sanitizer_; |
| 115 scoped_ptr<AudioStreamSanitizer> pre_splice_sanitizer_; | 116 std::unique_ptr<AudioStreamSanitizer> pre_splice_sanitizer_; |
| 116 scoped_ptr<AudioStreamSanitizer> post_splice_sanitizer_; | 117 std::unique_ptr<AudioStreamSanitizer> post_splice_sanitizer_; |
| 117 | 118 |
| 118 // Whether all buffers which should go into |pre_splice_sanitizer_| have been | 119 // Whether all buffers which should go into |pre_splice_sanitizer_| have been |
| 119 // received. If true, buffers should now be put in |post_splice_sanitizer_|. | 120 // received. If true, buffers should now be put in |post_splice_sanitizer_|. |
| 120 bool have_all_pre_splice_buffers_; | 121 bool have_all_pre_splice_buffers_; |
| 121 | 122 |
| 122 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSplicer); | 123 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSplicer); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 } // namespace media | 126 } // namespace media |
| 126 | 127 |
| 127 #endif | 128 #endif |
| OLD | NEW |