| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 18 | |
| 19 | import android.os.Handler; |
| 20 | import android.os.IBinder; |
| 21 | import android.os.Looper; |
| 22 | import android.os.Message; |
| 23 | import android.os.RemoteException; |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 24 | import android.telecom.InCallService.VideoCall; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 25 | import android.view.Surface; |
| 26 | |
| 27 | import com.android.internal.os.SomeArgs; |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 28 | import com.android.internal.telecom.IVideoCallback; |
| 29 | import com.android.internal.telecom.IVideoProvider; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Implementation of a Video Call, which allows InCallUi to communicate commands to the underlying |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 33 | * {@link Connection.VideoProvider}, and direct callbacks from the |
| 34 | * {@link Connection.VideoProvider} to the appropriate {@link VideoCall.Listener}. |
| 35 | * |
| 36 | * {@hide} |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 37 | */ |
| 38 | public class VideoCallImpl extends VideoCall { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 39 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 40 | private final IVideoProvider mVideoProvider; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 41 | private final VideoCallListenerBinder mBinder; |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 42 | private VideoCall.Callback mCallback; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 43 | |
| 44 | private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() { |
| 45 | @Override |
| 46 | public void binderDied() { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 47 | mVideoProvider.asBinder().unlinkToDeath(this, 0); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 48 | } |
| 49 | }; |
| 50 | |
| 51 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 52 | * IVideoCallback stub implementation. |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 53 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 54 | private final class VideoCallListenerBinder extends IVideoCallback.Stub { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 55 | @Override |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 56 | public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 57 | mHandler.obtainMessage(MessageHandler.MSG_RECEIVE_SESSION_MODIFY_REQUEST, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 58 | videoProfile).sendToTarget(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 62 | public void receiveSessionModifyResponse(int status, VideoProfile requestProfile, |
| 63 | VideoProfile responseProfile) { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 64 | SomeArgs args = SomeArgs.obtain(); |
| 65 | args.arg1 = status; |
| 66 | args.arg2 = requestProfile; |
| 67 | args.arg3 = responseProfile; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 68 | mHandler.obtainMessage(MessageHandler.MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args) |
| 69 | .sendToTarget(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void handleCallSessionEvent(int event) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 74 | mHandler.obtainMessage(MessageHandler.MSG_HANDLE_CALL_SESSION_EVENT, event) |
| 75 | .sendToTarget(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void changePeerDimensions(int width, int height) { |
| 80 | SomeArgs args = SomeArgs.obtain(); |
| 81 | args.arg1 = width; |
| 82 | args.arg2 = height; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 83 | mHandler.obtainMessage(MessageHandler.MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 87 | public void changeVideoQuality(int videoQuality) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 88 | mHandler.obtainMessage(MessageHandler.MSG_CHANGE_VIDEO_QUALITY, videoQuality, 0) |
| 89 | .sendToTarget(); |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void changeCallDataUsage(long dataUsage) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 94 | mHandler.obtainMessage(MessageHandler.MSG_CHANGE_CALL_DATA_USAGE, dataUsage) |
| 95 | .sendToTarget(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 99 | public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 100 | mHandler.obtainMessage(MessageHandler.MSG_CHANGE_CAMERA_CAPABILITIES, |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 101 | cameraCapabilities).sendToTarget(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** Default handler used to consolidate binder method calls onto a single thread. */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 106 | private final class MessageHandler extends Handler { |
| 107 | private static final int MSG_RECEIVE_SESSION_MODIFY_REQUEST = 1; |
| 108 | private static final int MSG_RECEIVE_SESSION_MODIFY_RESPONSE = 2; |
| 109 | private static final int MSG_HANDLE_CALL_SESSION_EVENT = 3; |
| 110 | private static final int MSG_CHANGE_PEER_DIMENSIONS = 4; |
| 111 | private static final int MSG_CHANGE_CALL_DATA_USAGE = 5; |
| 112 | private static final int MSG_CHANGE_CAMERA_CAPABILITIES = 6; |
| 113 | private static final int MSG_CHANGE_VIDEO_QUALITY = 7; |
| 114 | |
| 115 | public MessageHandler(Looper looper) { |
| 116 | super(looper); |
| 117 | } |
| 118 | |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 119 | @Override |
| 120 | public void handleMessage(Message msg) { |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 121 | if (mCallback == null) { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
| 125 | SomeArgs args; |
| 126 | switch (msg.what) { |
| 127 | case MSG_RECEIVE_SESSION_MODIFY_REQUEST: |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 128 | mCallback.onSessionModifyRequestReceived((VideoProfile) msg.obj); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 129 | break; |
| 130 | case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: |
| 131 | args = (SomeArgs) msg.obj; |
| 132 | try { |
| 133 | int status = (int) args.arg1; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 134 | VideoProfile requestProfile = (VideoProfile) args.arg2; |
| 135 | VideoProfile responseProfile = (VideoProfile) args.arg3; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 136 | |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 137 | mCallback.onSessionModifyResponseReceived( |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 138 | status, requestProfile, responseProfile); |
| 139 | } finally { |
| 140 | args.recycle(); |
| 141 | } |
| 142 | break; |
| 143 | case MSG_HANDLE_CALL_SESSION_EVENT: |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 144 | mCallback.onCallSessionEvent((int) msg.obj); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 145 | break; |
| 146 | case MSG_CHANGE_PEER_DIMENSIONS: |
| 147 | args = (SomeArgs) msg.obj; |
| 148 | try { |
| 149 | int width = (int) args.arg1; |
| 150 | int height = (int) args.arg2; |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 151 | mCallback.onPeerDimensionsChanged(width, height); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 152 | } finally { |
| 153 | args.recycle(); |
| 154 | } |
| 155 | break; |
| 156 | case MSG_CHANGE_CALL_DATA_USAGE: |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 157 | mCallback.onCallDataUsageChanged((long) msg.obj); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 158 | break; |
| 159 | case MSG_CHANGE_CAMERA_CAPABILITIES: |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 160 | mCallback.onCameraCapabilitiesChanged( |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 161 | (CameraCapabilities) msg.obj); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 162 | break; |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 163 | case MSG_CHANGE_VIDEO_QUALITY: |
| Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 164 | mCallback.onVideoQualityChanged(msg.arg1); |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 165 | break; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 166 | default: |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | }; |
| 171 | |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 172 | private Handler mHandler; |
| 173 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 174 | VideoCallImpl(IVideoProvider videoProvider) throws RemoteException { |
| 175 | mVideoProvider = videoProvider; |
| 176 | mVideoProvider.asBinder().linkToDeath(mDeathRecipient, 0); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 177 | |
| 178 | mBinder = new VideoCallListenerBinder(); |
| Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 179 | mVideoProvider.addVideoCallback(mBinder); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 182 | public void destroy() { |
| 183 | unregisterCallback(mCallback); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** {@inheritDoc} */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame^] | 187 | public void registerCallback(VideoCall.Callback callback) { |
| 188 | registerCallback(callback, null); |
| 189 | } |
| 190 | |
| 191 | /** {@inheritDoc} */ |
| 192 | public void registerCallback(VideoCall.Callback callback, Handler handler) { |
| 193 | mCallback = callback; |
| 194 | if (handler == null) { |
| 195 | mHandler = new MessageHandler(Looper.getMainLooper()); |
| 196 | } else { |
| 197 | mHandler = new MessageHandler(handler.getLooper()); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** {@inheritDoc} */ |
| 202 | public void unregisterCallback(VideoCall.Callback callback) { |
| 203 | if (callback != mCallback) { |
| 204 | return; |
| 205 | } |
| 206 | |
| Etan Cohen | 8942724 | 2015-04-23 12:26:37 -0700 | [diff] [blame] | 207 | mCallback = null; |
| Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 208 | try { |
| 209 | mVideoProvider.removeVideoCallback(mBinder); |
| 210 | } catch (RemoteException e) { |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** {@inheritDoc} */ |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 215 | public void setCamera(String cameraId) { |
| 216 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 217 | mVideoProvider.setCamera(cameraId); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 218 | } catch (RemoteException e) { |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** {@inheritDoc} */ |
| 223 | public void setPreviewSurface(Surface surface) { |
| 224 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 225 | mVideoProvider.setPreviewSurface(surface); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 226 | } catch (RemoteException e) { |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** {@inheritDoc} */ |
| 231 | public void setDisplaySurface(Surface surface) { |
| 232 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 233 | mVideoProvider.setDisplaySurface(surface); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 234 | } catch (RemoteException e) { |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** {@inheritDoc} */ |
| 239 | public void setDeviceOrientation(int rotation) { |
| 240 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 241 | mVideoProvider.setDeviceOrientation(rotation); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 242 | } catch (RemoteException e) { |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** {@inheritDoc} */ |
| 247 | public void setZoom(float value) { |
| 248 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 249 | mVideoProvider.setZoom(value); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 250 | } catch (RemoteException e) { |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** {@inheritDoc} */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 255 | public void sendSessionModifyRequest(VideoProfile requestProfile) { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 256 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 257 | mVideoProvider.sendSessionModifyRequest(requestProfile); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 258 | } catch (RemoteException e) { |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /** {@inheritDoc} */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 263 | public void sendSessionModifyResponse(VideoProfile responseProfile) { |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 264 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 265 | mVideoProvider.sendSessionModifyResponse(responseProfile); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 266 | } catch (RemoteException e) { |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** {@inheritDoc} */ |
| 271 | public void requestCameraCapabilities() { |
| 272 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 273 | mVideoProvider.requestCameraCapabilities(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 274 | } catch (RemoteException e) { |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /** {@inheritDoc} */ |
| 279 | public void requestCallDataUsage() { |
| 280 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 281 | mVideoProvider.requestCallDataUsage(); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 282 | } catch (RemoteException e) { |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /** {@inheritDoc} */ |
| 287 | public void setPauseImage(String uri) { |
| 288 | try { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 289 | mVideoProvider.setPauseImage(uri); |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 290 | } catch (RemoteException e) { |
| 291 | } |
| 292 | } |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 293 | } |