IAudioFlingerClient.cpp revision c2f1f07084818942352c6bbfb36af9b6b330eb4e
1/*
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
23#include <binder/Parcel.h>
24
25#include <media/IAudioFlingerClient.h>
26#include <media/AudioSystem.h>
27
28namespace android {
29
30enum {
31    IO_CONFIG_CHANGED = IBinder::FIRST_CALL_TRANSACTION
32};
33
34class BpAudioFlingerClient : public BpInterface<IAudioFlingerClient>
35{
36public:
37    BpAudioFlingerClient(const sp<IBinder>& impl)
38        : BpInterface<IAudioFlingerClient>(impl)
39    {
40    }
41
42    void ioConfigChanged(int event, void *param1, void *param2)
43    {
44        Parcel data, reply;
45        data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
46        data.writeInt32(event);
47        data.write(&param1, sizeof(void *));
48        if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
49            uint32_t stream = *(uint32_t *)param2;
50            LOGV("ioConfigChanged stream %d", stream);
51            data.writeInt32(stream);
52        } else if (event != AudioSystem::OUTPUT_CLOSED && event != AudioSystem::INPUT_CLOSED) {
53            AudioSystem::OutputDescriptor *desc = (AudioSystem::OutputDescriptor *)param2;
54            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);
61    }
62};
63
64IMPLEMENT_META_INTERFACE(AudioFlingerClient, "android.media.IAudioFlingerClient");
65
66// ----------------------------------------------------------------------
67
68status_t BnAudioFlingerClient::onTransact(
69    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
70{
71    switch(code) {
72    case IO_CONFIG_CHANGED: {
73            CHECK_INTERFACE(IAudioFlingerClient, data, reply);
74            int event = data.readInt32();
75            void *param1;
76            void *param2 = 0;
77            AudioSystem::OutputDescriptor desc;
78            uint32_t stream;
79            data.read(&param1, sizeof(void *));
80            if (event == AudioSystem::STREAM_CONFIG_CHANGED) {
81                stream = data.readInt32();
82                param2 = &stream;
83                LOGV("STREAM_CONFIG_CHANGED stream %d", stream);
84            } else if (event != AudioSystem::OUTPUT_CLOSED && event != AudioSystem::INPUT_CLOSED) {
85                desc.samplingRate = data.readInt32();
86                desc.format = data.readInt32();
87                desc.channels = data.readInt32();
88                desc.frameCount = data.readInt32();
89                desc.latency = data.readInt32();
90                param2 = &desc;
91            }
92            ioConfigChanged(event, param1, param2);
93            return NO_ERROR;
94        } break;
95        default:
96            return BBinder::onTransact(code, data, reply, flags);
97    }
98}
99
100// ----------------------------------------------------------------------------
101
102}; // namespace android
103