blob: 47edc4bd31b4fd7ef019c5a4492fb902ad434838 [file] [log] [blame]
Jean-Michel Trivi63189322017-01-05 18:05:28 -08001/*
2**
3** Copyright 2017, The Android Open Source Project
4**
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
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
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.
16*/
17
18#define LOG_TAG "IPlayer"
19//#define LOG_NDEBUG 0
20#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
25#include <binder/Parcel.h>
26
27#include <audiomanager/IPlayer.h>
28
29namespace android {
30
31enum {
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,
Jean-Michel Trivi1c762772017-02-01 14:55:51 -080036 SET_PAN = IBinder::FIRST_CALL_TRANSACTION + 4,
37 SET_START_DELAY_MS = IBinder::FIRST_CALL_TRANSACTION + 5,
Jean-Michel Trivi63189322017-01-05 18:05:28 -080038};
39
40class BpPlayer : public BpInterface<IPlayer>
41{
42public:
43 explicit BpPlayer(const sp<IBinder>& impl)
44 : BpInterface<IPlayer>(impl)
45 {
46 }
47
48 virtual void start()
49 {
50 Parcel data, reply;
51 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
52 remote()->transact(START, data, &reply);
53 }
54
55 virtual void pause()
56 {
57 Parcel data, reply;
58 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
59 remote()->transact(PAUSE, data, &reply);
60 }
61
62 virtual void stop()
63 {
64 Parcel data, reply;
65 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
66 remote()->transact(STOP, data, &reply);
67 }
68
69 virtual void setVolume(float vol)
70 {
71 Parcel data, reply;
72 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
73 data.writeFloat(vol);
74 remote()->transact(SET_VOLUME, data, &reply);
75 }
Jean-Michel Trivi1c762772017-02-01 14:55:51 -080076
77 virtual void setPan(float pan)
78 {
79 Parcel data, reply;
80 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
81 data.writeFloat(pan);
82 remote()->transact(SET_PAN, data, &reply);
83 }
84
85 virtual void setStartDelayMs(int32_t delayMs) {
86 Parcel data, reply;
87 data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());
88 data.writeInt32(delayMs);
89 remote()->transact(SET_START_DELAY_MS, data, &reply);
90 }
Jean-Michel Trivi63189322017-01-05 18:05:28 -080091};
92
93IMPLEMENT_META_INTERFACE(Player, "android.media.IPlayer");
94
95// ----------------------------------------------------------------------
96
97status_t BnPlayer::onTransact(
98 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
99{
100 switch (code) {
101 case START: {
102 CHECK_INTERFACE(IPlayer, data, reply);
103 start();
104 return NO_ERROR;
105 } break;
106 case PAUSE: {
107 CHECK_INTERFACE(IPlayer, data, reply);
108 pause();
109 return NO_ERROR;
110 }
111 case STOP: {
112 CHECK_INTERFACE(IPlayer, data, reply);
113 stop();
114 return NO_ERROR;
115 } break;
116 case SET_VOLUME: {
117 CHECK_INTERFACE(IPlayer, data, reply);
118 setVolume(data.readFloat());
119 return NO_ERROR;
Jean-Michel Trivi1c762772017-02-01 14:55:51 -0800120 } break;
121 case SET_PAN: {
122 CHECK_INTERFACE(IPlayer, data, reply);
123 setPan(data.readFloat());
124 return NO_ERROR;
125 } break;
126 case SET_START_DELAY_MS: {
127 CHECK_INTERFACE(IPlayer, data, reply);
128 setStartDelayMs(data.readInt32());
129 return NO_ERROR;
130 } break;
Jean-Michel Trivi63189322017-01-05 18:05:28 -0800131 default:
132 return BBinder::onTransact(code, data, reply, flags);
133 }
134}
135
136} // namespace android