| 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_bus.h" | 5 #include "media/base/audio_bus.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void AudioBus::CheckOverflow(int start_frame, int frames, int total_frames) { | 55 void AudioBus::CheckOverflow(int start_frame, int frames, int total_frames) { |
| 56 CHECK_GE(start_frame, 0); | 56 CHECK_GE(start_frame, 0); |
| 57 CHECK_GE(frames, 0); | 57 CHECK_GE(frames, 0); |
| 58 CHECK_GT(total_frames, 0); | 58 CHECK_GT(total_frames, 0); |
| 59 int sum = start_frame + frames; | 59 int sum = start_frame + frames; |
| 60 CHECK_LE(sum, total_frames); | 60 CHECK_LE(sum, total_frames); |
| 61 CHECK_GE(sum, 0); | 61 CHECK_GE(sum, 0); |
| 62 } | 62 } |
| 63 | 63 |
| 64 AudioBus::AudioBus(int channels, int frames) | 64 AudioBus::AudioBus(int channels, int frames) |
| 65 : frames_(frames), | 65 : data_size_(0), frames_(frames), can_set_channel_data_(false) { |
| 66 can_set_channel_data_(false) { | |
| 67 ValidateConfig(channels, frames_); | 66 ValidateConfig(channels, frames_); |
| 68 | 67 |
| 69 int aligned_frames = 0; | 68 int aligned_frames = 0; |
| 70 int size = CalculateMemorySizeInternal(channels, frames, &aligned_frames); | 69 data_size_ = CalculateMemorySizeInternal(channels, frames, &aligned_frames); |
| 71 | 70 |
| 72 data_.reset(static_cast<float*>(base::AlignedAlloc( | 71 data_.reset(static_cast<float*>( |
| 73 size, AudioBus::kChannelAlignment))); | 72 base::AlignedAlloc(data_size_, AudioBus::kChannelAlignment))); |
| 74 | 73 |
| 75 BuildChannelData(channels, aligned_frames, data_.get()); | 74 BuildChannelData(channels, aligned_frames, data_.get()); |
| 76 } | 75 } |
| 77 | 76 |
| 78 AudioBus::AudioBus(int channels, int frames, float* data) | 77 AudioBus::AudioBus(int channels, int frames, float* data) |
| 79 : frames_(frames), | 78 : data_size_(0), frames_(frames), can_set_channel_data_(false) { |
| 80 can_set_channel_data_(false) { | |
| 81 // Since |data| may have come from an external source, ensure it's valid. | 79 // Since |data| may have come from an external source, ensure it's valid. |
| 82 CHECK(data); | 80 CHECK(data); |
| 83 ValidateConfig(channels, frames_); | 81 ValidateConfig(channels, frames_); |
| 84 | 82 |
| 85 int aligned_frames = 0; | 83 int aligned_frames = 0; |
| 86 CalculateMemorySizeInternal(channels, frames, &aligned_frames); | 84 data_size_ = CalculateMemorySizeInternal(channels, frames, &aligned_frames); |
| 87 | 85 |
| 88 BuildChannelData(channels, aligned_frames, data); | 86 BuildChannelData(channels, aligned_frames, data); |
| 89 } | 87 } |
| 90 | 88 |
| 91 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) | 89 AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) |
| 92 : channel_data_(channel_data), | 90 : data_size_(0), |
| 91 channel_data_(channel_data), |
| 93 frames_(frames), | 92 frames_(frames), |
| 94 can_set_channel_data_(false) { | 93 can_set_channel_data_(false) { |
| 95 ValidateConfig( | 94 ValidateConfig( |
| 96 base::checked_cast<int>(channel_data_.size()), frames_); | 95 base::checked_cast<int>(channel_data_.size()), frames_); |
| 97 | 96 |
| 98 // Sanity check wrapped vector for alignment and channel count. | 97 // Sanity check wrapped vector for alignment and channel count. |
| 99 for (size_t i = 0; i < channel_data_.size(); ++i) | 98 for (size_t i = 0; i < channel_data_.size(); ++i) |
| 100 DCHECK(IsAligned(channel_data_[i])); | 99 DCHECK(IsAligned(channel_data_[i])); |
| 101 } | 100 } |
| 102 | 101 |
| 103 AudioBus::AudioBus(int channels) | 102 AudioBus::AudioBus(int channels) |
| 104 : channel_data_(channels), | 103 : data_size_(0), |
| 104 channel_data_(channels), |
| 105 frames_(0), | 105 frames_(0), |
| 106 can_set_channel_data_(true) { | 106 can_set_channel_data_(true) { |
| 107 CHECK_GT(channels, 0); | 107 CHECK_GT(channels, 0); |
| 108 for (size_t i = 0; i < channel_data_.size(); ++i) | 108 for (size_t i = 0; i < channel_data_.size(); ++i) |
| 109 channel_data_[i] = NULL; | 109 channel_data_[i] = NULL; |
| 110 } | 110 } |
| 111 | 111 |
| 112 AudioBus::~AudioBus() {} | 112 AudioBus::~AudioBus() {} |
| 113 | 113 |
| 114 std::unique_ptr<AudioBus> AudioBus::Create(int channels, int frames) { | 114 std::unique_ptr<AudioBus> AudioBus::Create(int channels, int frames) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return scoped_refptr<AudioBusRefCounted>( | 349 return scoped_refptr<AudioBusRefCounted>( |
| 350 new AudioBusRefCounted(channels, frames)); | 350 new AudioBusRefCounted(channels, frames)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 AudioBusRefCounted::AudioBusRefCounted(int channels, int frames) | 353 AudioBusRefCounted::AudioBusRefCounted(int channels, int frames) |
| 354 : AudioBus(channels, frames) {} | 354 : AudioBus(channels, frames) {} |
| 355 | 355 |
| 356 AudioBusRefCounted::~AudioBusRefCounted() {} | 356 AudioBusRefCounted::~AudioBusRefCounted() {} |
| 357 | 357 |
| 358 } // namespace media | 358 } // namespace media |
| OLD | NEW |