blob: 7f43347a86cb1f0bc238b037d467765e45c78833 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/* //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
Mathias Agopian75624082009-05-19 19:08:10 -070021#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080022
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;
Eric Laurent5841db72009-09-09 05:16:08 -070084 sp<IMemory> cblk;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurent5841db72009-09-09 05:16:08 -070086 status_t status = remote()->transact(GET_CBLK, data, &reply);
87 if (status == NO_ERROR) {
88 cblk = interface_cast<IMemory>(reply.readStrongBinder());
89 }
90 return cblk;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080091 }
92};
93
94IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack");
95
96// ----------------------------------------------------------------------
97
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098status_t BnAudioTrack::onTransact(
99 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
100{
101 switch(code) {
102 case GET_CBLK: {
103 CHECK_INTERFACE(IAudioTrack, data, reply);
104 reply->writeStrongBinder(getCblk()->asBinder());
105 return NO_ERROR;
106 } break;
107 case START: {
108 CHECK_INTERFACE(IAudioTrack, data, reply);
109 reply->writeInt32(start());
110 return NO_ERROR;
111 } break;
112 case STOP: {
113 CHECK_INTERFACE(IAudioTrack, data, reply);
114 stop();
115 return NO_ERROR;
116 } break;
117 case FLUSH: {
118 CHECK_INTERFACE(IAudioTrack, data, reply);
119 flush();
120 return NO_ERROR;
121 } break;
122 case MUTE: {
123 CHECK_INTERFACE(IAudioTrack, data, reply);
124 mute( data.readInt32() );
125 return NO_ERROR;
126 } break;
127 case PAUSE: {
128 CHECK_INTERFACE(IAudioTrack, data, reply);
129 pause();
130 return NO_ERROR;
131 }
132 default:
133 return BBinder::onTransact(code, data, reply, flags);
134 }
135}
136
137}; // namespace android
138