make sdp_audio_codecs_select() safe for any codec

So far, the selected codec needs to be a member of the list. Instead,
make this API safe for any instance, member or not, by looking it up.

Remove the lookup from the only caller.
A subsequent patch adds another caller that would have needed a manual
lookup before calling sdp_audio_codecs_select().

Change-Id: Ic1b5ba46c6f4c58e518b080bcb9b5741cb70ccc3
This commit is contained in:
Neels Hofmeyr 2024-02-05 06:24:47 +01:00
parent d94fe1cd37
commit dcb6ce71c2
3 changed files with 16 additions and 8 deletions

View File

@ -69,7 +69,8 @@ struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac,
void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
bool translate_payload_type_numbers);
void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
bool sdp_audio_codecs_select(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
void sdp_audio_codecs_select_member(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);

View File

@ -62,12 +62,10 @@ int codec_filter_run(struct codec_filter *codec_filter, struct sdp_msg *result,
if (sdp_audio_codec_is_set(a)) {
/* Assignment has completed, the chosen codec should be the first of the resulting SDP.
* If present, make sure this is listed in first place.
* If 'select' is NULL, the assigned codec is not present in the intersection of possible choices for
* TFO. Just omit the assigned codec from the filter result, and it is the CC code's responsibility to
* detect this and assign a working codec instead. */
struct sdp_audio_codec *select = sdp_audio_codecs_by_descr(r, a);
if (select)
sdp_audio_codecs_select(r, select);
* If the assigned codec is not present in the intersection of possible choices for TrFO, just omit the
* assigned codec from the filter result, and it is the CC code's responsibility to detect this and
* assign a working codec instead. */
sdp_audio_codecs_select(r, a);
}
return 0;
}

View File

@ -654,7 +654,7 @@ void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struc
/* Make sure the given codec is listed as the first codec. 'codec' must be an actual codec entry of the given audio
* codecs list. */
void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec)
void sdp_audio_codecs_select_member(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec)
{
struct sdp_audio_codec tmp;
struct sdp_audio_codec *pos;
@ -673,6 +673,15 @@ void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec
return;
}
bool sdp_audio_codecs_select(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec)
{
struct sdp_audio_codec *select = sdp_audio_codecs_by_descr(ac, codec);
if (!select)
return false;
sdp_audio_codecs_select_member(ac, select);
return true;
}
/* Short single-line representation of an SDP audio codec, convenient for logging.
* Like "AMR/8000:octet-align=1#122" */
int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec)