1 /*
2 * Copyright 2016 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 "IArcVideoBridge"
18 //#define LOG_NDEBUG 0
19
20 #include <stdint.h>
21 #include <sys/types.h>
22
23 #include "IArcVideoBridge.h"
24 #include <binder/Parcel.h>
25 #include <utils/Log.h>
26
27 namespace android {
28
29 enum {
30 BOOTSTRAP_VIDEO_ACCELERATOR_FACTORY = IBinder::FIRST_CALL_TRANSACTION,
31 HOST_VERSION,
32 };
33
34 class BpArcVideoBridge : public BpInterface<IArcVideoBridge> {
35 public:
BpArcVideoBridge(const sp<IBinder> & impl)36 BpArcVideoBridge(const sp<IBinder>& impl) : BpInterface<IArcVideoBridge>(impl) { }
37
bootstrapVideoAcceleratorFactory()38 virtual ::arc::MojoBootstrapResult bootstrapVideoAcceleratorFactory() {
39 Parcel data, reply;
40 ALOGV("bootstrapVideoAcceleratorFactory");
41 data.writeInterfaceToken(IArcVideoBridge::getInterfaceDescriptor());
42 status_t status = remote()->transact(
43 BOOTSTRAP_VIDEO_ACCELERATOR_FACTORY, data, &reply, 0);
44 if (status != 0) {
45 ALOGE("transact failed: %d", status);
46 return arc::MojoBootstrapResult();
47 }
48 return arc::MojoBootstrapResult::createFromParcel(reply);
49 }
50
hostVersion()51 virtual int32_t hostVersion() {
52 Parcel data, reply;
53 ALOGV("hostVersion");
54 data.writeInterfaceToken(IArcVideoBridge::getInterfaceDescriptor());
55 status_t status = remote()->transact(HOST_VERSION, data, &reply, 0);
56 if (status != 0) {
57 ALOGE("transact failed: %d", status);
58 return false;
59 }
60 return reply.readInt32();
61 }
62 };
63
64 IMPLEMENT_META_INTERFACE(ArcVideoBridge, "android.os.IArcVideoBridge");
65
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)66 status_t BnArcVideoBridge::onTransact(
67 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
68 switch(code) {
69 case BOOTSTRAP_VIDEO_ACCELERATOR_FACTORY: {
70 ALOGV("BOOTSTRAP_VIDEO_ACCELERATOR_FACTORY");
71 CHECK_INTERFACE(IArcVideoBridge, data, reply);
72 arc::MojoBootstrapResult result = bootstrapVideoAcceleratorFactory();
73 return result.writeToParcel(reply);
74 }
75 case HOST_VERSION: {
76 ALOGV("HOST_VERSION");
77 CHECK_INTERFACE(IArcVideoBridge, data, reply);
78 reply->writeInt32(hostVersion());
79 return OK;
80 }
81 default:
82 return BBinder::onTransact(code, data, reply, flags);
83 }
84 }
85
86 } // namespace android
87