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

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

Issue 2411263003: Android audio playout now supports non-call media streams (Closed)
Patch Set: Adding support for SetCommunicationMode in AudioManager Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
diff --git a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
index c2874316a5ddac0e6a0c03a78f810a918f420a38..825f627d038742d8c5ef6ec72a2bdd62e09fa7f2 100644
--- a/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
+++ b/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioTrack.java
@@ -188,6 +188,17 @@ public class WebRtcAudioTrack {
Logging.e(TAG, "AudioTrack.getMinBufferSize returns an invalid value.");
return false;
}
+ // The default (preferred) stream type is STREAM_VOICE_CALL since the
+ // WebRTC stack is mainly intended for VoIP calls.
+ int streamType = AudioManager.STREAM_VOICE_CALL;
+ if (audioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
+ // But if the user wants to run in another mode than COMM mode, we
+ // accept it and change the stream type to STREAM_MUSIC instead. It can
+ // e.g. be suitable for applications that do not record audio or if a
+ // call shall be casted to a Chromecast device.
+ streamType = AudioManager.STREAM_MUSIC;
+ Logging.w(TAG, "Using AudioManager.STREAM_MUSIC as stream type.");
+ }
// Ensure that prevision audio session was stopped correctly before trying
// to create a new AudioTrack.
@@ -199,9 +210,8 @@ public class WebRtcAudioTrack {
// Create an AudioTrack object and initialize its associated audio buffer.
// The size of this buffer determines how long an AudioTrack can play
// before running out of data.
- audioTrack =
- new AudioTrack(AudioManager.STREAM_VOICE_CALL, sampleRate, AudioFormat.CHANNEL_OUT_MONO,
- AudioFormat.ENCODING_PCM_16BIT, minBufferSizeInBytes, AudioTrack.MODE_STREAM);
+ audioTrack = new AudioTrack(streamType, sampleRate, AudioFormat.CHANNEL_OUT_MONO,
+ AudioFormat.ENCODING_PCM_16BIT, minBufferSizeInBytes, AudioTrack.MODE_STREAM);
} catch (IllegalArgumentException e) {
Logging.d(TAG, e.getMessage());
return false;

Powered by Google App Engine
This is Rietveld 408576698