3 ** Copyright 2017, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "IPlayer"
19 //#define LOG_NDEBUG 0
20 #include <utils/Log.h>
23 #include <sys/types.h>
25 #include <binder/Parcel.h>
27 #include <audiomanager/IPlayer.h>
32 START = IBinder::FIRST_CALL_TRANSACTION,
33 PAUSE = IBinder::FIRST_CALL_TRANSACTION + 1,
34 STOP = IBinder::FIRST_CALL_TRANSACTION + 2,
35 SET_VOLUME = IBinder::FIRST_CALL_TRANSACTION + 3,
36 SET_PAN = IBinder::FIRST_CALL_TRANSACTION + 4,
37 SET_START_DELAY_MS = IBinder::FIRST_CALL_TRANSACTION + 5,
38 APPLY_VOLUME_SHAPER = IBinder::FIRST_CALL_TRANSACTION + 6,
41 class BpPlayer : public BpInterface<IPlayer>
44 explicit BpPlayer(const sp<IBinder>& impl)
45 : BpInterface<IPlayer>(impl)
52 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
53 remote()->transact(START, data, &reply);
59 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
60 remote()->transact(PAUSE, data, &reply);
66 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
67 remote()->transact(STOP, data, &reply);
70 virtual void setVolume(float vol)
73 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
75 remote()->transact(SET_VOLUME, data, &reply);
78 virtual void setPan(float pan)
81 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
83 remote()->transact(SET_PAN, data, &reply);
86 virtual void setStartDelayMs(int32_t delayMs) {
88 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
89 data.writeInt32(delayMs);
90 remote()->transact(SET_START_DELAY_MS, data, &reply);
93 virtual void applyVolumeShaper(
94 const sp<VolumeShaper::Configuration>& configuration,
95 const sp<VolumeShaper::Operation>& operation) {
97 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
99 status_t status = configuration.get() == nullptr
102 ?: configuration->writeToParcel(&data);
103 if (status != NO_ERROR) {
104 ALOGW("applyVolumeShaper failed configuration parceling: %d", status);
105 return; // ignore error
108 status = operation.get() == nullptr
109 ? status = data.writeInt32(0)
111 ?: operation->writeToParcel(&data);
112 if (status != NO_ERROR) {
113 ALOGW("applyVolumeShaper failed operation parceling: %d", status);
114 return; // ignore error
117 status = remote()->transact(APPLY_VOLUME_SHAPER, data, &reply);
119 ALOGW_IF(status != NO_ERROR, "applyVolumeShaper failed transact: %d", status);
120 return; // one way transaction, ignore error
124 IMPLEMENT_META_INTERFACE(Player, "android.media.IPlayer");
126 // ----------------------------------------------------------------------
128 status_t BnPlayer::onTransact(
129 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
133 CHECK_INTERFACE(IPlayer, data, reply);
138 CHECK_INTERFACE(IPlayer, data, reply);
143 CHECK_INTERFACE(IPlayer, data, reply);
148 CHECK_INTERFACE(IPlayer, data, reply);
149 setVolume(data.readFloat());
153 CHECK_INTERFACE(IPlayer, data, reply);
154 setPan(data.readFloat());
157 case SET_START_DELAY_MS: {
158 CHECK_INTERFACE(IPlayer, data, reply);
159 setStartDelayMs(data.readInt32());
162 case APPLY_VOLUME_SHAPER: {
163 CHECK_INTERFACE(IPlayer, data, reply);
164 sp<VolumeShaper::Configuration> configuration;
165 sp<VolumeShaper::Operation> operation;
168 status_t status = data.readInt32(&present);
169 if (status == NO_ERROR && present != 0) {
170 configuration = new VolumeShaper::Configuration();
171 status = configuration->readFromParcel(data);
173 status = status ?: data.readInt32(&present);
174 if (status == NO_ERROR && present != 0) {
175 operation = new VolumeShaper::Operation();
176 status = operation->readFromParcel(data);
178 if (status == NO_ERROR) {
179 // one way transaction, no error returned
180 applyVolumeShaper(configuration, operation);
185 return BBinder::onTransact(code, data, reply, flags);
189 } // namespace android