Merge "Use switch in AudioMixer::setParameter"
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index c6dd40b..59751ac 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -48,6 +48,8 @@
 AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate)
     :   mActiveTrack(0), mTrackNames(0), mSampleRate(sampleRate)
 {
+    // AudioMixer is not yet capable of multi-channel beyond stereo
+    assert(2 == MAX_NUM_CHANNELS);
     mState.enabledTracks= 0;
     mState.needsChanged = 0;
     mState.frameCount   = frameCount;
@@ -169,68 +171,73 @@
     mActiveTrack = track;
 }
 
-status_t AudioMixer::setParameter(int target, int name, void *value)
+void AudioMixer::setParameter(int target, int name, void *value)
 {
     int valueInt = (int)value;
     int32_t *valueBuf = (int32_t *)value;
 
     switch (target) {
+
     case TRACK:
-        if (name == CHANNEL_MASK) {
+        switch (name) {
+        case CHANNEL_MASK: {
             uint32_t mask = (uint32_t)value;
             if (mState.tracks[ mActiveTrack ].channelMask != mask) {
                 uint8_t channelCount = popcount(mask);
-                if ((channelCount <= MAX_NUM_CHANNELS) && (channelCount)) {
-                    mState.tracks[ mActiveTrack ].channelMask = mask;
-                    mState.tracks[ mActiveTrack ].channelCount = channelCount;
-                    ALOGV("setParameter(TRACK, CHANNEL_MASK, %x)", mask);
-                    invalidateState(1<<mActiveTrack);
-                    return NO_ERROR;
-                }
-            } else {
-                return NO_ERROR;
+                assert((channelCount <= MAX_NUM_CHANNELS) && (channelCount));
+                mState.tracks[ mActiveTrack ].channelMask = mask;
+                mState.tracks[ mActiveTrack ].channelCount = channelCount;
+                ALOGV("setParameter(TRACK, CHANNEL_MASK, %x)", mask);
+                invalidateState(1<<mActiveTrack);
             }
-        }
-        if (name == MAIN_BUFFER) {
+            } break;
+        case MAIN_BUFFER:
             if (mState.tracks[ mActiveTrack ].mainBuffer != valueBuf) {
                 mState.tracks[ mActiveTrack ].mainBuffer = valueBuf;
                 ALOGV("setParameter(TRACK, MAIN_BUFFER, %p)", valueBuf);
                 invalidateState(1<<mActiveTrack);
             }
-            return NO_ERROR;
-        }
-        if (name == AUX_BUFFER) {
+            break;
+        case AUX_BUFFER:
             if (mState.tracks[ mActiveTrack ].auxBuffer != valueBuf) {
                 mState.tracks[ mActiveTrack ].auxBuffer = valueBuf;
                 ALOGV("setParameter(TRACK, AUX_BUFFER, %p)", valueBuf);
                 invalidateState(1<<mActiveTrack);
             }
-            return NO_ERROR;
+            break;
+        default:
+            // bad name
+            assert(false);
         }
-
         break;
+
     case RESAMPLE:
-        if (name == SAMPLE_RATE) {
-            if (valueInt > 0) {
-                track_t& track = mState.tracks[ mActiveTrack ];
-                if (track.setResampler(uint32_t(valueInt), mSampleRate)) {
-                    ALOGV("setParameter(RESAMPLE, SAMPLE_RATE, %u)",
-                            uint32_t(valueInt));
-                    invalidateState(1<<mActiveTrack);
-                }
-                return NO_ERROR;
+        switch (name) {
+        case SAMPLE_RATE: {
+            assert(valueInt > 0);
+            track_t& track = mState.tracks[ mActiveTrack ];
+            if (track.setResampler(uint32_t(valueInt), mSampleRate)) {
+                ALOGV("setParameter(RESAMPLE, SAMPLE_RATE, %u)",
+                        uint32_t(valueInt));
+                invalidateState(1<<mActiveTrack);
             }
-        }
-        if (name == RESET) {
+            } break;
+        case RESET: {
             track_t& track = mState.tracks[ mActiveTrack ];
             track.resetResampler();
             invalidateState(1<<mActiveTrack);
-            return NO_ERROR;
+            } break;
+        default:
+            // bad name
+            assert(false);
         }
         break;
+
     case RAMP_VOLUME:
     case VOLUME:
-        if ((uint32_t(name-VOLUME0) < MAX_NUM_CHANNELS)) {
+        switch (name) {
+        case VOLUME0:
+        case VOLUME1: {
             track_t& track = mState.tracks[ mActiveTrack ];
             if (track.volume[name-VOLUME0] != valueInt) {
                 ALOGV("setParameter(VOLUME, VOLUME0/1: %04x)", valueInt);
@@ -249,8 +256,8 @@
                 }
                 invalidateState(1<<mActiveTrack);
             }
-            return NO_ERROR;
-        } else if (name == AUXLEVEL) {
+            } break;
+        case AUXLEVEL: {
             track_t& track = mState.tracks[ mActiveTrack ];
             if (track.auxLevel != valueInt) {
                 ALOGV("setParameter(VOLUME, AUXLEVEL: %04x)", valueInt);
@@ -269,11 +276,17 @@
                 }
                 invalidateState(1<<mActiveTrack);
             }
-            return NO_ERROR;
+            } break;
+        default:
+            // bad name
+            assert(false);
         }
         break;
+
+    default:
+        // bad target
+        assert(false);
     }
-    return BAD_VALUE;
 }
 
 bool AudioMixer::track_t::setResampler(uint32_t value, uint32_t devSampleRate)
diff --git a/services/audioflinger/AudioMixer.h b/services/audioflinger/AudioMixer.h
index f380b35..288c70e 100644
--- a/services/audioflinger/AudioMixer.h
+++ b/services/audioflinger/AudioMixer.h
@@ -81,7 +81,7 @@
     void        disable();
 
     void        setActiveTrack(int track);
-    status_t    setParameter(int target, int name, void *value);
+    void        setParameter(int target, int name, void *value);
 
     void        setBufferProvider(AudioBufferProvider* bufferProvider);
     void        process();