ALOGV("getOutput() device %d, stream %d, samplingRate %d, format %x, channelMask %x, flags %x",
device, stream, samplingRate, format, channelMask, flags);
- return getOutputForDevice(device, AUDIO_SESSION_ALLOCATE,
+ return getOutputForDevice(device, AUDIO_SESSION_ALLOCATE, uid_t{0} /*Invalid uid*/,
stream, samplingRate,format, channelMask,
flags, offloadInfo);
}
ALOGV("getOutputForAttr() device 0x%x, samplingRate %d, format %x, channelMask %x, flags %x",
device, config->sample_rate, config->format, config->channel_mask, flags);
- *output = getOutputForDevice(device, session, *stream,
+ *output = getOutputForDevice(device, session, uid, *stream,
config->sample_rate, config->format, config->channel_mask,
flags, &config->offload_info);
if (*output == AUDIO_IO_HANDLE_NONE) {
audio_io_handle_t AudioPolicyManager::getOutputForDevice(
audio_devices_t device,
audio_session_t session __unused,
+ uid_t clientUid,
audio_stream_type_t stream,
uint32_t samplingRate,
audio_format_t format,
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
if (!desc->isDuplicated() && (profile == desc->mProfile)) {
outputDesc = desc;
- // reuse direct output if currently open and configured with same parameters
+ // reuse direct output if currently open by the same client
+ // and configured with same parameters
if ((samplingRate == outputDesc->mSamplingRate) &&
- audio_formats_match(format, outputDesc->mFormat) &&
- (channelMask == outputDesc->mChannelMask)) {
- outputDesc->mDirectOpenCount++;
- ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
- return mOutputs.keyAt(i);
+ audio_formats_match(format, outputDesc->mFormat) &&
+ (channelMask == outputDesc->mChannelMask)) {
+ if (clientUid == outputDesc->mDirectClientUid) {
+ outputDesc->mDirectOpenCount++;
+ ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
+ return mOutputs.keyAt(i);
+ } else {
+ ALOGV("getOutput() do not reuse direct output because current client (%ld) "
+ "is not the same as requesting client (%ld)",
+ (long)outputDesc->mDirectClientUid, (long)clientUid);
+ goto non_direct_output;
+ }
}
}
}
outputDesc->mRefCount[stream] = 0;
outputDesc->mStopTime[stream] = 0;
outputDesc->mDirectOpenCount = 1;
+ outputDesc->mDirectClientUid = clientUid;
audio_io_handle_t srcOutput = getOutputForEffect();
addOutput(output, outputDesc);