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

Side by Side Diff: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java

Issue 1344563002: Improving support for Android Audio Effects in WebRTC (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Improved comments Created 5 years, 3 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 Logd("ctor" + WebRtcAudioUtils.getThreadInfo()); 139 Logd("ctor" + WebRtcAudioUtils.getThreadInfo());
140 this.context = context; 140 this.context = context;
141 this.nativeAudioTrack = nativeAudioTrack; 141 this.nativeAudioTrack = nativeAudioTrack;
142 audioManager = (AudioManager) context.getSystemService( 142 audioManager = (AudioManager) context.getSystemService(
143 Context.AUDIO_SERVICE); 143 Context.AUDIO_SERVICE);
144 if (DEBUG) { 144 if (DEBUG) {
145 WebRtcAudioUtils.logDeviceInfo(TAG); 145 WebRtcAudioUtils.logDeviceInfo(TAG);
146 } 146 }
147 } 147 }
148 148
149 private void InitPlayout(int sampleRate, int channels) { 149 private void initPlayout(int sampleRate, int channels) {
150 Logd("InitPlayout(sampleRate=" + sampleRate + ", channels=" + 150 Logd("initPlayout(sampleRate=" + sampleRate + ", channels=" +
151 channels + ")"); 151 channels + ")");
152 final int bytesPerFrame = channels * (BITS_PER_SAMPLE / 8); 152 final int bytesPerFrame = channels * (BITS_PER_SAMPLE / 8);
153 byteBuffer = byteBuffer.allocateDirect( 153 byteBuffer = byteBuffer.allocateDirect(
154 bytesPerFrame * (sampleRate / BUFFERS_PER_SECOND)); 154 bytesPerFrame * (sampleRate / BUFFERS_PER_SECOND));
155 Logd("byteBuffer.capacity: " + byteBuffer.capacity()); 155 Logd("byteBuffer.capacity: " + byteBuffer.capacity());
156 // Rather than passing the ByteBuffer with every callback (requiring 156 // Rather than passing the ByteBuffer with every callback (requiring
157 // the potentially expensive GetDirectBufferAddress) we simply have the 157 // the potentially expensive GetDirectBufferAddress) we simply have the
158 // the native class cache the address to the memory once. 158 // the native class cache the address to the memory once.
159 nativeCacheDirectBufferAddress(byteBuffer, nativeAudioTrack); 159 nativeCacheDirectBufferAddress(byteBuffer, nativeAudioTrack);
160 160
(...skipping 24 matching lines...) Expand all
185 AudioTrack.MODE_STREAM); 185 AudioTrack.MODE_STREAM);
186 } catch (IllegalArgumentException e) { 186 } catch (IllegalArgumentException e) {
187 Logd(e.getMessage()); 187 Logd(e.getMessage());
188 return; 188 return;
189 } 189 }
190 assertTrue(audioTrack.getState() == AudioTrack.STATE_INITIALIZED); 190 assertTrue(audioTrack.getState() == AudioTrack.STATE_INITIALIZED);
191 assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); 191 assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED);
192 assertTrue(audioTrack.getStreamType() == AudioManager.STREAM_VOICE_CALL); 192 assertTrue(audioTrack.getStreamType() == AudioManager.STREAM_VOICE_CALL);
193 } 193 }
194 194
195 private boolean StartPlayout() { 195 private boolean startPlayout() {
196 Logd("StartPlayout"); 196 Logd("startPlayout");
197 assertTrue(audioTrack != null); 197 assertTrue(audioTrack != null);
198 assertTrue(audioThread == null); 198 assertTrue(audioThread == null);
199 audioThread = new AudioTrackThread("AudioTrackJavaThread"); 199 audioThread = new AudioTrackThread("AudioTrackJavaThread");
200 audioThread.start(); 200 audioThread.start();
201 return true; 201 return true;
202 } 202 }
203 203
204 private boolean StopPlayout() { 204 private boolean stopPlayout() {
205 Logd("StopPlayout"); 205 Logd("stopPlayout");
206 assertTrue(audioThread != null); 206 assertTrue(audioThread != null);
207 audioThread.joinThread(); 207 audioThread.joinThread();
208 audioThread = null; 208 audioThread = null;
209 if (audioTrack != null) { 209 if (audioTrack != null) {
210 audioTrack.release(); 210 audioTrack.release();
211 audioTrack = null; 211 audioTrack = null;
212 } 212 }
213 return true; 213 return true;
214 } 214 }
215 215
216 /** Get max possible volume index for a phone call audio stream. */ 216 /** Get max possible volume index for a phone call audio stream. */
217 private int GetStreamMaxVolume() { 217 private int getStreamMaxVolume() {
218 Logd("GetStreamMaxVolume"); 218 Logd("getStreamMaxVolume");
219 assertTrue(audioManager != null); 219 assertTrue(audioManager != null);
220 return audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL); 220 return audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
221 } 221 }
222 222
223 /** Set current volume level for a phone call audio stream. */ 223 /** Set current volume level for a phone call audio stream. */
224 private boolean SetStreamVolume(int volume) { 224 private boolean setStreamVolume(int volume) {
225 Logd("SetStreamVolume(" + volume + ")"); 225 Logd("setStreamVolume(" + volume + ")");
226 assertTrue(audioManager != null); 226 assertTrue(audioManager != null);
227 if (WebRtcAudioUtils.runningOnLollipopOrHigher()) { 227 if (WebRtcAudioUtils.runningOnLollipopOrHigher()) {
228 if (audioManager.isVolumeFixed()) { 228 if (audioManager.isVolumeFixed()) {
229 Loge("The device implements a fixed volume policy."); 229 Loge("The device implements a fixed volume policy.");
230 return false; 230 return false;
231 } 231 }
232 } 232 }
233 audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0); 233 audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, 0);
234 return true; 234 return true;
235 } 235 }
236 236
237 /** Get current volume level for a phone call audio stream. */ 237 /** Get current volume level for a phone call audio stream. */
238 private int GetStreamVolume() { 238 private int getStreamVolume() {
239 Logd("GetStreamVolume"); 239 Logd("getStreamVolume");
240 assertTrue(audioManager != null); 240 assertTrue(audioManager != null);
241 return audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); 241 return audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
242 } 242 }
243 243
244 /** Helper method which throws an exception when an assertion has failed. */ 244 /** Helper method which throws an exception when an assertion has failed. */
245 private static void assertTrue(boolean condition) { 245 private static void assertTrue(boolean condition) {
246 if (!condition) { 246 if (!condition) {
247 throw new AssertionError("Expected condition to be true"); 247 throw new AssertionError("Expected condition to be true");
248 } 248 }
249 } 249 }
250 250
251 private static void Logd(String msg) { 251 private static void Logd(String msg) {
252 Logging.d(TAG, msg); 252 Logging.d(TAG, msg);
253 } 253 }
254 254
255 private static void Loge(String msg) { 255 private static void Loge(String msg) {
256 Logging.e(TAG, msg); 256 Logging.e(TAG, msg);
257 } 257 }
258 258
259 private native void nativeCacheDirectBufferAddress( 259 private native void nativeCacheDirectBufferAddress(
260 ByteBuffer byteBuffer, long nativeAudioRecord); 260 ByteBuffer byteBuffer, long nativeAudioRecord);
261 261
262 private native void nativeGetPlayoutData(int bytes, long nativeAudioRecord); 262 private native void nativeGetPlayoutData(int bytes, long nativeAudioRecord);
263 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698