Skip to content

Commit 2d969a6

Browse files
author
xianing
committed
adapt 3.6.0 for windows
1 parent 5c98e9c commit 2d969a6

3 files changed

Lines changed: 60 additions & 134 deletions

File tree

windows/APIExample/APIExample/Advanced/MultiChannel/CAgoraMultiChannelDlg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class ChannelEventHandler :public agora::rtc::IChannelEventHandler
455455
@param state The RTMP streaming state. See: #RTMP_STREAM_PUBLISH_STATE.
456456
@param errCode The detailed error information for streaming. See: #RTMP_STREAM_PUBLISH_ERROR.
457457
*/
458-
virtual void onRtmpStreamingStateChanged(IChannel *rtcChannel, const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR errCode) {
458+
virtual void onRtmpStreamingStateChanged(IChannel *rtcChannel, const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR_TYPE errCode) {
459459

460460
}
461461

windows/APIExample/APIExample/Advanced/RTMPStream/AgoraRtmpStreaming.cpp

Lines changed: 58 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onUserOffline(uid_t uid, USER_
8989
@param state The RTMP streaming state. See: #RTMP_STREAM_PUBLISH_STATE.
9090
@param errCode The detailed error information for streaming. See: #RTMP_STREAM_PUBLISH_ERROR.
9191
*/
92-
void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onRtmpStreamingStateChanged(const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR errCode)
92+
void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onRtmpStreamingStateChanged(const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR_TYPE errCode)
9393
{
9494
if (m_hMsgHanlder) {
9595
PRtmpStreamStreamStateChanged rtmpState = new RtmpStreamStreamStateChanged;
@@ -116,31 +116,6 @@ void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onRtmpStreamingEvent(const cha
116116
}
117117
}
118118

119-
120-
121-
void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onStreamUnpublished(const char *url)
122-
{
123-
if (m_hMsgHanlder) {
124-
PStreamPublished streamPublished = new StreamPublished;
125-
int len = strlen(url);
126-
char* publishUrl = new char[len + 1];
127-
memset(publishUrl, 0, sizeof(publishUrl));
128-
strcpy_s(publishUrl, len, url);
129-
::PostMessage(m_hMsgHanlder, WM_MSGID(EID_RTMP_STREAM_STATE_UNPUBLISHED), (WPARAM)streamPublished, 0);
130-
}
131-
}
132-
133-
void CAgoraRtmpStreamingDlgRtcEngineEventHandler::onStreamPublished(const char *url, int error)
134-
{
135-
if (m_hMsgHanlder) {
136-
int len = strlen(url);
137-
char* publishUrl = new char[len + 1];
138-
memset(publishUrl, 0, sizeof(publishUrl));
139-
strcpy_s(publishUrl, len, url);
140-
::PostMessage(m_hMsgHanlder, WM_MSGID(EID_RTMP_STREAM_STATE_PUBLISHED), (WPARAM)publishUrl, error);
141-
}
142-
}
143-
144119
IMPLEMENT_DYNAMIC(CAgoraRtmpStreamingDlg, CDialogEx)
145120

146121
CAgoraRtmpStreamingDlg::CAgoraRtmpStreamingDlg(CWnd* pParent /*=nullptr*/)
@@ -182,8 +157,6 @@ BEGIN_MESSAGE_MAP(CAgoraRtmpStreamingDlg, CDialogEx)
182157
ON_MESSAGE(WM_MSGID(EID_RTMP_STREAM_STATE_CHANGED), &CAgoraRtmpStreamingDlg::OnEIDRtmpStateChanged)
183158
ON_MESSAGE(WM_MSGID(EID_USER_JOINED), &CAgoraRtmpStreamingDlg::OnEIDUserJoined)
184159
ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &CAgoraRtmpStreamingDlg::OnEIDUserOffline)
185-
ON_MESSAGE(WM_MSGID(EID_RTMP_STREAM_STATE_PUBLISHED), &CAgoraRtmpStreamingDlg::OnEIDStreamPublished)
186-
ON_MESSAGE(WM_MSGID(EID_RTMP_STREAM_STATE_UNPUBLISHED), &CAgoraRtmpStreamingDlg::OnEIDStreamUnpublished)
187160
ON_BN_CLICKED(IDC_BUTTON_JOINCHANNEL, &CAgoraRtmpStreamingDlg::OnBnClickedButtonJoinchannel)
188161
ON_BN_CLICKED(IDC_BUTTON_ADDSTREAM, &CAgoraRtmpStreamingDlg::OnBnClickedButtonAddstream)
189162
ON_BN_CLICKED(IDC_BUTTON_REMOVE_STREAM, &CAgoraRtmpStreamingDlg::OnBnClickedButtonRemoveStream)
@@ -316,7 +289,7 @@ void CAgoraRtmpStreamingDlg::RemoveAllRtmpUrls()
316289
for (int i = 0; i < m_cmbRtmpUrl.GetCount(); ++i) {
317290
m_cmbRtmpUrl.GetLBText(i, strUrl);
318291
std::string szUrl = cs2utf8(strUrl);
319-
m_rtcEngine->removePublishStreamUrl(szUrl.c_str());
292+
m_rtcEngine->stopRtmpStream(szUrl.c_str());
320293
}
321294
m_cmbRtmpUrl.Clear();
322295
m_cmbRtmpUrl.ResetContent();
@@ -393,7 +366,14 @@ void CAgoraRtmpStreamingDlg::OnBnClickedButtonAddstream()
393366
std::string szURL = cs2utf8(strURL);
394367
BOOL isTransCoding = m_chkTransCoding.GetCheck();
395368
// add publish stream in the engine.
396-
int ret = m_rtcEngine->addPublishStreamUrl(szURL.c_str(), isTransCoding);
369+
int ret;
370+
371+
if (isTransCoding) {
372+
ret = m_rtcEngine->startRtmpStreamWithTranscoding(szURL.c_str(), m_liveTransCoding);
373+
}
374+
else {
375+
ret = m_rtcEngine->startRtmpStreamWithoutTranscoding(szURL.c_str());
376+
}
397377

398378
if (ret != 0) {
399379
CString strInfo;
@@ -417,7 +397,7 @@ void CAgoraRtmpStreamingDlg::OnBnClickedButtonRemoveStream()
417397
m_cmbRtmpUrl.GetWindowText(strUrl);
418398
std::string szUrl = cs2utf8(strUrl);
419399
//remove publish stream in the engine.
420-
m_rtcEngine->removePublishStreamUrl(szUrl.c_str());
400+
m_rtcEngine->stopRtmpStream(szUrl.c_str());
421401
}
422402

423403
//remove all streams in the engine.
@@ -434,7 +414,7 @@ void CAgoraRtmpStreamingDlg::OnBnClickedButtonRemoveAllstream()
434414

435415
std::string szUrl = cs2utf8(strUrl);
436416
//remove public stream in the engine.
437-
m_rtcEngine->removePublishStreamUrl(szUrl.c_str());
417+
m_rtcEngine->stopRtmpStream(szUrl.c_str());
438418
m_btnRemoveStream.EnableWindow(FALSE);
439419
}
440420

@@ -479,7 +459,7 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam)
479459
//add user info to TranscodingUsers.
480460
m_liveTransCoding.transcodingUsers = p;
481461
//set current live trans coding.
482-
m_rtcEngine->setLiveTranscoding(m_liveTransCoding);
462+
m_rtcEngine->updateRtmpTranscoding(m_liveTransCoding);
483463
return TRUE;
484464
}
485465

