OSDN Git Service

Bug 5045590 preset reverb on audio players
authorGlenn Kasten <gkasten@google.com>
Fri, 22 Jul 2011 16:08:21 +0000 (09:08 -0700)
committerGlenn Kasten <gkasten@google.com>
Mon, 25 Jul 2011 19:47:30 +0000 (12:47 -0700)
Aux effects on MediaPlayer audio players (non-AudioTrack) were broken

Change-Id: I5b97bee08d809b12cb9815d6d277934123780581

wilhelm/src/android/android_Effect.cpp
wilhelm/src/android/android_GenericMediaPlayer.cpp
wilhelm/src/android/android_GenericMediaPlayer.h
wilhelm/src/android/android_GenericPlayer.cpp
wilhelm/src/android/android_GenericPlayer.h

index bcc0081..f277f10 100644 (file)
@@ -449,6 +449,22 @@ android::status_t android_fxSend_attach(CAudioPlayer* ap, bool attach,
         return android::INVALID_OPERATION;
     }
 
+    // There are 3 cases:
+    //  mAPlayer != 0 && mAudioTrack == 0 means playing decoded audio
+    //  mAPlayer == 0 && mAudioTrack != 0 means playing PCM audio
+    //  mAPlayer == 0 && mAudioTrack == 0 means player not fully configured yet
+    // The asserts document and verify this.
+    if (ap->mAPlayer != 0) {
+        assert(ap->mAudioTrack == 0);
+        if (attach) {
+            ap->mAPlayer->attachAuxEffect(pFx->id());
+            ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) );
+        } else {
+            ap->mAPlayer->attachAuxEffect(0);
+        }
+        return android::NO_ERROR;
+    }
+
     if (ap->mAudioTrack == 0) {
         // the player doesn't have an AudioTrack at the moment, so store this info to use it
         // when the AudioTrack becomes available
@@ -508,6 +524,12 @@ android::status_t android_fxSend_setSendLevel(CAudioPlayer* ap, SLmillibel sendL
     // we keep track of the send level, independently of the current audio player level
     ap->mAuxSendLevel = sendLevel - ap->mVolume.mLevel;
 
+    if (ap->mAPlayer != 0) {
+        assert(ap->mAudioTrack == 0);
+        ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) );
+        return android::NO_ERROR;
+    }
+
     if (ap->mAudioTrack == 0) {
         return android::NO_ERROR;
     }
index 2bbb4f3..4d99cdc 100644 (file)
@@ -339,6 +339,34 @@ void GenericMediaPlayer::onVolumeUpdate() {
 }
 
 
