blob: 07914379e99091b6ec1c6d8f85e0b2cb72af938a [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/* //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
Eric Laurent34f1d8e2009-11-04 08:27:26 -080018#define LOG_TAG "IAudioTrack"
19//#define LOG_NDEBUG 0
20#include <utils/Log.h>
21
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioTrack.h>
28
29namespace android {
30
31enum {
32 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
33 START,
34 STOP,
35 FLUSH,
36 MUTE,
Eric Laurentbe916aa2010-06-01 23:49:17 -070037 PAUSE,
38 ATTACH_AUX_EFFECT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080039};
40
41class BpAudioTrack : public BpInterface<IAudioTrack>
42{
43public:
44 BpAudioTrack(const sp<IBinder>& impl)
45 : BpInterface<IAudioTrack>(impl)
46 {
47 }
48
Glenn Kasten10995862012-01-03 14:50:23 -080049 virtual sp<IMemory> getCblk() const
50 {
51 Parcel data, reply;
52 sp<IMemory> cblk;
53 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
54 status_t status = remote()->transact(GET_CBLK, data, &reply);
55 if (status == NO_ERROR) {
56 cblk = interface_cast<IMemory>(reply.readStrongBinder());
57 }
58 return cblk;
59 }
60
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080061 virtual status_t start()
62 {
63 Parcel data, reply;
64 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurent34f1d8e2009-11-04 08:27:26 -080065 status_t status = remote()->transact(START, data, &reply);
66 if (status == NO_ERROR) {
67 status = reply.readInt32();
68 } else {
69 LOGW("start() error: %s", strerror(-status));
70 }
71 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 }
73
74 virtual void stop()
75 {
76 Parcel data, reply;
77 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
78 remote()->transact(STOP, data, &reply);
79 }
80
81 virtual void flush()
82 {
83 Parcel data, reply;
84 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
85 remote()->transact(FLUSH, data, &reply);
86 }
87
88 virtual void mute(bool e)
89 {
90 Parcel data, reply;
91 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
92 data.writeInt32(e);
93 remote()->transact(MUTE, data, &reply);
94 }
95
96 virtual void pause()
97 {
98 Parcel data, reply;
99 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
100 remote()->transact(PAUSE, data, &reply);
101 }
102
Eric Laurentbe916aa2010-06-01 23:49:17 -0700103 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 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116};
117
118IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack");
119
120// ----------------------------------------------------------------------
121
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800122status_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 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700156 case ATTACH_AUX_EFFECT: {
157 CHECK_INTERFACE(IAudioTrack, data, reply);
158 reply->writeInt32(attachAuxEffect(data.readInt32()));
159 return NO_ERROR;
160 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800161 default:
162 return BBinder::onTransact(code, data, reply, flags);
163 }
164}
165
166}; // namespace android
167