@@ -505,7 +485,7 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDUserOffline(WPARAM wParam, LPARAM lParam)
505485
m_liveTransCoding.transcodingUsers[i].width = width;
506486
}
507487
//set current live trans coding.
508-
m_rtcEngine->setLiveTranscoding(m_liveTransCoding);
488+
m_rtcEngine->updateRtmpTranscoding(m_liveTransCoding);
509489
return TRUE;
510490
}
511491

@@ -584,6 +564,49 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDRtmpStateChanged(WPARAM wParam, LPARAM lPar
584564
break;
585565
case RTMP_STREAM_PUBLISH_STATE_FAILURE:
586566
{
567+
strInfo = agoraRtmpStateRunningSuccess;
568+
CString strUrl;
569+
strUrl.Format(_T("%S"), rtmpState->url);
570+
std::string szUrl = cs2utf8(strUrl);
571+
m_rtcEngine->stopRtmpStream(szUrl.c_str());
572+
573+
int error = lParam;
574+
if (error == RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT
575+
|| error == RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR
576+
|| error == RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND
577+
|| error == RTMP_STREAM_PUBLISH_ERROR_NET_DOWN) {
578+
579+
m_mapRemoveFlag[szUrl.c_str()] = false;
580+
m_mapRepublishFlag[szUrl.c_str()] = true;
581+
CString strUrl;
582+
strUrl.Format(_T("%S"), szUrl.c_str());
583+
for (int i = 0; i < m_cmbRtmpUrl.GetCount(); ++i) {
584+
CString strText;
585+
m_cmbRtmpUrl.GetLBText(i, strText);
586+
if (strText.Compare(strUrl) == 0) {
587+
m_cmbRtmpUrl.DeleteString(i);
588+
break;
589+
}
590+
}
591+
592+
if (m_urlSet.find(strUrl) != m_urlSet.end()) {
593+
m_urlSet.erase(strUrl);
594+
}
595+
596+
if (m_cmbRtmpUrl.GetCurSel() < 0 && m_cmbRtmpUrl.GetCount() > 0)
597+
m_cmbRtmpUrl.SetCurSel(0);
598+
}
599+
else {
600+
if (m_mapRepublishFlag.find(szUrl.c_str()) != m_mapRepublishFlag.end()
601+
&& m_mapRemoveFlag.find(szUrl.c_str()) != m_mapRemoveFlag.end()) {
602+
if (m_mapRepublishFlag[szUrl.c_str()]
603+
&& !m_mapRemoveFlag[szUrl.c_str()]) {//republish, removePublish when error
604+
m_rtcEngine->startRtmpStreamWithoutTranscoding(szUrl.c_str());
605+
}
606+
}
607+
}
608+
609+
587610
switch (rtmpState->state)
588611
{
589612
case RTMP_STREAM_PUBLISH_ERROR_INVALID_ARGUMENT:
@@ -700,70 +723,6 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDRtmpEvent(WPARAM wParam, LPARAM lParam)
700723
return 0;
701724
}
702725

703-
LRESULT CAgoraRtmpStreamingDlg::OnEIDStreamUnpublished(WPARAM wParam, LPARAM lParam)
704-
{
705-
char* url = (char*)wParam;
706-
707-
if (m_mapRepublishFlag.find(url) != m_mapRepublishFlag.end()
708-
&& m_mapRemoveFlag.find(url) != m_mapRemoveFlag.end()) {
709-
if (m_mapRepublishFlag[url]
710-
&& !m_mapRemoveFlag[url]) {//republish, removePublish when error
711-
m_rtcEngine->addPublishStreamUrl(url, false);
712-
}
713-
}
714-
715-
delete[] url;
716-
url = nullptr;
717-
return 0;
718-
}
719-
720-
LRESULT CAgoraRtmpStreamingDlg::OnEIDStreamPublished(WPARAM wParam, LPARAM lParam)
721-
{
722-
char* url = (char*)wParam;
723-
int error = lParam;
724-
725-
if (error == 1 || error == 10 || error == 154) {
726-
m_mapRemoveFlag[url] = false;
727-
m_rtcEngine->removePublishStreamUrl(url);
728-
m_mapRepublishFlag[url] = true;
729-
CString strUrl;
730-
strUrl.Format(_T("%S"), url);
731-
for (int i = 0; i < m_cmbRtmpUrl.GetCount(); ++i) {
732-
CString strText;
733-
m_cmbRtmpUrl.GetLBText(i, strText);
734-
if (strText.Compare(strUrl) == 0) {
735-
m_cmbRtmpUrl.DeleteString(i);
736-
break;
737-
}
738-
}
739-
740-
if (m_urlSet.find(strUrl) != m_urlSet.end()) {
741-
m_urlSet.erase(strUrl);
742-
}
743-
744-
if (m_cmbRtmpUrl.GetCurSel() < 0 && m_cmbRtmpUrl.GetCount() > 0)
745-
m_cmbRtmpUrl.SetCurSel(0);
746-
}
747-
else if (error == 155) {
748-
m_rtcEngine->addPublishStreamUrl(url, false);
749-
750-
if (m_mapUrlToTimer.find(url) == m_mapUrlToTimer.end()) {
751-
LastTimer_Republish_id++;
752-
m_mapUrlToTimer[url] = LastTimer_Republish_id;
753-
m_mapTimerToUrl[LastTimer_Republish_id] = url;
754-
m_mapTimerToRepublishCount[LastTimer_Republish_id] = 1;
755-
756-
SetTimer(LastTimer_Republish_id, 1000, NULL);
757-
}
758-
759-
}
760-
761-
762-
delete[] url;
763-
url = nullptr;
764-
return 0;
765-
}
766-
767726

768727
void CAgoraRtmpStreamingDlg::OnTimer(UINT_PTR nIDEvent)
769728
{
@@ -778,6 +737,6 @@ void CAgoraRtmpStreamingDlg::OnTimer(UINT_PTR nIDEvent)
778737
}
779738

780739
m_mapTimerToRepublishCount[nIDEvent]++;
781-
m_rtcEngine->addPublishStreamUrl(m_mapTimerToUrl[nIDEvent].c_str(), false);
740+
m_rtcEngine->startRtmpStreamWithoutTranscoding(m_mapTimerToUrl[nIDEvent].c_str());
782741
}
783742
}

