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 android.telephony.imsmedia;
18 
19 import android.os.IBinder;
20 import android.os.RemoteException;
21 import android.telephony.ims.RtpHeaderExtension;
22 import android.util.Log;
23 import android.view.Surface;
24 
25 import java.util.List;
26 
27 /**
28  * API to manage the video session
29  *
30  * @hide
31  */
32 public class ImsVideoSession implements ImsMediaSession {
33     private static final String TAG = "ImsVideoSession";
34     private final IImsVideoSession mSession;
35 
36     /** @hide */
ImsVideoSession(final IImsVideoSession session)37     public ImsVideoSession(final IImsVideoSession session) {
38         mSession = session;
39     }
40 
41     /** @hide */
42     @Override
getBinder()43     public IBinder getBinder() {
44         return mSession.asBinder();
45     }
46 
47     /** {@inheritDoc} */
getSessionId()48     public int getSessionId() {
49         try {
50             return mSession.getSessionId();
51         } catch (RemoteException e) {
52             Log.e(TAG, "Failed to get session ID: " + e);
53         }
54 
55         return -1;
56     }
57 
58     /**
59      * {@inheritDoc}
60      */
modifySession(final RtpConfig config)61     public void modifySession(final RtpConfig config) {
62         try {
63             mSession.modifySession((VideoConfig) config);
64         } catch (RemoteException e) {
65             Log.e(TAG, "Failed to modify session: " + e);
66         }
67     }
68 
69     /**
70      * Send preview Surface to session to display video tx preview in video streaming.
71      * The setPreviewSurafce should be invoked after openSession or modifySession.
72      *
73      * @param surface the surface to set
74      */
setPreviewSurface(final Surface surface)75     public void setPreviewSurface(final Surface surface) {
76         try {
77             mSession.setPreviewSurface(surface);
78         } catch (RemoteException e) {
79             Log.e(TAG, "Failed to set preview surface: " + e);
80         }
81     }
82 
83     /**
84      * Send display Surface to session to display video rx decoded frames in video streaming.
85      * The setDisplaySurface should be invoked after openSession or modifySession.
86      *
87      * @param surface the surface to set
88      */
setDisplaySurface(final Surface surface)89     public void setDisplaySurface(final Surface surface) {
90         try {
91             mSession.setDisplaySurface(surface);
92         } catch (RemoteException e) {
93             Log.e(TAG, "Failed to set display surface: " + e);
94         }
95     }
96 
97     /**
98      * {@inheritDoc}
99      */
setMediaQualityThreshold(final MediaQualityThreshold threshold)100     public void setMediaQualityThreshold(final MediaQualityThreshold threshold) {
101         try {
102             mSession.setMediaQualityThreshold(threshold);
103         } catch (RemoteException e) {
104             Log.e(TAG, "Failed to set media quality threshold: " + e);
105         }
106     }
107 
108     /**
109      * Send RTP header extension to the other party in the next RTP packet.
110      *
111      * @param extensions List of RTP header extensions to be transmitted
112      */
sendHeaderExtension(final List<RtpHeaderExtension> extensions)113     public void sendHeaderExtension(final List<RtpHeaderExtension> extensions) {
114         try {
115             mSession.sendHeaderExtension(extensions);
116         } catch (RemoteException e) {
117             Log.e(TAG, "Failed to send RTP header extension: " + e);
118         }
119     }
120 
121     /**
122      * Request to report the amount of data usage in current video streaming session.
123      * The notifyVideoDataUsage() will be invoked as a notification.
124      */
requestVideoDataUsage()125     public void requestVideoDataUsage() {
126         try {
127             mSession.requestVideoDataUsage();
128         } catch (RemoteException e) {
129             Log.e(TAG, "Failed to request video data usage: " + e);
130         }
131     }
132 }
133