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
29 namespace android {
30
31 enum {
32 UNUSED_WAS_GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
33 START,
34 STOP
35 };
36
37 class BpAudioRecord : public BpInterface<IAudioRecord>
38 {
39 public:
BpAudioRecord(const sp<IBinder> & impl)40 BpAudioRecord(const sp<IBinder>& impl)
41 : BpInterface<IAudioRecord>(impl)
42 {
43 }
44
start(int event,audio_session_t triggerSession)45 virtual status_t start(int /*AudioSystem::sync_event_t*/ event, audio_session_t triggerSession)
46 {
47 Parcel data, reply;
48 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
49 data.writeInt32(event);
50 data.writeInt32(triggerSession);
51 status_t status = remote()->transact(START, data, &reply);
52 if (status == NO_ERROR) {
53 status = reply.readInt32();
54 } else {
55 ALOGW("start() error: %s", strerror(-status));
56 }
57 return status;
58 }
59
stop()60 virtual void stop()
61 {
62 Parcel data, reply;
63 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
64 remote()->transact(STOP, data, &reply);
65 }
66
67 };
68
69 IMPLEMENT_META_INTERFACE(AudioRecord, "android.media.IAudioRecord");
70
71 // ----------------------------------------------------------------------
72
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)73 status_t BnAudioRecord::onTransact(
74 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
75 {
76 switch (code) {
77 case START: {
78 CHECK_INTERFACE(IAudioRecord, data, reply);
79 int /*AudioSystem::sync_event_t*/ event = data.readInt32();
80 audio_session_t triggerSession = (audio_session_t) data.readInt32();
81 reply->writeInt32(start(event, triggerSession));
82 return NO_ERROR;
83 } break;
84 case STOP: {
85 CHECK_INTERFACE(IAudioRecord, data, reply);
86 stop();
87 return NO_ERROR;
88 } break;
89 default:
90 return BBinder::onTransact(code, data, reply, flags);
91 }
92 }
93
94 } // namespace android
95