1 /* //device/extlibs/pv/android/IAudioTrack.cpp
2 **
3 ** Copyright 2007, 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 "IAudioTrack"
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 <media/IAudioTrack.h>
28
29 namespace android {
30
31 enum {
32 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
33 START,
34 STOP,
35 FLUSH,
36 MUTE,
37 PAUSE,
38 ATTACH_AUX_EFFECT
39 };
40
41 class BpAudioTrack : public BpInterface<IAudioTrack>
42 {
43 public:
BpAudioTrack(const sp<IBinder> & impl)44 BpAudioTrack(const sp<IBinder>& impl)
45 : BpInterface<IAudioTrack>(impl)
46 {
47 }
48
start()49 virtual status_t start()
50 {
51 Parcel data, reply;
52 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
53 status_t status = remote()->transact(START, data, &reply);
54 if (status == NO_ERROR) {
55 status = reply.readInt32();
56 } else {
57 LOGW("start() error: %s", strerror(-status));
58 }
59 return status;
60 }
61
stop()62 virtual void stop()
63 {
64 Parcel data, reply;
65 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
66 remote()->transact(STOP, data, &reply);
67 }
68
flush()69 virtual void flush()
70 {
71 Parcel data, reply;
72 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
73 remote()->transact(FLUSH, data, &reply);
74 }
75
mute(bool e)76 virtual void mute(bool e)
77 {
78 Parcel data, reply;
79 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
80 data.writeInt32(e);
81 remote()->transact(MUTE, data, &reply);
82 }
83
pause()84 virtual void pause()
85 {
86 Parcel data, reply;
87 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
88 remote()->transact(PAUSE, data, &reply);
89 }
90
getCblk() const91 virtual sp<IMemory> getCblk() const
92 {
93 Parcel data, reply;
94 sp<IMemory> cblk;
95 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
96 status_t status = remote()->transact(GET_CBLK, data, &reply);
97 if (status == NO_ERROR) {
98 cblk = interface_cast<IMemory>(reply.readStrongBinder());
99 }
100 return cblk;
101 }
102
attachAuxEffect(int effectId)103 virtual status_t attachAuxEffect(int effectId)
104 {
105 Parcel data, reply;
106 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
107 data.writeInt32(effectId);
108 status_t status = remote()->transact(ATTACH_AUX_EFFECT, data, &reply);
109 if (status == NO_ERROR) {
110 status = reply.readInt32();
111 } else {
112 LOGW("attachAuxEffect() error: %s", strerror(-status));
113 }
114 return status;
115 }
116 };
117
118 IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack");
119
120 // ----------------------------------------------------------------------
121
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)122 status_t BnAudioTrack::onTransact(
123 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
124 {
125 switch(code) {
126 case GET_CBLK: {
127 CHECK_INTERFACE(IAudioTrack, data, reply);
128 reply->writeStrongBinder(getCblk()->asBinder());
129 return NO_ERROR;
130 } break;
131 case START: {
132 CHECK_INTERFACE(IAudioTrack, data, reply);
133 reply->writeInt32(start());
134 return NO_ERROR;
135 } break;
136 case STOP: {
137 CHECK_INTERFACE(IAudioTrack, data, reply);
138 stop();
139 return NO_ERROR;
140 } break;
141 case FLUSH: {
142 CHECK_INTERFACE(IAudioTrack, data, reply);
143 flush();
144 return NO_ERROR;
145 } break;
146 case MUTE: {
147 CHECK_INTERFACE(IAudioTrack, data, reply);
148 mute( data.readInt32() );
149 return NO_ERROR;
150 } break;
151 case PAUSE: {
152 CHECK_INTERFACE(IAudioTrack, data, reply);
153 pause();
154 return NO_ERROR;
155 }
156 case ATTACH_AUX_EFFECT: {
157 CHECK_INTERFACE(IAudioTrack, data, reply);
158 reply->writeInt32(attachAuxEffect(data.readInt32()));
159 return NO_ERROR;
160 } break;
161 default:
162 return BBinder::onTransact(code, data, reply, flags);
163 }
164 }
165
166 }; // namespace android
167
168