| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "content/browser/speech/audio_encoder.h" | 5 #include "content/browser/speech/audio_encoder.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 | 175 |
| 176 AudioEncoder::AudioEncoder(const std::string& mime_type) | 176 AudioEncoder::AudioEncoder(const std::string& mime_type) |
| 177 : mime_type_(mime_type) { | 177 : mime_type_(mime_type) { |
| 178 } | 178 } |
| 179 | 179 |
| 180 AudioEncoder::~AudioEncoder() { | 180 AudioEncoder::~AudioEncoder() { |
| 181 STLDeleteElements(&audio_buffers_); | 181 STLDeleteElements(&audio_buffers_); |
| 182 } | 182 } |
| 183 | 183 |
| 184 bool AudioEncoder::GetEncodedData(std::string* encoded_data) { | 184 bool AudioEncoder::GetEncodedDataAndClear(std::string* encoded_data) { |
| 185 if (!audio_buffers_.size()) | 185 if (!audio_buffers_.size()) |
| 186 return false; | 186 return false; |
| 187 | 187 |
| 188 int audio_buffer_length = 0; | 188 int audio_buffer_length = 0; |
| 189 for (AudioBufferQueue::iterator it = audio_buffers_.begin(); | 189 for (AudioBufferQueue::iterator it = audio_buffers_.begin(); |
| 190 it != audio_buffers_.end(); ++it) { | 190 it != audio_buffers_.end(); ++it) { |
| 191 audio_buffer_length += (*it)->length(); | 191 audio_buffer_length += (*it)->length(); |
| 192 } | 192 } |
| 193 encoded_data->reserve(audio_buffer_length); | 193 encoded_data->reserve(audio_buffer_length); |
| 194 for (AudioBufferQueue::iterator it = audio_buffers_.begin(); | 194 for (AudioBufferQueue::iterator it = audio_buffers_.begin(); |
| 195 it != audio_buffers_.end(); ++it) { | 195 it != audio_buffers_.end(); ++it) { |
| 196 encoded_data->append(*(*it)); | 196 encoded_data->append(*(*it)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 STLDeleteElements(&audio_buffers_); |
| 200 |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 | 203 |
| 202 void AudioEncoder::AppendToBuffer(std::string* item) { | 204 void AudioEncoder::AppendToBuffer(std::string* item) { |
| 203 audio_buffers_.push_back(item); | 205 audio_buffers_.push_back(item); |
| 204 } | 206 } |
| 205 | 207 |
| 206 } // namespace speech_input | 208 } // namespace speech_input |
| OLD | NEW |