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

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

Issue 131503006: Initialization of audio manager for Android is now done on the audio thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now passes findbugs Created 6 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 | Annotate | Revision Log
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 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 5 #ifndef MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 6 #define MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/synchronization/waitable_event.h"
13 #include "media/audio/audio_manager_base.h" 15 #include "media/audio/audio_manager_base.h"
14 16
15 namespace media { 17 namespace media {
16 18
17 class OpenSLESOutputStream; 19 class OpenSLESOutputStream;
18 20
19 // Android implemention of AudioManager. 21 // Android implemention of AudioManager.
20 class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase { 22 class MEDIA_EXPORT AudioManagerAndroid
23 : public AudioManagerBase,
24 public base::MessageLoop::DestructionObserver {
21 public: 25 public:
22 AudioManagerAndroid(AudioLogFactory* audio_log_factory); 26 AudioManagerAndroid(AudioLogFactory* audio_log_factory);
23 27
24 // Implementation of AudioManager. 28 // Implementation of AudioManager.
25 virtual bool HasAudioOutputDevices() OVERRIDE; 29 virtual bool HasAudioOutputDevices() OVERRIDE;
26 virtual bool HasAudioInputDevices() OVERRIDE; 30 virtual bool HasAudioInputDevices() OVERRIDE;
27 virtual void GetAudioInputDeviceNames( 31 virtual void GetAudioInputDeviceNames(
28 AudioDeviceNames* device_names) OVERRIDE; 32 AudioDeviceNames* device_names) OVERRIDE;
29 virtual void GetAudioOutputDeviceNames( 33 virtual void GetAudioOutputDeviceNames(
30 AudioDeviceNames* device_names) OVERRIDE; 34 AudioDeviceNames* device_names) OVERRIDE;
(...skipping 17 matching lines...) Expand all
48 const AudioParameters& params, 52 const AudioParameters& params,
49 const std::string& device_id, 53 const std::string& device_id,
50 const std::string& input_device_id) OVERRIDE; 54 const std::string& input_device_id) OVERRIDE;
51 virtual AudioInputStream* MakeLinearInputStream( 55 virtual AudioInputStream* MakeLinearInputStream(
52 const AudioParameters& params, 56 const AudioParameters& params,
53 const std::string& device_id) OVERRIDE; 57 const std::string& device_id) OVERRIDE;
54 virtual AudioInputStream* MakeLowLatencyInputStream( 58 virtual AudioInputStream* MakeLowLatencyInputStream(
55 const AudioParameters& params, 59 const AudioParameters& params,
56 const std::string& device_id) OVERRIDE; 60 const std::string& device_id) OVERRIDE;
57 61
62 // Implementation of MessageLoop::DestructionObserver.
63 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
tommi (sloooow) - chröme 2014/01/30 12:51:11 make this private
henrika (OOO until Aug 14) 2014/01/30 14:48:24 Done.
64
58 static bool RegisterAudioManager(JNIEnv* env); 65 static bool RegisterAudioManager(JNIEnv* env);
59 66
60 void SetMute(JNIEnv* env, jobject obj, jboolean muted); 67 void SetMute(JNIEnv* env, jobject obj, jboolean muted);
61 68
62 protected: 69 protected:
63 virtual ~AudioManagerAndroid(); 70 virtual ~AudioManagerAndroid();
64 71
65 virtual AudioParameters GetPreferredOutputStreamParameters( 72 virtual AudioParameters GetPreferredOutputStreamParameters(
66 const std::string& output_device_id, 73 const std::string& output_device_id,
67 const AudioParameters& input_params) OVERRIDE; 74 const AudioParameters& input_params) OVERRIDE;
68 75
69 private: 76 private:
70 bool HadNoAudioStreams(); 77 bool HadNoAudioStreams();
71 void Init(); 78 void Init();
72 void Close(); 79 void Close();
73 void SetCommunicationAudioModeOn(bool on); 80 void SetCommunicationAudioModeOn(bool on);
74 bool SetAudioDevice(const std::string& device_id); 81 bool SetAudioDevice(const std::string& device_id);
75 int GetNativeOutputSampleRate(); 82 int GetNativeOutputSampleRate();
76 bool IsAudioLowLatencySupported(); 83 bool IsAudioLowLatencySupported();
77 int GetAudioLowLatencyOutputFrameSize(); 84 int GetAudioLowLatencyOutputFrameSize();
78 int GetOptimalOutputFrameSize(int sample_rate, int channels); 85 int GetOptimalOutputFrameSize(int sample_rate, int channels);
79 86
87 void InitializeOnAudioThread();
88 void CloseOnAudioThread();
89 void GetAudioInputDeviceNamesOnAudioThread(
90 base::WaitableEvent* event, AudioDeviceNames* device_names);
91 void SetAudioDeviceOnAudioThread(base::WaitableEvent* event,
92 const std::string& device_id, bool* result);
80 void DoSetMuteOnAudioThread(bool muted); 93 void DoSetMuteOnAudioThread(bool muted);
81 94
82 // Allow the AudioAndroidTest to access private methods. 95 // Allow the AudioAndroidTest to access private methods.
83 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported); 96 FRIEND_TEST_ALL_PREFIXES(AudioAndroidOutputTest, IsAudioLowLatencySupported);
84 97
85 // Java AudioManager instance. 98 // Java AudioManager instance.
86 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; 99 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_;
87 100
88 typedef std::set<OpenSLESOutputStream*> OutputStreams; 101 typedef std::set<OpenSLESOutputStream*> OutputStreams;
89 OutputStreams streams_; 102 OutputStreams streams_;
90 // TODO(wjia): remove this lock once unit test modules are fixed to call 103 // TODO(wjia): remove this lock once unit test modules are fixed to call
91 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this 104 // AudioManager::MakeAudioOutputStream on the audio thread. For now, this
92 // lock is used to guard access to |streams_|. 105 // lock is used to guard access to |streams_|.
93 base::Lock streams_lock_; 106 base::Lock streams_lock_;
107 bool initialized_on_audio_thread_;
94 108
95 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid); 109 DISALLOW_COPY_AND_ASSIGN(AudioManagerAndroid);
96 }; 110 };
97 111
98 } // namespace media 112 } // namespace media
99 113
100 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_ 114 #endif // MEDIA_AUDIO_ANDROID_AUDIO_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698