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

Side by Side Diff: media/audio/android/audio_manager_android.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from patch 48 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/android/audio_manager_android.h" 5 #include "media/audio/android/audio_manager_android.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/context_utils.h" 8 #include "base/android/context_utils.h"
9 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 27 matching lines...) Expand all
38 } 38 }
39 39
40 // Maximum number of output streams that can be open simultaneously. 40 // Maximum number of output streams that can be open simultaneously.
41 const int kMaxOutputStreams = 10; 41 const int kMaxOutputStreams = 10;
42 42
43 const int kDefaultInputBufferSize = 1024; 43 const int kDefaultInputBufferSize = 1024;
44 const int kDefaultOutputBufferSize = 2048; 44 const int kDefaultOutputBufferSize = 2048;
45 45
46 } // namespace 46 } // namespace
47 47
48 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { 48 ScopedAudioManagerPtr CreateAudioManager(
49 return new AudioManagerAndroid(audio_log_factory); 49 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
50 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
51 AudioLogFactory* audio_log_factory) {
52 return ScopedAudioManagerPtr(new AudioManagerAndroid(
53 std::move(task_runner), std::move(worker_task_runner),
54 audio_log_factory));
50 } 55 }
51 56
52 AudioManagerAndroid::AudioManagerAndroid(AudioLogFactory* audio_log_factory) 57 AudioManagerAndroid::AudioManagerAndroid(
53 : AudioManagerBase(audio_log_factory), 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
59 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
60 AudioLogFactory* audio_log_factory)
61 : AudioManagerBase(std::move(task_runner),
62 std::move(worker_task_runner),
63 audio_log_factory),
54 communication_mode_is_on_(false), 64 communication_mode_is_on_(false),
55 output_volume_override_set_(false), 65 output_volume_override_set_(false),
56 output_volume_override_(0) { 66 output_volume_override_(0) {
57 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 67 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
58 68
59 // WARNING: This is executed on the UI loop, do not add any code here which 69 // WARNING: This is executed on the UI loop, do not add any code here which
60 // loads libraries or attempts to call out into the OS. Instead add such code 70 // loads libraries or attempts to call out into the OS. Instead add such code
61 // to the InitializeOnAudioThread() method below. 71 // to the InitializeOnAudioThread() method below.
62 72
63 // Task must be posted last to avoid races from handing out "this" to the 73 // Task must be posted last to avoid races from handing out "this" to the
64 // audio thread. 74 // audio thread.
65 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 75 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
66 &AudioManagerAndroid::InitializeOnAudioThread, 76 &AudioManagerAndroid::InitializeOnAudioThread,
67 base::Unretained(this))); 77 base::Unretained(this)));
68 } 78 }
69 79
70 AudioManagerAndroid::~AudioManagerAndroid() { 80 AudioManagerAndroid::~AudioManagerAndroid() {
71 // It's safe to post a task here since Shutdown() will wait for all tasks to 81 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
72 // complete before returning.
73 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
74 &AudioManagerAndroid::ShutdownOnAudioThread, base::Unretained(this)));
75 Shutdown(); 82 Shutdown();
83
84 DVLOG(2) << "Destroying Java part of the audio manager";
85 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(),
86 j_audio_manager_.obj());
87 j_audio_manager_.Reset();
76 } 88 }
77 89
78 bool AudioManagerAndroid::HasAudioOutputDevices() { 90 bool AudioManagerAndroid::HasAudioOutputDevices() {
79 return true; 91 return true;
80 } 92 }
81 93
82 bool AudioManagerAndroid::HasAudioInputDevices() { 94 bool AudioManagerAndroid::HasAudioInputDevices() {
83 return true; 95 return true;
84 } 96 }
85 97
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 base::android::GetApplicationContext(), 342 base::android::GetApplicationContext(),
331 reinterpret_cast<intptr_t>(this))); 343 reinterpret_cast<intptr_t>(this)));
332 344
333 // Prepare the list of audio devices and register receivers for device 345 // Prepare the list of audio devices and register receivers for device
334 // notifications. 346 // notifications.
335 Java_AudioManagerAndroid_init( 347 Java_AudioManagerAndroid_init(
336 base::android::AttachCurrentThread(), 348 base::android::AttachCurrentThread(),
337 j_audio_manager_.obj()); 349 j_audio_manager_.obj());
338 } 350 }
339 351
340 void AudioManagerAndroid::ShutdownOnAudioThread() {
341 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
342 DVLOG(2) << "Destroying Java part of the audio manager";
343 Java_AudioManagerAndroid_close(
344 base::android::AttachCurrentThread(),
345 j_audio_manager_.obj());
346 j_audio_manager_.Reset();
347 }
348
349 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { 352 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) {
350 Java_AudioManagerAndroid_setCommunicationAudioModeOn( 353 Java_AudioManagerAndroid_setCommunicationAudioModeOn(
351 base::android::AttachCurrentThread(), 354 base::android::AttachCurrentThread(),
352 j_audio_manager_.obj(), on); 355 j_audio_manager_.obj(), on);
353 } 356 }
354 357
355 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { 358 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) {
356 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 359 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
357 360
358 // Send the unique device ID to the Java audio manager and make the 361 // Send the unique device ID to the Java audio manager and make the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 output_volume_override_ = volume; 412 output_volume_override_ = volume;
410 413
411 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 414 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
412 for (OutputStreams::iterator it = streams_.begin(); 415 for (OutputStreams::iterator it = streams_.begin();
413 it != streams_.end(); ++it) { 416 it != streams_.end(); ++it) {
414 (*it)->SetVolume(volume); 417 (*it)->SetVolume(volume);
415 } 418 }
416 } 419 }
417 420
418 } // namespace media 421 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/android/audio_manager_android.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698