Agora C++ API Reference for All Platforms

NGIAgoraRtmpConnection.h
1 //
2 // Agora RTMP connection
3 //
4 // Created by Haonong Yu in 2020-02.
5 // Copyright (c) 2020 Agora.io. All rights reserved.
6 //
7
8 #pragma once // NOLINT(build/header_guard)
9
10 #include "AgoraBase.h"
11 #include "AgoraRefPtr.h"
12 #include <api/cpp/aosl_ares_class.h>
13
14 namespace agora {
15 namespace rtc {
16
17 class IRtmpLocalUser;
18
22 struct RtmpStreamingAudioConfiguration {
26 int sampleRateHz;
27
31 int bytesPerSample;
32
36 int numberOfChannels;
37
42 int bitrate;
43
44 RtmpStreamingAudioConfiguration(): sampleRateHz(44100), bytesPerSample(2),
45 numberOfChannels(1), bitrate(48000) {}
46 };
47
51 struct RtmpStreamingVideoConfiguration {
60 int width;
61
70 int height;
71
76 int framerate;
77
82 int bitrate;
83
88 int maxBitrate;
89
94 int minBitrate;
95
100 unsigned int gopInMs;
101
109 int encoderHwSwMode;
110
117 int encoderBitrateControlMode;
118
123 ORIENTATION_MODE orientationMode;
124
125 RtmpStreamingVideoConfiguration(): width(640), height(360), framerate(15),
126 bitrate(800), maxBitrate(960), minBitrate(600), gopInMs(2000), encoderHwSwMode(0),encoderBitrateControlMode(0),
127 orientationMode(ORIENTATION_MODE_ADAPTIVE) {}
128 };
129
130
134 enum RTMP_CONNECTION_ERROR {
138 RTMP_CONNECTION_ERR_OK = 0,
139
143 RTMP_CONNECTION_ERR_FAILED = 1,
144
148 RTMP_CONNECTION_ERR_INVALID_URL = 2,
149
153 RTMP_CONNECTION_ERR_BAD_NAME = 3,
154 };
155
159 enum RTMP_CONNECTION_STATE {
171 STATE_DISCONNECTED = 1,
172
184 STATE_CONNECTING = 2,
185
196 STATE_CONNECTED = 3,
197
206 STATE_RECONNECTING = 4,
207
215 STATE_FAILED = 5,
216
225 STATE_RECONNECTED = 6
226 };
227
231 struct RtmpConnectionConfiguration {
232 RtmpStreamingAudioConfiguration audioConfig;
233 RtmpStreamingVideoConfiguration videoConfig;
234 bool audioOnly;
235 RtmpConnectionConfiguration() : audioOnly(false) {}
236 };
237
241 struct RtmpConnectionInfo {
245 RTMP_CONNECTION_STATE state;
246
247 RtmpConnectionInfo() : state(STATE_DISCONNECTED) {}
248 };
249
250
254 class IRtmpConnectionObserver {
255 public:
261 virtual void onConnected(const RtmpConnectionInfo& connectionInfo) = 0;
262
268 virtual void onDisconnected(const RtmpConnectionInfo& connectionInfo) = 0;
269
275 virtual void onReconnecting(const RtmpConnectionInfo& connectionInfo) = 0;
276
282 virtual void onReconnected(const RtmpConnectionInfo& connectionInfo) = 0;
283
290 virtual void onConnectionFailure(const RtmpConnectionInfo& connectionInfo,
291 RTMP_CONNECTION_ERROR errCode) = 0;
292
302 virtual void onTransferStatistics(uint64_t video_width, uint64_t video_height, uint64_t video_bitrate, uint64_t audio_bitrate, uint64_t video_frame_rate, uint64_t push_video_frame_cnt, uint64_t pop_video_frame_cnt) = 0;
303
304 virtual ~IRtmpConnectionObserver() {}
305 };
306
317 class IRtmpConnection : public RefCountInterface {
318 public:
319 ~IRtmpConnection() {}
320
340 virtual int connect(const char* url, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
341
349 virtual int disconnect(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
350
358 virtual RtmpConnectionInfo getConnectionInfo() = 0;
359
367 virtual IRtmpLocalUser* getRtmpLocalUser() = 0;
368
377 virtual int registerObserver(IRtmpConnectionObserver* observer, void(*safeDeleter)(IRtmpConnectionObserver*) = NULL, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
378
388 virtual int unregisterObserver(IRtmpConnectionObserver* observer) = 0;
389 };
390
391 } // namespace rtc
392 } // namespace agora
agora::rtc::STATE_RECONNECTING
@ STATE_RECONNECTING
Definition: NGIAgoraRtmpConnection.h:206
agora::rtc::IRtmpConnection::unregisterObserver
virtual int unregisterObserver(IRtmpConnectionObserver *observer)=0
agora::rtc::RtmpStreamingAudioConfiguration::bytesPerSample
int bytesPerSample
Definition: NGIAgoraRtmpConnection.h:31
agora::rtc::RtmpStreamingVideoConfiguration::encoderBitrateControlMode
int encoderBitrateControlMode
Definition: NGIAgoraRtmpConnection.h:117
agora::rtc::IRtmpConnection::getRtmpLocalUser
virtual IRtmpLocalUser * getRtmpLocalUser()=0
agora::rtc::RTMP_CONNECTION_ERR_INVALID_URL
@ RTMP_CONNECTION_ERR_INVALID_URL
Definition: NGIAgoraRtmpConnection.h:148
agora::rtc::IRtmpConnection::connect
virtual int connect(const char *url, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::ORIENTATION_MODE
ORIENTATION_MODE
Definition: AgoraBase.h:1029
agora::rtc::RtmpStreamingVideoConfiguration::height
int height
Definition: NGIAgoraRtmpConnection.h:70
agora::rtc::STATE_FAILED
@ STATE_FAILED
Definition: NGIAgoraRtmpConnection.h:215
agora::rtc::IRtmpConnection::~IRtmpConnection
~IRtmpConnection()
Definition: NGIAgoraRtmpConnection.h:319
agora::rtc::STATE_RECONNECTED
@ STATE_RECONNECTED
Definition: NGIAgoraRtmpConnection.h:225
agora::rtc::RtmpConnectionInfo::RtmpConnectionInfo
RtmpConnectionInfo()
Definition: NGIAgoraRtmpConnection.h:247
agora::rtc::IRtmpConnectionObserver::onReconnected
virtual void onReconnected(const RtmpConnectionInfo &connectionInfo)=0
agora::rtc::RtmpStreamingVideoConfiguration::orientationMode
ORIENTATION_MODE orientationMode
Definition: NGIAgoraRtmpConnection.h:123
agora::rtc::RtmpConnectionConfiguration::videoConfig
RtmpStreamingVideoConfiguration videoConfig
Definition: NGIAgoraRtmpConnection.h:233
agora::rtc::IRtmpConnection
Definition: NGIAgoraRtmpConnection.h:317
agora::rtc::IRtmpConnectionObserver::onReconnecting
virtual void onReconnecting(const RtmpConnectionInfo &connectionInfo)=0
agora::rtc::RtmpConnectionConfiguration
Definition: NGIAgoraRtmpConnection.h:231
agora::rtc::RtmpConnectionInfo
Definition: NGIAgoraRtmpConnection.h:241
agora::rtc::RTMP_CONNECTION_ERR_OK
@ RTMP_CONNECTION_ERR_OK
Definition: NGIAgoraRtmpConnection.h:138
agora
Definition: AgoraAtomicOps.h:21
agora::rtc::RTMP_CONNECTION_STATE
RTMP_CONNECTION_STATE
Definition: NGIAgoraRtmpConnection.h:159
agora::rtc::RtmpConnectionConfiguration::audioOnly
bool audioOnly
Definition: NGIAgoraRtmpConnection.h:234
agora::rtc::RtmpStreamingVideoConfiguration::minBitrate
int minBitrate
Definition: NGIAgoraRtmpConnection.h:94
agora::rtc::RtmpStreamingVideoConfiguration::width
int width
Definition: NGIAgoraRtmpConnection.h:60
agora::rtc::RtmpStreamingVideoConfiguration
Definition: NGIAgoraRtmpConnection.h:51
agora::rtc::RtmpStreamingAudioConfiguration::sampleRateHz
int sampleRateHz
Definition: NGIAgoraRtmpConnection.h:26
agora::rtc::IRtmpConnectionObserver::onDisconnected
virtual void onDisconnected(const RtmpConnectionInfo &connectionInfo)=0
agora::rtc::RtmpStreamingVideoConfiguration::encoderHwSwMode
int encoderHwSwMode
Definition: NGIAgoraRtmpConnection.h:109
agora::rtc::RtmpStreamingAudioConfiguration::RtmpStreamingAudioConfiguration
RtmpStreamingAudioConfiguration()
Definition: NGIAgoraRtmpConnection.h:44
agora::rtc::RtmpStreamingVideoConfiguration::RtmpStreamingVideoConfiguration
RtmpStreamingVideoConfiguration()
Definition: NGIAgoraRtmpConnection.h:125
agora::rtc::RtmpStreamingAudioConfiguration
Definition: NGIAgoraRtmpConnection.h:22
agora::rtc::IRtmpConnectionObserver::onConnected
virtual void onConnected(const RtmpConnectionInfo &connectionInfo)=0
agora::rtc::IRtmpConnection::registerObserver
virtual int registerObserver(IRtmpConnectionObserver *observer, void(*safeDeleter)(IRtmpConnectionObserver *)=NULL, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::RTMP_CONNECTION_ERR_BAD_NAME
@ RTMP_CONNECTION_ERR_BAD_NAME
Definition: NGIAgoraRtmpConnection.h:153
agora::rtc::ORIENTATION_MODE_ADAPTIVE
@ ORIENTATION_MODE_ADAPTIVE
Definition: AgoraBase.h:1037
agora::rtc::STATE_CONNECTING
@ STATE_CONNECTING
Definition: NGIAgoraRtmpConnection.h:184
agora::rtc::RtmpStreamingAudioConfiguration::numberOfChannels
int numberOfChannels
Definition: NGIAgoraRtmpConnection.h:36
agora::rtc::RtmpConnectionInfo::state
RTMP_CONNECTION_STATE state
Definition: NGIAgoraRtmpConnection.h:245
agora::rtc::RtmpStreamingVideoConfiguration::gopInMs
unsigned int gopInMs
Definition: NGIAgoraRtmpConnection.h:100
agora::rtc::IRtmpConnection::disconnect
virtual int disconnect(aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::RtmpConnectionConfiguration::RtmpConnectionConfiguration
RtmpConnectionConfiguration()
Definition: NGIAgoraRtmpConnection.h:235
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::STATE_CONNECTED
@ STATE_CONNECTED
Definition: NGIAgoraRtmpConnection.h:196
agora::rtc::RTMP_CONNECTION_ERR_FAILED
@ RTMP_CONNECTION_ERR_FAILED
Definition: NGIAgoraRtmpConnection.h:143
agora::rtc::IRtmpConnection::getConnectionInfo
virtual RtmpConnectionInfo getConnectionInfo()=0
agora::rtc::IRtmpLocalUser
Definition: NGIAgoraRtmpLocalUser.h:117
agora::rtc::STATE_DISCONNECTED
@ STATE_DISCONNECTED
Definition: NGIAgoraRtmpConnection.h:171
agora::rtc::IRtmpConnectionObserver::onTransferStatistics
virtual void onTransferStatistics(uint64_t video_width, uint64_t video_height, uint64_t video_bitrate, uint64_t audio_bitrate, uint64_t video_frame_rate, uint64_t push_video_frame_cnt, uint64_t pop_video_frame_cnt)=0
agora::rtc::RtmpStreamingVideoConfiguration::framerate
int framerate
Definition: NGIAgoraRtmpConnection.h:76
agora::rtc::RtmpStreamingAudioConfiguration::bitrate
int bitrate
Definition: NGIAgoraRtmpConnection.h:42
agora::rtc::IRtmpConnectionObserver::~IRtmpConnectionObserver
virtual ~IRtmpConnectionObserver()
Definition: NGIAgoraRtmpConnection.h:304
agora::rtc::RtmpConnectionConfiguration::audioConfig
RtmpStreamingAudioConfiguration audioConfig
Definition: NGIAgoraRtmpConnection.h:232
agora::rtc::RtmpStreamingVideoConfiguration::bitrate
int bitrate
Definition: NGIAgoraRtmpConnection.h:82
agora::rtc::RtmpStreamingVideoConfiguration::maxBitrate
int maxBitrate
Definition: NGIAgoraRtmpConnection.h:88
agora::rtc::IRtmpConnectionObserver::onConnectionFailure
virtual void onConnectionFailure(const RtmpConnectionInfo &connectionInfo, RTMP_CONNECTION_ERROR errCode)=0
agora::rtc::IRtmpConnectionObserver
Definition: NGIAgoraRtmpConnection.h:254
rtc
Definition: video_node_i.h:28
agora::rtc::RTMP_CONNECTION_ERROR
RTMP_CONNECTION_ERROR
Definition: NGIAgoraRtmpConnection.h:134