Skip to content

Commit

Permalink
SDP: set audio ch count 2 for Opus
Browse files Browse the repository at this point in the history
According to RFC 7587, channel count must be set always to 2 (actual
channel count like mono is signalized in-band in Opus)
  • Loading branch information
MartinPulec committed Jan 8, 2024
1 parent edc39db commit 64d088f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/rtsp/BasicRTSPOnlySubsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:<track-id>

fSDPLines = sdpLines;
Expand Down
6 changes: 5 additions & 1 deletion src/utils/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 64d088f

Please sign in to comment.