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

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

Issue 1901583005: Revert of Pass task runners to AudioManager constructor. (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 (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 ScopedAudioManagerPtr CreateAudioManager( 48 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) {
49 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 49 return new AudioManagerAndroid(audio_log_factory);
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));
55 } 50 }
56 51
57 AudioManagerAndroid::AudioManagerAndroid( 52 AudioManagerAndroid::AudioManagerAndroid(AudioLogFactory* audio_log_factory)
58 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 53 : AudioManagerBase(audio_log_factory),
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),
64 communication_mode_is_on_(false), 54 communication_mode_is_on_(false),
65 output_volume_override_set_(false), 55 output_volume_override_set_(false),
66 output_volume_override_(0) { 56 output_volume_override_(0) {
67 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 57 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
68 58
69 // WARNING: This is executed on the UI loop, do not add any code here which 59 // WARNING: This is executed on the UI loop, do not add any code here which
70 // loads libraries or attempts to call out into the OS. Instead add such code 60 // loads libraries or attempts to call out into the OS. Instead add such code
71 // to the InitializeOnAudioThread() method below. 61 // to the InitializeOnAudioThread() method below.
72 62
73 // Task must be posted last to avoid races from handing out "this" to the 63 // Task must be posted last to avoid races from handing out "this" to the
74 // audio thread. 64 // audio thread.
75 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( 65 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
76 &AudioManagerAndroid::InitializeOnAudioThread, 66 &AudioManagerAndroid::InitializeOnAudioThread,
77 base::Unretained(this))); 67 base::Unretained(this)));
78 } 68 }
79 69
80 AudioManagerAndroid::~AudioManagerAndroid() { 70 AudioManagerAndroid::~AudioManagerAndroid() {
81 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 71 // It's safe to post a task here since Shutdown() will wait for all tasks to
72 // complete before returning.
73 GetTaskRunner()->PostTask(FROM_HERE, base::Bind(
74 &AudioManagerAndroid::ShutdownOnAudioThread, base::Unretained(this)));
82 Shutdown(); 75 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();
88 } 76 }
89 77
90 bool AudioManagerAndroid::HasAudioOutputDevices() { 78 bool AudioManagerAndroid::HasAudioOutputDevices() {
91 return true; 79 return true;
92 } 80 }
93 81
94 bool AudioManagerAndroid::HasAudioInputDevices() { 82 bool AudioManagerAndroid::HasAudioInputDevices() {
95 return true; 83 return true;
96 } 84 }
97 85
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 base::android::GetApplicationContext(), 330 base::android::GetApplicationContext(),
343 reinterpret_cast<intptr_t>(this))); 331 reinterpret_cast<intptr_t>(this)));
344 332
345 // Prepare the list of audio devices and register receivers for device 333 // Prepare the list of audio devices and register receivers for device
346 // notifications. 334 // notifications.
347 Java_AudioManagerAndroid_init( 335 Java_AudioManagerAndroid_init(
348 base::android::AttachCurrentThread(), 336 base::android::AttachCurrentThread(),
349 j_audio_manager_.obj()); 337 j_audio_manager_.obj());
350 } 338 }
351 339
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
352 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { 349 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) {
353 Java_AudioManagerAndroid_setCommunicationAudioModeOn( 350 Java_AudioManagerAndroid_setCommunicationAudioModeOn(
354 base::android::AttachCurrentThread(), 351 base::android::AttachCurrentThread(),
355 j_audio_manager_.obj(), on); 352 j_audio_manager_.obj(), on);
356 } 353 }
357 354
358 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { 355 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) {
359 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 356 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
360 357
361 // Send the unique device ID to the Java audio manager and make the 358 // 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
412 output_volume_override_ = volume; 409 output_volume_override_ = volume;
413 410
414 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 411 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
415 for (OutputStreams::iterator it = streams_.begin(); 412 for (OutputStreams::iterator it = streams_.begin();
416 it != streams_.end(); ++it) { 413 it != streams_.end(); ++it) {
417 (*it)->SetVolume(volume); 414 (*it)->SetVolume(volume);
418 } 415 }
419 } 416 }
420 417
421 } // namespace media 418 } // 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