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