MT#55283 add codec_def_supported() helper

Make sure a codec is not only known to us, but that it can actually be
used, in places where it makes sense. This is partially redundant
because ensure_codec_def_type already takes care of this, but a codec
definition may come from a different source, so it doesn't help to
double check.

Change-Id: I91af84afc2477840f1400674b2538ad8fb7746ee
pull/1910/head
Richard Fuchs 2 months ago
parent c42f130da8
commit 7b60e85970

@ -441,9 +441,9 @@ static bool __make_transcoder_full(struct codec_handler *handler, rtp_payload_ty
int cn_payload_type, int (*packet_decoded)(decoder_t *, AVFrame *, void *, void *),
struct ssrc_entry *(*ssrc_handler_new_func)(void *p))
{
if (!handler->source_pt.codec_def)
if (!codec_def_supported(handler->source_pt.codec_def))
return false;
if (!dest->codec_def)
if (!codec_def_supported(dest->codec_def))
return false;
// don't reset handler if it already matches what we want
@ -682,7 +682,7 @@ static void __check_codec_list(GHashTable **supplemental_sinks, rtp_payload_type
for (__auto_type l = sink->codecs.codec_prefs.head; l; l = l->next) {
rtp_payload_type *pt = l->data;
ensure_codec_def(pt, sink);
if (!pt->codec_def) // not supported, next
if (!codec_def_supported(pt->codec_def)) // not supported, next
continue;
// fix up ptime
@ -910,7 +910,7 @@ static void __check_t38_gateway(struct call_media *pcm_media, struct call_media
for (__auto_type l = pcm_media->codecs.codec_prefs.head; l; l = l->next) {
rtp_payload_type *pt = l->data;
struct codec_handler *handler = __get_pt_handler(pcm_media, pt, t38_media);
if (!pt->codec_def) {
if (!codec_def_supported(pt->codec_def)) {
// should not happen
ilogs(codec, LOG_WARN, "Unsupported codec " STR_FORMAT "/" STR_FORMAT
" for T.38 transcoding",
@ -1191,7 +1191,7 @@ void __codec_handlers_update(struct call_media *receiver, struct call_media *sin
struct codec_handler *handler = __get_pt_handler(receiver, pt, sink);
// check our own support for this codec
if (!pt->codec_def) {
if (!codec_def_supported(pt->codec_def)) {
// not supported
ilogs(codec, LOG_DEBUG, "No codec support for " STR_FORMAT "/" STR_FORMAT,
STR_FMT(&pt->encoding_with_params),
@ -1486,7 +1486,7 @@ next:
for (__auto_type l = receiver->codecs.codec_prefs.head; l; ) {
rtp_payload_type *pt = l->data;
if (pt->codec_def) {
if (codec_def_supported(pt->codec_def)) {
// supported
l = l->next;
continue;
@ -3869,7 +3869,7 @@ static bool __ssrc_handler_decode_common(struct codec_ssrc_handler *ch, struct c
static struct ssrc_entry *__ssrc_handler_transcode_new(void *p) {
struct codec_handler *h = p;
if (!h->source_pt.codec_def || !h->dest_pt.codec_def)
if (!codec_def_supported(h->source_pt.codec_def) || !codec_def_supported(h->dest_pt.codec_def))
return NULL;
ilogs(codec, LOG_DEBUG, "Creating SSRC transcoder from %s/%u/%i to "
@ -5490,7 +5490,7 @@ int codec_store_accept_one(struct codec_store *cs, str_q *accept, bool accept_an
rtp_payload_type *pt = l->data;
if (!accept_any) {
ensure_codec_def(pt, cs->media);
if (!pt->codec_def)
if (!codec_def_supported(pt->codec_def))
continue;
}
accept_pt = pt;
@ -5788,7 +5788,7 @@ void codec_store_synthesise(struct codec_store *dst, struct codec_store *opposit
// we already have a list of codecs - make sure they're all supported by us
for (__auto_type l = dst->codec_prefs.head; l;) {
rtp_payload_type *pt = l->data;
if (pt->codec_def) {
if (codec_def_supported(pt->codec_def)) {
l = l->next;
continue;
}

@ -894,7 +894,7 @@ static rtp_payload_type *media_player_get_dst_pt(struct media_player *mp) {
for (__auto_type l = mp->media->codecs.codec_prefs.head; l; l = l->next) {
dst_pt = l->data;
ensure_codec_def(dst_pt, mp->media);
if (dst_pt->codec_def && !dst_pt->codec_def->supplemental)
if (codec_def_supported(dst_pt->codec_def) && !dst_pt->codec_def->supplemental)
goto found;
}
if (!dst_pt) {
@ -987,7 +987,7 @@ static int __ensure_codec_handler(struct media_player *mp, const rtp_payload_typ
// synthesise rtp payload type
rtp_payload_type src_pt = { .payload_type = -1 };
src_pt.codec_def = codec_find_by_av(mp->coder.avstream->CODECPAR->codec_id);
if (!src_pt.codec_def) {
if (!src_pt.codec_def || !src_pt.codec_def->support_decoding) {
ilog(LOG_ERR, "Attempting to play media from an unsupported file format/codec");
return -1;
}

@ -399,7 +399,7 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media,
err = "Failed to init PCM codec";
ensure_codec_def(&tg->pcm_pt, pcm_media);
if (!tg->pcm_pt.codec_def)
if (!codec_def_supported(tg->pcm_pt.codec_def))
goto err;
err = "Failed to create spandsp T.38 gateway";

@ -505,6 +505,11 @@ INLINE int decoder_event(decoder_t *dec, enum codec_event event, void *ptr) {
return 0;
return dec->event_func(event, ptr, dec->event_data);
}
INLINE bool codec_def_supported(codec_def_t *def) {
if (!def)
return false;
return def->support_encoding && def->support_decoding;
}
#else
@ -536,6 +541,9 @@ INLINE codec_def_t *codec_find(const str *name, enum media_type type) {
INLINE void packet_sequencer_destroy(packet_sequencer_t *p) {
return;
}
INLINE bool codec_def_supported(codec_def_t *def) {
return false;
}
#endif

Loading…
Cancel
Save