IAudioFlingerClient.cpp revision 5e07b5774c8b376776caa4f5b0a193767697e97e
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 <utils/Parcel.h>
24
25#include <media/IAudioFlingerClient.h>
26
27namespace android {
28
29enum {
30    AUDIO_OUTPUT_CHANGED = IBinder::FIRST_CALL_TRANSACTION
31};
32
33class BpAudioFlingerClient : public BpInterface<IAudioFlingerClient>
34{
35public:
36    BpAudioFlingerClient(const sp<IBinder>& impl)
37        : BpInterface<IAudioFlingerClient>(impl)
38    {
39    }
40
41    void audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency)
42    {
43        Parcel data, reply;
44        data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
45        data.writeInt32(frameCount);
46        data.writeInt32(samplingRate);
47        data.writeInt32(latency);
48        remote()->transact(AUDIO_OUTPUT_CHANGED, data, &reply);
49    }
50};
51
52IMPLEMENT_META_INTERFACE(AudioFlingerClient, "android.media.IAudioFlingerClient");
53
54// ----------------------------------------------------------------------
55
56#define CHECK_INTERFACE(interface, data, reply) \
57        do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
58            LOGW("Call incorrectly routed to " #interface); \
59            return PERMISSION_DENIED; \
60        } } while (0)
61
62status_t BnAudioFlingerClient::onTransact(
63    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
64{
65    switch(code) {
66        case AUDIO_OUTPUT_CHANGED: {
67            CHECK_INTERFACE(IAudioFlingerClient, data, reply);
68            uint32_t frameCount = data.readInt32();
69            uint32_t samplingRate = data.readInt32();
70            uint32_t latency = data.readInt32();
71            audioOutputChanged(frameCount, samplingRate, latency);
72            return NO_ERROR;
73        } break;
74        default:
75            return BBinder::onTransact(code, data, reply, flags);
76    }
77}
78
79// ----------------------------------------------------------------------------
80
81}; // namespace android
82