Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: components/audio_modem/audio_recorder_impl.cc

Issue 1921973002: Convert //components/[a-e]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/audio_modem/audio_recorder_impl.h" 5 #include "components/audio_modem/audio_recorder_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "components/audio_modem/public/audio_modem_types.h" 16 #include "components/audio_modem/public/audio_modem_types.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "media/audio/audio_manager.h" 18 #include "media/audio/audio_manager.h"
19 #include "media/audio/audio_manager_base.h" 19 #include "media/audio/audio_manager_base.h"
20 #include "media/base/audio_bus.h" 20 #include "media/base/audio_bus.h"
21 21
22 namespace audio_modem { 22 namespace audio_modem {
23 23
24 namespace { 24 namespace {
25 25
26 const float kProcessIntervalMs = 500.0f; // milliseconds. 26 const float kProcessIntervalMs = 500.0f; // milliseconds.
27 27
28 void AudioBusToString(scoped_ptr<media::AudioBus> source, std::string* buffer) { 28 void AudioBusToString(std::unique_ptr<media::AudioBus> source,
29 std::string* buffer) {
29 buffer->resize(source->frames() * source->channels() * sizeof(float)); 30 buffer->resize(source->frames() * source->channels() * sizeof(float));
30 float* buffer_view = reinterpret_cast<float*>(string_as_array(buffer)); 31 float* buffer_view = reinterpret_cast<float*>(string_as_array(buffer));
31 32
32 const int channels = source->channels(); 33 const int channels = source->channels();
33 for (int ch = 0; ch < channels; ++ch) { 34 for (int ch = 0; ch < channels; ++ch) {
34 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels) 35 for (int si = 0, di = ch; si < source->frames(); ++si, di += channels)
35 buffer_view[di] = source->channel(ch)[si]; 36 buffer_view[di] = source->channel(ch)[si];
36 } 37 }
37 } 38 }
38 39
39 // Called every kProcessIntervalMs to process the recorded audio. This 40 // Called every kProcessIntervalMs to process the recorded audio. This
40 // converts our samples to the required sample rate, interleaves the samples 41 // converts our samples to the required sample rate, interleaves the samples
41 // and sends them to the whispernet decoder to process. 42 // and sends them to the whispernet decoder to process.
42 void ProcessSamples( 43 void ProcessSamples(
43 scoped_ptr<media::AudioBus> bus, 44 std::unique_ptr<media::AudioBus> bus,
44 const AudioRecorderImpl::RecordedSamplesCallback& callback) { 45 const AudioRecorderImpl::RecordedSamplesCallback& callback) {
45 std::string samples; 46 std::string samples;
46 AudioBusToString(std::move(bus), &samples); 47 AudioBusToString(std::move(bus), &samples);
47 content::BrowserThread::PostTask( 48 content::BrowserThread::PostTask(
48 content::BrowserThread::UI, FROM_HERE, base::Bind(callback, samples)); 49 content::BrowserThread::UI, FROM_HERE, base::Bind(callback, samples));
49 } 50 }
50 51
51 } // namespace 52 } // namespace
52 53
53 // Public methods. 54 // Public methods.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 193
193 void AudioRecorderImpl::OnError(media::AudioInputStream* /* stream */) { 194 void AudioRecorderImpl::OnError(media::AudioInputStream* /* stream */) {
194 LOG(ERROR) << "Error during sound recording."; 195 LOG(ERROR) << "Error during sound recording.";
195 media::AudioManager::Get()->GetTaskRunner()->PostTask( 196 media::AudioManager::Get()->GetTaskRunner()->PostTask(
196 FROM_HERE, 197 FROM_HERE,
197 base::Bind(&AudioRecorderImpl::StopAndCloseOnAudioThread, 198 base::Bind(&AudioRecorderImpl::StopAndCloseOnAudioThread,
198 base::Unretained(this))); 199 base::Unretained(this)));
199 } 200 }
200 201
201 } // namespace audio_modem 202 } // namespace audio_modem
OLDNEW
« no previous file with comments | « components/audio_modem/audio_recorder_impl.h ('k') | components/audio_modem/audio_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698