IAudioRecord.cpp revision 6dbc1359f778575d09d6da722b060a6d72c2e7c5
1/* 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 "IAudioRecord" 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/IAudioRecord.h> 28 29namespace android { 30 31enum { 32 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION, 33 START, 34 STOP 35}; 36 37class BpAudioRecord : public BpInterface<IAudioRecord> 38{ 39public: 40 BpAudioRecord(const sp<IBinder>& impl) 41 : BpInterface<IAudioRecord>(impl) 42 { 43 } 44 45 virtual status_t start(pid_t tid) 46 { 47 Parcel data, reply; 48 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor()); 49 data.writeInt32(tid); 50 status_t status = remote()->transact(START, data, &reply); 51 if (status == NO_ERROR) { 52 status = reply.readInt32(); 53 } else { 54 ALOGW("start() error: %s", strerror(-status)); 55 } 56 return status; 57 } 58 59 virtual void stop() 60 { 61 Parcel data, reply; 62 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor()); 63 remote()->transact(STOP, data, &reply); 64 } 65 66 virtual sp<IMemory> getCblk() const 67 { 68 Parcel data, reply; 69 sp<IMemory> cblk; 70 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor()); 71 status_t status = remote()->transact(GET_CBLK, data, &reply); 72 if (status == NO_ERROR) { 73 cblk = interface_cast<IMemory>(reply.readStrongBinder()); 74 } 75 return cblk; 76 } 77}; 78 79IMPLEMENT_META_INTERFACE(AudioRecord, "android.media.IAudioRecord"); 80 81// ---------------------------------------------------------------------- 82 83status_t BnAudioRecord::onTransact( 84 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 85{ 86 switch(code) { 87 case GET_CBLK: { 88 CHECK_INTERFACE(IAudioRecord, data, reply); 89 reply->writeStrongBinder(getCblk()->asBinder()); 90 return NO_ERROR; 91 } break; 92 case START: { 93 CHECK_INTERFACE(IAudioRecord, data, reply); 94 reply->writeInt32(start(data.readInt32())); 95 return NO_ERROR; 96 } break; 97 case STOP: { 98 CHECK_INTERFACE(IAudioRecord, data, reply); 99 stop(); 100 return NO_ERROR; 101 } break; 102 default: 103 return BBinder::onTransact(code, data, reply, flags); 104 } 105} 106 107}; // namespace android 108 109