189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project/*
289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** Copyright 2007, The Android Open Source Project
489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
5e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** Licensed under the Apache License, Version 2.0 (the "License");
6e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** you may not use this file except in compliance with the License.
7e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** You may obtain a copy of the License at
889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
9e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten**     http://www.apache.org/licenses/LICENSE-2.0
1089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project**
11e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** Unless required by applicable law or agreed to in writing, software
12e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** distributed under the License is distributed on an "AS IS" BASIS,
13e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten** See the License for the specific language governing permissions and
1589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project** limitations under the License.
1689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project*/
1789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1834f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent#define LOG_TAG "IAudioRecord"
1934f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent//#define LOG_NDEBUG 0
2034f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent#include <utils/Log.h>
2134f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent
2289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <stdint.h>
2389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <sys/types.h>
2489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
257562408b2261d38415453378b6188f74fda99d88Mathias Agopian#include <binder/Parcel.h>
2689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <media/IAudioRecord.h>
2889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectnamespace android {
3089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
3189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectenum {
3289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
3389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    START,
3489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    STOP
3589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
3689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
3789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass BpAudioRecord : public BpInterface<IAudioRecord>
3889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic:
4089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    BpAudioRecord(const sp<IBinder>& impl)
4189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        : BpInterface<IAudioRecord>(impl)
4289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
4389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
44e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten
450ec23ce0d1ff79566c402bc30df3074f6e25a22bGlenn Kasten    virtual status_t start(int /*AudioSystem::sync_event_t*/ event, int triggerSession)
4689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
4789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        Parcel data, reply;
4889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
49a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        data.writeInt32(event);
50a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        data.writeInt32(triggerSession);
5134f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent        status_t status = remote()->transact(START, data, &reply);
5234f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent        if (status == NO_ERROR) {
5334f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent            status = reply.readInt32();
5434f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent        } else {
555ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block            ALOGW("start() error: %s", strerror(-status));
5634f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent        }
5734f1d8ecd23169a5f299937e3aaf1bd7937578a0Eric Laurent        return status;
5889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
59e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten
6089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual void stop()
6189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
6289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        Parcel data, reply;
6389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
6489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        remote()->transact(STOP, data, &reply);
6589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
66e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten
6789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual sp<IMemory> getCblk() const
6889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
6989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        Parcel data, reply;
705841db78dff14898538200287d246577b1fc37e2Eric Laurent        sp<IMemory> cblk;
7189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
725841db78dff14898538200287d246577b1fc37e2Eric Laurent        status_t status = remote()->transact(GET_CBLK, data, &reply);
735841db78dff14898538200287d246577b1fc37e2Eric Laurent        if (status == NO_ERROR) {
745841db78dff14898538200287d246577b1fc37e2Eric Laurent            cblk = interface_cast<IMemory>(reply.readStrongBinder());
755841db78dff14898538200287d246577b1fc37e2Eric Laurent        }
765841db78dff14898538200287d246577b1fc37e2Eric Laurent        return cblk;
77e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten    }
7889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
7989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
8089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source ProjectIMPLEMENT_META_INTERFACE(AudioRecord, "android.media.IAudioRecord");
8189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
8289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// ----------------------------------------------------------------------
8389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
8489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectstatus_t BnAudioRecord::onTransact(
8589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
8689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
87e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten    switch (code) {
88e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten        case GET_CBLK: {
8989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            CHECK_INTERFACE(IAudioRecord, data, reply);
9089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            reply->writeStrongBinder(getCblk()->asBinder());
9189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return NO_ERROR;
9289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } break;
9389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        case START: {
9489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            CHECK_INTERFACE(IAudioRecord, data, reply);
950ec23ce0d1ff79566c402bc30df3074f6e25a22bGlenn Kasten            int /*AudioSystem::sync_event_t*/ event = data.readInt32();
9677d837ae86c791c46ce019b58e09ac62780bf973Glenn Kasten            int triggerSession = data.readInt32();
973acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten            reply->writeInt32(start(event, triggerSession));
9889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return NO_ERROR;
9989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } break;
10089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        case STOP: {
10189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            CHECK_INTERFACE(IAudioRecord, data, reply);
10289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            stop();
10389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return NO_ERROR;
10489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        } break;
10589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        default:
10689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project            return BBinder::onTransact(code, data, reply, flags);
10789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    }
10889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}
10989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
11089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}; // namespace android
111