+void GenericMediaPlayer::onAttachAuxEffect(const sp<AMessage> &msg) {
+    SL_LOGD("GenericMediaPlayer::onAttachAuxEffect()");
+    int32_t effectId = 0;
+    if (msg->findInt32(WHATPARAM_ATTACHAUXEFFECT, &effectId)) {
+        if (mPlayer != 0) {
+            status_t status;
+            status = mPlayer->attachAuxEffect(effectId);
+            // attachAuxEffect returns a status but we have no way to report it back to app
+            (void) status;
+        }
+    }
+}
+
+
+void GenericMediaPlayer::onSetAuxEffectSendLevel(const sp<AMessage> &msg) {
+    SL_LOGD("GenericMediaPlayer::onSetAuxEffectSendLevel()");
+    float level = 0.0f;
+    if (msg->findFloat(WHATPARAM_SETAUXEFFECTSENDLEVEL, &level)) {
+        if (mPlayer != 0) {
+            status_t status;
+            status = mPlayer->setAuxEffectSendLevel(level);
+            // setAuxEffectSendLevel returns a status but we have no way to report it back to app
+            (void) status;
+        }
+    }
+}
+
+
 void GenericMediaPlayer::onBufferingUpdate(const sp<AMessage> &msg) {
     int32_t fillLevel = 0;
     if (msg->findInt32(WHATPARAM_BUFFERING_UPDATE, &fillLevel)) {
index aac136d..38d0aa4 100644 (file)
@@ -88,6 +88,8 @@ protected:
     virtual void onVolumeUpdate();
     virtual void onBufferingUpdate(const sp<AMessage> &msg);
     virtual void onGetMediaPlayerInfo();
+    virtual void onAttachAuxEffect(const sp<AMessage> &msg);
+    virtual void onSetAuxEffectSendLevel(const sp<AMessage> &msg);
 
     bool mHasVideo;
     int32_t mSeekTimeMsec;
index f462531..d7ea0c8 100644 (file)
@@ -245,6 +245,26 @@ void GenericPlayer::setVolume(bool mute, bool useStereoPos,
 
 
 //--------------------------------------------------
+void GenericPlayer::attachAuxEffect(int32_t effectId)
+{
+    SL_LOGV("GenericPlayer::attachAuxEffect(id=%d)", effectId);
+    sp<AMessage> msg = new AMessage(kWhatAttachAuxEffect, id());
+    msg->setInt32(WHATPARAM_ATTACHAUXEFFECT, effectId);
+    msg->post();
+}
+
+
+//--------------------------------------------------
+void GenericPlayer::setAuxEffectSendLevel(float level)
+{
+    SL_LOGV("GenericPlayer::setAuxEffectSendLevel(level=%g)", level);
+    sp<AMessage> msg = new AMessage(kWhatSetAuxEffectSendLevel, id());
+    msg->setFloat(WHATPARAM_SETAUXEFFECTSENDLEVEL, level);
+    msg->post();
+}
+
+
+//--------------------------------------------------
 /*
  * post-condition: mDataLocatorType == kDataLocatorNone
  *
@@ -336,6 +356,16 @@ void GenericPlayer::onMessageReceived(const sp<AMessage> &msg) {
             onSetBufferingUpdateThreshold(msg);
             break;
 
+        case kWhatAttachAuxEffect:
+            SL_LOGV("kWhatAttachAuxEffect");
+            onAttachAuxEffect(msg);
+            break;
+
+        case kWhatSetAuxEffectSendLevel:
+            SL_LOGV("kWhatSetAuxEffectSendLevel");
+            onSetAuxEffectSendLevel(msg);
+            break;
+
         default:
             SL_LOGV("kWhatPlay");
             TRESPASS();
@@ -449,6 +479,16 @@ void GenericPlayer::onSetBufferingUpdateThreshold(const sp<AMessage> &msg) {
 }
 
 
+void GenericPlayer::onAttachAuxEffect(const sp<AMessage> &msg) {
+    SL_LOGV("GenericPlayer::onAttachAuxEffect()");
+}
+
+
+void GenericPlayer::onSetAuxEffectSendLevel(const sp<AMessage> &msg) {
+    SL_LOGV("GenericPlayer::onSetAuxEffectSendLevel()");
+}
+
+
 //-------------------------------------------------
 void GenericPlayer::notifyStatus() {
     SL_LOGV("GenericPlayer::notifyStatus");
index ba43e46..04e1793 100644 (file)
@@ -29,6 +29,8 @@
 #define WHATPARAM_LOOP_LOOPING                      "looping"
 #define WHATPARAM_BUFFERING_UPDATE                  "bufferingUpdate"
 #define WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT "buffUpdateThreshold"
+#define WHATPARAM_ATTACHAUXEFFECT                   "attachAuxEffect"
+#define WHATPARAM_SETAUXEFFECTSENDLEVEL             "setAuxEffectSendLevel"
 
 namespace android {
 
@@ -67,6 +69,8 @@ public:
     virtual void getSampleRate(uint32_t* hz);// hz  != NULL, UNKNOWN_SAMPLERATE if unknown
 
     void setVolume(bool mute, bool useStereoPos, XApermille stereoPos, XAmillibel volume);
+    void attachAuxEffect(int32_t effectId);
+    void setAuxEffectSendLevel(float level);
 
 protected:
     // mutex used for set vs use of volume and cache (fill, threshold) settings
@@ -89,7 +93,9 @@ protected:
         kWhatVolumeUpdate    = 'volu',
         kWhatBufferingUpdate = 'bufu',
         kWhatBuffUpdateThres = 'buut',
-        kWhatMediaPlayerInfo = 'mpin'
+        kWhatMediaPlayerInfo = 'mpin',
+        kWhatAttachAuxEffect = 'aaux',
+        kWhatSetAuxEffectSendLevel = 'saux',
     };
 
     // Send a notification to one of the event listeners
@@ -110,6 +116,8 @@ protected:
     virtual void onSeekComplete();
     virtual void onBufferingUpdate(const sp<AMessage> &msg);
     virtual void onSetBufferingUpdateThreshold(const sp<AMessage> &msg);
+    virtual void onAttachAuxEffect(const sp<AMessage> &msg);
+    virtual void onSetAuxEffectSendLevel(const sp<AMessage> &msg);
 
     // Convenience methods
     //   for async notifications of prefetch status and cache fill level, needs to be called