windows/APIExample/APIExample/Advanced/RTMPStream/AgoraRtmpStreaming.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,7 @@ class CAgoraRtmpStreamingDlgRtcEngineEventHandler
7171
@param state The RTMP streaming state. See: #RTMP_STREAM_PUBLISH_STATE.
7272
@param errCode The detailed error information for streaming. See: #RTMP_STREAM_PUBLISH_ERROR.
7373
*/
74-
virtual void onRtmpStreamingStateChanged(const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR errCode)override;
75-
76-
/** @deprecated This method is deprecated, use the \ref agora::rtc::IRtcEngineEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback instead.
77-
78-
Reports the result of calling the \ref agora::rtc::IRtcEngine::removePublishStreamUrl "removePublishStreamUrl" method. (CDN live only.)
79-
80-
This callback indicates whether you have successfully removed an RTMP stream from the CDN.
81-
82-
@param url The RTMP URL address.
83-
*/
84-
virtual void onStreamUnpublished(const char *url) override;
85-
86-
/** @deprecated This method is deprecated, use the \ref agora::rtc::IRtcEngineEventHandler::onRtmpStreamingStateChanged "onRtmpStreamingStateChanged" callback instead.
87-
88-
Reports the result of calling the \ref IRtcEngine::addPublishStreamUrl "addPublishStreamUrl" method. (CDN live only.)
89-
90-
@param url The RTMP URL address.
91-
@param error Error code: #ERROR_CODE_TYPE. Main errors include:
92-
- #ERR_OK (0): The publishing succeeds.
93-
- #ERR_FAILED (1): The publishing fails.
94-
- #ERR_INVALID_ARGUMENT (2): Invalid argument used. If, for example, you did not call \ref agora::rtc::IRtcEngine::setLiveTranscoding "setLiveTranscoding" to configure LiveTranscoding before calling \ref agora::rtc::IRtcEngine::addPublishStreamUrl "addPublishStreamUrl", the SDK reports #ERR_INVALID_ARGUMENT.
95-
- #ERR_TIMEDOUT (10): The publishing timed out.
96-
- #ERR_ALREADY_IN_USE (19): The chosen URL address is already in use for CDN live streaming.
97-
- #ERR_RESOURCE_LIMITED (22): The backend system does not have enough resources for the CDN live streaming.
98-
- #ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH (130): You cannot publish an encrypted stream.
99-
- #ERR_PUBLISH_STREAM_CDN_ERROR (151)
100-
- #ERR_PUBLISH_STREAM_NUM_REACH_LIMIT (152)
101-
- #ERR_PUBLISH_STREAM_NOT_AUTHORIZED (153)
102-
- #ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR (154)
103-
- #ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED (156)
104-
*/
105-
virtual void onStreamPublished(const char *url, int error) override;
74+
virtual void onRtmpStreamingStateChanged(const char *url, RTMP_STREAM_PUBLISH_STATE state, RTMP_STREAM_PUBLISH_ERROR_TYPE errType)override;
10675

10776
virtual void onRtmpStreamingEvent(const char* url, RTMP_STREAMING_EVENT eventCode)override;
10877
private:
@@ -169,8 +138,6 @@ class CAgoraRtmpStreamingDlg : public CDialogEx
169138
afx_msg LRESULT OnEIDLeaveChannel(WPARAM wParam, LPARAM lParam);
170139
afx_msg LRESULT OnEIDRtmpStateChanged(WPARAM wParam, LPARAM lParam);
171140
afx_msg void OnSelchangeListInfoBroadcasting();
172-
afx_msg LRESULT OnEIDStreamUnpublished(WPARAM wParam, LPARAM lParam);
173-
afx_msg LRESULT OnEIDStreamPublished(WPARAM wParam, LPARAM lParam);
174141
afx_msg LRESULT OnEIDRtmpEvent(WPARAM wParam, LPARAM lParam);
175142
afx_msg void OnTimer(UINT_PTR nIDEvent);
176143

0 commit comments

Comments
 (0)