blob: 5c494b306d147fc77bbfe6b26b2ac5548f5a0357 [file] [log] [blame]
Jeff Browne1045962012-09-04 21:38:42 -07001/*
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 McFadden8ba01022012-12-18 09:46:54 -080021#include <gui/IGraphicBufferProducer.h>
Jeff Browne1045962012-09-04 21:38:42 -070022#include <utils/String8.h>
23
24namespace android {
25
26enum {
27 ON_DISPLAY_CONNECTED = IBinder::FIRST_CALL_TRANSACTION,
28 ON_DISPLAY_DISCONNECTED,
29 ON_DISPLAY_ERROR,
30};
31
32class BpRemoteDisplayClient: public BpInterface<IRemoteDisplayClient>
33{
34public:
35 BpRemoteDisplayClient(const sp<IBinder>& impl)
36 : BpInterface<IRemoteDisplayClient>(impl)
37 {
38 }
39
Andy McFadden8ba01022012-12-18 09:46:54 -080040 void onDisplayConnected(const sp<IGraphicBufferProducer>& bufferProducer,
Jeff Browne1045962012-09-04 21:38:42 -070041 uint32_t width, uint32_t height, uint32_t flags)
42 {
43 Parcel data, reply;
44 data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
Andy McFadden8ba01022012-12-18 09:46:54 -080045 data.writeStrongBinder(bufferProducer->asBinder());
Jeff Browne1045962012-09-04 21:38:42 -070046 data.writeInt32(width);
47 data.writeInt32(height);
48 data.writeInt32(flags);
49 remote()->transact(ON_DISPLAY_CONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
50 }
51
52 void onDisplayDisconnected()
53 {
54 Parcel data, reply;
55 data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
56 remote()->transact(ON_DISPLAY_DISCONNECTED, data, &reply, IBinder::FLAG_ONEWAY);
57 }
58
59 void onDisplayError(int32_t error)
60 {
61 Parcel data, reply;
62 data.writeInterfaceToken(IRemoteDisplayClient::getInterfaceDescriptor());
63 data.writeInt32(error);
64 remote()->transact(ON_DISPLAY_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
65 }
66};
67
68IMPLEMENT_META_INTERFACE(RemoteDisplayClient, "android.media.IRemoteDisplayClient");
69
70// ----------------------------------------------------------------------
71
72status_t BnRemoteDisplayClient::onTransact(
73 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
74{
75 switch (code) {
76 case ON_DISPLAY_CONNECTED: {
77 CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
Andy McFadden8ba01022012-12-18 09:46:54 -080078 sp<IGraphicBufferProducer> surfaceTexture(
79 interface_cast<IGraphicBufferProducer>(data.readStrongBinder()));
Jeff Browne1045962012-09-04 21:38:42 -070080 uint32_t width = data.readInt32();
81 uint32_t height = data.readInt32();
82 uint32_t flags = data.readInt32();
83 onDisplayConnected(surfaceTexture, width, height, flags);
84 return NO_ERROR;
85 }
86 case ON_DISPLAY_DISCONNECTED: {
87 CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
88 onDisplayDisconnected();
89 return NO_ERROR;
90 }
91 case ON_DISPLAY_ERROR: {
92 CHECK_INTERFACE(IRemoteDisplayClient, data, reply);
93 int32_t error = data.readInt32();
94 onDisplayError(error);
95 return NO_ERROR;
96 }
97 default:
98 return BBinder::onTransact(code, data, reply, flags);
99 }
100}
101
102}; // namespace android