Chromium Code Reviews| Index: media/audio/sounds/wav_parser.cc |
| diff --git a/media/audio/sounds/wav_audio_handler.cc b/media/audio/sounds/wav_parser.cc |
| similarity index 71% |
| rename from media/audio/sounds/wav_audio_handler.cc |
| rename to media/audio/sounds/wav_parser.cc |
| index 20eab8be4377f908451905f53014326ca1994c03..409431ab9114d241d9ba4f8423ac1de720926dd8 100644 |
| --- a/media/audio/sounds/wav_audio_handler.cc |
| +++ b/media/audio/sounds/wav_parser.cc |
| @@ -2,14 +2,13 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "media/audio/sounds/wav_audio_handler.h" |
| +#include "media/audio/sounds/wav_parser.h" |
| #include <algorithm> |
| #include <cstring> |
| #include "base/logging.h" |
| #include "base/sys_byteorder.h" |
| -#include "media/base/audio_bus.h" |
| namespace { |
| @@ -40,7 +39,8 @@ const size_t kBitsPerSampleOffset = 14; |
| const int kAudioFormatPCM = 1; |
| // Reads an integer from |data| with |offset|. |
| -template<typename T> T ReadInt(const base::StringPiece& data, size_t offset) { |
| +template <typename T> |
| +T ReadInt(const base::StringPiece& data, size_t offset) { |
| CHECK_LE(offset + sizeof(T), data.size()); |
| T result; |
| memcpy(&result, data.data() + offset, sizeof(T)); |
| @@ -54,7 +54,7 @@ template<typename T> T ReadInt(const base::StringPiece& data, size_t offset) { |
| namespace media { |
| -WavAudioHandler::WavAudioHandler(const base::StringPiece& wav_data) |
| +WavParser::WavParser(const base::StringPiece& wav_data) |
| : num_channels_(0), |
| sample_rate_(0), |
| byte_rate_(0), |
|
DaleCurtis
2013/12/17 19:28:52
rename this to bytes_per_second_ or bytes_per_ms_
ygorshenin1
2013/12/18 14:33:12
After introduction of AudioParameters field these
|
| @@ -72,37 +72,16 @@ WavAudioHandler::WavAudioHandler(const base::StringPiece& wav_data) |
| CHECK_LE(0, length) << "can't parse wav sub-chunk"; |
| offset += length; |
| } |
| -} |
| - |
| -WavAudioHandler::~WavAudioHandler() { |
| -} |
| -bool WavAudioHandler::AtEnd(size_t cursor) const { |
| - return data_.size() <= cursor; |
| + const int64 size = data_.size(); |
| + const int64 rate = byte_rate_; |
| + if (rate) |
| + duration_ = base::TimeDelta::FromMicroseconds(size * 1000000 / rate); |
| } |
| -bool WavAudioHandler::CopyTo(AudioBus* bus, |
| - size_t cursor, |
| - size_t* bytes_written) const { |
| - if (!bus) |
| - return false; |
| - if (bus->channels() != num_channels_) { |
| - LOG(ERROR) << "Number of channel mismatch."; |
| - return false; |
| - } |
| - if (AtEnd(cursor)) { |
| - bus->Zero(); |
| - return true; |
| - } |
| - const int remaining_frames = (data_.size() - cursor) / bytes_per_frame_; |
| - const int frames = std::min(bus->frames(), remaining_frames); |
| - bus->FromInterleaved(data_.data() + cursor, frames, bytes_per_sample_); |
| - *bytes_written = frames * bytes_per_frame_; |
| - bus->ZeroFramesPartial(frames, bus->frames() - frames); |
| - return true; |
| -} |
| +WavParser::~WavParser() {} |
| -int WavAudioHandler::ParseSubChunk(const base::StringPiece& data) { |
| +int WavParser::ParseSubChunk(const base::StringPiece& data) { |
| if (data.size() < kChunkHeaderSize) |
| return data.size(); |
| uint32 chunk_length = ReadInt<uint32>(data, 4); |
| @@ -118,7 +97,7 @@ int WavAudioHandler::ParseSubChunk(const base::StringPiece& data) { |
| return chunk_length + kChunkHeaderSize; |
| } |
| -bool WavAudioHandler::ParseFmtChunk(const base::StringPiece& data) { |
| +bool WavParser::ParseFmtChunk(const base::StringPiece& data) { |
| if (data.size() < kFmtChunkMinimumSize) { |
| LOG(ERROR) << "Data size " << data.size() << " is too short."; |
| return false; |
| @@ -133,7 +112,7 @@ bool WavAudioHandler::ParseFmtChunk(const base::StringPiece& data) { |
| return true; |
| } |
| -bool WavAudioHandler::ParseDataChunk(const base::StringPiece& data) { |
| +bool WavParser::ParseDataChunk(const base::StringPiece& data) { |
| data_ = data; |
| return true; |
| } |