From 6108105064f935ccd1ff15485700cc8c3328e456 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Tue, 14 Feb 2017 13:45:26 -0800 Subject: [PATCH] VolumeShaper: Add to native IPlayer interface Test: Check proper ducking Bug: 31015569 Change-Id: I679b32a3adbf8ec56bafa20c8479c7645b3d59fa --- include/audiomanager/IPlayer.h | 4 +++ services/audiomanager/IPlayer.cpp | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/audiomanager/IPlayer.h b/include/audiomanager/IPlayer.h index 94afae545d..de5c1c7b64 100644 --- a/include/audiomanager/IPlayer.h +++ b/include/audiomanager/IPlayer.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,9 @@ public: virtual void setStartDelayMs(int delayMs) = 0; + virtual void applyVolumeShaper( + const sp& configuration, + const sp& operation) = 0; }; // ---------------------------------------------------------------------------- diff --git a/services/audiomanager/IPlayer.cpp b/services/audiomanager/IPlayer.cpp index 47edc4bd31..e8a9c3472f 100644 --- a/services/audiomanager/IPlayer.cpp +++ b/services/audiomanager/IPlayer.cpp @@ -35,6 +35,7 @@ enum { SET_VOLUME = IBinder::FIRST_CALL_TRANSACTION + 3, SET_PAN = IBinder::FIRST_CALL_TRANSACTION + 4, SET_START_DELAY_MS = IBinder::FIRST_CALL_TRANSACTION + 5, + APPLY_VOLUME_SHAPER = IBinder::FIRST_CALL_TRANSACTION + 6, }; class BpPlayer : public BpInterface @@ -88,6 +89,36 @@ public: data.writeInt32(delayMs); remote()->transact(SET_START_DELAY_MS, data, &reply); } + + virtual void applyVolumeShaper( + const sp& configuration, + const sp& operation) { + Parcel data, reply; + data.writeInterfaceToken(IPlayer::getInterfaceDescriptor()); + + status_t status = configuration.get() == nullptr + ? data.writeInt32(0) + : data.writeInt32(1) + ?: configuration->writeToParcel(&data); + if (status != NO_ERROR) { + ALOGW("applyVolumeShaper failed configuration parceling: %d", status); + return; // ignore error + } + + status = operation.get() == nullptr + ? status = data.writeInt32(0) + : data.writeInt32(1) + ?: operation->writeToParcel(&data); + if (status != NO_ERROR) { + ALOGW("applyVolumeShaper failed operation parceling: %d", status); + return; // ignore error + } + + status = remote()->transact(APPLY_VOLUME_SHAPER, data, &reply); + + ALOGW_IF(status != NO_ERROR, "applyVolumeShaper failed transact: %d", status); + return; // one way transaction, ignore error + } }; IMPLEMENT_META_INTERFACE(Player, "android.media.IPlayer"); @@ -128,6 +159,28 @@ status_t BnPlayer::onTransact( setStartDelayMs(data.readInt32()); return NO_ERROR; } break; + case APPLY_VOLUME_SHAPER: { + CHECK_INTERFACE(IPlayer, data, reply); + sp configuration; + sp operation; + + int32_t present; + status_t status = data.readInt32(&present); + if (status == NO_ERROR && present != 0) { + configuration = new VolumeShaper::Configuration(); + status = configuration->readFromParcel(data); + } + status = status ?: data.readInt32(&present); + if (status == NO_ERROR && present != 0) { + operation = new VolumeShaper::Operation(); + status = operation->readFromParcel(data); + } + if (status == NO_ERROR) { + // one way transaction, no error returned + applyVolumeShaper(configuration, operation); + } + return NO_ERROR; + } break; default: return BBinder::onTransact(code, data, reply, flags); } -- 2.11.0