blob: 4178b2938faa0a4202fffa0e98e9d1399eb6d4d8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "IAudioFlingerClient"
18#include <utils/Log.h>
19
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25#include <media/IAudioFlingerClient.h>
Eric Laurenta553c252009-07-17 12:17:14 -070026#include <media/AudioSystem.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28namespace android {
29
30enum {
Eric Laurenta553c252009-07-17 12:17:14 -070031 IO_CONFIG_CHANGED = IBinder::FIRST_CALL_TRANSACTION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032};
33
34class BpAudioFlingerClient : public BpInterface<IAudioFlingerClient>
35{
36public:
37 BpAudioFlingerClient(const sp<IBinder>& impl)
38 : BpInterface<IAudioFlingerClient>(impl)
39 {
40 }
41
Glenn Kastenffed04a2012-03-01 09:14:51 -080042 void ioConfigChanged(int event, audio_io_handle_t ioHandle, const void *param2)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 {
44 Parcel data, reply;
45 data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
Eric Laurenta553c252009-07-17 12:17:14 -070046 data.writeInt32(event);
Glenn Kasten39d00cb2012-01-17 11:09:42 -080047 data.writeInt32((int32_t) ioHandle);
Eric Laurenta553c252009-07-17 12:17:14 -070048 if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
Glenn Kastenffed04a2012-03-01 09:14:51 -080049 uint32_t stream = *(const uint32_t *)param2;
Steve Block71f2cf12011-10-20 11:56:00 +010050 ALOGV("ioConfigChanged stream %d", stream);
Eric Laurenta553c252009-07-17 12:17:14 -070051 data.writeInt32(stream);
52 } else if (event != AudioSystem::OUTPUT_CLOSED && event != AudioSystem::INPUT_CLOSED) {
Glenn Kastenffed04a2012-03-01 09:14:51 -080053 const AudioSystem::OutputDescriptor *desc = (const AudioSystem::OutputDescriptor *)param2;
Eric Laurenta553c252009-07-17 12:17:14 -070054 data.writeInt32(desc->samplingRate);
55 data.writeInt32(desc->format);
56 data.writeInt32(desc->channels);
57 data.writeInt32(desc->frameCount);
58 data.writeInt32(desc->latency);
59 }
60 remote()->transact(IO_CONFIG_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 }
62};
63
64IMPLEMENT_META_INTERFACE(AudioFlingerClient, "android.media.IAudioFlingerClient");
65
66// ----------------------------------------------------------------------
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068status_t BnAudioFlingerClient::onTransact(
69 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
70{
Glenn Kasten18db49a2012-03-12 16:29:55 -070071 switch (code) {
Eric Laurenta553c252009-07-17 12:17:14 -070072 case IO_CONFIG_CHANGED: {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 CHECK_INTERFACE(IAudioFlingerClient, data, reply);
Eric Laurenta553c252009-07-17 12:17:14 -070074 int event = data.readInt32();
Glenn Kasten39d00cb2012-01-17 11:09:42 -080075 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kastenffed04a2012-03-01 09:14:51 -080076 const void *param2 = NULL;
Eric Laurenta553c252009-07-17 12:17:14 -070077 AudioSystem::OutputDescriptor desc;
78 uint32_t stream;
Eric Laurenta553c252009-07-17 12:17:14 -070079 if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
80 stream = data.readInt32();
81 param2 = &stream;
Steve Block71f2cf12011-10-20 11:56:00 +010082 ALOGV("STREAM_CONFIG_CHANGED stream %d", stream);
Eric Laurenta553c252009-07-17 12:17:14 -070083 } else if (event != AudioSystem::OUTPUT_CLOSED && event != AudioSystem::INPUT_CLOSED) {
84 desc.samplingRate = data.readInt32();
85 desc.format = data.readInt32();
86 desc.channels = data.readInt32();
87 desc.frameCount = data.readInt32();
88 desc.latency = data.readInt32();
89 param2 = &desc;
90 }
Eric Laurentddb78e72009-07-28 08:44:33 -070091 ioConfigChanged(event, ioHandle, param2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 return NO_ERROR;
93 } break;
94 default:
95 return BBinder::onTransact(code, data, reply, flags);
96 }
97}
98
99// ----------------------------------------------------------------------------
100
101}; // namespace android