Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #include <stdint.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <media/IRemoteDisplayClient.h> |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 21 | #include <gui/IGraphicBufferProducer.h> |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 22 | #include <utils/String8.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | enum { |
| 27 | ON_DISPLAY_CONNECTED = IBinder::FIRST_CALL_TRANSACTION, |
| 28 | ON_DISPLAY_DISCONNECTED, |
| 29 | ON_DISPLAY_ERROR, |
| 30 | }; |
| 31 | |
| 32 | class BpRemoteDisplayClient: public BpInterface<IRemoteDisplayClient> |
| 33 | { |
| 34 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 35 | explicit BpRemoteDisplayClient(const sp<IBinder>& impl) |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 36 | : BpInterface<IRemoteDisplayClient>(impl) |
| 37 | { |
| 38 | } |
| 39 | |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 40 | void onDisplayConnected(const sp<IGraphicBufferProducer>& bufferProducer, |
Chong Zhang | 87ecf19 | 2013-06-06 12:42:59 -0700 | [diff] [blame] | 41 | uint32_t width, uint32_t height, uint32_t flags, uint32_t session) |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 42 | { |
| 43 | Parcel data, reply; |
| 44 | data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 45 | data.writeStrongBinder(IInterface::asBinder(bufferProducer)); |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 46 | data.writeInt32(width); |
| 47 | data.writeInt32(height); |
| 48 | data.writeInt32(flags); |
Chong Zhang | 87ecf19 | 2013-06-06 12:42:59 -0700 | [diff] [blame] | 49 | data.writeInt32(session); |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 50 | remote()->transact(ON_DISPLAY_CONNECTED, data, &reply, IBinder::FLAG_ONEWAY); |
| 51 | } |
| 52 | |
| 53 | void onDisplayDisconnected() |
| 54 | { |
| 55 | Parcel data, reply; |
| 56 | data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor()); |
| 57 | remote()->transact(ON_DISPLAY_DISCONNECTED, data, &reply, IBinder::FLAG_ONEWAY); |
| 58 | } |
| 59 | |
| 60 | void onDisplayError(int32_t error) |
| 61 | { |
| 62 | Parcel data, reply; |
| 63 | data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor()); |
| 64 | data.writeInt32(error); |
| 65 | remote()->transact(ON_DISPLAY_ERROR, data, &reply, IBinder::FLAG_ONEWAY); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | IMPLEMENT_META_INTERFACE(RemoteDisplayClient, "android.media.IRemoteDisplayClient"); |
| 70 | |
| 71 | // ---------------------------------------------------------------------- |
| 72 | |
| 73 | status_t BnRemoteDisplayClient::onTransact( |
| 74 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 75 | { |
| 76 | switch (code) { |
| 77 | case ON_DISPLAY_CONNECTED: { |
| 78 | CHECK_INTERFACE(IRemoteDisplayClient, data, reply); |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 79 | sp<IGraphicBufferProducer> surfaceTexture( |
| 80 | interface_cast<IGraphicBufferProducer>(data.readStrongBinder())); |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 81 | uint32_t width = data.readInt32(); |
| 82 | uint32_t height = data.readInt32(); |
| 83 | uint32_t flags = data.readInt32(); |
Chong Zhang | 87ecf19 | 2013-06-06 12:42:59 -0700 | [diff] [blame] | 84 | uint32_t session = data.readInt32(); |
| 85 | onDisplayConnected(surfaceTexture, width, height, flags, session); |
Jeff Brown | e104596 | 2012-09-04 21:38:42 -0700 | [diff] [blame] | 86 | return NO_ERROR; |
| 87 | } |
| 88 | case ON_DISPLAY_DISCONNECTED: { |
| 89 | CHECK_INTERFACE(IRemoteDisplayClient, data, reply); |
| 90 | onDisplayDisconnected(); |
| 91 | return NO_ERROR; |
| 92 | } |
| 93 | case ON_DISPLAY_ERROR: { |
| 94 | CHECK_INTERFACE(IRemoteDisplayClient, data, reply); |
| 95 | int32_t error = data.readInt32(); |
| 96 | onDisplayError(error); |
| 97 | return NO_ERROR; |
| 98 | } |
| 99 | default: |
| 100 | return BBinder::onTransact(code, data, reply, flags); |
| 101 | } |
| 102 | } |
| 103 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 104 | } // namespace android |