OLD | NEW |
---|---|
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 Loading... | |
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()); |
DaleCurtis
2016/04/06 22:07:49
Hmm, this might be a bit dicy in the future since
alokp
2016/04/07 00:38:10
We have a DCHECK_EQ(0, num_input_streams_) in Audi
tommi (sloooow) - chröme
2016/04/07 14:33:40
What do you think about upgrading that to CHECK_EQ
DaleCurtis
2016/04/07 17:23:09
+1 I think we should do this, though it'll be hard
| |
72 // complete before returning. | 82 DVLOG(2) << "Destroying Java part of the audio manager"; |
73 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | 83 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(), |
74 &AudioManagerAndroid::ShutdownOnAudioThread, base::Unretained(this))); | 84 j_audio_manager_.obj()); |
75 Shutdown(); | 85 j_audio_manager_.Reset(); |
76 } | 86 } |
77 | 87 |
78 bool AudioManagerAndroid::HasAudioOutputDevices() { | 88 bool AudioManagerAndroid::HasAudioOutputDevices() { |
79 return true; | 89 return true; |
80 } | 90 } |
81 | 91 |
82 bool AudioManagerAndroid::HasAudioInputDevices() { | 92 bool AudioManagerAndroid::HasAudioInputDevices() { |
83 return true; | 93 return true; |
84 } | 94 } |
85 | 95 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 base::android::GetApplicationContext(), | 340 base::android::GetApplicationContext(), |
331 reinterpret_cast<intptr_t>(this))); | 341 reinterpret_cast<intptr_t>(this))); |
332 | 342 |
333 // Prepare the list of audio devices and register receivers for device | 343 // Prepare the list of audio devices and register receivers for device |
334 // notifications. | 344 // notifications. |
335 Java_AudioManagerAndroid_init( | 345 Java_AudioManagerAndroid_init( |
336 base::android::AttachCurrentThread(), | 346 base::android::AttachCurrentThread(), |
337 j_audio_manager_.obj()); | 347 j_audio_manager_.obj()); |
338 } | 348 } |
339 | 349 |
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) { | 350 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { |
350 Java_AudioManagerAndroid_setCommunicationAudioModeOn( | 351 Java_AudioManagerAndroid_setCommunicationAudioModeOn( |
351 base::android::AttachCurrentThread(), | 352 base::android::AttachCurrentThread(), |
352 j_audio_manager_.obj(), on); | 353 j_audio_manager_.obj(), on); |
353 } | 354 } |
354 | 355 |
355 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { | 356 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { |
356 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 357 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
357 | 358 |
358 // Send the unique device ID to the Java audio manager and make the | 359 // 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 Loading... | |
409 output_volume_override_ = volume; | 410 output_volume_override_ = volume; |
410 | 411 |
411 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 412 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
412 for (OutputStreams::iterator it = streams_.begin(); | 413 for (OutputStreams::iterator it = streams_.begin(); |
413 it != streams_.end(); ++it) { | 414 it != streams_.end(); ++it) { |
414 (*it)->SetVolume(volume); | 415 (*it)->SetVolume(volume); |
415 } | 416 } |
416 } | 417 } |
417 | 418 |
418 } // namespace media | 419 } // namespace media |
OLD | NEW |