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