blob: bc8ff34182a449585d2ae0dc66b6b1be42ccb811 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Laurentbda74692009-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 Project9066cfe2009-03-03 19:31:44 -080022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian07952722009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-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 Laurent65b65452010-06-01 23:49:17 -070037 PAUSE,
38 ATTACH_AUX_EFFECT
The Android Open Source Project9066cfe2009-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
49 virtual status_t start()
50 {
51 Parcel data, reply;
52 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurentbda74692009-11-04 08:27:26 -080053 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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 }
61
62 virtual void stop()
63 {
64 Parcel data, reply;
65 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
66 remote()->transact(STOP, data, &reply);
67 }
68
69 virtual void flush()
70 {
71 Parcel data, reply;
72 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
73 remote()->transact(FLUSH, data, &reply);
74 }
75
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
84 virtual void pause()
85 {
86 Parcel data, reply;
87 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
88 remote()->transact(PAUSE, data, &reply);
89 }
90
91 virtual sp<IMemory> getCblk() const
92 {
93 Parcel data, reply;
Eric Laurent8a77a992009-09-09 05:16:08 -070094 sp<IMemory> cblk;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurent8a77a992009-09-09 05:16:08 -070096 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;
Eric Laurent65b65452010-06-01 23:49:17 -0700101 }
102
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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116};
117
118IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack");
119
120// ----------------------------------------------------------------------
121
The Android Open Source Project9066cfe2009-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 Laurent65b65452010-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 Project9066cfe2009-03-03 19:31:44 -0800161 default:
162 return BBinder::onTransact(code, data, reply, flags);
163 }
164}
165
166}; // namespace android
167