ToneGenerator: fix use of STREAM_VOICE_CALL

ToneGenerator is only used for signalling, never for voice.
In order to use proper audio attributes usage and content type, convert
requests to play on stream VOICE_CALL to stream DTMF.
This will produce consistent routing and volume behavior when apps use
DTMF or VOICE_CALL streams.
Also use audio attributes when creating the AudioTrack

Test: CTS for ToneGenerator, voice and VoIP calls
Change-Id: Ic67abaeed0ea09f08ad5586cebe858e74fe21af9
gugelfrei
Eric Laurent 7 years ago
parent 28288fb0b1
commit 53ad17fd64

@ -20,6 +20,7 @@
#include <math.h>
#include <utils/Log.h>
#include <cutils/properties.h>
#include <media/AudioPolicyHelper.h>
#include "media/ToneGenerator.h"
@ -1044,7 +1045,7 @@ bool ToneGenerator::startTone(tone_type toneType, int durationMs) {
}
}
ALOGV("startTone");
ALOGV("startTone toneType %d", toneType);
mLock.lock();
@ -1196,9 +1197,16 @@ bool ToneGenerator::initAudioTrack() {
mpAudioTrack = new AudioTrack();
ALOGV("AudioTrack(%p) created", mpAudioTrack.get());
audio_attributes_t attr;
audio_stream_type_t streamType = mStreamType;
if (mStreamType == AUDIO_STREAM_VOICE_CALL) {
streamType = AUDIO_STREAM_DTMF;
}
stream_type_to_audio_attributes(streamType, &attr);
const size_t frameCount = mProcessSize;
status_t status = mpAudioTrack->set(
mStreamType,
AUDIO_STREAM_DEFAULT,
0, // sampleRate
AUDIO_FORMAT_PCM_16_BIT,
AUDIO_CHANNEL_OUT_MONO,
@ -1210,7 +1218,11 @@ bool ToneGenerator::initAudioTrack() {
0, // sharedBuffer
mThreadCanCallJava,
AUDIO_SESSION_ALLOCATE,
AudioTrack::TRANSFER_CALLBACK);
AudioTrack::TRANSFER_CALLBACK,
nullptr,
AUDIO_UID_INVALID,
-1,
&attr);
if (status != NO_ERROR) {
ALOGE("AudioTrack(%p) set failed with error %d", mpAudioTrack.get(), status);

Loading…
Cancel
Save