Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame^] | 1 | /* |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 Laurent | 34f1d8e | 2009-11-04 08:27:26 -0800 | [diff] [blame] | 18 | #define LOG_TAG "IAudioTrack" |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | #include <utils/Log.h> |
| 21 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 25 | #include <binder/Parcel.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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, |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 37 | PAUSE, |
| 38 | ATTACH_AUX_EFFECT |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpAudioTrack : public BpInterface<IAudioTrack> |
| 42 | { |
| 43 | public: |
| 44 | BpAudioTrack(const sp<IBinder>& impl) |
| 45 | : BpInterface<IAudioTrack>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Glenn Kasten | 1099586 | 2012-01-03 14:50:23 -0800 | [diff] [blame] | 49 | 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 | |
Glenn Kasten | 6dbc135 | 2012-02-02 10:56:47 -0800 | [diff] [blame] | 61 | virtual status_t start(pid_t tid) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | { |
| 63 | Parcel data, reply; |
| 64 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
Glenn Kasten | 6dbc135 | 2012-02-02 10:56:47 -0800 | [diff] [blame] | 65 | data.writeInt32(tid); |
Eric Laurent | 34f1d8e | 2009-11-04 08:27:26 -0800 | [diff] [blame] | 66 | status_t status = remote()->transact(START, data, &reply); |
| 67 | if (status == NO_ERROR) { |
| 68 | status = reply.readInt32(); |
| 69 | } else { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 70 | ALOGW("start() error: %s", strerror(-status)); |
Eric Laurent | 34f1d8e | 2009-11-04 08:27:26 -0800 | [diff] [blame] | 71 | } |
| 72 | return status; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | virtual void stop() |
| 76 | { |
| 77 | Parcel data, reply; |
| 78 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
| 79 | remote()->transact(STOP, data, &reply); |
| 80 | } |
| 81 | |
| 82 | virtual void flush() |
| 83 | { |
| 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
| 86 | remote()->transact(FLUSH, data, &reply); |
| 87 | } |
| 88 | |
| 89 | virtual void mute(bool e) |
| 90 | { |
| 91 | Parcel data, reply; |
| 92 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
| 93 | data.writeInt32(e); |
| 94 | remote()->transact(MUTE, data, &reply); |
| 95 | } |
| 96 | |
| 97 | virtual void pause() |
| 98 | { |
| 99 | Parcel data, reply; |
| 100 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
| 101 | remote()->transact(PAUSE, data, &reply); |
| 102 | } |
| 103 | |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 104 | virtual status_t attachAuxEffect(int effectId) |
| 105 | { |
| 106 | Parcel data, reply; |
| 107 | data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); |
| 108 | data.writeInt32(effectId); |
| 109 | status_t status = remote()->transact(ATTACH_AUX_EFFECT, data, &reply); |
| 110 | if (status == NO_ERROR) { |
| 111 | status = reply.readInt32(); |
| 112 | } else { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 113 | ALOGW("attachAuxEffect() error: %s", strerror(-status)); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 114 | } |
| 115 | return status; |
| 116 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack"); |
| 120 | |
| 121 | // ---------------------------------------------------------------------- |
| 122 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | status_t BnAudioTrack::onTransact( |
| 124 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 125 | { |
| 126 | switch(code) { |
| 127 | case GET_CBLK: { |
| 128 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 129 | reply->writeStrongBinder(getCblk()->asBinder()); |
| 130 | return NO_ERROR; |
| 131 | } break; |
| 132 | case START: { |
| 133 | CHECK_INTERFACE(IAudioTrack, data, reply); |
Glenn Kasten | 6dbc135 | 2012-02-02 10:56:47 -0800 | [diff] [blame] | 134 | reply->writeInt32(start(data.readInt32())); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | return NO_ERROR; |
| 136 | } break; |
| 137 | case STOP: { |
| 138 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 139 | stop(); |
| 140 | return NO_ERROR; |
| 141 | } break; |
| 142 | case FLUSH: { |
| 143 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 144 | flush(); |
| 145 | return NO_ERROR; |
| 146 | } break; |
| 147 | case MUTE: { |
| 148 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 149 | mute( data.readInt32() ); |
| 150 | return NO_ERROR; |
| 151 | } break; |
| 152 | case PAUSE: { |
| 153 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 154 | pause(); |
| 155 | return NO_ERROR; |
| 156 | } |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 157 | case ATTACH_AUX_EFFECT: { |
| 158 | CHECK_INTERFACE(IAudioTrack, data, reply); |
| 159 | reply->writeInt32(attachAuxEffect(data.readInt32())); |
| 160 | return NO_ERROR; |
| 161 | } break; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | default: |
| 163 | return BBinder::onTransact(code, data, reply, flags); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | }; // namespace android |
| 168 | |