Skip to content

Commit d4ab4ef

Browse files
author
xianing
committed
adjust rtmp error code handling
1 parent 2952b54 commit d4ab4ef

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR;
4545
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_NET_DOWN;
4646
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_OK;
47+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR;
4748
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND;
4849
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
4950
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
@@ -528,10 +529,15 @@ public void onRtmpStreamingStateChanged(String url, int state, int errorType) {
528529
engine.stopRtmpStream(et_url.getText().toString());
529530
if((errorType == RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT
530531
|| errorType == RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR
532+
|| errorType == RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR
531533
|| errorType == RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND
532534
|| errorType == RTMP_STREAM_PUBLISH_ERROR_NET_DOWN))
533535
{
534-
/**if failed, make changes to the UI.*/
536+
/**need republishing.*/
537+
Log.w(TAG, "RTMP publish failure ->" + url + ", state->" + state + ", errorType->" + errorType);
538+
}
539+
else{
540+
/**Other failures which can't be recover by republishing, make changes to the UI.*/
535541
retryTask.cancel(true);
536542
unpublishing = true;
537543
}

iOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ extension RTMPStreamingMain: AgoraRtcEngineDelegate {
334334
if errorCode == .streamingErrorCodeInternalServerError
335335
|| errorCode == .streamingErrorCodeStreamNotFound
336336
|| errorCode == .streamPublishErrorNetDown
337+
|| errorCode == .streamingErrorCodeRtmpServerError
337338
|| errorCode == .streamingErrorCodeConnectionTimeout {
338339
self.showAlert(title: "Error", message: "RTMP Publish Failed: \(errorCode.rawValue)")
340+
}
341+
else{
339342
stopRetryTimer()
340343
unpublishing = true
341344
}

macOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
352352
if errorCode == .streamingErrorCodeInternalServerError
353353
|| errorCode == .streamingErrorCodeStreamNotFound
354354
|| errorCode == .streamPublishErrorNetDown
355+
|| errorCode == .streamingErrorCodeRtmpServerError
355356
|| errorCode == .streamingErrorCodeConnectionTimeout {
356357
self.showAlert(title: "Error", message: "\(url) Publish Failed: \(errorCode.rawValue)")
358+
}
359+
else{
357360
unpublishing = true
358361
}
359362
} else if(state == .idle) {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDRtmpStateChanged(WPARAM wParam, LPARAM lPar
513513
{
514514
case RTMP_STREAM_PUBLISH_STATE_IDLE:
515515
{
516-
strInfo.Format(_T("%s:%S¡£"), agoraRtmpStateIdle, rtmpState->url);
516+
strInfo.Format(_T("%s:%S��"), agoraRtmpStateIdle, rtmpState->url);
517517
CString strUrl;
518518
strUrl.Format(_T("%S"), rtmpState->url);
519519
int sel = m_cmbRtmpUrl.GetCurSel();
@@ -574,8 +574,19 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDRtmpStateChanged(WPARAM wParam, LPARAM lPar
574574
if (error == RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT
575575
|| error == RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR
576576
|| error == RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND
577+
|| error == RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR
577578
|| error == RTMP_STREAM_PUBLISH_ERROR_NET_DOWN) {
578-
579+
if (m_mapRepublishFlag.find(szUrl.c_str()) != m_mapRepublishFlag.end()
580+
&& m_mapRemoveFlag.find(szUrl.c_str()) != m_mapRemoveFlag.end()) {
581+
if (m_mapRepublishFlag[szUrl.c_str()]
582+
&& !m_mapRemoveFlag[szUrl.c_str()]) {
583+
//republish, removePublish when error
584+
m_rtcEngine->startRtmpStreamWithoutTranscoding(szUrl.c_str());
585+
}
586+
}
587+
}
588+
else {
589+
// stop retrying
579590
m_mapRemoveFlag[szUrl.c_str()] = false;
580591
m_mapRepublishFlag[szUrl.c_str()] = true;
581592
CString strUrl;
@@ -596,15 +607,6 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDRtmpStateChanged(WPARAM wParam, LPARAM lPar
596607
if (m_cmbRtmpUrl.GetCurSel() < 0 && m_cmbRtmpUrl.GetCount() > 0)
597608
m_cmbRtmpUrl.SetCurSel(0);
598609
}
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-
}
608610

609611

610612
switch (rtmpState->state)

0 commit comments

Comments
 (0)