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

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

Issue 1444313002: Adding thread timeout for audio recorer thread in Java (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Moved stuff around Created 5 years, 1 month 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
« no previous file with comments | « webrtc/base/java/src/org/webrtc/ThreadUtils.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 package org.webrtc.voiceengine; 11 package org.webrtc.voiceengine;
12 12
13 import java.lang.System; 13 import java.lang.System;
14 import java.nio.ByteBuffer; 14 import java.nio.ByteBuffer;
15 import java.util.concurrent.TimeUnit; 15 import java.util.concurrent.TimeUnit;
16 16
17 import android.content.Context; 17 import android.content.Context;
18 import android.media.AudioFormat; 18 import android.media.AudioFormat;
19 import android.media.AudioRecord; 19 import android.media.AudioRecord;
20 import android.media.MediaRecorder.AudioSource; 20 import android.media.MediaRecorder.AudioSource;
21 import android.os.Build; 21 import android.os.Build;
22 import android.os.Process; 22 import android.os.Process;
23 import android.os.SystemClock; 23 import android.os.SystemClock;
24 24
25 import org.webrtc.Logging; 25 import org.webrtc.Logging;
26 import org.webrtc.ThreadUtils;
26 27
27 class WebRtcAudioRecord { 28 class WebRtcAudioRecord {
28 private static final boolean DEBUG = false; 29 private static final boolean DEBUG = false;
29 30
30 private static final String TAG = "WebRtcAudioRecord"; 31 private static final String TAG = "WebRtcAudioRecord";
31 32
32 // Default audio data format is PCM 16 bit per sample. 33 // Default audio data format is PCM 16 bit per sample.
33 // Guaranteed to be supported by all devices. 34 // Guaranteed to be supported by all devices.
34 private static final int BITS_PER_SAMPLE = 16; 35 private static final int BITS_PER_SAMPLE = 16;
35 36
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 97
97 try { 98 try {
98 audioRecord.stop(); 99 audioRecord.stop();
99 } catch (IllegalStateException e) { 100 } catch (IllegalStateException e) {
100 Logging.e(TAG,"AudioRecord.stop failed: " + e.getMessage()); 101 Logging.e(TAG,"AudioRecord.stop failed: " + e.getMessage());
101 } 102 }
102 } 103 }
103 104
104 public void joinThread() { 105 public void joinThread() {
105 keepAlive = false; 106 keepAlive = false;
106 while (isAlive()) { 107 if (!ThreadUtils.joinUninterruptibly(this, 1000)) {
107 try { 108 Logging.e(TAG, "Timeout in WebRtcAudioRecord.joinThread()");
108 join();
109 } catch (InterruptedException e) {
110 // Ignore.
111 }
112 } 109 }
113 } 110 }
114 } 111 }
115 112
116 WebRtcAudioRecord(Context context, long nativeAudioRecord) { 113 WebRtcAudioRecord(Context context, long nativeAudioRecord) {
117 Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo()); 114 Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
118 this.context = context; 115 this.context = context;
119 this.nativeAudioRecord = nativeAudioRecord; 116 this.nativeAudioRecord = nativeAudioRecord;
120 if (DEBUG) { 117 if (DEBUG) {
121 WebRtcAudioUtils.logDeviceInfo(TAG); 118 WebRtcAudioUtils.logDeviceInfo(TAG);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 if (!condition) { 263 if (!condition) {
267 throw new AssertionError("Expected condition to be true"); 264 throw new AssertionError("Expected condition to be true");
268 } 265 }
269 } 266 }
270 267
271 private native void nativeCacheDirectBufferAddress( 268 private native void nativeCacheDirectBufferAddress(
272 ByteBuffer byteBuffer, long nativeAudioRecord); 269 ByteBuffer byteBuffer, long nativeAudioRecord);
273 270
274 private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord); 271 private native void nativeDataIsRecorded(int bytes, long nativeAudioRecord);
275 } 272 }
OLDNEW
« no previous file with comments | « webrtc/base/java/src/org/webrtc/ThreadUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698