OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/audio/sounds/wav_audio_handler.h" | 5 #include "media/audio/sounds/wav_audio_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/sys_byteorder.h" | 12 #include "base/sys_byteorder.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 namespace { | 17 namespace { |
17 | 18 |
18 const char kChunkId[] = "RIFF"; | 19 const char kChunkId[] = "RIFF"; |
19 const char kFormat[] = "WAVE"; | 20 const char kFormat[] = "WAVE"; |
20 const char kFmtSubchunkId[] = "fmt "; | 21 const char kFmtSubchunkId[] = "fmt "; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 bits_per_sample_(bits_per_sample) { | 168 bits_per_sample_(bits_per_sample) { |
168 DCHECK_NE(num_channels_, 0u); | 169 DCHECK_NE(num_channels_, 0u); |
169 DCHECK_NE(sample_rate_, 0u); | 170 DCHECK_NE(sample_rate_, 0u); |
170 DCHECK_NE(bits_per_sample_, 0u); | 171 DCHECK_NE(bits_per_sample_, 0u); |
171 total_frames_ = data_.size() * 8 / num_channels_ / bits_per_sample_; | 172 total_frames_ = data_.size() * 8 / num_channels_ / bits_per_sample_; |
172 } | 173 } |
173 | 174 |
174 WavAudioHandler::~WavAudioHandler() {} | 175 WavAudioHandler::~WavAudioHandler() {} |
175 | 176 |
176 // static | 177 // static |
177 scoped_ptr<WavAudioHandler> WavAudioHandler::Create( | 178 std::unique_ptr<WavAudioHandler> WavAudioHandler::Create( |
178 const base::StringPiece wav_data) { | 179 const base::StringPiece wav_data) { |
179 WavAudioParameters params; | 180 WavAudioParameters params; |
180 base::StringPiece audio_data; | 181 base::StringPiece audio_data; |
181 | 182 |
182 // Attempt to parse the WAV data. | 183 // Attempt to parse the WAV data. |
183 if (!ParseWavData(wav_data, &audio_data, ¶ms)) | 184 if (!ParseWavData(wav_data, &audio_data, ¶ms)) |
184 return scoped_ptr<WavAudioHandler>(); | 185 return nullptr; |
185 | 186 |
186 return make_scoped_ptr(new WavAudioHandler(audio_data, params.num_channels, | 187 return base::WrapUnique(new WavAudioHandler(audio_data, params.num_channels, |
187 params.sample_rate, | 188 params.sample_rate, |
188 params.bits_per_sample)); | 189 params.bits_per_sample)); |
189 } | 190 } |
190 | 191 |
191 bool WavAudioHandler::AtEnd(size_t cursor) const { | 192 bool WavAudioHandler::AtEnd(size_t cursor) const { |
192 return data_.size() <= cursor; | 193 return data_.size() <= cursor; |
193 } | 194 } |
194 | 195 |
195 bool WavAudioHandler::CopyTo(AudioBus* bus, | 196 bool WavAudioHandler::CopyTo(AudioBus* bus, |
196 size_t cursor, | 197 size_t cursor, |
197 size_t* bytes_written) const { | 198 size_t* bytes_written) const { |
198 if (!bus) | 199 if (!bus) |
(...skipping 15 matching lines...) Expand all Loading... |
214 bus->ZeroFramesPartial(frames, bus->frames() - frames); | 215 bus->ZeroFramesPartial(frames, bus->frames() - frames); |
215 return true; | 216 return true; |
216 } | 217 } |
217 | 218 |
218 base::TimeDelta WavAudioHandler::GetDuration() const { | 219 base::TimeDelta WavAudioHandler::GetDuration() const { |
219 return base::TimeDelta::FromSecondsD(total_frames_ / | 220 return base::TimeDelta::FromSecondsD(total_frames_ / |
220 static_cast<double>(sample_rate_)); | 221 static_cast<double>(sample_rate_)); |
221 } | 222 } |
222 | 223 |
223 } // namespace media | 224 } // namespace media |
OLD | NEW |