blob: 7bef6881f571664dd9613a330157e068b89d7a66 [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;
Rekha Kumar07366812015-03-24 16:42:31 -070045 private static final int MSG_CHANGE_VIDEO_QUALITY = 7;
Andrew Lee50aca232014-07-22 16:41:54 -070046
Ihab Awadb19a0bc2014-08-07 19:46:01 -070047 private final IVideoProvider mVideoProvider;
Andrew Lee50aca232014-07-22 16:41:54 -070048 private final VideoCallListenerBinder mBinder;
Andrew Leeda80c872015-04-15 14:09:50 -070049 private VideoCall.Callback mCallback;
Andrew Lee50aca232014-07-22 16:41:54 -070050
51 private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() {
52 @Override
53 public void binderDied() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054 mVideoProvider.asBinder().unlinkToDeath(this, 0);
Andrew Lee50aca232014-07-22 16:41:54 -070055 }
56 };
57
58 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070059 * IVideoCallback stub implementation.
Andrew Lee50aca232014-07-22 16:41:54 -070060 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070061 private final class VideoCallListenerBinder extends IVideoCallback.Stub {
Andrew Lee50aca232014-07-22 16:41:54 -070062 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -070064 mHandler.obtainMessage(MSG_RECEIVE_SESSION_MODIFY_REQUEST,
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 videoProfile).sendToTarget();
Andrew Lee50aca232014-07-22 16:41:54 -070066 }
67
68 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -070069 public void receiveSessionModifyResponse(int status, VideoProfile requestProfile,
70 VideoProfile responseProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -070071 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 Kumar07366812015-03-24 16:42:31 -070092 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 Lee50aca232014-07-22 16:41:54 -070098 mHandler.obtainMessage(MSG_CHANGE_CALL_DATA_USAGE, dataUsage).sendToTarget();
99 }
100
101 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700102 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Andrew Lee50aca232014-07-22 16:41:54 -0700103 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) {
Andrew Leeda80c872015-04-15 14:09:50 -0700112 if (mCallback == null) {
Andrew Lee50aca232014-07-22 16:41:54 -0700113 return;
114 }
115
116 SomeArgs args;
117 switch (msg.what) {
118 case MSG_RECEIVE_SESSION_MODIFY_REQUEST:
Andrew Leeda80c872015-04-15 14:09:50 -0700119 mCallback.onSessionModifyRequestReceived((VideoProfile) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700120 break;
121 case MSG_RECEIVE_SESSION_MODIFY_RESPONSE:
122 args = (SomeArgs) msg.obj;
123 try {
124 int status = (int) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700125 VideoProfile requestProfile = (VideoProfile) args.arg2;
126 VideoProfile responseProfile = (VideoProfile) args.arg3;
Andrew Lee50aca232014-07-22 16:41:54 -0700127
Andrew Leeda80c872015-04-15 14:09:50 -0700128 mCallback.onSessionModifyResponseReceived(
Andrew Lee50aca232014-07-22 16:41:54 -0700129 status, requestProfile, responseProfile);
130 } finally {
131 args.recycle();
132 }
133 break;
134 case MSG_HANDLE_CALL_SESSION_EVENT:
Andrew Leeda80c872015-04-15 14:09:50 -0700135 mCallback.onCallSessionEvent((int) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700136 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;
Andrew Leeda80c872015-04-15 14:09:50 -0700142 mCallback.onPeerDimensionsChanged(width, height);
Andrew Lee50aca232014-07-22 16:41:54 -0700143 } finally {
144 args.recycle();
145 }
146 break;
147 case MSG_CHANGE_CALL_DATA_USAGE:
Andrew Leeda80c872015-04-15 14:09:50 -0700148 mCallback.onCallDataUsageChanged((long) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700149 break;
150 case MSG_CHANGE_CAMERA_CAPABILITIES:
Andrew Leeda80c872015-04-15 14:09:50 -0700151 mCallback.onCameraCapabilitiesChanged(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 (CameraCapabilities) msg.obj);
Andrew Lee50aca232014-07-22 16:41:54 -0700153 break;
Rekha Kumar07366812015-03-24 16:42:31 -0700154 case MSG_CHANGE_VIDEO_QUALITY:
Andrew Leeda80c872015-04-15 14:09:50 -0700155 mCallback.onVideoQualityChanged(msg.arg1);
Rekha Kumar07366812015-03-24 16:42:31 -0700156 break;
Andrew Lee50aca232014-07-22 16:41:54 -0700157 default:
158 break;
159 }
160 }
161 };
162
163 /** {@hide} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700164 VideoCallImpl(IVideoProvider videoProvider) throws RemoteException {
165 mVideoProvider = videoProvider;
166 mVideoProvider.asBinder().linkToDeath(mDeathRecipient, 0);
Andrew Lee50aca232014-07-22 16:41:54 -0700167
168 mBinder = new VideoCallListenerBinder();
Ihab Awada64627c2014-08-20 09:36:40 -0700169 mVideoProvider.setVideoCallback(mBinder);
Andrew Lee50aca232014-07-22 16:41:54 -0700170 }
171
172 /** {@inheritDoc} */
Andrew Leeda80c872015-04-15 14:09:50 -0700173 public void registerCallback(VideoCall.Callback callback) {
174 mCallback = callback;
Andrew Lee50aca232014-07-22 16:41:54 -0700175 }
176
177 /** {@inheritDoc} */
178 public void setCamera(String cameraId) {
179 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700180 mVideoProvider.setCamera(cameraId);
Andrew Lee50aca232014-07-22 16:41:54 -0700181 } catch (RemoteException e) {
182 }
183 }
184
185 /** {@inheritDoc} */
186 public void setPreviewSurface(Surface surface) {
187 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700188 mVideoProvider.setPreviewSurface(surface);
Andrew Lee50aca232014-07-22 16:41:54 -0700189 } catch (RemoteException e) {
190 }
191 }
192
193 /** {@inheritDoc} */
194 public void setDisplaySurface(Surface surface) {
195 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700196 mVideoProvider.setDisplaySurface(surface);
Andrew Lee50aca232014-07-22 16:41:54 -0700197 } catch (RemoteException e) {
198 }
199 }
200
201 /** {@inheritDoc} */
202 public void setDeviceOrientation(int rotation) {
203 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700204 mVideoProvider.setDeviceOrientation(rotation);
Andrew Lee50aca232014-07-22 16:41:54 -0700205 } catch (RemoteException e) {
206 }
207 }
208
209 /** {@inheritDoc} */
210 public void setZoom(float value) {
211 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 mVideoProvider.setZoom(value);
Andrew Lee50aca232014-07-22 16:41:54 -0700213 } catch (RemoteException e) {
214 }
215 }
216
217 /** {@inheritDoc} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700218 public void sendSessionModifyRequest(VideoProfile requestProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -0700219 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700220 mVideoProvider.sendSessionModifyRequest(requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700221 } catch (RemoteException e) {
222 }
223 }
224
225 /** {@inheritDoc} */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700226 public void sendSessionModifyResponse(VideoProfile responseProfile) {
Andrew Lee50aca232014-07-22 16:41:54 -0700227 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700228 mVideoProvider.sendSessionModifyResponse(responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700229 } catch (RemoteException e) {
230 }
231 }
232
233 /** {@inheritDoc} */
234 public void requestCameraCapabilities() {
235 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700236 mVideoProvider.requestCameraCapabilities();
Andrew Lee50aca232014-07-22 16:41:54 -0700237 } catch (RemoteException e) {
238 }
239 }
240
241 /** {@inheritDoc} */
242 public void requestCallDataUsage() {
243 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700244 mVideoProvider.requestCallDataUsage();
Andrew Lee50aca232014-07-22 16:41:54 -0700245 } catch (RemoteException e) {
246 }
247 }
248
249 /** {@inheritDoc} */
250 public void setPauseImage(String uri) {
251 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700252 mVideoProvider.setPauseImage(uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700253 } catch (RemoteException e) {
254 }
255 }
Rekha Kumar07366812015-03-24 16:42:31 -0700256}