blob: 01ffd75e56c5bcb018eb30cf696bc5d844b1d0cf [file] [log] [blame]
The Android Open Source Project9066cfe2009-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
Eric Laurentbda74692009-11-04 08:27:26 -080018#define LOG_TAG "IAudioTrack"
19//#define LOG_NDEBUG 0
20#include <utils/Log.h>
21
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian07952722009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
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};
39
40class BpAudioTrack : public BpInterface<IAudioTrack>
41{
42public:
43 BpAudioTrack(const sp<IBinder>& impl)
44 : BpInterface<IAudioTrack>(impl)
45 {
46 }
47
48 virtual status_t start()
49 {
50 Parcel data, reply;
51 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurentbda74692009-11-04 08:27:26 -080052 status_t status = remote()->transact(START, data, &reply);
53 if (status == NO_ERROR) {
54 status = reply.readInt32();
55 } else {
56 LOGW("start() error: %s", strerror(-status));
57 }
58 return status;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 }
60
61 virtual void stop()
62 {
63 Parcel data, reply;
64 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
65 remote()->transact(STOP, data, &reply);
66 }
67
68 virtual void flush()
69 {
70 Parcel data, reply;
71 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
72 remote()->transact(FLUSH, data, &reply);
73 }
74
75 virtual void mute(bool e)
76 {
77 Parcel data, reply;
78 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
79 data.writeInt32(e);
80 remote()->transact(MUTE, data, &reply);
81 }
82
83 virtual void pause()
84 {
85 Parcel data, reply;
86 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
87 remote()->transact(PAUSE, data, &reply);
88 }
89
90 virtual sp<IMemory> getCblk() const
91 {
92 Parcel data, reply;
Eric Laurent8a77a992009-09-09 05:16:08 -070093 sp<IMemory> cblk;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 data.writeInterfaceToken(IAudioTrack::getInterfaceDescriptor());
Eric Laurent8a77a992009-09-09 05:16:08 -070095 status_t status = remote()->transact(GET_CBLK, data, &reply);
96 if (status == NO_ERROR) {
97 cblk = interface_cast<IMemory>(reply.readStrongBinder());
98 }
99 return cblk;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
101};
102
103IMPLEMENT_META_INTERFACE(AudioTrack, "android.media.IAudioTrack");
104
105// ----------------------------------------------------------------------
106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107status_t BnAudioTrack::onTransact(
108 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
109{
110 switch(code) {
111 case GET_CBLK: {
112 CHECK_INTERFACE(IAudioTrack, data, reply);
113 reply->writeStrongBinder(getCblk()->asBinder());
114 return NO_ERROR;
115 } break;
116 case START: {
117 CHECK_INTERFACE(IAudioTrack, data, reply);
118 reply->writeInt32(start());
119 return NO_ERROR;
120 } break;
121 case STOP: {
122 CHECK_INTERFACE(IAudioTrack, data, reply);
123 stop();
124 return NO_ERROR;
125 } break;
126 case FLUSH: {
127 CHECK_INTERFACE(IAudioTrack, data, reply);
128 flush();
129 return NO_ERROR;
130 } break;
131 case MUTE: {
132 CHECK_INTERFACE(IAudioTrack, data, reply);
133 mute( data.readInt32() );
134 return NO_ERROR;
135 } break;
136 case PAUSE: {
137 CHECK_INTERFACE(IAudioTrack, data, reply);
138 pause();
139 return NO_ERROR;
140 }
141 default:
142 return BBinder::onTransact(code, data, reply, flags);
143 }
144}
145
146}; // namespace android
147