diff --git a/src/rtsp/BasicRTSPOnlySubsession.cpp b/src/rtsp/BasicRTSPOnlySubsession.cpp index c13053da2..adb1416b4 100644 --- a/src/rtsp/BasicRTSPOnlySubsession.cpp +++ b/src/rtsp/BasicRTSPOnlySubsession.cpp @@ -149,6 +149,8 @@ void BasicRTSPOnlySubsession::setSDPLines() { char* rtpmapLine = strdup("a=rtpmap:97 PCMU/48000/2\n"); //only to alloc max possible size //char const* auxSDPLine = ""; + const int sdp_ch_count = audio_codec == AC_OPUS ? 2 : + audio_channels; // RFC 7587 enforces 2 for Opus char const* const sdpFmt = "m=%s %u RTP/AVP %u\r\n" "c=IN IP4 %s\r\n" "b=AS:%u\r\n" @@ -172,7 +174,7 @@ void BasicRTSPOnlySubsession::setSDPLines() { rtpPayloadType, audio_codec == AC_MULAW ? "PCMU" : audio_codec == AC_ALAW ? "PCMA" : "opus", audio_sample_rate, - audio_channels, + sdp_ch_count, trackId()); // a=control: fSDPLines = sdpLines; diff --git a/src/utils/sdp.c b/src/utils/sdp.c index d78cfe678..d51ead3e0 100644 --- a/src/utils/sdp.c +++ b/src/utils/sdp.c @@ -251,7 +251,11 @@ int sdp_add_audio(bool ipv6, int port, int sample_rate, int channels, audio_code return -2; } - snprintf(sdp_state->stream[index].rtpmap, STR_LENGTH, "a=rtpmap:%d %s/%i/%i\n", PT_DynRTP_Type97, audio_codec, ts_rate, channels); + const int sdp_ch_count = + codec == AC_OPUS ? 2 : channels; // RFC 7587 enforces 2 for Opus + snprintf(sdp_state->stream[index].rtpmap, STR_LENGTH, + "a=rtpmap:%d %s/%i/%i\n", PT_DynRTP_Type97, audio_codec, + ts_rate, sdp_ch_count); } sdp_state->audio_set = true; start();