1 /** 2 * Copyright (C) 2022 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 package com.android.telephony.imsmedia; 18 19 import android.os.Parcel; 20 import android.telephony.ims.RtpHeaderExtension; 21 import android.telephony.imsmedia.MediaQualityThreshold; 22 import android.telephony.imsmedia.VideoConfig; 23 import android.util.Log; 24 import android.view.Surface; 25 26 import java.util.List; 27 28 /** Video session implementation for internal AP based RTP stack. This handles 29 * all API calls from applications and passes it to native library. 30 */ 31 public class VideoLocalSession { 32 private static final String TAG = "VideoLocalSession"; 33 private int mSessionId; 34 private long mNativeObject = 0; 35 36 /* Instantiates a new audio session based on AP RTP stack 37 * 38 * @param sessionId : session identifier 39 * @param nativeObject : jni object modifier for calling jni methods 40 */ VideoLocalSession(final int sessionId, final long nativeObject)41 VideoLocalSession(final int sessionId, final long nativeObject) { 42 mSessionId = sessionId; 43 mNativeObject = nativeObject; 44 } 45 46 /** Returns the unique session identifier */ getSessionId()47 public int getSessionId() { 48 Log.d(TAG, "getSessionId"); 49 return mSessionId; 50 } 51 52 /** 53 * Send request message with the corresponding arguments to libimsmediajni library to operate 54 * 55 * @param sessionId : session identifier 56 * @param parcel : parcel argument to send to jni 57 */ sendRequest(final int sessionId, final Parcel parcel)58 public void sendRequest(final int sessionId, final Parcel parcel) { 59 if (mNativeObject != 0) { 60 if (parcel == null) return; 61 byte[] data = parcel.marshall(); 62 JNIImsMediaService.sendMessage(mNativeObject, sessionId, data); 63 parcel.recycle(); 64 } 65 } 66 67 /** 68 * Modifies the configuration of the RTP session after the session is opened. 69 * It can be used modify the direction, access network, codec parameters 70 * RTCP configuration, remote address and remote port number. The service will 71 * apply if anything changed in this invocation compared to previous and respond 72 * the updated the config in ImsMediaSession#onModifySessionResponse() API 73 * 74 * @param config provides remote end point info and codec details 75 */ modifySession(final VideoConfig config)76 public void modifySession(final VideoConfig config) { 77 Log.d(TAG, "modifySession: " + config); 78 Parcel parcel = Parcel.obtain(); 79 parcel.writeInt(VideoSession.CMD_MODIFY_SESSION); 80 if (config != null) { 81 config.writeToParcel(parcel, 0); 82 } 83 sendRequest(mSessionId, parcel); 84 } 85 86 /** 87 * Send preview Surface to session to display video tx preview in video streaming. 88 * The setPreviewSurafce should be invoked after openSession or modifySession. 89 * 90 * @param surface the surface to set 91 */ setPreviewSurface(final Surface surface)92 public void setPreviewSurface(final Surface surface) { 93 if (mNativeObject != 0) { 94 JNIImsMediaService.setPreviewSurface(mNativeObject, mSessionId, surface); 95 } 96 } 97 98 /** 99 * Send display Surface to session to display video rx decoded frames in video streaming. 100 * The setDisplaySurface should be invoked after openSession or modifySession. 101 * 102 * @param surface the surface to set 103 */ setDisplaySurface(final Surface surface)104 public void setDisplaySurface(final Surface surface) { 105 if (mNativeObject != 0) { 106 JNIImsMediaService.setDisplaySurface(mNativeObject, mSessionId, surface); 107 } 108 } 109 110 /** 111 * Sets the media quality threshold parameters of the session to get 112 * media quality notifications. 113 * 114 * @param threshold media quality thresholds for various quality 115 * parameters 116 */ setMediaQualityThreshold(final MediaQualityThreshold threshold)117 public void setMediaQualityThreshold(final MediaQualityThreshold threshold) { 118 Log.d(TAG, "setMediaQualityThreshold: " + threshold); 119 Parcel parcel = Parcel.obtain(); 120 parcel.writeInt(VideoSession.CMD_SET_MEDIA_QUALITY_THRESHOLD); 121 if (threshold != null) { 122 threshold.writeToParcel(parcel, 0); 123 } 124 sendRequest(mSessionId, parcel); 125 } 126 127 /** 128 * Send RTP header extension to the other party in the next RTP packet. 129 * 130 * @param extensions List of RTP header extensions to be transmitted 131 */ sendHeaderExtension(final List<RtpHeaderExtension> extensions)132 public void sendHeaderExtension(final List<RtpHeaderExtension> extensions) { 133 Log.d(TAG, "sendHeaderExtension"); 134 // TODO: add implementation 135 } 136 137 /** 138 * Request to report current video data usage to get the amount of data usage in current 139 * video streaming session. 140 */ requestVideoDataUsage()141 public void requestVideoDataUsage() { 142 Log.d(TAG, "requestVideoDataUsage"); 143 Parcel parcel = Parcel.obtain(); 144 parcel.writeInt(VideoSession.CMD_REQUEST_VIDEO_DATA_USAGE); 145 sendRequest(mSessionId, parcel); 146 } 147 } 148