Agora Java API Reference for Android
rtc_connection_i.h
1 //
2 // Agora Media SDK
3 //
4 // Created by Sting Feng in 2015-05.
5 // Copyright (c) 2015 Agora IO. All rights reserved.
6 //
7 #pragma once
8 
9 #include <functional>
10 #include <list>
11 #include <memory>
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 #include "IAgoraService.h"
17 #include "NGIAgoraRtcConnection.h"
18 
19 namespace agora {
20 namespace base {
21 class BaseWorker;
22 struct ExtraReportData;
23 } // namespace base
24 
25 namespace commons {
26 namespace network {
27 struct network_info_t;
28 } // namespace network
29 } // namespace commons
30 
31 namespace config {
32 class IConfigEngineListener;
33 } // namespace config
34 
35 namespace rtc {
36 
37 namespace protocol {
38 struct CmdRecordingEventReportArgus;
39 } // namespace protocol
40 
41 class CallContext;
42 class IRtcEngineEventHandler;
43 class InternalConnectionEventHandler;
44 class IAudioEngineWrapper;
45 class IVideoEngine;
46 class AudioPacketFilter;
47 class VideoPacketFilter;
48 struct audio_packet_t;
49 struct SAudioFrame;
50 struct video_packet_t;
51 struct video_rtcp_packet_t;
52 struct video_report_packet_t;
53 struct video_custom_ctrl_broadcast_packet_t;
54 struct WebAgentVideoStats;
55 
56 static const uint8_t AUDIO_MEDIA_PACKET_PAYLOAD_TYPE = 127;
57 
59  // Agora will ignore unknown payload type
60  uint8_t payload_type;
61  // RTP ssrc
62  uint32_t ssrc;
63  // bool is_key_frame;
64  // uint8_t frame_packet_count;
65  // uint8_t frame_packet_sequence;
68  payload_type(0),
69  ssrc(0) {}
70 };
71 
72 enum CongestionControlType {
73  CONGESTION_CONTROLLER_TYPE_AGORA_CC = 0,
74 
75  CONGESTION_CONTROLLER_TYPE_REMB,
76 
77  CONGESTION_CONTROLLER_TYPE_TRANSPORT_CC,
78 
79  CONGESTION_CONTROLLER_TYPE_AUT_CC
80 };
81 
82 enum ConnectionMode {
83  // In active mode, broadcast messages will be sent through the connection.
84  // This is used as a publisher is bound with the connection.
85  CONNECTION_MODE_ACTIVE,
86  // In passive mode, broadcast messages will not be sent through the
87  // connection.
88  // This is used as default mode and no publisher is bound with the connection,
89  CONNECTION_MODE_PASSIVE
90 };
91 
94  : RtcConnectionConfiguration::RtcConnectionConfiguration(),
95  clientType(0),
96 #ifdef P2P_SWITCH_DEFAULT_VALUE
97  is_p2p_switch_enabled(P2P_SWITCH_DEFAULT_VALUE)
98 #else
99  is_p2p_switch_enabled(false)
100 #endif
101  {}
102 
109  minPort = rhs.minPort;
110  maxPort = rhs.maxPort;
114  clientType = 0;
115 #ifdef P2P_SWITCH_DEFAULT_VALUE
116  is_p2p_switch_enabled = P2P_SWITCH_DEFAULT_VALUE;
117 #else
118  is_p2p_switch_enabled = false;
119 #endif
120  }
121  int clientType;
122  bool is_p2p_switch_enabled;
123  std::list<std::string> vosList;
124 };
125 
127  using onAudioPacketType = std::function<int(audio_packet_t&)>;
128  using onVideoPacketType = std::function<int(video_packet_t&)>;
129  using onVideoRtcpPacketType = std::function<int(video_rtcp_packet_t&)>;
130  using onVideoReportPacketType = std::function<int(video_report_packet_t&)>;
131  using onVideoCustomCtrlPacketType = std::function<int(video_custom_ctrl_broadcast_packet_t&)>;
132  using onAudioFrameType = std::function<int(SAudioFrame&)>;
133 
134  onAudioPacketType onAudioPacket_;
135  onVideoPacketType onVideoPacket_;
136  onVideoRtcpPacketType onVideoRtcpPacket_;
137  onVideoReportPacketType onVideoReportPacket_;
138  onVideoCustomCtrlPacketType onVideoCustomCtrlPacket_;
139  onAudioFrameType onAudioFrame_;
140  ReceivePacketHandler(onAudioPacketType&& onAudioPacket = nullptr,
141  onVideoPacketType&& onVideoPacket = nullptr,
142  onVideoRtcpPacketType&& onVideoRtcpPacket = nullptr,
143  onVideoReportPacketType&& onVideoReportPacket = nullptr,
144  onVideoCustomCtrlPacketType&& onVideoCustomCtrlPacket = nullptr,
145  onAudioFrameType&& onAudioFrame = nullptr)
146  : onAudioPacket_(std::move(onAudioPacket)),
147  onVideoPacket_(std::move(onVideoPacket)),
148  onVideoRtcpPacket_(std::move(onVideoRtcpPacket)),
149  onVideoReportPacket_(std::move(onVideoReportPacket)),
150  onVideoCustomCtrlPacket_(std::move(onVideoCustomCtrlPacket)),
151  onAudioFrame_(std::move(onAudioFrame)) {}
153  : onAudioPacket_(std::move(rhs.onAudioPacket_)),
154  onVideoPacket_(std::move(rhs.onVideoPacket_)),
155  onVideoRtcpPacket_(std::move(rhs.onVideoRtcpPacket_)),
156  onVideoReportPacket_(std::move(rhs.onVideoReportPacket_)),
157  onVideoCustomCtrlPacket_(std::move(rhs.onVideoCustomCtrlPacket_)),
158  onAudioFrame_(std::move(rhs.onAudioFrame_)) {}
159 };
160 
161 struct RtcConnStats {
162  RtcStats stats;
163  uint64_t banned_elapse = 0;
164  uint64_t space_id = UINT64_MAX;
165 };
166 
168  public:
169  virtual int initialize(const base::AgoraServiceConfiguration& serviceCfg,
170  const RtcConnectionConfiguration& cfg) = 0;
171  virtual int initializeEx(const base::AgoraServiceConfiguration& serviceCfg,
172  const RtcConnectionConfigurationEx& cfg) = 0;
173  virtual int deinitialize() = 0;
174  virtual void setUserRole(CLIENT_ROLE_TYPE role) = 0;
175  virtual CLIENT_ROLE_TYPE getUserRole() = 0;
176  virtual bool isEncryptionEnabled() const = 0;
177  virtual int sendAudioPacket(audio_packet_t& packet, int delay_ms = 0) = 0;
178  virtual int sendAudioFrame(SAudioFrame& frame) = 0;
179  virtual int sendVideoPacket(video_packet_t& packet) = 0;
180  virtual int batchSendVideoPacket(std::vector<video_packet_t>& packets) = 0;
181  virtual int sendBroadcastPacket(std::string&& data) = 0;
182  virtual int sendVideoRtcpPacket(video_rtcp_packet_t& rtcp) = 0;
183  virtual int sendVideoRtcpFeedbackPacket(video_report_packet_t& report) = 0;
184  virtual int sendVideoCustomCtrlBroadcastPacket(video_custom_ctrl_broadcast_packet_t& packet) = 0;
185  virtual void subscribeReceivePacketHandler(ReceivePacketHandler&& handler) = 0;
186  virtual void unsubscribeReceivePacketHandler() = 0;
187  virtual void setChannelId(const char* channel) = 0;
188  virtual void setConnectionState(CONNECTION_STATE_TYPE state) = 0;
189  virtual void setLocalUserId(user_id_t userId) = 0;
190  // FIXME: remove this after we rework internal logic. Only modules of the call
191  // engine relies on CallContext
192  virtual CallContext* getCallContext() = 0;
193  virtual std::shared_ptr<base::BaseWorker> getIOWorker() = 0;
194  virtual bool getUid(user_id_t userId, rtc::uid_t* uid) = 0;
195  virtual bool getUserId(rtc::uid_t uid, std::string& userId) = 0;
196  virtual rtc::uid_t getLocalUid() = 0;
197  virtual void muteLocalAudio(bool mute) = 0;
198  virtual void muteRemoteAudio(user_id_t userId, bool mute) = 0;
199  virtual void muteAllRemoteAudio(bool mute) = 0;
200  virtual void setDefaultMuteAllRemoteAudioStreams(bool mute) = 0;
201  virtual void muteLocalVideo(bool mute) = 0;
202  virtual void muteRemoteVideo(user_id_t userId, bool mute) = 0;
203  virtual void muteAllRemoteVideo(bool mute) = 0;
204  virtual void setDefaultMuteAllRemoteVideoStreams(bool mute) = 0;
205  virtual void setRemoteVideoStreamType(user_id_t userId, VIDEO_STREAM_TYPE type) = 0;
206  virtual void setRemoteDefaultVideoStreamType(VIDEO_STREAM_TYPE type) = 0;
207 
208  virtual void setRtcStats(const RtcStats& stats) = 0;
209  virtual void setBannedTime(const uint64_t banned_time) = 0;
210  virtual RtcConnStats GetStats() = 0;
211  virtual bool isConnected() = 0;
212  virtual uint32_t getCid() = 0;
213  virtual void setVos(const char* name, int port) = 0;
214  virtual int reportArgusCounters(int* counterId, int* value, int count, user_id_t userId) = 0;
215  virtual void setChannelProfile(CHANNEL_PROFILE_TYPE channel_profile) = 0;
216 
217  // The following functions should only be used in UT.
218  virtual AudioPacketFilter* getAudioPacketFilter() = 0;
219  virtual VideoPacketFilter* getVideoPacketFilter() = 0;
220  virtual bool hasAudioRemoteTrack(user_id_t id) = 0;
221  virtual bool hasVideoRemoteTrack(user_id_t id, uint32_t ssrc) = 0;
222  // The upper functions should only be used by UT.
223 
224  virtual CongestionControlType ccType() = 0;
225 
226  // TODO(hanpengfei): maybe need to implement at other place.
227  virtual bool isRtcContextValid() = 0;
228  virtual void onClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) = 0;
229  virtual void onApiCallExecuted(int err, const char* api, const char* result) = 0;
230  virtual void networkChanged(commons::network::network_info_t&& networkInfo) = 0;
231  virtual int sendReport(const void* data, size_t length, int level, int type, int retry,
232  const base::ExtraReportData* extra) = 0;
233  virtual int setParameters(const std::string& parameters, bool cache,
234  bool suppressNotification) = 0;
235  virtual int getParameters(const std::string& parameters, any_document_t& results) = 0;
236  virtual void stopAsyncHandler(bool waitForExit) = 0;
237  virtual bool registerEventHandler(IRtcEngineEventHandler* eventHandler,
238  bool isExHandler) = 0;
239  virtual bool unregisterEventHandler(IRtcEngineEventHandler* eventHandler) = 0;
240  virtual void setPacketObserver(IPacketObserver* observer) = 0;
241  virtual int sendWebAgentVideoStats(const std::string& uidstr,
242  const WebAgentVideoStats& stats) = 0;
243  virtual void sendRecordingArgusEvents(const protocol::CmdRecordingEventReportArgus& events) = 0;
244 
245  virtual int sendCallRating(const std::string& callId, int rating,
246  const std::string& description) = 0;
247  virtual bool isCommunicationMode() = 0;
248  virtual bool isWebrtcPacerEnabled() = 0;
249  virtual void didStreamMessageSync(uid_t userId, int streamId, const char* data, size_t length,
250  uint64_t sentTs) = 0;
251 };
252 
253 } // namespace rtc
254 } // namespace agora
agora::rtc::RtcConnectionConfiguration::channelProfile
CHANNEL_PROFILE_TYPE channelProfile
Definition: NGIAgoraRtcConnection.h:134
agora::rtc::RtcConnectionConfiguration::audioSubscriptionOptions
AudioSubscriptionOptions audioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:127
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:119
agora::rtc::WebAgentVideoStats
Definition: rtc_engine_i.h:193
agora::rtc::INetworkObserver
Definition: NGIAgoraRtcConnection.h:748
agora::rtc::PacketOptions
Definition: rtc_connection_i.h:58
agora::base::AgoraServiceConfiguration
Definition: IAgoraService.h:80
agora::rtc::IRtcEngineEventHandler
Definition: IAgoraRtcEngine.h:836
agora::rtc::RtcConnectionConfiguration::autoSubscribeAudio
bool autoSubscribeAudio
Definition: NGIAgoraRtcConnection.h:99
agora::rtc::RtcConnectionConfiguration::audioRecvMediaPacket
bool audioRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:139
agora::rtc::RtcConnStats
Definition: rtc_connection_i.h:161
agora::rtc::IPacketObserver
Definition: AgoraBase.h:2835
agora::rtc::RtcConnectionConfigurationEx
Definition: rtc_connection_i.h:92
agora::rtc::ReceivePacketHandler
Definition: rtc_connection_i.h:126
agora::media::base::PacketOptions
Definition: AgoraMediaBase.h:126
agora::rtc::video_packet_t
Definition: packet_i.h:124
agora::rtc::video_rtcp_packet_t
Definition: packet_i.h:232
agora::rtc::SAudioFrame
Definition: packet_i.h:48
agora::rtc::RtcConnectionConfiguration::enableAudioRecordingOrPlayout
bool enableAudioRecordingOrPlayout
Definition: NGIAgoraRtcConnection.h:111
agora::rtc::audio_packet_t
Definition: packet_i.h:115
agora::rtc::RtcConnectionConfiguration::videoRecvMediaPacket
bool videoRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:144
agora::rtc::RtcConnectionConfiguration::autoSubscribeVideo
bool autoSubscribeVideo
Definition: NGIAgoraRtcConnection.h:105
agora::rtc::RtcStats
Definition: AgoraBase.h:2040
agora::rtc::RtcConnectionConfiguration
Definition: NGIAgoraRtcConnection.h:93
agora::rtc::RtcConnectionConfiguration::maxPort
int maxPort
Definition: NGIAgoraRtcConnection.h:123
agora::rtc::video_report_packet_t
Definition: packet_i.h:243
agora::rtc::video_custom_ctrl_broadcast_packet_t
Definition: packet_i.h:238
agora::rtc::IRtcConnection
Definition: NGIAgoraRtcConnection.h:169
agora::rtc::RtcConnectionConfiguration::maxSendBitrate
int maxSendBitrate
Definition: NGIAgoraRtcConnection.h:115
agora::rtc::IRtcConnectionEx
Definition: rtc_connection_i.h:167