2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <sys/types.h>
20 #include <binder/IInterface.h>
21 #include <binder/Parcel.h>
23 #include <gui/IConsumerListener.h>
24 #include <gui/BufferItem.h>
26 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
31 ON_FRAME_AVAILABLE = IBinder::FIRST_CALL_TRANSACTION,
33 ON_SIDEBAND_STREAM_CHANGED,
37 class BpConsumerListener : public BpInterface<IConsumerListener>
40 BpConsumerListener(const sp<IBinder>& impl)
41 : BpInterface<IConsumerListener>(impl) {
44 virtual ~BpConsumerListener();
46 virtual void onFrameAvailable(const BufferItem& item) {
48 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor());
50 remote()->transact(ON_FRAME_AVAILABLE, data, &reply, IBinder::FLAG_ONEWAY);
53 virtual void onBuffersReleased() {
55 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor());
56 remote()->transact(ON_BUFFER_RELEASED, data, &reply, IBinder::FLAG_ONEWAY);
59 virtual void onSidebandStreamChanged() {
61 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor());
62 remote()->transact(ON_SIDEBAND_STREAM_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
65 virtual bool getFrameTimestamps(uint64_t frameNumber,
66 FrameTimestamps* outTimestamps) const {
68 status_t result = data.writeInterfaceToken(
69 IConsumerListener::getInterfaceDescriptor());
70 if (result != NO_ERROR) {
71 ALOGE("getFrameTimestamps failed to write token: %d", result);
74 result = data.writeUint64(frameNumber);
75 if (result != NO_ERROR) {
76 ALOGE("getFrameTimestamps failed to write: %d", result);
79 result = remote()->transact(GET_FRAME_TIMESTAMPS, data, &reply);
80 if (result != NO_ERROR) {
81 ALOGE("getFrameTimestamps failed to transact: %d", result);
85 result = reply.readBool(&found);
86 if (result != NO_ERROR) {
87 ALOGE("getFrameTimestamps failed to read: %d", result);
91 result = reply.read(*outTimestamps);
92 if (result != NO_ERROR) {
93 ALOGE("getFrameTimestamps failed to read timestamps: %d",
102 // Out-of-line virtual method definition to trigger vtable emission in this
103 // translation unit (see clang warning -Wweak-vtables)
104 BpConsumerListener::~BpConsumerListener() {}
106 IMPLEMENT_META_INTERFACE(ConsumerListener, "android.gui.IConsumerListener");
108 // ----------------------------------------------------------------------
110 status_t BnConsumerListener::onTransact(
111 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
114 case ON_FRAME_AVAILABLE: {
115 CHECK_INTERFACE(IConsumerListener, data, reply);
118 onFrameAvailable(item);
120 case ON_BUFFER_RELEASED: {
121 CHECK_INTERFACE(IConsumerListener, data, reply);
124 case ON_SIDEBAND_STREAM_CHANGED: {
125 CHECK_INTERFACE(IConsumerListener, data, reply);
126 onSidebandStreamChanged();
128 case GET_FRAME_TIMESTAMPS: {
129 CHECK_INTERFACE(IConsumerListener, data, reply);
130 uint64_t frameNumber = 0;
131 status_t result = data.readUint64(&frameNumber);
132 if (result != NO_ERROR) {
133 ALOGE("onTransact failed to read: %d", result);
136 FrameTimestamps timestamps;
137 bool found = getFrameTimestamps(frameNumber, ×tamps);
138 result = reply->writeBool(found);
139 if (result != NO_ERROR) {
140 ALOGE("onTransact failed to write: %d", result);
144 result = reply->write(timestamps);
145 if (result != NO_ERROR) {
146 ALOGE("onTransact failed to write timestamps: %d", result);
153 return BBinder::onTransact(code, data, reply, flags);
157 // ---------------------------------------------------------------------------
158 }; // namespace android
159 // ---------------------------------------------------------------------------