Add AudioTrack and AudioRecord flag checks
Verify that the requested flags are compatible with the input
or output flags when creating and AudioRecord or AudioTrack
Get rid of IAudioFlinger::track_flags_t which was redundant
with audio_input_flags_t and audio_output_flags_t.
Change-Id: I0dd9232f857b2737e99a8c668806e45bce09cdbd
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index d9bb856..9a87023 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -593,11 +593,10 @@
size_t notificationFrames = mNotificationFramesReq;
size_t frameCount = mReqFrameCount;
- IAudioFlinger::track_flags_t trackFlags = IAudioFlinger::TRACK_DEFAULT;
+ audio_input_flags_t flags = mFlags;
pid_t tid = -1;
if (mFlags & AUDIO_INPUT_FLAG_FAST) {
- trackFlags |= IAudioFlinger::TRACK_FAST;
if (mAudioRecordThread != 0) {
tid = mAudioRecordThread->getTid();
}
@@ -615,7 +614,7 @@
mChannelMask,
opPackageName,
&temp,
- &trackFlags,
+ &flags,
mClientPid,
tid,
mClientUid,
@@ -638,7 +637,7 @@
mAwaitBoost = false;
if (mFlags & AUDIO_INPUT_FLAG_FAST) {
- if (trackFlags & IAudioFlinger::TRACK_FAST) {
+ if (flags & AUDIO_INPUT_FLAG_FAST) {
ALOGI("AUDIO_INPUT_FLAG_FAST successful; frameCount %zu", frameCount);
mAwaitBoost = true;
} else {
@@ -648,6 +647,7 @@
continue; // retry
}
}
+ mFlags = flags;
if (iMem == 0) {
ALOGE("Could not get control block");
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 1963da3..3961e6e 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -1372,24 +1372,15 @@
}
}
- IAudioFlinger::track_flags_t trackFlags = IAudioFlinger::TRACK_DEFAULT;
+ audio_output_flags_t flags = mFlags;
pid_t tid = -1;
if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
- trackFlags |= IAudioFlinger::TRACK_FAST;
if (mAudioTrackThread != 0 && !mThreadCanCallJava) {
tid = mAudioTrackThread->getTid();
}
}
- if (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
- trackFlags |= IAudioFlinger::TRACK_OFFLOAD;
- }
-
- if (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) {
- trackFlags |= IAudioFlinger::TRACK_DIRECT;
- }
-
size_t temp = frameCount; // temp may be replaced by a revised value of frameCount,
// but we will still need the original value also
audio_session_t originalSessionId = mSessionId;
@@ -1398,7 +1389,7 @@
mFormat,
mChannelMask,
&temp,
- &trackFlags,
+ &flags,
mSharedBuffer,
output,
mClientPid,
@@ -1451,23 +1442,23 @@
mAwaitBoost = false;
if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
- if (trackFlags & IAudioFlinger::TRACK_FAST) {
+ if (flags & AUDIO_OUTPUT_FLAG_FAST) {
ALOGV("AUDIO_OUTPUT_FLAG_FAST successful; frameCount %zu", frameCount);
if (!mThreadCanCallJava) {
mAwaitBoost = true;
}
} else {
ALOGW("AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount %zu", frameCount);
- mFlags = (audio_output_flags_t) (mFlags & ~AUDIO_OUTPUT_FLAG_FAST);
}
}
+ mFlags = flags;
// Make sure that application is notified with sufficient margin before underrun.
// The client can divide the AudioTrack buffer into sub-buffers,
// and expresses its desire to server as the notification frame count.
if (mSharedBuffer == 0 && audio_is_linear_pcm(mFormat)) {
size_t maxNotificationFrames;
- if (trackFlags & IAudioFlinger::TRACK_FAST) {
+ if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
// notify every HAL buffer, regardless of the size of the track buffer
maxNotificationFrames = afFrameCountHAL;
} else {
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 92e65e4..900d418 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -101,7 +101,7 @@
audio_format_t format,
audio_channel_mask_t channelMask,
size_t *pFrameCount,
- track_flags_t *flags,
+ audio_output_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
pid_t pid,
@@ -119,7 +119,7 @@
data.writeInt32(channelMask);
size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
data.writeInt64(frameCount);
- track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
+ audio_output_flags_t lFlags = flags != NULL ? *flags : AUDIO_OUTPUT_FLAG_NONE;
data.writeInt32(lFlags);
// haveSharedBuffer
if (sharedBuffer != 0) {
@@ -145,7 +145,7 @@
if (pFrameCount != NULL) {
*pFrameCount = frameCount;
}
- lFlags = reply.readInt32();
+ lFlags = (audio_output_flags_t)reply.readInt32();
if (flags != NULL) {
*flags = lFlags;
}
@@ -180,7 +180,7 @@
audio_channel_mask_t channelMask,
const String16& opPackageName,
size_t *pFrameCount,
- track_flags_t *flags,
+ audio_input_flags_t *flags,
pid_t pid,
pid_t tid,
int clientUid,
@@ -200,7 +200,7 @@
data.writeString16(opPackageName);
size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
data.writeInt64(frameCount);
- track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
+ audio_input_flags_t lFlags = flags != NULL ? *flags : AUDIO_INPUT_FLAG_NONE;
data.writeInt32(lFlags);
data.writeInt32((int32_t) pid);
data.writeInt32((int32_t) tid);
@@ -221,7 +221,7 @@
if (pFrameCount != NULL) {
*pFrameCount = frameCount;
}
- lFlags = reply.readInt32();
+ lFlags = (audio_input_flags_t)reply.readInt32();
if (flags != NULL) {
*flags = lFlags;
}
@@ -947,7 +947,7 @@
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
size_t frameCount = data.readInt64();
- track_flags_t flags = (track_flags_t) data.readInt32();
+ audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
bool haveSharedBuffer = data.readInt32() != 0;
sp<IMemory> buffer;
if (haveSharedBuffer) {
@@ -986,7 +986,7 @@
audio_channel_mask_t channelMask = data.readInt32();
const String16& opPackageName = data.readString16();
size_t frameCount = data.readInt64();
- track_flags_t flags = (track_flags_t) data.readInt32();
+ audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
pid_t pid = (pid_t) data.readInt32();
pid_t tid = (pid_t) data.readInt32();
int clientUid = data.readInt32();