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 { |
| 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; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 45 | private static final int MSG_CHANGE_VIDEO_QUALITY = 7; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 46 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 47 | private final IVideoProvider mVideoProvider; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 48 | private final VideoCallListenerBinder mBinder; |
| 49 | private VideoCall.Listener mVideoCallListener; |
| 50 | |
| 51 | private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() { |
| 52 | @Override |
| 53 | public void binderDied() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 54 | mVideoProvider.asBinder().unlinkToDeath(this, 0); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 55 | } |
| 56 | }; |
| 57 | |
| 58 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 59 | * IVideoCallback stub implementation. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 60 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 61 | private final class VideoCallListenerBinder extends IVideoCallback.Stub { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 62 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 63 | public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 64 | mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 65 | videoProfile).sendToTarget(); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 69 | public void receiveSessionModifyResponse(int status, VideoProfile requestProfile, |
| 70 | VideoProfile responseProfile) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 71 | SomeArgs args = SomeArgs.obtain(); |
| 72 | args.arg1 = status; |
| 73 | args.arg2 = requestProfile; |
| 74 | args.arg3 = responseProfile; |
| 75 | mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_RESPONSE, args).sendToTarget(); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void handleCallSessionEvent(int event) { |
| 80 | mHandler.obtainMessage(MSG_HANDLE_CALL_SESSION_EVENT, event).sendToTarget(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void changePeerDimensions(int width, int height) { |
| 85 | SomeArgs args = SomeArgs.obtain(); |
| 86 | args.arg1 = width; |
| 87 | args.arg2 = height; |
| 88 | mHandler.obtainMessage(MSG_CHANGE_PEER_DIMENSIONS, args).sendToTarget(); |
| 89 | } |
| 90 | |
| 91 | @Override |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 92 | public void changeVideoQuality(int videoQuality) { |
| 93 | mHandler.obtainMessage(MSG_CHANGE_VIDEO_QUALITY, videoQuality, 0).sendToTarget(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void changeCallDataUsage(long dataUsage) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 98 | mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, dataUsage).sendToTarget(); |
| 99 | } |
| 100 | |
| 101 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 102 | public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 103 | mHandler.obtainMessage(MSG_CHANGE_CAMERA_CAPABILITIES, |
| 104 | cameraCapabilities).sendToTarget(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** Default handler used to consolidate binder method calls onto a single thread. */ |
| 109 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 110 | @Override |
| 111 | public void handleMessage(Message msg) { |
| 112 | if (mVideoCallListener == null) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | SomeArgs args; |
| 117 | switch (msg.what) { |
| 118 | case MSG_RECEIVE_SESSION_MODIFY_REQUEST: |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 119 | mVideoCallListener.onSessionModifyRequestReceived((VideoProfile) msg.obj); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 120 | break; |
| 121 | case MSG_RECEIVE_SESSION_MODIFY_RESPONSE: |
| 122 | args = (SomeArgs) msg.obj; |
| 123 | try { |
| 124 | int status = (int) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 125 | VideoProfile requestProfile = (VideoProfile) args.arg2; |
| 126 | VideoProfile responseProfile = (VideoProfile) args.arg3; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 127 | |
| 128 | mVideoCallListener.onSessionModifyResponseReceived( |
| 129 | status, requestProfile, responseProfile); |
| 130 | } finally { |
| 131 | args.recycle(); |
| 132 | } |
| 133 | break; |
| 134 | case MSG_HANDLE_CALL_SESSION_EVENT: |
| 135 | mVideoCallListener.onCallSessionEvent((int) msg.obj); |
| 136 | break; |
| 137 | case MSG_CHANGE_PEER_DIMENSIONS: |
| 138 | args = (SomeArgs) msg.obj; |
| 139 | try { |
| 140 | int width = (int) args.arg1; |
| 141 | int height = (int) args.arg2; |
| 142 | mVideoCallListener.onPeerDimensionsChanged(width, height); |
| 143 | } finally { |
| 144 | args.recycle(); |
| 145 | } |
| 146 | break; |
| 147 | case MSG_CHANGE_CALL_DATA_USAGE: |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 148 | mVideoCallListener.onCallDataUsageChanged((long) msg.obj); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 149 | break; |
| 150 | case MSG_CHANGE_CAMERA_CAPABILITIES: |
| 151 | mVideoCallListener.onCameraCapabilitiesChanged( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 152 | (CameraCapabilities) msg.obj); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 153 | break; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 154 | case MSG_CHANGE_VIDEO_QUALITY: |
| 155 | mVideoCallListener.onVideoQualityChanged(msg.arg1); |
| 156 | break; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | /** {@hide} */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 164 | VideoCallImpl(IVideoProvider videoProvider) throws RemoteException { |
| 165 | mVideoProvider = videoProvider; |
| 166 | mVideoProvider.asBinder().linkToDeath(mDeathRecipient, 0); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 167 | |
| 168 | mBinder = new VideoCallListenerBinder(); |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 169 | mVideoProvider.setVideoCallback(mBinder); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** {@inheritDoc} */ |
| 173 | public void setVideoCallListener(VideoCall.Listener videoCallListener) { |
| 174 | mVideoCallListener = videoCallListener; |
| 175 | } |
| 176 | |
| 177 | /** {@inheritDoc} */ |
| 178 | public void setCamera(String cameraId) { |
| 179 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 180 | mVideoProvider.setCamera(cameraId); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 181 | } catch (RemoteException e) { |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** {@inheritDoc} */ |
| 186 | public void setPreviewSurface(Surface surface) { |
| 187 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 188 | mVideoProvider.setPreviewSurface(surface); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 189 | } catch (RemoteException e) { |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** {@inheritDoc} */ |
| 194 | public void setDisplaySurface(Surface surface) { |
| 195 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 196 | mVideoProvider.setDisplaySurface(surface); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 197 | } catch (RemoteException e) { |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** {@inheritDoc} */ |
| 202 | public void setDeviceOrientation(int rotation) { |
| 203 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 204 | mVideoProvider.setDeviceOrientation(rotation); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 205 | } catch (RemoteException e) { |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /** {@inheritDoc} */ |
| 210 | public void setZoom(float value) { |
| 211 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 212 | mVideoProvider.setZoom(value); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 213 | } catch (RemoteException e) { |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** {@inheritDoc} */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 218 | public void sendSessionModifyRequest(VideoProfile requestProfile) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 219 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 220 | mVideoProvider.sendSessionModifyRequest(requestProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 221 | } catch (RemoteException e) { |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /** {@inheritDoc} */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 226 | public void sendSessionModifyResponse(VideoProfile responseProfile) { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 227 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 228 | mVideoProvider.sendSessionModifyResponse(responseProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 229 | } catch (RemoteException e) { |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** {@inheritDoc} */ |
| 234 | public void requestCameraCapabilities() { |
| 235 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 236 | mVideoProvider.requestCameraCapabilities(); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 237 | } catch (RemoteException e) { |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | /** {@inheritDoc} */ |
| 242 | public void requestCallDataUsage() { |
| 243 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 244 | mVideoProvider.requestCallDataUsage(); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 245 | } catch (RemoteException e) { |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** {@inheritDoc} */ |
| 250 | public void setPauseImage(String uri) { |
| 251 | try { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 252 | mVideoProvider.setPauseImage(uri); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 253 | } catch (RemoteException e) { |
| 254 | } |
| 255 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 256 | } |