From 48219758eae1ddef151d2b38b647f95b4a403a04 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 26 Apr 2023 09:05:00 +0200 Subject: [PATCH] use Opus, not OPUS For audio codecs, we respect its native capitalization of letters, eg. AAC, speex. So do it also for Opus. This should not affect existing applications since the Opus name is parsed case-insensitively. Only exception is SDP (rtpmap) where is usually used lower-case (at least in rfc7587). --- src/audio/codec.cpp | 4 ++-- src/audio/codec/libavcodec.c | 6 +++--- src/main.cpp | 2 +- src/rtsp/BasicRTSPOnlySubsession.cpp | 2 +- src/transmit.cpp | 8 ++++---- src/utils/sdp.c | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/audio/codec.cpp b/src/audio/codec.cpp index 0f2989b5d..3ba922150 100644 --- a/src/audio/codec.cpp +++ b/src/audio/codec.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2013-2021 CESNET, z. s. p. o. + * Copyright (c) 2013-2023 CESNET, z. s. p. o. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,7 +65,7 @@ static const unordered_map> audio_c {AC_ALAW, { "A-law", 0x0006 }}, {AC_MULAW, { "u-law", 0x0007 }}, {AC_SPEEX, { "speex", 0xA109 }}, - {AC_OPUS, { "OPUS", 0x7375704F }}, // == Opus, the TwoCC isn't defined + {AC_OPUS, { "Opus", 0x7375704F }}, // == Opus, the TwoCC isn't defined {AC_G722, { "G.722", 0x028F }}, {AC_MP3, { "MP3", 0x0055 }}, {AC_AAC, { "AAC", 0x00FF }}, diff --git a/src/audio/codec/libavcodec.c b/src/audio/codec/libavcodec.c index 2be0d5abc..34485e330 100644 --- a/src/audio/codec/libavcodec.c +++ b/src/audio/codec/libavcodec.c @@ -1,5 +1,5 @@ /** - * @file audio/codec/libavcodec.cpp + * @file audio/codec/libavcodec.c * @author Martin Pulec */ /* @@ -335,7 +335,7 @@ static bool reinitialize_encoder(struct libavcodec_codec_state *s, struct audio_ if (strcmp(s->codec->name, "libopus") == 0) { int ret = av_opt_set(s->codec_ctx->priv_data, "application", "lowdelay", 0); if (ret != 0) { - print_libav_audio_error(LOG_LEVEL_WARNING, "Could not set OPUS low delay app type", ret); + print_libav_audio_error(LOG_LEVEL_WARNING, "Could not set Opus low delay app type", ret); } } else if (strcmp(s->codec->name, "opus") == 0) { char warn[] = MOD_NAME "Native FFmpeg Opus encoder seems to be currently broken " @@ -356,7 +356,7 @@ static bool reinitialize_encoder(struct libavcodec_codec_state *s, struct audio_ if (s->codec->id == AV_CODEC_ID_OPUS) { int ret = av_opt_set_double(s->codec_ctx->priv_data, "frame_duration", frame_duration, 0); if (ret != 0) { - print_libav_audio_error(LOG_LEVEL_ERROR, "Could not set OPUS frame duration", ret); + print_libav_audio_error(LOG_LEVEL_ERROR, "Could not set Opus frame duration", ret); } } if (s->codec->id == AV_CODEC_ID_FLAC) { diff --git a/src/main.cpp b/src/main.cpp index 75d215f6f..1f7414ff5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1130,7 +1130,7 @@ static int adjust_params(struct ug_options *opt) { if (opt->audio.codec_cfg == nullptr) { if (strcasecmp(opt->audio.proto, "rtsp") == 0 || strcasecmp(opt->audio.proto, "sdp") == 0) { - opt->audio.codec_cfg = "OPUS:sample_rate=48000"; + opt->audio.codec_cfg = "Opus:sample_rate=48000"; } else { opt->audio.codec_cfg = DEFAULT_AUDIO_CODEC; } diff --git a/src/rtsp/BasicRTSPOnlySubsession.cpp b/src/rtsp/BasicRTSPOnlySubsession.cpp index bed3f49cb..eddf38f18 100644 --- a/src/rtsp/BasicRTSPOnlySubsession.cpp +++ b/src/rtsp/BasicRTSPOnlySubsession.cpp @@ -170,7 +170,7 @@ void BasicRTSPOnlySubsession::setSDPLines() { //rtpmapLine, // a=rtpmap:... (if present) rtp_port_audio + 1, rtpPayloadType, - audio_codec == AC_MULAW ? "PCMU" : audio_codec == AC_ALAW ? "PCMA" : "OPUS", + audio_codec == AC_MULAW ? "PCMU" : audio_codec == AC_ALAW ? "PCMA" : "opus", audio_sample_rate, audio_channels, trackId()); // a=control: diff --git a/src/transmit.cpp b/src/transmit.cpp index 6ff990229..d57b31dd8 100644 --- a/src/transmit.cpp +++ b/src/transmit.cpp @@ -17,7 +17,7 @@ * * Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya * Copyright (c) 2001-2004 University of Southern California - * Copyright (c) 2005-2021 CESNET z.s.p.o. + * Copyright (c) 2005-2023 CESNET z.s.p.o. * * Redistribution and use in source and binary forms, with or without * modification, is permitted provided that the following conditions @@ -983,7 +983,7 @@ void audio_tx_send_standard(struct tx* tx, struct rtp *rtp_session, if (buffer->get_codec() == AC_OPUS) { // OPUS needs to fit one package if (payload_size < data_len) { - log_msg(LOG_LEVEL_ERROR, "Transmit: OPUS frame larger than packet! Discarding...\n"); + log_msg(LOG_LEVEL_ERROR, "Transmit: Opus frame larger than packet! Discarding...\n"); return; } } else { // we may split the data into more packets, compute chunk size @@ -997,8 +997,8 @@ void audio_tx_send_standard(struct tx* tx, struct rtp *rtp_session, // interleave if (buffer->get_codec() == AC_OPUS) { - if (buffer->get_channel_count() > 1) { // we cannot interleave OPUS here - LOG(LOG_LEVEL_ERROR) << "Transmit: Only OPUS with 1 channel is supported in RFC-compliant mode! Discarding...\n"; + if (buffer->get_channel_count() > 1) { // we cannot interleave Opus here + LOG(LOG_LEVEL_ERROR) << "Transmit: Only Opus with 1 channel is supported in RFC-compliant mode! Discarding...\n"; return; } memcpy(tx->tmp_packet, buffer->get_data(0), pkt_len); diff --git a/src/utils/sdp.c b/src/utils/sdp.c index 1aeb668b3..ecbb5d58f 100644 --- a/src/utils/sdp.c +++ b/src/utils/sdp.c @@ -183,11 +183,11 @@ int sdp_add_audio(struct sdp *sdp, int port, int sample_rate, int channels, audi audio_codec = "PCMU"; break; case AC_OPUS: - audio_codec = "OPUS"; - ts_rate = 48000; // RFC 7587 specifies always 48 kHz for OPUS + audio_codec = "opus"; + ts_rate = 48000; // RFC 7587 specifies always 48 kHz for Opus break; default: - log_msg(LOG_LEVEL_ERROR, "[SDP] Currently only PCMA, PCMU and OPUS audio codecs are supported!\n"); + log_msg(LOG_LEVEL_ERROR, "[SDP] Currently only PCMA, PCMU and Opus audio codecs are supported!\n"); return -2; }