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

Side by Side Diff: media/audio/audio_system_impl.cc

Issue 2675713002: Switch Speech Recognition to asynchronous callback-based AudioManager interactions. (Closed)
Patch Set: another rebase! Created 3 years, 10 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/audio_system_impl.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/task_runner_util.h"
10 #include "media/audio/audio_manager.h"
11
12 // Using base::Unretained for |audio_manager_| is safe since it is deleted after
13 // its task runner, and AudioSystemImpl is deleted on the UI thread after the IO
14 // thread has been stopped and before |audio_manager_| deletion is scheduled.
15 namespace media {
16
17 namespace {
18
19 AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager,
20 const std::string& device_id) {
21 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread());
22
23 // TODO(olka) : remove this when AudioManager::GetInputStreamParameters()
tommi (sloooow) - chröme 2017/02/05 20:14:54 nit: TODO(foo):
o1ka 2017/02/06 12:06:08 Done.
24 // works this way on all the platforms.
25 if (!audio_manager->HasAudioInputDevices())
26 return AudioParameters();
27
28 return audio_manager->GetInputStreamParameters(device_id);
29 }
30
31 } // namespace
32
33 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager)
34 : audio_manager_(audio_manager) {
35 DCHECK(audio_manager_);
36 }
37
38 AudioSystemImpl::~AudioSystemImpl() {}
39
40 // static
41 std::unique_ptr<AudioSystem> AudioSystemImpl::Create(
42 AudioManager* audio_manager) {
43 return base::WrapUnique(new AudioSystemImpl(audio_manager));
44 }
45
46 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const {
47 return audio_manager_->GetTaskRunner();
48 }
49
50 void AudioSystemImpl::GetInputStreamParameters(
tommi (sloooow) - chröme 2017/02/05 20:14:54 is it the intent that this method can be called on
o1ka 2017/02/06 12:06:08 Yes, it can be called from UI and IO threads, and
51 const std::string& device_id,
52 OnAudioParamsCallback on_params_cb) {
53 if (GetTaskRunner()->BelongsToCurrentThread()) {
54 GetTaskRunner()->PostTask(
55 FROM_HERE, base::Bind(on_params_cb, GetInputParametersOnDeviceThread(
56 audio_manager_, device_id)));
57 return;
58 }
59 base::PostTaskAndReplyWithResult(
60 GetTaskRunner(), FROM_HERE,
61 base::Bind(&GetInputParametersOnDeviceThread,
62 base::Unretained(audio_manager_), device_id),
63 std::move(on_params_cb));
64 }
65
66 AudioManager* AudioSystemImpl::GetAudioManager() {
67 return audio_manager_;
68 }
69
70 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698