IAudioTrack.cpp revision b7056fc8525e0515c6f46676e3307088f8b64cdc
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#include <stdint.h> 19#include <sys/types.h> 20 21#include <binder/Parcel.h> 22 23#include <media/IAudioTrack.h> 24 25namespace android { 26 27enum { 28 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION, 29 START, 30 STOP, 31 FLUSH, 32 MUTE, 33 PAUSE 34}; 35 36class BpAudioTrack : public BpInterface<IAudioTrack> 37{ 38public: 39 BpAudioTrack(const sp<IBinder>& impl) 40 : BpInterface<IAudioTrack>(impl) 41 { 42 } 43 44 virtual status_t start() 45 { 46 Parcel data, reply; 47 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 48 remote()->transact(START, data, &reply); 49 return reply.readInt32(); 50 } 51 52 virtual void stop() 53 { 54 Parcel data, reply; 55 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 56 remote()->transact(STOP, data, &reply); 57 } 58 59 virtual void flush() 60 { 61 Parcel data, reply; 62 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 63 remote()->transact(FLUSH, data, &reply); 64 } 65 66 virtual void mute(bool e) 67 { 68 Parcel data, reply; 69 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 70 data.writeInt32(e); 71 remote()->transact(MUTE, data, &reply); 72 } 73 74 virtual void pause() 75 { 76 Parcel data, reply; 77 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 78 remote()->transact(PAUSE, data, &reply); 79 } 80 81 virtual sp<IMemory> getCblk() const 82 { 83 Parcel data, reply; 84 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor()); 85 remote()->transact(GET_CBLK, data, &reply); 86 return interface_cast<IMemory>(reply.readStrongBinder()); 87 } 88}; 89 90IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack"); 91 92// ---------------------------------------------------------------------- 93 94status_t BnAudioTrack::onTransact( 95 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 96{ 97 switch(code) { 98 case GET_CBLK: { 99 CHECK_INTERFACE(IAudioTrack, data, reply); 100 reply->writeStrongBinder(getCblk()->asBinder()); 101 return NO_ERROR; 102 } break; 103 case START: { 104 CHECK_INTERFACE(IAudioTrack, data, reply); 105 reply->writeInt32(start()); 106 return NO_ERROR; 107 } break; 108 case STOP: { 109 CHECK_INTERFACE(IAudioTrack, data, reply); 110 stop(); 111 return NO_ERROR; 112 } break; 113 case FLUSH: { 114 CHECK_INTERFACE(IAudioTrack, data, reply); 115 flush(); 116 return NO_ERROR; 117 } break; 118 case MUTE: { 119 CHECK_INTERFACE(IAudioTrack, data, reply); 120 mute( data.readInt32() ); 121 return NO_ERROR; 122 } break; 123 case PAUSE: { 124 CHECK_INTERFACE(IAudioTrack, data, reply); 125 pause(); 126 return NO_ERROR; 127 } 128 default: 129 return BBinder::onTransact(code, data, reply, flags); 130 } 131} 132 133}; // namespace android 134 135