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/filters/audio_renderer_algorithm.h" | 5 #include "media/filters/audio_renderer_algorithm.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 // is blocked for a significant amount of time, decoding can stall. By | 70 // is blocked for a significant amount of time, decoding can stall. By |
71 // maintaining a larger audio buffer we are more resilient to underflows | 71 // maintaining a larger audio buffer we are more resilient to underflows |
72 // caused by long running main thread tasks. | 72 // caused by long running main thread tasks. |
73 // TODO(watk,xhwang): Delete this when decrypting moves to the media thread | 73 // TODO(watk,xhwang): Delete this when decrypting moves to the media thread |
74 // (http://crbug.com/403462). | 74 // (http://crbug.com/403462). |
75 static const int kStartingCapacityForEncryptedInMs = 500; | 75 static const int kStartingCapacityForEncryptedInMs = 500; |
76 | 76 |
77 AudioRendererAlgorithm::AudioRendererAlgorithm() | 77 AudioRendererAlgorithm::AudioRendererAlgorithm() |
78 : channels_(0), | 78 : channels_(0), |
79 samples_per_second_(0), | 79 samples_per_second_(0), |
80 is_bitstream_format_(false), | |
80 muted_partial_frame_(0), | 81 muted_partial_frame_(0), |
81 capacity_(0), | 82 capacity_(0), |
82 output_time_(0.0), | 83 output_time_(0.0), |
83 search_block_center_offset_(0), | 84 search_block_center_offset_(0), |
84 search_block_index_(0), | 85 search_block_index_(0), |
85 num_candidate_blocks_(0), | 86 num_candidate_blocks_(0), |
86 target_block_index_(0), | 87 target_block_index_(0), |
87 ola_window_size_(0), | 88 ola_window_size_(0), |
88 ola_hop_size_(0), | 89 ola_hop_size_(0), |
89 num_complete_frames_(0), | 90 num_complete_frames_(0), |
90 initial_capacity_(0), | 91 initial_capacity_(0), |
91 max_capacity_(0) {} | 92 max_capacity_(0) {} |
92 | 93 |
93 AudioRendererAlgorithm::~AudioRendererAlgorithm() {} | 94 AudioRendererAlgorithm::~AudioRendererAlgorithm() {} |
94 | 95 |
95 void AudioRendererAlgorithm::Initialize(const AudioParameters& params, | 96 void AudioRendererAlgorithm::Initialize(const AudioParameters& params, |
96 bool is_encrypted) { | 97 bool is_encrypted) { |
97 CHECK(params.IsValid()); | 98 CHECK(params.IsValid()); |
98 | 99 |
99 channels_ = params.channels(); | 100 channels_ = params.channels(); |
100 samples_per_second_ = params.sample_rate(); | 101 samples_per_second_ = params.sample_rate(); |
102 is_bitstream_format_ = params.IsBitstreamFormat(); | |
101 initial_capacity_ = capacity_ = std::max( | 103 initial_capacity_ = capacity_ = std::max( |
102 params.frames_per_buffer() * 2, | 104 params.frames_per_buffer() * 2, |
103 ConvertMillisecondsToFrames(is_encrypted | 105 ConvertMillisecondsToFrames(is_encrypted |
104 ? kStartingCapacityForEncryptedInMs | 106 ? kStartingCapacityForEncryptedInMs |
105 : kStartingCapacityInMs)); | 107 : kStartingCapacityInMs)); |
106 max_capacity_ = | 108 max_capacity_ = |
107 std::max(initial_capacity_, kMaxCapacityInSeconds * samples_per_second_); | 109 std::max(initial_capacity_, kMaxCapacityInSeconds * samples_per_second_); |
108 num_candidate_blocks_ = ConvertMillisecondsToFrames(kWsolaSearchIntervalMs); | 110 num_candidate_blocks_ = ConvertMillisecondsToFrames(kWsolaSearchIntervalMs); |
109 ola_window_size_ = ConvertMillisecondsToFrames(kOlaWindowSizeMs); | 111 ola_window_size_ = ConvertMillisecondsToFrames(kOlaWindowSizeMs); |
110 | 112 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, | 152 int AudioRendererAlgorithm::FillBuffer(AudioBus* dest, |
151 int dest_offset, | 153 int dest_offset, |
152 int requested_frames, | 154 int requested_frames, |
153 double playback_rate) { | 155 double playback_rate) { |
154 if (playback_rate == 0) | 156 if (playback_rate == 0) |
155 return 0; | 157 return 0; |
156 | 158 |
157 DCHECK_GT(playback_rate, 0); | 159 DCHECK_GT(playback_rate, 0); |
158 DCHECK_EQ(channels_, dest->channels()); | 160 DCHECK_EQ(channels_, dest->channels()); |
159 | 161 |
162 dest->set_is_bitstream_format(is_bitstream_format_); | |
chcunningham
2017/06/14 20:03:08
this block too could use some documentation for fu
AndyWu
2017/08/02 01:43:41
Done.
| |
163 if (is_bitstream_format_) { | |
164 dest->set_data_size(0); | |
DaleCurtis
2017/06/15 21:46:32
Why?
AndyWu
2017/08/02 01:43:40
Removed.
| |
165 dest->set_frames(0); | |
166 | |
167 return audio_buffer_.ReadFrames(requested_frames, dest_offset, dest); | |
168 } | |
169 | |
160 // Optimize the muted case to issue a single clear instead of performing | 170 // Optimize the muted case to issue a single clear instead of performing |
161 // the full crossfade and clearing each crossfaded frame. | 171 // the full crossfade and clearing each crossfaded frame. |
162 if (playback_rate < kMinPlaybackRate || playback_rate > kMaxPlaybackRate) { | 172 if (playback_rate < kMinPlaybackRate || playback_rate > kMaxPlaybackRate) { |
163 int frames_to_render = | 173 int frames_to_render = |
164 std::min(static_cast<int>(audio_buffer_.frames() / playback_rate), | 174 std::min(static_cast<int>(audio_buffer_.frames() / playback_rate), |
165 requested_frames); | 175 requested_frames); |
166 | 176 |
167 // Compute accurate number of frames to actually skip in the source data. | 177 // Compute accurate number of frames to actually skip in the source data. |
168 // Includes the leftover partial frame from last request. However, we can | 178 // Includes the leftover partial frame from last request. However, we can |
169 // only skip over complete frames, so a partial frame may remain for next | 179 // only skip over complete frames, so a partial frame may remain for next |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 } | 458 } |
449 } | 459 } |
450 | 460 |
451 target_block_wrapper_ = | 461 target_block_wrapper_ = |
452 AudioBus::WrapVector(target_block_->frames(), active_target_channels); | 462 AudioBus::WrapVector(target_block_->frames(), active_target_channels); |
453 search_block_wrapper_ = | 463 search_block_wrapper_ = |
454 AudioBus::WrapVector(search_block_->frames(), active_search_channels); | 464 AudioBus::WrapVector(search_block_->frames(), active_search_channels); |
455 } | 465 } |
456 | 466 |
457 } // namespace media | 467 } // namespace media |
OLD | NEW |