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 space_id = UINT64_MAX;
164 };
165 
167  public:
168  virtual int initialize(const base::AgoraServiceConfiguration& serviceCfg,
169  const RtcConnectionConfiguration& cfg) = 0;
170  virtual int initializeEx(const base::AgoraServiceConfiguration& serviceCfg,
171  const RtcConnectionConfigurationEx& cfg) = 0;
172  virtual int deinitialize() = 0;
173  virtual void setUserRole(CLIENT_ROLE_TYPE role) = 0;
174  virtual CLIENT_ROLE_TYPE getUserRole() = 0;
175  virtual bool isEncryptionEnabled() const = 0;
176  virtual int sendAudioPacket(audio_packet_t& packet, int delay_ms = 0) = 0;
177  virtual int sendAudioFrame(SAudioFrame& frame) = 0;
178  virtual int sendVideoPacket(video_packet_t& packet) = 0;
179  virtual int batchSendVideoPacket(std::vector<video_packet_t>& packets) = 0;
180  virtual int sendBroadcastPacket(std::string&& data) = 0;
181  virtual int sendVideoRtcpPacket(video_rtcp_packet_t& rtcp) = 0;
182  virtual int sendVideoRtcpFeedbackPacket(video_report_packet_t& report) = 0;
183  virtual int sendVideoCustomCtrlBroadcastPacket(video_custom_ctrl_broadcast_packet_t& packet) = 0;
184  virtual void subscribeReceivePacketHandler(ReceivePacketHandler&& handler) = 0;
185  virtual void unsubscribeReceivePacketHandler() = 0;
186  virtual void setChannelId(const char* channel) = 0;
187  virtual void setConnectionState(CONNECTION_STATE_TYPE state) = 0;
188  virtual void setLocalUserId(user_id_t userId) = 0;
189  // FIXME: remove this after we rework internal logic. Only modules of the call
190  // engine relies on CallContext
191  virtual CallContext* getCallContext() = 0;
192  virtual std::shared_ptr<base::BaseWorker> getIOWorker() = 0;
193  virtual bool getUid(user_id_t userId, rtc::uid_t* uid) = 0;
194  virtual bool getUserId(rtc::uid_t uid, std::string& userId) = 0;
195  virtual rtc::uid_t getLocalUid() = 0;
196  virtual void muteLocalAudio(bool mute) = 0;
197  virtual void muteRemoteAudio(user_id_t userId, bool mute) = 0;
198  virtual void muteAllRemoteAudio(bool mute) = 0;
199  virtual void setDefaultMuteAllRemoteAudioStreams(bool mute) = 0;
200  virtual void muteLocalVideo(bool mute) = 0;
201  virtual void muteRemoteVideo(user_id_t userId, bool mute) = 0;
202  virtual void muteAllRemoteVideo(bool mute) = 0;
203  virtual void setDefaultMuteAllRemoteVideoStreams(bool mute) = 0;
204  virtual void setRemoteVideoStreamType(user_id_t userId, VIDEO_STREAM_TYPE type) = 0;
205  virtual void setRemoteDefaultVideoStreamType(VIDEO_STREAM_TYPE type) = 0;
206 
207  virtual void setRtcStats(const RtcStats& stats) = 0;
208  virtual RtcConnStats GetStats() = 0;
209  virtual bool isConnected() = 0;
210  virtual uint32_t getCid() = 0;
211  virtual void setVos(const char* name, int port) = 0;
212  virtual int reportArgusCounters(int* counterId, int* value, int count, user_id_t userId) = 0;
213  virtual void setChannelProfile(CHANNEL_PROFILE_TYPE channel_profile) = 0;
214 
215  // The following functions should only be used in UT.
216  virtual AudioPacketFilter* getAudioPacketFilter() = 0;
217  virtual VideoPacketFilter* getVideoPacketFilter() = 0;
218  virtual bool hasAudioRemoteTrack(user_id_t id) = 0;
219  virtual bool hasVideoRemoteTrack(user_id_t id, uint32_t ssrc) = 0;
220  // The upper functions should only be used by UT.
221 
222  virtual CongestionControlType ccType() = 0;
223 
224  // TODO(hanpengfei): maybe need to implement at other place.
225  virtual bool isRtcContextValid() = 0;
226  virtual void onClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole) = 0;
227  virtual void onApiCallExecuted(int err, const char* api, const char* result) = 0;
228  virtual void networkChanged(commons::network::network_info_t&& networkInfo) = 0;
229  virtual int sendReport(const void* data, size_t length, int level, int type, int retry,
230  const base::ExtraReportData* extra) = 0;
231  virtual int setParameters(const std::string& parameters, bool cache,
232  bool suppressNotification) = 0;
233  virtual int getParameters(const std::string& parameters, any_document_t& results) = 0;
234  virtual void stopAsyncHandler(bool waitForExit) = 0;
235  virtual bool registerEventHandler(IRtcEngineEventHandler* eventHandler,
236  bool isExHandler) = 0;
237  virtual bool unregisterEventHandler(IRtcEngineEventHandler* eventHandler) = 0;
238  virtual void setPacketObserver(IPacketObserver* observer) = 0;
239  virtual int sendWebAgentVideoStats(const std::string& uidstr,
240  const WebAgentVideoStats& stats) = 0;
241  virtual void sendRecordingArgusEvents(const protocol::CmdRecordingEventReportArgus& events) = 0;
242 
243  virtual int sendCallRating(const std::string& callId, int rating,
244  const std::string& description) = 0;
245  virtual bool isCommunicationMode() = 0;
246  virtual bool isWebrtcPacerEnabled() = 0;
247  virtual void didStreamMessageSync(uid_t userId, int streamId, const char* data, size_t length,
248  uint64_t sentTs) = 0;
249 };
250 
251 } // namespace rtc
252 } // namespace agora
agora::rtc::RtcConnectionConfiguration::channelProfile
CHANNEL_PROFILE_TYPE channelProfile
Definition: NGIAgoraRtcConnection.h:135
agora::rtc::RtcConnectionConfiguration::audioSubscriptionOptions
AudioSubscriptionOptions audioSubscriptionOptions
Definition: NGIAgoraRtcConnection.h:128
agora::rtc::RtcConnectionConfiguration::minPort
int minPort
Definition: NGIAgoraRtcConnection.h:120
agora::rtc::WebAgentVideoStats
Definition: rtc_engine_i.h:193
agora::rtc::INetworkObserver
Definition: NGIAgoraRtcConnection.h:749
agora::rtc::PacketOptions
Definition: rtc_connection_i.h:58
agora::base::AgoraServiceConfiguration
Definition: IAgoraService.h:78
agora::rtc::IRtcEngineEventHandler
Definition: IAgoraRtcEngine.h:853
agora::rtc::RtcConnectionConfiguration::autoSubscribeAudio
bool autoSubscribeAudio
Definition: NGIAgoraRtcConnection.h:100
agora::rtc::RtcConnectionConfiguration::audioRecvMediaPacket
bool audioRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:140
agora::rtc::RtcConnStats
Definition: rtc_connection_i.h:161
agora::rtc::IPacketObserver
Definition: AgoraBase.h:2746
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:106
agora::rtc::video_packet_t
Definition: packet_i.h:121
agora::rtc::video_rtcp_packet_t
Definition: packet_i.h:229
agora::rtc::SAudioFrame
Definition: packet_i.h:48
agora::rtc::RtcConnectionConfiguration::enableAudioRecordingOrPlayout
bool enableAudioRecordingOrPlayout
Definition: NGIAgoraRtcConnection.h:112
agora::rtc::audio_packet_t
Definition: packet_i.h:112
agora::rtc::RtcConnectionConfiguration::videoRecvMediaPacket
bool videoRecvMediaPacket
Definition: NGIAgoraRtcConnection.h:145
agora::rtc::RtcConnectionConfiguration::autoSubscribeVideo
bool autoSubscribeVideo
Definition: NGIAgoraRtcConnection.h:106
agora::rtc::RtcStats
Definition: AgoraBase.h:1952
agora::rtc::RtcConnectionConfiguration
Definition: NGIAgoraRtcConnection.h:94
agora::rtc::RtcConnectionConfiguration::maxPort
int maxPort
Definition: NGIAgoraRtcConnection.h:124
agora::rtc::video_report_packet_t
Definition: packet_i.h:240
agora::rtc::video_custom_ctrl_broadcast_packet_t
Definition: packet_i.h:235
agora::rtc::IRtcConnection
Definition: NGIAgoraRtcConnection.h:170
agora::rtc::RtcConnectionConfiguration::maxSendBitrate
int maxSendBitrate
Definition: NGIAgoraRtcConnection.h:116
agora::rtc::IRtcConnectionEx
Definition: rtc_connection_i.h:166