• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.view.Surface;
24 
25 import com.android.telephony.imsmedia.util.Log;
26 
27 import java.util.List;
28 
29 /** Video session implementation for internal AP based RTP stack. This handles
30  * all API calls from applications and passes it to native library.
31  */
32 public class VideoLocalSession {
33     private static final String TAG = "VideoLocalSession";
34     private int mSessionId;
35     private long mNativeObject = 0;
36 
37     /* Instantiates a new audio session based on AP RTP stack
38     *
39     * @param sessionId : session identifier
40     * @param nativeObject : jni object modifier for calling jni methods
41     */
VideoLocalSession(final int sessionId, final long nativeObject)42     VideoLocalSession(final int sessionId, final long nativeObject) {
43         mSessionId = sessionId;
44         mNativeObject = nativeObject;
45     }
46 
47     /** Returns the unique session identifier */
getSessionId()48     public int getSessionId() {
49         Log.dc(TAG, "getSessionId");
50         return mSessionId;
51     }
52 
53     /**
54      * Send request message with the corresponding arguments to libimsmediajni library to operate
55      *
56      * @param sessionId : session identifier
57      * @param parcel : parcel argument to send to jni
58      */
sendRequest(final int sessionId, final Parcel parcel)59     public void sendRequest(final int sessionId, final Parcel parcel) {
60         if (mNativeObject != 0) {
61             if (parcel == null) return;
62             byte[] data = parcel.marshall();
63             JNIImsMediaService.sendMessage(mNativeObject, sessionId, data);
64             parcel.recycle();
65         }
66     }
67 
68     /**
69      * Modifies the configuration of the RTP session after the session is opened.
70      * It can be used modify the direction, access network, codec parameters
71      * RTCP configuration, remote address and remote port number. The service will
72      * apply if anything changed in this invocation compared to previous and respond
73      * the updated the config in ImsMediaSession#onModifySessionResponse() API
74      *
75      * @param config provides remote end point info and codec details
76      */
modifySession(final VideoConfig config)77     public void modifySession(final VideoConfig 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         Parcel parcel = Parcel.obtain();
119         parcel.writeInt(VideoSession.CMD_SET_MEDIA_QUALITY_THRESHOLD);
120         if (threshold != null) {
121             threshold.writeToParcel(parcel, 0);
122         }
123         sendRequest(mSessionId, parcel);
124     }
125 
126     /**
127      * Send RTP header extension to the other party in the next RTP packet.
128      *
129      * @param extensions List of RTP header extensions to be transmitted
130      */
sendHeaderExtension(final List<RtpHeaderExtension> extensions)131     public void sendHeaderExtension(final List<RtpHeaderExtension> extensions) {
132         Log.dc(TAG, "sendHeaderExtension");
133         // TODO: add implementation
134     }
135 
136     /**
137      * Request to report current video data usage to get the amount of data usage in current
138      * video streaming session.
139      */
requestVideoDataUsage()140     public void requestVideoDataUsage() {
141         Log.d(TAG, "requestVideoDataUsage");
142         Parcel parcel = Parcel.obtain();
143         parcel.writeInt(VideoSession.CMD_REQUEST_VIDEO_DATA_USAGE);
144         sendRequest(mSessionId, parcel);
145     }
146 }
147