blob: 925058e190e9085fb18d1645e66e42d60447491c [file] [log] [blame]
Andrew Lee50aca232014-07-22 16:41:54 -07001/*
2 * Copyright (C) 2014 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Andrew Lee50aca232014-07-22 16:41:54 -070018
19import android.os.Handler;
20import android.os.IBinder;
21import android.os.Looper;
22import android.os.Message;
23import android.os.RemoteException;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070024import android.telecom.InCallService.VideoCall;
Andrew Lee50aca232014-07-22 16:41:54 -070025import android.view.Surface;
26
27import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028import com.android.internal.telecom.IVideoCallback;
29import com.android.internal.telecom.IVideoProvider;
Andrew Lee50aca232014-07-22 16:41:54 -070030
31/**
32 * Implementation of a Video Call, which allows InCallUi to communicate commands to the underlying
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033 * {@link Connection.VideoProvider}, and direct callbacks from the
34 * {@link Connection.VideoProvider} to the appropriate {@link VideoCall.Listener}.
35 *
36 * {@hide}
Andrew Lee50aca232014-07-22 16:41:54 -070037 */
38public class VideoCallImpl extends VideoCall {
39 private static final int MSG_RECEIVE_SESSION_MODIFY_REQUEST = 1;
40 private static final int MSG_RECEIVE_SESSION_MODIFY_RESPONSE = 2;
41 private static final int MSG_HANDLE_CALL_SESSION_EVENT = 3;
42 private static final int MSG_CHANGE_PEER_DIMENSIONS = 4;
43 private static final int MSG_CHANGE_CALL_DATA_USAGE = 5;
44 private static final int MSG_CHANGE_CAMERA_CAPABILITIES = 6;
45
Ihab Awadb19a0bc2014-08-07 19:46:01 -070046 private final IVideoProvider mVideoProvider;
Andrew Lee50aca232014-07-22 16:41:54 -070047 private final VideoCallListenerBinder mBinder;
48 private VideoCall.Listener mVideoCallListener;
49
50 private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() {
51 @Override
52 public void binderDied() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070053 mVideoProvider.asBinder().unlinkToDeath(this, 0);
Andrew Lee50aca232014-07-22 16:41:54 -070054 }
55 };
56
57 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070058 * IVideoCallback stub implementation.
Andrew Lee50aca232014-07-22 16:41:54 -070059 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 private final class VideoCallListenerBinder extends IVideoCallback.Stub {
Andrew Lee50aca232014-07-22 16:41:54 -070061 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -070063 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST,
Ihab Awadb19a0bc2014-08-07 19:46:01 -070064 videoProfile).sendToTarget();
Andrew Lee50aca232014-07-22 16:41:54 -070065 }
66
67 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 public void receiveSessionModifyResponse(int status, VideoProfile requestProfile,
69 VideoProfile responseProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -070070 SomeArgs args = SomeArgs.obtain();
71 args.arg1 = status;
72 args.arg2 = requestProfile;
73 args.arg3 = responseProfile;
74 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget();
75 }
76
77 @Override
78 public void handleCallSessionEvent(int event) {
79 mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, event).sendToTarget();
80 }
81
82 @Override
83 public void changePeerDimensions(int width, int height) {
84 SomeArgs args = SomeArgs.obtain();
85 args.arg1 = width;
86 args.arg2 = height;
87 mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget();
88 }
89
90 @Override
91 public void changeCallDataUsage(int dataUsage) {
92 mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, dataUsage).sendToTarget();
93 }
94
95 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Andrew Lee50aca232014-07-22 16:41:54 -070097 mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES,
98 cameraCapabilities).sendToTarget();
99 }
100 }
101
102 /** Default handler used to consolidate binder method calls onto a single thread. */
103 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
104 @Override
105 public void handleMessage(Message msg) {
106 if (mVideoCallListener == null) {
107 return;
108 }
109
110 SomeArgs args;
111 switch (msg.what) {
112 case MSG_RECEIVE_SESSION_MODIFY_REQUEST:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700113 mVideoCallListener.onSessionModifyRequestReceived((VideoProfile) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700114 break;
115 case MSG_RECEIVE_SESSION_MODIFY_RESPONSE:
116 args = (SomeArgs) msg.obj;
117 try {
118 int status = (int) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700119 VideoProfile requestProfile = (VideoProfile) args.arg2;
120 VideoProfile responseProfile = (VideoProfile) args.arg3;
Andrew Lee50aca232014-07-22 16:41:54 -0700121
122 mVideoCallListener.onSessionModifyResponseReceived(
123 status, requestProfile, responseProfile);
124 } finally {
125 args.recycle();
126 }
127 break;
128 case MSG_HANDLE_CALL_SESSION_EVENT:
129 mVideoCallListener.onCallSessionEvent((int) msg.obj);
130 break;
131 case MSG_CHANGE_PEER_DIMENSIONS:
132 args = (SomeArgs) msg.obj;
133 try {
134 int width = (int) args.arg1;
135 int height = (int) args.arg2;
136 mVideoCallListener.onPeerDimensionsChanged(width, height);
137 } finally {
138 args.recycle();
139 }
140 break;
141 case MSG_CHANGE_CALL_DATA_USAGE:
142 mVideoCallListener.onCallDataUsageChanged(msg.arg1);
143 break;
144 case MSG_CHANGE_CAMERA_CAPABILITIES:
145 mVideoCallListener.onCameraCapabilitiesChanged(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700146 (CameraCapabilities) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700147 break;
148 default:
149 break;
150 }
151 }
152 };
153
154 /** {@hide} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700155 VideoCallImpl(IVideoProvider videoProvider) throws RemoteException {
156 mVideoProvider = videoProvider;
157 mVideoProvider.asBinder().linkToDeath(mDeathRecipient, 0);
Andrew Lee50aca232014-07-22 16:41:54 -0700158
159 mBinder = new VideoCallListenerBinder();
Ihab Awada64627c2014-08-20 09:36:40 -0700160 mVideoProvider.setVideoCallback(mBinder);
Andrew Lee50aca232014-07-22 16:41:54 -0700161 }
162
163 /** {@inheritDoc} */
164 public void setVideoCallListener(VideoCall.Listener videoCallListener) {
165 mVideoCallListener = videoCallListener;
166 }
167
168 /** {@inheritDoc} */
169 public void setCamera(String cameraId) {
170 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700171 mVideoProvider.setCamera(cameraId);
Andrew Lee50aca232014-07-22 16:41:54 -0700172 } catch (RemoteException e) {
173 }
174 }
175
176 /** {@inheritDoc} */
177 public void setPreviewSurface(Surface surface) {
178 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179 mVideoProvider.setPreviewSurface(surface);
Andrew Lee50aca232014-07-22 16:41:54 -0700180 } catch (RemoteException e) {
181 }
182 }
183
184 /** {@inheritDoc} */
185 public void setDisplaySurface(Surface surface) {
186 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700187 mVideoProvider.setDisplaySurface(surface);
Andrew Lee50aca232014-07-22 16:41:54 -0700188 } catch (RemoteException e) {
189 }
190 }
191
192 /** {@inheritDoc} */
193 public void setDeviceOrientation(int rotation) {
194 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700195 mVideoProvider.setDeviceOrientation(rotation);
Andrew Lee50aca232014-07-22 16:41:54 -0700196 } catch (RemoteException e) {
197 }
198 }
199
200 /** {@inheritDoc} */
201 public void setZoom(float value) {
202 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700203 mVideoProvider.setZoom(value);
Andrew Lee50aca232014-07-22 16:41:54 -0700204 } catch (RemoteException e) {
205 }
206 }
207
208 /** {@inheritDoc} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700209 public void sendSessionModifyRequest(VideoProfile requestProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -0700210 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 mVideoProvider.sendSessionModifyRequest(requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700212 } catch (RemoteException e) {
213 }
214 }
215
216 /** {@inheritDoc} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700217 public void sendSessionModifyResponse(VideoProfile responseProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -0700218 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700219 mVideoProvider.sendSessionModifyResponse(responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700220 } catch (RemoteException e) {
221 }
222 }
223
224 /** {@inheritDoc} */
225 public void requestCameraCapabilities() {
226 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 mVideoProvider.requestCameraCapabilities();
Andrew Lee50aca232014-07-22 16:41:54 -0700228 } catch (RemoteException e) {
229 }
230 }
231
232 /** {@inheritDoc} */
233 public void requestCallDataUsage() {
234 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700235 mVideoProvider.requestCallDataUsage();
Andrew Lee50aca232014-07-22 16:41:54 -0700236 } catch (RemoteException e) {
237 }
238 }
239
240 /** {@inheritDoc} */
241 public void setPauseImage(String uri) {
242 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700243 mVideoProvider.setPauseImage(uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700244 } catch (RemoteException e) {
245 }
246 }
247}