IAudioTrack.cpp revision 6dbc1359f778575d09d6da722b060a6d72c2e7c5
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 29namespace android { 30 31enum { 32 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION, 33 START, 34 STOP, 35 FLUSH, 36 MUTE, 37 PAUSE, 38 ATTACH_AUX_EFFECT 39}; 40 41class BpAudioTrack : public BpInterface<IAudioTrack> 42{ 43public: 44 BpAudioTrack(const sp<IBinder>& impl) 45 : BpInterface<IAudioTrack>(impl) 46 { 47 } 48 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 61 virtual status_t start(pid_t tid) 62 { 63 Parcel data, reply; 64 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 65 data.writeInt32(tid); 66 status_t status = remote()->transact(START, data, &reply); 67 if (status == NO_ERROR) { 68 status = reply.readInt32(); 69 } else { 70 ALOGW("start() error: %s", strerror(-status)); 71 } 72 return status; 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 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 { 113 ALOGW("attachAuxEffect() error: %s", strerror(-status)); 114 } 115 return status; 116 } 117}; 118 119IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack"); 120 121// ---------------------------------------------------------------------- 122 123status_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); 134 reply->writeInt32(start(data.readInt32())); 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 } 157 case ATTACH_AUX_EFFECT: { 158 CHECK_INTERFACE(IAudioTrack, data, reply); 159 reply->writeInt32(attachAuxEffect(data.readInt32())); 160 return NO_ERROR; 161 } break; 162 default: 163 return BBinder::onTransact(code, data, reply, flags); 164 } 165} 166 167}; // namespace android 168 169