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

Side by Side Diff: webrtc/modules/audio_device/android/opensles_player.h

Issue 2019223004: Moves ownership of OpenSL engine object to Android audio manager (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from magjed@ Created 4 years, 6 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 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // platform version 2.3) or later, then we can still use the OpenSL ES APIs but 48 // platform version 2.3) or later, then we can still use the OpenSL ES APIs but
49 // the output latency may be higher. 49 // the output latency may be higher.
50 class OpenSLESPlayer { 50 class OpenSLESPlayer {
51 public: 51 public:
52 // The lower output latency path is used only if the application requests a 52 // The lower output latency path is used only if the application requests a
53 // buffer count of 2 or more, and a buffer size and sample rate that are 53 // buffer count of 2 or more, and a buffer size and sample rate that are
54 // compatible with the device's native output configuration provided via the 54 // compatible with the device's native output configuration provided via the
55 // audio manager at construction. 55 // audio manager at construction.
56 static const int kNumOfOpenSLESBuffers = 4; 56 static const int kNumOfOpenSLESBuffers = 4;
57 57
58 // There is no need for this class to use JNI.
59 static int32_t SetAndroidAudioDeviceObjects(void* javaVM, void* context) {
60 return 0;
61 }
62 static void ClearAndroidAudioDeviceObjects() {}
63
64 explicit OpenSLESPlayer(AudioManager* audio_manager); 58 explicit OpenSLESPlayer(AudioManager* audio_manager);
65 ~OpenSLESPlayer(); 59 ~OpenSLESPlayer();
66 60
67 int Init(); 61 int Init();
68 int Terminate(); 62 int Terminate();
69 63
70 int InitPlayout(); 64 int InitPlayout();
71 bool PlayoutIsInitialized() const { return initialized_; } 65 bool PlayoutIsInitialized() const { return initialized_; }
72 66
73 int StartPlayout(); 67 int StartPlayout();
(...skipping 22 matching lines...) Expand all
96 90
97 // Configures the SL_DATAFORMAT_PCM structure. 91 // Configures the SL_DATAFORMAT_PCM structure.
98 SLDataFormat_PCM CreatePCMConfiguration(size_t channels, 92 SLDataFormat_PCM CreatePCMConfiguration(size_t channels,
99 int sample_rate, 93 int sample_rate,
100 size_t bits_per_sample); 94 size_t bits_per_sample);
101 95
102 // Allocate memory for audio buffers which will be used to render audio 96 // Allocate memory for audio buffers which will be used to render audio
103 // via the SLAndroidSimpleBufferQueueItf interface. 97 // via the SLAndroidSimpleBufferQueueItf interface.
104 void AllocateDataBuffers(); 98 void AllocateDataBuffers();
105 99
106 // Creates/destroys the main engine object and the SLEngineItf interface. 100 // Obtaines the SL Engine Interface from the existing global Engine object.
107 bool CreateEngine(); 101 // The interface exposes creation methods of all the OpenSL ES object types.
108 void DestroyEngine(); 102 // This method defines the |engine_| member variable.
103 bool ObtainEngineInterface();
109 104
110 // Creates/destroys the output mix object. 105 // Creates/destroys the output mix object.
111 bool CreateMix(); 106 bool CreateMix();
112 void DestroyMix(); 107 void DestroyMix();
113 108
114 // Creates/destroys the audio player and the simple-buffer object. 109 // Creates/destroys the audio player and the simple-buffer object.
115 // Also creates the volume object. 110 // Also creates the volume object.
116 bool CreateAudioPlayer(); 111 bool CreateAudioPlayer();
117 void DestroyAudioPlayer(); 112 void DestroyAudioPlayer();
118 113
119 SLuint32 GetPlayState() const; 114 SLuint32 GetPlayState() const;
120 115
121 // Ensures that methods are called from the same thread as this object is 116 // Ensures that methods are called from the same thread as this object is
122 // created on. 117 // created on.
123 rtc::ThreadChecker thread_checker_; 118 rtc::ThreadChecker thread_checker_;
124 119
125 // Stores thread ID in first call to SimpleBufferQueueCallback() from internal 120 // Stores thread ID in first call to SimpleBufferQueueCallback() from internal
126 // non-application thread which is not attached to the Dalvik JVM. 121 // non-application thread which is not attached to the Dalvik JVM.
127 // Detached during construction of this object. 122 // Detached during construction of this object.
128 rtc::ThreadChecker thread_checker_opensles_; 123 rtc::ThreadChecker thread_checker_opensles_;
129 124
125 // Raw pointer to the audio manager injected at construction. Used to cache
126 // audio parameters and to access the global SL engine object needed by the
127 // ObtainEngineInterface() method. The audio manager outlives any instance of
128 // this class.
129 AudioManager* audio_manager_;
130
130 // Contains audio parameters provided to this class at construction by the 131 // Contains audio parameters provided to this class at construction by the
131 // AudioManager. 132 // AudioManager.
132 const AudioParameters audio_parameters_; 133 const AudioParameters audio_parameters_;
133 134
134 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the 135 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the
135 // AudioDeviceModuleImpl class and called by AudioDeviceModule::Create(). 136 // AudioDeviceModuleImpl class and called by AudioDeviceModule::Create().
136 AudioDeviceBuffer* audio_device_buffer_; 137 AudioDeviceBuffer* audio_device_buffer_;
137 138
138 bool initialized_; 139 bool initialized_;
139 bool playing_; 140 bool playing_;
(...skipping 22 matching lines...) Expand all
162 // WebRTC will provide 480 audio frames per 10ms but OpenSL ES asks for 240 163 // WebRTC will provide 480 audio frames per 10ms but OpenSL ES asks for 240
163 // in each callback (one every 5ms). This class can then ask for 240 and the 164 // in each callback (one every 5ms). This class can then ask for 240 and the
164 // FineAudioBuffer will ask WebRTC for new data only every second callback 165 // FineAudioBuffer will ask WebRTC for new data only every second callback
165 // and also cach non-utilized audio. 166 // and also cach non-utilized audio.
166 std::unique_ptr<FineAudioBuffer> fine_buffer_; 167 std::unique_ptr<FineAudioBuffer> fine_buffer_;
167 168
168 // Keeps track of active audio buffer 'n' in the audio_buffers_[n] queue. 169 // Keeps track of active audio buffer 'n' in the audio_buffers_[n] queue.
169 // Example (kNumOfOpenSLESBuffers = 2): counts 0, 1, 0, 1, ... 170 // Example (kNumOfOpenSLESBuffers = 2): counts 0, 1, 0, 1, ...
170 int buffer_index_; 171 int buffer_index_;
171 172
172 // The engine object which provides the SLEngineItf interface.
173 // Created by the global Open SL ES constructor slCreateEngine().
174 webrtc::ScopedSLObjectItf engine_object_;
175
176 // This interface exposes creation methods for all the OpenSL ES object types. 173 // This interface exposes creation methods for all the OpenSL ES object types.
177 // It is the OpenSL ES API entry point. 174 // It is the OpenSL ES API entry point.
178 SLEngineItf engine_; 175 SLEngineItf engine_;
179 176
180 // Output mix object to be used by the player object. 177 // Output mix object to be used by the player object.
181 webrtc::ScopedSLObjectItf output_mix_; 178 webrtc::ScopedSLObjectItf output_mix_;
182 179
183 // The audio player media object plays out audio to the speakers. It also 180 // The audio player media object plays out audio to the speakers. It also
184 // supports volume control. 181 // supports volume control.
185 webrtc::ScopedSLObjectItf player_object_; 182 webrtc::ScopedSLObjectItf player_object_;
(...skipping 11 matching lines...) Expand all
197 // properties. This interface is supported on the Audio Player object. 194 // properties. This interface is supported on the Audio Player object.
198 SLVolumeItf volume_; 195 SLVolumeItf volume_;
199 196
200 // Last time the OpenSL ES layer asked for audio data to play out. 197 // Last time the OpenSL ES layer asked for audio data to play out.
201 uint32_t last_play_time_; 198 uint32_t last_play_time_;
202 }; 199 };
203 200
204 } // namespace webrtc 201 } // namespace webrtc
205 202
206 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_PLAYER_H_ 203 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_PLAYER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/opensles_common.cc ('k') | webrtc/modules/audio_device/android/opensles_player.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698