Skip to content

Commit

Permalink
MT#55283 add option allow no codec media
Browse files Browse the repository at this point in the history
Change-Id: I516972d85a26d68b9f9c2a9613294a02448391b6
  • Loading branch information
rfuchs committed Oct 9, 2024
1 parent 39069a7 commit c4b81b6
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 8 deletions.
6 changes: 3 additions & 3 deletions daemon/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ static void codecs_offer(struct call_media *media, struct call_media *other_medi
codec_store_offer(&other_media->codecs, &flags->codec_offer, &sp->codecs);
if (!other_media->codecs.strip_full)
codec_store_offer(&other_media->codecs, &flags->codec_transcode, &sp->codecs);
codec_store_check_empty(&other_media->codecs, &sp->codecs);
codec_store_check_empty(&other_media->codecs, &sp->codecs, flags);
codec_store_accept(&other_media->codecs, &flags->codec_accept, NULL);
codec_store_accept(&other_media->codecs, &flags->codec_consume, &sp->codecs);
codec_store_track(&other_media->codecs, &flags->codec_mask);
Expand Down Expand Up @@ -2489,7 +2489,7 @@ static void codecs_offer(struct call_media *media, struct call_media *other_medi
codec_store_strip(&media->codecs, &flags->codec_mask, flags->codec_except);
codec_store_offer(&media->codecs, &flags->codec_offer, &sp->codecs);
codec_store_transcode(&media->codecs, &flags->codec_transcode, &sp->codecs);
codec_store_check_empty(&media->codecs, &sp->codecs);
codec_store_check_empty(&media->codecs, &sp->codecs, flags);
codec_store_synthesise(&media->codecs, &other_media->codecs);

// update supp codecs based on actions so far
Expand Down Expand Up @@ -2535,7 +2535,7 @@ static void codecs_answer(struct call_media *media, struct call_media *other_med
.allow_asymmetric = !!flags->allow_asymmetric_codecs);
codec_store_strip(&other_media->codecs, &flags->codec_strip, flags->codec_except);
codec_store_offer(&other_media->codecs, &flags->codec_offer, &sp->codecs);
codec_store_check_empty(&other_media->codecs, &sp->codecs);
codec_store_check_empty(&other_media->codecs, &sp->codecs, flags);

// update callee side codec handlers again (second pass after the offer) as we
// might need to update some handlers, e.g. when supplemental codecs have been
Expand Down
6 changes: 6 additions & 0 deletions daemon/call_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,12 @@ void call_ng_flags_flags(str *s, unsigned int idx, helper_arg arg) {
case CSH_LOOKUP("allow-asymmetric-codec"):
out->allow_asymmetric_codecs = 1;
break;
case CSH_LOOKUP("allow-no-codec-media"):
case CSH_LOOKUP("allow-no-codec-medias"):
case CSH_LOOKUP("allow-empty-codec-media"):
case CSH_LOOKUP("allow-empty-codec-medias"):
out->allow_no_codec_media = 1;
break;
case CSH_LOOKUP("allow-transcoding"):
out->allow_transcoding = 1;
break;
Expand Down
5 changes: 4 additions & 1 deletion daemon/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -5160,10 +5160,13 @@ void __codec_store_populate_reuse(struct codec_store *dst, struct codec_store *s
}
}

void codec_store_check_empty(struct codec_store *dst, struct codec_store *src) {
void codec_store_check_empty(struct codec_store *dst, struct codec_store *src, sdp_ng_flags *flags) {
if (dst->codec_prefs.length)
return;

if (flags->allow_no_codec_media)
return;

ilog(LOG_WARN, "Usage error: List of codecs empty. Restoring original list of codecs. "
"Results may be unexpected.");

Expand Down
15 changes: 13 additions & 2 deletions daemon/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,11 @@ static void print_codec_list(GString *s, struct call_media *media) {
return;
}

if (media->codecs.codec_prefs.length == 0)
return; // legacy protocol or usage error
if (media->codecs.codec_prefs.length == 0) {
// legacy protocol, usage error, or allow-no-codec-media set. Print something and bail
g_string_append(s, "0");
return;
}

for (__auto_type l = media->codecs.codec_prefs.head; l; l = l->next) {
rtp_payload_type *pt = l->data;
Expand Down Expand Up @@ -3052,6 +3055,14 @@ static struct call_media *sdp_out_set_source_media_address(struct call_media *me
return source_media;
}

// handle special case: allow-no-codec-media
if (flags->allow_no_codec_media && media->codecs.codec_prefs.length == 0
&& proto_is_rtp(media->protocol))
{
// convert to rejected/removed stream
*sdp_address = NULL;
}

return NULL;
}

Expand Down
12 changes: 12 additions & 0 deletions docs/ng_control_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,18 @@ Spaces in each string may be replaced by hyphens.
Note that payload type number translation will not be performed in this
situation.

* `allow no codec media`

Enables special handling for SDP media sections (`m=` lines) that are left
without any codecs after codec manipulation operations (in particular codec
stripping) have been performed. By default without this option set, a media
section without any codecs would be considered a usage error, and the
original list of codecs would be restored so that media flow can be
established. With this option set, a media section without any codecs would
be considered intentionally so, and would be converted to a rejected or
removed media section, that is a media section with a zero port, a dummy
format list, and further attributes.

* `allow transcoding`

This flag is only useful in commands that provide an explicit answer SDP to *rtpengine*
Expand Down
1 change: 1 addition & 0 deletions include/call_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct sdp_ng_flags {
single_codec:1,
reuse_codec:1,
static_codecs:1,
allow_no_codec_media:1,
allow_transcoding:1,
allow_asymmetric_codecs:1,
early_media:1,
Expand Down
4 changes: 2 additions & 2 deletions include/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ __attribute__((nonnull(1, 2)))
void codec_store_strip(struct codec_store *, str_q *strip, str_case_ht except);
__attribute__((nonnull(1, 2, 3)))
void codec_store_offer(struct codec_store *, str_q *, struct codec_store *);
__attribute__((nonnull(1, 2)))
void codec_store_check_empty(struct codec_store *, struct codec_store *);
__attribute__((nonnull(1, 2, 3)))
void codec_store_check_empty(struct codec_store *, struct codec_store *, sdp_ng_flags *);
__attribute__((nonnull(1, 2)))
void codec_store_accept(struct codec_store *, str_q *, struct codec_store *);
__attribute__((nonnull(1, 2)))
Expand Down
71 changes: 71 additions & 0 deletions t/auto-daemon-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24672,5 +24672,76 @@ sub stun_succ {
like($resp->{sdp}, qr/\r\na=foobar\r\na=sendrecv\r\na=rtcp:\d+\r\n$/s, 'SDP matches');


new_call;

offer('allow-no-codec-media control', {
codec => { strip => ['all'], except => ['PCMA'] },
}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2000 RTP/AVP 8
c=IN IP4 198.51.100.1
a=rtpmap:8 PCMA/8000
a=sendrecv
m=video 3000 RTP/AVP 97
c=IN IP4 198.51.100.1
a=rtpmap:97 H264/90000
a=fmtp:97 profile-level-id=428016;packetization-mode=0;max-mbps=490000;max-fs=8160;max-cpb=200;max-dpb=16320;max-br=5000;max-smbps=490000;max-fps=6000
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio PORT RTP/AVP 8
c=IN IP4 203.0.113.1
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
m=video PORT RTP/AVP 97
c=IN IP4 203.0.113.1
a=rtpmap:97 H264/90000
a=fmtp:97 profile-level-id=428016;packetization-mode=0;max-mbps=490000;max-fs=8160;max-cpb=200;max-dpb=16320;max-br=5000;max-smbps=490000;max-fps=6000
a=sendrecv
a=rtcp:PORT
SDP

new_call;

offer('allow-no-codec-media control', {
codec => { strip => ['all'], except => ['PCMA'] },
flags => ['allow no codec media'],
}, <<SDP);
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio 2000 RTP/AVP 8
c=IN IP4 198.51.100.1
a=rtpmap:8 PCMA/8000
a=sendrecv
m=video 3000 RTP/AVP 97
c=IN IP4 198.51.100.1
a=rtpmap:97 H264/90000
a=fmtp:97 profile-level-id=428016;packetization-mode=0;max-mbps=490000;max-fs=8160;max-cpb=200;max-dpb=16320;max-br=5000;max-smbps=490000;max-fps=6000
a=sendrecv
----------------------------------
v=0
o=- 1545997027 1 IN IP4 198.51.100.1
s=tester
t=0 0
m=audio PORT RTP/AVP 8
c=IN IP4 203.0.113.1
a=rtpmap:8 PCMA/8000
a=sendrecv
a=rtcp:PORT
m=video 0 RTP/AVP 0
c=IN IP4 0.0.0.0
SDP



#done_testing;NGCP::Rtpengine::AutoTest::terminate('f00');exit;
done_testing();
1 change: 1 addition & 0 deletions utils/rtpengine-ng-client
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ my @flags = qw(
recording-vsc
block-egress
directional
allow-no-codec-media
);

my @string_opts = qw(
Expand Down

0 comments on commit c4b81b6

Please sign in to comment.