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(audio_io_config_event event, const sp<AudioIoDescriptor>& ioDesc)
43    {
44        Parcel data, reply;
45        data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
46        data.writeInt32(event);
47        data.writeInt32((int32_t)ioDesc->mIoHandle);
48        data.write(&ioDesc->mPatch, sizeof(struct audio_patch));
49        data.writeInt32(ioDesc->mSamplingRate);
50        data.writeInt32(ioDesc->mFormat);
51        data.writeInt32(ioDesc->mChannelMask);
52        data.writeInt64(ioDesc->mFrameCount);
53        data.writeInt32(ioDesc->mLatency);
54        remote()->transact(IO_CONFIG_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
55    }
56};
57
58IMPLEMENT_META_INTERFACE(AudioFlingerClient, "android.media.IAudioFlingerClient");
59
60// ----------------------------------------------------------------------
61
62status_t BnAudioFlingerClient::onTransact(
63    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
64{
65    switch (code) {
66    case IO_CONFIG_CHANGED: {
67            CHECK_INTERFACE(IAudioFlingerClient, data, reply);
68            audio_io_config_event event = (audio_io_config_event)data.readInt32();
69            sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor();
70            ioDesc->mIoHandle = (audio_io_handle_t) data.readInt32();
71            data.read(&ioDesc->mPatch, sizeof(struct audio_patch));
72            ioDesc->mSamplingRate = data.readInt32();
73            ioDesc->mFormat = (audio_format_t) data.readInt32();
74            ioDesc->mChannelMask = (audio_channel_mask_t) data.readInt32();
75            ioDesc->mFrameCount = data.readInt64();
76            ioDesc->mLatency = data.readInt32();
77            ioConfigChanged(event, ioDesc);
78            return NO_ERROR;
79        } break;
80        default:
81            return BBinder::onTransact(code, data, reply, flags);
82    }
83}
84
85// ----------------------------------------------------------------------------
86
87} // namespace android
88