Home | History | Annotate | Download | only in binding
      1 /*
      2  * Copyright (C) 2017 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 "AAudio"
     18 //#define LOG_NDEBUG 0
     19 #include <utils/Log.h>
     20 
     21 #include <aaudio/AAudio.h>
     22 
     23 #include "binding/AAudioBinderClient.h"
     24 #include "binding/AAudioServiceDefinitions.h"
     25 #include "binding/IAAudioClient.h"
     26 #include "utility/AAudioUtilities.h"
     27 
     28 namespace android {
     29 
     30 using aaudio::aaudio_handle_t;
     31 
     32 /**
     33  * This is used by the AAudio Service to talk to an AAudio Client.
     34  *
     35  * The order of parameters in the Parcels must match with code in AAudioClient.cpp.
     36  */
     37 class BpAAudioClient : public BpInterface<IAAudioClient>
     38 {
     39 public:
     40     explicit BpAAudioClient(const sp<IBinder>& impl)
     41         : BpInterface<IAAudioClient>(impl)
     42     {
     43     }
     44 
     45     void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) override {
     46         Parcel data, reply;
     47         data.writeInterfaceToken(IAAudioClient::getInterfaceDescriptor());
     48         data.writeInt32(handle);
     49         data.writeInt32(opcode);
     50         data.writeInt32(value);
     51         remote()->transact(ON_STREAM_CHANGE, data,  &reply, IBinder::FLAG_ONEWAY);
     52     }
     53 
     54 };
     55 
     56 // Implement an interface to the service.
     57 IMPLEMENT_META_INTERFACE(AAudioClient, "IAAudioClient");
     58 
     59 // The order of parameters in the Parcels must match with code in BpAAudioClient
     60 
     61 status_t BnAAudioClient::onTransact(uint32_t code, const Parcel& data,
     62                                         Parcel* reply, uint32_t flags) {
     63     aaudio_handle_t streamHandle;
     64     int32_t opcode = 0;
     65     int32_t value = 0;
     66     ALOGV("BnAAudioClient::onTransact(%u) %u", code, flags);
     67 
     68     switch(code) {
     69         case ON_STREAM_CHANGE: {
     70             CHECK_INTERFACE(IAAudioClient, data, reply);
     71             data.readInt32(&streamHandle);
     72             data.readInt32(&opcode);
     73             data.readInt32(&value);
     74             onStreamChange(streamHandle, opcode, value);
     75             ALOGD("BnAAudioClient onStreamChange(%x, %d, %d)", streamHandle, opcode, value);
     76             return NO_ERROR;
     77         } break;
     78 
     79         default:
     80             // ALOGW("BnAAudioClient::onTransact not handled %u", code);
     81             return BBinder::onTransact(code, data, reply, flags);
     82     }
     83 }
     84 
     85 } /* namespace android */
     86