IAudioTrack.cpp revision 89fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5
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 <utils/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
94#define CHECK_INTERFACE(interface, data, reply) \
95        do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
96            LOGW("Call incorrectly routed to " #interface); \
97            return PERMISSION_DENIED; \
98        } } while (0)
99
100status_t BnAudioTrack::onTransact(
101    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
102{
103    switch(code) {
104       case GET_CBLK: {
105            CHECK_INTERFACE(IAudioTrack, data, reply);
106            reply->writeStrongBinder(getCblk()->asBinder());
107            return NO_ERROR;
108        } break;
109        case START: {
110            CHECK_INTERFACE(IAudioTrack, data, reply);
111            reply->writeInt32(start());
112            return NO_ERROR;
113        } break;
114        case STOP: {
115            CHECK_INTERFACE(IAudioTrack, data, reply);
116            stop();
117            return NO_ERROR;
118        } break;
119        case FLUSH: {
120            CHECK_INTERFACE(IAudioTrack, data, reply);
121            flush();
122            return NO_ERROR;
123        } break;
124        case MUTE: {
125            CHECK_INTERFACE(IAudioTrack, data, reply);
126            mute( data.readInt32() );
127            return NO_ERROR;
128        } break;
129        case PAUSE: {
130            CHECK_INTERFACE(IAudioTrack, data, reply);
131            pause();
132            return NO_ERROR;
133        }
134        default:
135            return BBinder::onTransact(code, data, reply, flags);
136    }
137}
138
139}; // namespace android
140
141