Move up initialization of mFormat, mStreamType, and mSharedBuffer earlier
This will allow removal of most of the parameter list to createTrack_l.
Also check for valid stream type at client so we can log a better error
message.
Change-Id: Ia7176896d47fbb49106119fca26d9de8e7efe859
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index a113f77..eeaab44 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -216,6 +216,7 @@
ALOGE("Invalid transfer type %d", transferType);
return BAD_VALUE;
}
+ mSharedBuffer = sharedBuffer;
mTransfer = transferType;
// FIXME "int" here is legacy and will be replaced by size_t later
@@ -244,6 +245,11 @@
if (streamType == AUDIO_STREAM_DEFAULT) {
streamType = AUDIO_STREAM_MUSIC;
}
+ if (uint32_t(streamType) >= AUDIO_STREAM_CNT) {
+ ALOGE("Invalid stream type %d", streamType);
+ return BAD_VALUE;
+ }
+ mStreamType = streamType;
status_t status;
if (sampleRate == 0) {
@@ -266,6 +272,7 @@
ALOGE("Invalid format %d", format);
return BAD_VALUE;
}
+ mFormat = format;
if (!audio_is_output_channel(channelMask)) {
ALOGE("Invalid channel mask %#x", channelMask);
@@ -363,9 +370,6 @@
}
mStatus = NO_ERROR;
- mStreamType = streamType;
- mFormat = format;
- mSharedBuffer = sharedBuffer;
mState = STATE_STOPPED;
mUserData = user;
mLoopPeriod = 0;