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 #ifndef AUDIO_SESSION_H 18 #define AUDIO_SESSION_H 19 20 #include <ImsMediaDefine.h> 21 #include <BaseSession.h> 22 #include <AudioStreamGraphRtpTx.h> 23 #include <AudioStreamGraphRtpRx.h> 24 #include <AudioStreamGraphRtcp.h> 25 #include <RtpConfig.h> 26 #include <MediaQualityAnalyzer.h> 27 #include <RtpHeaderExtension.h> 28 #include <list> 29 30 class AudioSession : public BaseSession 31 { 32 public: 33 AudioSession(); 34 virtual ~AudioSession(); 35 virtual SessionState getState(); 36 virtual void onEvent(int32_t type, uint64_t param1, uint64_t param2); 37 virtual void setMediaQualityThreshold(const MediaQualityThreshold& threshold); 38 virtual ImsMediaResult startGraph(RtpConfig* config); 39 40 /** 41 * @brief Add and start stream graph instance of the session. It has to be called only to create 42 * new StreamGraph should be added with different RtpConfig as a argument. 43 * 44 * @param config The parameters to operate nodes in the StreamGraph. 45 * @param enableRtcp {@code true} when the rtcp needs to be enabled to the rest of the graphs 46 * @return ImsMediaResult result of create or start graph. If the result has no error, it 47 * returns RESULT_SUCCESS. check #ImsMediaDefine.h. 48 */ 49 ImsMediaResult addGraph(RtpConfig* config, bool enableRtcp); 50 51 /** 52 * @brief Determine to remain only one StreamGraph instance and remove other StreamGraph. If the 53 * target StreamGraph is not in RUN state, call start instance to change to RUN state. 54 * when the call session is converted to confirmed session. It has to be called with 55 * proper RtpConfig argument that can choose the StreamGraph with the config. If there is 56 * no matched StreamGraph with same RtpConfig, it returns failure of 57 * RESULT_INVALID_PARAM. 58 * 59 * @param config The parameters to operate nodes in the StreamGraph. 60 * @return ImsMediaResult result of create or start graph. If the result has no error, it 61 * returns RESULT_SUCCESS. check #ImsMediaDefine.h. 62 */ 63 ImsMediaResult confirmGraph(RtpConfig* config); 64 65 /** 66 * @brief Delete a StreamGraph which has a matched RtpConfig argument. 67 * 68 * @param config A parameter to find the matching StreamGraph instance. 69 * @return ImsMediaResult A result of deleting StreamGraph instance. If the result has no error, 70 * it returns RESULT_SUCCESS. check #ImsMediaDefine.h. 71 */ 72 ImsMediaResult deleteGraph(RtpConfig* config); 73 74 /** 75 * @brief Send Dtmf digit to the network 76 * 77 * @param digit A digit character 78 * @param duration The duration of millisecond unit indicate how long to send the digit as a rtp 79 * event packet 80 */ 81 void sendDtmf(char digit, int duration); 82 83 /** 84 * @brief Request the current rtp reception statistics params for checking the current status of 85 * the rtp stream. It will trigger the notifyRtpReceptionStats() with the 86 * RtpReceptionStats. 87 * 88 * @param intervalMs The interval of the time in milliseconds of the rtp reception notification 89 */ 90 void requestRtpReceptionStats(int32_t intervalMs); 91 92 /** 93 * @brief Adjust the delay in the jitter buffer to synchronize the audio with the time of video 94 * frames 95 * 96 * @param delayMs The additional delay to the jitter buffer in milliseconds unit. The value is 97 * always positive. 98 */ 99 void adjustDelay(const int32_t delayMs); 100 101 /** 102 * @brief Send internal event to process in the stream graph 103 * 104 * @param type The type of internal event defined in ImsMediaDefine.h 105 * @param param1 The additional parameter to set 106 * @param param2 The additional parameter to set 107 */ 108 void SendInternalEvent(int32_t type, uint64_t param1, uint64_t param2); 109 110 /** 111 * @brief Check whether the graph has the same remote address or not 112 * 113 * @param config The RtpConfig to check the remote address 114 */ 115 bool IsGraphAlreadyExist(RtpConfig* config); 116 117 /** 118 * @brief Get graph list size with repective stream type 119 * 120 * @param type The graph type to fetch 121 * @return uint32_t The size of list 122 */ 123 uint32_t getGraphSize(ImsMediaStreamType type); 124 125 /** 126 * @brief Send rtp header extension to the audio rtp 127 * 128 * @param listExtension The list of rtp header extension data 129 */ 130 void sendRtpHeaderExtension(std::list<RtpHeaderExtension>* listExtension); 131 132 /** 133 * @brief Move session to inactive. i.e., Rtp Tx and Rtp Rx graphs are stopped 134 * 135 * @return bool false if failed to move session to inactive 136 */ 137 bool deactivate(); 138 139 private: 140 std::list<AudioStreamGraphRtpTx*> mListGraphRtpTx; 141 std::list<AudioStreamGraphRtpRx*> mListGraphRtpRx; 142 std::list<AudioStreamGraphRtcp*> mListGraphRtcp; 143 std::unique_ptr<MediaQualityAnalyzer> mMediaQualityAnalyzer; 144 }; 145 146 #endif