blob: e289703fc4fdb4a228a6f97d7694a99c6ece44ca [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
vivek mehta2192bc92012-12-04 11:46:08 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
3 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08006 * Copyright (C) 2009 The Android Open Source Project
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#define LOG_TAG "IAudioFlingerClient"
22#include <utils/Log.h>
23
24#include <stdint.h>
25#include <sys/types.h>
26
Mathias Agopian75624082009-05-19 19:08:10 -070027#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028
29#include <media/IAudioFlingerClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070030#include <media/AudioSystem.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080031
32namespace android {
33
34enum {
Eric Laurentc2f1f072009-07-17 12:17:14 -070035 IO_CONFIG_CHANGED = IBinder::FIRST_CALL_TRANSACTION
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036};
37
38class BpAudioFlingerClient : public BpInterface<IAudioFlingerClient>
39{
40public:
41 BpAudioFlingerClient(const sp<IBinder>& impl)
42 : BpInterface<IAudioFlingerClient>(impl)
43 {
44 }
45
Glenn Kastenb81cc8c2012-03-01 09:14:51 -080046 void ioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080047 {
48 Parcel data, reply;
49 data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 data.writeInt32(event);
Glenn Kasten72ef00d2012-01-17 11:09:42 -080051 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -070052 if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
Glenn Kastenb81cc8c2012-03-01 09:14:51 -080053 uint32_t stream = *(const uint32_t *)param2;
Steve Block3856b092011-10-20 11:56:00 +010054 ALOGV("ioConfigChanged stream %d", stream);
Eric Laurentc2f1f072009-07-17 12:17:14 -070055 data.writeInt32(stream);
vivek mehta2192bc92012-12-04 11:46:08 -080056 } else if (event != AudioSystem::OUTPUT_CLOSED &&
57#ifdef QCOM_HARDWARE
58 event != AudioSystem::EFFECT_CONFIG_CHANGED &&
59#endif
60 event != AudioSystem::INPUT_CLOSED) {
Glenn Kastenb81cc8c2012-03-01 09:14:51 -080061 const AudioSystem::OutputDescriptor *desc = (const AudioSystem::OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -070062 data.writeInt32(desc->samplingRate);
63 data.writeInt32(desc->format);
64 data.writeInt32(desc->channels);
65 data.writeInt32(desc->frameCount);
66 data.writeInt32(desc->latency);
67 }
68 remote()->transact(IO_CONFIG_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069 }
70};
71
72IMPLEMENT_META_INTERFACE(AudioFlingerClient, "android.media.IAudioFlingerClient");
73
74// ----------------------------------------------------------------------
75
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080076status_t BnAudioFlingerClient::onTransact(
77 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
78{
Glenn Kastene53b9ea2012-03-12 16:29:55 -070079 switch (code) {
Eric Laurentc2f1f072009-07-17 12:17:14 -070080 case IO_CONFIG_CHANGED: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080081 CHECK_INTERFACE(IAudioFlingerClient, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -070082 int event = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -080083 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kastenb81cc8c2012-03-01 09:14:51 -080084 const void *param2 = NULL;
Eric Laurentc2f1f072009-07-17 12:17:14 -070085 AudioSystem::OutputDescriptor desc;
86 uint32_t stream;
Eric Laurentc2f1f072009-07-17 12:17:14 -070087 if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
88 stream = data.readInt32();
89 param2 = &stream;
Steve Block3856b092011-10-20 11:56:00 +010090 ALOGV("STREAM_CONFIG_CHANGED stream %d", stream);
Eric Laurentc2f1f072009-07-17 12:17:14 -070091 } else if (event != AudioSystem::OUTPUT_CLOSED && event != AudioSystem::INPUT_CLOSED) {
92 desc.samplingRate = data.readInt32();
93 desc.format = data.readInt32();
94 desc.channels = data.readInt32();
95 desc.frameCount = data.readInt32();
96 desc.latency = data.readInt32();
97 param2 = &desc;
98 }
Eric Laurentfa2877b2009-07-28 08:44:33 -070099 ioConfigChanged(event, ioHandle, param2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 return NO_ERROR;
101 } break;
102 default:
103 return BBinder::onTransact(code, data, reply, flags);
104 }
105}
106
107// ----------------------------------------------------------------------------
108
109}; // namespace android