From 64d088f5e7b852b60712fe54d4e2c17e95039f11 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 8 Jan 2024 17:09:20 +0100 Subject: [PATCH] SDP: set audio ch count 2 for Opus According to RFC 7587, channel count must be set always to 2 (actual channel count like mono is signalized in-band in Opus) --- src/rtsp/BasicRTSPOnlySubsession.cpp | 4 +++- src/utils/sdp.c | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rtsp/BasicRTSPOnlySubsession.cpp b/src/rtsp/BasicRTSPOnlySubsession.cpp index c13053da2a..adb1416b4b 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 d78cfe678e..d51ead3e0d 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();