111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk/*
211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * Copyright (C) 2017 The Android Open Source Project
311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk *
411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * Licensed under the Apache License, Version 2.0 (the "License");
511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * you may not use this file except in compliance with the License.
611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * You may obtain a copy of the License at
711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk *
811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk *      http://www.apache.org/licenses/LICENSE-2.0
911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk *
1011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * Unless required by applicable law or agreed to in writing, software
1111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * distributed under the License is distributed on an "AS IS" BASIS,
1211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * See the License for the specific language governing permissions and
1411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * limitations under the License.
1511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk */
1611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
1711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#define LOG_TAG "AAudio"
1811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk//#define LOG_NDEBUG 0
1911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include <utils/Log.h>
2011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
2111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include <aaudio/AAudio.h>
2211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
2311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include "binding/AAudioBinderClient.h"
2411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include "binding/AAudioServiceDefinitions.h"
2511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include "binding/IAAudioClient.h"
2611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk#include "utility/AAudioUtilities.h"
2711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
2811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burknamespace android {
2911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
3011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burkusing aaudio::aaudio_handle_t;
3111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
3211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk/**
3311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * This is used by the AAudio Service to talk to an AAudio Client.
3411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk *
3511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk * The order of parameters in the Parcels must match with code in AAudioClient.cpp.
3611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk */
3711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burkclass BpAAudioClient : public BpInterface<IAAudioClient>
3811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk{
3911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burkpublic:
4011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    explicit BpAAudioClient(const sp<IBinder>& impl)
4111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        : BpInterface<IAAudioClient>(impl)
4211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    {
4311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    }
4411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
4511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) override {
4611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        Parcel data, reply;
4711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        data.writeInterfaceToken(IAAudioClient::getInterfaceDescriptor());
4811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        data.writeInt32(handle);
4911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        data.writeInt32(opcode);
5011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        data.writeInt32(value);
5111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        remote()->transact(ON_STREAM_CHANGE, data,  &reply, IBinder::FLAG_ONEWAY);
5211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    }
5311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
5411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk};
5511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
5611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk// Implement an interface to the service.
5711e8d335b1da528ee771b19b63df23ae6fd52f41Phil BurkIMPLEMENT_META_INTERFACE(AAudioClient, "IAAudioClient");
5811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
5911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk// The order of parameters in the Parcels must match with code in BpAAudioClient
6011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
6111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burkstatus_t BnAAudioClient::onTransact(uint32_t code, const Parcel& data,
6211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk                                        Parcel* reply, uint32_t flags) {
6311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    aaudio_handle_t streamHandle;
6411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    int32_t opcode = 0;
6511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    int32_t value = 0;
6611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    ALOGV("BnAAudioClient::onTransact(%u) %u", code, flags);
6711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
6811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    switch(code) {
6911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        case ON_STREAM_CHANGE: {
7011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            CHECK_INTERFACE(IAAudioClient, data, reply);
7111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            data.readInt32(&streamHandle);
7211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            data.readInt32(&opcode);
7311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            data.readInt32(&value);
7411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            onStreamChange(streamHandle, opcode, value);
7511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            ALOGD("BnAAudioClient onStreamChange(%x, %d, %d)", streamHandle, opcode, value);
7611e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            return NO_ERROR;
7711e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        } break;
7811e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
7911e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk        default:
8011e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            // ALOGW("BnAAudioClient::onTransact not handled %u", code);
8111e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk            return BBinder::onTransact(code, data, reply, flags);
8211e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk    }
8311e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk}
8411e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk
8511e8d335b1da528ee771b19b63df23ae6fd52f41Phil Burk} /* namespace android */
86